function loadurl(dest) {
try {
	// Moz supports XMLHttpRequest. IE uses ActiveX.
	// browser detction is bad. object detection works for any browser
	xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
	// browser doesn't support ajax. handle however you want
}
// the xmlhttp object triggers an event everytime the status changes

// triggered() function handles the events
xmlhttp.onreadystatechange = triggered;
// open takes in the HTTP method and url.
xmlhttp.open("POST", dest, true);
var params = "username="+document.routerlogin.username.value+"&password="+document.routerlogin.password.value;
//var params = null;
// send the request. if this is a POST request we would have
// sent post variables: send("name=aleem&gender=male)
// Moz is fine with just send(); but
// IE expects a value here, hence we do send(null);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);

}
function clearProcess(){
	document.getElementById('0').style.visibility="hidden";
	document.getElementById('1').style.visibility="hidden";
	document.getElementById('2').style.visibility="hidden";
	document.getElementById('3').style.visibility="hidden";
	document.getElementById('4').style.visibility="hidden";
}
function showProcessing(){
	document.getElementById('xmlwarning').innerHTML="Processing...";
}

function triggered() {
// if the readyState code is 4 (Completed)
// and http status is 200 (OK) we go ahead and get the responseText
// other readyState codes:
// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
	// xmlhttp.responseText object contains the response.
	//document.getElementById("output").innerHTML = xmlhttp.responseText;

	

	clearProcess();
	var xmlDoc=xmlhttp.responseXML.documentElement;
	if (xmlDoc.getElementsByTagName("status")[0].firstChild.data>=1) 
	{
		document.routerlogin.elements["data[User][username]"].value=document.getElementById("username").value;
		document.routerlogin.elements["data[User][password]"].value=document.getElementById("password").value;

		//Handle multiple accounts returned
		var account_count = xmlDoc.getElementsByTagName("account_count")[0].firstChild.data;
		if(account_count>1){
			document.getElementById("xmlwarning").style.color="red";
			document.getElementById("xmlwarning").style.visibility="visible";
			document.getElementById("xmlwarning").innerHTML=xmlDoc.getElementsByTagName("error")[0].firstChild.data;
			for (var x = 0; x < account_count; x++)
			{
				document.getElementById(x).innerHTML="<br>"+xmlDoc.getElementsByTagName("system")[x].firstChild.data;
				document.getElementById(x).style.visibility="visible";
				document.getElementById("idoptlinkurl"+x).value=xmlDoc.getElementsByTagName("url")[x].firstChild.data;
				document.getElementById(x).onclick=function() {clearProcess(); showProcessing(); document.routerlogin.action=document.getElementById("idoptlinkurl"+this.id).value; document.routerlogin.submit();};
			}
		}
		else 
		{
			//one account - login
			clearProcess();
			showProcessing();
			document.routerlogin.action=xmlDoc.getElementsByTagName("url")[0].firstChild.data;
			document.routerlogin.submit();
		}	
	}
	else
	{
		document.getElementById("xmlwarning").style.color="red";
		document.getElementById("xmlwarning").innerHTML=xmlDoc.getElementsByTagName("error")[0].firstChild.data;
		document.getElementById("xmlwarning").style.visibility="visible";
	}
}
}