﻿$(function() { $.fx.off = true; });
var calendarImagePath = "/jsscript/jquery/buttonCalendar.gif";

$(document).ready(function() {
   $(".flightAutoComplete").livequery(function() {
        $(this).autocomplete("/WordWheelService.asmx/jGetFlightCities", { highlight : false, delay: 0 } );
    });
   
   $(".hotelAutoComplete").livequery(function(){
        $(this).autocomplete("/WordWheelService.asmx/jGetHotelCities", { highlight : false, delay: 0 } );
    });
    
    $(".carAutoComplete").livequery(function(){
        $(this).autocomplete("/WordWheelService.asmx/jGetCarCities", { highlight : false, delay: 0 } );
    });
    
    $(".hotelAutoComplete").livequery(function(){
        $(this).autocomplete("/WordWheelService.asmx/jGetHotelCities", { highlight : false, delay: 0 } );
    });
    
    $(".awardAutoComplete").livequery(function(){
        $(this).autocomplete("/WordWheelService.asmx/jGetAwardTravelCities", { highlight : false, delay: 0 } );
    });
   
   loadIds(); 
});

function tabLoaded(sender, args) {
   var thePanel = args._panelsCreated[1] || args._panelsUpdated[1];
   var thePanelName = $(thePanel).children(':first-child').attr("id").match("__(.*)(?=Tab)");
   switch(thePanelName[1].toUpperCase()) {
      case "FLIGHT" : $("input[id*='departTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : departDateSelectedCallback }
      );
      var box = $("input[id*='radioTicketType_1']");
      if (!box.attr("checked")) {
         $("input[id*='returnTextBox']").datepicker( {
            showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : function(dateText, inst) {
               $("input[id*='departTextBox']").datepicker('hide') }
            }
         );
         }
      break;
      case "MULTICITY":
	            
	            //$("input:regex(id, .*departTextBox)").datepicker({
	            $("input[id$='departTextBox']").datepicker({
	                showAnim: 'show',
	                showOn: 'both',
	                showButtonPanel: true,
	                minDate: '+0d',
	                maxDate: '+330d',
	                hideIfNoPrevNext: true,
	                buttonImage: calendarImagePath,
	                buttonText: 'Click to select date',
	                numberOfMonths: 2,
	                buttonImageOnly: true,
	                constrainInput: false,
	                onSelect: departDate1SelectedCallback
		        });
		        
     				$("input[id*='departTextBox2']").datepicker({
							 showAnim: 'show',
							 showOn: 'both',
							 showButtonPanel: true,
							 minDate: '+0d',
							 maxDate: '+330d',
							 hideIfNoPrevNext: true,
							 buttonImage: calendarImagePath,
							 buttonText: 'Click to select date',
							 numberOfMonths: 2,
							 buttonImageOnly: true,
							 constrainInput: false,
							 onSelect: departDate2SelectedCallback
					  });
					  
					  $("input[id*='departTextBox3']").datepicker({
							 showAnim: 'show',
							 showOn: 'both',
							 showButtonPanel: true,
							 minDate: '+0d',
							 maxDate: '+330d',
							 hideIfNoPrevNext: true,
							 buttonImage: calendarImagePath,
							 buttonText: 'Click to select date',
							 numberOfMonths: 2,
							 buttonImageOnly: true,
							 constrainInput: false,
							 onSelect: departDate3SelectedCallback
					  });
					  
					  $("input[id*='departTextBox4']").datepicker({
							 showAnim: 'show',
							 showOn: 'both',
							 showButtonPanel: true,
							 minDate: '+0d',
							 maxDate: '+330d',
							 hideIfNoPrevNext: true,
							 buttonImage: calendarImagePath,
							 buttonText: 'Click to select date',
							 numberOfMonths: 2,
							 buttonImageOnly: true,
							 constrainInput: false,
							 onSelect: function(dateText, inst) { $("input[id*='departTextBox4']").datepicker('hide') }
					  });
		        break;
      case "HOTEL" : $("input[id*='checkInTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : checkInDateSelectedCallback }
      );
      $("input[id*='checkoutTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : function(dateText, inst) {
            $("input[id*='departTextBox']").datepicker('hide') }
         }
      );
      break;
      case "CAR" : $("input[id*='pickupTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : pickUpDateSelectedCallback }
      );
      $("input[id*='dropOffTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : function(dateText, inst) {
            $("input[id*='departTextBox']").datepicker('hide') }
         }
      );
      break;
      case "AWARDTRAVEL" : $("input[id*='awardDepartDateTextBox']").datepicker( {
         showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : awardDepartDateSelectedCallback }
      );
      var select = $("select[id*='typesDropDownList']");
      if (select.attr("selectedIndex") != 1) {
         $("input[id*='awardReturnDateTextBox']").datepicker( {
            showAnim : 'show', showOn : 'both', showButtonPanel : true, minDate : '+0d', maxDate : '+330d', hideIfNoPrevNext : true, buttonImage : calendarImagePath, buttonText : 'Click to select date', numberOfMonths : 2, buttonImageOnly : true, constrainInput : false, onSelect : function(dateText, inst) {
               $("input[id*='departTextBox']").datepicker('hide') }
            }
         );
         }
      break;
      }
   loadIds();
   wordWheel(thePanelName[1]);
   }
