s_userAgent = window.navigator.userAgent
KON = (s_userAgent.indexOf("KHTML")>-1) ? 1 : 0;
isMac = (navigator.userAgent.indexOf("Mac")>-1) ? 1 : 0;
isIE = (navigator.userAgent.indexOf("MSIE")>-1) ? 1 : 0;
isMacIE = (isMac&&isIE) ? 1 : 0;
navTimer = null;
currentNav = 0;


/* cannonball functions HH */
/* sync cannonball nav and cannonaball form */
function cbSetUpnav(){
	a_nav = document.cbNav.nav
	if(!a_nav.length) o_nav = document.cbNav.nav;
	else for(i=0;i<a_nav.length;i++) if(a_nav[i].checked) o_nav = a_nav[i];
	
	cb_ChangeNav( o_nav, o_nav.parentNode);
}

/* Set the default tab based on cookie DDA */
function onLoadSetTabFromCookie()
{
	var tabname = GetCookie("CurrentTab");
	if (tabname){
		//alert("cookie found: " + tabname);
		// Hide all of them
		var a_lis = document.getElementsByName("nav");
		for(i=0;i<a_lis.length;i++){
			//alert(a_lis[i].value);
			if (a_lis[i].value == tabname) cb_ChangeNav(a_lis[i],a_lis[i].parentNode);
		} 
	}
}

/* change cannonball */
function cb_ChangeNav(o_radio, o_span){
	//alert("set cookie: " + o_radio.value);
	var exp = new Date();
	var oneday = exp.getTime() + (1 * 24 * 60 * 60 * 1000);
	exp.setTime(oneday);

	SetCookie("CurrentTab",o_radio.value,exp,"/");
	o_li = o_span.parentNode;
	o_ul = o_li.parentNode;
	a_lis = o_ul.getElementsByTagName("li");
/* If i am displayed kill the click */	
	//alert("cb_"+o_radio.value);
	if(document.getElementById("cb_"+o_radio.value).style.display == "block") return false;
	for(i=0;i<a_lis.length;i++){
			a_lis[i].firstChild.className="";
			document.getElementById("cb_"+a_lis[i].firstChild.firstChild.value).style.display = "none";
	}
	o_li.firstChild.className = "cbNavon";
	o_radio.checked = true;
	s_radio = o_radio.value
	document.getElementById("cb_"+s_radio).style.display = "block";
	/* DANDERSON 10/28/04: Added return to skipped rest of this function */
	return false;
	switch(s_radio){
		case "formFO":
			document.getElementById("h_formFOto").name = "tt1";
			document.getElementById("h_formFOhp").name = "tt2";			
			cb_bff(document.formFO);
			childAges(document.getElementById("FO_children"),'cbFOchildages')
		break;
		case "formFH":
			childAges(document.getElementById("FH_children"),'cbFHchildages')
		break;
		case "formHO":
			cb_destination(eval("document."+s_radio));
		break;
		case "formFRT":
			cb_SSA(document.formFRT.pref_aln[0]);
			cb_bff(document.formFRT);
			childAges(document.getElementById("FRT_children"),'cbFRTchildages')
		break;
		case "formFOW":
			cb_SSA(document.formFOW.pref_aln[0]);
			cb_bff(document.formFOW);
			childAges(document.getElementById("FOW_children"),'cbFOWchildages')
		break;
		case "formFMD":
			cb_SSA(document.formFMD.pref_aln[0]);
			childAges(document.getElementById("FMD_children"),'cbFMDchildages')
		break;
		default:
	}
	if(isMacIE) fixMacIEselect("cb_"+o_radio.value,o_radio);
	return false;
}
/* get MousePos for calendar */
function getMousePos(evt) {
	if (window.event) {
		s_srcElement = window.event.srcElement.nodeName;
//Safari will set the clienty of an event from a form input to the form offset
		yPos= (s_srcElement=="INPUT" && KON) ? Math.abs(window.event.offsetY)+10 : window.event.clientY - 5;
	} else if(document.getElementById&&!document.all){
		xPos = evt.clientX+165;
		yPos = evt.clientY-5;
	}else{
		xPos=50
		yPos=50
	}
}
/* get which form was clicked */
function getCBform(){
	for(i=0;i<document.cbNav.nav.length;i++){
		if(document.cbNav.nav[i].checked) s_form = document.cbNav.nav[i].value
	}
	return s_form;
}
/* parse date for start date */
function parseCalDate(o_input){
	o_dateinput = eval("document."+getCBform()+"."+o_input);
	s_dateinput = o_dateinput.value;
	if(s_dateinput.indexOf("/")>-1)	a_dateinput = s_dateinput.split("/")
	return a_dateinput;
}

