// Javascript code for T2 QuickFinders
var clubnum = "176"; 		// Club Number
var cruise_url = "http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=AAA&club="+ clubnum +"&page=PartnerRedirect&PID=412";
var hotel_url = "http://www.aaa.com/travel2/common/quickSearchHotel.xhtml?association=AAA&club="+ clubnum;
var car_url = "http://www.aaa.com/travel2/common/quickSearchCar.xhtml?association=AAA&club="+ clubnum;
var air_url = "http://www.aaa.com/travel2/common/quickSearchAir.xhtml?association=AAA&club="+ clubnum;
var maps_page = "ITTServices"; // QuickRouteRequest or ITTServices
var maps_url = "http://www.aaa.com/scripts/WebObjects.dll/AAAOnline?association=AAA&club="+ clubnum +"&page="+maps_page;

function HotelQF(){
	var url = hotel_url+"&advancedSearch=NO&searchType=HOTEL";
	url = url+"&city="+document.HotelsSearch.hotelCity.value;
	url = url+"&diamondRating="+document.HotelsSearch.diamondRating.value;
	url = url+"&checkinMonth="+getMonthFromDateMDY(document.HotelsSearch.Hoteldatein.value);
	url = url+"&checkinDay="+getDayFromDateMDY(document.HotelsSearch.Hoteldatein.value);
	url = url+"&checkinYear="+getYearFromDateMDY(document.HotelsSearch.Hoteldatein.value);
	url = url+"&checkoutMonth="+getMonthFromDateMDY(document.HotelsSearch.Hoteldateout.value);
	url = url+"&checkoutDay="+getDayFromDateMDY(document.HotelsSearch.Hoteldateout.value);
	url = url+"&checkoutYear="+getYearFromDateMDY(document.HotelsSearch.Hoteldateout.value);
	url = url+"&adults="+document.HotelsSearch.num_adults.value;
	url = url+"&children="+document.HotelsSearch.num_children.value;
	top.location.href = url;
}
function CarQF(){
	var url = car_url+"&advancedSearch=NO&searchType=CAR";
	url = url+"&pickupCity="+document.CarsSearch.pickupCity.value;
	url = url+"&carClass="+document.CarsSearch.carClass.value;
	url = url+"&pickupMonth="+getMonthFromDateMDY(document.CarsSearch.pickupDate.value);
	url = url+"&pickupDay="+getDayFromDateMDY(document.CarsSearch.pickupDate.value);
	url = url+"&pickupYear="+getYearFromDateMDY(document.CarsSearch.pickupDate.value);
	url = url+"&pickupTime="+arrayTime(document.CarsSearch.pickupTime.value);
	url = url+"&dropoffMonth="+getMonthFromDateMDY(document.CarsSearch.dropoffDate.value);
	url = url+"&dropoffDay="+getDayFromDateMDY(document.CarsSearch.dropoffDate.value);
	url = url+"&dropoffYear="+getYearFromDateMDY(document.CarsSearch.dropoffDate.value);
	url = url+"&dropoffTime="+arrayTime(document.CarsSearch.dropoffTime.value);
	top.location.href = url;
}
function AirQF(){
	var url = air_url+"&advancedSearch=NO&searchType=AIR";
	url = url+"&depCity="+document.FlightsSearch.depCity.value;
	url = url+"&arrCity="+document.FlightsSearch.arrCity.value;
	url = url+"&depMonth="+getMonthFromDateMDY(document.FlightsSearch.departDate.value);
	url = url+"&depDay="+getDayFromDateMDY(document.FlightsSearch.departDate.value);
	url = url+"&depYear="+getYearFromDateMDY(document.FlightsSearch.departDate.value);
	url = url+"&retMonth="+getMonthFromDateMDY(document.FlightsSearch.returnDate.value);
	url = url+"&retDay="+getDayFromDateMDY(document.FlightsSearch.returnDate.value);
	url = url+"&retYear="+getYearFromDateMDY(document.FlightsSearch.returnDate.value);
	url = url+"&adults="+document.FlightsSearch.num_adults.value;
	url = url+"&children="+document.FlightsSearch.num_children.value;
	url = url+"&seniors="+document.FlightsSearch.num_seniors.value;
	top.location.href = url;
}
function MapsQF(){
	var url = maps_url+""
	if ((isEmpty(document.MapsSearch.mapsHomeStreet)) && (isEmpty(document.MapsSearch.mapsHomeCity)) && (isEmpty(document.MapsSearch.mapsHomeState)) && (isEmpty(document.MapsSearch.mapsDestStreet)) && (isEmpty(document.MapsSearch.mapsDestCity)) && (isEmpty(document.MapsSearch.mapsDestState))) {
top.location.href = maps_url;
	} else {
if (!isEmpty(document.MapsSearch.mapsHomeStreet)){ fromAddr1 = document.MapsSearch.mapsHomeStreet.value.replace(/ /g,"+"); } else { fromAddr1 = "%20"; }if (!isEmpty(document.MapsSearch.mapsHomeCity)){ fromCity = document.MapsSearch.mapsHomeCity.value.replace(/ /g,"+"); } else { fromCity = "%20"; }if (!isEmpty(document.MapsSearch.mapsHomeState)){ fromState = document.MapsSearch.mapsHomeState.value.replace(/ /g,"+"); } else { fromState = "%20"; }if (!isEmpty(document.MapsSearch.mapsDestStreet)){ toAddr1 = document.MapsSearch.mapsDestStreet.value.replace(/ /g,"+"); } else { toAddr1 = "%20"; }if (!isEmpty(document.MapsSearch.mapsDestCity)){ toCity = document.MapsSearch.mapsDestCity.value.replace(/ /g,"+"); } else { toCity = "%20"; }if (!isEmpty(document.MapsSearch.mapsDestState)){ toState = document.MapsSearch.mapsDestState.value.replace(/ /g,"+"); } else { toState = "%20"; }if (maps_page=="ITTServices"){	top.location.href = maps_url+"&subCommand=routeLocs&routeLocs=Address|"+fromAddr1+"|"+fromCity+"|"+fromState+"|%20|%20|%20|Address|"+toAddr1+"|"+toCity+"|"+toState+"|%20|%20|%20";} else {	top.location.href = maps_url+"&advancedSearch=NO&fromAddress1="+fromAddr1+"&fromCity="+fromCity+"&toState="+fromState+"&toAddress1="+toAddr1+"&toCity="+toCity+"&fromState="+toState;}}}

