	function wctShow(bid) {
		if (document.getElementById) {
			document.getElementById("HotelsContainer").style.display = "none";
			document.getElementById("AirContainer").style.display = "none";
			document.getElementById("CarsContainer").style.display = "none";
			document.getElementById("PackagesContainer").style.display = "none";
			document.getElementById("LastMinuteContainer").style.display = "none";
			document.getElementById(bid).style.display = "block";
		} else if (document.all) {
			document.all["HotelsContainer"].style.display = "none";
			document.all["AirContainer"].style.display = "none";
			document.all["CarsContainer"].style.display = "none";
			document.all["PackagesContainer"].style.display = "none";
			document.all["LastMinuteContainer"].style.display = "none";
			document.all[bid].style.display = "block";
		}
	}

		function updEDate(arr, frm, edate) {
			var oneDay = 1000 * 60 * 60 * 24;
	
			var dpt = eval('document.' + frm + '.' + edate);
			
			if (arr.value.length > 0 && fmtDate(arr, '-')) {
				//if (dpt.value.length == 0) { 
				var sString = arr.value.split("-");
				var myDate = new Date(sString[2],sString[0]-1,sString[1]);
				
				var newDay = new Date();
				newDay.setTime(myDate.getTime() + 2 * oneDay);
	
				var theMonth = 1 + newDay.getMonth(); // zero-based, remember?
				var theDay   = newDay.getDate();
				var str = "";

				if (theMonth < 10) str += "0";
					str += theMonth;
					str += "-";
				if(theDay < 10) str += "0";
					str += theDay;
					str += "-" + newDay.getFullYear();
			
				//alert(str);
				dpt.value = str;
				
			//}
			}
		}
		
	function chkRates(){
		document.listsearch.checkrates.checked = true;
	}
	//for hotels

	function updateDtField(frm,fld,id){
		str = document.getElementById("monthdropdown"+id).value +'-'+document.getElementById("daydropdown"+id).value +'-'+document.getElementById("yeardropdown"+id).value;
		frm.fld.value = str;
	}
	
	function trim(str) {
		var	str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length;
		while (ws.test(str.charAt(--i)));
		return str.slice(0, i + 1);
	}
	
	/* If we change the Month and it's a month that has passed, lets assume that they want next year */
	function changeFromMonth(obj, tab) {
		var d = new Date();
		
		switch(tab) {
			case 'air':
				if (obj.value < (d.getMonth() + 1)) {
					document.getElementById('yeardropdown222').value = d.getFullYear() + 1;
					document.getElementById('yeardropdown333').value = d.getFullYear() + 1;
				} else {
					document.getElementById('yeardropdown222').value = d.getFullYear();
					
					/* If the departure month is this month or later, set the year back to this year
						Otherwise just leave it alone... */
					if (document.getElementById('monthdropdown333').value >= (d.getMonth() + 1)) {
						document.getElementById('yeardropdown333').value = d.getFullYear();
					}
				}
				break;
			case 'car':
				if (obj.value < (d.getMonth() + 1)) {
					document.getElementById('yeardropdown444').value = d.getFullYear() + 1;
					document.getElementById('yeardropdown555').value = d.getFullYear() + 1;
				} else {
					document.getElementById('yeardropdown444').value = d.getFullYear();
					
					/* If the departure month is this month or later, set the year back to this year
						Otherwise just leave it alone... */
					if (document.getElementById('monthdropdown444').value >= (d.getMonth() + 1)) {
						document.getElementById('yeardropdown555').value = d.getFullYear();
					}
				}
				break;
		}
	}
	function changeToMonth(obj, tab) {
		var d = new Date();
		
		switch(tab) {
			case 'air':
				if (obj.value < (d.getMonth() + 1)) {
					document.getElementById('yeardropdown333').value = d.getFullYear() + 1;
				} else {
					document.getElementById('yeardropdown333').value = d.getFullYear();
				}
				break;
			case 'car':
				if (obj.value < (d.getMonth() + 1)) {
					document.getElementById('yeardropdown555').value = d.getFullYear() + 1;
				} else {
					document.getElementById('yeardropdown555').value = d.getFullYear();
				}
				break;
		}
	}
	
	
	
	// for firefox, when form loads with preexisting data
	$(document).observe('load',function () {
		var d;
		d = document.getElementsByName('children');
		if (d.length) updateChildren(d[0],'hotel');
		d = document.getElementsByName('numchild');
		if (d.length) updateChildren(d[0],'air');
	});
	
	function updateChildren(selObj,tab){
		var div,imgDiv,td,numChildren,selecty,useFormName,opty;
		
		var childAgeFormName;
		if (tab=='hotel') childAgeFormName = 'childAge';
		else if (tab=='air') childAgeFormName = 'minorsAge';
		else return false;
		var minAge = 2;
		var maxAge = 17;
		var formNameUseInt = (tab=='air');
		
		//formNameUseInt = true;
		
		var tabs = new Array('hotel','air');
		/*for (var i in tabs) {
			div = document.getElementById('childDiv_'+tabs[i]);
			if (!div) continue;
			div.style.display = 'none';
		}*/
		
		// not a select object
		if (typeof(selObj.selectedIndex)=='undefined') return false;
		
		numChildren = selObj.options[selObj.selectedIndex].value;
		if (!numChildren) return false;
			
		div = document.getElementById('childDiv_'+tab);
		if (!div) {
			//alert('nodiv');
			return false;
		}
		td = div.getElementsByTagName('td');
		if (!td.length) {
			//alert('notd');
			return false;
		}
		td = td[1];
		if (td.className!='padSelects') {
			//alert('nopadSelects');
			return false;
		}
		
		td.innerHTML = '';
		
		// hide image div
		imgDiv = div.parentNode.getElementsByTagName('div');
		if (imgDiv.length) {
			imgDiv = imgDiv[1];
			imgDiv.style.display = 'none';
		}
		else imgDiv = null;
		
		// 0 children
		if (selObj.options[selObj.selectedIndex].value=='0') {
			div = document.getElementById('childDiv_'+tab);
			if (!div) return false;
			div.style.display = 'none';
			if (imgDiv) imgDiv.style.display = 'block';
			return false;
		}
		
		for (var i=1; i<=numChildren; i++) {
			selecty = document.createElement('select');
			useFormName = childAgeFormName;
			if (formNameUseInt) useFormName += (i-1);
			selecty.name = useFormName;
			for (o=minAge; o<=maxAge; o++) {
				selecty.options[selecty.options.length] = new Option(o,o);
			}
			selecty.options[0].selected = true;
			td.appendChild(selecty);
		}
		// make div visible
		div.style.display = 'block';		
	}
	
	
	
	
	function validateWCTForm(obj) {
		var errMsg = '', fmtMsg = '', reqMsg = '', sDate = new Date(), eDate = new Date();
		with(obj) {
			switch(obj.name) {
				case 'resrvForm':
					sDate.setFullYear(doa_yy.value);
					sDate.setMonth(doa_mm.value - 1, doa_dd.value);
					
					if (sDate.getFullYear() != doa_yy.value
							|| (sDate.getMonth() + 1) != doa_mm.value
							|| sDate.getDate() != doa_dd.value) {
						fmtMsg += '    The Arrival Date is Invalid\n';
					} else {
						eDate.setFullYear(doa_yy.value);
						eDate.setMonth(doa_mm.value - 1, parseInt(doa_dd.value) + parseInt(wctNumNights.value));
					
						if (sDate >= eDate) {
							fmtMsg += '    Check In Date must be before the Check Out Date\n';
						}
					}
					break;
				case 'airSearchForm':
					sDate.setFullYear(dateLeavingYear.value);
					sDate.setMonth(dateLeavingMonth.value - 1, dateLeavingDay.value);
					eDate.setFullYear(dateReturningYear.value);
					eDate.setMonth(dateReturningMonth.value - 1, dateReturningDay.value);
					
					if (sDate.getFullYear() != dateLeavingYear.value
							|| (sDate.getMonth() + 1) != dateLeavingMonth.value
							|| sDate.getDate() != dateLeavingDay.value) {
						fmtMsg += '    The Departure Date is Invalid\n';
					} else {
						if (sDate >= eDate) {
							fmtMsg += '    Departure Date must be before the Returning Date\n';
						}
					}
					
					if (eDate.getFullYear() != dateReturningYear.value
							|| (eDate.getMonth() + 1) != dateReturningMonth.value
							|| eDate.getDate() != dateReturningDay.value) {
						fmtMsg += '    The Returning Date is Invalid\n';
					}
					
					if (leavingFrom.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '').length == 0) {
						reqMsg += '    You must specify a From City or Airport\n';
					}
					break;
				case 'autoSearchForm':
					sDate.setFullYear(pu_year.value);
					sDate.setMonth(pu_month.value - 1, pu_day.value);
					eDate.setFullYear(do_year.value);
					eDate.setMonth(do_month.value - 1, do_day.value);
					
					if (sDate.getFullYear() != pu_year.value
							|| (sDate.getMonth() + 1) != pu_month.value
							|| sDate.getDate() != pu_day.value) {
						fmtMsg += '    The Pick-Up Date is Invalid\n';
					} else {
						if (sDate >= eDate) {
							fmtMsg += '    Pick-Up Date must be before the Drop-Off Date\n';
						}
					}
				
					if (eDate.getFullYear() != do_year.value
							|| (eDate.getMonth() + 1) != do_month.value
							|| eDate.getDate() != do_day.value) {
						fmtMsg += '    The Drop-Off Date is Invalid\n';
					}
					
					if (puair.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '').length == 0) {
						reqMsg += '    You must specify an Airport Code\n';
					}
					break;
			}
		}
		if ((reqMsg.length + fmtMsg.length) != 0) {
			errMsg = 'This search cannot be submitted at this time!\n\n';
			if (reqMsg.length > 0)
				errMsg += 'The following fields are required!\n' + reqMsg + '\n';
			
			if (fmtMsg.length > 0)
				errMsg += 'The following information is invalid!\n' + fmtMsg + '\n';
			
			alert(errMsg);
			return false;
		}
		initializeWCTDates(sDate, eDate);
		return true;
	}
  
