function SetYear(form)
{ 
	var today = new Date(); 
	var vacDate = new Date(today.getFullYear(),form.DEPARTMONTH.selectedIndex,form.DEPARTDAY.selectedIndex+1); 

	if (vacDate <= today) 
	{ 
		form.DEPARTYEAR.value = today.getFullYear() + 1;
	} 
	else 
	{ 
		form.DEPARTYEAR.value = today.getFullYear();
	}
	
	checkDateIsValid(form);
}

function SetCarHotel(form,type) 
{ 
	var Dest = form.DEST.value; 
	
	if (type == "car") 
	{ 
		form.action = "http://alaska.wwte.com/pubspec/scripts/eap.asp?goto=carsearch&eapid=0-30003&PickUpLoc=" + Dest;
	}
	else 
	{ 
		form.action = "http://alaska.wwte.com/pubspec/scripts/eap.asp?goto=hotsearch&eapid=0-30003&CityName=" + Dest;
	}
}

function checkFormCount()
{ 
	ShowVacationType()
	
	HideElement(GetErrorMsgElement(''));
	HideElement(GetErrorMsgElement('2'));
	HideElement(GetArrowElement(''));
	HideElement(GetArrowElement('2'));
	HideElement(document.getElementById('LAPCHILDERRORMSG'));
	
	for(i=0; i<document.forms.length; i++) 
	{ 
		if(document.forms[i].name == "frmVacations") 
		{ 
			checkPaxCount(document.forms[i]); break;
		}
	}
}

function checkOrigCityEntered(form)
{ 
	var retval = true;
	var oOrigin = GetOriginElement(form);
	var oError = GetErrorMsgElement('');
	var oArrow = GetArrowElement('');
	var olabel = document.getElementById('FROM');
	
	if(oOrigin == null){ return false;}
	
	if(oOrigin.selectedIndex == 0 || oOrigin.value == "-" || oOrigin.value == document.getElementById('gsDestination').value)
	{ 
		DisplayElement(oError);
		DisplayElement(oArrow);
		SetClassName(document.getElementById('FROM'), 'sub2red');
		retval = false;
	}
	if(retval == true)
	{ 
		HideElement(oError);
		HideElement(oArrow);
		SetClassName(document.getElementById('FROM'), '');
	}
	return retval;
}

function checkDestCityEntered(form)
{ 
	var retval = true;
	var oDestination = GetDestinationElement(form);
	var oError = GetErrorMsgElement('5');
	var oArrow = GetArrowElement('5');
	var olabel = document.getElementById('TO');
	
	if(oDestination == null){ return false;}
	
	if(oDestination.selectedIndex == 0 || oDestination.value == "-" || oDestination.value == document.getElementById('gsOrigin').value)
	{ 
		DisplayElement(oError);
		DisplayElement(oArrow);
		SetClassName(document.getElementById('TO'), 'sub2red');
		retval = false;
	}
	if(retval == true)
	{ 
		HideElement(oError);
		HideElement(oArrow);
		SetClassName(document.getElementById('TO'), '');
	}
	return retval;
}

function checkPromoCodeEntered(form)
{ 
	var retval = true;
	var sPromoCode = document.frmVacations.gsPromotionCode.value;
	var oError = GetErrorMsgElement('4');
	var oArrow = GetArrowElement('4');
	var olabel = document.getElementById('PROMOCODE');
				
	if(!sPromoCode == "" && !IsAlphaNumeric(sPromoCode))
	{ 
		DisplayElement(oError);
		DisplayElement(oArrow);
		SetClassName(document.getElementById('PROMOCODE'), 'sub2red');
		retval = false;
	}
	if(retval == true)
	{ 
		HideElement(oError);
		HideElement(oArrow);
		SetClassName(document.getElementById('PROMOCODE'), '');
	}
	return retval;
}

function IsAlphaNumeric(checkStr)
{		
	checkStr = checkStr.toLowerCase();
	return /^[a-zA-Z\d]+$/.test(checkStr);		
}