function departDateSelectedCallback(date, instance) {
   $("input[id*='departTextBox']").datepicker('hide');
   var day = 1000 * 60 * 60 * 24;
   var now = new Date();
   $("input[id*='returnTextBox']").datepicker('option', 'minDate', Math.ceil(((Date.parse(date) - now) /day)) + 'd');
   }
function awardDepartDateSelectedCallback(date, instance) {
   $("input[id*='awardDepartDateTextBox']").datepicker('hide');
   var day = 1000 * 60 * 60 * 24;
   var now = new Date();
   $("input[id*='awardReturnDateTextBox']").datepicker('option', 'minDate', Math.ceil(((Date.parse(date) - now) /day)) + 'd');
   }
function checkInDateSelectedCallback(date, instance) {
   $("input[id*='checkInTextBox']").datepicker('hide');
   var day = 1000 * 60 * 60 * 24;
   var now = new Date();
   $("input[id*='checkoutTextBox']").datepicker('option', 'minDate', (Math.ceil(((Date.parse(date) - now) /day)) + 1) + 'd');
   }
function pickUpDateSelectedCallback(date, instance) {
   $("input[id*='pickupTextBox']").datepicker('hide');
   var day = 1000 * 60 * 60 * 24;
   var now = new Date();
   $("input[id*='dropOffTextBox']").datepicker('option', 'minDate', (Math.ceil(((Date.parse(date) - now) /day)) + 1) + 'd');
   }
   function departDate1SelectedCallback(date, instance){
		$("input[id*='departTextBox']").datepicker('hide');
		
		var day = 1000 * 60 * 60 * 24;
		var now = new Date();
		
		$("input[id*='departTextBox2']").datepicker('option', 'minDate', Math.ceil(((Date.parse(date) - now) /day)) + 'd');	
	}
	
	function departDate2SelectedCallback(date, instance){
		$("input[id*='departTextBox2']").datepicker('hide');
		
		var day = 1000 * 60 * 60 * 24;
		var now = new Date();
		
		$("input[id*='departTextBox3']").datepicker('option', 'minDate', Math.ceil(((Date.parse(date) - now) /day)) + 'd');	
	}
	
	function departDate3SelectedCallback(date, instance){
		$("input[id*='departTextBox3']").datepicker('hide');
		
		var day = 1000 * 60 * 60 * 24;
		var now = new Date();
		
		$("input[id*='departTextBox4']").datepicker('option', 'minDate', Math.ceil(((Date.parse(date) - now) /day)) + 'd');	
	}
var flightDepartDateId, flightReturnDateId, flightDateValidatorId, flightCitiesValidatorId, flightCityOneId, flightCityTwoId, flightRoundTripId;
var flightPassengersId, flightInfantsId, flightPassengersValidatorId;
var hotelDateOneId, hotelDateTwoId, hotelCityOneId, hotelDateValidatorId, hotelCityValidatorId;
var carDateOneId, carDateTwoId, carCityOneId, carPickupTimeId, carCityValidatorId, carDateValidatorId;
var awardDateOneId, awardDateTwoId, awardCityOneId, awardCityTwoId, awardCityValidatorId, awardDateValidatorId, awardTypeId;
var awardPassengersId, awardInfantsId, awardPassengersValidatorId;
var flightHiddenScript, hotelHiddenScript, carHiddenScript, awardHiddenScript, multiHiddenScript;

var multiDateOneId, multiDateTwoId, multiDateThreeId, multiDateFourId;

