// controls the display/hide of the child ages according to how many children
function displayChildAgeBoxes(numChild)
{
	if (document.getElementById("book")!=null){
		// random children allowed for hotel and holiday booking
		var chdds = document.getElementById("book").getElementsByTagName("dd");
		totNum = chdds.length;
	} else {
		//fixed number for site main search box hotel booking
		totNum = 4;
	}
	document.getElementById("ChildAgeRow").style.display = numChild > 0 ? "" : "none";
	for (i=1; i<=numChild; i++)
		document.getElementById("rm1ChildAge" + i).style.display = "";
	for (; i<=totNum; i++)
		  document.getElementById("rm1ChildAge" + i).style.display = "none";
	
}

function QBCarSetParams()
{
	// For car quickbook, just copy over the duration

	document.getElementById("carAuto").value="dur=" + document.getElementById("carDuration").value;
	setLocalWebBook("QBCarForm");
						
}

// Copies child ages over from the drop downs to the webbook child age params.  Clears out any unspecified child ages
function QBHotelSetParams(numChild)
{
	// For hotel quickbook, use auto to pass through rating and duration
	var autoString;
	autoString = "dur=" + document.getElementById("duration").value;
	autoString = autoString + "#rating=" + document.getElementById("rating").value;
	document.getElementById("auto").value=autoString;
									
    for (i=1; i<=numChild; i++)
	  document.getElementById("par_child_1_" + i).value = document.getElementById("rm1ChildAge" + i).value;
	for (; i<=4; i++)
	  document.getElementById("par_child_1_" + i).value = "";
	  
	setLocalWebBook("QBHotelForm"); 

}

function verify(arg_form)
{
    lclMsg = "";
    totalPassengers =parseInt (arg_form.child_1.value) +  parseInt (arg_form.adult_1.value);
    
    if (( totalPassengers < minTotPax) || ( totalPassengers > maxTotPax))
    {
       lclMsg += "- Selected a minimum of " +minTotPax +" and a maximum "+ maxTotPax +" passengers (incl. children)\n";         
    }
    if (minDuration!=0)
    {
	    
	    selectedStay = parseInt (arg_form.duration.value); 

	    
	    if (selectedStay < minDuration )
	    {
		lclMsg += "- The minimum number of nights allowed is " + minDuration +" \n"; 	
		    
	    }
	    if (selectedStay > maxDuration)
	    {
		lclMsg += "- The maximum number of nights allowed is " + maxDuration +" \n"; 		
	    }
		
		//test if number is entered in number of nights.
		testVar = isNaN(selectedStay);
		if (testVar == true){
			lclMsg += "- Please enter a valid number for nights \n"; 	
		}
    }
	 	
    if(lclMsg!="")
    {
	lclMsg = "Please ensure you have...\n" + lclMsg;
	alert(lclMsg);
	return false;
    }
    else
    {
		//Detect IE5.5
		version=0
		if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE")
		version=parseFloat(temp[1])
		}
		//if browser not ie5.5
		if (version != 5.5) {
			wbSupub = window.open('','wbSupub','resizable=1,width=770,height=570');
			document.params.submit();	
		}
		
		return true;
    } 
}

function SupBookSetParams(numChild,maxChildren)
{
    // For supplier publisher based booking
    var autoString;
    autoString = "dur=" + document.getElementById("duration").value;
	document.getElementById("auto").value=autoString + "#" + document.getElementById("param_str").value;
    for (i=1; i<=numChild; i++)
        document.getElementById("par_child_1_" + i).value = document.getElementById("rm1ChildAge" + i).value;
    for (; i<=maxChildren; i++)
        document.getElementById("par_child_1_" + i).value = "";
    setLocalWebBook("supubForm");
}


function setLocalWebBook(frmId)
{
	// changes the submit action for clienttest and www-ch originated pages (lets us test the booking process with TT)
	
	var frm=document.getElementById(frmId);
	if (frm == null)  return;
	
	thisPage=window.location.href;
	thisPage=thisPage.substring(thisPage.lastIndexOf('://')+3,thisPage.length);
	thisPage=thisPage.substring(0,thisPage.indexOf('/'));
	if ((thisPage.indexOf('www-ch') ==0) ||
		(thisPage.indexOf('clienttest') == 0) ||
		(thisPage.indexOf('webdevhost') == 0) ||
		(thisPage.indexOf('staging') == 0) ||
		(thisPage.indexOf('ausydcs') == 0))
	{
		 frm.action="http://" + thisPage + "/apps/webbook/creative/engine";
		 
	}
	
}


 
