Better JS Contact Parser For a site I wrote this JS contact parser. It simply reads contacts and parses links if a known service is identified. Could this be made more compact? How about robustness? (it cannot handle exceptions where the url does not begin with http for instance). What other services should I consider to add?

Here is jsfiddle. And the code is below:

Markup

&lt;div id="contacts"&gt;&lt;/div&gt;


CSS

span { padding: 10px; }


JS

var contacts = 'guy@gmail.com, guy@owndomain.com, http://twitter.com/guy, http://www.facebook.com/profile.php?id=100002877203519, http://www.linkedin.com/in/coolguy, http://www.myspace.com/coolguy, skype:cool.guy?call, aim:goim?screenname=cool.guy, http://coolguy.com';
var re = / /gi;
contacts = contacts.replace(re, "");
contacts = contacts.split(',');

var picBase = 'http://jqeedu.tuxfamily.org/images/media/';

jQuery(document).ready(function() {

    for (var i = 0; i &lt; contacts.length; i++) {
        addContact(contacts[i]);
    }

});

function addContact(c) {
    cdiv = jQuery("#contacts");
    var i = false;
    var h = '';
    var n = '';

    if(c.indexOf('@gmail.com') != -1) {
        i = 'gmail.png';
        h = 'mailto:'+c;
    }

    if(!i &amp;&amp; c.indexOf('http://www.facebook.com/profile.php?id=') == 0) {
        i = 'facebook.png';
        h = c;
    }

    if(!i &amp;&amp; c.indexOf('http://www.linkedin.com/in/') == 0) {
        i = 'linkedin.png';
        h = c;
    }

    if(!i &amp;&amp; c.indexOf('http://www.myspace.com/') == 0) {
        i = 'myspace.png';
        h = c;
    }

    if(!i &amp;&amp; c.indexOf('skype:') == 0 &amp;&amp; c.indexOf('?call') != -1) {
        i = 'skype.png';
        h = c;
    }

    if(!i &amp;&amp; c.indexOf('aim:goim?screenname=') == 0 ) {
        i = 'aim.png';
        h = c;
    }


    if(!i &amp;&amp; c.indexOf('http://twitter.com/') == 0) {
        i = 'twitter.png';
        h = c;
    }

    if(!i &amp;&amp; c.indexOf('http://') == 0) {
        i = 'website.png';
        h = c;
    }    

    if(!i) {
        i = 'email.png';
        h = 'mailto:'+c;
    }


    n = '&lt;span&gt;&lt;a href="'+h+'"&gt;&lt;img src="'+picBase+i+'"&gt;&lt;/a&gt;&lt;/span&gt;';

    cdiv.append(n);

}
Firstly I would change all the occurances of 

}

if(!i &amp;&amp; c.indexOf(...


to 

 } else if(c.indexOf(...


To me there doesn't seem to be any difference logically and its cleaner.

Second I would use regexes for the urls (I'm sure someone will comment on how regexes aren't needed/ too slow yadda yadda.)

var regexFBprofile = /^(http\:\/\/)?(www\.)?facebook\.com\/profile\.php\?id=/;
var regexLinkedIn = /^(http\:\/\/)?(www\.)?linkedin\.com\/in\//;
var regexMySpace = /^(http\:\/\/)?(www\.)?myspace\.com/;
var regexTwitter = /^(http\:\/\/)?(www\.)?twitter\.com\//;


another small thing:

re = / /g;
contacts = contacts.replace re, "");


with:

contacts[i].trim();


http://jsfiddle.net/96Gk6/34/