function decimalToCurrencyString(amount){
amount=parseFloat(amount);
if (amount==0){return "0.00";}
amount = Math.round(amount*100).toString();
amount = amount.substring(0,amount.length-2)+'.'+
amount.substring(amount.length-2,amount.length);
return amount;
}

//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;

//Check if we are using IE.
try {
	//If the Javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//If not, then use the older active x object.
	try {
		//If we are using MS.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		//Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}





function makerequest(siteroot,serverPage, objID,dbid) {
	wks=0;
	sDate='';
	idx='';
	
	var elArr2=document.getElementById("course_num_weeks"+dbid);

	if(elArr2){
		idx = elArr2.selectedIndex;
  		wks = elArr2[idx].value;
		}

	var elArr=document.getElementById("course_start_date"+dbid);
	idx = elArr.selectedIndex;
  	sDate = elArr[idx].value;
	
	if ((wks == null) || (wks == "")) wks=0;
	
	var obj = document.getElementById(objID);
	
	xmlhttp.open("GET", siteroot+serverPage+"?wks="+escape(wks)+"&sDate="+escape(sDate)+"&dbid="+escape(dbid));
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML 		= xmlhttp.responseText;
			subtotalArrElements	= getElementsByClassName(document,"td","singlecoursecost");
			
			total=0.00;
			for (i=0;i<subtotalArrElements.length;i++){
				total+=parseFloat(subtotalArrElements[i].innerHTML);
			}
		document.getElementById("currtotalcoursescost").innerHTML=decimalToCurrencyString(total);
		
		}
	}
	xmlhttp.send(null);
	
	
	//window.setTimeout("updatetotal('"+siteroot+"','scripts/total.php','menutotal')",2000);
}	




function changeairport(siteroot,serverPage, objID,airport) {
	var idx = airport.selectedIndex;
	var val = airport[idx].value;
	var obj = document.getElementById(objID);

	xmlhttp.open("GET", siteroot+serverPage+"?airport="+escape(val));
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}	

function changehalls(siteroot,serverPage, objID) {
	var checkindate = document.getElementById("accomm_check_in_date").value;
	var checkoutdate = document.getElementById("accomm_check_out_date").value;
	
	var obj = document.getElementById("accomm_residence_name");
	var idx = obj.selectedIndex;
	var res = obj[idx].value;
	
	
	var obj = document.getElementById(objID);

	xmlhttp.open("GET", siteroot+serverPage+"?checkindate="+escape(checkindate)+"&checkoutdate="+escape(checkoutdate)+"&residence="+escape(res));
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			
			if (!document.getElementById("currenthomestaycost")){
				homestaytotal=0.00;
				}
			else {
				homestaytotal		=	document.getElementById("currenthomestaycost").innerHTML;	
			}
			if (!document.getElementById("currentaccommcost")){
				accomtotal=0.00;
				}
			else {
				accomtotal		=	document.getElementById("currentaccommcost").innerHTML;	
			}
			bookingfee			=	document.getElementById("currbookingfee").innerHTML;
			if (isNaN(accomtotal)){accomtotal='0.00';}
			if (isNaN(homestaytotal)){homestaytotal='0.00';}
			if (isNaN(bookingfee)){bookingfee='0.00';}
			curtotalaccomtotal	=	parseFloat(accomtotal)+parseFloat(homestaytotal)+parseFloat(bookingfee);
			
			document.getElementById("currenttotalcost").innerHTML=decimalToCurrencyString(curtotalaccomtotal);
		}
	}
	xmlhttp.send(null);
}	




function changehomestay(siteroot,serverPage, objID) {
	var arrivaldate = document.getElementById("home_stay_arrival_date").value;
	var departdate = document.getElementById("home_stay_departure_date").value;
	
	var obj = document.getElementById(objID);

	xmlhttp.open("GET", siteroot+serverPage+"?arrivaldate="+escape(arrivaldate)+"&departdate="+escape(departdate));
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			accomtotal			=	0.00;
			homestaytotal		=	document.getElementById("currenthomestaycost").innerHTML;
			bookingfee			=	document.getElementById("currbookingfee").innerHTML;
			if (isNaN(accomtotal)){accomtotal='0.00';}
			if (isNaN(homestaytotal)){homestaytotal='0.00';}
			if (isNaN(bookingfee)){bookingfee='0.00';}
			curtotalaccomtotal	=	parseFloat(accomtotal)+parseFloat(homestaytotal)+parseFloat(bookingfee);
			
			document.getElementById("currenttotalcost").innerHTML=decimalToCurrencyString(curtotalaccomtotal);
			}
		}
		xmlhttp.send(null);
	}	


function changevisaadminfee(siteroot,serverPage, objID) {
	var obj = document.getElementById(objID);
	var use_admin_fee="y";
	if (document.content.need_a_visa[0].checked)
      {
      use_admin_fee="y";
      }
	 else
	 {
	 use_admin_fee="n";	 
	 }


	xmlhttp.open("GET", siteroot+serverPage+"?use_admin_fee="+use_admin_fee);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			
			document.getElementById("currentvisaadminfee").innerHTML=decimalToCurrencyString(obj.innerHTML);
			}
		}
		xmlhttp.send(null);
	}	



function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements);
}


