var validchars_currency = "0123456789.";
var http = createRequestObject_currency();
var areal = Math.random() + "";
var real = areal.substring(2,6);

function createRequestObject_currency() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function sendRequest_currency() {
	var rnd = Math.random();
	
	var fromCurrency = document.getElementById("fromCurrency").value;
	var toCurrency = document.getElementById("toCurrency").value;
        var amount = escape(document.getElementById("amount").value);
		
	try
        {
         http.open('POST',  '/modules/currency.php');
         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
         http.onreadystatechange = handleResponse_currency;
	 http.send('fromCurrency='+fromCurrency+'&toCurrency='+toCurrency+'&rnd='+rnd+'&amount='+amount);
	}
	catch(e){}
	finally{}
}


function check_values_currency() 
{   
    var amount = escape(document.getElementById("amount").value);
    for(i=0; i<amount.length; i++)
    {
      if (validchars_currency.indexOf(amount.charAt(i),0)!=-1)
      {
         testchar = true;
      }
      else
      {
         testchar = false;
         break;
      }
    }
    if(testchar)
    {
     sendRequest_currency();
    }
    else
    {
      document.getElementById("results").innerHTML = ' Opps ';
      document.getElementById("results").style.display ="";
    }		
}

function handleResponse_currency() {

    if(http.readyState == 1){
      document.getElementById("results").innerHTML = '<img src="/images/mozilla_blu.gif"/> Converting...';
      document.getElementById("results").style.display ="";
    }
    try{
    if((http.readyState == 4)&&(http.status == 200)){
    	var response = http.responseText;
      document.getElementById("results").innerHTML = response;
      document.getElementById("results").style.display ="";
      //document.getElementById("form").style.display = "none";
		}
  }
	catch(e){}
	finally{}
}


