var b_stopBit = 0; // Setting to enable Date Increments

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;
var b_loaded = 0;

/* cannonball functions */
/* 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];
	document.getElementById("cbForms").style.display = "block";
	cb_ChangeNav(o_nav, o_nav.parentNode);
	b_loaded = 1;
}
/* change cannonball */
function cb_ChangeNav(o_radio, o_span){
	o_li = o_span.parentNode
	o_ul = o_li.parentNode;
	a_lis = o_ul.getElementsByTagName("li");
/* If i am displayed kill the click */	
	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";
			document.getElementById("cb_"+a_lis[i].firstChild.firstChild.value).style.visibility = "hidden";
	}
	o_li.firstChild.className = "cbNavon";
	o_radio.checked = true;
	s_radio = o_radio.value
	document.getElementById("cb_"+s_radio).style.display = "block";
	document.getElementById("cb_"+s_radio).style.visibility = "visible";
	switch(s_radio){
		case "formFO":
			document.getElementById("h_formFOhp").name = "tt2";			
			cb_bff(document.formFO);
			childAges(document.getElementById("FO_children"),'cbFOchildages')
			document.formFO.inp_num_cnx.value = "";
		break;
		case "formFH":
			//childAges(document.getElementById("FH_children"),'cbFHchildages')
		break;
		case "formHO":
			cb_hoscope(document.getElementById("HO_country"),"cbHOstate");
		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;
		case "formCO":
			carPUDO(document.getElementById("FCO_pickupoption"));
		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){
	if (!b_loaded) return false;
		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";
				}
			}
		}
	}