function isEmpty(txtField) {if ((txtField.value.length==0) || (txtField.value==null)) {return true;} else { return false;}}

function get_valid_year(valid_month, valid_day) {if (valid_day == null) {valid_day = 1;}var current_Date = new Date();current_month = current_Date.getMonth(); current_day = current_Date.getDate();if(valid_month == null) {valid_month = current_month;}if (current_month > valid_month || (current_month == valid_month && current_day > valid_day)) {valid_year = current_Date.getFullYear() + 1;} else {valid_year = current_Date.getFullYear(); } return valid_year;}

function updateTravelYear(monthObj,yearObj){ month = monthObj.options[monthObj.selectedIndex].value;current_date = new Date();  current_year = current_date.getFullYear();if (month > 0 ) {validYear = get_valid_year(month);}else {validYear = current_year;}for (i = 0; i < yearObj.options.length; i++) {if (yearObj.options[i].value == validYear) {yearObj.selectedIndex = i; break;}}}

function CruiseQF(){ // Revelex Cruise QuickFinder
if(document.CruiseForm.DestinationID){
var DestinationID = document.CruiseForm.DestinationID.value;
/* Add tracking code for Destination of Cruise */
}else{ var DestinationID=""; /* Default Destination */}
if(document.CruiseForm.cruise_duration){
var cruise_duration = document.CruiseForm.cruise_duration.value;
/* Add tracking code for duration of cruise */
}else{ var cruise_duration="0-9999"; /* Default Cruise Duration */}
if(document.CruiseForm.VendorID && document.CruiseForm.VendorID.value!=""){
var cruiseline = document.CruiseForm.VendorID.value; 
/* Add tracking code for Cruise Line (Vendor) */
}else if(DestinationID!=""){ var cruiseline="";
}else{ var cruiseline=""; /*Default Cruise Line (Vendor) */}
if(document.CruiseForm.cruise_month){
var cruise_month = document.CruiseForm.cruise_month.value;
/* Add Tracking Code for Month of Cruise */
}else{ var cruise_month=""; /*Default Cruise Month */}
if(document.CruiseForm.cruise_year && cruise_month!=""){
var cruise_year = "X"+document.CruiseForm.cruise_year.value;
/* Add Tracking Code for Year of Cruise */
}else{ var cruise_year=""; /*Default Cruise Year */}
if(document.CruiseForm.ShipName){ 
var ShipName = document.CruiseForm.ShipName.value;
/* Add Tracking Code for ShipName */ 
}else{ var ShipName=""; /*Default ShipName */}
if(document.CruiseForm.SailingDate){
var SailingDate = document.CruiseForm.SailingDate.value;
/* Add Tracking Code for Sailing Date */ 
}else{ var SailingDate=""; /*Default SailingDate*/}
cruise_url = cruise_url+"&destination="+DestinationID+"&date="+cruise_month+""+cruise_year+"&duration="+cruise_duration+"&cruiseline="+cruiseline;
top.location.href = cruise_url;}