function DisplayElement(elem)
{
	if(elem != null){	elem.style.display='block';}
}
function HideElement(elem)
{
	if(elem != null){	elem.style.display='none';}
}
function SetClassName(elem, cName)
{
	if(elem != null){	elem.className=cName;}
}
function GetOriginElement(form)
{
	if(form.ORIGINENGLISH){	return form.ORIGINENGLISH;}
	if(form.gsOrigin){	return form.gsOrigin;}
	return null;
}
function GetDestinationElement(form)
{
	if(form.DESTINATIONENGLISH){	return form.DESTINATIONENGLISH;}
	if(form.gsDestination){	return form.gsDestination;}
	return null;
}
function GetErrorMsgElement(suf)
{
	if(document.getElementById('ERRORMSG'+suf)){	return document.getElementById('ERRORMSG'+suf);}
	return null;
}
function GetArrowElement(suf)
{
	if(document.getElementById('ARROW'+suf)){	return document.getElementById('ARROW'+suf);}
	return null;
}
function GetChildAgeElement(num)
{
	if(document.getElementById('CHILD'+num+'AGEID')){	return document.getElementById('CHILD'+num+'AGEID');}
	if(document.getElementById('gsAge'+num)){	return document.getElementById('gsAge'+num);}
	return null;
}
function GetNbrChildElement(form)
{
	if(form.NUMBERCHILDREN){	return form.NUMBERCHILDREN;} 
	if(form.numberChildren){	return form.numberChildren;} 
	return null;
}
function GetNbrAdultElement(form)
{
	if(form.NUMBERTRAVELERS){	return form.NUMBERTRAVELERS;} 
	if(form.numberAdults){	return form.numberAdults;} 
	return null;
}
function checkAgesOfChildren(form)
{ 
	var retval = true; 

	for(i=1; i<5; i++) 
	{ 
		var oAge = GetChildAgeElement(i);
		if(oAge != null && oAge.style.display=='block')
		{ 
			if(oAge.selectedIndex < 2)
			{ 
				DisplayElement(document.getElementById('LAPCHILDERRORMSG')); 
				SetClassName(document.getElementById('AGESLABEL'),'sub2red'); 
				retval = false; 
				break;
			}
		}
	}
	if(retval == true)
	{ 
		HideElement(document.getElementById('LAPCHILDERRORMSG')); 
		SetClassName(document.getElementById('AGESLABEL'), '');
	}
	return retval;
}
function check_form(form)
{	
	document.getElementById('gsDepartureDate').value = document.getElementById('gsDepartureDateBox').value;
	document.getElementById('gsReturnDate').value = document.getElementById('gsReturnDateBox').value;
	
	if(document.frmVacations.VACTYPE)
	{ 
		if(document.frmVacations.VACTYPE[1].checked)
		{ 
			document.getElementById('ORIGINENGLISHID').options[1].value = "XXX"; 
			document.getElementById('ORIGINENGLISHID').options[1].selected = "true"; 
			document.getElementById('DESTINATIONID').value = document.getElementById('HOTELDESTINATIONID').value; 
			CopyHotelDates();
		}
	}
	
	cityretval = checkOrigCityEntered(form);
	destcityretval = checkDestCityEntered(form);
	agesretval = checkAgesOfChildren(form); 
	dateretval = checkDateIsValid(form);
	promoretVal = checkPromoCodeEntered(form);
	
	if(cityretval && destcityretval && agesretval && dateretval && promoretVal){	SetDateStyles();}
	if(document.getElementById('gsNumberOfTravelers')){	document.getElementById('gsNumberOfTravelers').value = GetNumTravelers(form);}
	
	return (cityretval && destcityretval && agesretval && dateretval && promoretVal);
}
function check_hotel_form(form)
{ 
	document.getElementById('gsDepartureDate').value = document.getElementById('gsDepartureDateBox').value;
	document.getElementById('gsReturnDate').value = document.getElementById('gsReturnDateBox').value;
	
	agesretval = checkAgesOfChildren(form); 
	dateretval = checkDateIsValid(form); 
	promoretVal = checkPromoCodeEntered(form);	
	if(agesretval && dateretval && promoretVal){	SetDateStyles();}
	if(document.getElementById('gsNumberOfTravelers')){	document.getElementById('gsNumberOfTravelers').value = GetNumTravelers(form);}
	
	return (agesretval && dateretval && promoretVal);
}
function GetNumTravelers(form)
{
	var oNbrChildElem = GetNbrChildElement(form);
	var oNbrAdultElem = GetNbrAdultElement(form);
	var nbrchildren=oNbrChildElem.selectedIndex;
	var nbradults=oNbrAdultElem.selectedIndex+1;
	return  (nbrchildren + nbradults)
}
function checkPaxCount(form, elm)
{ 
	var oWindow = this;
	var oFrame = oWindow.frameElement;
	var oNbrChildElem = GetNbrChildElement(form);
	var oNbrAdultElem = GetNbrAdultElement(form);
	var nbrchildren=oNbrChildElem.selectedIndex;
	var nbradults = oNbrAdultElem.selectedIndex+1;
	
	if(oFrame!=null) {
		if(oFrame.ownerDocument.URL.indexOf('tab')>0) {
			var oParentFrame = this.parent.frameElement;
			oParentFrame.height=(500+(nbrchildren*25));
		}
		oFrame.height=(450+(nbrchildren*25));
	}
 
	HideElement(document.getElementById('INFOLINE')); 
	HideElement(document.getElementById('INFOLINE2')); 
	HideElement(document.getElementById('AGESLABEL')); 
	HideElement(document.getElementById('s_in_ages'));
	HideElement(document.getElementById('gsAge1'));
	HideElement(document.getElementById('gsAge2'));
	HideElement(document.getElementById('gsAge3'));
	HideElement(document.getElementById('gsAge4'));
	HideElement(document.getElementById('CHILD1AGEID')); 
	HideElement(document.getElementById('CHILD2AGEID')); 
	HideElement(document.getElementById('CHILD3AGEID')); 
	HideElement(document.getElementById('CHILD4AGEID')); 
	
	if(nbradults + nbrchildren > 6) 
	{ 
		switch(elm.id)
		{
			case "numberAdults":
			case "NUMBERTRAVELERSID":
				nbradults = 6 - nbrchildren; 
				oNbrAdultElem.selectedIndex = nbradults - 1;
			case "numberChildren":
			case "NUMBERCHILDRENID":
				oNbrChildElem.selectedIndex = nbrchildren = 6 - nbradults;
		}
		DisplayElement(document.getElementById('INFOLINE')); 
		DisplayElement(document.getElementById('INFOLINE2'));
	}
	
	if(nbrchildren>0) 
	{ 
		DisplayElement(document.getElementById('AGESLABEL')); 
		if(nbrchildren!=1) 
		{ 
			document.getElementById('s_in_ages').style.display='inline';
		}
	} 
	else 
	{ 
		HideElement(document.getElementById('LAPCHILDERRORMSG')); 
		SetClassName(document.getElementById('AGESLABEL'),'');
	}
	
	for(i=1; i<=nbrchildren; i++)
	{ 
		DisplayElement(document.getElementById('gsAge'+i));
		DisplayElement(document.getElementById('CHILD'+i+'AGEID'));
	}
}
function Right(str, n)
{
    if(n<=0)
       return "";
    else if(n>String(str).length)
       return str;
    else 
    {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen-n);
    }
}
function SetDateStyle(elem)
{
	var MONTHS=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	var vals = elem.value.split('/');
	var selDate = '';
	if(vals.length>1){	selDate+=vals[1];}
	if(vals.length>0){	selDate+=MONTHS[(vals[0]-1)];}
	if(vals.length>2){	selDate+=Right(vals[2],2);}
	elem.value = selDate;
}
function SetDateStyles()
{
	if(document.getElementById('gsDepartureDate') && document.getElementById('gsReturnDate'))
	{
		SetLengthOfStay(document.getElementById('gsDepartureDate').value, document.getElementById('gsReturnDate').value);
		SetDateStyle(document.getElementById('gsDepartureDate'));
		SetDateStyle(document.getElementById('gsReturnDate'));
	}
}
//format of mm/dd/yyyy is expected (NOTE:  Modified to accept 2-digit year)
function ValidateDateElement(elem)
{
	var retVal = true;
	var Today = new Date();
	var mm = (Today.getMonth()+1);
	var dd = (Today.getDate()+3);
	var yyyy = (Today.getFullYear());
	
	if(elem == null){	return false;}
	if(elem.value.length == 0){return false;}
	if(!(elem.value.match(/^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}|\d{2}$/)))
	{	

		elem.value = mm + '/' + dd + '/' + yyyy;
		return false;
		
	} else {
		var date = elem.value.split('/');
		mm = (date.length > 0) ? date[0] : '';
		dd = (date.length > 1) ? date[1] : '';
		yyyy = (date.length > 2) ? date[2] : '';
	}

	retVal = ValidateDate(dd, mm, yyyy);

	return retVal;
}
function ValidateDate(dd, mm, yyyy)
{
	var retval = true;
	if(mm < 1 || mm > 12 || dd < 1 || dd > 31 || yyyy < 6)
	{
		retval = false;
	}
	if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) 
	{	retval = false;} 
	else 
	{
		if(mm == 2) 
		{ 
			if(yyyy % 4 > 0 && dd > 28) {	retval = false;} 
			else 
			{	if(dd > 29){	retval = false;}}
		}
	}
	return retval;
}
function checkDateIsValid(form)
{ 
	var retval = true;
	var retdateval = true;
	if(form.DEPARTYEAR && form.DEPARTMONTH && form.DEPARTDAY)
	{	retval = ValidateDate(form.DEPARTDAY.selectedIndex+1, form.DEPARTMONTH.selectedIndex+1, form.DEPARTYEAR.value);}
	else
	{
		retval = ValidateDateElement(document.getElementById('gsDepartureDate'));
		retdateval = ValidateDateElement(document.getElementById('gsReturnDate'));
	}
	if(retval == false) 
	{ 
		DisplayElement(GetErrorMsgElement('2'));
		DisplayElement(GetArrowElement('2'));
		SetClassName(document.getElementById('DEPARTING'), 'sub2red');
		
		if(document.frmVacations.VACTYPE)
		{ 
			SetClassName(document.getElementById('HOTELDEPART'),'sub2red');
		}
	} 
	else 
	{ 
		HideElement(GetErrorMsgElement('2'));
		HideElement(GetArrowElement('2'));
		SetClassName(document.getElementById('DEPARTING'), '');
		
		if(document.frmVacations.VACTYPE)
		{ 
			SetClassName(document.getElementById('HOTELDEPART'),'');
		}
	}
	if(!retdateval)
	{
		DisplayElement(GetErrorMsgElement('3'));
		DisplayElement(GetArrowElement('3'));
		SetClassName(document.getElementById('RETURNING'), 'sub2red');
	}
	else
	{
		HideElement(GetErrorMsgElement('3'));
		HideElement(GetArrowElement('3'));
		SetClassName(document.getElementById('RETURNING'), '');
	}
	return (retval && retdateval);
}
function SetLengthOfStay(d1, d2)
{
	if(document.getElementById("gsLengthOfStay"))
	{
		try
		{
			var aryDate1 = d1.split('/');
			var date1 = new Date(aryDate1[2], aryDate1[0] - 1, aryDate1[1]);
			var aryDate2 = d2.split('/');
			var date2 = new Date(aryDate2[2], aryDate2[0] - 1, aryDate2[1]);
			var difference = Date.UTC(date2.getFullYear(),date2.getMonth(),date2.getDate(),0,0,0) - Date.UTC(date1.getFullYear(),date1.getMonth(),date1.getDate(),0,0,0);
			//set difference in days and not milseconds
			document.getElementById("gsLengthOfStay").value = (difference/1000/60/60/24);
		}
		catch(err){}
	}
}
function ShowVacationType()
{ 
  if(document.frmVacations && document.frmVacations.VACTYPE)
  { 
	if(document.frmVacations.VACTYPE[0].checked)
	{ 
		DisplayElement(document.getElementById("FROM")); 
		DisplayElement(document.getElementById("ORIGIN")); 
		DisplayElement(document.getElementById("TO")); 
		DisplayElement(document.getElementById("DESTINATION")); 
		HideElement(document.getElementById("DESTLABEL")); 
		HideElement(document.getElementById("HOTELDESTINATION")); 
		HideElement(document.getElementById("HOTELDEPART")); 
		DisplayElement(document.getElementById("DEPARTING")); 
		HideElement(document.getElementById("HOTELDATE")); 
		DisplayElement(document.getElementById("DEPARTDATE"));
	}
	else
	{ 
		HideElement(GetErrorMsgElement(''));
		HideElement(document.getElementById("FROM")); 
		HideElement(document.getElementById("ORIGIN")); 
		HideElement(document.getElementById("TO")); 
		HideElement(document.getElementById("DESTINATION")); 
		DisplayElement(document.getElementById("DESTLABEL")); 
		DisplayElement(document.getElementById("HOTELDESTINATION")); 
		DisplayElement(document.getElementById("HOTELDEPART")); 
		HideElement(document.getElementById("DEPARTING")); 
		DisplayElement(document.getElementById("HOTELDATE")); 
		HideElement(document.getElementById("DEPARTDATE"));
	}
  }
}
function CopyHotelDates()
{ 
	document.getElementById('DEPARTMONTHID').value = document.getElementById('HOTELDEPARTMONTHID').value; 
	document.getElementById('DEPARTDAYID').value = document.getElementById('HOTELDEPARTDAYID').value;
}
function ShowHide(divID)
{
	if (document.getElementById(divID).style.display=="block")
	{
		document.getElementById(divID).style.display="none";
	}
	else
	{
        document.getElementById(divID).style.display="block";
	}
}