/* maintain state between cannonball forms */
function maintainState(o_input){
		a_bit = o_input.id.split("_");
		s_bit = a_bit[1];
		for(i=0;i<document.cbNav.nav.length;i++){
			a_formbit = document.cbNav.nav[i].value.split("form");
			s_formbit = a_formbit[1];
			o_formelement = document.getElementById(s_formbit+"_"+s_bit);	
			if(eval("document."+document.cbNav.nav[i].value)&&o_formelement!=o_input){
				if(o_formelement&&o_formelement!=o_input && o_input.type!="radio"){
					(o_formelement.type=="select-one" &&o_formelement.length>o_input.selectedIndex) ?  o_formelement.selectedIndex=o_input.selectedIndex : o_formelement.value=o_input.value;
				}else{
					a_input = eval("document."+document.cbNav.nav[i].value+"."+o_input.name);
					if(a_input) for(j=0;j<a_input.length;j++)if(a_input[j]!=o_input&&a_input[j].value==o_input.value)a_input[j].checked="checked";
				}
			}
		}
	}

/* request ages of children */
function childAges(o_select,s_div){
	o_div = document.getElementById(s_div)
	if(o_select.selectedIndex!=0){
		if(s_div=="cbFOchildages") document.getElementById("cbFOpromo").style.display = "none";
		if(s_div=="cbFHchildages") document.getElementById("cbFHpromo").style.display = "none";
		a_children = o_div.getElementsByTagName("div")
		o_div.style.display = "block";
//		for(i=0;i<a_children.length;i++) a_children[i].style.visibility = "hidden";
		for(i=0;i<a_children.length;i++) a_children[i].style.visibility = (i<o_select.selectedIndex) ? "visible" : "hidden";
	}else{
		if(s_div=="cbFOchildages"&&document.getElementById("cbFOpromo")) document.getElementById("cbFOpromo").style.display = "block";
		if(s_div=="cbFHchildages"&&document.getElementById("cbFHpromo")) document.getElementById("cbFHpromo").style.display = "block";
		o_div.style.display = "none";
	}
}
/* search specific air */
function cb_SSA(o_input){
	o_form = o_input.form;
	s_input = o_input.name
	a_input = eval("o_form."+s_input);
	for(i=0;i<a_input.length;i++) if(a_input[i].checked)o_input=a_input[i];
	o_ul = o_input.parentNode.parentNode;
	a_li = o_ul.getElementsByTagName("li")
	s_display = (o_input.value=="spec") ? "block" : "none";
	for(i=0;i<a_li.length;i++)if(a_li[i].className=="specificair")a_li[i].style.display = s_display;
}
/* best fare finder for FOform only*/
function cb_bff(o_form){
	s_radio = "";
	a_formbits = o_form.name.split("form");
	s_formbit = a_formbits[1];
	a_radio = (o_form.name=="formFOW")? o_form.module:o_form.SearchMethod;
	for(i=0;i<a_radio.length;i++)if(a_radio[i].checked){
		s_radio = a_radio[i].value;
		o_radio = a_radio[i]
	}
	if(s_radio=="tripsrch")s_radio="LowFareByDate";
	if(s_radio=="calendar")s_radio="BestFareFinder";
	switch(s_radio){
		case "LowFareByDate":
			document.getElementById(s_formbit+"_fromcal").style.display = "inline"
			document.getElementById("cb"+s_formbit+"bff").style.display = "none";
			switch(s_formbit){
				case "FO":
				document.getElementById(s_formbit+"_tocal").style.visibility = "visible"; 
				document.getElementById("FO_fromcal2").style.display = "block";
				document.getElementById("FO_fromcal3").style.display = "block";
				document.getElementById("FO_fromcal4").style.display = "block";
				document.getElementById("cbSubmitText").style.display = "block";
				document.getElementById("FHbutton").style.display = "block";			
				break;
				case "FRT":
				document.getElementById(s_formbit+"_tocal").style.visibility = "visible"; 
				o_form.module.value = "tripsrch";
				document.getElementById("cbFRTmsg").style.visibility = "visible";
				break;	
				default:
			}				
			if(document.getElementById("cb"+s_formbit+"nobff"))document.getElementById("cb"+s_formbit+"nobff").style.display = "inline";
			if(document.getElementById("cb"+s_formbit+"promo"))document.getElementById("cb"+s_formbit+"promo").style.visibility = "visible";					
		break;
		case "BestFareFinder":
			switch(s_formbit){
				case "FO":
					document.getElementById(s_formbit+"_tocal").style.visibility = "hidden";			
					document.getElementById("FO_fromcal2").style.display = "none";
					document.getElementById("FO_fromcal3").style.display = "none";
					document.getElementById("FO_fromcal4").style.display = "none";

					document.getElementById("cbSubmitText").style.display = "none";
					document.getElementById("FHbutton").style.display = "none";			
				break;
				case "FRT":
					o_form.module.value = "calendar";
					document.getElementById(s_formbit+"_tocal").style.visibility = "hidden";
					document.getElementById("cbFRTmsg").style.visibility = "hidden";								
					if(o_form.FRT_addHot.checked)o_form.FRT_addHot.checked=false;
					addHotel(o_form.FRT_addHot);
				break;	
				default:
			}
			document.getElementById("cb"+s_formbit+"bff").style.display = "inline"
			document.getElementById(s_formbit+"_fromcal").style.display = "none";			
			if(isMacIE) fixMacIEselect("cb_"+o_form.name,o_radio);
			if(document.getElementById("cb"+s_formbit+"nobff"))document.getElementById("cb"+s_formbit+"nobff").style.display = "none";
			if(document.getElementById("cb"+s_formbit+"promo"))document.getElementById("cb"+s_formbit+"promo").style.visibility = "hidden";							
		break;
		default:
	}
}
function addHotelFO(o_form){
if(checkform(o_form,1,2,3,4,5,6)){
	document.getElementById("h_formFOto").name = "trip_option";
	document.getElementById("h_formFOhp").name = "htl_pkgs";
	document.formFO.submit();
}else{return false}
}
function addHotel(o_input){
	o_form = o_input.form;
	switch (o_input.checked){
	case true:
		o_form.trip_option.value = "fltplushotel";
		o_form.htl_pkgs.disabled = false;
		o_form.action = o_form.fhaction.value;
		document.getElementById("FRT_from").name = "inp_dep_arp_cd_1";
		o_frommonth = document.getElementById("FRT_frommonth");
		o_frommonth.name = "leaveMonth";
		o_frommonth[o_frommonth.selectedIndex].value = o_frommonth.selectedIndex + 1;
		document.getElementById("FRT_frommonth").selectedIndex
		document.getElementById("FRT_fromdate").name = "inp_dep_dt_dy_1";
		document.getElementById("FRT_fromtime").name = "inp_dep_tm_1";
		document.getElementById("FRT_to").name = "inp_arr_arp_cd_1";
		o_tomonth = document.getElementById("FRT_tomonth");
		o_tomonth.name = "returnMonth";
		o_tomonth[o_tomonth.selectedIndex].value = o_tomonth.selectedIndex + 1;
		document.getElementById("FRT_todate").name = "inp_ret_dep_dt_dy";
		document.getElementById("FRT_totime").name = "inp_ret_dep_tm";
		document.getElementById("FRT_adults").name = "inp_adult_pax_cnt";
		document.getElementById("FRT_children").name = "inp_child_pax_cnt";
		document.getElementById("FRT_seniors").name = "inp_senior_pax_cnt";
		document.getElementById("FRT_con").name = "inp_num_cnx";
	break;
	default:
		o_form.trip_option.value = "roundtrp";
		o_form.htl_pkgs.disabled = true;
		o_form.action = o_form.rtaction.value;
		document.getElementById("FRT_from").name = "dep_arp_cd(1)";
		o_frommonth = document.getElementById("FRT_frommonth");
		o_frommonth.name = "dep_dt_mn_1";
		o_frommonth[o_frommonth.selectedIndex].value = o_frommonth[o_frommonth.selectedIndex].text;
		document.getElementById("FRT_fromdate").name = "dep_dt_dy_1";
		document.getElementById("FRT_fromtime").name = "dep_tm_1";
		document.getElementById("FRT_to").name = "arr_arp_cd(1)";
		o_tomonth = document.getElementById("FRT_tomonth");
		o_tomonth.name = "dep_dt_mn_2";
		o_tomonth[o_tomonth.selectedIndex].value = o_tomonth[o_tomonth.selectedIndex].text;
		document.getElementById("FRT_todate").name = "dep_dt_dy_2";
		document.getElementById("FRT_totime").name = "dep_tm_2";
		document.getElementById("FRT_adults").name = "adult_pax_cnt";
		document.getElementById("FRT_children").name = "chld_pax_cnt";
		document.getElementById("FRT_seniors").name = "senior_pax_cnt";
		document.getElementById("FRT_con").name = "num_cnx";
	}
}
function cb_destination(o_form){
	s_radio = "";
	for(i=0;i<o_form.searchoption.length;i++)if(o_form.searchoption[i].checked)s_radio = o_form.searchoption[i].value;
	switch(s_radio){
		case "USorCA":
			document.getElementById("cbHOstate").style.visibility = "visible";
			document.getElementById("HO_to").name = "city";
			o_form.searchMode.value = "city";
			//o_form.mode.value = "1";
		break;
		default:
			document.getElementById("cbHOstate").style.visibility = "hidden";
			document.getElementById("HO_to").name = "airport";
			o_form.searchMode.value = "airport";
			//o_form.mode.value = "2";
	}
	return false;
}
function cb_specificAirlines(o_input){
	if(o_input.value.length>0){
		o_dl = o_input.parentNode.parentNode
		a_dd = o_dl.getElementsByTagName("dd")
		for(i=0;i<a_dd.length;i++)a_dd[i].className = "display"
	}else{
		for(i=1;i<a_dd.length;i++)a_dd[i].className = "";
	}
}
function fixMacIEselect(s_formdivid,o_radio){
o_formdiv = document.getElementById(s_formdivid)
a_modOptions = o_formdiv.getElementsByTagName("select");
if(a_modOptions)for(i=0;i< a_modOptions.length;i++){
	a_modOptions[i].focus();
	a_modOptions[i].blur();
}
o_radio.focus();
}
function departureArrival(o_form){
	if(o_form.aln_name.selectedIndex==0){
		alert(o_form.error1.value)
		return false;
	}
	if(o_form.flt_num.value=="Flight #"){
		alert(o_form.error2.value)
		return false;
	}
	return true;
}

