﻿var CommonResTool = 
{
    departCalOpen: false,
    returnCalOpen: false,
    
    paxCountExceeded: false,
    
    currentComponentOrder: "AHCF",
    
    currentResTool: "main",

    // Function Name: toggleCalendar
    // Purpose: toggle departCalOpen and returnCalOpen based on user gestures
    // Parameters: None
    // Return: None
        
        toggleCalendar: function(id, newClass, calType, departDates, departDays, resTool, packageType, maxDateAir, maxDateLand)
        {
            var _id = id;
            var _oppositeId;
            var _calType = calType;
            var _calOpen = eval("this." + _calType.toLowerCase() + "CalOpen");
            var _oppositeCalType;
            var _oppositeCalOpen;
            var _resTool = resTool;// ["main"|"hotelProfiles"|"deals"]
            
            //this.currentResTool is set to value passed to this function when calendar is clicked
            //calendarRequest.js=>fillDate needs to know what restool id to pass
            //into toggleDropdownForIECalDisplay to re-display divs which have been hidden
            this.currentResTool = _resTool;
            
            switch(_calType.toLowerCase())
            {
                case "depart":
                    _oppositeCalType = "Return";
                    _oppositeCalOpen = this.returnCalOpen;
                    _oppositeId = "changingReturn";
                    break;
                case "return":
                    _oppositeCalType = "Depart";
                    _oppositeCalOpen = this.departCalOpen;
                    _oppositeId = "changingDepart";
                    break;
            }
         
	        if ( _calOpen == false )
	        {
	            changeCalendarClass(_id, "normal", _calType, departDates, departDays, packageType, maxDateAir, maxDateLand);// display calendar
	            //this.toggleDropdownsForIECalDisplay("hide", _calType, _resTool);// hide pax dropdowns so they don't overlap calendar
	            
                if ( _oppositeCalOpen == true ){// hide other calendar, if visible
                    newCalendarClass(_oppositeId, "visibility_off", _oppositeCalType);// hide calendar
                    //this.toggleDropdownsForIECalDisplay("hide", _oppositeCalType, _resTool);// show pax dropdowns
                    eval("this." + _oppositeCalType.toLowerCase() + "CalOpen = false");// change object property
                }
	            eval("this." + _calType.toLowerCase() + "CalOpen = true");// set property indicating this calendar is open == true
	        }
	        else {
	            newCalendarClass(_id, "visibility_off", _calType); // hide calendar
	            //this.toggleDropdownsForIECalDisplay("show", _calType, _resTool); // show pax dropdowns
	            eval("this." + _calType.toLowerCase() + "CalOpen = false");
	        }
        },
        
        
    // Function Name: togglePaxDropdownsForIE6CalDisplay
    // Purpose: toggle pax dropdowns visible so they don't appear above the calendars in IE6
    // Parameters: typ => [show | hide]
    // Return: None  
      
        toggleDropdownsForIECalDisplay: function(typ, cal, resTool)
        {
            var visType = "";
            var browserName = navigator.appName;
            
            var _resTool = resTool; // ["main" | "hotelProfiles" | "deals"]
            var i, j, k;
            
            // for depart menu
            var depart_rooms_1_children_no =    ["rooms","adults1","children1"];
            var depart_rooms_2_children_no =    ["rooms","adults1","adults2","children1","children2"];
            var depart_rooms_2_children_1 =     ["rooms","adults1","children1","child1Age1","child1Age2","child1Age3","child1Age4"];
            var depart_rooms_2_children_2 =     ["rooms","adults1","adults2","children1","children2"];
            
            // for return menu
            var return_rooms_1_children_no =    ["rooms","adults1","children1"];
            var return_rooms_2_children_no =    ["rooms","adults1","adults2","children1","children2"];
            var return_rooms_3_children_no =    ["rooms","adults1","adults2","adults3","children1","children2","children3"];
            var return_rooms_1_children_1 =     ["rooms","adults1","children1","child1Age1","child1Age2","child1Age3","child1Age4"];
            
            var return_rooms_2_children_1 =     ["rooms","adults1","adults2","children1","children2","child1Age1","child1Age2","child1Age3","child1Age4"];
            var return_rooms_2_children_2 =     ["rooms","adults1","adults2","children1","children2","child2Age1","child2Age2","child2Age3","child2Age4"];
            
            // RULE: if room 1 has children, no need to check to see if room 2 has children.
            //          BECAUSE if room 1 has children, room 2's children will
            //          be pushed down far enough to NOT need to be hidden
            // below is same as "return_rooms_2_children_1"
            // var return_rooms_2_children_1_2 =   ["rooms","adults1","adults2","children1","children2","child1Age1","child1Age2","child1Age3","child1Age4"];
            
           
            var calType = cal.toLowerCase();
            var currentNumRooms = RoomValues.rooms.length;
            var this_child_present = "no";
            var room1_child_present = "no";
            var room2_child_present = "no";
            var room_child_value = "no";
            var room_loop_limit = 0;
            var thisArray;
            
            if ( RoomValues.rooms.length < 2 ){
                room_loop_limit = RoomValues.rooms.length; 
            }
            else {
                room_loop_limit = 2;
            }
            
            for(i = 0; i < room_loop_limit; i++){
                if ( RoomValues.rooms[i].numChildren > 0 ){
                    eval("room" + (i+1) + "_child_present = '" + (i+1) + "'");
                }
            }
            
            if( browserName == "Microsoft Internet Explorer" ){
                if ( typ == "show" ){
                    visType = "visible";
                }
                else {
                    visType = "hidden";
                }
                
                for (j = 0; j < 2; j++){// we are only concerned with the first 2 rooms here, hence the j < 2
                    this_child_present = eval("room" + (j+1) + "_child_present");
                
                    if ( this_child_present != "no" ){
                        room_child_value = this_child_present;
                        break;
                    }
                }
                
                if ( calType == "depart" ){// rules for applying existing show/hide div set arrays to room counts above the "affected" numbers
                    if (currentNumRooms > 2){
                        currentNumRooms = 2;
                    } 
                }
                else if ( calType == "return" ){
                    if ( (room1_child_present == "no") && (room2_child_present == "no") )
                    {
                        if (currentNumRooms >= 3){
                            currentNumRooms = 3;
                        }
                    }
                    else {
                        if (currentNumRooms > 2){
                            currentNumRooms = 2;
                        }
                    }
                }
                
                thisArray = eval(calType + "_rooms_" + currentNumRooms + "_children_" + room_child_value);
        
                //DEBUG - THIS WORKS - alert(calType + "_rooms_" + currentNumRooms + "_children_" + room_child_value);
                
                switch ( _resTool )
                {
                    case "hotelProfiles":// hide nothing
                        break;
                        
                    case "deals":// hide child count dropdowns for rooms 1 & 2
                        if ( calType == "depart" ) {
                           document.getElementById("children1").style.visibility = visType; 
                        }
                        else {
                            document.getElementById("children1").style.visibility = visType;
                            document.getElementById("children2").style.visibility = visType;
                        }
                        
                        break;
                        
                    case "main":
                        if ( thisArray != null )
                        {
                            if ( !this.paxCountExceeded ){ // only hide if pax count error message is not visible
                                
                                for (k = 0;k < thisArray.length;k++) //loop through array and hide elements
                                {
                                    document.getElementById(thisArray[k]).style.visibility = visType;
                                }  
                            }
                            else {
                                document.getElementById("rooms").style.visibility = visType;
                            }
                        }
                        break;
                            
                    default:
                        break;
                } 
            }
        },
    
    // Function Name: FIND
    // Purpose: locate and return DOM object
    // Parameters: item - id of target object
    // Return: DOM object
    
        FIND: function(item)
        {
	        if (document.all){
		        return(document.all[item]);
	        } 
	        if (document.getElementById){
		        return(document.getElementById(item));
	        } 
	        return(false);
        },
    	
    
    // Function Name: changeClass
    // Purpose: change CSS class of DOM object
    // Parameters: elm - id of target object, newClass - new class for target object
    // Return: nothing
    
	    changeClass: function(elm, newClass)
	    {
	        var thisElm = this.FIND(elm);
	        
		    if ( thisElm )
		    {
			    thisElm.className = newClass;
		    }
	    },
	   
	   
    // Function Name: convertDateToMMDDYYYY
    // Purpose: Takes in a date object and converts it to "MM/DD/YYYY" format
    // Parameters: dateIn - JS date variable to format
    // Return: date as string in "MM/DD/YYYY" formatting

        convertDateToMMDDYYYY: function(dateIn)
        {
	        var year, month, day, retDate;
        	
	        year = dateIn.getFullYear();
	        month = dateIn.getMonth() + 1; // 0-base collection so add 1
	        day = dateIn.getDate();
        	
	        if ( month < 10 ) {
	            month = "0" + month.toString();
	        }
        	
	        if ( day < 10 ) {
	            day = "0" + day.toString();
	        }

	        retDate =  month + "\/" + day + "\/" + year;
        	
	        return retDate;
        },
    
    
    // Function Name: initDepartureDate
    // Purpose: Initializes the departure date to how many days specified out as in the global variables OR
    //          is set to a value passed back from the booking engine
    // Parameters: dateIn - date value posted in from booking engine
    // Return: None
    
        initDate: function(dateIn, typ)
        {
	        var outValue = "";
	        var dateInput;
	        var d = new Date();
	        
	        var lastSlash = 0;
	        var firstDash = 0;
	        var yearStr = "";
	        var moDateStr = "";
	        var moDateAry;
        	
	        if ( dateIn == "" ) // dateIn has no value, which means this wasn't posted from booking engine
	        {
		        if ( typ == "depart" )
		        {
			        d.setDate(d.getDate() + g_DepartOffset);
			        outValue += this.padAge((d.getMonth() + 1).toString()) + "/";
			        outValue += this.padAge(d.getDate().toString()) + "/";
			        outValue += d.getFullYear().toString().substr(2,2);
		        }
		        else {
			        // set default value for return date field
			        outValue = "mm\/dd\/yy";
		        } 
	        }
	        else  
	        {
		        // values have been posted back from booking engine in 2008-03-13T10:00:00 format, so change it to 01/01/01 
		        if (dateIn.indexOf("-") != -1)
		        {
			        firstDash = dateIn.indexOf("-");
			        yearStr = dateIn.substr(0, firstDash);
			        yearStr = yearStr.substr(2,2);
			        moDateStr = dateIn.substr(firstDash+1,5);
			        moDateAry = moDateStr.split("-");
			        outValue = moDateAry[0] + "\/" + moDateAry[1] + "\/" + yearStr;
		        }
		        // values have been posted back from booking engine in 01/01/2001 format, so change it to 01/01/01
		        else {
			        lastSlash = dateIn.lastIndexOf("\/");
			        yearStr = dateIn.substring(lastSlash + 1);
			        yearStr = yearStr.substr(2,2);
			        moDateStr = dateIn.substr(0,lastSlash);
			        outValue = moDateStr + "\/" + yearStr;
		        }
	        }
        	
	        if ( typ == "depart" )
	        {
		        // this.FIND did not work in IE... WHY? NO IDEA
		        document.getElementById("gsDepartureDate").value = outValue;
	        }
	        else if ( typ == "return" )
	        {
		        // this.FIND did not work in IE... WHY? NO IDEA
		        document.getElementById("gsReturnDate").value = outValue;
	        }
        },
        
    // Function Name: initGenericField
    // Purpose: Initializes given text box with given posted value
    // Parameters:  val => the value to place in the field
    //              fld => the field ID
    // Return: None
    
        initGenericField: function(val, fld, fldTyp)
        {
            var outValue = val;
	        var input = this.FIND(fld);
			//var input = document.getElementById(fld);
	        var i = 0;
	        
	        if ( input ) 
	        {
	            if ( fldTyp == "text" )
	            {
	                input.value = outValue;
	            }
	            else if ( fldTyp == "select" ) 
	            {
	                //loop thru select and find index whose value matches outValue
	                for (i = 0; i < input.options.length; i++)
	                {
	                    if ( input.options[i].value == outValue )
						{
							input.selectedIndex = i;
						}
	                }
	            }
	        }
        },
        
        
    // Function Name: highlightDateInput
    // Purpose: handles click event on date input fields to clear default date text (mm/dd/yy)
    //          or highlight date currently in input
    // Parameters:  elm => the input to highlight/clear
    // Return: None
    
        highlightDateInput: function(elm)
		{
			if ( elm.value == "mm/dd/yy" ) {
				elm.select();
			}
		},
  
        
    // Function Name: initOriginDestination
    // Purpose: Initializes the origin to a value passed back from the booking engine
    // Parameters: orgIn - previously selected org code that has been passed back from the booking engine
    // Return: None
    
        initOriginDestination: function(inOrg, inDest, inPackage, inResToolType)
        {
            var i = 0;
            var j = 0;
            var orgSelect = document.getElementById("gsOrigin");
            var destSelect = document.getElementById("gsDestination");
            var destLabel = document.getElementById("gsDestinationLabel");
            var orgValue = "";
            var cookieValue = "";
            var thisOptionValueOrg = "";
            var thisOptionValueDest = "";
            var checkFormElmExistTimeout = null;
            var activeIndex = 0;
            var isAir = false;
            var isHotelProfileResTool = false;
            var isHotDealsResTool = false;
            if ( inPackage.indexOf("A") != -1 ) { isAir = true; }
            if ( inResToolType == "hotel" ) { isHotelProfileResTool = true; }
            if ( inResToolType == "hotdeals" ) { isHotDealsResTool = true; }
            
            cookieValue = this.readCookie("dDownOrg");
            
            // check to see if DOM elements are present
            if ( orgSelect && destSelect ) {
                // only do the following if this is not the hot deals res tool
                if (!isHotDealsResTool) {
                    // populate origin dropdown
                    this.doDynamicOrigins();
                }
                
                if ( inOrg.length < 3 ) { // if empty string, length will be "0"
                    if ( typeof(cookieValue) == "object" ) { 
                        // IE 6 and 7 if cookie has not been set
                        orgValue = "XXX";
                    }
                    else if ( cookieValue.length == 9 ) {   
                        // firefox "undefined" (9 characters) if cookie has not been set
                        orgValue = "XXX";
                    }
                    else {
                        orgValue = cookieValue;
                    }
                }
                else {
                    // stick with the value because it's coming from the hot deal
                    orgValue = inOrg;
                }
                
                if ( orgValue != "XXX" ) { 
                    // set selected origin
                    if ( orgSelect.options.length > 0 ) {
                        for(i = 0; i < orgSelect.options.length; i++) {
                            thisOptionValueOrg = orgSelect.options[i].value;
                            thisOptionValueOrg = thisOptionValueOrg.toUpperCase();
	                        
                            if ( thisOptionValueOrg == orgValue ) {
                                orgSelect.selectedIndex = i;
                                break;
                            }
                        }
                    }
	                // populate dest dropdown with origin-specific destinations
	                this.doDynamicDestinations(orgValue, false);
	            }
	            else {
	                if ( !isHotelProfileResTool ) {
	                    this.doDynamicDestinations(orgValue, false);
	                }
	                else {
	                    this.doDynamicDestinations(orgValue, true);
	                }
	            }
	            
	            // set selected destination in dest dropdown if destIn has value that is not "XXX" 
    	        if ( inDest != "" ) {                                            
                    if ( destSelect && destSelect.options ) {
                        if ( destSelect.options.length > 0 ) {
                            for(j = 0; j < destSelect.options.length; j++) {
                                thisOptionValueDest = destSelect.options[j].value;
                                thisOptionValueDest = thisOptionValueDest.toUpperCase();
    	                        
                                if ( thisOptionValueDest == inDest ) {
                                    activeIndex = j;
                                    break;
                                }
                            }
                        }
                    } 
                }
                
                // this will be used by the hotel & deals(?) pages to display
                // dest label if there is only one destination
                this.showHideDestDropdown();
    	        
	            // hide origin dropdown if air is not part of current package
	            if ( inPackage != "" ) {
	                if ( !isAir ) {
	                    document.getElementById("orgContainer").style.display = "none";
	                    if(document.getElementById("resInfants1")){
	                        document.getElementById("resInfants1").style.display = "none";
	                    }
	                    if(document.getElementById("resInfants2")){
	                        document.getElementById("resInfants2").style.display = "none";
	                    }
	                    if(document.getElementById("resInfants3")){
	                        document.getElementById("resInfants3").style.display = "none";
	                    }
	                    if(document.getElementById("resInfants4")){
	                        document.getElementById("resInfants4").style.display = "none";
	                    }  
	                }
	            }
	            
	            //set selected index of dest dropdown
	            destSelect.selectedIndex = activeIndex;
            }
            else 
            {
                //DEBUG
                //THIS BLOCK IS NOT HIT WHEN ERROR WITH HOTEL PROFILES DEST DROPDOWN OCCURS 
                //alert("dropdown not found in DOM");
            }
        },
     
            
    // Function Name: doDynamicOrigins
    // Purpose: build origins dropdown
    // Parameters: none
    // Return: none
        
        doDynamicOrigins: function() 
        {
            var i,j,nOpt,ddOrg;
            
            ddOrg = document.getElementById("gsOrigin");
        
            if ( ddOrg )
            {
                //remove options currenly in dropdown
	            for (j = (ddOrg.options.length - 1); j >= 0; j--) 
	            {
		            ddOrg.options[j] = null;
	            }
    	        
	            // loop thru ORGDES array, adding org to options in org dropdown
                for (i = 0; i < ORGDES.length; i++) 
                {
    	            nOpt = new Option( ORGDES[i].city, ORGDES[i].code, false, false);
				    ddOrg.options[ddOrg.options.length] = nOpt; 
                }
    	        
	            if ( ddOrg.options.selectedIndex == -1 ) 
	            {
		            ddOrg.options.selectedIndex = 0;
	            }
            }
        },


    // Function Name: doDynamicDestinations
    // Purpose: build destinations dropdown based on choice made in origin dropdown
    // Parameters: inOrg - origin for which to find valid destinations
    // Return: none

        doDynamicDestinations: function( inOrg, inIsHotel ) 
        { 
            var i = 0;
            var j = 0;
            var k = 0;
        
            if ( inOrg != "XXX") {                
                this.createCookie("dDownOrg",inOrg,182);
            }
              
	        var ddDest = document.getElementById("gsDestination");
	        
	        if ( !inIsHotel ) {
	    
	            // this is regular res tool, and will pull from ORGDES array
	            if ( ddDest ) {
	                if ( ddDest.options != null )
	                {
	                    for (j=(ddDest.options.length - 1); j >= 0; j--) 
	                    {
		                    ddDest.options[j] = null;
	                    }
	                    for (k = 0; k < ORGDES.length; k++) 
	                    {
		                    if ( ORGDES[k].code == inOrg ) 
		                    {
			                    for (i = 0; i < ORGDES[k].dest.length; i++) 
			                    {
				                    var nOpt = new Option( ORGDES[k].dest[i].city, ORGDES[k].dest[i].code, false, false);
				                    ddDest.options[document.getElementById('gsDestination').options.length] = nOpt;
			                    }
        			            
			                    // exit loop so we don't duplicate options in dropdown 
			                    // if another instance of airport code is found
			                    break;
		                    }
	                    } 
	                }
	            }
	        }
	        else 
	        {
	            // THIS IS THE HOTEL PROFILES RES TOOL
	            // inOrg is null, so this is the hotels page
	            // only put valid dests to current hotel in dest dropdown ( ORGDESValidDests array )
	            if ( ddDest )
	            {
	                if ( ddDest.options != null )
	                {
	                    for (j=(ddDest.options.length - 1); j >= 0; j--) 
	                    {
		                    ddDest.options[j] = null;
	                    }
    	                
	                    // only show first index in ORDDESValidDests array
	                    for (i = 0; i < ORGDESValidDests[0].dest.length; i++) 
	                    {
		                    var nOpt = new Option( ORGDESValidDests[0].dest[i].city, ORGDESValidDests[0].dest[i].code, false, false);
		                    ddDest.options[document.getElementById('gsDestination').options.length] = nOpt;
	                    }
	                }
	            }
	        } 
        },
        
    // Function Name: showHideDestDropdown
    // Purpose: hide destinations dropdown if no destinations
    // Parameters: none
    // Return: none
    
        showHideDestDropdown: function() 
        {
	        var destDropdown = document.getElementById("gsDestination");
	        var destLabel = document.getElementById("gsDestinationLabel");
        	
	        if (destDropdown.length == 1) 
	        {
	            //DEBUG
	            //alert("showHideDestDropdown -> destDropdown.length = 1");
	            
	            if(destLabel)
	            {
	                destLabel.innerHTML = destDropdown[0].text;
		            destLabel.style.display = "block"; 
	            }
	            
	            if(destDropdown)
	            {
	                destDropdown.style.display = "none";
	            }
	        }
	        else 
	        {
	            if ( destLabel )
	            {
	                destLabel.style.display = "none";
	            }
	            
		        if ( destDropdown )
		        {
		            destDropdown.style.display = "block";
		        }
	        }
	        
	        // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        //equalColumns('resToolContainer','resShadow');
        },
       
       
    // Function Name: addOption
    // Purpose: addOption to specified dropdown
    // Parameters:  selectbox   => dropdown to add option to
    //              text        => text for option
    //              value       => value of option
    //              isSelect    => mark option as selected if true
    // Return: none
        
        /*addOption: function(selectbox,text,value,isSelect)
        {
            var optn = document.createElement("option");
            optn.text = text;
            optn.value = value;
            optn.selected = isSelect;
            selectbox.options.add(optn);
        },*/
       
       
    // Function Name: adjustYear
    // Purpose: Adjusts year from 2 digit to proper four digit
    // Parameters: date - Date object to have adjusted year
    // Return: Date - object with adjusted date
        
        adjustYear: function( date )
        {
	        // Check if full year returns as less then 2000
	        if (parseInt(date.getFullYear(),10) < 2000){
		        // Take year and add 2000
		        date.setFullYear(2000 + date.getYear());
		        return date;
	        }else{
		        return date;
	        }
        },

    // Function Name: findSeperator
    // Purpose: Helper function for validateDateFormat to find the seperator in the date string
    // Parameters: inDate - date to find seperator in
    // Return: Char - Seperator used in date string
    
        findSeperator: function( inDate )
        {
	        var i;
	        var retVal = "";
	        // Loop through each Char in String
	        for (i = 0; i < inDate.length; i++){
		        // If the current index value is not a number, then it is the seperator
		        if (isNaN(inDate.substr(i,1))){
			        retVal = inDate.substr(i,1);
		        }
	        }
	        return retVal;
        },
        
    // Function Name: adjustYear
    // Purpose: Adjusts year from 2 digit to proper four digit
    // Parameters: date - Date object to have adjusted year
    // Return: Date - object with adjusted date
    
        adjustYear: function( date )
        {
	        // Check if full year returns as less then 2000
	        if (parseInt(date.getFullYear(),10) < 2000)
	        {
		        // Take year and add 2000
		        date.setFullYear(2000 + date.getYear());
		        return date;
	        }
	        else
	        {
		        return date;
	        }
        }, 
        
    // Function Name: getDepartDate
    // Purpose: gets value of departure date field and passes to return date calendar for display
    // Parameters: None
    // Return: value of depart date field
    
        getDepartDate: function()
	    {
	        return document.getElementById("gsDepartureDate").value;
	    },
        
    // Function Name: TRIM
    // Purpose: Standard string trim function
    // Parameters: s - string to be trimmed of whitespace
    // Return: String - trimmed string
    
        TRIM: function( s ) 
        {
          // Remove leading spaces and carriage returns
          while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
          {
            s = s.substring(1,s.length);
          }
          // Remove trailing spaces and carriage returns
          while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
          {
            s = s.substring(0,s.length-1);
          }
          return s;
        },
        
    // Function Name: showHideBookingOptions
    // Purpose: Shows or hides available booking options based on package type
    // Parameters: compOrder - code representing required/available components for particular package type
    // Return: None

        showHideBookingOptions: function( compOrder, inIsHotelProfile, inIsPageLoad )
        {
            var isAir = false;
            var isHotel = false;
            var isHotelProfile = inIsHotelProfile;
            var isPageLoad = inIsPageLoad;
            
            this.currentComponentOrder = compOrder;
            
            isAir = compOrder.indexOf("A") != -1;
            isHotel = compOrder.indexOf("H") != -1;

            if ( !isAir && !isHotel ) /*FC*/
            {
                document.getElementById("orgContainer").style.display = "none";
                document.getElementById("divRoomContainer").style.display = "none";
                document.getElementById("depDateCaptAir").style.display = "none";
                document.getElementById("depDateCaptLandOnly").style.display = "block";
                
                if(document.getElementById("resInfants1")){
                    document.getElementById("resInfants1").style.display = "inline";
                }
                if(document.getElementById("resInfants2")){
                    document.getElementById("resInfants2").style.display = "inline";
                }
                if(document.getElementById("resInfants3")){
                    document.getElementById("resInfants3").style.display = "inline";
                }
                if(document.getElementById("resInfants4")){
                    document.getElementById("resInfants4").style.display = "inline";
                }
                
                this.hideRooms();
                
                // set origins to default list as there is no origin
                if ( !isPageLoad )
                {
                    this.doDynamicDestinations("XX1", isHotelProfile);
                }
               
                this.showHideRoomReferences("hide");
            }
            else if ( !isAir && isHotel ) /*HCF*/
            {      
	            document.getElementById("orgContainer").style.display = "none";
	            document.getElementById("divRoomContainer").style.display = "block";
	            document.getElementById("depDateCaptAir").style.display = "none";
                document.getElementById("depDateCaptLandOnly").style.display = "block";
                
                if(document.getElementById("resInfants1")){
                    document.getElementById("resInfants1").style.display = "none";
                }
                if(document.getElementById("resInfants2")){
                    document.getElementById("resInfants2").style.display = "none";
                }
                if(document.getElementById("resInfants3")){
                    document.getElementById("resInfants3").style.display = "none";
                }
                if(document.getElementById("resInfants4")){
                    document.getElementById("resInfants4").style.display = "none";
                }
                
                // set origins to default list as there is no origin
                if ( !isPageLoad )
                {
                    this.doDynamicDestinations("XXX", isHotelProfile);
                }
                
	            this.showHideRoomReferences("show");
	        }
	        else if ( isAir && !isHotel ) /*ACF*/
	        { 
	            document.getElementById("orgContainer").style.display = "block";
	            document.getElementById("divRoomContainer").style.display = "none";
	            document.getElementById("depDateCaptAir").style.display = "block";
                document.getElementById("depDateCaptLandOnly").style.display = "none";
                
                if(document.getElementById("resInfants1")){
                    document.getElementById("resInfants1").style.display = "inline";
                }
                if(document.getElementById("resInfants2")){
                    document.getElementById("resInfants2").style.display = "inline";
                }
                if(document.getElementById("resInfants3")){
                    document.getElementById("resInfants3").style.display = "inline";
                }
                if(document.getElementById("resInfants4")){
                    document.getElementById("resInfants4").style.display = "inline";
                }
                
	            this.hideRooms();
	            this.showHideRoomReferences("hide");    
	        }
	        else /*AHCF*/
	        {
	            document.getElementById("orgContainer").style.display = "block";
                document.getElementById("divRoomContainer").style.display = "block";
                document.getElementById("depDateCaptAir").style.display = "block";
                document.getElementById("depDateCaptLandOnly").style.display = "none";
                
                if(document.getElementById("resInfants1")){
                    document.getElementById("resInfants1").style.display = "inline";
                }
                if(document.getElementById("resInfants2")){
                    document.getElementById("resInfants2").style.display = "inline";
                }
                if(document.getElementById("resInfants3")){
                    document.getElementById("resInfants3").style.display = "inline";
                }
                if(document.getElementById("resInfants4")){
                    document.getElementById("resInfants4").style.display = "inline";
                }
                
                this.showHideRoomReferences("show");
	        }
	        
	        // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        // equalColumns('resToolContainer','resShadow');   
        },

    // Function Name: showHideRoomReferences
    // Purpose: encapsulates function calls for multi-room
    // Parameters: type => [show | hide]
    // Return: None

        showHideRoomReferences: function( type )
        {
           var divRoomDropDownObj = this.FIND("rooms");

           if ( type == "show" )
           {
                // show "Room 1" label
	            document.getElementById("divLabelRoom1").style.display = "block";
	            // show "Rooms" dropdown
                document.getElementById("divRoomContainer").style.display = "block";
           }
           else {
                // hide "Room 1" label
                document.getElementById("divLabelRoom1").style.display = "none";
                // hide "Rooms" dropdown
                document.getElementById("divRoomContainer").style.display = "none";
                
                if ( divRoomDropDownObj ) 
                {
                    divRoomDropDownObj.selectedIndex = 0;
                }
           }
           
           // reset height of dropshadow col based on form changes
	       // function "equalColumns" defined in header
	       //equalColumns('resToolContainer','resShadow');
       },
       
    // Function Name: createCookie
    // Purpose: writes or updates cookie
    // Parameters: name => [cookie name], value => [cookie value], days => [days until cookie expiration]
    // Return: None

        createCookie: function( name,value,days )
        {      
           if (days) {           
		        var date = new Date();
		        date.setTime(date.getTime()+(days*24*60*60*1000));
		        var expires = "; expires="+date.toGMTString();
	        }
	        else {
	            var expires = "";
	        }
	        document.cookie = name+"="+value+expires+";";
       },
       
    // Function Name: readCookie
    // Purpose: reads cookie
    // Parameters: name => [cookie name]
    // Return: None

        readCookie: function( name )
        {
           var nameEQ = name + "=";
	       var ca = document.cookie.split(';');
	        for(var i=0;i < ca.length;i++) {
		        var c = ca[i];
		        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	        }
	        return null;
       },  
       
       
    /*BEGIN TRANSFERRED FROM ROOMVALUES.JS 2.29.08 - CK*/
     
    // Function Name: showRooms
    // Purpose: invoked by "Rooms" dropdown menu onchange
    // Parameters: idx => selected index in "Rooms" select
    // Return: None

        showRooms: function(idx)
        {   
	        var roomCount = idx+1;
	        var maxPossibleRooms = 4;
	        var thisRoom;
	        var numToHide = RoomValues.maxPossibleRooms - roomCount;
            var newRoom;
            var difference = 0;
            
            // is the selected number of rooms larger than the number contained in the rooms array?
            if ( roomCount > RoomValues.rooms.length )
            {
                // find number of rooms to add
                difference = roomCount - RoomValues.rooms.length;
                
                for(i = 0; i < difference; i++)
                {
                    //add new room object to rooms array
                    newRoom = new Object();
                    newRoom.numAdults = 2;
                    newRoom.numChildren = 0;
                    newRoom.childAges = new Array();
                    newRoom.totalTravelers = 2;
                    newRoom.maxOccupancyExceeded = false;
                    RoomValues.rooms.push(newRoom);
                }
            }
            else {
                // find number of rooms to remove
                difference = RoomValues.rooms.length - roomCount;
                
                for(i = 0; i < difference; i++)
                {   
                    // remove last room object from rooms array
                    RoomValues.rooms.pop();
                }
            }
            
	        // show requested # rooms
	        for(i = 0; i < roomCount; i++)
	        {
		        thisRoom = "divRoom" + (i+1);
		        document.getElementById(thisRoom).style.display = "block";
	        }
	        // hide any rooms currently displaying beyond # requested
	        if ( (maxPossibleRooms - roomCount) > 0 ) 
	        {
		        for(j = maxPossibleRooms; j > roomCount; j--)
		        {
			        thisRoom = "divRoom" + j;
			        document.getElementById(thisRoom).style.display = "none";
		        }
	        }
	        
	        // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        // equalColumns('resToolContainer','resShadow');
	        
	        /* call function to make pax/child age values ready for booking engine */
            RoomValues.createPipeDelimitedStrings();
        },

    
    // Function Name: hideRooms
    // Purpose: this function is invoked by this.showHideBookingOptions() 
    //          to hide extra rooms (2,3,4) when package type is changed to one that does not include hotel
    // Parameters: None
    // Return: None
     
        hideRooms: function()
        {
	        var thisRoom;
	        var thisChildrenDropDown;
	        var thisChildrenDropDownObj;
		    var j;
		    var maxPossibleRooms = 4;
		    var currentNumRooms = RoomValues.rooms.length;
            
	        for(j = currentNumRooms; j > 1; j--)
	        {
		        thisRoom = "divRoom" + j;
		        document.getElementById(thisRoom).style.display = "none";
		        thisChildrenDropDown = "children" + j;
		        thisChildrenDropDownObj = this.FIND(thisChildrenDropDown);
    			
		        // reset # children dropdown
		        if ( thisChildrenDropDownObj )
		        {
			        thisChildrenDropDownObj.selectedIndex = 0;
		        }
    			
			    // remove room from rooms object
			    RoomValues.rooms.pop();
    			
		        // hide child age dropdowns
		        this.hideChildren(j);
	        }
	        
	        // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        // equalColumns('resToolContainer','resShadow');
	        
	        /* call function to make pax/child age values ready for booking engine */
            RoomValues.createPipeDelimitedStrings();
        },

   
    // Function Name: showChildren
    // Purpose: displays pax sets for multiple rooms
    // Parameters: obj => reference to dropdown generating event
    // Return: None

        showChildren: function(obj)
        {   
            var objName = obj.name;
            var objIdx = obj.selectedIndex;
            
            //get number of child dropdown... naming is "children1", "children2", etc
            var room = objName.substr(8,1) // room will equal single digit int
	        var childCount = objIdx;
	        var maxChildCount = RoomValues.maxChildCount;
	        var thisChildBlock = "divChildrenAges" + room;
	        var numToHide = maxChildCount - childCount;
    		
	        if ( objIdx > 0 )
	        {
		        //display parent dropdown container  
		        document.getElementById(thisChildBlock).style.display = "block";
    			
		        //show requested # children
		        for(i = 0; i < childCount; i++)
		        {
			        thisChild = "divSelectChild" + room + "Age" + (i+1);
			        document.getElementById(thisChild).style.display = "block";
		        }
		        //hide any rooms currently displaying beyond # requested
		        if ( (maxChildCount - childCount) > 0 ) 
		        {
			        for(j = maxChildCount; j > childCount; j--)
			        {
				        thisChild = "divSelectChild" + room + "Age" + j;
				        document.getElementById(thisChild).style.display = "none";
    				    
				        // remove unneeded ages from childAges array
				        RoomValues.rooms[room-1].childAges.pop();
			        }
		        }
	        }
	        else 
	        {
		        document.getElementById(thisChildBlock).style.display = "none";
    			
		        for(i = 0; i < maxChildCount; i++)
		        {
			        thisChild = "divSelectChild" + room + "Age" + (i+1);
			        document.getElementById(thisChild).style.display = "none";
		        }
		        // hide child age elements and reset dropdowns
		        this.hideChildren(room);
    		    
                // remove unneeded ages from childAges array 
		        if ( RoomValues.rooms[room-1].numChildren > 0 )
                {
                    for(i = 0; i < RoomValues.rooms[room-1].numChildren; i++)
                    {
                        RoomValues.rooms[room-1].childAges.pop();
                    }
                    
                    RoomValues.rooms[room-1].numChildren = 0;
                }
	        } 
    	    
    	    // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        // equalColumns('resToolContainer','resShadow');
    	    
	        RoomValues.modifyOccupants(obj); 
        },


    // Function Name: hideChildren
    // Purpose: hides child age dropdowns
    // Parameters: rm => room index for which to  hide children
    // Return: None
    
        hideChildren: function(rm)
        {
	        var thisParent = "divChildrenAges" + rm;
	        var thisChild;
	        var thisChildrenDropDown;
	        var thisChildDropDown;
	        var i,j,k;
	        var maxChildCount = RoomValues.maxChildCount;
    		
	        // hide parent dropdown container
	        document.getElementById(thisParent).style.display = "none";
	        // hide each individual dropdown container
	        for(i = 0; i < maxChildCount; i++)
	        {
		        thisChild = "divSelectChild" + rm + "Age" + (i+1);
		        document.getElementById(thisChild).style.display = "none";
	        }
    	    
	        // reset ages in dropdowns
	        for(j = 0; j < maxChildCount; j++)
	        {
		        thisChildDropDown = "child" + rm + "Age" + (j+1);
		        thisChildDropDownObj = this.FIND(thisChildDropDown);
    			
		        if ( thisChildDropDownObj )
		        {
			        thisChildDropDownObj.selectedIndex = 0;
		        }
	        }
	        
	        // reset height of dropshadow col based on form changes
	        // function "equalColumns" defined in header
	        //equalColumns('resToolContainer','resShadow');
        },

    // Function Name: clearChildren
    // Purpose: resets child age dropdown and calls hideChildren
    // Parameters: rm => room index for which to hide children
    // Return: None
    
        clearChildren: function(rm)
        {
	        var thisChildrenDropDown;
	        var thisChildrenDropDownObj;
	        var j;
    	   
	        for(j = RoomValues.maxPossibleRooms; j > 1; j--)
	        {
		        thisChildrenDropDown = "children" + j;
		        thisChildrenDropDownObj = this.FIND(thisChildrenDropDown);
    			
		        // reset # children dropdown
		        if ( thisChildrenDropDownObj )
		        {
			        thisChildrenDropDownObj.selectedIndex = 0;
		        }
    			
		        // hide child age dropdowns
		        this.hideChildren(j);
	        }
        },
        
        
    /* 3.7.08 CK - BEGIN TRANSFERRED FROM RESTOOL.JS */
    // Function Name: submitSBT
    // Purpose: Submits the SBT form directly to SBT
    // Parameters: None
    // Return: None
        submitSBT: function()
        {    	
	        var validForm = this.validateDepartureDateSubmit();	
            var lengthOfStay;
	        if ( CommonResTool.currentComponentOrder.indexOf("A") != -1 ) // if no air, then, no origin
	        {      
	            validForm = this.validateOriginSubmit() && validForm;
	        }
        	
	        validForm = this.validateReturnDateSubmit() && validForm;	
            validForm = this.validateDestinationSubmit() && validForm;
            validForm = RoomValues.checkOccupancyWarningStateOnSubmit() && validForm;
          
            if (document.resTool.gsPromotionCode.value !=null){
                if (document.resTool.gsPromotionCode.value != ""){
                    if (validate(document.resTool.gsPromotionCode.value, "PROMOCODE") == false) {
			            if(document.getElementById("promoWarning1")!=null){
			                document.getElementById("promoWarning1").style.display = "block"
			                return false;
			            } 
			            if(document.getElementById("promoWarning2")!=null){
			                document.getElementById("promoWarning2").style.display = "block"
			                return false;
			            }
			      
			        }
		        }
		    }
	    
        	
	        if (validForm){	    

	            // Determine package type	      
                var packageTypeLen = 0;
                var setPackageType = false;
                var packageType = "";
                
                // if the package type radio button list exists, loop thru and find selected value
                // if there are no radio buttons, we are on the super res tool page where the 
                // package type is passed in with the other deal data, and plugged into a hidden form field via ASP
                if ( document.resTool.packageType )
                {
                    packageTypeLen = document.resTool.packageType.length;
                
                    for(var i = 0; i < packageTypeLen; i++) 
                    {
	                    if(document.resTool.packageType[i].checked) 
	                    {
		                    packageType = document.resTool.packageType[i].value;
	                    }
	                }
	                // we found a package type and will transfer the value to SBTresTool in submitSBT() function
	                // otherwise, setPackageType will remain false
	                if ( packageType != "" )
	                {
	                    setPackageType = true;
	                } 
                }
                
    	        var departDateStr = document.getElementById('gsDepartureDate').value;
    	        var returnDateStr = document.getElementById('gsReturnDate').value;
            	
	            // Create date objects out of return and departure date
	            var departDate = new Date(departDateStr);
                var returnDate = new Date(returnDateStr);        

                // set gsLengthOfStay
                lengthOfStay = Math.round((Date.parse(returnDateStr) - Date.parse(departDateStr)) / 86400000);
                
	            // Adjust year from '05' to '2005'
	            departDate = CommonResTool.adjustYear(departDate);
	            returnDate = CommonResTool.adjustYear(returnDate);
        	    	    
                // format dates as "MM/DD/YYYY" for booking engine
                departDate = CommonResTool.convertDateToMMDDYYYY(departDate);
                returnDate = CommonResTool.convertDateToMMDDYYYY(returnDate);
                
	            if ( setPackageType ) // if this is true, we have a package type from a radio button list
	            {                     // otherwise, it is the super res tool and the package type is passed into a hidden form field via ASP
	                document.SBTresTool.gsVacationType.value = packageType;
	            }
        	    
	            if (document.getElementById("gsOrigin").style.display != 'none')
	            {
	                document.SBTresTool.gsOrigin.value = document.resTool.gsOrigin[document.resTool.gsOrigin.selectedIndex].value;
	            }else{
	                document.SBTresTool.gsOrigin.value = '';
	            }
	            //added xx1 code for activities only, is not a valid dest code so we have to remove before posting
	            if (document.SBTresTool.gsOrigin.value == "XX1")
	                document.SBTresTool.gsOrigin.value = '';
	                
	            // This is for super res tool... the destination is pre-filled, and thus in a hidden form field instead
	            // of a select. Check the type of the form field before assigning value to SBTresTool elm.
	            
	            if ( (document.getElementById("gsDestination").type == "hidden") || (document.getElementById("gsDestination").type == "text") ) 
	            {
	                document.SBTresTool.gsDestination.value = document.resTool.gsDestination.value;
	            }
	            else {
	                document.SBTresTool.gsDestination.value = document.resTool.gsDestination[document.resTool.gsDestination.selectedIndex].value;
	            }
	            
	            document.SBTresTool.gsDepartureDate.value = departDate;	
	            document.SBTresTool.gsReturnDate.value = returnDate;
	            document.SBTresTool.gsLengthOfStay.value = lengthOfStay;
	            document.SBTresTool.gsPromotionCode.value = document.resTool.gsPromotionCode.value;
        	    
	            // don't overwrite if SEO "Referrer" variable value is set in document.SBTresTool.sbtReferrer
	            if( document.SBTresTool.Referrer.value  != "")
	            {
	                document.SBTresTool.Referrer.value = document.resTool.Referrer.value;
	            }
            		     
	            document.SBTresTool.submit();
        	    
	            // reset rooms array
	            //RoomValues.resetRoomsArray();
	        }
            return false;
        },	

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    // Function Name: validateDateFormat
    // Purpose: Validates entered date against a regular expression and valid values, accounts for leap years in february.
    // Parameters: inDate - string representation of date
    // Return: Boolean - whether the date is valid
    
        validateDateFormat: function( inDate ) 
        {
            // Generate regular expression for "mm/dd/yy[yy]" where the month and day can be 1 or 2 digits and year 2 or 4
            var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;
            
	        // Test against regular expression
	        if(!objRegExp.test(inDate))
	        {
		        // Failure
		        return false; 
	        }
	        else
	        {
		        // Parse out date components and determine if it is a valid day for the month
		        // Find seperator
		        var sSeparator = findSeperator(inDate);
		        // Split date into array
		        var arrayDate = inDate.split(sSeparator);
		        // Create array of valid days for each month
		        var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		        // Parse day from array
		        var intDay = parseInt(arrayDate[1],10);
		        // Determine if month exists
		        if(arrayLookup[padAge(arrayDate[0])] != null) 
		        {
                    // Determine if the day entered is less then or equal to valid max day
                    if(intDay <= arrayLookup[padAge(arrayDate[0])] && intDay != 0)
                    {
	                    return true;
	                }
			    } 
	        }

	        // Process Feruary differently.
            var intMonth = parseInt(arrayDate[0],10);
            if (intMonth == 2) { 
	            // Pull year out of array
                var intYear = parseInt(arrayDate[2],10);
	            // Determine valid max day for February based on leap year or not.
                if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
                {
                    return true;
                } 
            }
            
            return false; 
        },

    // Needed to delay the function call, so the calendar can input the new date before validation
        validateDepartureDate: function()
        {
            // normally, the function call below would be this.validateDepartureDate2(), as
            // it's a member of the same object, but for some reason it wouldn't work; so I had to use "CommonResTool.validateDepartureDate2()
	        self.setTimeout('CommonResTool.validateDepartureDate2()', 500);
        },

    // Function Name: validateDepartureDate
    // Purpose: Validates that the departure date is not before today and is before the return date
    // Parameters: None
    // Return: Boolean - whether the date is valid
        validateDepartureDate2: function()
        {      
	        // Create a date object from the entered departure date 
	        var departDateString = document.getElementById('gsDepartureDate').value;	
            var departDate = new Date(departDateString);
            
	        // Create a date object for today.
	        var today = new Date();
	        var retVal = true;
        	
	        // Adjust year from '05' to '2005'
	        departDate = CommonResTool.adjustYear(departDate);
	       
	        // Find warnings for departures
	        // Field Required asterisk
	        var required = document.getElementById("divDepartureRequired");
	        // Invalid date entry warning
            var warning = document.getElementById("divDepartureWarning");
	        // Date is in the past warning
	        var warningPast = document.getElementById("divDepartureWarningPast");    

	        // If the departure date is still "mm/dd/yy" then don't do anything, the user hasn't entered anythign yet
	        if (document.getElementById('gsDepartureDate').value != "mm/dd/yy"){
        	  	
		        // Check if the date is not a date at all, or fails at RegEx validations
		        if (departDate == "NaN" || !CommonResTool.validateDateFormat(departDateString)){			
			        // Show invalid date warning			
		           warning.style.display = "block";	
		           required.style.display = "inline";	  
		           retVal = retVal && false;
		        }else {			
			        warning.style.display = "none";
			        required.style.display = "none";
			        retVal = retVal && true;
		        }

		        // Check if departure date is before today		
		        if (departDate < today){		    
		            // Show date in past warning			
		           warningPast.style.display = "block";
		           //alert("Departure Date cannot be less than today's date.");
   		           retVal = retVal && false;
		        }else{
		           warningPast.style.display = "none";
   			        retVal = retVal && true;
		        }
	        }else{
		        // We can't validate the date since nothing was entered, so that's a failure		
		        retVal = false;
	        }
	        return retVal;
        },

    // Function Name: validateDepartureDateSubmit
    // Purpose: Similar to validateDepartureDate, but only called on form submit, doesn't check for 'mm/dd/yy'
    // Parameters: None
    // Return: Boolean - whether the date is valid
        validateDepartureDateSubmit: function()
        {    
	        // Create a date object from the entered departure date 
	        var departDateString = document.getElementById('gsDepartureDate').value;
            var departDate = new Date(departDateString);
	        // Create a date object for today.
	        var today = new Date();	
	        var retVal = true;

	        // Adjust year from '05' to '2005'
	        departDate = CommonResTool.adjustYear(departDate);

	        // Field Required asterisk
	        var required = document.getElementById("divDepartureRequired");
	        // Invalid date entry warning
            var warning = document.getElementById("divDepartureWarning");
	        // Date is in the past warning
	        var warningPast = document.getElementById("divDepartureWarningPast");

	        // Check if the date is not a date at all, or fails at RegEx validations
	        if (departDate == "NaN" || !CommonResTool.validateDateFormat(departDateString)){
		        // Show invalid date warning
	           warning.style.display = "block";
	           required.style.display = "inline";
	           retVal = retVal && false;
	        }else{
		        warning.style.display = "none";
		        required.style.display = "none";
		        retVal = retVal && true;
	        }	
	        // Check if departure date is before today
	        if (departDate != "NaN" && CommonResTool.validateDateFormat(departDateString)){
		        if (departDate < today){		    
			        // Show date in past warning
			        warningPast.style.display = "block";
			        retVal = retVal && false;
		        }else{
			        warningPast.style.display = "none";
			        retVal = retVal && true;
		        }
	        }else{
		        warningPast.style.display = "none";
	        }	

	        return retVal;
        },

    // Function Name: validateReturnDate
    // Purpose: Validates that the return date is not before today and is after depart date, and valid format
    // Parameters: None
    // Return: Boolean - whether the date is valid
        validateReturnDate: function()
        {
            if(document.getElementById('gsReturnDate') != null){
	            // Create a date object from the entered return date 
	            var returnDateString = document.getElementById('gsReturnDate').value;
                var returnDate = new Date(returnDateString);
	            // Create a date object from the entered departure date 
                var departDate = new Date(document.getElementById('gsDepartureDate').value);
	            // Create a date object for today.
	            var today = new Date();

	            var retVal = true;

	            // Adjust year from '05' to '2005'
	            returnDate = CommonResTool.adjustYear(returnDate);
	            departDate = CommonResTool.adjustYear(departDate);
               
	            // Find warnings for returns
	            // Field Required asterisk
                var required = document.getElementById("divReturnRequired");
	            // Date in the past warning
                var warning = document.getElementById("divReturnWarning");
	            // Depart > Return warning
                var warning2 = document.getElementById("divReturnWarning2");
	            // Invalid date format warning
                var warningPast = document.getElementById("divReturnWarningPast");
                // Check if the date entered is before today
                
	            // Check if user has changed value from default value
	            if (document.getElementById('gsReturnDate').value != "mm/dd/yy"){
		            // Check if valid date format was entered
		            if (returnDate == "NaN" || !CommonResTool.validateDateFormat(returnDateString)){
			            // Show invalid date format warning
		                warning.style.display = "block";
		                required.style.display = "inline";  
			            retVal = retVal && false;
		            }else{
		               warning.style.display = "none";
		               required.style.display = "none";    
			            retVal = retVal && true;
		            }	
		            // Check if the date entered is before today
		            if (returnDate != "NaN" && CommonResTool.validateDateFormat(returnDateString)){
			            if (returnDate < today){
				            // Show past date warning
				            warning2.style.display = "block";
				            retVal = retVal && false;
			            }else{
				            warning2.style.display = "none";
				            retVal = retVal && true;
			            }
		            }else{
			            warning2.style.display = "none";
		            }
		            // Check if depart date is after return date		
		            if (returnDate != "NaN" && CommonResTool.validateDateFormat(returnDateString)){
			            if (returnDate > today){		
				            if ((departDate >= returnDate) && (departDate != "NaN")){
					            // Show Depart > Return date warning
					            warning.style.display = "none";
					            required.style.display = "none";
					            warning2.style.display = "none";
					            warningPast.style.display = "block";
					            retVal = retVal && false;
				            }else{
					            warningPast.style.display = "none";
					            retVal = retVal && true;
				            }
			            }else{
				            warningPast.style.display = "none";
			            }
		            }else{
			            warningPast.style.display = "none";
		            }
	            }else{
		            // If we are still in the default entry, then return false.
		            retVal = false;
	            }
	            return retVal;
            }
        },

    // Function Name: validateReturnDateSubmit
    // Purpose: Similar to validateReturnDate, but only called on form submit, doesn't check for 'mm/dd/yy'
    // Parameters: None
    // Return: Boolean - whether the date is valid
        validateReturnDateSubmit: function()
        {
	        // Create a date object from the entered return date 
	        var returnDateString = document.getElementById('gsReturnDate').value;
            var returnDate = new Date(returnDateString);
	        // Create a date object from the entered departure date 
            var departDate = new Date(document.getElementById('gsDepartureDate').value);
	        // Create a date object for today.
	        var today = new Date();
	        var retVal = true;

	        // Adjust year from '05' to '2005'
	        returnDate = CommonResTool.adjustYear(returnDate);
	        departDate = CommonResTool.adjustYear(departDate);
           
	        // Find warnings for returns
	        // return date required asterisk
            var required = document.getElementById("divReturnRequired");
	        // Date in the past warning
            var warning = document.getElementById("divReturnWarning");
	        // Depart > Return warnging
            var warning2 = document.getElementById("divReturnWarning2");
	        // Invalid date format warning
            var warningPast = document.getElementById("divReturnWarningPast");
            
            // Check if valid date format was entered
	        if (returnDate == "NaN" || !CommonResTool.validateDateFormat(returnDateString)){
		        // Show invalid date format warning
	            warning.style.display = "block"; 
	            required.style.display = "inline";   
		        retVal = retVal && false;
	        }else{
	           warning.style.display = "none";
	           required.style.display = "none";   
		        retVal = retVal && true;
	        }
	        // Check if the date entered is before today
	        if (returnDate != "NaN" && CommonResTool.validateDateFormat(returnDateString)){
		        if (returnDate < today){
			        // Show past date warning
			        warning2.style.display = "block";
			        retVal = retVal && false;
		        }else{
			        warning2.style.display = "none";
			        retVal = retVal && true;
		        }
	        }else{
		        warning2.style.display = "none";
	        }
	        // Check if depart date is after return date		
	        if (returnDate != "NaN" && CommonResTool.validateDateFormat(returnDateString)){
		        if (returnDate > today){		
			        if ((departDate >= returnDate) && (departDate != "NaN")){
				        // Show Depart > Return date warning
				        warning.style.display = "none";
				        warning2.style.display = "none";
				        required.style.display = "none";
				        warningPast.style.display = "block";
				        retVal = retVal && false;
			        }else{
				        warningPast.style.display = "none";
				        retVal = retVal && true;
			        }
		        }else{
			        warningPast.style.display = "none";
		        }
	        }else{
		        warningPast.style.display = "none";
	        }	
	        return retVal;
        },
        
        
    // Function Name: validateOriginSubmit
    // Purpose: Ensure that an origin has been selected from the dropdown
    // Parameters: None
    // Return: Boolean - whether the origin is valid
        validateOriginSubmit: function()
        { 
            var retVal = true; 
              
	        if ( document.getElementById("gsOrigin")[document.getElementById("gsOrigin").selectedIndex].value == 'XXX' ||document.getElementById("gsOrigin")[document.getElementById("gsOrigin").selectedIndex].value == 'XX1' )
	        {
	            document.getElementById("divOriginWarning").style.display = 'block';
	            document.getElementById("divOriginRequired").style.display = 'block';
	            retVal = retVal && false;
	        }
	        else
	        {
	            document.getElementById("divOriginWarning").style.display = 'none';
	            document.getElementById("divOriginRequired").style.display = 'none';
	        }
	        
	        return retVal;
        },

    // Function Name: validateDestinationSubmit
    // Purpose: Ensure that an destination has been selected from the dropdown
    // Parameters: None
    // Return: Boolean - whether the destination is valid
        validateDestinationSubmit: function()
        {
            var retVal = true;
            var destElmValue;
            
            if ( document.getElementById("gsDestination").type == "hidden" )
            {
                destElmValue = document.getElementById("gsDestination").value;
            }
            else 
            {
                destElmValue = document.getElementById("gsDestination")[document.getElementById("gsDestination").selectedIndex].value;
            }
              
	        if ( (destElmValue == 'XXX') || (destElmValue == '') )
	        {
	            document.getElementById("divDestinationWarning").style.display = 'block';
	            document.getElementById("divDestinationRequired").style.display = 'block';
	            retVal = retVal && false;
	        }
	        else {
	            document.getElementById("divDestinationWarning").style.display = 'none';
	            document.getElementById("divDestinationRequired").style.display = 'none';
	        }
	        return retVal;
        },
    /* END TRANSFERRED FROM RESTOOL.JS */
    
    // Function Name: validateOrigin
    // Purpose: Ensure that an origin has been selected from the dropdown
    // Parameters: None
    // Return: None
        validateOrigin: function()
        {
	        if ( document.getElementById("gsOrigin")[document.getElementById("gsOrigin").selectedIndex].value == 'XXX' || document.getElementById("gsOrigin")[document.getElementById("gsOrigin").selectedIndex].value == 'XX1')
	        {
	            document.getElementById("divOriginWarning").style.display = 'block';
	            document.getElementById("divOriginRequired").style.display = 'block';
	        }
	        else
	        {
	            document.getElementById("divOriginWarning").style.display = 'none';
	            document.getElementById("divOriginRequired").style.display = 'none';
	        }
        },

    // Function Name: validateDestination
    // Purpose: Ensure that an destination has been selected from the dropdown
    // Parameters: None
    // Return: None
        validateDestination: function()
        {
            var destElmValue;
            
            if ( document.getElementById("gsDestination").type == "hidden" )
            {
                destElmValue = document.getElementById("gsDestination").value;
            }
            else 
            {
                destElmValue = document.getElementById("gsDestination")[document.getElementById("gsDestination").selectedIndex].value;
            }
              
	        if ( (destElmValue == 'XXX') || (destElmValue == '') )
	        {
	            document.getElementById("divDestinationWarning").style.display = 'block';
	            document.getElementById("divDestinationRequired").style.display = 'block';
	        }
	        else {
	            document.getElementById("divDestinationWarning").style.display = 'none';
	            document.getElementById("divDestinationRequired").style.display = 'none';
	        }
        },
        
    // Function Name: initTravelers
    // Purpose: reset num rooms, adults, children, and child age dropdowns from what is posted back from the booking engine
    // Parameters: numTravelers, agePos1, agePos2, agePos3, agePos4
    // Return: None
        
        initTravelers: function(numTravelers, agePos1, agePos2, agePos3, agePos4)
        {
            var i,j,k,m,n;
            var aryNumTravelers, aryAgePos1, aryAgePos2, aryAgePos3, aryAgePos4;
            var numRooms = 0;
            
            // check for presence of pipe in numTravelers; this will indicate multiple rooms
            if ( numTravelers.indexOf("|") != -1 )
            {
                //DEBUG
                //THIS WORKS - alert("CommonResTool->initTravelers: MANY rooms!");
            
                // create array of "rooms"; each array index will hold number of travelers per room
                aryNumTravelers = numTravelers.split("|");
                numRooms = aryNumTravelers.length;
                
                // child positions will also have pipes even if they have no children;
                // split them up into the corresponding arrays
                aryAgePos1 = agePos1.split("|");
                aryAgePos2 = agePos2.split("|");
                aryAgePos3 = agePos3.split("|");
                aryAgePos4 = agePos4.split("|");
            }
            else 
            {
                // only one room - place number of travelers in first index of aryNumTravelers
                aryNumTravelers = new Array();
                aryNumTravelers[0] = numTravelers;
                numRooms = aryNumTravelers.length;
                
                //DEBUG
                //THIS RETURNS CORRECT VALUE - alert("CommonResTool->initTravelers->numTravelers: " + numTravelers);
                
                // initialize child age position arrays
                aryAgePos1 = new Array();
                aryAgePos2 = new Array();
                aryAgePos3 = new Array();
                aryAgePos4 = new Array();
                
                // set up first index in child position arrays to be == to gsAgeX equivalents
                aryAgePos1[0] = agePos1;
                aryAgePos2[0] = agePos2;
                aryAgePos3[0] = agePos3;
                aryAgePos4[0] = agePos4;
            }
            
            // DISPLAY CORRECT NUMBER OF ROOMS
            // only if more than 1 room... if this is flight/car or feature only, 
            // we don't want the labels or room dropdowns to display
            if ( numRooms > 1 )
            {
                this.showRooms(numRooms-1);
            }
            
            // SET CORRECT NUMBER IN ROOMS DROPDOWN
            this.initGenericField(numRooms, "rooms", "select");
            
            var numChildrenRoom1, numChildrenRoom2, numChildrenRoom3, numChildrenRoom4;
            var aryAgesRoom1 = new Array();
            var aryAgesRoom2 = new Array();
            var aryAgesRoom3 = new Array();
            var aryAgesRoom4 = new Array();
            
            //loop thru each aryAgePosX, pushing child age into aryAgesRoomX array
            var thisAryAgePos;
            var thisAryChildAgesInRoom;
            
            for(j = 0; j < RoomValues.maxPossibleRooms; j++)
            {
                thisAryAgePos = eval("aryAgePos" + (j+1));
                
                if ( thisAryAgePos.length > 0 )
                {
                    for(k = 0; k < thisAryAgePos.length; k++)
                    {
                        thisAryChildAgesInRoom = eval("aryAgesRoom" + (k+1));
                        if ( thisAryAgePos[k] != "" )
                        {
                            thisAryChildAgesInRoom.push(thisAryAgePos[k]);
                        }
                    }
                }
            }
            
            numChildrenRoom1 = aryAgesRoom1.length;
            numChildrenRoom2 = aryAgesRoom2.length;
            numChildrenRoom3 = aryAgesRoom3.length;
            numChildrenRoom4 = aryAgesRoom4.length;
            
            var thisChildAgeFieldID = "";
            var genNumChildObj = new Object();
            var genChildAgeObj = new Object();
            var thisAgesContainerID = "";
            
            // loop through each aryAgesRoomX array
            for(m = 0; m < RoomValues.maxPossibleRooms; m++)
            {
                // generate div ID for num child dropdown container
                thisNumChildSelectID = "children" + (m + 1).toString();
                // current array of children in room m
                thisAryChildAgesInRoom = eval("aryAgesRoom" + (m+1));
                
                // create object to pass into showChildren containing name of field and number of children
                // IF there are children in that room
                
                if ( thisAryChildAgesInRoom.length > 0 )
                {
                    genNumChildObj.name = thisNumChildSelectID;
                    genNumChildObj.selectedIndex = thisAryChildAgesInRoom.length; //don't forget, child menus have "NA" at idx 0,
                                                                            // so we don't have to subtract 1
                    // call this.showChildren
                    this.showChildren(genNumChildObj);
                    
                    // call this.initGenericField to set value of num children dropdown for this room
                    this.initGenericField(thisAryChildAgesInRoom.length, thisNumChildSelectID, "select");
                }
                
                //loop thru each age in thisAryChildAgesInRoom
                for (n = 0; n < thisAryChildAgesInRoom.length; n++)
                {
                    if ( thisAryChildAgesInRoom[n] != "" ) // if there is an age in this index
                    {
                        // generate name of child age dropdown (child1Age1)
                        thisChildAgeFieldID = "child" + (m+1) + "Age" + (n+1);
                        // generate object to pass to modifyOccupants
                        genChildAgeObj.name = thisChildAgeFieldID;
                        // 1 is the offset between the selectedIndex (0-base) and the age set (starts at 1 yr of age)
                        genChildAgeObj.selectedIndex = parseInt(thisAryChildAgesInRoom[n]) - 1;
                        // populate child age dropdown with correct age
                        this.initGenericField(thisAryChildAgesInRoom[n], thisChildAgeFieldID, "select");
                        // call modifyOccupants to add child ages to rooms array object
                        RoomValues.modifyOccupants(genChildAgeObj);
                    }    
                } 
            }
           
            // DISPLAY CORRECT NUMBER OF ADULTS IN EACH ROOM
            var genNumAdultsObj = new Object();
            var thisAdultDropdownId;
            var thisNumAdults = 0;
            var thisNumChildrenVar;
            
            for(i = 0; i < aryNumTravelers.length; i++)
            {
                thisAdultDropdownId = "adults" + (i+1).toString();
                thisNumChildrenVar = eval("numChildrenRoom" + (i+1));
                thisNumAdults = aryNumTravelers[i] - thisNumChildrenVar;
                
                this.initGenericField(thisNumAdults, thisAdultDropdownId, "select");
                
                genNumAdultsObj.name = thisAdultDropdownId;
                genNumAdultsObj.selectedIndex = thisNumAdults - 1;
                RoomValues.modifyOccupants(genNumAdultsObj);
                
                // reset thisAdultDropdownId
                thisAdultDropdownId = "";
            }
         
        },
    
    // Function Name: padAge
    // Purpose: Places a leading zero on values that are a single digit.  Needed for OVM
    // Parameters: age - value to be padded
    // Return: String - padded value
    
        padAge: function(age)
        {
	        if (age.length < 2 && age != 0)	{
		        age = '0' + age;		
	        }
	        return age;
        }
};