function loadIds() {
   flightDateValidatorId = $("#_flightPanel").find("span[id$='_flightDateCustomValidator']").attr("id");
   flightCitiesValidatorId = $("#_flightPanel").find("span[id$='_flightCitiesCustomValidator']").attr("id");
   flightCityOneId = $("#_flightPanel").find("input[id$='_fromCitiesTextBox']").attr("id");
   flightCityTwoId = $("#_flightPanel").find("input[id$='_toCitiesTextBox']").attr("id");
   flightDepartDateId = $("#_flightPanel").find("input[id$='_departTextBox']").attr("id");
   flightReturnDateId = $("#_flightPanel").find("input[id$='_returnTextBox']").attr("id");
   flightRoundTripId = $("#_flightPanel").find("span[id$='_radioTicketType']").attr("id");
   flightHiddenScript = $("#_flightPanel").find("input[id$='_hiddenScript']").attr("id");
   flightPassengersId = $("#_flightPanel").find("select[id$='_passengersDropDown']").attr("id");
   flightInfantsId = $("#_flightPanel").find("select[id$='_infantDropDown']").attr("id");
   flightPassengersValidatorId = $("#_flightPanel").find("span[id$='_passInfantCustomValidator']").attr("id");
   
   multiHiddenScript = $("#_multiPanel").find("input[id$='_hiddenScriptField']").attr("id");
   multiDateOneId = $("#_multiPanel").find("input[id$='_departTextBox']").attr("id");
   multiDateTwoId = $("#_multiPanel").find("input[id$='_departTextBox2']").attr("id");
   multiDateThreeId = $("#_multiPanel").find("input[id$='_departTextBox3']").attr("id");
   multiDateFourId = $("#_multiPanel").find("input[id$='_departTextBox4']").attr("id");
   
   hotelDateOneId = $("#_hotelPanel").find("input[id$='_checkInTextBox']").attr("id");
   hotelDateTwoId = $("#_hotelPanel").find("input[id$='_checkoutTextBox']").attr("id");
   hotelCityOneId = $("#_hotelPanel").find("input[id$='_hotelCitiesTextBox']").attr("id");
   hotelHiddenScript = $("#_hotelPanel").find("input[id$='_hiddenScript']").attr("id");
   hotelDateValidatorId = $("#_hotelPanel").find("span[id$='_hotelDateCustomValidator']").attr("id");
   hotelCityValidatorId = $("#_hotelPanel").find("span[id$='_hotelCityCustomValidator']").attr("id");
   carDateOneId = $("#_carPanel").find("input[id$='_pickupTextBox']").attr("id");
   carDateTwoId = $("#_carPanel").find("input[id$='_dropOffTextBox']").attr("id");
   carPickupTimeId = $("#_carPanel").find("select[id$='_pickupTimeDropDown']").attr("id");
   carCityOneId = $("#_carPanel").find("input[id$='_carAirportTextBox']").attr("id");
   carCityValidatorId = $("#_carPanel").find("span[id$='_carCitiesCustomValidator']").attr("id");
   carDateValidatorId = $("#_carPanel").find("span[id$='_carDateCustomValidator']").attr("id");
   carHiddenScript = $("#_carPanel").find("input[id$='_hiddenScript']").attr("id");
   awardDateOneId = $("#_awardPanel").find("input[id$='_awardDepartDateTextBox']").attr("id");
   awardDateTwoId = $("#_awardPanel").find("input[id$='_awardReturnDateTextBox']").attr("id");
   awardCityOneId = $("#_awardPanel").find("input[id$='_fromCitiesTextBox']").attr("id");
   awardCityTwoId = $("#_awardPanel").find("input[id$='_toCitiesTextBox']").attr("id");
   awardTypeId = $("#_awardPanel").find("select[id$='_typesDropDownList']").attr("id");
   awardHiddenScript = $("#_awardPanel").find("input[id$='_hiddenScriptAward']").attr("id");
   awardCityValidatorId = $("#_awardPanel").find("span[id$='_flightCitiesCustomValidator']").attr("id");
   awardDateValidatorId = $("#_awardPanel").find("span[id$='_flightDateCustomValidator']").attr("id");
   awardPassengersId = $("#_awardPanel").find("select[id$='_passengersDropDownList']").attr("id");
   awardInfantsId = $("#_awardPanel").find("select[id$='_infantsDropDownList']").attr("id");
   awardPassengersValidatorId = $("#_awardPanel").find("span[id$='_awardPassInfantCustomValidator']").attr("id");
   }

function FlightDateValidator(source, args) {
   DateValidator(source, args, "Flight");
   }
function HotelDateValidator(source, args) {
   DateValidator(source, args, "Hotel");
   }
function CarDateValidator(source, args) {
   DateValidator(source, args, "Car");
   }
function AwardDateValidator(source, args) {
   DateValidator(source, args, "AwardTravel");
   }
function flightCitiesValidation(source, args) {
   CitiesValidation(source, args, "Flight");
   }
function AwardCitiesValidation(source, args) {
   CitiesValidation(source, args, "AwardTravel");
   }
function CarCitiesValidator(source, args) {
   CitiesValidation(source, args, "Car");
   }
function HotelCityValidator(source, args) {
   CitiesValidation(source, args, "Hotel");
   }
