
function togglebookform() {
	if(document.getElementById('bookingform').style.display=='block') {
		document.getElementById('bookingform').style.display='none';
		/*document.getElementById('searchagainlink').className='searchagainlabelup';*/
		document.getElementById('searchagainbutton').className='searchagainbutton-up';
	}
	else {
		document.getElementById('bookingform').style.display='block';
		/*document.getElementById('searchagainlink').className='searchagainlabeldown';*/
		document.getElementById('searchagainbutton').className='searchagainbutton-down';
	}
}
	
function showdofields() {
				
	var displayval = 'table-row';
	
	//figure out if its IE6 or not and set display to block if it is
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6) {
	  		displayval = 'block';
		}
	}
	
	if (document.carform.diffdo.checked == true) {
		document.getElementById('doruleblock').style.display=displayval;
		document.getElementById('doctryblock').style.display=displayval;
		document.getElementById('docityblock').style.display=displayval;
	}
	else {
		document.getElementById('doruleblock').style.display='none';
		document.getElementById('doctryblock').style.display='none';
		document.getElementById('docityblock').style.display='none';
		
		//they've decided not to drop off in a different city, so set the dropoff fields back to the pickup values
		document.carform.docode.selectedIndex=document.carform.pucode.selectedIndex;
		ColdFusion.navigate('/ajaxsupport/car-citylist_cf.cfm?site=' + document.carform.scode.value + '&lang=' + document.carform.lcode.value + '&docode=' + document.carform.pucode.value + '&pucode=' + document.carform.pucode.value + '&docity=' + document.carform.pucity.value + '&listof=do','docity');
	}
	
}

function showtafields() {
				
	var displayval = 'table-row';
	
	//figure out if its IE6 or not and set display to block if it is
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6) {
	  		displayval = 'block';
		}
	}
	
	if (document.getElementById('agtnameblock').style.display == 'none' || document.getElementById('agtiatablock').style.display == 'none') {
		document.getElementById('agtnameblock').style.display=displayval;
		document.getElementById('agtiatablock').style.display=displayval;
		document.getElementById('agtspacerblock').style.display=displayval;
		document.getElementById('tatoggle').className="tasectiondown";
	}
	else {
		document.getElementById('agtnameblock').style.display='none';
		document.getElementById('agtiatablock').style.display='none';
		document.getElementById('agtspacerblock').style.display='none';
		document.getElementById('tatoggle').className="tasectionup";
	}
	
}

function showassocfields() {
				
	var displayval = 'table-row';
	
	//figure out if its IE6 or not and set display to block if it is
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6) {
	  		displayval = 'block';
		}
	}
	
	if (document.getElementById('assocnameblock').style.display == 'none' || document.getElementById('associdblock').style.display == 'none') {
		document.getElementById('assocnameblock').style.display=displayval;
		document.getElementById('associdblock').style.display=displayval;
		document.getElementById('assoctoggle').className="assocsectiondown";
	}
	else {
		document.getElementById('assocnameblock').style.display='none';
		document.getElementById('associdblock').style.display='none';
		document.getElementById('assoctoggle').className="assocsectionup";
	}
	
}

function showtraveast() {
	
	var displayval = 'table';
	
	//figure out if its IE6 or not and set display to block if it is
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6) {
	  		displayval = 'block';
		}
	}
	
	if (document.getElementById('traveastnotes').style.display == 'none') {
		document.getElementById('traveastnotes').style.display=displayval;
	}
	else {
		document.getElementById('traveastnotes').style.display='none';
	}
	
}

function synccities () {
	if (document.carform.pucode.value == document.carform.docode.value) {
		var i=0;
		var len=document.carform.docity.length;
		while (i<=len) {
			if (document.carform.docity[i].value == document.carform.pucity.value) {
				document.carform.docity.selectedIndex=i;
				break;
			}
			i++;
		}
	}
}

function togglehours(hoursid) {
	
	label = hoursid + 'label';
	
	if (document.getElementById(hoursid).style.visibility!='visible') {
	
		document.getElementById(hoursid).style.visibility='visible';
		document.getElementById(hoursid).style.display='block';
		document.getElementById(label).className='bklochourslabeldown';
		
	}
	else {
	
		document.getElementById(hoursid).style.visibility='hidden';
		document.getElementById(hoursid).style.display='none';
		document.getElementById(label).className='bklochourslabelup';
	}
}


