var xmlHttp;

function SetXmlHttp()
{
	if(window.XMLHttpRequest) {
		xmlHttp    = new XMLHttpRequest();
	} else {
		xmlHttp    = new ActiveXObject("Microsoft.XMLHTTP");
	} 
}

function GetInfo(pctg, pickup, destination, passenger ,price_obj, hidden_price_obj, pickup_obj, destination_obj, numofpassenger_obj) 
{
	// pctg = 100 //
	// pickup = pickup select value e.g. circular query //
	// destination = destination select value e.g. Rushchutter's Bay //
	// passengers = No of passengers //
	// price obj = div id element where the quote prices are displaying //
	// hidden_price_obj = 
	
	
	
    // init xmlHttp
	SetXmlHttp();

	// Build the URL to connect to

	//var url = "get_price.php?pickup="+escape(pickup)+"&destination="+escape(destination)+"&numofpassenger="+passenger;

	var url = "get_price.php?pickup="+pickup+"&destination="+destination+"&numofpassenger="+passenger;


	//alert("Ready state is: " + request.readyState);

	// Open a connection to the server
	xmlHttp.open("GET", url, true);
	
	// Setup a function for the server to run when it's done
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) 
		{
			if (xmlHttp.status == 200) 
			{
			
//				alert('server is done');
				
				var xml     = xmlHttp.responseXML;
				var param   = xml.getElementsByTagName("price");

				var price = param[0].firstChild.nodeValue;
				var int_price	= parseInt(price)*pctg/100 ;

				if(passenger >= 5) {
					int_price = int_price + (passenger - 4) * 10;
				}
//				price_obj.innerHTML = '$'+int_price.toString()+'.00';
				int_price	= Math.ceil( (int_price) * 100 ) / 100;
				int_price	= Math.round(int_price);

				price_obj.innerHTML = '$'+int_price.toString();
				hidden_price_obj.value = int_price;


				if(pickup_obj == '[object]' || pickup_obj == '[object HTMLInputElement]')
					pickup_obj.value = pickup;
				if(destination_obj == '[object]' || destination_obj == '[object HTMLInputElement]')
					destination_obj.value	 = destination;
				if(numofpassenger_obj == '[object]' || numofpassenger_obj == '[object HTMLInputElement]')
					numofpassenger_obj.value = passenger;

			} else if (xmlHttp.status == 404) {
				alert("Request URL does not exist");
			} else {
				//alert("Error: status code is " + xmlHttp.status);
				alert('Sorry database connection error, please try 10 minutes later.');
			}
		}
	}
	// Send the request
	xmlHttp.send(null);
}
