/**
	The functions below are used to show and hide boxes in a form.
	
	The form allows upto 10 rooms to be chosen from a select box.
	When a number is selected, that many boxes of form fields 
	need to be shown to allow the user to fill in details for the room.
	The details for each room allow upto 6 children to be chosen from a select box.
	When a number is selected, that many text fields need to be show to allow the user
	to enter the age of each child in the room.
	
	The room boxes in the form should be called "folding#" where "#" is a number from
	1 to maxUnits.
	The chilren boxes in the forms should be called "folding#_?" where "#" is the room number
	and "?" is a number from 1 to maxChilren.
	
	Dreamweaver, eat my pants.
	
	The functions will only work for browsers that support getElementById 
	(IE 5+, Netscape 6+, Firefox and most modern browsers).
	
	18 July 2006
	
	Added seatUpgradeSelected function for page9_new.htm to calculate the seating extra cost when
	different options are selected.
	
	Added insuranceQtySelected function for insurance_trs.htm to calculate subtotal when a
	quantity of insurance package(s) is(are) selected.
	
	Added a call to "correctHolidayDates" in the hideOnLoad function so that the
	earliest departure and return dates are automatically selected in the date boxes
	
	27 June 2006
	
	Added correctHolidayDates function to make sure that a person cannot select a commence date less than
	15 days from today.  This updates the return date to be at least a day later.
	
	TODO ??? - make the system generate dates dynamically so we have 12 months from this one..
	
	
	08:11 19th Dec 2005
		unitNum = parseInt(obj.id.substr(obj.id.indexOf("_") + 1)); (in the childrenChange function)
	was changed to:
		unitNum = parseInt(obj.id.substr(obj.id.indexOf(".") + 1));
	in order to allow for Travel Options change to the variable name structure from:
		unit1childage_1_1
	to the following with "." instead of "_":
		rep_accom_child_age.1.1
	
	I love those single character change fixes!!
	
	Tested on PC ie6, firefox, OS9 ie5.1, OSx ie 5.2, OSx Firefox,
	
	Toby P
	
	
*/
//Debugging - if this is "true" you get an alert box when you do things...

debug = false;
//debug = true;
//The maximum number of rooms - if you add rooms to the form, then increase this.
var maxUnits = 10;
//The maximum number of children in each room - increase for more children.
var maxChildren = 6;
//The minimum number of days between commence & return dates.
var minDays = 8;
/**
	function: correctHolidayDates
	param:	  nothing
	returns:  nothing.
	does:	  Retrieves values from the commence & return date dropdowns,
	          checks that the return date is minDays after the commence date
	          if not, it will set the values of the return date to this.
	          Does not wrap round to the next year because these values are not
	          in the box...

*/
//****************This is from the date.js but the browsers were unable to find it **********************  	
// Add an amount of time to a date. Negative numbers can be passed to subtract time.
Date.prototype.add = function(interval, number) {
	if (typeof(interval)=="undefined" || interval==null || typeof(number)=="undefined" || number==null) { 
		return this; 
	}
	number = +number;
	if (interval=='y') { // year
		this.setFullYear(this.getFullYear()+number);
	}
	else if (interval=='M') { // Month
		this.setMonth(this.getMonth()+number);
	}
	else if (interval=='d') { // Day
		this.setDate(this.getDate()+number);
	}
	else if (interval=='w') { // Weekday
		var step = (number>0)?1:-1;
		while (number!=0) {
			this.add('d',step);
			while(this.getDay()==0 || this.getDay()==6) { 
				this.add('d',step);
			}
			number -= step;
		}
	}
	else if (interval=='h') { // Hour
		this.setHours(this.getHours() + number);
	}
	else if (interval=='m') { // Minute
		this.setMinutes(this.getMinutes() + number);
	}
	else if (interval=='s') { // Second
		this.setSeconds(this.getSeconds() + number);
	}
	return this;
}
//*****************************************************************************************************************
    // Function to allow one JavaScript file to be included by another.
    // Copyright (C) 2006 www.cryer.co.uk
    function includeJS(js)
    {
      document.write('<script type="text/javascript" src="'
        + js + '"></script>'); 
    }
    includeJS('./js/date.js');