function addvars(url,o_form){
s_url=new String(url);
s_url+="&expr_path="+o_form.expr_path.value;
s_url+="&city="+o_form.city.value;
s_url+="&dateLeavingMonth="+o_form.dateLeavingMonth.value;
s_url+="&dateLeavingDay="+o_form.dateLeavingDay.value;
s_url+="&dateReturningMonth="+o_form.dateReturningMonth.value;
s_url+="&dateReturningDay="+o_form.dateReturningDay.value;
s_url+="&searchMode="+o_form.searchMode.value;
s_url+="&pax_cnt="+o_form.pax_cnt.value;
s_url+="&state="+o_form.state.value;
s_url+="&city="+o_form.city.value;

parent.window.location=s_url;

}/*
function loadSuperPromo(){
	o_sploader = (document.getElementById("superpromoloader")) ? document.getElementById("superpromoloader") : 0;
	if(!o_sploader) return false;
	o_sp = document.getElementById("superpromo");
	a_sploadera = o_sploader.getElementsByTagName("a")
	o_sp.appendChild(a_sploadera[0])
}
function swapoutsuperpromoiframe(){
	o_superpromo = document.getElementById("superpromo");
	a_spiframes = o_superpromo.getElementsByTagName("iframe")
	if(a_spiframes[0]){
		o_spiframe = a_spiframes[0];
		o_spspan = document.getElementById("spspan");
	   	o_spspan.innerHTML = o_spiframe.innerHTML
		o_spiframe.style.display = "none"
	}
}
*/

/* DDA added function 12/15 to operate tabs on search detail page*/
function cb_ChangeNavSearch(o_radio, o_span, click, uri, pagetitle){
	o_li = o_span.parentNode;
	o_ul = o_li.parentNode;
	a_lis = o_ul.getElementsByTagName("li");
/* If i am displayed kill the click */	
	//alert("cb_"+o_radio.value);
	if(document.getElementById("cb_"+o_radio.value).style.display == "block") return false;
	//alert(a_lis.length);
	for(i=0;i<a_lis.length;i++){
		//alert(a_lis[i].firstChild.firstChild.value + i ) ;
			a_lis[i].firstChild.className="";
			//document.getElementById("cb_"+a_lis[i].firstChild.firstChild.value).style.display = "none";
			document.getElementById("cb_"+a_lis[i].firstChild.firstChild.value).style.display = "none";
	}
	o_li.firstChild.className = "tabNavon";
	o_radio.checked = true;
	s_radio = o_radio.value
	document.getElementById("cb_"+s_radio).style.display = "block";
	if(o_radio.value == "Map") {
		LoadMap();
	}
	return false;
}