//=============================================================================
//NEW FUNCTIONS FOR VACATION FORMLETS
//=============================================================================
//global
var _maxTravelers = 7;
var _maxChildTravelers = 5;
var _showAlerts = false;
//special bools for CustomValidators
var LapChild_IsValid = false;
var gsPromotionCode_IsValid = false;

function PrepFormlet(formletType) {
    msgbox('PrepFormlet fired');
    
    //Call Validators    
    //=========================================================================
    var allValid = true;
    var continueToShowError = false;
    for(i=0; i < Page_Validators.length; i++) {
        if(Page_Validators[i] != null) {
            //force the validators to validate (except custom validators)
            if(Page_Validators[i].id.indexOf('ChildAgeValidator') != -1) {
                var elementName = Page_Validators[i].id.substring(0, 13);  //pluck out the name of the element being validated
                var elementSubName = Page_Validators[i].id.substring(0, 9);                   
                var element = document.getElementById(elementName);
                //var lblChildAgeValidatorError = document.getElementById(elementSubName + 'ChildAgeValidatorError');  //grab the error label
                var lblChildAgeValidatorError = document.getElementById('_lblChildAgeValidatorError');  //grab the error label
                if(element != null) {
                    if(element.style.display == 'block') {  //if the element is visible fire the validator
                        msgbox('ChildAgeValidator being validated -- Page_Validators[' + i + '].id: ' + Page_Validators[i].id);                   
                        ValidatorValidate(Page_Validators[i]);
                        //special handling for child age validators
                        if(!Page_Validators[i].isvalid) {
                            continueToShowError = true;
                            lblChildAgeValidatorError.style.display = 'block';
                        } else {
                            if(!continueToShowError) {
                                lblChildAgeValidatorError.style.display = 'none';
                            }
                        }
                    }                    
                }
            } else {  //as long as the validator isn't a child age validator, then fire away
                ValidatorValidate(Page_Validators[i]);
            }
            if(!Page_Validators[i].isvalid) {
                msgbox('Page_Validators[' + i + '].id: ' + Page_Validators[i].id + ' isvalid? --> ' + Page_Validators[i].isvalid);            
                allValid = false;
            }
        }
    }
    
    msgbox('allValid: ' + allValid);        
    
    if(allValid) {        
        //SET & FORMAT INPUTS:  
        //=========================================================================
        
        //set number of children for each "bucket" (gsAge1 - gsAge5) ex. gsAge1 = 2|5
        //gsAge1, gsAge2, gsAge3, gsAge4, gsAge5
        SetChildAges();  
        
        //SET INPUT:  gsLengthOfStay
        var departureDate = document.getElementById('gsDepartureDate');  //set via wrapper prep formlet function
        var returnDate = document.getElementById('gsReturnDate');  //set via wrapper prep formlet function    
        if(departureDate != null && returnDate != null) {            
            SetLengthOfStay2(departureDate.value, returnDate.value, 'gsLengthOfStay');
            //FORMAT INPUT:  gsDepartureDate & gsReturnDate
            departureDate.value = FormatDateValue(departureDate.value);
            returnDate.value = FormatDateValue(returnDate.value);                
        }        
                        
        //SET INPUT:  gsNumberOfTravelers                
        var numberOfTravelers = document.getElementById('gsNumberOfTravelers');
        if(numberOfTravelers != null) {
            //check for room2's presence and visibility
            var room2 = document.getElementById('Room2');
            if(room2 != null && room2.style.display == 'block') {
                //MULTI ROOM
                numberOfTravelers.value = CalculateNumberOfTravelers('1') + '|' + CalculateNumberOfTravelers('2');    
            } else if (room2 == null || room2.style.display == 'none') {
                numberOfTravelers.value = CalculateNumberOfTravelers('1');
            }            
            //if things check out, hide the over 7 warning
            HideNumberOfPassengersWarningLabel(numberOfTravelers.value)          
        } 
        
        //SUMMARY
        //Debug(formletType);
                    
        //set the target before submitting
        window.document.forms[0].target = '_top';          
        return true;  
    } else {
        window.document.forms[0].target = '';
        return false;
    }            
}
/**********************************************************
Name:   PrepACPFormlet
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/23/2007
Desc:   Prep function that calculates some values before allowing 
        the form to be submitted to the external search site (ex. Trisept)
        Wrapper for PrepFormlet
***********************************************************/
function PrepACPFormlet() {
    msgbox('PrepACPFormlet fired');    
    
    var departureDate = document.getElementById('gsDepartureDate');
    var departureDateBox = document.getElementById('_ucDepartingDateTime__txtDateBox');    
    if(departureDate != null && departureDateBox != null) {
        departureDate.value = departureDateBox.value;
    }    
    var returnDate = document.getElementById('gsReturnDate');
    var returnDateBox = document.getElementById('_ucReturningDateTime__txtDateBox');                        
    if(returnDate != null && returnDateBox != null) {
        returnDate.value = returnDateBox.value;
    }    
    var returnVal = PrepFormlet('AirAndCar');  
    msgbox('returnVal: ' + returnVal);    
    return returnVal;
}
/**********************************************************
Name:   PrepCPFormlet
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Prep function that calculates some values before allowing 
        the form to be submitted to the external search site (ex. Trisept)
        Wrapper for PrepFormlet
***********************************************************/            
function PrepCPFormlet() {                
    msgbox('PrepCPFormlet fired');   
    
    var departureDate = document.getElementById('gsDepartureDate');
    var departureDateBox = document.getElementById('_ucDepartingDateTime__txtDateBox');    
    if(departureDate != null && departureDateBox != null) {
        departureDate.value = departureDateBox.value;
    }    
    var returnDate = document.getElementById('gsReturnDate');
    var returnDateBox = document.getElementById('_ucReturningDateTime__txtDateBox');                        
    if(returnDate != null && returnDateBox != null) {
        returnDate.value = returnDateBox.value;
    } 
    //PrepFormlet('CompletePackage');   
    var returnVal = PrepFormlet('CompletePackage');   
    msgbox('returnVal: ' + returnVal); 
    return returnVal;    
}
/**********************************************************
Name:   PrepHOPFormlet
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Prep function that calculates some values before allowing 
        the form to be submitted to the external search site (ex. Trisept)
        Wrapper for PrepFormlet
***********************************************************/
function PrepHOPFormlet() {
    msgbox('PrepHOPFormlet fired');
    
    var departureDate = document.getElementById('gsDepartureDate');
    var departureDateBox = document.getElementById('_ucCheckInDate__txtDateBox');    
    if(departureDate != null && departureDateBox != null) {
        departureDate.value = departureDateBox.value;
    }    
    var returnDate = document.getElementById('gsReturnDate');
    var returnDateBox = document.getElementById('_ucCheckOutDate__txtDateBox');                        
    if(returnDate != null && returnDateBox != null) {
        returnDate.value = returnDateBox.value;
    }        
    var returnVal = PrepFormlet('HotelOnly');
    msgbox('returnVal: ' + returnVal);    
    return returnVal;
}
/**********************************************************
Name:   ShowHideNumberOfPassengersWarningLabel
Args:   showWarning - boolean indicating show or hide
Author: kdonohu, AlaskaAir.com
Date:   12/24/2007
Desc:   Helper method that hides or shows the warning
***********************************************************/
function ShowHideNumberOfPassengersWarningLabel(showWarning) {
    msgbox('ShowHideNumberOfPassengersWarningLabel fired');
    var warning = document.getElementById('_lblNumberOfPassengersWarningLabel');    
    if(warning != null) {
        if(showWarning) {
            warning.style.display = 'block';
        } else {
            warning.style.display = 'none';
        }
    }
}
/**********************************************************
Name:   HideNumberOfPassengersWarningLabel
Args:   numberOfTravelers - the number of current travelers
Author: kdonohu, AlaskaAir.com
Date:   12/20/2007
Desc:   Helper method that hides the NumberOfPassengersWarningLabel if 
        the number of passengers is at or below the max
***********************************************************/
function HideNumberOfPassengersWarningLabel(numberOfTravelers) {
    msgbox('HideNumberOfPassengersWarningLabel fired');
    if(numberOfTravelers != null && _maxTravelers != null) {
        if(numberOfTravelers <= _maxTravelers) {           
            ShowHideNumberOfPassengersWarningLabel(false);
        }
    }
}
/**********************************************************
Name:   Destination_OnChange
Args:   ddl - the ddl for selecting the destination
        originElement - the element target that will receive the selected value
Author: kdonohu, AlaskaAir.com
Date:   12/20/2007
Desc:   OnChange event handler for the ddl for selecting the
        destination.
***********************************************************/
function Destination_OnChange(ddl, destinationElement) {
    msgbox('Destination_OnChange fired');
    if(ddl != null) {
        var gsDestination = document.getElementById(destinationElement);
        if(gsDestination != null) {
            gsDestination.value = ddl.value;
        }
    }
}
/**********************************************************
Name:   Origin_OnChange
Args:   ddl - the ddl for selecting the origin
        originElement - the element target that will receive the selected value
Author: kdonohu, AlaskaAir.com
Date:   12/20/2007
Desc:   OnChange event handler for the ddl for selecting the
        origin.
***********************************************************/ 
function Origin_OnChange(ddl, originElement) {
    msgbox('Origin_OnChange fired');
    if(ddl != null) {
        var originElement = document.getElementById(originElement);
        if(originElement != null) {
            originElement.value = ddl.value;
        }
    }
}
/**********************************************************
Name:   CabinPreference_OnChange
Args:   dropDownList - the ddl for selecting the number of adult travelers
        cabinPreferenceElement - the element target that will receive the selected value
Author: kdonohu, AlaskaAir.com
Date:   12/20/2007
Desc:   OnChange event handler for the ddl for selecting the
        cabin preference (coach, first).
***********************************************************/ 
function CabinPreference_OnChange(dropDownList, cabinPreferenceElement) {
    msgbox('CabinPreference_OnChange fired');
    if(dropDownList != null) {
        var cabinPrefElement = document.getElementById(cabinPreferenceElement);
        if(cabinPrefElement != null) {
            cabinPrefElement.value = dropDownList.value;
        }
    }
}
/**********************************************************
Name:   HotelRooms_OnLoad
Args:   ddlName - the name of the ddl for selecting the number of adult travelers        
Author: kdonohu, AlaskaAir.com
Date:   2/4/2008
Desc:   OnLoad event handler for the ddl for showing or hiding 
the Room2 controls; the primary reason for this event handler is 
to deal with users hitting the Back button ... if they do and they've 
selected 2 rooms (or in the future more) then they won't see the second 
room controls.
***********************************************************/
function HotelRooms_OnLoad(ddlName) {
    msgbox('HotelRooms_OnLoad');
    if(ddlName != '') {
        var dropDownList = document.getElementById(ddlName);
        var room2 = document.getElementById('Room2');
        if(dropDownList != null && room2 != null) {
            var selectedValue = dropDownList.value;
            var selectedIndex = dropDownList.selectedIndex;
            switch(selectedValue) {
                case 'Y':
                    room2.style.display = 'none';
                break;
                
                case '':
                    room2.style.display = 'block';
                break;
            }
        }
    }
}
/**********************************************************
Name:   HotelRooms_OnChange
Args:   dropDownList - the ddl for selecting the number of adult travelers
        hotelRoomsElement - the element target that will receive the selected value
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   OnChange event handler for the ddl for selecting the
        number of rooms.
***********************************************************/            
function HotelRooms_OnChange(dropDownList, hotelRoomsElement) {
    msgbox('HotelRooms_OnChange fired');
    if(dropDownList != null) {
        //store the currently selected value in the hidden element
        var hotelRoomsElement = document.getElementById(hotelRoomsElement);
        if(hotelRoomsElement != null) {                
            hotelRoomsElement.value = dropDownList.value;
        }     
        //handle Room2
        var room2 = document.getElementById('Room2');                       
        if(room2 != null) {
            var selectedValue = dropDownList.value;
            switch(selectedValue) {
                case 'Y':
                    msgbox('hide');
                    room2.style.display = 'none';
                    //HideElement(room2);
                    //reset the adults and child drop downs
                    var ddlRoom2Children = document.getElementById('_ddlRoom2Children');
                    if(ddlRoom2Children != null) {
                        //reset the child drop down
                        ddlRoom2Children.selectedIndex = 0;
                        //now fire the OnChange to adjust the individual drop downs in response
                        RoomChildren_OnChange(ddlRoom2Children, 2);
                    }
                    var ddlRoom2Adults = document.getElementById('_ddlRoom2Adults');
                    if(ddlRoom2Adults != null) {
                        //reset the adult drop down
                        ddlRoom2Adults.selectedIndex = 0;
                        //now fire the OnChange to adjust the individual drop downs in response
                        RoomAdults_OnChange(document.getElementById('_ddlRoom2Adults'));
                    }
                break;
                
                case '':
                    msgbox('show');
                    room2.style.display = 'block';
                    var ddlRoom2Adults = document.getElementById('_ddlRoom2Adults');
                    if(ddlRoom2Adults != null) {
                        ddlRoom2Adults.selectedIndex = 1;  //select 2 passengers as the default
                    }
                    //fire the OnChange for adults to check number of passengers (adults)
                    RoomAdults_OnChange(document.getElementById('_ddlRoom2Adults'));
                    RoomAdults_OnChange(document.getElementById('_ddlRoom1Adults'));
                    //ShowElement(room2);
                break;                        
            }
        }    
    }
}               
/**********************************************************
Name:   RoomAdults_OnChange
Args:   dropDownList - the ddl for selecting the number of adult travelers
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   OnChange event handler for the ddl for selecting the
        number of adults in each of the rooms.
***********************************************************/             
function RoomAdults_OnChange(dropDownList) {                
    msgbox('RoomAdults_OnChange fired');        
    //obtain number of travelers                        
    //adjust drop down list based on number of travelers
    AdjustDDL(dropDownList, "adult");
}
/**********************************************************
Name:   RoomChildren_OnLoad
Args:   ddlName - the name of the drop down list
Author: kdonohu, AlaskaAir.com
Date:   2/2/2008
Desc:   OnLoad event handler to adjust the presentation of the 
selected number of children.  This handles when users hit the 
back button and return to the page -- the drop downs wouldn't be 
visible without this handler.
***********************************************************/  
function RoomChildren_OnLoad(ddlName) {
    msgbox('RoomChildren_OnLoad fired');
    if(ddlName != '') {
        var dropDownList = document.getElementById(ddlName);
        if(dropDownList != null) {
            msgbox('calling HideShowChildDDLs');
            HideShowChildDDLs(dropDownList);
        }
    }
}
/**********************************************************
Name:   RoomChildren_OnChange
Args:   dropDownList - the ddl for selecting the number of child travelers
        roomNumber - the room where the dropDownList lives
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   OnChange event handler for the ddl for selecting the
        number of children in each of the rooms.
***********************************************************/             
function RoomChildren_OnChange(dropDownList) {
    msgbox('RoomChildren_OnChange fired');
    //adjust drop down list based on number of travelers
    AdjustDDL(dropDownList, "child");
    //call HideShow  
    HideShowChildDDLs(dropDownList);
}
/**********************************************************
Name:   UCVacationsDateTime_OnChange
Args:   ctrl - User control
        lengthOfStayElement - target input that will get the value from the ctrl
Author: kdonohu, AlaskaAir.com
Date:   12/14/2007
Desc:   OnChange handler that assigns a value from the ctrl to an input 
***********************************************************/    
function UCVacationsDateTime_OnChange(ctrl1, ctrl2, lengthOfStayElement) {
    msgbox('UCVacationsDateTime_OnChange fired');
    if(ctrl1 != null && ctrl2 != null && lengthOfStayElement != null) {            
        var lengthOfStay = document.getElementById(lengthOfStayElement);
        if(lengthOfStay != null) {
            lengthOfStay.value = CalculateLengthOfStay(ctrl1, ctrl2);
        }
    }
}
/**********************************************************
Name:   ddlTime_OnChange
Args:   ddl - drop down list element
        timeElement - target input that will get the value from ddl
Author: kdonohu, AlaskaAir.com
Date:   12/13/2007
Desc:   OnChange handler that assigns the value of the ddl to an input 
***********************************************************/
function ddlTime_OnChange(ddl, timeElement) {
    msgbox('ddlTime_OnChange fired');
    if(ddl != null) {
        var timeElement = document.getElementById(timeElement);
        if(timeElement != null) {                
            timeElement.value = ddl.value;
        }
    }
}    
/**********************************************************
Name:   txtDateBox_OnChange
Args:   textbox - textbox element 
        dateElement - target input that will get the value from textbox          
Author: kdonohu, AlaskaAir.com
Date:   12/13/2007
Desc:   OnChange handler that assigns the value of the textbox to an input
***********************************************************/
function txtDateBox_OnChange(textbox, dateElement) {
    msgbox('txtDateBox_OnChange fired');
    if(textbox != null) {
        var dateElement = document.getElementById(dateElement);       
        if(dateElement != null) {
            dateElement.value = textbox.value;
        }
    }
}    
/**********************************************************
Name:   FormatDateValue
Args:   date - date string to be formatted          
Author: kdonohu, AlaskaAir.com
Date:   12/13/2007
Desc:   Formats the provided date string to match Trisept's 
        pretty date format requirements [ex. ddMonyy - 13Dec07]            
Note:   ##Code is similar to SetDateStyle in VacationUtilsv8.js##
***********************************************************/
function FormatDateValue(date)
{
    msgbox('FormatDateValue fired');
    var formattedDate = '';
    var MONTHS=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var vals = date.split('/');
    if(vals.length>1)
    {	
        formattedDate+=vals[1];
    }
    if(vals.length>0)
    {	
        formattedDate+=MONTHS[(vals[0]-1)];
    }
    if(vals.length>2)
    {	
        formattedDate+=Right(vals[2],2);
    }	   
    return formattedDate;
}
/**********************************************************
Name:   CalculateLengthOfStay
Args:   ctrl1 - User control
        ctrl2 - User control          
Author: kdonohu, AlaskaAir.com
Date:   12/14/2007
Desc:   Given two controls (with date values), calculates the 
        difference between the two values, and returns, 
        in the number of days, the difference to the caller
Note:   Logic for this method *stolen* from SetLengthOfStay
        from VacationUtilsv8.js
***********************************************************/
function CalculateLengthOfStay(ctrl1Value, ctrl2Value) {
    msgbox('CalculateLengthOfStay fired');
    var diffInDays = 0;
    if(ctrl1Value != null && ctrl2Value != null) {
        var arrDate1 = ctrl1Value.split('/');
        var arrDate2 = ctrl2Value.split('/');
        //if the date array length isn't 3 (day month year), then our date isn't valid for
        //calculating the length of stay
        if(arrDate1.length == 3 && arrDate2.length == 3) {
            var date1 = new Date(arrDate1[2], arrDate1[0] - 1, arrDate1[1]);
            var date2 = new Date(arrDate2[2], arrDate2[0] - 1, arrDate2[1]);
            var diff = (Date.UTC(date2.getFullYear(),date2.getMonth(),date2.getDate(),0,0,0,0) - Date.UTC(date1.getFullYear(), date1.getMonth(), date1.getDate(),0,0,0,0));
            diffInDays = (diff/1000/60/60/24);
        }            
    }
    return diffInDays;
}
/**********************************************************
Name:   SetLengthOfStay2
Args:   ctrl1 - User control
        ctrl2 - User control          
        target - target control
Author: kdonohu, AlaskaAir.com
Date:   1/7/2008
Desc:   Given two controls (with date values), calculates the 
        difference between the two values, and sets the given target 
        to the result
***********************************************************/
function SetLengthOfStay2(ctrl1Value, ctrl2Value, target) {
    var targetElement = document.getElementById(target);
    if(targetElement != null && ctrl1Value != null && ctrl2Value != null) {
        targetElement.value = CalculateLengthOfStay(ctrl1Value, ctrl2Value);
    }
}
/**********************************************************
Name:   AdjustDDL
Args:   dropDownList - the drop down list for selecting the number of travelers
        type - the type of travelers being adjusted (adult, child)
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method that adjusts the number of travelers (ddls)
        based on the maximum number of travelers allowed
        This method disallows users from selecting more than 
        the maximum number of travelers; auto. adjusting the 
        latest touched ddl
***********************************************************/             
function AdjustDDL(dropDownList, type) {
    msgbox('AdjustDDL fired');
    var numberOfTravelers = CalculateNumberOfTravelers('BOTH');  
    var diff;
    var newval;                              
    if(dropDownList != null && numberOfTravelers != null) { 
        //show/hide alert
        if(numberOfTravelers > _maxTravelers) {
            ShowHideNumberOfPassengersWarningLabel(true);                                    
            //adjust drop down being manipulated to reduce number of travelers under max
            diff = (numberOfTravelers - _maxTravelers);
            newval = dropDownList.value - diff;
            switch(type) {
                case 'adult':
                    if(newval > 0) {                             
                        dropDownList.selectedIndex = newval - 1;
                    } else {
                        dropDownList.selectedIndex = 0;
                    }                            
                break;
                
                case 'child':
                    if(newval > 0) {                             
                        dropDownList.selectedIndex = newval;
                    } else {
                        dropDownList.selectedIndex = 0;
                    }                            
                break;
            }
        } else {
            ShowHideNumberOfPassengersWarningLabel(false);
        }              
    }                
}
/**********************************************************
Name:   HideShowChildDDLs
Args:   dropDownList - the drop down list for selecting the number of children
        roomNumber - the room number where the dropDownList lives
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method that hides or shows the child ddls
        based on what has been selected in the ddl for number of children
***********************************************************/        
function HideShowChildDDLs(dropDownList) {
    msgbox('HideShowChildDDLs fired');
    //TODO: Refactor
    var ddlID = dropDownList.id;
    var roomNumber;
    //determine room first     
    if(ddlID != null) {
        if(ddlID.indexOf('Room1') != -1) {
            //Room1 control fired check
            roomNumber = 1;
        } else if (ddlID.indexOf('Room2') != -1) {
            //Room2 control fired check
            roomNumber = 2;
        }
    }        
    var selectedValue = dropDownList.value; 
    //room labels      
    var roomAgeLabel = document.getElementById('_lblRoom' + roomNumber + 'AgeLabel');    
    var roomAges = document.getElementById('_lblRoom' + roomNumber + 'Ages');                      
    if(roomAgeLabel != null) {
        roomAgeLabel.style.display = 'block';  //always show unless 00      
    }
    if(roomAges != null) {
        roomAges.style.display = 'none';
    }
    //TODO:  Write in some protection so that we only operate on these elements if they exist
    //ddls
    var ddlAge1 = document.getElementById('_ddlRoom' + roomNumber + 'Age1');
    var ddlAge2 = document.getElementById('_ddlRoom' + roomNumber + 'Age2');               
    var ddlAge3 = document.getElementById('_ddlRoom' + roomNumber + 'Age3');                
    var ddlAge4 = document.getElementById('_ddlRoom' + roomNumber + 'Age4');      
    var ddlAge5 = document.getElementById('_ddlRoom' + roomNumber + 'Age5');                   
    //arrays                
    var ddls = new Array(ddlAge1, ddlAge2, ddlAge3, ddlAge4, ddlAge5);
    //handle the labels
    if(parseInt(selectedValue,10) == 0) {
        roomAgeLabel.style.display = 'none';
    } else if (parseInt(selectedValue,10) == 1) {
        roomAgeLabel.style.display = 'block';
    } else if(parseInt(selectedValue,10) > 1) {
        roomAgeLabel.style.display = 'block';
        roomAges.style.display = 'inline';  //needs to be inline so 's' is shown on the end of the word
    }  
    //handle the ddls and divs
    for(i=0;i<ddls.length;i++) {
        switch(parseInt(selectedValue,10)) {
            case '0':
                //show none
                ddls[i].selectedIndex = 0;                           
                ddls[i].style.display = 'none';
            break;                                               
            case '5':
                //show all
                ddls[i].style.display = 'block';
            break;                       
            default:       
                if(i < parseInt(selectedValue,10)) {
                    ddls[i].style.display = 'block';
                } else {
                    ddls[i].selectedIndex = 0;
                    ddls[i].style.display = 'none';
                }                             
            break;                      
        }
    }                
}        
/**********************************************************
Name:   CalculateNumberOfTravelers
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Wrapper, helper method that determines the number of travelers 
        selected by calling the two calculate methods
***********************************************************/            
function CalculateNumberOfTravelers(roomNumber) {
    //calc number of adults
    var numAdults = CalculateNumberOfAdultTravelers(roomNumber);
    //calc number of children  
    var numChildren = CalculateNumberOfChildTravelers(roomNumber);
    return (numAdults + numChildren);
}
/**********************************************************
Name:   CalculateNumberOfAdultTravelers
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method that determines the number of adult 
        travelers selected by checking the ddls for adults
        in both of the rooms (if visible)
***********************************************************/            
function CalculateNumberOfAdultTravelers(roomNumber) {
    msgbox('CalculateNumberOfAdultTravelers fired');
    var total = 0;
    var numRoom1 = 0;
    var numRoom2 = 0;
    
    switch(roomNumber) {
        case '1':
            //room1
            var ddlRoom1Adults = document.getElementById('_ddlRoom1Adults');                 
            if(ddlRoom1Adults != null) {
                numRoom1 = parseInt(ddlRoom1Adults.selectedIndex,10) + 1;
            }
            total = numRoom1;
        break;
        
        case '2':
            //room2
            var room2 = document.getElementById('Room2');
            var ddlRoom2Adults = document.getElementById('_ddlRoom2Adults');                 
            if(room2 != null && room2.style.display == 'block' && ddlRoom2Adults != null) {
                numRoom2 = parseInt(ddlRoom2Adults.selectedIndex,10) + 1;
            } //otherwise room2 isn't visible so don't calculate a total
            total = numRoom2;
        break;
        
        case 'BOTH':
            //room1 and room2 -- will check for each, so just room1 or room2 existing is OK too
            var ddlRoom1Adults = document.getElementById('_ddlRoom1Adults');            
            if(ddlRoom1Adults != null) {
                numRoom1 = parseInt(ddlRoom1Adults.selectedIndex,10) + 1;                                                
            }
            var room2 = document.getElementById('Room2');
            if(room2 != null && room2.style.display == 'block') {
                var ddlRoom2Adults = document.getElementById('_ddlRoom2Adults');
                if(ddlRoom2Adults != null) {
                    numRoom2 = parseInt(ddlRoom2Adults.selectedIndex,10) + 1;
                }
            }
            total = (numRoom1 + numRoom2);
        break;
    }    
    return total;
}
/**********************************************************
Name:   CalculateNumberOfChildTravelers
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method that determines the number of child 
        travelers selected by checking the ddls for children
        in both of the rooms (if visible)
***********************************************************/             
function CalculateNumberOfChildTravelers(roomNumber) {
    msgbox('CalculateNumberOfChildTravelers fired');
    var total = 0;
    var numRoom1 = 0;
    var numRoom2 = 0;
    
    switch(roomNumber) {
        case '1':
            //room1
            var ddlRoom1Children = document.getElementById('_ddlRoom1Children');    
            if(ddlRoom1Children != null) {
                numRoom1 = parseInt(ddlRoom1Children.selectedIndex,10);
            }
            total = numRoom1;
        break;
        
        case '2':
            //room2
            var room2 = document.getElementById('Room2');  
            var ddlRoom2Children = document.getElementById('_ddlRoom2Children');     
            if(room2 != null && room2.style.display == 'block' && ddlRoom2Children != null) {
                numRoom2 = parseInt(ddlRoom2Children.selectedIndex,10);
            }
            total = numRoom2;
        break;
        
        case 'BOTH':
            //room1
            var ddlRoom1Children = document.getElementById('_ddlRoom1Children');    
            if(ddlRoom1Children != null) {
                numRoom1 = parseInt(ddlRoom1Children.selectedIndex,10);
            }            
            //room2
            var room2 = document.getElementById('Room2');  
            if(room2 != null && room2.style.display == 'block') {
                var ddlRoom2Children = document.getElementById('_ddlRoom2Children');             
                if(ddlRoom2Children != null) {
                    numRoom2 = parseInt(ddlRoom2Children.selectedIndex,10);
                }    
            }                        
            total = (numRoom1 + numRoom2);            
        break;        
    }        
    return total;
}   
/**********************************************************
Name:   SetChildAges
Args:   none
Author: kdonohu, AlaskaAir.com
Date:   1/16/2007
Desc:   Helper method that walks the child ddls and builds 
        the strings that will be assigned to the age elmeents
        ex. gsAge1 = 2|8
***********************************************************/            
function SetChildAges() {
    msgbox('SetChildAges fired');
    var secondRoom = document.getElementById('Room2');
    var rooms;
    var ages = new Array('1','2','3','4','5');
    var currentDDL;
    var currentGS;
    
    if(secondRoom == null || (secondRoom != null && secondRoom.style.display == 'none')) {
        //second room isn't available or isn't visible ... just check for selected ages in the first room
        rooms = new Array('1');
        for(i=0;i<ages.length;i++) {
            currentDDL = document.getElementById('_ddlRoom' + rooms[0] + 'Age' + ages[i]);
            currentGS = document.getElementById('gsAge' + ages[i]);
            if(currentDDL != null && currentGS != null) {                                
                if(currentDDL.selectedIndex == 0) {
                    currentGS.value = '';
                } else {
                    currentGS.value = currentDDL.value;
                }
            }
        }
    } else if (secondRoom != null && secondRoom.style.display == 'block') {
        //MULTI ROOM (Pipes)
        rooms = new Array('1','2');                                            
        for(i=0;i<rooms.length;i++) {       
            for(j=0;j<ages.length;j++) {
                currentDDL = document.getElementById('_ddlRoom' + rooms[i] + 'Age' + ages[j]);
                currentGS = document.getElementById('gsAge' + ages[j]);
                if(currentDDL != null && currentGS != null) {
                    //only do this for the first room
                    if(i == 0) {
                        //first room
                        msgbox('first room');
                        if(currentDDL.selectedIndex == 0) {
                            currentGS.value = '|';
                        } else {
                            currentGS.value = currentDDL.value + '|';
                        }
                    } else {
                        //second room
                        msgbox('second room');
                        if(currentDDL.selectedIndex == 0) {                            
                            currentGS.value = currentGS.value;
                        } else {
                            currentGS.value = currentGS.value + currentDDL.value;
                        }                          
                    }                    
                }
                msgbox('currentGS.value: ' + currentGS.value);
            }
        }    
    }    
}   
/**********************************************************
Name:   gsPromotionCodeCustomValidator_ClientValidate
Args:   n/a
Author: kdonohu, AlaskaAir.com
Date:   1/16/2007
Desc:   Client-side validator method for the child age drop down lists (10x)
UPDATE: This is no longer bound to an asp:CusotmValidator control,
        it is simply called from Prep methods when validating formlet values
        before submission.
***********************************************************/
function gsPromotionCodeCustomValidator_ClientValidate() {
    msgbox('gsPromotionCodeCustomValidator_ClientValidate FIRED');
    var promoCode = document.getElementById('gsPromotionCode');
    var error = document.getElementById('_lblPromoCodeError');
    var isValid;
    if(promoCode != null && promoCode.value.length > 0) {
        if(IsAlphaNumeric(promoCode.value)) {
            isValid = true;
            error.style.display = 'none';
        } else {
            isValid = false;
            error.style.display = 'block';
        } 
    } else {
        //if the element isn't on the page or if it doesn't contain a value,
        //don't worry about it ... just return true
        isValid = true;
        error.style.display = 'none';
    }
    msgbox('isValid: ' + isValid);
    return isValid;
}
/**********************************************************
Name:   LapChildCustomValidator_ClientValidate
Args:   n/a
Author: kdonohu, AlaskaAir.com
Date:   1/16/2007
Desc:   Client-side validator method for the child age drop down lists (10x)
UPDATE: This is no longer bound to an asp:CusotmValidator control, 
        it is simply called from Prep methods when validating formlet values
        before submission.
***********************************************************/
function LapChildCustomValidator_ClientValidate() {
    msgbox('LapChildCustomValidator_ClientValidate FIRED');
    var isValid = false;
    var roomNumber = 0;
    var foundError = false;
    var room2 = document.getElementById('Room2');
    var rooms;
    //check for room2 visibility first
    if(room2 != null && room2.style.display == 'block') {
        rooms = new Array('1','2');        
    } else {
        //just room1 to deal with
        rooms = new Array('1');
    }
    for(i=0;i<rooms.length;i++) {     
        //use this boolean to break out ... ex. if we find an error in room 1 then don't 
        //continue on validating
        if(foundError) {
            msgbox('found error ... outer loop');
            break;
        }
        //grab all of the elements
        var errorSpan = document.getElementById('_lblLapChildErrorRoom' + rooms[i]);
        var ddlAge1 = document.getElementById('_ddlRoom' + rooms[i] + 'Age1');
        var ddlAge2 = document.getElementById('_ddlRoom' + rooms[i] + 'Age2');            
        var ddlAge3 = document.getElementById('_ddlRoom' + rooms[i] + 'Age3');                
        var ddlAge4 = document.getElementById('_ddlRoom' + rooms[i] + 'Age4');
        var ddlAge5 = document.getElementById('_ddlRoom' + rooms[i] + 'Age5');
        //create an array of the drop downs
        var ddls = new Array(ddlAge1, ddlAge2, ddlAge3, ddlAge4, ddlAge5);        
        for(j=0;j<ddls.length;j++) {
            //bust outta here if you found an error already...
            if(foundError) {
                break;
            }
            switch(ddls[j].style.display) {                            
                case 'none':
                    isValid = true;
                    errorSpan.style.display = 'none';                          
                break;
                        
                case 'block':               
                    if(ddls[j].value == '' || isNaN(ddls[j].value) || parseInt(ddls[j].value,10) < 2) {
                        isValid = false;
                        errorSpan.style.display = 'block';
                        foundError = true;
                    } else {
                        isValid = true;
                        errorSpan.style.display = 'none';
                    }                                
                break;                            
            }                                             
        }        
    }
    msgbox('isValid: ' + isValid);
    return isValid;
}
/**********************************************************
Name:   ShowTravelerTips
Args:   n/a
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method to popup the window based on variables passed in
***********************************************************/              
function ShowTravelerTips() {
    var url = 'http://www.alaskaair.com/as/vacations/TravelerTips.asp';
    var name = 'TravelerTips';
    var features = 'width=320,height=365,resizable=no,scrollbars=no,screenX=0,screenY=0';
    ShowWindow(url, name, features);
}
/**********************************************************
Name:   ShowVacationPackageTips
Args:   n/a
Author: kdonohu, AlaskaAir.com
Date:   1/23/2008
Desc:   Helper method to popup the window based on variables passed in
***********************************************************/
function ShowVacationPackageTips() {
    //OLD URL  'http://www.alaskaair.com/shared/tips/VacationPackageTips.asp';
    var url = 'http://www.alaskaair.com/as/vacations/VacationPackageTips.asp';
    var name = 'VacationPackageTips';
    var features = 'width=320,height=235,resizable=no,scrollbars=no,screenX=0,screenY=0';
    ShowWindow(url, name, features);
}
/**********************************************************
Name:   ShowVacationShoppingTips
Args:   n/a
Author: kdonohu, AlaskaAir.com
Date:   1/24/2008
Desc:   Helper method to popup the window based on variables passed in
***********************************************************/
function ShowVacationShoppingTips() {
    var url = 'http://www.alaskaair.com/as/vacations/VacationShoppingTips.asp';
    var name = 'ShoppingTips';
    var features = 'width=320,height=540,resizable=no,scrollbars=no,screenX=0,screenY=0';
    ShowWindow(url, name, features);
}
/**********************************************************
Name:   ShowWindow
Args:   url - url of the popup window
        name - name of the popup window
        features - window features for the popup window
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Helper method to popup the window based on variables passed in
***********************************************************/
function ShowWindow(url, name, features) {
    window.open(url, name, features);
}  
/**********************************************************
Name:   Debug
Args:   formletType - type of formlet prep method that needs debugging                    
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Utility function for debugging; uses a type to show all of the 
        supported items that will be submitted
***********************************************************/
function Debug(formletType) {    
    //SUMMARY
    alert('gsOrigin: ' + document.getElementById('gsOrigin').value);     
    alert('gsDestination: ' + document.getElementById('gsDestination').value);     
    alert('gsNumberOfTravelers: ' + document.getElementById('gsNumberOfTravelers').value);
    alert('gsLengthOfStay: ' + document.getElementById('gsLengthOfStay').value);
    alert('gsDepartureDate: ' + document.getElementById('gsDepartureDate').value);
    alert('gsReturnDate: ' + document.getElementById('gsReturnDate').value);
    if(formletType == 'CompletePackage') {
        alert('foDepartureTime: ' + document.getElementById('foDepartureTime').value);
        alert('foReturnTime: ' + document.getElementById('foReturnTime').value);
        alert('foCabinPreference: ' + document.getElementById('foCabinPreference').value);
    }
    if(formletType == 'CompletePackage' || formletType == 'HotelOnly') {
        alert('foHotelRooms: ' + document.getElementById('foHotelRooms').value);
    }
    alert('gsPromotionCode: ' + document.getElementById('gsPromotionCode').value);
    alert('gsAge1: ' + document.getElementById('gsAge1').value);
    alert('gsAge2: ' + document.getElementById('gsAge2').value);
    alert('gsAge3: ' + document.getElementById('gsAge3').value);
    alert('gsAge4: ' + document.getElementById('gsAge4').value);    
    alert('gsAge5: ' + document.getElementById('gsAge5').value);    
}     
/**********************************************************
Name:   msgbox - Utility function
Args:   strMsg - message to be alerted                    
Author: kdonohu, AlaskaAir.com
Date:   12/18/2007
Desc:   Utility function for debugging; uses a global variable to turn alerts on and off
***********************************************************/
function msgbox(strMsg) {
    if(_showAlerts) { window.alert(strMsg) };
}
function Test() {
    window.alert('TEST');
}
//=============================================================================
//END - NEW FUNCTIONS
//=============================================================================