function correctHolidayDates(forceUpdate) {
    
    var depMonthFld = document.getElementById("enq_dep_month");
    var depDayFld = document.getElementById("enq_dep_day");
    var retMonthFld = document.getElementById("enq_ret_month");
    var retDayFld = document.getElementById("enq_ret_day");
    //Create String in form d-MMyy i.e. 03-1106 = 3rd November 2006
	
    var depStr = depDayFld[depDayFld.selectedIndex].value + "-" + depMonthFld[depMonthFld.selectedIndex].value;
   	//alert('field types: ' + retMonthFld.type + ' / ' + retDayFld.type);
    if ((retMonthFld.type == 'hidden' && retDayFld.type == 'hidden') || (retMonthFld.type == 'text' && retDayFld.type == 'text')) { 
    	//alert("return fields are not selects");
    	if (retDayFld.value == ""){retDayFld.value = depDayFld[depDayFld.selectedIndex].value;}
    	if (retMonthFld.value == ""){retMonthFld.value = depMonthFld[depMonthFld.selectedIndex].value;}
    	var retStr = retDayFld.value + "-" + retMonthFld.value;
    	//alert("return fields are " + retStr);
    } else {
		var retStr = retDayFld[retDayFld.selectedIndex].value + "-" + retMonthFld[retMonthFld.selectedIndex].value;    	
    }
    
	
	        			       
    if(true == debug) {
        alert("depart " + depStr + " return " + retStr + " Date Version " + Date.$VERSION);
    }
    
    if(false == Date.isValid(depStr, "d-MMyy")) {
        alert("invalid date " + depStr);
        return;
    }                              
        //alert("depart " + depStr + " return " + retStr + " Date Version " + Date.$VERSION);
    
    //var res=document.getElementById("result");
    //res.value=depStr+"  "+retStr;   
   
    var depDate = Date.parseString(depStr, "d-MMyy");
    var retDate = Date.parseString(retStr, "d-MMyy");
    
    earliestDepDate = new Date();
    var tmpDate = earliestDepDate.add("d", minDays);//today+15 days
    
    if(true == debug) {
        alert("Chosen Dep " + depDate); 
        alert("Earliest Dep " + tmpDate);
    }
    
    //First set the date to be minDays from today.
    if(true == depDate.isBefore(tmpDate)) {
        depDate = earliestDepDate;//.add("d", minDays);
        if(true == debug) {
            alert("depDate is now " + depDate);
        }
        var depMonth = tmpDate.format("MMyy");
        var depDay = tmpDate.format("d");
        
        //Can't seem to get this working - declared in validation.js
        //I can!!. You didn't declare a link to validations.js in the header. Neil 2/2/07  
        /*      
        setInputValue(retDayFld, retDay);
        setInputValue(retMonthFld, retMonth);
        */
        /*Use this instead..*/
        var o=depDayFld.options;
		for(var i=0;i<o.length;i++){
			if(o[i].value==depDay){o[i].selected=true;}
			else{o[i].selected=false;}
		}
        o=depMonthFld.options;
		for(i=0;i<o.length;i++){
			if(o[i].value==depMonth){o[i].selected=true;}
			else{o[i].selected=false;}
		}  
		
    }   
    //Now make the return date minimum the day after departure.
    tmpDate = depDate.add("d", 1);
    
    if(true == debug) {
        alert("tmp " + tmpDate.getDate() + " " + tmpDate.getMonthName() + " " + tmpDate.getFullYear());
    }
    
    if(true == retDate.isBefore(tmpDate) || true == forceUpdate) {
        
        retDate = tmpDate;
        var retMonth = tmpDate.format("MMyy");
        var retDay = tmpDate.format("d");
        
        //Can't seem to get this working - declared in validation.js
        //I can!!. You didn't declare a link to validations.js in the header. Neil 2/2/07
        /*
        setInputValue(retDayFld, retDay);
        setInputValue(retMonthFld, retMonth);
        */
        /*Use this instead..*/
        //alert('retMonthFld = [' + retMonthFld.type + ']   retDayFld = [' + retDayFld.type +']');
        if ((retMonthFld.type == 'hidden' && retDayFld.type == 'hidden') || (retMonthFld.type == 'text' && retDayFld.type == 'text')) { 
        	//alert("Setting return to " + retMonth + " " + retDay);
        	retMonthFld.value = retMonth;
        	retDayFld.value = retDay;
        } else {
        	//alert ('return fields not text or hidden');
        	var o=retDayFld.options;
			for(var i=0;i<o.length;i++){
				if(o[i].value==retDay){o[i].selected=true;}
				else{o[i].selected=false;}
			}
        	o=retMonthFld.options;
			for(i=0;i<o.length;i++){
				if(o[i].value==retMonth){o[i].selected=true;}
				else{o[i].selected=false;}
			}
        }
        
        if(true == debug) {
            alert("depart " + retDate.getDate() + " " + retDate.getMonthName() + " " + retDate.getFullYear());
        }
    }
}