/* Populates the Month Date Field on Disney Vacations */
function populateDate() {
	var m_names = new Array("", "January", "February", "March", 
	"April", "May", "June", "July", "August", "September", 
	"October", "November", "December");
	var o_todays_date=new Date;  // Create new Date Object
	var a_currentYear=o_todays_date.getFullYear(); // Get the current Year
	var a_currentMonth=o_todays_date.getMonth(); // Get the Months numeric value
	var s_form_options = new String();
	var s_monthRange = 6; // How many months to show
	 for (i = 0 ; i < s_monthRange; i++) {
	  s_form_options = s_form_options + '<option value="'+eval(o_todays_date.getMonth() + 1)+'-'+o_todays_date.getFullYear()+'">'+m_names[eval(o_todays_date.getMonth() + 1)]+'-'+o_todays_date.getFullYear()+' ';
	  o_todays_date.setMonth(o_todays_date.getMonth() + 1);
	 }
	document.write(s_form_options);
}
/* 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":
			if(document.getElementById("cb"+s_formbit+"bff")){
				document.getElementById("cb"+s_formbit+"bff").style.display = "none";
			}else{
				document.getElementById("cb"+s_formbit+"bffstart").style.display = "none";
				document.getElementById("cb"+s_formbit+"bffthru").style.display = "none";			
			}
			switch(s_formbit){
				case "FO":
				document.getElementById(s_formbit+"_fromcal").style.display = "block"
				document.getElementById(s_formbit+"_tocal").style.display = "block"; 
				document.getElementById("cbSubmitText").style.display = "block";
				document.getElementById("FHbutton").style.display = "block";			
				break;
				case "FRT":
				o_form.module.value = "tripsrch";
				document.getElementById(s_formbit+"_tocal").style.visibility = "visible";			
				document.getElementById(s_formbit+"_fromcal").style.display = "inline";					
				document.getElementById("cbFRTmsg").style.visibility = "visible";
				document.getElementById(s_formbit+"_addopt").style.visibility = "visible";
				break;
				case "FOW":	
					document.getElementById(s_formbit+"_fromcal").style.display = "inline";	
					document.getElementById(s_formbit+"_addopt").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.display = "none";			
					document.getElementById(s_formbit+"_fromcal").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(s_formbit+"_fromcal").style.display = "none";				
					document.getElementById("cbFRTmsg").style.visibility = "hidden";
					document.getElementById(s_formbit+"_addopt").style.visibility = "hidden";													
					if(o_form.FRT_addHot.checked)o_form.FRT_addHot.checked=false;
					addHotel(o_form.FRT_addHot);
				break;
				case "FOW":	
					document.getElementById(s_formbit+"_fromcal").style.display = "none";
					document.getElementById(s_formbit+"_addopt").style.visibility = "hidden";
				break;	
				default:
			}
			if(document.getElementById("cb"+s_formbit+"bff")){
				document.getElementById("cb"+s_formbit+"bff").style.display = "inline"
			}else{
				document.getElementById("cb"+s_formbit+"bffstart").style.display = "block";
				document.getElementById("cb"+s_formbit+"bffthru").style.display = "block";	
			}
	
			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_formFOhp").name = "htl_pkgs";
	document.formFO.inp_num_cnx.value = "1";
	document.formFO.submit();
}else{return false}
}
function addHotel(o_input){
	o_form = o_input.form;
	switch (o_input.checked){
	case true:
		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+= (o_form.name=="formHOgbl") ? "&airport="+o_form.airport.value : "&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;
parent.window.location=s_url;
}
function cb_hoscope(o_select,s_state){
	switch(o_select.value){
		case "us":
		case "ca":
			document.getElementById(s_state).style.visibility = "visible";
		break;
		default:
			document.getElementById(s_state).style.visibility = "hidden";
	}
}
function cb_hoGetYear(i_month,i_date){
d_today = new Date();
i_year = d_today.getFullYear();
if(i_month<=d_today.getMonth()+1&&i_date<d_today.getDate())i_year+=1;
return i_year;
}
function cb_hosubmit(o_form){
	b_form = false;
	s_radio = "";
	for(var i=0;i<o_form.rooms.length;i++){
		if(o_form.rooms[i].checked) s_radio = o_form.rooms[i].value
	}
	if(s_radio=="groople"){
		s_groople = "http://www.groople.com/travelocity/hotels/default.aspx?"
		s_groople+= "Checkin="+o_form.dateLeavingMonth.value+"/"+o_form.dateLeavingDay.value+"/"+cb_hoGetYear(o_form.dateLeavingMonth.value,o_form.dateLeavingDay.value);
		s_groople+= "&Checkout="+o_form.dateReturningMonth.value+"/"+o_form.dateReturningDay.value+"/"+cb_hoGetYear(o_form.dateReturningMonth.value,o_form.dateReturningDay.value);
		switch(o_form.cityCountryCode.value){
			case "us":
			case "ca":
				s_groople+= "&City="+escape(o_form.city.value);
				if(o_form.state.value!="") s_groople+=",%20"+o_form.state.value;
			break;
			default:
				s_groople+= "&City="+escape(o_form.city.value) //+",%20"+o_form.cityCountryCode.value;
		}
		s_groople+= "&GroupType=Other&Rooms=5";
		window.location = s_groople;
	}else{
		b_form = checkform(o_form,1,2,3,6);
	}
	return b_form;
}

function carPUDO(o_select){
	switch(o_select.options[o_select.selectedIndex].value){
	case "pu_air":
		document.getElementById("fco_airport").style.display = "block";
		document.getElementById("fco_nearaddress").style.display = "none";
		document.getElementById("fco_nearplace").style.display = "none";
	break;
	case "pu_addr":
		document.getElementById("fco_airport").style.display = "none";
		document.getElementById("fco_nearaddress").style.display = "block";
		document.getElementById("fco_nearplace").style.display = "none";	
	break;
	case "pu_poi":
		document.getElementById("fco_airport").style.display = "none";
		document.getElementById("fco_nearaddress").style.display = "none";
		document.getElementById("fco_nearplace").style.display = "block";	
	break;
	default:
		window.location=o_select.options[o_select.selectedIndex].value;
	}
}
function checkCar(o_form){
	o_select = document.getElementById("FCO_pickupoption") 
	switch(o_select.options[o_select.selectedIndex].value){
	case "pu_poi":
		b_checkCar = checkform(o_form,2,3,6);
	break;
	case "pu_addr":
		b_checkCar = checkform(o_form,6)
	break;
	default:
		b_checkCar = checkform(o_form,1,2,3,6);
	}
	return b_checkCar;	
}

function chkForMatch(){
  if((document.getElementById("CO_to").value.toUpperCase() == document.getElementById("CO_do").value.toUpperCase()) && document.getElementById("FCO_dropoffoption").value =='do_air'){
   document.getElementById("CO_do").value ='';
   document.getElementById("FCO_dropoffoption").options[document.getElementById("FCO_dropoffoption").selectedIndex].value ='';
   return true;
  }
  return true;
}
<!-- Adjustments for CB End Dates -->
function adjDate(o_form) {
 if (b_stopBit == 0) {   
  // Set Variables
  var a_selectedForm;
  var o_todays_date=new Date;  // Create new Date Object
  var a_currentYear=o_todays_date.getYear(); // Get the current Year
  var o_days = new Array(31, ((a_currentYear % 4 == 0 && a_currentYear % 100 != 0) || a_currentYear % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // Set the days for each month
  var a_dateDiff = 3; // Number of days to Increment
  if(o_form){
    a_selectedForm = o_form.name;
  } else {
    a_selectedForm = getCBform(); // Get what form is in focus
  }	 
  var a_formPrefix = a_selectedForm.substring(4); // Obtain Prefix to use for element IDs
  var a_fromVal = document.getElementById(a_formPrefix+"_fromdate").value; // Form Value : From Date
  var a_fromMonth = document.getElementById(a_formPrefix+"_frommonth").selectedIndex; // Form Value : From Month 
 	
  // Check if they selected a date outside the Max Date
  if(a_fromVal > o_days[a_fromMonth]) {
   document.getElementById(a_formPrefix+"_fromdate").options[eval(o_days[a_fromMonth] - 1)].selected=true; // Correct Date
   var a_fromVal = document.getElementById(a_formPrefix+"_fromdate").value; // Reset the from Date variable
  } 
  
  var o_selectedDate=new Date(a_currentYear,a_fromMonth,a_fromVal); // Create a Date Obj from dates selected
  var o_toDate = o_selectedDate.setDate(o_selectedDate.getDate() + a_dateDiff); // Increment the Date
 
  // Set the form fields
  document.getElementById(a_formPrefix+"_tomonth").options[o_selectedDate.getMonth()].selected=true;
  document.getElementById(a_formPrefix+"_todate").options[(o_selectedDate.getDate() - 1)].selected=true;
  
  // Make sure all the Cannonball forms keep dates
  maintainState(document.getElementById(a_formPrefix+"_tomonth"));
  maintainState(document.getElementById(a_formPrefix+"_todate"));
  maintainState(document.getElementById(a_formPrefix+"_fromdate"));
  maintainState(document.getElementById(a_formPrefix+"_frommonth"));
  
  //Unset Variables
  var a_fromMonth;
  var a_fromVal;
  var a_currentYear;
  var selectedDate;
 }
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 24*60*60*1000*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function GetCookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function formCtrl(o_form){
 s_formName = o_form.name;
 var b_submit = false;
 var s_popFlag='0';
 switch (s_formName){  
  case 'formCO': //Car Only
     o_select = document.getElementById("FCO_pickupoption") 
	 switch(o_select.options[o_select.selectedIndex].value){
	  case "pu_poi": //Car by Point of Interest
		 b_submit = checkform(o_form,2,3,6);
	  break;
	  case "pu_addr": //Car by Address
		b_submit = checkform(o_form,6)
	  break;
	  default:
		b_submit = checkform(o_form,1,2,3,6);
	 }
  break;
  case 'formFO': //Flight Only
  case 'formFRT': //Flight Round Trip
     b_submit = checkform(o_form,1,2,3,4,5,6);
	 s_popFlag='1';
  break;
  case 'formFMD': //Flights with Multiple City
     b_submit = checkform(o_form,1,2,3,4,5,6);
	 s_popFlag='1';  
  break;
  case 'formFH': //Flight & Hotel
     b_submit = checkform(o_form,1,2,3,4,6);
	 s_popFlag='1';
  break;
  case 'formHOgbl': //Hotel other Destinations
  case 'formHOus': //Hotel US Canada
     b_submit = checkform(o_form,1,2,3,6);
	 s_popFlag='1';
  break;
  case 'formFOW': //Flight One Way
     b_submit = checkform(o_form,1,2,3,4,5);
     s_popFlag='1';
  break;
  case 'formHO': //Hotel Only
     b_submit = cb_hosubmit(o_form);
	 s_popFlag='1';
  break;   
 }

 loadPopOrNot(b_submit,s_popFlag,o_form);
 return b_submit; 
}

function getElementByValue(ElementCollection, Value)
{
    var i, Element;
     for (i = 0 ; i < ElementCollection.length ; i++)
     {
          if (ElementCollection[i].value == Value)
          {
               return ElementCollection[i];
          }
     }
     return null;
}

<!-- Begin Popunder Scripts -->
var once_per_session='1'; //Pop every time = 0, or Verify = 1
var popunder="http://www.travelocity.com/popWindow";
var winfeatures="left=150,top=200,width=500,height=250,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0";

function loadPopOrNot () {
  var a_arguments = new Array;
  a_arguments = loadPopOrNot.arguments;
  b_submit = a_arguments[0];
  s_popFlag = a_arguments[1];
  o_form = a_arguments[2];
  if ((b_submit) && (s_popFlag == '1')) {
    if(once_per_session==0){
       loadpopunder(o_form);
      } else {
	   if(!GetCookie('popunder')){
	     SetCookie('popunder','yes','1');
	     loadpopunder(o_form);
       }         
	  }
  }
}

// Load the popUnder
function loadpopunder(o_form){
 var s_theURL = location.href;
 // Check for the Site59 tags to disable pops
 var i_s59Svc1 = s_theURL.indexOf('S59BT'); 
 var i_s59Svc2 = s_theURL.indexOf('S59LG');
 var s_theAdtoShow;
 var s_days;
 var s_theDomain = document.location.hostname;
 var s_selectedForm = o_form.name; // Get what form is in focus
 if ((s_selectedForm == 'formDV') || (s_selectedForm == 'formEV')) {
  <!-- NoOp --> 
 } else if (s_selectedForm == 'formFOW') {
  var a_formPrefix = s_selectedForm.substring(4); // Obtain Prefix to use for element IDs
  var a_fromDate = document.getElementById(a_formPrefix+"_fromdate").value; // Form Value : From Date
  var a_fromMonth = document.getElementById(a_formPrefix+"_frommonth").selectedIndex; // Form Value : From Month
  var b_bestFareFinder = getElementByValue(o_form,"calendar"); //calendar value is used on FOW 
  b_bestFareFinder = (b_bestFareFinder) ?  b_bestFareFinder.checked : false;
  b_bestFareFinder = (b_bestFareFinder) ? true : false; 
  var i_dayRange = 17; // Days between Departure and today
  var o_dateDiff=new Date;
  var a_currentYear=o_dateDiff.getFullYear(); 	
  var o_fromDate=new Date(a_currentYear,a_fromMonth,a_fromDate); // Generate a date Obj from the selection
  var o_currDate= new Date;
  o_dateDiff.setTime(o_fromDate.getTime() - o_currDate.getTime());
  var timeDiff = o_dateDiff.getTime();
  var s_days = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); 
 } else {
  var a_formPrefix = s_selectedForm.substring(4); // Obtain Prefix to use for element IDs
  var a_fromDate = document.getElementById(a_formPrefix+"_fromdate").value; // Form Value : From Date
  var a_fromMonth = document.getElementById(a_formPrefix+"_frommonth").selectedIndex; // Form Value : From Month
  var b_bestFareFinder = getElementByValue(o_form,"BestFareFinder");
  b_bestFareFinder = (b_bestFareFinder) ?  b_bestFareFinder.checked : false;
  b_bestFareFinder = (b_bestFareFinder) ? true : false;
  var i_dayRange = 17; // Days between Departure and today
  var o_dateDiff=new Date;
  var a_currentYear=o_dateDiff.getFullYear(); 	
  var o_fromDate=new Date(a_currentYear,a_fromMonth,a_fromDate); // Generate a date Obj from the selection
  var o_currDate= new Date;
  o_dateDiff.setTime(o_fromDate.getTime() - o_currDate.getTime());
  var timeDiff = o_dateDiff.getTime();
  var s_days = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); 
 }  
 
  // Check the Range and Submitted Values
  if((s_days <= i_dayRange) || (s_selectedForm == 'formDV') || (s_selectedForm == 'formEV') || (b_bestFareFinder)) {
	  s_theAdtoShow = 'ad1'; //Site59 Ad
  } 

  // Check for WCT Criteria
  if((s_selectedForm == 'formHO') || (s_selectedForm == 'formHOgbl') || (s_selectedForm == 'formHOus')) {
	  s_theAdtoShow = 'ad2'; //WCT Ad
  } 
 
 var win2 = new Object;
   
 if(s_theAdtoShow && !b_overide && i_s59Svc1 == '-1' && i_s59Svc2 == '-1'){
	 var s_urlString = '?s_theDomain='+s_theDomain+'&s_selectedForm='+s_selectedForm+'&a_formPrefix='+a_formPrefix+'&a_fromDate='+a_fromDate+'&a_fromMonth='+a_fromMonth+'&s_theAdtoShow='+s_theAdtoShow;
	 win2=window.open(popunder+s_urlString,"adWindow",winfeatures);
	 win2.blur();
	 win2.screenX = 150;
	 win2.screenY = 200;
	 window.focus();
 } 
}