function init_date_originations() {
	var orig = document.date.in_origination_key;
	var i = 0;
	for (o in originations) {
		orig.options[i] = new Option(originations[o], o); 
		i++;
	}
	var idx = 0;
	i = 0;
	for (k in originations) {
		if (k == 371)
			break;
		i++;
	}
	orig.selectedIndex = i;
}

function initform(form) {
		init_date_originations();
        var ds = document.date.in_start_date;
        var de = document.date.in_end_date;

        ds.options[0] = new Option('This weekend', '1204956000,');
        de.options[0] = new Option('This weekend', '1205042400,1205125200,1205211600,1205298000');

        if (!nnw)
                ds.options[1] = new Option('Next Weekend', '1205557200,');

        var i = (nnw) ? 1 : 2; 
        for (var j = 0; j < starts.length; i++, j++) {				
                ds.options[i] = new Option(starts[j].v, starts[j].t);
        }
        de.selectedIndex = 0;
}

function setWctCheckOut(numDays,id,fldid){
	//alert('here');
	//alert('id = '+ id);
	
	var m = document.getElementById('monthdropdown'+id).value;
	var d = document.getElementById('daydropdown'+id).value;
	var y = document.getElementById('yeardropdown'+id).value;
	
	var chkInDate = new Date();
	chkInDate.setYear(y);
	chkInDate.setMonth(m-1); //month is zero based 
	chkInDate.setDate(d);	
	
	var chkOutDate;				
	var t = chkInDate.getTime();
	//alert('chkInDate = ' + chkInDate);
	//alert('numDays = ' + numDays);
	chkOutDate = chkInDate.getTime() + 1000 * 60 * 60 * 24 * numDays;	
	//alert('chkOutDate = ' + chkOutDate)
	var chkOut = new Date(chkOutDate);
	//alert('chkOut = '+ chkOut);
	
	try {
		document.getElementById('dod_mm').value = (chkOut.getMonth() + 1);
		document.getElementById('dod_dd').value = chkOut.getDate();
		document.getElementById('dod_yy').value = chkOut.getFullYear();
	} catch(err) {}
	
	//alert('fldid = ' + fldid);
	document.getElementById(fldid).value = (chkOut.getMonth() + 1)+"-"+chkOut.getDate()+"-"+chkOut.getFullYear();
	
	//alert(document.getElementById('dod_dd').value +'-'+document.getElementById('dod_mm').value +'-'+document.getElementById('dod_yy').value);

}