/**
	function: unitsChange
	param:	  obj - a select box.
	returns:  nothing.
	does:	  Retrieves the number selected, counts from 
			  1 to maxUnits and gets the name of a "div" that
			  we can hide - the "div" is called "folding#"
			  where "#" is a number.
			  It hides the box, then if the counter is less than
			  or equal to the selected number, it will show the box.

*/

function unitsChange(obj) {
	if(!document.getElementById) {
		return;
	}
	if("units" != obj.id) {
		return;
	}
	var numUnits = obj.options[obj.selectedIndex].value;
	
	if(true == debug) {
		alert("numUnits " + numUnits);
	}
	for(i = 1;i <= maxUnits;i++) {
		var foldingDiv = document.getElementById("folding" + i);
		foldingDiv.style.display = "none";
		if(i <= numUnits) {
			foldingDiv.style.display = "inline";
		}
	}
}


/**
	function: childrenChange
	param:	  obj - a select box.
	returns:  nothing.
	does:	  Retrieves the number selected, counts from 
			  1 to maxChildren and gets the name of a "span" that
			  we can hide - the "span" is called "folding#_?"
			  where "#" is the number of the "units" "div" (above)
			  and "?" is the number of a "span" containing in that "div".
			  It hides the "span", then if the counter is less than
			  or equal to the selected number, it will show that "span".
*/
function childrenChange(obj) {
	if(!document.getElementById) {
		return;
	}
	var numChildren = obj.options[obj.selectedIndex].value;
	
	if(true == debug) {
		alert(obj.id + " value is " + numChildren);
	}
	
	//The following line used "_" but the live Travel Options site uses "."
	//unitNum = parseInt(obj.id.substr(obj.id.indexOf("_") + 1));
	var unitNum = parseInt(obj.id.substr(obj.id.indexOf(".") + 1));
	
	if(isNaN(unitNum)) {
		if(true == debug) {
			alert("unitNum is not a number " + unitNum);
		}
		return
	}
	var str = "folding" + unitNum + "_";
	if(true == debug) {
		alert("str " + str);
	}
	
	for(i = 1;i <= maxChildren;i++) {
		var spanfield = document.getElementById(str + i);
		
		//if you uncomment this you will have to do lots of clicking  - only do it if something is knackered.
		/*if(true == debug) {
			alert("(str) "+ str + "_" + i);
		}
		*/
		
		spanfield.style.display = "none";
		if(i <= numChildren) {
			spanfield.style.display = "inline";		
		}
		
	}
}

/**
	function: 	hideOnLoad
	param:	  	hideChildren - boolean - if the form has "child age" boxes, set to true.
	returns:  	nothing.
	does:	  	loops through the "units" boxes and each of the "children" boxes
				inside a "units" box and hides them all.
				This is because we have to start off with showing all the boxes because
				people may not have javascript so the show / hide thing won't work and
				they need to see everything.
				This function is called after the form with the boxes in.
*/
function hideOnLoad(hideChildren) {
	if(document.getElementById) {
		for(i = 1;i <= maxUnits;i++) {
			if(true == hideChildren) {
			    for(j = 1;j <= maxChildren;j++) {
			    	var foldingChild = document.getElementById("folding" + i + "_" + j);
			    	
			    	
		            //if you uncomment this you will have to do lots of clicking  - only do it if something is knackered.
		            /*if(true == debug) {
		            	alert("(foldingChild) "+ foldingChild + " i " + i + " j " + j);
		            }*/
		        
			    	
			    	foldingChild.style.display = "none";
			    }
			}
			foldingDiv = document.getElementById("folding" + i);
			
			//if you uncomment this you will have to do lots of clicking  - only do it if something is knackered.
		    /*if(true == debug) {
		    	alert("(foldingDiv) "+ foldingDiv + " i " + i);
		    }*/
			
			foldingDiv.style.display = "none";
		}
	}
	
	//Now call the dates function to sort out the earliest departure date
	//correctHolidayDates();
	changeDiv();
}

