var xmlHttp

function GetXmlHttpObject(){

var xmlHttp = null;
	try {
	  xmlHttp = new XMLHttpRequest();
	  }
	catch (e) {
	  try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function convert(func){
	xmlHttp = GetXmlHttpObject()
	
	if(xmlHttp == null){
		alert ("Your browser does not support AJAX!");
		return;
	}

	var converter=document.getElementById("converter").value;
	var amount=document.getElementById("amount").value;

	var fromx=document.getElementById("from");
	var from = fromx.options[fromx.selectedIndex].value;
	var tox=document.getElementById("to");
	var to = tox.options[tox.selectedIndex].value;
	if (amount != '' && from != '' && to != '') {
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4) {
				document.getElementById('conversion').value = xmlHttp.responseText;
			} 
			else {
				//loader.innerHTML = 'Loading...';
			}
		}
		
		var url = "http://www.numberconverter.net/process.php";
		var params = "converter="+converter+"&amount="+amount+"&from="+from+"&to="+to;
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
} 