function DateValidator(source, args, tab) {
   var errorMessage = "";
   var validator = "";
   var dateOne = "";
   var dateTwo = "";
   var typeOne = "";
   var typeTwo = "";
   var roundtrip = "";
   var pickUpTime = "";
   var dateOneMonth = "";
   var dateOneDay = "";
   var dateOneYear = "";
   var myDateOne = "";
   var dateTwoMonth = "";
   var dateTwoDay = "";
   var dateTwoYear = "";
   var myDateTwo = "";
   var breakline = "";
   var tab = tab;
   var isOneWay;
   switch(tab) {
      case "Flight" : var validatorFlight = document.getElementById(flightDateValidatorId);
      var dateOneFlight = document.getElementById(flightDepartDateId);
      var dateTwoFlight = document.getElementById(flightReturnDateId);
      roundtrip = document.getElementById(flightRoundTripId);
      var typeOneFlight = "Departure";
      var typeTwoFlight = "Return";
      break;
      case "Hotel" : var validatorHotel = document.getElementById(hotelDateValidatorId);
      var dateOneHotel = document.getElementById(hotelDateOneId);
      var dateTwoHotel = document.getElementById(hotelDateTwoId);
      var typeOneHotel = "Check-in";
      var typeTwoHotel = "Check-out";
      case "Car" : var validatorCar = document.getElementById(carDateValidatorId);
      var dateOneCar = document.getElementById(carDateOneId);
      var dateTwoCar = document.getElementById(carDateTwoId);
      pickUpTime = document.getElementById(carPickupTimeId);
      var typeOneCar = "Pick up";
      var typeTwoCar = "Drop off";
      break;
      case "AwardTravel" : var validatorAwardTravel = document.getElementById(awardCityValidatorId);
      var dateOneAwardTravel = document.getElementById(awardDateOneId);
      var dateTwoAwardTravel = document.getElementById(awardDateTwoId);
      isOneWay = (document.getElementById(awardTypeId).value == "YXOW15");
      var typeOneAwardTravel = "Departure";
      var typeTwoAwardTravel = "Return";
      break;
      }
   validator = eval("validator" + tab);
   dateOne = eval("dateOne" + tab);
   dateTwo = eval("dateTwo" + tab);
   typeOne = eval("typeOne" + tab);
   typeTwo = eval("typeTwo" + tab);
   if (tab == "Car") pickUpTime = pickUpTime.options[pickUpTime.selectedIndex].value;
   else pickUpTime = null;
   dateOneMonth = dateOne.value.split("/")[0];
   dateOneDay = dateOne.value.split("/")[1];
   dateOneYear = dateOne.value.split("/")[2];
   if(dateOneYear.length == 2) dateOneYear = "20" + dateOneYear;
   myDateOne = new Date(dateOneYear, dateOneMonth - 1, dateOneDay);
   dateTwoMonth = dateTwo.value.split("/")[0];
   dateTwoDay = dateTwo.value.split("/")[1];
   dateTwoYear = dateTwo.value.split("/")[2];
   if(dateTwoYear.length == 2) dateTwoYear = "20" + dateTwoYear;
   myDateTwo = new Date(dateTwoYear, dateTwoMonth - 1, dateTwoDay);
   //validate date one
   if(validateDate(dateOne.value, typeOne, pickUpTime) != "") {
      args.IsValid = false;
      errorMessage = validateDate(dateOne.value, typeOne, pickUpTime);
      }
   breakline = "";
   if(!args.IsValid) breakline = "<br />";
   if((tab != "Flight") || (!roundtrip.checked)) {
      if((tab != "AwardTravel") || (!isOneWay)) {
         if(validateDate(dateTwo.value, typeTwo, null) != "") {
            args.IsValid = false;
            errorMessage += breakline + validateDate(dateTwo.value, typeTwo, null);
            }
         }
      }
   if (args.IsValid) {
      if(tab == "Hotel") {
         if(myDateOne.valueOf() == myDateTwo.valueOf()) {
            args.IsValid = false;
            errorMessage = typeTwo + " date cannot be the same as " + typeOne + " date.";
            }
         else {
            if(myDateTwo.valueOf() < myDateOne.valueOf()) {
               args.IsValid = false;
               errorMessage = "Please ensure your " + typeOne + " and " + typeTwo + " dates are in the proper order.";
               }
            }
         }
      else if (!(tab == "Flight" && roundtrip.checked) && !(tab == "AwardTravel" && isOneWay)) {
         if(myDateTwo.valueOf() < myDateOne.valueOf()) {
            args.IsValid = false;
            errorMessage = "Please ensure your " + typeOne + " and " + typeTwo + " dates are in the proper order.";
            }
         }
      }
   validator.errormessage = errorMessage;
   }
function validateDate(date, myType, myPickUpTime) {
   var date = date;
   var myType = myType;
   var myPickUpTime = myPickUpTime;
   var errorMessage = "";
   var todayDate = new Date();
   var todayDateDay = todayDate.getDate();
   var todayDateMonth = todayDate.getMonth();
   var todayDateYear = todayDate.getFullYear();
   var todayDateFull = new Date (todayDateYear, todayDateMonth, todayDateDay);
   var tomorrowDateFull = new Date();
   tomorrowDateFull.setFullYear(todayDate.getFullYear(), [todayDate.getMonth()], [todayDate.getDate() + 1]);
   var validformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;
   var myMin;
   var hours;
   var min;
   var time;
   var oneFutureYear = new Date();
   oneFutureYear.setFullYear(todayDateYear, [todayDateMonth], [todayDateDay + 330]);
   var today = "today";
   var dateMonth;
   var dateDay;
   var dateYear;
   var myDate;
   if (validformat.test(date)) {
      dateMonth = date.split("/")[0];
      dateDay = date.split("/")[1];
      dateYear = date.split("/")[2];
      if(dateYear.length == 2) {
         dateYear = "20" + dateYear;
         }
      myDate = new Date(dateYear, dateMonth - 1, dateDay);
      }
   if (date == "") {
      errorMessage = "Please enter a " + myType + " date.";
      }
   //if field isn't a valid datetime
   else if (!validformat.test(date)) {
      errorMessage = "Please enter a valid " + myType + " date.";
      }
   else if ((dateMonth > 12) || (dateDay < 1) || dateDay > 31) {
      errorMessage = "Please enter a valid " + myType + " date.";
      }
   else if ( myDate.valueOf() < todayDateFull.valueOf()) {
      errorMessage = myType + " date cannot be prior to " + today + "'s date.";
      }
   else if(myPickUpTime != null) {
      if (myDate.valueOf() == todayDateFull.valueOf()) {
         //pickUpTime
         myMin = myPickUpTime;
         hours = todayDate.getHours();
         min = todayDate.getMinutes();
         hours = hours * 60;
         min = min + 359;
         time = parseInt(hours + min);
         if(myMin < time) {
            errorMessage = "Pick up time needs to be at least 6 hours in the future.";
            }
         }
      }
   else if(myDate.valueOf() > oneFutureYear.valueOf()) {
      errorMessage = myType + " date cannot be more than 330 days in the future.";
      }
   else if (dateMonth == 2) {
      if (((dateYear % 400) != 0) || (((dateYear % 4) != 0) && !((dateYear % 100) != 0))) {
         if(dateDay > 28) {
            errorMessage = "Please enter a valid " + myType + " date.";
            }
         }
      }
   else if ((dateMonth != 1) && (dateMonth != 3) && (dateMonth != 5) && (dateMonth != 7) && (dateMonth != 8) && (dateMonth != 10) && (dateMonth != 12)) {
      if(dateDay == 31) {
         errorMessage = "Please enter a valid " + myType + " date.";
         }
      }
   return errorMessage;
   //end function
   }