/*
	function	seatUpgradeSelected
	param		A number used to reference a select box and 2 span elements
	return		nothing
	does		updates the cost fields when someone chooses a seat upgrade
				on the "Seating / Cabin Requirments" page
				The number passed in is used to refer to elements containing the
				selected quantity, the cost per upgrade and the target where the 
				value is output.
*/
function seatUpgradeSelected(num) {
	if(true == debug) {
		alert("seatUpgradeSelected " + num);
	}
	
	//Get the select box
	var selectBox = document.getElementById("enq_av_quantity." + num);
	
	//and quantity
	var selectQty = parseInt(selectBox.options[selectBox.selectedIndex].childNodes[0].nodeValue);
	//if(0 == selectQty || true == isNaN(selectQty)) { //adjusted by Richard 110806 - 16:52
	if(true == isNaN(selectQty) && 0 != selectQty) {
		alert("selectQty isNaN " + selectBox);
		return;	
	}
	
	//Get the corresponding cost field.
	var upgradeCost = parseFloat(document.getElementById("gav_stg_adult_price." + num).childNodes[0].nodeValue);
	
	//Get the placeholder for results
	var upgradeTotal = document.getElementById("gav_stg_avail_text." + num);
	
	//Do the sums
	var total = selectQty * upgradeCost;
	
	if(true == debug) {
		alert("selectQty " + selectQty + " upgradeCost " + upgradeCost + " total " + total);
	}
	
	//Update the placeholder
	upgradeTotal.childNodes[0].nodeValue = total.toFixed(2);
}

/*
	function	insuranceQtySelected
	param		A number used to reference a select box and 2 span elements
	return		nothing
	does		updates the cost fields when someone chooses an insurance package
				on the "Holiday Insurance" page
				The number passed in is used to refer to elements containing the
				selected quantity, the cost per upgrade and the target where the 
				value is output.
*/
function insuranceQtySelected(num) {
	if(true == debug) {
		alert("insuranceQtySelected " + num);
	}
	
	//Get the select box
	var selectBox = document.getElementById("enq_av_quantity." + num);
	
	//and quantity
	var selectQty = parseInt(selectBox.options[selectBox.selectedIndex].childNodes[0].nodeValue);
	//if(false == isNaN(selectQty) && 0 != selectQty) {
	if(false == isNaN(selectQty)) {	
		//Get the corresponding cost field.
		var insuranceCost = parseFloat(document.getElementById("gav_price1." + num).childNodes[0].nodeValue);
		
		//Get the placeholder for results
		var insuranceTotal = document.getElementById("enq_ins_subtotal." + num);
		
		//Do the sums
		var total = selectQty * insuranceCost;
		
		if(true == debug) {
			alert("selectQty " + selectQty + " insuranceCost " + insuranceCost + " total " + total);
		}
	
		//Update the placeholder
		insuranceTotal.childNodes[0].nodeValue = total.toFixed(2);
	}

	//now update the tickbox setting
	updateInsuranceTickBox();
}