function clearpay(toClear) {
	if (toClear == 'debit') {
		// clear debit fields
		document.carformcheckout.ddname.value='';
		document.carformcheckout.ddaccount.value='';
		document.carformcheckout.ddbank.value='';
		}
	else {
		// clear credit fields
		document.carformcheckout.ccnum.value='';
		document.carformcheckout.cvc.value='';
		document.carformcheckout.ccholder.value='';
		}
	}


function showstate() {
	thisChoice = document.carformcheckout.billcountry.selectedIndex;
	selCountry = document.carformcheckout.billcountry[thisChoice].value;
	
	if (selCountry == 'US'|selCountry == 'CA'|selCountry == 'BR'|selCountry == 'AU'|selCountry == 'ZA') {
		document.getElementById('eurostate').style.visibility='visible';
		document.getElementById('eurostate').style.height='45px';
		document.getElementById('eurostate').style.margin='11px 0px';
		}
	else {
		document.getElementById('eurostate').style.visibility='hidden';
		document.getElementById('eurostate').style.height='0px';
		document.getElementById('eurostate').style.margin='0';
		}

	populateStates(selCountry);

	}

function showstaterow() {
	thisChoice = document.carformcheckout.billcountry.selectedIndex;
	selCountry = document.carformcheckout.billcountry[thisChoice].value;
	
	var displayval = 'table-row';
	
	//figure out if its IE6 or not and set display to block if it is
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6) {
	  		displayval = 'block';
		}
	}
	
	if (selCountry == 'US'|selCountry == 'CA'|selCountry == 'BR'|selCountry == 'AU'|selCountry == 'ZA') {
		document.getElementById('eurostate').style.display=displayval;
		}
	else {
		document.getElementById('eurostate').style.display='none';
		}

	populateStates(selCountry);

	}

function populateStates(thisCountry) {

	switch(thisCountry)
	{
		case 'US':
			var arrNames = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Palau","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming","-------","Armed Forces Africa","Armed Forces Americas","Armed Forces Canada","Armed Forces Europe","Armed Forces Middle East","Armed Forces Pacific","American Samoa","Federated States of Micronesia","Guam","Marshall Islands","Northern Mariana Islands","Virgin Islands");
			var arrCodes = new Array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PW","PA","PR","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","-","AE","AA","AE","AE","AE","AP","AS","FM","GU","MH","MP","VI");
			break;
			
		case 'CA':
			var arrNames = new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland and Labrador","Nova Scotia","Northwest Territories","Nunavut","Ontario","Prince Edward Island","Québec","Saskatchewan","Yukon");
			var arrCodes = new Array("AB","BC","MB","NB","NL","NS","NT","NU","ON","PE","QC","SK","YT");
			break;

		case 'AU':
			var arrNames = new Array("New South Wales","Northern Territory","Queensland","South Australia","Tasmania","Victoria","Western Australia","Australian Capital Territory");
			var arrCodes = new Array("NSW","NT","QLD","SA","TAS","VIC","WA","ACT");
			break;

		case 'BR':
			var arrNames = new Array("Acre","Alagoas","Amapá","Amazonas","Bahia","Ceará","Distrito Federal","Espírito Santo","Goiás","Maranhão","Mato Grosso","Mato Grosso do Sul","Minas Gerais","Pará","Paraíba","Paraná","Pernambuco","Piauí","Rio de Janeiro","Rio Grande do Norte","Rio Grande do Sul","Rondônia","Roraima","Santa Catarina","São Paulo","Sergipe","Tocantins");
			var arrCodes = new Array("AC","AL","AP","AM","BA","CE","DF","ES","GO","MA","MT","MS","MG","PA","PB","PR","PE","PI","RJ","RN","RS","RO","RR","SC","SP","SE","TO");
			break;

		case 'ZA':
			var arrNames = new Array("Eastern Cape","Free State","Gauteng","KwaZulu-Natal","Limpopo","Mpumalanga","North West","Northern Cape","Western Cape");
			var arrCodes = new Array("EC","FS","GP","KZ","LP","MP","NW","NC","WC");
			break;

		default:
			var arrNames = new Array("");
			var arrCodes = new Array("");
	}

	//zero out billstate menu
	document.carformcheckout.billstate.options.length = 0;

	//if arrNames len gt 0, rebuild billstate menu
	if (arrNames.length > 0) {
		for (i=0; i<arrNames.length; i++){
			document.carformcheckout.billstate.options[document.carformcheckout.billstate.options.length] = new Option(arrNames[i],arrCodes[i],false,false);
		}
	}
}



