<!--

INTERISLAND_STAY_DAYS = 1;
INBOUND_STAY_DAYS = 7;
OUTBOUND_STAY_DAYS = 7;
MAINLAND_STAY_DAYS = 7;
INTERNATIONAL_STAY_DAYS = 7;
INTERNATIONAL_DESTINATION = "domestic";

    //setup display hotels
    function displayHotels(destinationIdx, resKey) {
        document.TravelRequestForm.submitAction.value= "dsplHtls";
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayHotels.do");
        document.TravelRequestForm.dtIdx.value = destinationIdx;
        document.TravelRequestForm.dtRes.value = resKey;
        document.TravelRequestForm.submit();
    }

    //setup display cars
    function displayCars(destinationIdx, resKey) {
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayCars.do");
        document.TravelRequestForm.submitAction.value= "dsplCars";
        document.TravelRequestForm.dtIdx.value = destinationIdx;
        document.TravelRequestForm.dtRes.value = resKey;
        document.TravelRequestForm.submit();
    }

    //setup display flights
    function displayFlights() {
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayFlights.do");
        document.TravelRequestForm.submitAction.value="dsplFlts";
        document.TravelRequestForm.submit();
    }

    //select room - display flights
    function selectRoomDisplayFlights(destinationIdx, resKey) {
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayFlights.do");
        document.TravelRequestForm.submitAction.value="1";
        document.TravelRequestForm.selectedRoom.value = resKey;
        document.TravelRequestForm.submit();
    }

    //update - selected car
    function updateCar(destinationIdx, resKey) {
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectCar.do");
        document.TravelRequestForm.submitAction.value = "SelectCar";
        document.TravelRequestForm.dtIdx.value = destinationIdx;
        document.TravelRequestForm.dtRes.value = resKey;
        document.TravelRequestForm.submit();
    }


    //select flight
    function selectFlight(idx, resKey) {
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectFlight.do");
        document.TravelRequestForm.dtIdx.value = idx;
        switch (idx) {
            case 0:
                document.TravelRequestForm.selectedFlight0.value = resKey;
                break;
            case 1:
                document.TravelRequestForm.selectedFlight1.value = resKey;
                break;
            case 2:
                document.TravelRequestForm.selectedFlight2.value = resKey;
                break;
            case 3:
                document.TravelRequestForm.selectedFlight3.value = resKey;
                break;
            case 4:
                document.TravelRequestForm.selectedFlight4.value = resKey;
                break;
            case 5:
                document.TravelRequestForm.selectedFlight5.value = resKey;
                break;
            default:
        }

        document.TravelRequestForm.submit();
    }

    //select hotel
    function selectHotel(destinationIdx, resKey)  {
        //when select a hotel in UDSell in Hotel Info page, keep the action
        if (document.TravelRequestForm.action.indexOf("HotelInfo.do") < 0) {
            document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectHotel.do");
        }else {
            document.TravelRequestForm.submitAction.value = 6;  //HotelInfoAction.ACTION_SELECT_UD_HOTEL
        }
        document.TravelRequestForm.dtIdx.value = destinationIdx;
        document.TravelRequestForm.dtRes.value = resKey;
        document.TravelRequestForm.submit();
    }



    //setup process insurance
    function processInsurance() {
        document.forms[0].submitAction.value="processInsurance";
        document.forms[0].submit();
    }

    //forward to the page that show hotel information

    //show hotel info page
    function showHotel(dtIdx, roomId, submitAction) {
        //var strOpen="HotelInfo.do?roomId="+roomId+ "&dtIdx=" + dtIdx;
        //set the navigation id as 1 by default, which is overview
        document.TravelRequestForm.action =
        replaceActionName(document.TravelRequestForm.action, "HotelInfo.do");
        document.TravelRequestForm.dtIdx.value=dtIdx;
        document.TravelRequestForm.dtRes.value=roomId;
        if (document.TravelRequestForm.selectedRoom != null) {
            document.TravelRequestForm.selectedRoom.value = roomId;
        }
        document.TravelRequestForm.submitAction.value= submitAction;
        document.TravelRequestForm.submit();
    }

    //this function is used when user selects a different hotel set (different set of packages) on availability page
    //or select hotel page.
    function moreHotelOptionsSegmentIdx(idx, selectOptionIndex) {
        if (document.TravelRequestForm.action.indexOf("SelectHotel.do") >= 0) {
            document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayHotels.do");
        }
        document.TravelRequestForm.submitAction.value="moreHotelOptions";
        document.TravelRequestForm.dtIdx.value = idx;
        //unlike flights, hotels display one destination
        document.TravelRequestForm.stIdx0.value = selectOptionIndex;
        document.TravelRequestForm.submit();
    }


    //retrieve the terms for display in new window
    function showTerm(url,title,w,h,features) {
        if (window.checkG2HPageTimeOut && checkG2HPageTimeOut()){
            return;
        } else if (window.startG2HPageTimeOut){
            startG2HPageTimeOut();
        }

        var win1 = 0;
        var wint = 0;
        if(screen.width){
            winl = (screen.width-w)/2;
            wint = (screen.height-h)/2;
        }

        if (winl < 0)
            winl = 0;
        if (wint < 0)
            wint = 0;
        var settings = 'height=' + h + ',';
        settings += 'width=' + w + ',';
        settings += 'top=' + wint + ',';
        settings += 'left=' + winl + ',';
        settings += features;
        win = window.open(url,'title',settings);

    }

    //display voucher on Confirmation.jsp
    function displayVoucher(voucherCode, localeCode) {
        if (window.checkG2HPageTimeOut && checkG2HPageTimeOut()){
            return;
        } else if (window.startG2HPageTimeOut){
            startG2HPageTimeOut();
        }
        var w = 600;
        var h = 550;
        if(screen.width){
            var winl = (screen.width-w)/2;
            var wint = (screen.height-h)/2;
        }
        else{
            winl = 0;
            wint =0;
        }
        if (winl < 0) winl = 0;
        if (wint < 0) wint = 0;
        var settings = 'height=' + h + ',';
        settings += 'width=' + w + ',';
        settings += 'top=' + wint + ',';
        settings += 'left=' + winl + ',';
        settings += 'scrollbars=yes,';
        settings += 'resizable=yes';
        var strOpen="ActivityVoucher.jsp?voucherCode=" + voucherCode;
        if (localeCode != "") {
            strOpen += "&lang=" + localeCode;
        }
        hotelWindow = window.open(strOpen,"replace",settings);
    }

    //filter hotels by view/area, used in SelectHotel
    function viewByHotels() {
        document.TravelRequestForm.submitAction.value = "viewByHotels";
        document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayHotels.do");
        document.TravelRequestForm.submit();
    }

    //general javascript
    function replaceActionName(oldName, newName) {
        var name = oldName.substring(0, oldName.lastIndexOf('/') + 1);
        name += newName;
        return name;
    }

    function MM_findObj(n, d) { //v4.0
        var p,i,x;
        if(!d) d=document;
        if((p=n.indexOf("?"))>0&&parent.frames.length) {
            d=parent.frames[n.substring(p+1)].document;
            n=n.substring(0,p);
        }

        if(!(x=d[n])&&d.all) x=d.all[n];
        for (i=0;!x&&i<d.forms.length;i++)
            x=d.forms[i][n];

        for(i=0;!x&&d.layers&&i<d.layers.length;i++)
            x=MM_findObj(n,d.layers[i].document);

        if(!x && document.getElementById)
            x=document.getElementById(n);
        return x;
    }

    function MM_showHideLayers() { //v3.0
        var i,p,v,obj,args=MM_showHideLayers.arguments;

        for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
            obj.visibility=v; }
        }

    function getObj(objID) {
        if (document.getElementById){
            return document.getElementById(objID);
        }
        else if (document.all){
            //old msie versions work
            return document.all[objID];
        }
        else if (document.layers){
            //nn4 woks
            return document.layers[objID];
        }
    }

    function expandCar(show, showArray, hideArray) {
        var i;
        var j;
        if (show) {
            for (i = 0; i < showArray.length; i++){
                for (j=0; j<showArray[i].length; j++) {
                    var o = getObj(showArray[i][j]);
                    if (o!=null)
                        o.style.display = "block";
                }
            }
            for (i = 0; i < hideArray.length; i++){
                for (j=0; j<hideArray[i].length; j++) {
                    var o = getObj(hideArray[i][j]);
                    if (o!=null)
                        o.style.display = "none";
                 }
            }
        }else {
            for (i = 0; i < showArray.length; i++){
                for (j=0; j<showArray[i].length; j++) {
                    var o = getObj(showArray[i][j]);
                    if (o!=null)
                        o.style.display = "none";
                }
            }

            for (i = 0; i < hideArray.length; i++){
                for (j=0; j<hideArray[i].length; j++) {
                    var o = getObj(hideArray[i][j]);
                    if (o!=null)
                        o.style.display = "block";
                }
            }
        }
    } // function expandCar


    function expandHeader(show, showH, hideH) {
        if (show) {
            var o = getObj(showH);
            if (o!=null)
                o.style.display = "block";
            var h = getObj(hideH);
            if (h!=null)
                h.style.display = "none";
        }else {
            var o = getObj(showH);
            if (o!=null)
                o.style.display = "none";
            var h = getObj(hideH);
            if (h!=null)
                h.style.display = "block";
        }
    } // function expandHeader



    function carExpand(switchC, switchE, headerC, headerE,expArray, colArray) {
        MM_showHideLayers(switchC,'','hide');
        MM_showHideLayers(switchE,'','show');
        expandHeader(true, headerE, headerC);
        expandCar(true, expArray, colArray);
    } // function carExpand


    function carCollapse(switchC, switchE, headerC, headerE, expArray, colArray)  {
        MM_showHideLayers(switchC,'','show');
        MM_showHideLayers(switchE,'','hide');
        expandHeader(false, headerE, headerC);
        expandCar(false,expArray, colArray);
    }


    function showDetailHotels() {
        document.TravelRequestForm.submitAction.value="showDetailHotels";
        document.TravelRequestForm.submit();
    }

    //setup to return user appropriately
    function returnBack(returnAvailabilityPage) {
        if (returnAvailabilityPage) {
            document.TravelRequestForm.submitAction.value="showDetailHotels";
        }else {
            document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "ReturnItinerary.do");
        }
        document.TravelRequestForm.submit();
    }


    function MM_displayLayers() { //v3.0
        var i,p,v,obj,args=MM_displayLayers.arguments;
        for (i=0; i<(args.length-2); i+=3)
            if ((obj=MM_findObj(args[i]))!=null) {
            d=args[i+2];
        if (obj.style) {
            obj=obj.style;
        }
            obj.display=d;
        }
    }

    function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v4.0
      var newURL='', verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
      if (app.indexOf('Netscape') != -1) {
        if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
        else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
      } else if (app.indexOf('Microsoft') != -1) {
        if (version >= IEvers || verStr.indexOf(IEvers) != -1)
         {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
        else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
      } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
      if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
    }



    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
        if (init==true) with (navigator) {
            if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
                document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
            }
        }
        else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
            location.reload();
    }
    MM_reloadPage(true);

    function MM_findObj(n, d) { //v4.0
        var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

        if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

        if(!x && document.getElementById) x=document.getElementById(n); return x;

    }



    function MM_openBrWindow(theURL,winName,features) { //v2.0
        window.open(theURL,winName,features);
    }



    function MM_showHideLayers() { //v3.0
        var i,p,v,obj,args=MM_showHideLayers.arguments;

        for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }

            obj.visibility=v; }
            }

            function displayLayers() {

            var i, p, v, obj, args = displayLayers.arguments;

        for(i = 0; i < (args.length - 2); i += 3)
            if ((obj = MM_findObj(args[i])) != null) {
            v = args[i+2];

            if(obj.style) {
                obj = obj.style;
                v = (v == 'show') ? 'block' : (v = 'hide') ? 'none' : v;
            }

            obj.display=v;
        }
    }


    function newWindow(url,title,w,h,features) {
        if(screen.width){
            var winl = (screen.width-w)/2;
            var wint = (screen.height-h)/2;
        }
        else {
            winl = 0;
            wint =0;
        }

        if (winl < 0)
            winl = 0;
        if (wint < 0)
            wint = 0;
        var settings = 'height=' + h + ',';
        settings += 'width=' + w + ',';
        settings += 'top=' + wint + ',';
        settings += 'left=' + winl + ',';
        settings += features;
        win = window.open(url,'title',settings);
    }

    function changeto(highlightcolor){
        source=event.srcElement
        if (source.tagName=="TR"||source.tagName=="TABLE")
            return
        while(source.tagName!="TABLE")
            source=source.parentElement
        if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
            source.style.backgroundColor=highlightcolor
    }

    function changeback(originalcolor){
        if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
            return
        if (event.toElement!=source)
            source.style.backgroundColor=originalcolor

    }


    //Return true if air is included, false otherwise
    function includesAir() {
        var value = "";
        for (var i = 0; i < document.TravelRequestForm.typeOfPackage.length; i++) {
            if (document.TravelRequestForm.typeOfPackage[i].checked == "1") {
                value = document.TravelRequestForm.typeOfPackage[i].value;
            }
        }
        if(value == "HOTEL-ONLY" || value == "CAR-HOTEL" || value == "CAR-ONLY" || value == "") {
            return false;
        }
        return true;
    }

    //Return true if a hotel is included, false otherwise
    function includesHotel() {
        var value = "";
        for (var i = 0; i < document.TravelRequestForm.typeOfPackage.length; i++) {
            if (document.TravelRequestForm.typeOfPackage[i].checked == "1") {
                value = document.TravelRequestForm.typeOfPackage[i].value;
            }
        }

        if(value == "AIR-ONLY" || value == "AIR-CAR" || value == "CAR-ONLY" || value == "") {
            return false;
        }
        return true;
    }

    //Remove all but numbers
    function cleanNumber(strNum) {
        var temp = strNum.replace(/[^\d]/g,'');
        return temp;
    }

    //Determine is str is numeric
    function isNumeric(strString) {
        var strValidChars = "0123456789.-";
        var strChar;
        if (strString.length == 0)
            return false;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }

    function checkDecimal(num) {
        var index = num.indexOf(".") - 0;
        if(index != -1) {
            var temp = num.substring(index + 1);
            if(temp.length > 2) {
                return false;
            }
        }
        return true;
    }

    //Return true if src is in the right email address format
    function validateEmailAddressFormat(src) {
        var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
        return regex.test(src);
    }

    // This function is called when the submit image or link is clicked. The validations done here should
    // really be done in supporting Java code, but in the interest of time we added them here.
    function submitForm() {
        //The following fields are not always available in all departure pages
        if (document.TravelRequestForm.submitAction) document.TravelRequestForm.submitAction.value="";
        if (document.TravelRequestForm.currentDestination) document.TravelRequestForm.currentDestination.value=0;
        if (document.TravelRequestForm.currentComponent) document.TravelRequestForm.currentComponent.value="";
            validateAndSubmit();
    }


    //Return true is package is car only, false otherwise
    function isCarOnlyPackage() {
        var value = "";
        for (var i = 0; i < document.TravelRequestForm.typeOfPackage.length; i++) {
            if (document.TravelRequestForm.typeOfPackage[i].checked == "1") {
                value = document.TravelRequestForm.typeOfPackage[i].value;
            }
        }

        if(value == "CAR-ONLY" ) {
            return true;
        }
        return false;
    }


    //Determine if airport note should be displayed
    //Return true if airport is (JHM island airport), false otherwise
    function showAirportNote() {
        var toDisplay = false;
        if((document.TravelRequestForm.from0.type == "select-one") && (document.TravelRequestForm.to0.type == "select-one")) {
            if (document.TravelRequestForm.from0.options[document.TravelRequestForm.from0.selectedIndex].value == "JHM"
                || document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "JHM") {
                toDisplay = true;
            }
        }else if((document.TravelRequestForm.from0.type == "text") && (document.TravelRequestForm.to0.type == "select-one")) {
            if(document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "JHM") {
                toDisplay = true;
            }
        }else if((document.TravelRequestForm.from0.type == "select-one") && (document.TravelRequestForm.to0.type == "text")) {
            if (document.TravelRequestForm.from0.options[document.TravelRequestForm.from0.selectedIndex].value == "JHM") {
                toDisplay = true;
            }
        }
        if(toDisplay) {
            displayLayers('airportNote','','show');
        }else {
            displayLayers('airportNote','','hide');
        }
    }

    //Determine if airport note should be displayed
    //Return true if airport is (JHM), false otherwise
    function showAirportNoteMulti(lastDestination) {
    var toDisplay = false;
    var fromValue, toValue;

    for (var i = 0; i < (lastDestination + 1); i++) {
        toValue = getValueOfSelectObject("to" + i);
        fromValue = getValueOfSelectObject("from"+i);
            if (toValue=="JHM" ||fromValue=="JHM") {
                toDisplay = true;
                break;
            }
        }
        if(toDisplay) {
            displayLayers('airportNote','','show');
        }else {
            displayLayers('airportNote','','hide');
        }
    return toDisplay;
    }

    //Determine if international airport note should be displayed
    //Return true if airport is (PPT, SYD, MNL), false otherwise
    function showInternationalAirportNote() {
        var toDisplayPPT = false;
        var toDisplaySYD = false;
        var toDisplayMNL = false;
        var toDisplayPPG = false;

        //International is always drop-down
        if ( document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "PPT") {
            toDisplayPPT = true;
        }else if ( document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "SYD") {
            toDisplaySYD = true;
        }else if ( document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "MNL") {
            toDisplayMNL = true;
        }else if ( document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "PPG") {
            toDisplayPPG = true;
        }

        if(toDisplayPPT) {
            displayLayers('airportNotePPT','','show');
        } else {
            displayLayers('airportNotePPT','','hide');
        }
        if(toDisplaySYD) {
            displayLayers('airportNoteSYD','','show');
        } else {
            displayLayers('airportNoteSYD','','hide');
        }
        if(toDisplayPPG) {
            displayLayers('airportNotePPG','','show');
        } else {
            displayLayers('airportNotePPG','','hide');
        }
    }

    //Hide or display child age selection.
    //Excuted when numberOfChildren is changed
    function changeNumberOfChildren(){
        var countChildren = document.TravelRequestForm.numberOfChildren.value;
        var age;
        var hasInfant = false;
        for (var i=0; i< 6; i++){
            if (i < countChildren){
                displayLayers('divchild' + i,'','show');
                age = getValueOfSelectObject("childAge" + i);
                if (age != "" && age == "0" && includesAir() ){
                    displayLayers('divinfant' + i,'','show');
                    hasInfant = true;
                } else {
                    displayLayers('divinfant' + i,'','hide');
                }
            }
            else{
                displayLayers('divchild' + i,'','hide');
                displayLayers('divinfant' + i,'','hide');
            }
        }

        if (countChildren > 0 && hasInfant == true ) {
            displayLayers('infantInLapMsg','','show');
        }else {
            displayLayers('infantInLapMsg','','hide');
        }
    }

    //Hide or display infant seat selection.
    //Excuted when childAge is changed
    function changeChildAge(){
        //infant selection does not apply to non-air
        var countChildren = document.TravelRequestForm.numberOfChildren.value;
        var age;
        var displayInfantMsg = false;
        for (var i=0; i< countChildren; i++){
            age = getValueOfSelectObject("childAge" + i);
            if (age != "" && age == "0" && includesAir() ) {
                displayLayers('divinfant' + i,'','show');
                displayInfantMsg = true;
            }else {
                displayLayers('divinfant' + i,'','hide');
            }
        }

        if (displayInfantMsg == true) {
            displayLayers('infantInLapMsg','','show');
        }else {
            displayLayers('infantInLapMsg','','hide');
        }
    }


    function getValueOfSelectObject(objectName){
        for (var i=0; i<document.TravelRequestForm.elements.length; i++){
            if ( (document.TravelRequestForm.elements[i].name == objectName)
                && (document.TravelRequestForm.elements[i].type == "select-one"))  {

                return document.TravelRequestForm.elements[i].value;
            }
        }
        //not found
        return "";
    }

    function getValueOfRadioObject(objectName){
        for (var i=0; i<document.TravelRequestForm.elements.length; i++){
            if ( (document.TravelRequestForm.elements[i].name == objectName)
                && (document.TravelRequestForm.elements[i].type == "radio")
                && (document.TravelRequestForm.elements[i].checked) )  {
                return document.TravelRequestForm.elements[i].value;
            }
        }
        //not found
        return "";
    }


	//clean phone fields
	//remove any blank strings from fields before validation
	function cleanBlankStrPhoneFields() {
		var phoneFields = new Array('phoneCountry', 'phoneAreaCode', 'phoneNumber',
									 'businessPhoneCountry', 'businessPhoneAreaCode', 'businessPhoneNumber',
									 'faxCountry', 'faxAreaCode', 'faxNumber');
		var fieldObj;
		for (j in phoneFields) {
			fieldObj = eval('document.OrderForm.' + phoneFields[j]);
			cleanBlankStr(fieldObj);
		}
	}

	//
	function cleanBlankStr(field) {
		if ((field != null) && (field != undefined)){
			field.value = trim(field.value);
		}
	}

    function isValidPhoneNumber(strString) {
        var strValidChars = " 0123456789-";
        var strChar;
        if (strString.length == 0)
            return false;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }

    //valid area code -- 3 digits
    function isValidAreaCode(strString) {
        //strString = cleanNumber(strString); //clean number first
        var strValidChars = "0123456789";
        var strChar;
        if (strString.length != 3)
            return false;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }

    //valid phone segment -- digits only, clean
    //international
    function isValidAreaPhoneSegIntl(strString) {
        //strString = cleanNumber(strString); //clean number first
        var strValidChars = "0123456789";
        var strChar;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }

    //valid phone number -- digits only, length > 4
    //international
    function isValidPhoneNumberIntl(strString) {
        var strValidChars = "0123456789-";
        var strChar;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        //clean number and count
        strString = cleanNumber(strString);
        if (strString.length < 5)
            return false;

        return true;
    }


    //valid phone number -- 7 digits
    function isValidPhoneNumber2(strString) {
        strString = cleanNumber(strString); //clean number first
        var strValidChars = "0123456789";
        var strChar;
        if (strString.length != 7)
            return false;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }


    //Determine if travel type is one way
    function isOneWay() {
        var value = 2;
        if(document.TravelRequestForm.travelType) {
            for(var i = 0; i < document.TravelRequestForm.travelType.length; i++) {
                if(document.TravelRequestForm.travelType[i].checked == "1") {
                    value = document.TravelRequestForm.travelType[i].value;
                }
            }
        }
        if(value == 1) {
            return true;
        }
        return false;
    }

    //Determine if search is multi city
    function isMultiCity() {
        var value;
        //some departure page, e.g., non air have no travelType
        if (document.TravelRequestForm.travelType){
            for(var i = 0; i < document.TravelRequestForm.travelType.length; i++) {
                if(document.TravelRequestForm.travelType[i].checked == "1") {
                    value = document.TravelRequestForm.travelType[i].value;
                }
            }

            if (value == 3){
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    //Determine if package includes car
    function includesCar() {
        var value = "";
        for(var i = 0; i < document.TravelRequestForm.typeOfPackage.length; i++) {
            if (document.TravelRequestForm.typeOfPackage[i].checked == "1") {
                value = document.TravelRequestForm.typeOfPackage[i].value;
            }
        }
        if(value == "AIR-ONLY" || value == "AIR-HOTEL" || value == "HOTEL-ONLY" || value == "") {
            return false;
        }
        return true;
    }

    function getValueOfTextObject(objectName){
        return getValueOfTextObjectFromForm(document.TravelRequestForm, objectName);
    }


    function getValueOfTextObjectFromForm(thisForm, objectName){
        for (var i=0; i<thisForm.elements.length; i++){
           if ( (thisForm.elements[i].name == objectName)
                    && (thisForm.elements[i].type == "text"))  {
                return thisForm.elements[i].value;
            }
        }
        //not found
        return "";
    }


    function trim(str) {
        return str.replace(/^\s*|\s*$/g,"");
    }


    function showMoreOptions() {
        displayLayers('moreOptions','','show');

        //the code below is used to track if the user has clicked showMoreOptions. If it has been clicked, keep the
        //layer open
        if (document.TravelRequestForm.showMoreOptions != null ) {
            document.TravelRequestForm.showMoreOptions.value = "show";
        }
    }

    /*******************
     ** view and search enhancement
     ********************/

    //validate the departure date
    function validateDepartureDate() {
        if(checkdate(document.TravelRequestForm.itineraryStartDate)) {
            DepartChecker(document.TravelRequestForm.itineraryStartDate, document.TravelRequestForm.itineraryEndDate, '<%=indexObj.getNumberOfNights()%>');
        }
    }

    //validate the return date
    function validateReturnDate() {
        if(checkdate(document.TravelRequestForm.itineraryEndDate)) {
            ReturnChecker(document.TravelRequestForm.itineraryStartDate,document.TravelRequestForm.itineraryEndDate);
        }
    }

    /**
     * This function only applied to hawaiian island. Since there is no map in javascipt, use
     * comparing island one by one though it is inefficient.
     *          <option value="HNL">Honolulu, Oahu (HNL)</option>
     *         <option value="LIH">Lihue, Kauai (LIH)</option>
     *        <option value="OGG">Kahului, Maui (OGG)</option>
     *        <option value="KOA">Kona, Hawaii (KOA)</option>
     *        <option value="ITO">Hilo, Hawaii (ITO)</option>
     *        <option value="LNY">Lanai City, Lanai (LNY)</option>
     *        <option value="MKK">Hoolehua, Molokai (MKK)</option>
     */
    function getHawaiianIslandByAirportCode(code) {
        if (code == "HNL") {
            return "Oahu";
        }else if (code == "LIH") {
            return "Kauai";
        }else if (code == "OGG") {
            return "Maui";
        }else if (code == "KOA") {
            return "Hawaii/Big Island";
        }else if (code == "ITO") {
            return "Hawaii/Big Island";
        }else if (code == "LNY") {
            return "Lanai";
        }else if (code == "MKK") {
            return "Molokai";
        }else {
            //alert ( "Airport code " + code + " is not Supported");
            alert("Please specify an Island/Airport.");
            return ("Not Supported");
        }
    }


    /*
    MultiCityPackage Departure page
    */
    function clickNeedComponent(cbComponent, selectDateDivName, component){
        if (cbComponent.checked){
            displayLayers(selectDateDivName, '', 'show');
        } else {
            displayLayers(selectDateDivName, '', 'hide');
        }
        if ("hotel" == component){
            displayHotelLayers();
        } else if ("car"== component){
            displayCarLayers();
        }
    }

    /*
    Hide destinations starting from startDestination
    */
    function hideDestinations(startDestination) {
        for (i=startDestination; i<3; i++){
            displayLayers('destination' + i, '', 'hide');
        }
    }

    /*
    Deselect nextOption radio button. It is called when users click on Cancel
    */
    function deselectAllNextOption(destinationNo){
        for (var i=0; i<document.TravelRequestForm.elements.length; i++){
            if ( (document.TravelRequestForm.elements[i].name == ('nextOption' +destinationNo) )
                && (document.TravelRequestForm.elements[i].type == "radio") )  {
                document.TravelRequestForm.elements[i].checked = false;
            }
        }
    }

    /*
    Depending on which radio button, hide or show the correct layer
    Valid values are pkg, flight and end
    When users choose to end, display confirmation page before going to
    CustomCarDates or CustomHotelDates
    */
    function clickNextOption(rbValue, destinationNo, hasCustomDates){
        if (rbValue == "pkg"){
            displayLayers('destination' + (destinationNo + 1), '', 'show');
            hideDestinations(destinationNo + 2);
            displayLayers('returnFlight', '', 'hide');
            document.TravelRequestForm.multiCityPkgLastIdx.value=destinationNo + 1;
        } else if (rbValue == "flight"){
            hideDestinations(destinationNo + 1);
            displayLayers('returnFlight', '', 'show');
            document.TravelRequestForm.multiCityPkgLastIdx.value=destinationNo;
        } else if (rbValue == "end"){
            hideDestinations(destinationNo + 1);
            displayLayers('returnFlight', '', 'hide');
            document.TravelRequestForm.multiCityPkgLastIdx.value=destinationNo;
            if (isCheckBoxSelected("needHotel" + destinationNo) || isCheckBoxSelected("needCar" + destinationNo) ){
                var cmpMsg;
                var currentComponent;
                var dtMsg;
                if (isCheckBoxSelected("needHotel" + destinationNo)){
                    cmpMsg="hotel";
                    dtMsg="check-out";
                    currentComponent="hotel";
                    if (isCheckBoxSelected("needCar" + destinationNo)){
                        currentComponent="hotelcar"; //it used to set both
                    }
                } else {
                    cmpMsg="car";
                    dtMsg="drop-off";
                    currentComponent="car";
                }
                if (! hasCustomDates){
                    if (confirm("To end your trip in " + getValueOfSelectObject('to' + destinationNo)
                        + ", please provide your "+ cmpMsg +" "+ dtMsg +" date at this destination." + '\n'
                        + "Click OK to specify the "+ dtMsg + " date at this destination or Cancel to reset your next action for this destination.")){

                        document.TravelRequestForm.submitAction.value="EndTripDates";
                        document.TravelRequestForm.currentDestination.value=destinationNo;
                        document.TravelRequestForm.currentComponent.value=currentComponent;

                        if (validateAndSubmit() == false){
                            deselectAllNextOption(destinationNo);
                        }
                    } else {
                        deselectAllNextOption(destinationNo);
                    }
                }
            }
        }
    }

    /*
    To find out if a check box is selected
    */
    function isCheckBoxSelected(objectName){
        for (var i=0; i<document.TravelRequestForm.elements.length; i++){
            if ( (document.TravelRequestForm.elements[i].name == objectName)
                && (document.TravelRequestForm.elements[i].type == "checkbox") )  {

                return document.TravelRequestForm.elements[i].checked;
            }
        }
        //not found
        return false;
    }

    /*
    Hotel layers are displayed if any destination need hotel
    */
    function displayHotelLayers(){
        displayLayers("hotelRatingLayer", "", "hide");
        displayLayers("hotelRatingLayer1", "", "hide");
        displayLayers("numberOfRoomLayer", "", "hide");
        var lastDestination = document.TravelRequestForm.multiCityPkgLastIdx.value;
        var hasHotel = false;
        for (var i=0; i <lastDestination + 1; i++){
            if (isCheckBoxSelected("needHotel" + i)){
                displayLayers("hotelRatingLayer", "", "show");
                displayLayers("hotelRatingLayer1", "", "show");
                displayLayers("numberOfRoomLayer", "", "show");
                hasHotel = true;
                return;
            }
        }
        if (!hasHotel && document.TravelRequestForm.numberOfRooms) {
            document.TravelRequestForm.numberOfRooms.value = '1';
        }
    }

    /*
    Car layers are displayed if any destination need car
    */
    function displayCarLayers(){
        displayLayers("carCompanyLayer", "", "hide");
        displayLayers("carTypeLayer", "", "hide");
        var lastDestination = document.TravelRequestForm.multiCityPkgLastIdx.value;
        for (var i=0; i <lastDestination + 1; i++){
            if (isCheckBoxSelected("needCar" + i)){
                displayLayers("carCompanyLayer", "", "show");
                displayLayers("carTypeLayer", "", "show");
                return;
            }
        }
    }


    function isNumber(strString) {
        var strValidChars = "0123456789";
        var strChar;
        if (strString.length == 0)
            return true;
        for (i = 0; i < strString.length; i++) {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1) {
                return false;
            }
        }
        return true;
    }

    /*
     It is called when users click on Select Different Car/Hotel Dates
     */
    function selectDifferentDates(destination, component){
        document.TravelRequestForm.submitAction.value="SelectDifferentDates";
        document.TravelRequestForm.currentDestination.value=destination;
        document.TravelRequestForm.currentComponent.value=component;
        validateAndSubmit();
    }

    /*
    It is called from CustomHotelDates and CarDates to validate date inputs
    */
    function validateDateRange(dateInput, startDateRangeValue, endDateRangeValue, errorMsg, isStartDate) {
        if(checkdate(dateInput)) {
            dateDt = new Date(getDateStr(dateInput.value));
            if (isStartDate){
                if (startDateRangeValue != null && startDateRangeValue != ""){
                    startDateDt= new Date(getDateStr(startDateRangeValue));
                    if (dateDt < startDateDt && endDateRangeValue != null && endDateRangeValue != ""){
                        alert(errorMsg);
                        return false;
                    } else if(dateDt < startDateDt){
                        alert(errorMsg );
                        return false;
                    }
                }
            }else {
                if (endDateRangeValue != null && endDateRangeValue != ""){
                    endDateDt= new Date(getDateStr(endDateRangeValue));
                    if(dateDt > endDateDt && startDateRangeValue != null && startDateRangeValue != ""){
                        alert(errorMsg);
                        return false;
                    } else if(dateDt > endDateDt){
                        alert(errorMsg);
                        return false;
                    }
                }
            }
        }
        return true;
    }

    /*
    Called when radio button or link is clicked
    CustomEndDate, customStartTime and customEndTime are not always available
    */
    function changeHasCustomDate(rbFormName, newValue, startDateValue, endDateValue) {
        document.TravelRequestForm.customStartDate.value=startDateValue;
        if (document.TravelRequestForm.customEndDate){
            document.TravelRequestForm.customEndDate.value=endDateValue;
        }

        if (document.TravelRequestForm.customStartTime){
            document.TravelRequestForm.customStartTime.value="3:00 PM";
        }

        if (document.TravelRequestForm.customEndTime){
            document.TravelRequestForm.customEndTime.value="3:00 PM";
        }

        //make radiobutton selected
        for (var i=0; i<document.TravelRequestForm.elements.length; i++){
            if ( (document.TravelRequestForm.elements[i].name == rbFormName)
                && (document.TravelRequestForm.elements[i].type == "radio")
                && (document.TravelRequestForm.elements[i].value == newValue) )  {

                document.TravelRequestForm.elements[i].checked = true;
            }
        }
    }

    //Determine if package is air only
    function isAirOnlyPackage() {
        var value = "";
        for (var i = 0; i < document.TravelRequestForm.typeOfPackage.length; i++) {
            if (document.TravelRequestForm.typeOfPackage[i].checked == "1") {
                value = document.TravelRequestForm.typeOfPackage[i].value;}
            }
            if(value == "AIR-ONLY" ) {
            return true;
        }
        return false;
    }

    //Initialize hotel/car links for multicity package
    function initMultiCityPackageDepartureCommon(lastDestinationIdx) {
        for (var i=0; i<= lastDestinationIdx; i++){
            displayLayers('destination' + i, '', 'show');
            if (isCheckBoxSelected("needHotel" + i)){
                displayLayers('hotelDatesLinkShow' + i, '', 'show');
            } else {
                displayLayers('hotelDatesLinkShow' + i, '', 'hide');
            }
            if (isCheckBoxSelected("needCar" + i)){
                displayLayers('carDatesLinkShow' + i, '', 'show');
            } else {
                displayLayers('carDatesLinkShow' + i, '', 'hide');
            }
        }
        hideDestinations(lastDestinationIdx + 1);
        if ("flight" == getValueOfRadioObject("nextOption" + lastDestinationIdx)){
            displayLayers('returnFlight', '', 'show');
        }
        displayHotelLayers();
        displayCarLayers();
    }


    //Set the multicity return flight default date
    function setMulticityReturnFlightDefaultDate(){
        if (document.TravelRequestForm.returnFlightDefaultDate && document.TravelRequestForm.multiCityPkgLastIdx){
            last = document.TravelRequestForm.multiCityPkgLastIdx.value;
            document.TravelRequestForm.returnFlightDefaultDate.value = getValueOfTextObject("itineraryStartDate" + last);
        }
    }

    //Shows the seating class note
    function showClassNote() {
        if (document.TravelRequestForm.flightClass.selectedIndex == 1) {
            displayLayers('seatingclass','','show');
        }else {
            displayLayers('seatingclass','','hide');
        }
    }
//-->

