// JavaScript Document
var xmlHttp

function update(str, action)
{	

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="bookingform.php"
url=url+"?id="+str
url=url+"&action="+action

url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 
function stateChanged() 
{ 	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		 var response = xmlHttp.responseText;
		 var layers_replace = new Array();
		 layers_replace = response.split('*');
		 
		 for(i=0;i<layers_replace.length;i++) 
		 {
			var update = new Array();
			update = layers_replace[i].split('|');
			document.getElementById(update[0]).innerHTML = update[1];
		}
		price();
	} 
} 

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

function loading()
{
	image = "<img src = 'images/loading.gif'>"
	document.getElementById("showhere").innerHTML = image
}

function DisplayImage(picURL,picWidth,picHeight,picTitle){

newWindow=window.open(picURL,'newWin','toolbar=no,width='+picWidth+',height='+picHeight)

newWindow.document.write('<html><head><title>'+picTitle+'<\/title><\/head><body background="'+picURL+'"><\/body><\/html>')

newWindow.resizeBy(picWidth-newWindow.document.body.clientWidth,picHeight-newWindow.document.body.clientHeight)

newWindow.focus()

}
function price()
{
	var bhc_cost = document.getElementById('bhc_cost').value;
	var amc_cost = document.getElementById('amc_cost').value;
	
	if(eval("document.getElementById('EarlyCheckIn').checked") == true)
	{
		var eci_cost = document.getElementById('eci_cost').value	
		bhc_cost = (bhc_cost*1) + (eci_cost*1);		
	}	

	if(eval("document.getElementById('ExtraPet1').checked") == true)
	{
		var ExtraPet = document.getElementById('pet_cost').value
		bhc_cost = (bhc_cost*1) + (ExtraPet*1)		
	}
	if(eval("document.getElementById('ExtraCot1').checked") == true)
	{
		var ExtraCot = document.getElementById('cot_cost').value
		bhc_cost = (bhc_cost*1) + (ExtraCot*1)		
	}
	if(eval("document.getElementById('ExtraHighChair1').checked") == true)
	{
		var ExtraHighChair = document.getElementById('high_chair').value
		bhc_cost = (bhc_cost*1) + (ExtraHighChair*1)		
	}
	if(eval("document.getElementById('AdditionalParty1Age1').value") != " ")
	{
			bhc_cost = (bhc_cost*1) + (amc_cost*1)
			var AdditionalParty1 = new Spry.Widget.ValidationTextField("AdditionalParty1", "none", {isRequired:true});
	}else{var AdditionalParty1 = new Spry.Widget.ValidationTextField("AdditionalParty1", "none", {isRequired:false});}
	if(eval("document.getElementById('AdditionalParty2Age1').value") != " ")
	{
			bhc_cost = (bhc_cost*1) + (amc_cost*1)
			var AdditionalParty2 = new Spry.Widget.ValidationTextField("AdditionalParty2", "none", {isRequired:true});
	}else{var AdditionalParty2 = new Spry.Widget.ValidationTextField("AdditionalParty2", "none", {isRequired:false});}
	if(eval("document.getElementById('AdditionalParty3Age1').value") != " ")
	{
			bhc_cost = (bhc_cost*1) + (amc_cost*1)
			var AdditionalParty3 = new Spry.Widget.ValidationTextField("AdditionalParty3", "none", {isRequired:true});
	}else{var AdditionalParty3 = new Spry.Widget.ValidationTextField("AdditionalParty3", "none", {isRequired:false});}
	if(eval("document.getElementById('AdditionalParty4Age1').value") != " ")
	{
			bhc_cost = (bhc_cost*1) + (amc_cost*1)	
			var AdditionalParty4 = new Spry.Widget.ValidationTextField("AdditionalParty4", "none", {isRequired:true});
	}else{var AdditionalParty4 = new Spry.Widget.ValidationTextField("AdditionalParty4", "none", {isRequired:false});}
	
	bhc_cost = toDollarsAndCents(bhc_cost)
	document.getElementById('total').value = bhc_cost;	
	document.getElementById('hiddentotal').value = bhc_cost;	
	
}
function toDollarsAndCents(n) {
	var s = "" + Math.round(n * 100) / 100
	var i = s.indexOf('.')
	if (i < 0) return s + ".00"
	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
	if (i + 2 == s.length) t += "0"
	return t
	}