function checklocs() {
	if	(document.carform.puloc & document.carform.doloc) {
		if (typeof(document.carform.puloc.length) == "undefined") document.carform.puloc.click(); // length attributed doesn't work if only 1 item in radio group
		if (typeof(document.carform.doloc.length) == "undefined") document.carform.doloc.click();
	}
}

//legacy pop-up handler
function openWindow(url, name) {
  popupWin = window.open(url, name, 'menubar,scrollbars,resizable,width=325,height=460,left=0,top=0')
}

//legacy pop-up handler
function openProdWindow(url, name, wide, high) {
  popupWin = window.open(url, name, 'menubar,scrollbars,resizable,width='+wide+',height='+high+',left=0,top=0')
}

//auto select drop-off location if possible
function seldoloc(dolocid) {
	if (document.getElementById(dolocid) != null) {
		document.getElementById(dolocid).checked = true;
	}
}

//auto select drop-off location revised
function doLocMatch(locData,locType,locCount) {
	
	temp = flagChosen(locData,'puloc');
	
 	if (locCount != 0) { //only run if there are corresponding locs to match
		var locList = locData.value;  
		var locArray = locList.split(","); //array of locids to match
		
		for (var x=1; x<=locCount; x++) {
			var testElement = "doloc_" + locType + x; //id to match
			
			if (document.getElementById(testElement) != null) {
				var doLocString = document.getElementById(testElement).value;
				for(var i=0; i<locArray.length; i++){
					
					if (doLocString.search(locArray[i]) != -1) {
						document.getElementById(testElement).checked = true;
						temp = flagChosen(testElement,'doloc');
						x = locCount + 1; //end outer loop
						break;
					}
				}
			}				
		}
	}
}


function flagChosen(thisNode,colType) {
	var dbName = document.getElementsByName(colType);
	lenDName = dbName.length;
	for(var j = 0; j < lenDName; j++) {
		var itemID = dbName[j].id;
		if(dbName[j].checked == false) {
			document.getElementById(itemID).parentNode.parentNode.setAttribute("class", "bklocblock");
		}
		
		else {
			document.getElementById(itemID).parentNode.parentNode.setAttribute("class", "bklocblockChosen");
		}
	}
}


//auto select drop-off location revised again (the only difference between this function and doLocMatch is that this one calls the flagChosenById function instead of the old flagChosen function.)
function doLocMatchById(locData,locType,locCount) {
	
	temp = flagChosenById(locData,'puloc');
	
 	if (locCount != 0) { //only run if there are corresponding locs to match
		var locList = locData.value;  
		var locArray = locList.split(","); //array of locids to match
		
		for (var x=1; x<=locCount; x++) {
			var testElement = "doloc_" + locType + x; //id to match
			
			if (document.getElementById(testElement) != null) {
				var doLocString = document.getElementById(testElement).value;
				for(var i=0; i<locArray.length; i++){
					
					if (doLocString.search(locArray[i]) != -1) {
						document.getElementById(testElement).checked = true;
						temp = flagChosenById(testElement,'doloc');
						x = locCount + 1; //end outer loop
						break;
					}
				}
			}				
		}
	}
}


function flagChosenById(thisNode,colType) {
	var dbName = document.getElementsByName(colType); 
	lenDName = dbName.length;
	for(var j = 0; j < lenDName; j++) {
		var itemID = dbName[j].id;
		divID = "div_" + itemID;
		
	
		if(dbName[j].checked == false) {
			/*document.getElementById(itemID).parentNode.parentNode.setAttribute("class", "bklocblock");*/
			document.getElementById(divID).setAttribute("class", "bklocblock");
		}
		
		else {
			/*document.getElementById(itemID).parentNode.parentNode.setAttribute("class", "bklocblockChosen");*/
			document.getElementById(divID).setAttribute("class", "bklocblockChosen");
			
		}
	}
}
