/*
    The following methods relate to a browser's back button and the redisplay of
    previous forms - mainly the reselection of radiobuttons upon back button click.

*/
    //MAIN
    //USE THIS METHOD IN FUTURE
    //generic radiobutton checker method
    //validates the url parameters against the currently selected radio button
    //to determine if they match or not;
    //the correct page view is requested from the server upon mismatch.
    //@lastSelected            holds the values for the last radio button selection
    function checkAllRadioButtons(lastSelected, packageRB,
                                  destinationRB, travelRB) {
        //See : Forwards.AIR_CAR_HOTEL = AirCarHotel
        //See : Ojbects.HOMEPAGE_SEARCH = homePageSearch
        //temporary disable
        return;
        if (lastSelected == "AirCarHotel") { //from agent
            window.location.href="ChangePackageType.do?packageType=AIR-CAR-HOTEL";
            return;
        }
        else if (lastSelected == "homePageSearch") { //from homepage search
            window.location.href="ChangeTravelType.do?typeOfTravel=3";
            return;
        }
        else if (lastSelected == "") { 
            return;
        }
        //see TraveRequestForm.saveLastRadioButtonSelection() for string format
        var selArr = lastSelected.split("|");
        var packageSel = selArr[0];
        var destinationSel = selArr[1];
        var travelSel = selArr[2];
        var isPackageRB = checkRadioButtons(packageRB, packageSel);
        var isDestinationRB = checkRadioButtons(destinationRB, destinationSel);
        var isTravelRB = checkRadioButtons(travelRB, travelSel);
        if (isPackageRB && isDestinationRB && isTravelRB) {
            return;
        }
        //if (radiobuttongroup != null) and value doesn't match, refresh
        if ((packageRB != null) && !isPackageRB) {
            window.location.href="ChangePackageType.do?packageType=" + packageSel;
        }
        if ((destinationRB != null) && !isDestinationRB) {
            window.location.href="ChangeDestination.do?destination=" + destinationSel;
        }
        if ((travelRB != null) && !isTravelRB) {
            window.location.href="ChangeTravelType.do?typeOfTravel=" + travelSel;
        }
    }

    //generic radiobutton vs param check
    function checkRadioButtons(radioButtonGroup, paramVal) {
        if (radioButtonGroup == null) {
            return false;
        }
        for (counter = 0; counter < radioButtonGroup.length; counter++) {
            ///determine if the selected radio button w/in the group
            //matches the given parameter, else reretrieve current url
            if ((radioButtonGroup[counter].checked) &&
                (radioButtonGroup[counter].value == paramVal)) {
                return true;
            }
        }
        return false;
    }

    //Retrieves a given parameter from a given query string
    //@param    queryString - current window url
    //@param    parameterName - name of the parameter to retrieve
    //@return   String, parameter value or "null" if none
    function getParameter ( queryString, paramName ) {
        // Add "=" to the parameter name (i.e. parameterName=value)
        var parameterName = paramName + "=";
        if ( queryString.length > 0 ) {
            // Find the beginning of the string
            begin = queryString.indexOf ( parameterName );
            // If the parameter name is not found, skip it, otherwise return the value
            if ( begin != -1 ) {
                // Add the length (integer) to the beginning
                begin += parameterName.length;
                // Multiple parameters are separated by the "&" sign
                end = queryString.indexOf ( "&" , begin );
                if ( end == -1 ) {
                    end = queryString.length
                }
                // Return the string
                return unescape ( queryString.substring ( begin, end ) );
            }
        }
        // Return "null" if no parameter has been found
        return "null";
    }