/*
	function	updateInsuranceTickBox
	param		nothing
	return		nothing
	does		Loops through each of the select boxes on the "Holiday Insurance"
				page and if all the quantities are set to "0" it will hide the
				paragraph containing the "tick box" for "I Agree to terms & conditions"
*/
function updateInsuranceTickBox() {
	
	//Number of insurance packages returned by our system.
	var numPackages = document.getElementById("numInsurancePackages").value;

	
	var tickBoxPara = document.getElementById("insurance_tick_box");

	//Display the box by default;
	tickBoxPara.style.display = 'block';	

	for(var i = 1;i <= numPackages;i++) {
		//Get the select box
		var selectBox = document.getElementById("enq_av_quantity." + i);
		//and quantity
		var selectQty = parseInt(selectBox.options[selectBox.selectedIndex].childNodes[0].nodeValue);
		
		if(true == debug) {
			alert("selectBox is " + selectBox + " i is " + i + " selected is " + selectQty);
		}
		
		//If the quantity is a non-zero number, we don't hide the box
		if(true != isNaN(selectQty) && 0 != selectQty) {
			return;
		}
	}
	
	//If we got this far we hide the para
	tickBoxPara.style.display = 'none';		
}

/*
	function	insuranceSubmit
	params		none
	return		nothing
	does		returns nothing if insurance box(es) are not ticked
				if they all are then submits form OR if insurance is not selected then
				submits
*/
function validate(form) {
	//Number of insurance packages returned by our system.
	var numPackages = document.getElementById("numInsurancePackages").value;

	for(var i = 1;i <= numPackages;i++) {
		//Get the select box
		var selectBox = document.getElementById("enq_av_quantity." + i);
		//and quantity
		var selectQty = parseInt(selectBox.options[selectBox.selectedIndex].childNodes[0].nodeValue);
		}
	if(!document.add_insurance.booking_cond.checked && 0 != selectQty){
    alert("You must tick the box to agree you have read the Summary of Insurance Cover");
  return false; }
return true;
}

function changeDiv(type) {
	if (type == "submit") {
		document.getElementById("loadingdiv").style.display='inline';
		document.getElementById("loadingdiv").style.visibility='visible';
		timeout()
		//document.getElementById("loadingimg").innerHTML = "<img src=\"http://www.travelcommunications.co.uk/trs/images/loading_circle_07.gif\"><br>Loading.... please wait";	
		//setTimeout('document.images.src="http://www.travelcommunications.co.uk/trs/images/loading_circle_07.gif"', 200);
	} else {
		document.getElementById("loadingdiv").style.display='none';
		document.getElementById("loadingdiv").style.visibility='hidden';
	}
}

function timeout() {
setTimeout("replace()",2);
}

function replace() {
//document.all.repl.innerHTML="<B>New Text</B>";
document.getElementById("loadingimg").innerHTML = "<img src=\"https://www.travelcommunications.co.uk/trs/images/loading_circle_07.gif\"><br>Loading.... please wait";	
} 
//***********************************************************************************************
//********************************New Section ***************************************************
//***********************************************************************************************

	var datesDebug=false;
	//var today = new Date(2007,2,30); 
	var today = new Date();
	//alert("Today is "+today);
	var earliestDepart= today.add("d",minDays); //minDays is 15
	var cYear = earliestDepart.getFullYear();	//Year in YYYY format
	//var cYear = 2008;
	var cMonth =earliestDepart.getMonth();		//Month in mm form where Jan=1, Feb=2 etc
	var cDay = earliestDepart.getDate();		//Date in dd form 
	//alert("cDay is "+cDay);
	var earliestRet = earliestDepart.add("d",1);
//****************** Date Data Arrays *************************************** 	
	var Months= new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var Days = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var CampMonths= new Array("May","June","July","August");
	var CampDays = new Array(31,30,31,31);
	var Camping = false;
//---------------------------Functions----------------------------------------------------------	
	
//***********************************************************************************************
//********************************Called when the page initially loads***************************
//***********************************************************************************************
	function populateDates(camp){
//	alert("Year is : "+cYear+"   Month is : "+cMonth+"  Day is : "+cDay);	
		if(camp == 'true'){
	Camping = true; //camping season dates only
	}
	//alert("Camping is "+Camping);
	//************************Depart Month**********************
	var depMonthBox = document.getElementById("enq_dep_month");	
	populateMonths(depMonthBox,cMonth);//populate options starting with current month
		depMonthBox.options[0].selected=true;//select earliest departure month
	//*****************Depart Date******************************
	var depDateBox=document.getElementById("enq_dep_day");
	if(Camping ==true){cMonth = 4;}
	populateDays(depDateBox,cMonth);
	depDateBox.options[cDay-1].selected=true;//select earliest departure day
		
	if(Camping == false){
	//*****************Return Month*****************************
	var retMonthBox = document.getElementById("enq_ret_month");
	populateMonths(retMonthBox,cMonth);
		retMonthBox.options[0].selected=true;
	//*****************Return Date*****************************
	var retDateBox=document.getElementById("enq_ret_day");
	populateDays(retDateBox,cMonth);
		retDateBox.options[earliestRet.getDate()-1].selected=true;
	//correctHolidayDates();
		}else{
			updateReturnDate();
		}		
	}
