var xmlhttp;

function CalculateQuote()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	{
  		alert ("Browser does not support HTTP Request");
  		return;
  	}

	// create the URL with quantity of tables as parameters
	var url="calculate_quote.php?sid="+Math.random();
	
	// itterate through the input elements and add them to the URL
	//    the id of the input is the id in the pricelist.xml file
	//    the url should include the parameters ?blackjack=3&roulette=2&craps8=1....
	var elements=document.getElementsByTagName("input");
	for (i=0; i<elements.length;i++)
	{
		url=url+"&"+elements[i].id+"="+elements[i].value;
	}

	// alert(url);
	
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
	// just waiting for ready state to be 4--anything else we can let go.
	if (xmlhttp.readyState!=4) return;
  	
		// use responseText or responseXML
  		//document.getElementById("totals").innerHTML=xmlhttp.responseText;
		
		// debug the xml response....
		// alert(xmlhttp.responseText);
		
		// get the responseXML  		
		var xmlDoc=xmlhttp.responseXML;

		// then update the fields
		document.getElementById("price").innerHTML = xmlDoc.getElementsByTagName("price")[0].childNodes[0].nodeValue;
		document.getElementById("players").innerHTML = xmlDoc.getElementsByTagName("players")[0].childNodes[0].nodeValue;
		document.getElementById("space").innerHTML = xmlDoc.getElementsByTagName("space")[0].childNodes[0].nodeValue;
		document.getElementById("setup").innerHTML = xmlDoc.getElementsByTagName("setup")[0].childNodes[0].nodeValue;
		document.getElementById("guests").innerHTML = xmlDoc.getElementsByTagName("guests")[0].childNodes[0].nodeValue;
		document.getElementById("supervisor").innerHTML = xmlDoc.getElementsByTagName("supervisor")[0].childNodes[0].nodeValue;	
		document.getElementById("attendant").innerHTML = xmlDoc.getElementsByTagName("attendant")[0].childNodes[0].nodeValue;	
}

function GetXmlHttpObject()
{
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
  	{
  		objXMLHttp=new XMLHttpRequest();
  	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	return objXMLHttp;
} 