// to redirect to 4hr car advanced search page
function go() {
   var destination = document.autoSearchForm.puwhere.value;
   var re = new RegExp('CarRequest');
   var m = re.exec(destination);
   if (m != null) {
	   //location.target = "_top";
	   top.location.href = destination;
   } else {
	   return false;
   }
}


function getChildAgesFtr(maxChildren,defaultValue){
	var arr = new Array();
	var dd = '';
	for (var i = 0; i < maxChildren; i++){
		dd = getChildDDFtr(i);
		if (dd){
			arr.push(dd.options[dd.selectedIndex].value);
		}
		else
			arr.push(defaultValue);
	}
	return arr;
}

function newChildDDFtr(id,selValue){
	var s = document.createElement('SELECT');
	s.id = id;
	s.name = 'childageselect';
	for (var i= 1; i < 18; i++){
		var o = new Option();
		o.text = i;
		o.value = i;
		s.options[s.options.length] = o;
	}
	if(selValue)
		s.selectedIndex = selValue-1;
	return s;
}

function getChildDDFtr(childnum){
	return document.getElementById('childage_' + (childnum));
}

function updateChildrenFtr(){
	var numChildren = 0;
	var row = document.getElementById('childage_rowv2');
	var cell = document.getElementById('childage_cellv2');

	numChildren = document.resrvForm.numchild.options[document.resrvForm.numchild.selectedIndex].value;

	var agearray = getChildAgesFtr(numChildren,12);

	//Clear Display and hide row
	row.style.display = 'none';
	cell.innerHTML = '';

	//Get Number of children and create dropdowns where necessary
	for (var i = 0; i < numChildren; i++){
		row.style.display = '';
		dd = newChildDDFtr('childage_' + i,agearray[i]);
		cell.appendChild(dd);
		cell.innerHTML += '&nbsp;&nbsp;&nbsp;';
	}
}

function formatDate(date){
	var d = new Date(date);
	var day = d.getDate();
	var month = d.getMonth() + 1;
	var year = d.getFullYear();
	
	return month + "/" + day + "/" + year;
}