/*
JavaScript Document
05/09/2008 JRanz add logic to SS API and AirVendor API to Hawaii pages.
*/ 

function highlight(field){
  field.focus();
  field.select();
}

function CheckAge(s,n){
if (s.length > 1){
	if (s > 12){
		alert("Please child age are under 12");
		findObj(n).value = ''
	return false;
	} 
}
return true;
}

function addFly(wnFly){
	//alert(wnFly)
	if (wnFly == 'True'){
		displayDiv('wfly',true);
		if (findObj('wfly1') != null){
			displayDiv('wfly1',true);
		}
		displayDiv('divcabin',true);
		if (findObj('divcabin1') != null){
			displayDiv('divcabin1',true);
		}
		displayDiv('nfly',false);
		if (findObj('wfly1') != null){
			displayDiv('nfly1',false);
		}
		findObj('addFlight').value = wnFly
		AirOption = 1
		createCookie('wFLY','True',1);
		findObj('BaddFlight')[0].checked = "Yes";
	}
	if (wnFly == 'False'){
		displayDiv('wfly',false);
		if (findObj('wfly1') != null){
			displayDiv('wfly1',false);
		}
		displayDiv('divcabin',false);
		if (findObj('divcabin1') != null){
			displayDiv('divcabin1',false);
		}
		displayDiv('nfly',true);
		displayDiv('nfly1',true);
		findObj('addFlight').value = wnFly
		AirOption = 0
		createCookie('wFLY','False',1);
		findObj('BaddFlight')[1].checked = "Yes";
	}
	//callClean()
}

function callClean(){
	document.BfrmListQry.reset();
}

function showChild(n){
    var objChild0=document.getElementById("divChild0")
    var objChild1=document.getElementById("divChild1")
    var objChild2=document.getElementById("divChild2")
    var objChild3=document.getElementById("divChild3")
    var objChild4=document.getElementById("divChild4")

    if (n>0)
	   objChild0.style.display='block'
	
    if (n==0)
      objChild0.style.display='none'
	 
    for(i=1;i<=n;i++)
	  eval("objChild"+i+".style.display='block'"); 
      
    for(;i<=4;i++){
      eval("objChild"+i+".style.display='none'");
      eval("document.BfrmListQry.BiChild"+i+".value=''");
    }
}

function selectItemFromListW(inputElementName, listElementName, formName, strFlag){
	//get the input value and the list length
	inputElementValue = new String(eval("document." + formName + "." + inputElementName + ".value")).toLowerCase();	
	 var c = inputElementValue.length;
    // alert(c)
    if (c<=3){
		listElementLength = eval("document." + formName + "." + listElementName + ".length");
		
		//get the string delimiter (to filter out the country name, or any other prefix to the list data)
		strDelimiterValue = new String(strFlag).toLowerCase();
		//alert(strDelimiterValue)
		//get length of string delimiter
		if (strDelimiterValue != null){
			strDelimiterLength = strDelimiterValue.length;
		}
		else{
			strDelimiterLength = 0;
		}
			
		//cycle through list to find a match
		for (count=0; count<listElementLength; count++){
			//get the distinct list value and match text
			listElementValue = new String(eval("document." + formName + "." + listElementName + ".options[count].text")).toLowerCase();
			//position 
			var startPosition = listElementValue.indexOf( strFlag, 0 ) + strDelimiterLength;
			var matchText = listElementValue.substr(startPosition, inputElementValue.length);
			
			if (inputElementValue == matchText){ //then match found
				// set matching list option to selected
				eval("document." + formName + "." + listElementName + ".options[count]").selected = true;
				break; 
			} 
		}
	}
	
	if (c>3){
		eval("findVal = (new String(document." + formName + "." + inputElementName + ".value)).toLowerCase()");	
		eval("len=document." + formName + "." + listElementName + ".length");
		var findLength = findVal.length;
		for (count=0; count<len; count++){
			eval("compVal = (new String(document." + formName + "." + listElementName + ".options[count].text)).toLowerCase()");
			var subStrin = compVal.substr(0, findLength);
			if (findVal == subStrin){
				eval("document." + formName + "." + listElementName + ".options[count].selected = true");
				break; 
			} 
		}
	} 
}