function CitiesValidation(source, args, tab) {
   //validating the cities drop down or ajax textboxes.
   var errorMessage = "";
   var validator = "";
   var scriptDiv = "";
   var cityOne = "";
   var cityTwo = "";
   var breakline = "";
   var errorMessageCityOne = "";
   var tab = tab;
   switch(tab) {
      case "Flight" : var validatorFlight = document.getElementById(flightCitiesValidatorId);
      var scriptDivFlight = document.getElementById("_scriptFromCities");
      var cityOneFlight = document.getElementById(flightCityOneId);
      var cityTwoFlight = document.getElementById(flightCityTwoId);
      break;
      case "Hotel" : var validatorHotel = document.getElementById(hotelCityValidatorId);
      var scriptDivHotel = document.getElementById("_scriptHotel");
      var cityOneHotel = document.getElementById(hotelCityOneId);
      break;
      case "Car" : var validatorCar = document.getElementById(carCityValidatorId);
      var scriptDivCar = document.getElementById("_scriptCar");
      var cityOneCar = document.getElementById(carCityOneId);
      break;
      case "AwardTravel" : var validatorAwardTravel = document.getElementById(awardCityValidatorId);
      var scriptDivAwardTravel = document.getElementById("_scriptFromCitiesAward");
      var cityOneAwardTravel = document.getElementById(awardCityOneId);
      var cityTwoAwardTravel = document.getElementById(awardCityTwoId);
      break;
      }
   validator = eval("validator" + tab);
   scriptDiv = eval("scriptDiv" + tab);
   cityOne = eval("cityOne" + tab);
   if((tab == "Flight") || (tab = "AwardTravel")) {
      cityTwo = eval("cityTwo" + tab);
      errorMessageCityOne = "Departure city/airport is required.";
      }
   else {
      cityTwo = "";
      errorMessageCityOne = "Airport/City is required.";
      }
   if(scriptDiv.style.display != "none") {
      //script is on
      if(cityOne.value == "") {
         args.IsValid = false;
         errorMessage = errorMessageCityOne;
         breakline = "<br />";
         }
      if((tab == "Flight") || (tab = "AwardTravel")) {
         if((cityTwo != null) && (cityTwo.value == "")) {
            args.IsValid = false;
            errorMessage += breakline + "Arrival city/airport is required.";
            }
         if(args.IsValid) {
            if((cityTwo != null) && (cityOne.value == cityTwo.value)) {
               args.IsValid = false;
               errorMessage = "Arrival city/airport cannot be the same as the departure city/airport.";
               }
            }
         }
      }
   validator.errormessage = errorMessage;
   }
function infant(source, args) {
   var passengers = document.getElementById(flightPassengersId);
   var infants = document.getElementById(flightInfantsId);
   var validator = document.getElementById(flightPassengersValidatorId);
   if (passengers.options[passengers.selectedIndex].value < infants.options[infants.selectedIndex].value) {
      validator.errormessage = "Number of in lap infants cannot be more than the number of passengers.";
      args.IsValid = false;
      }
   }
function infantAward(source, args) {
   var passengers = document.getElementById(awardPassengersId);
   var infants = document.getElementById(awardInfantsId);
   var validator = document.getElementById(awardPassengersValidatorId);
   if (passengers.options[passengers.selectedIndex].value < infants.options[infants.selectedIndex].value) {
      validator.errormessage = "Number of in lap infants cannot be more than the number of passengers.";
      args.IsValid = false;
      }
   }
