var elCount = 1;
	
function add()
{

	if(elCount <= 5)
	{
	    

	    var aname = document.getElementById('friends1').value;
	
	    var aname1 = document.getElementById('friends1')[document.getElementById('friends1').selectedIndex].innerHTML;

	    var parent = document.getElementById('addname');

	    var article = document.createElement('DIV');

		article.id = "aname" + elCount;

		article.name = "aname" + elCount;                                // NEW LINE

	    var article_title_label = document.createElement('LABEL');

		article_title_label.appendChild(document.createTextNode(aname1 + " "));

	    var article_title_text = document.createElement('input');
	
		article_title_text.type = 'hidden';
		
		article_title_text.id = 'id[' + aname + ']';

		article_title_text.name = 'id[' + aname + ']';
		
		article_title_text.value = 'random' + elCount;


		var article_remove_a = document.createElement('A');

		article_remove_a.appendChild(document.createTextNode('Remove'));

		article_remove_a.href = "javascript:remove('aname" + elCount + "');";


		article.appendChild(article_title_label);

		article.appendChild(article_title_text);
	
		article.appendChild(article_remove_a);

		parent.appendChild(article);

		//var toremove = document.getElementById('friends1');
	
		//toremove.remove(aname);
	
		elCount++
	}	

}

function remove(el) {

    if(typeof(el) == 'string')

        el = document.getElementById(el);

/*
	var elOptNew = document.createElement('option');
  	elOptNew.text = 'Append' + el;
  	elOptNew.value = 'append' + el;
*/

    var parent = el.parentNode;

    parent.removeChild(el);
/*	
    var toadd = document.getElementById('friends1');

    try {
    	toadd.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    toadd.add(elOptNew); // IE only
  }
*/
}


var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}

function validate(user) {
  http.abort();
  http.open("GET", "namecheck.php?name=" + user, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById('foo').innerHTML = http.responseText;
    }
  }
  http.send(null);
}