function valDest(idval,selNa){
	//alert(idval)
	if (idval == -1){
		//You selected a country/region. Please select a city within this country/region to proceed with your query.
		alert('You selected a country/region.\nPlease select a city within this country/region to proceed with your query.\nThanks')
		document.getElementById(selNa).focus();
		//eval("document.BfrmListQry."+ selNa +".focus()");
		//return;
	}
}

function GetBook(){
var dh
myOption = -1;
	for (i=document.BfrmListQry.BaddFlight.length-1; i > -1; i--){
		if (document.BfrmListQry.BaddFlight[i].checked){
		myOption = i; i = -1;
		}
	}
	
	p = document.BfrmListQry.BaddFlight[myOption].value;
	
	if (p == 'True'){
		if (document.BfrmListQry.BiDepCity.value == -1){
			document.BfrmListQry.BiDepCity.focus();
			alert('Please Select Leaving From')
			return;
		} 
		if (document.BfrmListQry.BiFindStayCity.value == -1){
			document.BfrmListQry.BiFindStayCity.focus();
			alert('Please Select a Valid Destinations')
			return;
		}
		if (document.BfrmListQry.BInDate1.value.indexOf('Select') == 0){
			document.BfrmListQry.BInDate1.focus();
			alert('Please Select Departing Date')
			return;
		}
		if (document.BfrmListQry.BOutDate1.value.indexOf('Select') == 0){
			document.BfrmListQry.BOutDate1.focus();
			alert('Please Select Returning Date')
			return;
		}
		
	document.frmListQry.SystemID.value = "B3E36AE7-0E39-4B3F-B892-4CE2446D83CD"
	document.frmListQry.addFlight.value = 'True'
	document.frmListQry.iDepCity.value = document.BfrmListQry.BiDepCity.value 
	document.frmListQry.InDate1.value = document.BfrmListQry.BInDate1.value
	document.frmListQry.iRetCity.value = document.BfrmListQry.BiDepCity.value 
	document.frmListQry.OutDate1.value = document.BfrmListQry.BOutDate1.value
	document.frmListQry.Cabin.value = document.BfrmListQry.BCabin.value
	
	eval("destCtyID =  document.BfrmListQry.BiFindStayCity.value")
	eval("destCtyNa =  document.BfrmListQry.BiFindStayCity.options[document.BfrmListQry.BiFindStayCity.selectedIndex].text")
	
	if(document.frmListQry.chkIDcountry != null){
		if (document.frmListQry.chkIDcountry.value == 3887){
			destCtyNa =  "Hawaii - " + destCtyNa
		}
	}
	s = (destCtyNa.indexOf("-"))
	u = (destCtyNa.substring(-1,s - 1))
	destCtyNa = destCtyNa.replace(u +" - ","")
	dh = destCtyID
	if (dh == 3889 || dh == 3892 || dh == 3891 || dh == 3890 || dh == 3888){
		u = 'Hawaii'
	}
	if (u=="Hawaii"){
		eval("document.frmListQry.APICity1.value = '2|X1-X3'");
		eval("document.frmListQry.AirVendorAPI.value = '3|11-13-30-35-68-69'");
		eval("document.frmListQry.SSVendorAPI.value = 'X1'");
		eval("document.frmListQry.CarVendorAPI.value = ''");
	}
	else{
		eval("document.frmListQry.APICity1.value = '2|X0-X3'");
		eval("document.frmListQry.AirVendorAPI.value = '3|11-13-30-35'");
		eval("document.frmListQry.SSVendorAPI.value = ''");
		eval("document.frmListQry.CarVendorAPI.value = 'CX1'");
	}
	
	
	
	document.frmListQry.StayCity1.value = destCtyID
	document.frmListQry.StayCity1_Name.value = destCtyNa
	document.frmListQry.StayCityS.value = destCtyID
	document.frmListQry.StayCityS_Name.value = destCtyNa
	document.frmListQry.StayCityE.value = destCtyID
	document.frmListQry.StayCityE_Name.value = destCtyNa
	}
	
	
	if (p == 'False'){
		if (document.BfrmListQry.BiFindStayCity2.value == -1){
			document.BfrmListQry.BiFindStayCity2.focus();
			alert('Please Select Going To')
			return;
		}
		if (document.BfrmListQry.BInDate12.value.indexOf('Select') == 0){
			document.BfrmListQry.BInDate12.focus();
			alert('Please Select CheckIn Date')
			return;
		}
		if (document.BfrmListQry.BOutDate12.value.indexOf('Select') == 0){
			document.BfrmListQry.BOutDate12.focus();
			alert('Please Select CheckOut Date')
			return;
		}
		
	document.frmListQry.SystemID.value =  "392FAC89-CF2D-4BD8-9E9F-5026853CD105"
	document.frmListQry.addFlight.value = 'False'
	document.frmListQry.InDate1.value = document.BfrmListQry.BInDate12.value
	document.frmListQry.OutDate1.value = document.BfrmListQry.BOutDate12.value
	eval("destCtyID =  document.BfrmListQry.BiFindStayCity2.value")
	eval("destCtyNa =  document.BfrmListQry.BiFindStayCity2.options[document.BfrmListQry.BiFindStayCity2.selectedIndex].text")
	if(document.frmListQry.chkIDcountry != null){
		if (document.frmListQry.chkIDcountry.value == 3887){
			destCtyNa =  "Hawaii - " + destCtyNa
		}
	}
	s = (destCtyNa.indexOf("-"))
	u = (destCtyNa.substring(-1,s - 1))
	destCtyNa = destCtyNa.replace(u +" - ","")
	dh = destCtyID
	if (dh == 3889 || dh == 3892 || dh == 3891 || dh == 3890 || dh == 3888){
		u = 'Hawaii'
	}
	
	if (u=="Hawaii"){
		eval("document.frmListQry.APICity1.value = '2|X1-X3'");
		eval("document.frmListQry.AirVendorAPI.value = '3|11-13-30-35-68-69'");
		eval("document.frmListQry.SSVendorAPI.value = 'X1'");
		eval("document.frmListQry.CarVendorAPI.value = ''");
	}
	else{
		eval("document.frmListQry.APICity1.value = '2|X0-X3'");
		eval("document.frmListQry.AirVendorAPI.value = '3|11-13-30-35'");
		eval("document.frmListQry.SSVendorAPI.value = ''");
		eval("document.frmListQry.CarVendorAPI.value = 'CX1'");
	}
	document.frmListQry.StayCity1.value = destCtyID
	document.frmListQry.StayCity1_Name.value = destCtyNa
	document.frmListQry.StayCityS.value = destCtyID
	document.frmListQry.StayCityS_Name.value = destCtyNa
	document.frmListQry.StayCityE.value = destCtyID
	document.frmListQry.StayCityE_Name.value = destCtyNa
	}
document.frmListQry.iAdults.value = document.BfrmListQry.BiAdults.value
document.frmListQry.iChildren.value = document.BfrmListQry.BiChildren.value
document.frmListQry.iChild1.value = document.BfrmListQry.BiChild1.value
document.frmListQry.iChild2.value = document.BfrmListQry.BiChild2.value
document.frmListQry.iChild3.value = document.BfrmListQry.BiChild3.value
document.frmListQry.iChild4.value = document.BfrmListQry.BiChild4.value
//document.frmListQry.action="http://10.15.2.202/TVLAPI/Multicity3/MC_ComponentList.ASP" 
document.frmListQry.action="http://beachdestinations.bookingprocess.com/TVLAPI/Multicity3/MC_ComponentList.ASP" 
document.frmListQry.submit()
if (typeof(__utmLinkPost) == 'function') {
 __utmLinkPost('http://beachdestinations.bookingprocess.com/TVLAPI/Multicity3/MC_ComponentList.ASP');
}
} 