function wordWheel(tab) {
   var noScriptOne;
            var noScriptTwo;
            var noScriptThree;
            var noScriptFour;
            var noScriptFive;
            var noScriptSix;
            var noScriptSeven;
            var noScriptEight;
            var scriptOne;
            var scriptTwo;
            var scriptThree;
            var scriptFour;
            var scriptFive;
            var scriptSix;
            var scriptSeven;
            var scriptEight;
            
            var hiddenScript;
            var ImgOne;
            var ImgTwo;
            var ImgThree;
            var ImgFour;
   switch(tab) {
      case "flight" : noScriptOne = document.getElementById("_noScriptToCities");
      noScriptTwo = document.getElementById("_noScriptFromCities");
      scriptOne = document.getElementById("_scriptToCities");
      scriptTwo = document.getElementById("_scriptFromCities");
      hiddenScript = document.getElementById(flightHiddenScript);
      ImgOne = document.getElementById("departDateImage");
      ImgTwo = document.getElementById("returnDateImage");
      break;
      case "multi":
            noScriptOne = document.getElementById("_noScriptToCity1");
            noScriptTwo = document.getElementById("_noScriptFromCity1");
            scriptOne = document.getElementById("_scriptToCity1");
            scriptTwo = document.getElementById("_scriptFromCity1");
            noScriptThree = document.getElementById("_noScriptToCity2");
            noScriptFour = document.getElementById("_noScriptFromCity2");
            scriptThree = document.getElementById("_scriptToCity2");
            scriptFour = document.getElementById("_scriptFromCity2");
            noScriptFive = document.getElementById("_noScriptToCity3");
            noScriptSix = document.getElementById("_noScriptFromCity3");
            scriptFive = document.getElementById("_scriptToCity3");
            scriptSix = document.getElementById("_scriptFromCity3");
            noScriptSeven = document.getElementById("_noScriptToCity4");
            noScriptEight = document.getElementById("_noScriptFromCity4");
            scriptSeven = document.getElementById("_scriptToCity4");
            scriptEight = document.getElementById("_scriptFromCity4");
            hiddenScript = document.getElementById(multiHiddenScript);
            ImgOne = document.getElementById("departDateImage");
            ImgTwo = document.getElementById("departDateImage2");
            ImgThree = document.getElementById("departDateImage3");
            ImgFour = document.getElementById("departDateImage4");
        break;
      case "hotel" : noScriptOne = document.getElementById("_noScriptHotel");
      scriptOne = document.getElementById("_scriptHotel");
      hiddenScript = document.getElementById(hotelHiddenScript);
      ImgOne = document.getElementById("checkInImage");
      ImgTwo = document.getElementById("checkOutImage");
      break;
      case "car" : noScriptOne = document.getElementById("_noScriptCar");
      scriptOne = document.getElementById("_scriptCar");
      hiddenScript = document.getElementById(carHiddenScript);
      ImgOne = document.getElementById("pickupImage");
      ImgTwo = document.getElementById("dropOffImage");
      break;
      case "awardTravel" : noScriptOne = document.getElementById("_noScriptToCitiesAward");
      noScriptTwo = document.getElementById("_noScriptFromCitiesAward");
      scriptOne = document.getElementById("_scriptToCitiesAward");
      scriptTwo = document.getElementById("_scriptFromCitiesAward");
      hiddenScript = document.getElementById(awardHiddenScript);
      ImgOne = document.getElementById("departDateImageAward");
      ImgTwo = document.getElementById("returnDateImageAward");
      break;
      }
   if(noScriptOne != null) {
      noScriptOne.style.display = "none";
      scriptOne.style.display = "inline";
      hiddenScript.value = "on";
      if(noScriptTwo != null) {
         noScriptTwo.style.display = "none";
         scriptTwo.style.display = "inline";
         }
     if(noScriptThree != null) {
         noScriptThree.style.display="none";
         scriptThree.style.display="inline";
         noScriptFour.style.display="none";
         scriptFour.style.display="inline";
         noScriptFive.style.display="none";
         scriptFive.style.display="inline";
         noScriptSix.style.display="none";
         scriptSix.style.display="inline";
         noScriptSeven.style.display="none";
         scriptSeven.style.display="inline";
         noScriptEight.style.display="none";
         scriptEight.style.display="inline";
         //ImgThree.style.display="inline";
         //ImgFour.style.display="inline";
         }
      }
   }