//***********************************************************************************************
//********************************Populate just the departure dates******************************
//***********************************************************************************************
	
	function populateDepDates(){
	//**********************Depart Month**************************
	var depMonthBox = document.getElementById("enq_dep_month");	
	populateMonths(depMonthBox,cMonth);//populate options starting with current month
		depMonthBox.options[0].selected=true;//select earliest departure month
	//*********************Depart Date******************************
	var depDateBox=document.getElementById("enq_dep_day");
	populateDays(depDateBox,cMonth);
	depDateBox.options[cDay-1].selected=true;//select earliest departure day
	//correctHolidayDates();
}
//************************************************************************************************	
//******************** Populate the Month options box starting with the current Month*************
//************************************************************************************************
	function populateMonths(dateBox,cM){
	removeOptions(dateBox);	// remove the old options first
	var y = cYear;
	var m = cM;
//	alert("Camping "+Camping);	
	if(false==Camping){
	for (var i=0; i < Months.length;++i){
		m = i+cM;// iteration +currentMonth
		if(m==1 && leap(y)){Days[1]=29;} //if its a leapyear make Feb have 29 days
		if(m>11){m=m-12;y=cYear+1;if(m==1 && leap(y)==1){Days[1]=29;}}//if we go from December to January add 1 to the year				
		dateBox.options[i] = new Option(Months[m]+" "+y,makeDateStr(m,y));
			}
		}else{
	for (var i=0; i < CampMonths.length;++i){
		m = i+4;// iteration +currentMonth
		dateBox.options[i] = new Option(CampMonths[i]+" "+y,makeDateStr(m,y));
			}			
		}
	}
//***********************************************************************************************
//********************************Check if its a leap year **************************************
//***********************************************************************************************
// Returns true if it is.
 	function leap (year) {
		return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
	}
//***********************************************************************************************
//********************************Populate the days of the month***************************
//***********************************************************************************************

	function populateDays(dateBox,month){
		removeOptions(dateBox);	// remove the old options first
		
		var st = new String();
		
		//alert("Month is " + month);	
		for (var i=0; i < Days[month] ;++i){//then set the new ones
			st=(i+1).toString();
			dateBox.options[i] = new Option(st,st);
			//alert('datebox options' + i + '=' + dateBox.options[i].name + '=' + dateBox.options[i].value );
			}	
		//alert('datebox index=' + dateBox.options[dateBox.options.selectedIndex].value);
	}
//***********************************************************************************************
//********************************Remove any existing Options***************************
//***********************************************************************************************
		
	function removeOptions(dateBox){
		//alert("dataBox length is :"+dateBox.length);
		if(dateBox.length > 0 && dateBox.length != null){
			dLength = dateBox.length;
		for (var i=0; i<dLength; i++)
		dateBox.options[i] = null;
		dateBox.options.length=0;
		}
	}
//***********************************************************************************************
//********************************Create a padded string in the format ss***************************
//***********************************************************************************************

	function pad(s){
		if(s.length <2){s="0"+s;}
		return s;
	}
//***********************************************************************************************
//********************************Create a padded string in the format mmyy***************************
//***********************************************************************************************

	function makeDateStr(m,y){
	var st = new String();
	st=(m+1).toString();	//Month m is 0=Jan, 1=Feb etc
	st = pad(st);			//convert the integer month to a string
	st=st+(y.toString().slice(-2));// add the last two digits of the year
	return st;	
	}
