var xmlhttp;

function change_currency(field_selection)
  {
	var selected_currency = document.getElementById("current_currency").innerHTML;

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
  	  {
		alert ("Browser does not support HTTP Request");
		return;
	  }
	var url="sb-functions/currency_ajax.php?sid="+Math.random()+"&tocurrency="+field_selection;
	if (field_selection != "" && field_selection != selected_currency)
	  {
		document.getElementById("conversion_rate").innerHTML = "";
		document.getElementById("ajax_loading").style.display = "inline";
		xmlhttp.onreadystatechange=
		function stateChanged()
		  {
			if (xmlhttp.readyState==4)
			  {
				var ratechange = xmlhttp.responseText;

				var ls = document.getElementById("dollar_ls").innerHTML.replace(/\D/g,'');
				var lp = document.getElementById("dollar_lp").innerHTML.replace(/\D/g,'');
				var lf = document.getElementById("dollar_lf").innerHTML.replace(/\D/g,'');
				var ss = document.getElementById("dollar_ss").innerHTML.replace(/\D/g,'');
				var sp = document.getElementById("dollar_sp").innerHTML.replace(/\D/g,'');
				var sf = document.getElementById("dollar_sf").innerHTML.replace(/\D/g,'');

				var unConvert = 1/document.getElementById("current_currency_rate").innerHTML;
				if (unConvert != 1)
				  {
					ls*=unConvert;
					lp*=unConvert;
					lf*=unConvert;
					ss*=unConvert;
					sp*=unConvert;
					sf*=unConvert;
				  }

				document.getElementById("dollar_ls").innerHTML = "= "+Math.round(ratechange*ls)+" "+field_selection+" a month";
				document.getElementById("dollar_lp").innerHTML = "= "+Math.round(ratechange*lp)+" "+field_selection+" a month";
				document.getElementById("dollar_lf").innerHTML = "= "+Math.round(ratechange*lf)+" "+field_selection+" a month";
				document.getElementById("dollar_ss").innerHTML = "= "+Math.round(ratechange*ss)+" "+field_selection+" a week";
				document.getElementById("dollar_sp").innerHTML = "= "+Math.round(ratechange*sp)+" "+field_selection+" a week";
				document.getElementById("dollar_sf").innerHTML = "= "+Math.round(ratechange*sf)+" "+field_selection+" a week";

				document.getElementById("conversion_rate").innerHTML = "USD to "+field_selection+" is "+ratechange;
				document.getElementById("current_currency").innerHTML = field_selection;
				document.getElementById("current_currency_rate").innerHTML = ratechange;
				document.getElementById("ajax_loading").style.display = "none";
			  }
		  }
	  }
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
  }

function GetXmlHttpObject()
  {
	if (window.XMLHttpRequest)
	  {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
  }