function hideDropDown(tab, stats, control) {
   //if IE6 then maxHeight is undefined.
   //hide drop down controls when ajax controls are displayed.
   if (typeof document.body.style.maxHeight == "undefined") {
      switch(tab) {
         case "flight" : break;
         case "awardTravel" : break;
         case "car" : if(control != 'cal') {
            if(stats == 'hide') {
               document.getElementById('carDropDown').style.display = 'none';
               }
            else {
               document.getElementById('carDropDown').style.display = 'inline';
               }
            }
         //this to control the click on the cal icon.
         else {
            if(document.getElementById('carDropDown').style.display != 'none') {
               document.getElementById('carDropDown').style.display = 'none';
               }
            else {
               document.getElementById('carDropDown').style.display = 'inline';
               }
            }
         break;
         case "hotel" : if(stats == 'hide') {
            if(control == 'in') {
               document.getElementById('numberRooms').style.display = 'none';
               document.getElementById('numberChildren').style.display = 'none';
               }
            else if (control == 'out') {
               document.getElementById('numberAdults').style.display = 'none';
               }
            else if(control == 'cal1') {
               if(document.getElementById('numberRooms').style.display != 'none') {
                  document.getElementById('numberRooms').style.display = 'none';
                  document.getElementById('numberChildren').style.display = 'none';
                  }
               else {
                  document.getElementById('numberRooms').style.display = 'block';
                  document.getElementById('numberChildren').style.display = 'block';
                  }
               }
            else if (control == 'cal2') {
               if(document.getElementById('numberAdults').style.display != 'none') {
                  document.getElementById('numberAdults').style.display = 'none';
                  }
               else {
                  document.getElementById('numberAdults').style.display = 'block';
                  }
               }
            }
         else {
            if(control == 'in') {
               document.getElementById('numberRooms').style.display = 'block';
               document.getElementById('numberChildren').style.display = 'block';
               }
            else if(control == 'out') {
               document.getElementById('numberAdults').style.display = 'block';
               }
            }
         break;
         }
      }
   }
function updateDate(tab) {
   var validformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;
   var validDateNoYear = /^\d{1,2}(\-|\/|\.)\d{1,2}$/;
   var date;
   var dateOne;
   var dateTwo;
   var calendar;
   switch(tab) {
      case "Flight" : var dateOneFlight = document.getElementById("<%= _flightTab.DepartDate.ClientID %>");
      var dateTwoFlight = document.getElementById("<%= _flightTab.ReturnDate.ClientID %>");
      var calendarFlight = "<%=_flightTab.ReturnCalendar.ClientID%>";
      break;
      case "Hotel" : var dateOneHotel = document.getElementById("<%=_hotelTab.CheckInDate.ClientID %>");
      var dateTwoHotel = document.getElementById("<%=_hotelTab.CheckOutDate.ClientID %>");
      var calendarHotel = "<%=_hotelTab.CheckOutCalendar.ClientID%>";
      break;
      case "Car" : var dateOneCar = document.getElementById("<%= _carTab.PickUpDate.ClientID %>");
      var dateTwoCar = document.getElementById("<%= _carTab.DropOffDate.ClientID %>");
      var calendarCar = "<%=_carTab.DropOffCalendar.ClientID%>";
      break;
      case "AwardTravel" : var dateOneAwardTravel = document.getElementById("<%= _awardTravelTab.DepartDate.ClientID %>");
      var dateTwoAwardTravel = document.getElementById("<%= _awardTravelTab.ReturnDate.ClientID %>");
      var calendarAwardTravel = "<%=_awardTravelTab.ReturnCalendar.ClientID%>";
      break;
      case "Multi":
            var dateOneMulti = document.getElementById("<%= _multiCityTab.DepartDate1.ClientID %>");
            var dateTwoMulti = document.getElementById("<%= _multiCityTab.DepartDate2.ClientID %>");
            dateThree = document.getElementById("<%= _multiCityTab.DepartDate3.ClientID %>");
            dateFour = document.getElementById("<%= _multiCityTab.DepartDate4.ClientID %>");
            break;
      }
   dateOne = eval("dateOne" + tab);
   dateTwo = eval("dateTwo" + tab);
   calendar = eval("calendar" + tab);
   if(!validformat.test(dateOne.value)) {
      if(validDateNoYear.test(dateOne.value)) {
         date = noYearDate(dateOne.value);
         dateOne.value = date;
         if(tab != "Multi") {
            updateValid(date);
        }
         }
      }
   //if(validformat.test(dateOne.value))
   else {
       if(tab != "Multi") { updateValid(dateOne.value); }
      }
   if(!validformat.test(dateTwo.value) && validDateNoYear.test(dateTwo.value)) {
      date = noYearDate(dateTwo.value);
      dateTwo.value = date;
      }
      if(tab == "Multi")
            {
             if(!validformat.test(dateThree.value) && validDateNoYear.test(dateThree.value))
                {
                    date = noYearDate(dateThree.value);
                    dateThree.value = date;
                }
             if(!validformat.test(dateFour.value) && validDateNoYear.test(dateFour.value))
                {
                    date = noYearDate(dateFour.value);
                    dateFour.value = date;
                }
            }
   }
   