function show(element) { document.getElementById(element).style.display = '';
if(element == 'hotel'){
checkCookie("HotelsSearch", "hotelCity", document.HotelsSearch.hotelCity, "text", "city or airport");
checkCookie("HotelsSearch", "Hoteldatein", document.HotelsSearch.Hoteldatein, "text", "mm/dd/yyyy");
checkCookie("HotelsSearch", "Hoteldateout", document.HotelsSearch.Hoteldateout, "text", "mm/dd/yyyy");
checkCookie("HotelsSearch", "num_children", document.HotelsSearch.num_children, "select", "1");
checkCookie("HotelsSearch", "num_adults", document.HotelsSearch.num_adults, "select", "1");
checkCookie("HotelsSearch", "hotelRating", document.HotelsSearch.hotelRating, "select", "No Preference");
} else if(element == 'car'){
checkCookie("CarsSearch", "pickupCity", document.CarsSearch.pickupCity, "text", "city or airport");
checkCookie("CarsSearch", "pickupDate", document.CarsSearch.pickupDate, "text", "mm/dd/yyyy");
checkCookie("CarsSearch", "dropoffDate", document.CarsSearch.dropoffDate, "text", "mm/dd/yyyy");
checkCookie("CarsSearch", "pickupTime", document.CarsSearch.pickupTime, "select", "9 am");
checkCookie("CarsSearch", "dropoffTime", document.CarsSearch.dropoffTime, "select", "9 am");
checkCookie("CarsSearch", "carClass", document.CarsSearch.carClass, "select", "No Preference");
} else if(element == 'flight'){
checkCookie("FlightsSearch", "depCity", document.FlightsSearch.depCity, "text", "city or airport");
checkCookie("FlightsSearch", "arrCity", document.FlightsSearch.arrCity, "text", "city or airport");
checkCookie("FlightsSearch", "departDate", document.FlightsSearch.departDate, "text", "mm/dd/yyyy");
checkCookie("FlightsSearch", "returnDate", document.FlightsSearch.returnDate, "text", "mm/dd/yyyy");
checkCookie("FlightsSearch", "num_adults", document.FlightsSearch.num_adults, "select", "1");
checkCookie("FlightsSearch", "num_children", document.FlightsSearch.num_children, "select", "0");
checkCookie("FlightsSearch", "num_seniors", document.FlightsSearch.num_seniors, "select", "0");
} else if(element == 'maps'){
} else if(element == 'cruise'){document.getElementById('vacations').style.display = 'none';} 
else if(element == 'vacations'){document.getElementById('cruise').style.display = 'none';	}}

function hide(element) { document.getElementById(element).style.display = 'none'; }	
var timerID = 0;
var previousDateValue = ''; 

function getDayFromDateMDY(strDate) { var dateVal = strDate; var fSepIndex = strDate.indexOf('/'); var lSepIndex = strDate.lastIndexOf('/'); fSepIndex = fSepIndex > -1 ? fSepIndex : strDate.indexOf('-'); lSepIndex = lSepIndex > -1 ? lSepIndex : strDate.lastIndexOf('-'); dateVal = (fSepIndex > -1 && lSepIndex > -1) ? strDate.substring(fSepIndex+1,lSepIndex) : ""; return dateVal; } 

function getMonthFromDateMDY(strDate) { var monthVal = strDate; var sepIndex = strDate.indexOf('/'); sepIndex = sepIndex > -1 ? sepIndex : strDate.indexOf('-'); monthVal = sepIndex > -1 ? strDate.substring(0,sepIndex) : ""; return monthVal; } 

function getYearFromDateMDY(strDate) { var yearVal = strDate; var sepIndex = strDate.lastIndexOf('/'); sepIndex = sepIndex > -1 ? sepIndex : strDate.lastIndexOf('-'); yearVal = sepIndex > -1 ? strDate.substring(sepIndex+1) : ""; return yearVal; } 

function startDepartDateTimer(){ if(timerID != 0){ clearInterval(timerID); } previousDateValue = document.FlightsSearch.departDate.value; timerID = setInterval("updateCookieForDate(document.FlightsSearch.departDate)",500); } 

function startReturnDateTimer(){if(timerID != 0){clearInterval(timerID); } previousDateValue = document.FlightsSearch.returnDate.value; timerID = setInterval("updateCookieForDate(document.FlightsSearch.returnDate)",500); } 

function startPickDateTimer(){ if(timerID != 0){ clearInterval(timerID); }previousDateValue = document.CarsSearch.pickupDate.value; timerID = setInterval("updateCookieForDate(document.CarsSearch.pickupDate)",500); } 

function startDropDateTimer(){if(timerID != 0){clearInterval(timerID);}previousDateValue = document.CarsSearch.dropoffDate.value;timerID = setInterval("updateCookieForDate(document.CarsSearch.dropoffDate)",500);} 