//***********************************************************************************************
//********************************Update the Departure and Return Boxes***************************
//***********************************************************************************************
	
	function updateDays(b,type,forceUpdate){
		
		if(b == "dep_date"){
			
			//departure month has changed so update the the number
			//  of days in the month		
			var cM = document.getElementById("enq_dep_month");
			cM = cM.options[cM.options.selectedIndex].value;
			cM = cM.substr(0,2);		//Get the value of the selected option
			populateDays(document.getElementById("enq_dep_day"),cM-1);// set the days to the right number for the month
			//if(type == 'single'){	//If there is no return date i.e. a duration box or a micro break of one or two days
			//	return;
			//	}
			correctHolidayDates(forceUpdate);
		}
		
		if((b == "ret_date") || (b == "dep_date")){// Return Month has changed so update the days
			var cM = document.getElementById("enq_ret_month");
			if ('text' == cM.type || 'hidden' == cM.type) {
				cM = cM.value;
			} else {
				cM = cM.options[cM.options.selectedIndex].value;
				cM = cM.substr(0,2);//Get the value of the return Month
				var retDay=document.getElementById("enq_ret_day");
				//alert("currentMonth = "+cM);
				//alert('retDay name/type:' + retDay.name + '/' + retDay.type);
				populateDays(retDay,cM-1);
				correctHolidayDates(forceUpdate);
			}
		}
		
	}
//***********************************************************************************************
//*************Called when there is a duration box instead of a return date**********************
//***********************************************************************************************
	
	function updateReturnDate(){
	//alert('update return date');
	var r = document.getElementById('Duration');
	var duration = r.options[r.selectedIndex].value;
	//alert("Duration is "+duration);
	var depMonthFld = document.getElementById("enq_dep_month");
    var depDayFld = document.getElementById("enq_dep_day");
    var depDay = depDayFld[depDayFld.selectedIndex].value;
    var depMonth = depMonthFld[depMonthFld.selectedIndex].value;
      //Create String in form d-MMyy i.e. 03-1106 = 3rd November 2006
    var depStr =  depDay+ "-" +depMonth ;
    //Create a Date object
	var depDate = Date.parseString(depStr, "d-MMyy");
	if(datesDebug){
		alert("DepDate is :"+depDate);
	}
	//Add Duration days
	var Return = depDate.add("d",duration);	
		//alert("Return is :"+Return);
	var retDayFld = document.getElementById("enq_ret_day");		//Both these are hidden fields in the html form
	var retMonthFld = document.getElementById("enq_ret_month");
	retMonth= Return.format("MMyy");
    retDay = Return.format("d");
	retDayFld.value = retDay;
	retMonthFld.value = retMonth;
	if(datesDebug){
 	alert("Depart is "+depDay+"  "+depMonth+"  Return is " + retDay + " " + retMonth);	
		}
	}
//***********************************************************************************************
//*************Called to show the departure date**********************
//***********************************************************************************************
	
	function showDepart(){
    var depMonthFld = document.getElementById("enq_dep_month");
    var depDayFld = document.getElementById("enq_dep_day");
    
    var depStr = depDayFld[depDayFld.selectedIndex].value + "-" + depMonthFld[depMonthFld.selectedIndex].value;
       // alert("depart " + depStr);
		
	}

if (document.getElementById('enq_dep_day') != null) {
var t = document.getElementById('enq_dep_day');
	t.setAttribute()
}

function updateTransfersText() {
	if (document.getElementById("enq_requests") != null) {
		var eRequests = document.getElementById("enq_requests");
		
		if (eRequests.checked == 'false') {
			eRequests.value = '';
			eRequests.checked = 'true'
		} else {
			eRequests.value = 'Transfers to/from accommodation not required as making own arrangements';
			eRequests.checked = 'false'
		}
	}
}

function updateCarDetails() {
	//Number of vehicle
	//Either 0 or 1
	var carNumber = document.getElementById("enq_car_qty");
	
	//alert("Vehicle number is : " + carNumber);
	
	if (document.getElementById("vehicledetails") != null) {
		var carDetails = document.getElementById("vehicledetails");
		carDetails.style.display = "none";
		if (carNumber == "1") {
			alert("Car Number is :" + carNumber);
			carDetails.style.display = "block";
		}
	}
}