function saveDateFieldName (tab, fieldname) {
   var field;
   var field2;
   var calendar;
   var validformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;
   document.getElementById("_dateFieldHidden").value = fieldname;
   switch(tab) {
      case "flight" : field = flightDepartDateId;
      field2 = flightReturnDateId;
      break;
      case "car" : field = carDateOneId;
      field2 = carDateTwoId;
      break;
      case "hotel" : field = hotelDateOneId;
      field2 = hotelDateTwoId;
      break;
      case "AwardTravel" : field = awardDateOneId;
      field2 = awardDateTwoId;
      break;
      case "multi":
            switch(fieldname) {
                case "departTextBox2":
                field = multiDateOneId;
                field2 = multiDateTwoId;
                break;
                case "departTextBox3":
                field = multiDateTwoId;
                field2 = multiDateThreeId;
                break;
                case "departTextBox4":
                field = multiDateThreeId;
                field2 = multiDateFourId;
                break;
                case "none":
                field = multiDateOneId;
                field2 = multiDateTwoId;
                break;
                default:
                field = multiDateOneId;
                field2 = multiDateTwoId;
                break;
            }
        break;
      }
   if(!validformat.test(document.getElementById(field).value)) {
      document.getElementById("_dateFieldOneHidden").value = "<%# DateTime.Today.ToShortDateString()%>";
      }
   else {
      var dateMonth = document.getElementById(field).value.split("/")[0];
      var dateDay = document.getElementById(field).value.split("/")[1];
      var dateYear = document.getElementById(field).value.split("/")[2];
      if(dateYear.length == 2) {
         dateYear = "20" + dateYear;
         }
      var enteredDate = new Date(dateYear, dateMonth - 1, dateDay);
      var todaysDate = new Date();
      todaysDate = new Date(todaysDate.getFullYear(), todaysDate.getMonth(), todaysDate.getDate());
      var oneFutureYear = new Date();
      oneFutureYear.setFullYear(todaysDate.getFullYear(), [todaysDate.getMonth()], [todaysDate.getDate() + 330]);
      if(enteredDate.valueOf() < todaysDate.valueOf()) {
         document.getElementById("_dateFieldOneHidden").value = "<%# DateTime.Today.ToShortDateString()%>";
         //document.getElementById(field).value = "mm/dd/yyyy";
         }
      else if(enteredDate.valueOf() > oneFutureYear.valueOf()) {
         document.getElementById("_dateFieldOneHidden").value = "<%# DateTime.Today.AddDays(330).ToShortDateString()%>";
         }
      else {
         var myDate = dateMonth + "/" + dateDay + "/" + dateYear;
         document.getElementById(field).value = myDate;
         document.getElementById("_dateFieldOneHidden").value = myDate;
         }
      }
   if(validformat.test(document.getElementById(field2).value)) {
      dateMonth = document.getElementById(field2).value.split("/")[0];
      dateDay = document.getElementById(field2).value.split("/")[1];
      dateYear = document.getElementById(field2).value.split("/")[2];
      if(dateYear.length == 2) {
         dateYear = "20" + dateYear;
         }
      var enteredDate2 = new Date(dateYear, dateMonth - 1, dateDay);
      if(enteredDate2.valueOf() < todaysDate.valueOf() || enteredDate2.valueOf() > oneFutureYear.valueOf()) {
         //document.getElementById(field2).value = "mm/dd/yyyy";
         }
      else {
         myDate = dateMonth + "/" + dateDay + "/" + dateYear;
         document.getElementById(field2).value = myDate;
         if(enteredDate2.valueOf() > enteredDate.valueOf()) {
            document.getElementById("_dateFieldTwoHidden").value = myDate;
            document.getElementById("valid").value = "valid";
            }
         else {
            document.getElementById("valid").value = "none";
            }
         }
      }
   }
   
    var index = 0;
    var timerId;
        
    function nextImage() {
        setTextDecoration(index, '');
        index++;
    
        if (index == rotatingImages.length)
            index = 0;
    
        setImage(index);
    }
    
    function previousImage() {
        setTextDecoration(index, '');
        index--;
    
        if (index == -1)
            index = (rotatingImages.length - 1);
    
        setImage(index);
    }
            
    function setImage(imageIndex) {
        clearTimeout(timerId);
        setTextDecoration(index, '');
        index = imageIndex;
        setTextDecoration(imageIndex, 'underline');
    
        var image = document.getElementById('rotatingImage');
        var link = document.getElementById('rotatingImageLink');
        image.src = rotatingImages[index][0];
        link.href = rotatingImages[index][1];
        timerId = setTimeout(nextImage, 5000);
    }
    
    function setTextDecoration(numberIndex, value) {
        var numberLink = document.getElementById('_number' + numberIndex);
        numberLink.style.textDecoration = value;
    }
            
    function loadQuickLinks() {
        $.post("/Common/ContentService.asmx/LoadHomePageImages", imageLinksLoaded, "xml");
    }
                    
    var rotatingImages = new Array();
                    
    function imageLinksLoaded(data) {
        var index = 0;
        $(data).find("ImageLink").each(function() {
               rotatingImages[index] = [$(this).find("ImageUrl").text(), $(this).find("Address").text()];
               
               var item = $("#numberButtonClone").clone().css("display","inline").attr("id","_number" + index);
               item.attr("onclick", "setImage(" + index + ")");
               if (index == 0)
                   item.css("text-decoration", "underline");
                   
               item.html(index + 1);
               //item.children("a").text($(this).find("Title").text()).attr("href", $(this).find("Address").text()).attr("target", $(this).find("NewWindow").text() == "true" ? "_blank" : "");
               item.appendTo($("#_imageButtons"));
               
               index++;
        });
        timerId = setTimeout(nextImage, 5000);
        $("#_imageButtons").toggle();
    }
    
   