function startCheckinDateTimer(){if(timerID != 0){clearInterval(timerID);}previousDateValue = document.HotelsSearch.Hoteldatein.value;timerID = setInterval("updateCookieForDate(document.HotelsSearch.Hoteldatein)",500); } 

function startCheckoutDateTimer(){if(timerID != 0){clearInterval(timerID);}previousDateValue = document.HotelsSearch.Hoteldateout.value;timerID = setInterval("updateCookieForDate(document.HotelsSearch.Hoteldateout)",500);} 

function updateCookieForDate(dateFormObj){if(previousDateValue == dateFormObj.value){return;}setCookieForDate(dateFormObj);} 

function setCookieForDate(dateFormObj){	var objName = dateFormObj.name;var formName = dateFormObj.form.name; setCookie(formName, objName, dateFormObj.value, null);}	

function getCookie(formName, propName){if(document.cookie.length>0){c_start=document.cookie.indexOf(formName+"."+propName + "=");if (c_start!=-1){c_start=c_start + (formName+"."+propName).length+1;c_end=document.cookie.indexOf(";",c_start);if (c_end==-1){ c_end=document.cookie.length;}return unescape(document.cookie.substring(c_start,c_end));}}return "";}

function setCookie(formName, propName, propValue, expiredays){
var exdate=new Date();	
expiredays=30;
exdate.setDate(exdate.getDate()+expiredays);
if((formName == "HotelsSearch" && propName == "hotelCity") || (formName == "CarsSearch" && propName == "pickupCity") || (formName == "FlightsSearch" && propName == "arrCity")){
	document.cookie="HotelsSearch.hotelCity="+escape(propValue)+((expiredays==null)?"" : ";expires="+exdate.toGMTString()) + "; path=/"; 
	document.cookie="CarsSearch.pickupCity=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/"; 
	document.cookie="FlightsSearch.arrCity=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";}
	else if((formName == "HotelsSearch" && propName == "Hoteldatein") || (formName == "CarsSearch" && propName == "pickupDate") ||(formName == "FlightsSearch" && propName == "departDate")){	
	document.cookie="HotelsSearch.Hoteldatein=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";	
	document.cookie="CarsSearch.pickupDate=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";
	document.cookie="FlightsSearch.departDate=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";	
	}else if((formName == "HotelsSearch" && propName == "Hoteldateout") ||(formName == "CarsSearch" && propName == "dropoffDate") ||(formName == "FlightsSearch" && propName == "returnDate")){	document.cookie="HotelsSearch.Hoteldateout=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";document.cookie="CarsSearch.dropoffDate=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";document.cookie="FlightsSearch.returnDate=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/"; }else{	document.cookie=formName+"."+propName+"=" +escape(propValue)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + "; path=/";	}} 

function checkCookie(formName, propName, propElement, elementType, defaultValue){
propValue=getCookie(formName, propName);
	
if (propValue!=null && propValue!=""){
	if(elementType == "text"){propElement.value = propValue;} else if(elementType == "select"){propElement.selectedIndex = propValue;}else if(elementType == "travelsearchradio"){if (propValue == "hotel") { document.HotelCarFlightSearch.hotelcarflight[0].checked="checked";	show('hotel');hide('car');hide('flight');} else if(propValue == "car"){	document.HotelCarFlightSearch.hotelcarflight[1].checked="checked";show('car');hide('hotel');hide('flight');}			else if(propValue == "flight"){	document.HotelCarFlightSearch.hotelcarflight[2].checked="checked"; show('flight');hide('car');hide('hotel');}}} else {if(elementType == "text"){propElement.value = defaultValue;}}}

function updateLocationOnFocus(propElement){if(propElement.value == "city or airport"){propElement.value = "";}}

function updateDateOnFocus(propElement){if(propElement.value == "mm/dd/yyyy"){propElement.value = "";}}

function updateLocationOnBlur(propElement){if(propElement.value == null || propElement.value == ""){propElement.value = "city or airport";}}

function updateDateOnBlur(propElement){if(propElement.value == null || propElement.value == ""){propElement.value = "mm/dd/yyyy";} else {}}

function enableVacation(){document.getElementById("vacationradio").checked="checked";show('vacations');hide('cruise');}
function enableCruise(){document.getElementById("cruiseradio").checked="checked";show('cruise');hide('vacations');}
function SkipDate(dateIn,dateOut){var tmp_dateIn=getYearFromDateMDY(dateIn)+getMonthFromDateMDY(dateIn)+getDayFromDateMDY(dateIn);	var tmp_dateOut=getYearFromDateMDY(dateOut.value)+getMonthFromDateMDY(dateOut.value)+getDayFromDateMDY(dateOut.value);if(dateOut.value=="" || dateOut.value=="mm/dd/yyyy" || tmp_dateOut<tmp_dateIn){dateOut.value=dateIn;}}