
/***************************************************************************
 * Filename: commonCustomerInfo.js                                         *
 *	Purpose: Javascript file containing all methods used for the enhanced  *
 *  store locator popup                                                    *
 *                                                                         *
 ***************************************************************************/

var gStrLabel_SchoolCampus       = "school/campus/base";
var gStrLabel_Building           = "building";
var gStrLabel_Base               = "base";
var gStrLabel_SelectA            = "- select a ";
var gStrLabel_RetrievingStates   = "- estados -";
var gStrLabel_SelectAState       = "- elige un estado -";
var gStrLabel_Campus             = "campus/base";
var gStrLabel_Campuses           = "schools/campuses/bases";
var gStrLabel_BaseNames          = "base names";
var gStrLabel_Retrieving         = "- ";
var gStrLabel_DormBuildings      = "dorms/buildings";
var gStrLabel_Bases              = "bases";
var gStrLabel_Buildings          = "edificios";
var gStrLabel_No                 = "- no ";
var gStrLabel_Found              = " encontrado -";
var gStrError_Selected           = " selected";
var gStrError_NoInfoState        = "Lo sentimos, pero no hay informaci\363n disponible para el estado seleccionado";
var gStrError_NoInfo             = "Lo sentimos, pero no hay informaci\363n disponible para ";
var gStrError_NoInfoAddresType   = "Lo sentimos, pero no hay informaci\363n disponible para el tipo de direcci\363n seleccionada.";
var gStrError_TempUnavailable    = "Lo sentimos, pero este servicio no est\341 disponible por el momento. Vuelve a intentarlo m\341s tarde.";

<!-- mp_trans_disable_start -->

var gObjStateRequest = null; 
var gObjUnitRequest = null; 
var gObjBldgRequest = null; 

/***************************************************************************
 * toggleDiv()                                                             *
 *                                                                         *
 * input: strDivId - id of the div tag to be toggled                       *
 *        blnValue - whether to toggle on or off - defaults to true (on)   *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: toggle display value of html element                       *
 *                                                                         *
 ***************************************************************************/
function toggleDiv(strDivId, blnValue, strFormNum) {
    var strStyle;
    var objDiv;
    var objAddressType;
    
    if (blnValue == null || typeof(blnValue) == undefined) {
        blnValue = true;
    }

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    objAddressType = document.getElementById('addresstype' + strFormNum);
    
    strStyle = (blnValue) ? "inline" : "none";
    objDiv = document.getElementById(strDivId + strFormNum);

    if (objAddressType != null) {

        if (strDivId == "campus_tab") {
            objAddressType.value = "Campus";
        } else if (strDivId == "military_tab") {
            objAddressType.value = "MilitaryBase";
        } else {
            objAddressType.value = "";
        }
    }

    if (objDiv) {
        objDiv.style.display = strStyle;
    }


    //Clear objects
    objectDiv = null;
    objAddressType = null;
    
    return;
} //toggleDiv()


/***************************************************************************
 * showStandardAddressForm()                                               *
 *                                                                         *
 * input: strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: shows the standard address form                            *
 *                                                                         *
 ***************************************************************************/
function showStandardAddressForm(strFormNum) {
    
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    toggleDiv('campus_tab', false, strFormNum);
    clearEnhancedAddressFields('Campus', strFormNum);
    toggleDiv('std_addr_tab', true, strFormNum);
    focusPopup(strFormNum);

} //showStandardAddressForm()

/***************************************************************************
 * showCampusAddressForm()                                                 *
 *                                                                         *
 * input: strServerURL - the server URL                                    *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: shows the campus address form                              *
 *                                                                         *
 ***************************************************************************/
function showCampusAddressForm(strServerURL, strFormNum) {
    
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    toggleDiv('std_addr_tab', false, strFormNum);
    clearStandardAddressFields(strFormNum);
    toggleDiv('campus_tab', true, strFormNum);
    getStates(strServerURL, 'Campus', null, null, true, strFormNum);

} //showCampusAddressForm()


/***************************************************************************
 * prepopulateDropdowns()                                                  *
 *                                                                         *
 * input: gStrServerURL - the url of the enhanced store locator            *
 *        strAddressType - the addressType, either C or M                  *
 *        strStateValue - the state value                                  *
 *        strStateCode - the state code                                    *
 *        strUnitValue - the unit value                                    *
 *        strUnitCode - the unit code                                      *
 *        strBuildingValue - the building value                            *
 *        strBuildingCode - the building code                              *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 * 												                           *
 * description: Populates the enhanced dropdowns with the code/value pairs *
 *                                                                         *
 ***************************************************************************/
function prepopulateDropdowns(strServerURL, strAddressType, strStateValue, strStateCode, strUnitValue, strUnitCode,
                              strBuildingValue, strBuildingCode, strFormNum) {
    var objUnitSelBox;
    var objBuildingSelBox;
    var objStateSelBox;
    var strUnitLabel;
    var strBuildingLabel;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
            
    if (strAddressType == "Campus") {
        objStateSelBox = document.getElementById('cp_state' + strFormNum);
        objUnitSelBox = document.getElementById('cp_campus' + strFormNum);
        objBuildingSelBox = document.getElementById('cp_bldg' + strFormNum);
        strUnitLabel = gStrLabel_SchoolCampus;
        strBuildingLabel = gStrLabel_Building;
    } else {
        objStateSelBox = document.getElementById('ml_state' + strFormNum);
        objUnitSelBox = document.getElementById('ml_base' + strFormNum);
        objBuildingSelBox = document.getElementById('ml_bldg' + strFormNum);
        strUnitLabel = gStrLabel_Base;
        strBuildingLabel = gStrLabel_Building;
    }

    if (objStateSelBox != null) {
        objStateSelBox.options.length = 0;

        if (strStateValue != "" && strStateCode != "") {
            objStateSelBox.options[0] = new Option(strStateValue, strStateCode, true, true);
            setHiddenAddressField(objStateSelBox, strFormNum);
        } else {
            getStates(strServerURL, strAddressType);
        }
    }

    if (objUnitSelBox != null) {
        objUnitSelBox.options.length = 0;

        if (strUnitValue != "" && strUnitCode != "") {
            objUnitSelBox.options[0] = new Option(strUnitValue, strUnitCode, true, true);
        } else {
            objUnitSelBox.options[0] = new Option(gStrLabel_SelectA + strUnitLabel + " -", "", true, true);
        }
        setHiddenAddressField(objUnitSelBox, strFormNum);
    }
    if (objBuildingSelBox != null) {
        objBuildingSelBox.options.length = 0;

        if (strBuildingValue != "" && strBuildingCode != "") {
            objBuildingSelBox.options[0] = new Option(strBuildingValue, strBuildingCode, true, true);
        } else {
            objBuildingSelBox.options[0] = new Option(gStrLabel_SelectA + strBuildingLabel + " -", "", true, true);
        }
        setHiddenAddressField(objBuildingSelBox, strFormNum);
    }

    //Clear objects
    objUnitSelBox = null;
    objBuildingSelBox = null;
    objStateSelBox = null;

    return;
} //prepopulateDropdowns()

/***************************************************************************
 * loadDropdown()                                                          *
 *                                                                         *
 * input: objDropdown - the dropdown object to load                        *
 *        strServerURL - the url of the enhanced store locator             * 
 *        fncLoad - the function to load the dropdown                      *
 *        strAddressType - the addressType, either Campus or MilitaryBase  *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: if the dropdown isn't populated, populate it               *
 *                                                                         *
 ***************************************************************************/
function loadDropdown(objDropdown, strServerURL, fncLoad, strAddressType, strFormNum) {
    var strValue = objDropdown.value;

    if (objDropdown.options.length <= 1 && strValue != "") {
        fncLoad(strServerURL, strAddressType, null, strValue, true, strFormNum);

    }
    
    //objDropdown.click();

    return;
} //loadDropdown()


/***************************************************************************
 * onKeyDown()                                                             *
 *                                                                         *
 * input: strRequestType - state, unit or building                         *
 *        objDropdown - the dropdown object to process                     *
 *        objEvent - the event                                             *
 *        strServerURL - the url of the enhanced store locator             *
 *        fncLoad - the function to pass to load the dropdown              *
 *        strAddressType - the address type, 'Campus' or 'Military'        * 
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Handles all keystroke events                               *
 *                                                                         *
 ***************************************************************************/
function onKeyDown(strRequestType, objDropdown, objEvent, strServerURL, fncLoad, strAddressType, strFormNum)
{  
	var strValue;
    
    intKeyCode = objEvent.keyCode;

    if ((intKeyCode >= 48 && intKeyCode <= 90) || (intKeyCode == 38) || intKeyCode == 40) {
        loadDropdown(objDropdown, strServerURL, fncLoad, strAddressType, strFormNum);

        if (strRequestType == "state") {
            if (gObjStateRequest != null) {
                gObjStateRequest.intKeyCode = intKeyCode;
            }
        } else if (strRequestType == "unit") {
            if (gObjUnitRequest != null) {
                gObjUnitRequest.intKeyCode = intKeyCode;
            }
        } else if (strRequestType == "building") {
            if (gObjBldgRequest != null) {
                gObjBldgRequest.intKeyCode = intKeyCode;
            }
        }

    }

	return true;
} //onKeyDown()


/***************************************************************************
 * clearStandardAddressFields()                                            *
 *                                                                         *
 * input: strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: clears the values in the provided fields                   *
 *                                                                         *
 ***************************************************************************/
function clearStandardAddressFields(strFormNum) {
    var objStreetTxtFld;
    var objCityStateZipTxtFld;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    objStreetTxtFld = document.getElementById('street-address' + strFormNum);
    objCityStateZipTxtFld = document.getElementById('city-state-zip' + strFormNum);

    if (objStreetTxtFld) {
        objStreetTxtFld.value = "";
    }
    if (objCityStateZipTxtFld) {
        objCityStateZipTxtFld.value = "";
    }

    //Clear objects
    objStreetTxtFld = null;
    objCityStateZipTxtFld = null;

    return;
} //clearStandardAddressFields()

/***************************************************************************
 * clearEnhancedAddressFields()                                            *
 *                                                                         *
 * input: strType - the type of address                                    *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: clears the values in the provided fields                   *
 *                                                                         *
 ***************************************************************************/
function clearEnhancedAddressFields(strType, strFormNum) {
    var objStateSelBox;
    var objUnitSelBox;
    var objBuildingSelBox;
    var objRoomTxtFld;
    var strLabel;
    var strBuildingLabel;
    var objStateHid;
    var objUnitHid;
    var objBuildingHid;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    if (strType == "Campus") {
        objStateSelBox = document.getElementById('cp_state' + strFormNum);
        objStateHid = document.getElementById('cp_state_value' + strFormNum);
        objUnitSelBox = document.getElementById('cp_campus' + strFormNum);
        objUnitHid = document.getElementById('cp_campus_value' + strFormNum);
        objBuildingSelBox = document.getElementById('cp_bldg' + strFormNum);
        objBuildingHid = document.getElementById('cp_bldg_value' + strFormNum);
        objRoomTxtFld = document.getElementById('cp_room' + strFormNum);
        strLabel = gStrLabel_SchoolCampus;
        strBuildingLabel = gStrLabel_Building;
    } else {
        objStateSelBox = document.getElementById('ml_state' + strFormNum);
        objStateHid = document.getElementById('ml_state_value' + strFormNum);
        objUnitSelBox = document.getElementById('ml_campus' + strFormNum);
        objUnitHid = document.getElementById('ml_campus_value' + strFormNum);
        objBuildingSelBox = document.getElementById('ml_bldg' + strFormNum);
        objBuildingHid = document.getElementById('ml_bldg_value' + strFormNum);
        objRoomTxtFld = document.getElementById('ml_room' + strFormNum);
        objRoomTxtFld = document.getElementById('ml_room' + strFormNum);
        strLabel = gStrLabel_Base;
        strBuildingLabel = gStrLabel_Building;
    }

    if (objStateSelBox && objStateHid) {
        if (objStateSelBox.options.length == 1 && objStateSelBox.value != "") {
            objStateSelBox.options.length = 0;
            objStateSelBox.options[0] = new Option(gStrLabel_SelectAState, "", true, true);
        } 
        objStateSelBox.selectedIndex = 0;
        objStateSelBox.value = "";
        objStateHid.value = "";
    }
    if (objUnitSelBox && objUnitHid) {
        if (objUnitSelBox.options.length == 1 && objUnitSelBox.value != "") {
            objUnitSelBox.options.length = 0;
            objUnitSelBox.options[0] = new Option(gStrLabel_SelectA + strLabel + " -", "", true, true);
        } 
        objUnitSelBox.selectedIndex = 0;
        objUnitSelBox.value = "";
        objUnitHid.value = "";
    }
    if (objBuildingSelBox && objBuildingHid) {
        if (objBuildingSelBox.options.length == 1 && objBuildingSelBox.value != "") {
            objBuildingSelBox.options.length = 0;
            objBuildingSelBox.options[0] = new Option(gStrLabel_SelectA + strBuildingLabel + " -", "", true, true);
        } 
        objBuildingSelBox.selectedIndex = 0;
        objBuildingSelBox.value = "";
        objBuildingHid.value = "";
    }
    if (objRoomTxtFld) {
        objRoomTxtFld.value = "";
    }

    //Clear objects
    objStateSelBox = null;
    objStateHid = null;
    objUnitSelBox = null;
    objUnitHid = null;
    objBuildingSelBox = null;
    objBuildingHid = null;
    objRoomTxtFld = null;

    return;
} //clearEnhancedAddressFields()

/***************************************************************************
 * getStates()                                                             *
 *                                                                         *
 * input: strServerURL - the url of the enhanced store locator             *
 *        strType - the type of primary value API to call                  *
 *        strInputValue - the value to use as input, null for now          *
 *        strSelectedValue - the value to select if any                    *
 *        blnClear - whether to clear the other dropdowns, default true    *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 * 												                           *
 * description: Calls the API to retrieve the list of values to            *
 *              populate the primary dropdown list (i.e. states)           *
 *              The list can be filtered based on the input entered so far *
 *                                                                         *
 ***************************************************************************/
function getStates(strServerURL, strType, strInputValue, strSelectedValue, blnClear, strFormNum) {
    var objStateSelBox;
    var strStateURL = strServerURL + "GetSLStates?type=" + strType;
    var strValue;
    
    if (strSelectedValue == null) {
        strSelectedValue = "";
    }

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    if (blnClear == null || typeof(blnClear) == undefined) {
        blnClear = true;
    }
            
    if (strType == "Campus") {
        objStateSelBox = document.getElementById('cp_state' + strFormNum);
    } else {
        objStateSelBox = document.getElementById('ml_state' + strFormNum);
    }

    if (objStateSelBox != null) {
        if (objStateSelBox.options.length <= 1) {
            strValue = objStateSelBox.value;

            if (strSelectedValue == "") {
                objStateSelBox.options.length = 0;
                objStateSelBox.options[0] = new Option(gStrLabel_RetrievingStates, "", true, true);
            }
            
            if (gObjStateRequest != null) {
                gObjStateRequest.blnControlledAbort = true;
                timeoutRequest(gObjStateRequest);
                gObjStateRequest.blnControlledAbort = false;
            }

            gObjStateRequest = getNewAjaxRequest("GetSLStates");

            gObjStateRequest.strAddressType = strType;
            gObjStateRequest.strFormNum = strFormNum;
            gObjStateRequest.strSelectedValue = strSelectedValue;
            gObjStateRequest.strPrevSelectedValue = strValue;
            gObjStateRequest.blnClear = blnClear;
            gObjStateRequest.strServerURL = strServerURL;

            sendAjaxRequest(gObjStateRequest, handleGetStateResponse, "POST", strStateURL, true, 
                            gStrError_TempUnavailable, 15000);
        }
    }

    //Clear objects
    objStateSelBox = null;

    return;
} //getStates()

/***************************************************************************
 * handleGetStateResponse()                                                *
 *                                                                         *
 * input: none                                                             *
 *                                                                         *
 * output: none                                                            *
 * 												                           *
 * description: The onstatechange function for the Store Locator get       *
 *              states API                                                 *
 *                                                                         *
 ***************************************************************************/
function handleGetStateResponse() {
    var strLatency;
    var objStateSelBox;
    var objUnitSelBox;
    var arrStates;
    var arrStateItem;
    var blnSelected = false;
    var strUnitLabel;
    var blnDefault = false;

    if (gObjStateRequest.objXmlHttp.readyState == 4) {
        window.clearTimeout(gObjStateRequest.intTimeoutId);
        gObjStateRequest.datXmlEnd = new Date();
        
        // if "OK"
        if (gObjStateRequest.objXmlHttp.status == 200) {
            strLatency = ((gObjStateRequest.datXmlEnd - gObjStateRequest.datXmlStart)/1000).toString();
            
            if (gObjStateRequest.strAddressType == "Campus") {
                objStateSelBox = document.getElementById('cp_state' + gObjStateRequest.strFormNum);
                objUnitSelBox = document.getElementById('cp_campus' + gObjStateRequest.strFormNum);
                strUnitLabel = gStrLabel_SchoolCampus;
            } else {
                objStateSelBox = document.getElementById('ml_state' + gObjStateRequest.strFormNum);
                objUnitSelBox = document.getElementById('ml_base' + gObjStateRequest.strFormNum);
                strUnitLabel = gStrLabel_Base; 
            }

            if (objStateSelBox != null && objUnitSelBox != null) {
                objStateSelBox.options.length = 0;


                if (gObjStateRequest.objXmlHttp.responseXML != null) {

                    arrStates = gObjStateRequest.objXmlHttp.responseXML.getElementsByTagName('State');

                    objStateSelBox.options[0] = new Option(gStrLabel_SelectAState, "", true, true);
                    if (arrStates.length > 0) {
                        for (var i = 0 ; i < arrStates.length ; i++) {
                            arrStateItem = strGetFirstChild(arrStates[i]).split("|");
                            blnSelected = (gObjStateRequest.strSelectedValue == arrStateItem[1]);
                            blnDefault = blnDefault || blnSelected; 
                            objStateSelBox.options[i+1] = new Option(arrStateItem[0].convertXML(true), arrStateItem[1], false, blnSelected);

                        }

                        if (gObjStateRequest.intKeyCode == 38) {
                            if (objStateSelBox.selectedIndex > 0) {
                                objStateSelBox.selectedIndex--;
                                retrieveUnits(gObjStateRequest.strServerURL, gObjStateRequest.strAddressType);
                                objStateSelBox.focus();
                            }
                        } else if (gObjStateRequest.intKeyCode == 40) {
                            
                            if (objStateSelBox.selectedIndex < (objStateSelBox.options.length-1)) {
                                objStateSelBox.selectedIndex++;

                                retrieveUnits(gObjStateRequest.strServerURL, gObjStateRequest.strAddressType);
                                objStateSelBox.focus();
                            }
                        }
                        if (gObjStateRequest.strPrevSelectedValue != objStateSelBox.value && gObjStateRequest.blnClear) {
                            objUnitSelBox.options.length = 0;
                            objUnitSelBox.options[0] = new Option(gStrLabel_SelectA + strUnitLabel + " -", "", true, true);
                        }
                        gObjStateRequest.intKeyCode = 0;

                        if (blnDefault) {
                            setHiddenAddressField(objStateSelBox);
                        }

                    } else {
                        alert(gStrError_NoInfoAddresType);
                    }
                } else {
                    alert(gStrError_NoInfoAddresType);
                }
            }
               
        } else if (!gObjStateRequest.blnControlledAbort) {
            if (gObjStateRequest.objXmlHttp.status == 0) {
                alert(gStrError_TempUnavailable);
            } else {
                alert(gStrError_TempUnavailable);
            }
        }

        gObjStateRequest.datXmlStart = null;
    }

    //Clear objects
    objStateSelBox = null;
    objUnitSelBox = null;
    arrStates = null;
    arrStateItem = null;

    return;

} //handleGetStateResponse()


/***************************************************************************
 * retrieveUnits()                                                         *
 *                                                                         *
 * input: strServerURL - the url of the enhanced store locator             *
 *        strType - the type of primary value API to call                  *
 *        strStateValue - the value to use as input                        *
 *        strSelectedValue - the value to select if any                    *
 *        blnClear - whether to clear the other dropdowns, default true    *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Calls the API to retrieve the list of values to            *
 *              populate the secondary dropdown list (i.e. campuses)       *
 *              The method will first obtain the primary value and will    *
 *              pass that to the API                                       *
 *                                                                         *
 ***************************************************************************/
function retrieveUnits(strServerURL, strType, strStateValue, strSelectedValue, blnClear, strFormNum) {
    var objStateSelBox;
    var objUnitSelBox;
    var strUnitURL;
    var strLabel;
    var strValue;

    if (strSelectedValue == null) {
        strSelectedValue = "";
    }

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
            
    if (blnClear == null || typeof(blnClear) == undefined) {
        blnClear = true;
    }

    if (strType == "Campus") {
        objStateSelBox = document.getElementById('cp_state' + strFormNum);
        objUnitSelBox = document.getElementById('cp_campus' + strFormNum);
        strLabel = gStrLabel_Campuses;
    } else {
        objStateSelBox = document.getElementById('ml_state' + strFormNum);
        objUnitSelBox = document.getElementById('ml_base' + strFormNum);
        strLabel = gStrLabel_BaseNames;
    }

    if (strSelectedValue != "" || didValueChange(objStateSelBox, strFormNum)) {
        setHiddenAddressField(objStateSelBox, strFormNum);

        if (strStateValue == null || typeof(strStateValue) == undefined) {
            if (objStateSelBox != null) {
                strStateValue = objStateSelBox.value;
            } else {
                strStateValue = "";
            }
        }

        if (objStateSelBox != null && objUnitSelBox != null && strStateValue != "") {

            strValue = objUnitSelBox.value;
            if (strSelectedValue == "" && !isRequestActive(gObjUnitRequest)) {

                objUnitSelBox.options.length = 0;

                objUnitSelBox.options[0] = new Option(gStrLabel_Retrieving + strLabel + " -", "", true, true);
            }

            if (gObjUnitRequest != null) {
                gObjUnitRequest.blnControlledAbort = true;
                timeoutRequest(gObjUnitRequest);
                gObjUnitRequest.blnControlledAbort = false;
            }

            gObjUnitRequest = getNewAjaxRequest("GetAllUnits");

            gObjUnitRequest.strAddressType = strType;
            gObjUnitRequest.strFormNum = strFormNum;
            gObjUnitRequest.strSelectedValue = strSelectedValue;
            gObjUnitRequest.strPrevSelectedValue = strValue;
            gObjUnitRequest.blnClear = blnClear;
            gObjUnitRequest.strServerURL = strServerURL;

            strUnitURL = strServerURL + "GetAllUnits?type=" + strType + "&state=" + escape(strStateValue);

            sendAjaxRequest(gObjUnitRequest, handleGetUnitResponse, "POST", strUnitURL, true, 
                            gStrError_TempUnavailable, 15000);
        }
    }

    //Clear objects
    objStateSelBox = null;
    objUnitSelBox = null;

    return;
} //retrieveUnits()


/***************************************************************************
 * handleGetUnitResponse()                                                 *
 *                                                                         *
 * input: none                                                             *
 *                                                                         *
 * output: none                                                            *
 * 												                           *
 * description: The onstatechange function for the Store Locator get       *
 *              units API                                                  *
 *                                                                         *
 ***************************************************************************/
function handleGetUnitResponse() {
    var strLatency;
    var objUnitSelBox;
    var objBuildingSelBox;
    var arrUnits;
    var arrUnitItem;
    var strLabel;
    var strLabelPlural;
    var strBuildingLabel;
    var strBuildingLabelPlural;
    var blnSelected = false;
    var blnDefault = false;

    if (gObjUnitRequest.objXmlHttp.readyState == 4) {
        window.clearTimeout(gObjUnitRequest.intTimeoutId);
        gObjUnitRequest.datXmlEnd = new Date();
        // if "OK"
        
        if (gObjUnitRequest.objXmlHttp.status == 200) {
            strLatency = ((gObjUnitRequest.datXmlEnd - gObjUnitRequest.datXmlStart)/1000).toString();
            
            if (gObjUnitRequest.strAddressType == "Campus") {
                objUnitSelBox = document.getElementById('cp_campus' + gObjUnitRequest.strFormNum);
                objBuildingSelBox = document.getElementById('cp_bldg' + gObjUnitRequest.strFormNum);
                strLabel = gStrLabel_SchoolCampus;
                strLabelPlural = gStrLabel_Campuses;
                strBuildingLabel = gStrLabel_Building;
                strBuildingLabelPlural = gStrLabel_DormBuildings;
            } else {
                objUnitSelBox = document.getElementById('ml_base' + gObjUnitRequest.strFormNum);
                objBuildingSelBox = document.getElementById('ml_bldg' + gObjUnitRequest.strFormNum);
                strLabel = gStrLabel_Base;
                strLabelPlural = gStrLabel_Bases;
                strBuildingLabel = gStrLabel_Building;
                strBuildingLabelPlural = gStrLabel_Buildings;
            }

            if (objUnitSelBox != null && objBuildingSelBox != null) {
                objUnitSelBox.options.length = 0;
                //objBuildingSelBox.options.length = 0;

                if (gObjUnitRequest.objXmlHttp.responseXML != null) {
                    arrUnits = gObjUnitRequest.objXmlHttp.responseXML.getElementsByTagName('SLUnit');

                    if (arrUnits.length == 0) {
                        objUnitSelBox.options[0] = new Option(gStrLabel_No + strLabelPlural + gStrLabel_Found, "", true, true);

                        if (gObjUnitRequest.blnClear) {
                            objBuildingSelBox.options.length = 0;
                            objBuildingSelBox.options[0] = new Option(gStrLabel_No + strBuildingLabelPlural + gStrLabel_Found, "", true, true);
                        }
                        alert(gStrError_NoInfoState);
                    } else {
                        objUnitSelBox.options[0] = new Option(gStrLabel_SelectA + strLabel + " -", "", true, true);
                        //objBuildingSelBox.options[0] = new Option("Select A " + strBuildingLabel, "", true, true);
                        for (var i = 0 ; i < arrUnits.length ; i++) {

                            arrUnitItem = strGetFirstChild(arrUnits[i]).split("|");
                            blnSelected = (gObjUnitRequest.strSelectedValue == arrUnitItem[1]);
                            blnDefault = blnDefault || blnSelected;
                            objUnitSelBox.options[i+1] = new Option(arrUnitItem[0].trim().convertXML(true), arrUnitItem[1].trim(), false, blnSelected);

                        }

                        if (gObjUnitRequest.intKeyCode == 38) {
                            if (objUnitSelBox.selectedIndex > 0) {
                                objUnitSelBox.selectedIndex--;
                                retrieveBuildings(gObjUnitRequest.strServerURL, gObjUnitRequest.strAddressType);
                                objUnitSelBox.focus();
                            }
                        } else if (gObjUnitRequest.intKeyCode == 40) {
                            
                            if (objUnitSelBox.selectedIndex < (objUnitSelBox.options.length-1)) {
                                objUnitSelBox.selectedIndex++;
                                retrieveBuildings(gObjUnitRequest.strServerURL, gObjUnitRequest.strAddressType);
                                objUnitSelBox.focus();
                            }
                        }                        
                        if (gObjUnitRequest.strPrevSelectedValue != objUnitSelBox.value && gObjUnitRequest.blnClear) {
                            objBuildingSelBox.options.length = 0;
                            objBuildingSelBox.options[0] = new Option(gStrLabel_SelectA + strBuildingLabel + " -", "", true, true);
                        }
                        gObjUnitRequest.intKeyCode = 0;
                    }
                    if (blnDefault) {
                        setHiddenAddressField(objUnitSelBox, gObjUnitRequest.strFormNum);
                    }
                    //objUnitSelBox.focus();
                } else {
                    alert(gStrError_NoInfoState);
                }

            }

        } else if (!gObjUnitRequest.blnControlledAbort) {
            if (gObjUnitRequest.objXmlHttp.status == 0) {
                alert(gStrError_TempUnavailable);
            } else {
                alert(gStrError_TempUnavailable);
            }
        }

        gObjUnitRequest.datXmlStart = null;
    }

    //Clear objects
    objUnitSelBox = null;
    objBuildingSelBox = null;
    arrUnits = null;
    arrUnitItem = null;

    return;
} //handleGetUnitResponse()

/***************************************************************************
 * retrieveBuildings()                                                     *
 *                                                                         *
 * input: strServerURL - the url of the enhanced store locator             *
 *        strType - the type of primary value API to call                  *
 *        strUnitValue - the value to use as input                         *
 *        strSelectedValue - the value to select if any                    *
 *        blnClear - whether to clear the other dropdowns, default true    *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Calls the API to retrieve the list of values to            *
 *              populate the tertiary dropdown list (i.e. buildings)       *
 *              The method will first obtain the primary and secondary     *
 *              values and will pass those to the API                      *
 *                                                                         *
 ***************************************************************************/
function retrieveBuildings(strServerURL, strType, strUnitValue, strSelectedValue, blnClear, strFormNum)
{
    var objUnitSelBox;
    var objBuildingSelBox;
    var strBuildingURL;
    var strLabel;

    if (strSelectedValue == null) {
        strSelectedValue = "";
    }

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
            
    if (strType == "Campus") {
        objUnitSelBox = document.getElementById('cp_campus' + strFormNum);
        objBuildingSelBox = document.getElementById('cp_bldg' + strFormNum);
        strLabel = gStrLabel_DormBuildings;
    } else {
        objUnitSelBox = document.getElementById('ml_base' + strFormNum);
        objBuildingSelBox = document.getElementById('ml_bldg' + strFormNum);
        strLabel = gStrLabel_Buildings;
    }

    setHiddenAddressField(objUnitSelBox, strFormNum);

    if (strUnitValue == null || typeof(strUnitValue) == undefined) {
        if (objUnitSelBox != null && objUnitSelBox.value != null) {
            strUnitValue = objUnitSelBox.value;
        } else {
            strUnitValue = "";
        }
    }

    if (objUnitSelBox != null && objBuildingSelBox != null && strUnitValue != "") {

        if (strSelectedValue == "") {
            objBuildingSelBox.options.length = 0;

            objBuildingSelBox.options[0] = new Option(gStrLabel_Retrieving + strLabel + " -", "", true, true);
        }

        if (gObjBldgRequest != null) {
            gObjBldgRequest.blnControlledAbort = true;
            timeoutRequest(gObjBldgRequest);
            gObjBldgRequest.blnControlledAbort = false;
        }

        gObjBldgRequest = getNewAjaxRequest("GetSLBuildings");

        gObjBldgRequest.strAddressType = strType;
        gObjBldgRequest.strFormNum = strFormNum;
        gObjBldgRequest.strSelectedValue = strSelectedValue;
        gObjBldgRequest.strServerURL = strServerURL;

        strBuildingURL = strServerURL + "GetSLBuildings?type=" + strType + "&slUnit=" + escape(strUnitValue);

        sendAjaxRequest(gObjBldgRequest, handleGetBuildingResponse, "POST", strBuildingURL, true, 
                        gStrError_TempUnavailable, 15000);
    }

    //Clear objects
    objUnitSelBox = null;
    objBuildingSelBox = null;

    return;
 
} //retrieveBuildings()

/***************************************************************************
 * handleGetBuildingResponse()                                             *
 *                                                                         *
 * input: none                                                             *
 *                                                                         *
 * output: none                                                            *
 * 												                           *
 * description: The onstatechange function for the Store Locator get       *
 *              buildings API                                              *
 *                                                                         *
 ***************************************************************************/
function handleGetBuildingResponse() {
    var strLatency;
    var objBuildingSelBox;
    var arrBuildings;
    var strBuilding;
    var strLabel;
    var strLabelPlural;
    var strInput;
    var blnSelected = false;
    var blnDefault = false;

    if (gObjBldgRequest.objXmlHttp.readyState == 4) {
        window.clearTimeout(gObjBldgRequest.intTimeoutId);
        gObjBldgRequest.datXmlEnd = new Date();
        // if "OK"
        
        if (gObjBldgRequest.objXmlHttp.status == 200) {
            strLatency = ((gObjBldgRequest.datXmlEnd - gObjBldgRequest.datXmlStart)/1000).toString();
            
            if (gObjBldgRequest.strAddressType == "Campus") {
                objBuildingSelBox = document.getElementById('cp_bldg' + gObjBldgRequest.strFormNum);
                strLabel = gStrLabel_Building;
                strLabelPlural = gStrLabel_DormBuildings;
                strInput = gStrLabel_Campus;
            } else {
                objBuildingSelBox = document.getElementById('ml_bldg' + gObjBldgRequest.strFormNum);
                strLabel = gStrLabel_Building;
                strLabelPlural = gStrLabel_Buildings;
                strInput = gStrLabel_Base;
            }

            if (objBuildingSelBox != null) {
                objBuildingSelBox.options.length = 0;


                if (gObjBldgRequest.objXmlHttp.responseXML != null) {
                    arrBuildings = gObjBldgRequest.objXmlHttp.responseXML.getElementsByTagName('SLBuilding');

                    if (arrBuildings.length == 0) {
                        objBuildingSelBox.options[0] = new Option(gStrLabel_No + strLabelPlural + gStrLabel_Found, "", true, true);
                        alert(gStrError_NoInfo + strInput + gStrError_Selected);
                    } else {
                        objBuildingSelBox.options[0] = new Option(gStrLabel_SelectA + strLabel + " -", "", true, true);
                        for (var i = 0 ; i < arrBuildings.length ; i++) {

                            strBuilding = strGetFirstChild(arrBuildings[i]);
                            blnSelected = (gObjBldgRequest.strSelectedValue == strBuilding);
                            blnDefault = blnDefault || blnSelected; 
                            objBuildingSelBox.options[i+1] = new Option(strBuilding.convertXML(true), strBuilding, false, blnSelected);

                        }
                        if (gObjBldgRequest.intKeyCode == 38) {
                            if (objBuildingSelBox.selectedIndex > 0) {
                                objBuildingSelBox.selectedIndex--;
                            }
                        } else if (gObjBldgRequest.intKeyCode == 40) {
                            
                            if (objBuildingSelBox.selectedIndex < (objBuildingSelBox.options.length-1)) {
                                objBuildingSelBox.selectedIndex++;
                            }
                        }
                        gObjBldgRequest.intKeyCode = 0;
                    }
                    if (blnDefault) {
                        setHiddenAddressField(objBuildingSelBox, gObjBldgRequest.strFormNum);
                    }
                    //objUnitSelBox.focus();
                } else {
                    alert(gStrError_NoInfo + strInput + gStrError_Selected);
                }

            }

        } else if (!gObjBldgRequest.blnControlledAbort) {
            if (gObjBldgRequest.objXmlHttp.status == 0) {
                alert(gStrError_TempUnavailable);
            } else {
                alert(gStrError_TempUnavailable);
            }
        }

        gObjBldgRequest.datXmlStart = null;
    }

    //Clear objects
    objBuildingSelBox = null;
    arrBuildings = null;

    return;
} //handleGetBuildingResponse()


/***************************************************************************
 * setHiddenAddressField()                                                 *
 *                                                                         *
 * input: objDropdown - the dropdown to use to get the value               *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: sets the values of the hidden field                        *
 *                                                                         *
 ***************************************************************************/
function setHiddenAddressField(objDropdown, strFormNum) {
    var objHid;
    var strId;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    if (objDropdown != null) {
        strId = objDropdown.id;

        if (strId.length > 1) {
            if (strId.substring(strId.length-1, strId.length) == strFormNum) {
                strId = strId.substring(0, strId.length-1);
            }

            objHid = document.getElementById(strId + "_value" + strFormNum);

            if (objHid && objDropdown.selectedIndex > -1 && objDropdown.options[objDropdown.selectedIndex]) { 
                objHid.value = objDropdown.options[objDropdown.selectedIndex].innerHTML.convertXML(true);
            }
        }

    }


    //Clear objects
    objHid = null;

    return;
} //setHiddenAddressField()


/***************************************************************************
 * didValueChange()                                                        *
 *                                                                         *
 * input: objDropdown - the dropdown to use to get the value               *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: checks to see if value in dropdown has changed             *
 *                                                                         *
 ***************************************************************************/
function didValueChange(objDropdown, strFormNum) {
    var objHid;
    var strId;
    var blnReturn = true;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    if (objDropdown != null) {
        strId = objDropdown.id;

        if (strId.length > 1) {
            if (strId.substring(strId.length-1, strId.length) == strFormNum) {
                strId = strId.substring(0, strId.length-1);
            }

            objHid = document.getElementById(strId + "_value" + strFormNum);

            if (objHid && objDropdown.selectedIndex > -1) {
                return !(objHid.value == objDropdown.options[objDropdown.selectedIndex].innerHTML.convertXML(true));
            }
        }

    }


    //Clear objects
    objHid = null;

    return blnReturn;
} //didValueChange()

/***************************************************************************
 * AjaxRequest()                                                           *
 *                                                                         *
 * description: An XmlHttpRequest object and its attributes.               *
 *                                                                         *
 ***************************************************************************/
function AjaxRequest()
{
	//An XMLHTTP object		
	this.objXmlHttp = null;

	//A DOMDocument object	
	this.objDomDoc = null;

	//Date used to measure latency times  
	this.datXmlStart = null;

	//Date used to measure latency times  
	this.datXmlEnd = null;
	
	//Integer timeout id
	this.intTimeoutId = 0;

	//Whether the abortion was controlled
	this.blnControlledAbort = false;

	//Return code from xml calls	 
	this.strStatusCode = "-1";

	//Return status from xml calls							 
	this.strStatusText = "";

	//The timeout function
	this.timeoutRequest = null;

	//The # of results
	this.intNumResults = 0;

	//The type of request
	this.strRequestType = "";

    //The address type 
    this.strAddressType = "";

    //The form number
    this.strFormNum = "";

    //The value to preselect
    this.strSelectedValue = "";

    //The previously selected value
    this.strPrevSelectedValue = "";

    //The keycode selected
    this.intKeyCode = 0;

    //Whether to clear the other dropdowns
    this.blnClear = true;

    //The url of the API
    this.strServerURL = "";

} //AjaxRequest()


/***************************************************************************
 * getNewAjaxRequest()                                                     *
 *                                                                         *
 * input: strType - the type of request being made                         *
 *        xmlDocument - the xml document to load                           *
 *        blnAsync - whether the dom doc is asynchronous, default true     *
 *                                                                         *
 * output: a new XMLHTTP Request object or ActiveXObject depending on      *
 *         browser                                                         *
 *                                                                         *
 * description: determines which type of object to create depending on the *
 *              browser and returns that new object.                       *
 *                                                                         *
 ***************************************************************************/
function getNewAjaxRequest(strType, xmlDocument, blnAsync) {
	var objNewAjaxRequest = new AjaxRequest();

	if (strType != null && typeof(strType) != undefined) {
		objNewAjaxRequest.strRequestType = strType;
	}
    if (blnAsync == null || typeof(blnAsync) != undefined) {
        blnAsync = true;
    }
	
	objNewAjaxRequest.timeoutRequest = function() {	
		if (objNewAjaxRequest.objXmlHttp) {	
			if (objNewAjaxRequest.objXmlHttp.readyState) {
				if (objNewAjaxRequest.objXmlHttp.readyState != 4) {	
					objNewAjaxRequest.objXmlHttp.abort();
				}
			}
		}
	}

	var arrVers = ["MSXML2.XmlHttp.3.0"];

	if (typeof XMLHttpRequest != 'undefined') {
		objNewAjaxRequest.objXmlHttp = new XMLHttpRequest();

	} else if (window.ActiveXObject) {  
        for (var i = 0; i < arrVers.length && objNewAjaxRequest.objXmlHttp == null; i++) {
            try {
				objNewAjaxRequest.objXmlHttp = new ActiveXObject(arrVers[i]);
			} 
			catch(e) {
                alert(gStrError_TempUnavailable);
            }
		}
	}

	if (xmlDocument != null && typeof(xmlDocument) != undefined) {
		objNewAjaxRequest.objDomDoc = getDomDocument();
		objNewAjaxRequest.objDomDoc.async = blnAsync;

		if (objNewAjaxRequest.objDomDoc != null) {
			objNewAjaxRequest.objDomDoc.loadXML(xmlDocument);
		}

	}
	
	return(objNewAjaxRequest);
} //getNewAjaxRequest()

/***************************************************************************
 * sendAjaxRequest()                                                       *
 *                                                                         *
 * input: objAjaxRequest - the xml http request object                     *
 *        fncOnReadyStateChange - function to call on ready state change   *
 *        strMethod - the method to use when opening, "GET" or "POST"      *
 *        strUrl - the url to open                                         *
 *        blnAsync - whether or not the open command is asynchronous       *
 *        strAlert - the alert to display for a failure                    * 
 *        intTimeout	- how long to wait for a timeout                   *
 *        fncError - the function to call in the event of an error         *
 *        strParseAlert	- the alert to display for a parse error           *
 *        fncParseError	- the function to call for a parse error           *
 *        blnSendStr - whether to send the data as a string                *
 *        strParameterName - the parameter name for the send string        *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: sends the request.                                         *
 *                                                                         *
 ***************************************************************************/
function sendAjaxRequest(objAjaxRequest, fncOnReadyStateChange, strMethod, strUrl, blnAsync, strAlert, 
                         intTimeout, fncError, strParseAlert, fncParseError, blnSendString, strParameterName) {	
	if (blnSendString == null || typeof(blnSendString) == undefined) {
		blnSendString = false;
	}
	if (objAjaxRequest.objXmlHttp != null) {
		objAjaxRequest.datXmlStart = new Date();
		
		if (objAjaxRequest.objDomDoc != null && objAjaxRequest.objDomDoc.parseError != 0) {

			if (strParseAlert != null && typeof(strParseAlert) != undefined && strParseAlert != "") {
				alert(strParseAlert + objAjaxRequest.objDomDoc.parseError);
			}
			if (fncParseError != null && typeof(fncParseError) != undefined) {
				fncParseError(objAjaxRequest.objDomDoc.parseError);
			}
		} else {

			try {
				objAjaxRequest.objXmlHttp.onreadystatechange = fncOnReadyStateChange;
				objAjaxRequest.objXmlHttp.open(strMethod, strUrl, blnAsync);

				if (objAjaxRequest.objDomDoc != null) {

					if (blnSendString && strParameterName != null & strParameterName != "") {  
						objAjaxRequest.objXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-9");
						objAjaxRequest.objXmlHttp.send(strParameterName + "=" + escapeURI(objAjaxRequest.objDomDoc.xml));
                    } else {
						objAjaxRequest.objXmlHttp.send(objAjaxRequest.objDomDoc);
					}
				} else {

					objAjaxRequest.objXmlHttp.send(null);
				}

				if (intTimeout != null && typeof(intTimeout) != undefined) {
					objAjaxRequest.intTimeoutId = window.setTimeout(objAjaxRequest.timeoutRequest, intTimeout);
				}
			}
			catch(err) { 

				if (strAlert != null && typeof(strAlert) != undefined && strAlert != "") {
					alert(strAlert);
				}
				if (fncError != null && typeof(fncError) != undefined) {
					fncError(err.description);
				}
			}
		}

	}

	return;
} //sendAjaxRequest()

/***************************************************************************
 * getDomDocument()                                                        *
 *                                                                         *
 * input: none                                                             * 
 *                                                                         *
 * output: objNewDomDoc - a DOM Document object                            *
 *                                                                         *
 * description: creates a DOM Document object using the latest version     *
 *              available to the browser.                                  *
 *                                                                         *
 ***************************************************************************/
function getDomDocument()
{
    var arrDomVers = ["MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument.2.0", "MSXML2.DOMDocument.1.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
    var objNewDomDoc = null;

	for (var i = 0; i < arrDomVers.length && objNewDomDoc == null; i++) {
		try {
			objNewDomDoc = new ActiveXObject(arrDomVers[i]);
		} 
		catch(e) {
            alert(gStrError_TempUnavailable);
        }
	}

	return objNewDomDoc;
} //getDomDocument()

/***************************************************************************
 * timeoutRequest()                                                        *
 *                                                                         *
 * input: objAjaxRequest - the ajax request object to abort                * 
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Aborts a request.                                          *
 *                                                                         *
 ***************************************************************************/
function timeoutRequest(objAjaxRequest)
{
	if (objAjaxRequest.objXmlHttp) {	
		if (objAjaxRequest.objXmlHttp.readyState) {
			if (objAjaxRequest.objXmlHttp.readyState != 4) {	
				objAjaxRequest.objXmlHttp.abort();
			}
		}
	}
} //timeoutRequest()


/***************************************************************************
 * isRequestActive()                                                       *
 *                                                                         *
 * input: objAjaxRequest - the ajax request object to abort                *
 *                                                                         *
 * output:  blnActive - whether a request is active                        *
 *                                                                         *
 * description: Returns true or false - whether a request is active.       *
 *                                                                         *
 ***************************************************************************/
function isRequestActive(objAjaxRequest)
{
    var blnActive = false;
    if (objAjaxRequest) {
        if (objAjaxRequest.objXmlHttp) {	
            if (objAjaxRequest.objXmlHttp.readyState) {
                blnActive = (objAjaxRequest.objXmlHttp.readyState != 4);
            }
        }
    }
   
   return blnActive;
} //isRequestActive()


/***************************************************************************
 * strGetFirstChild()                                                      *
 *                                                                         *
 * input: objNode - the node to process                                    *
 *        strDefault - the default value to use if null                    * 
 *                                                                         *
 * output: strNodeValue - the data under a node                            *
 *                                                                         *
 * description: Returns the first data contents under a node.              *
 *                                                                         *
 ***************************************************************************/
function strGetFirstChild(objNode, strDefault)
{
	var strNodeValue;

	if (strDefault == null || typeof(strDefault) == undefined)
	{
		strDefault = "";
	}
	strNodeValue = strDefault;
	if (objNode)
	{
		strNodeValue = (objNode.firstChild) ? 
							objNode.firstChild.data : strDefault;
	}

	return(strNodeValue);
} //strGetFirstChild()


/***************************************************************************
 * strGetFirstChildArray()                                                 *
 *                                                                         *
 * input: arrNode - the array of nodes to process                          *
 *        strDefault - the default value to use if null                    *
 *                                                                         *
 * output: strNodeValue - the data under a node                            *
 *                                                                         *
 * description: Returns the first data contents under a node.              *
 *                                                                         *
 ***************************************************************************/
function strGetFirstChildArray(arrNode, strDefault)
{
	var strNodeValue;

	if (strDefault == null || typeof(strDefault) == undefined) {
		strDefault = "";
	}
	strNodeValue = strDefault;
	if (arrNode.length> 0) {
		strNodeValue = (arrNode[0].firstChild) ? 
							arrNode[0].firstChild.data : strDefault;
	}

	return(strNodeValue);
} //strGetFirstChildArray()

/***************************************************************************
 * strGetFirstChildAttribute()                                             *
 *                                                                         *
 * input: objNode - the node to process                                    *
 *        strAttributeName - the name of the attribute to retrieve         *
 *        strDefault - the default value to use if null                    * 
 *                                                                         *
 * output: strNodeValue - the data under a node                            *
 *                                                                         *
 * description: Returns the first data contents under a node.              *
 *                                                                         *
 ***************************************************************************/
function strGetFirstChildAttribute(objNode, strAttributeName, strDefault)
{
	var strAttrValue;

	if (strDefault == null || typeof(strDefault) == undefined)
	{
		strDefault = "";
	}
	strAttrValue = strDefault;
	if (objNode)
	{
		strAttrValue = (objNode.getAttribute(strAttributeName) != "" && objNode.getAttribute(strAttributeName) != null) ? 
							objNode.getAttribute(strAttributeName) : strDefault;
	}

	return(strAttrValue);
} //strGetFirstChildAttribute()


/***************************************************************************
 * strGetTextNodeValue()                                                   *
 *                                                                         *
 * input: xmlDocument - the xml document to retrieve the node from         *
 *        strNodeName - the name of the node requested                     *
 *        strDefault - the default value to use if null                    *
 *                                                                         *
 * output: strReturn - the text value of the first node requested          *
 *                                                                         *
 * description: Retrieves the text value of the first node with the given  *
 *              name.                                                      *
 *                                                                         *
 ***************************************************************************/
function strGetTextNodeValue(xmlDocument, strNodeName, strDefault)
{
	var arrNodes;
	var strReturn = "";

	if (xmlDocument && strNodeName != "")
	{
		arrNodes = xmlDocument.getElementsByTagName(strNodeName);

		if (arrNodes.length > 0)
		{
			strReturn = strGetFirstChildArray(arrNodes, strDefault);
		}
	}

	//Clear objects
	arrNodes = null;

	return strReturn;
} //strGetTextNodeValue()

/***************************************************************************
 *                                                                         *
 * description: Creates a trim function for the string class.              *
 *                                                                         *
 ***************************************************************************/
String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

String.prototype.convertXML = function(blnConvert) {
    var str = this;
    
    if (blnConvert) {
        str = str.replace(/\&amp;/g,'&');
        str = str.replace(/\&lt;/g,'<');
    }
    else {
        str = str.replace(/\&/g,'&amp;');
        str = str.replace(/</g,'&lt;');
    }
    return str;
};


/***************************************************************************
 * showCorrectAddressForm()                                                *
 *                                                                         *
 * input: addressTypeChosenL - the address type                            *
 *        stateChosenL - the state code                                    *
 *        campusChosenL - the campus code                                  *
 *        buildingChosenL - the building code                              *
 *        roomChosenL - the room number                                    *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Selects the campus tab and populates the values.           *
 *                                                                         *
 ***************************************************************************/
function showCorrectAddressForm(addressTypeChosenL, stateChosenL, campusChosenL, buildingChosenL, roomChosenL) {
    if(addressTypeChosenL == 'C') {
        hideStreetAddress();
        showCampusAddress();
        document.getElementById('cp_room').value = roomChosenL;
        getStates(gStrServerURLscdv, 'Campus', null, stateChosenL, false);
        retrieveUnits(gStrServerURLscdv, 'Campus', stateChosenL, campusChosenL, false);
        retrieveBuildings(gStrServerURLscdv, 'Campus', campusChosenL, buildingChosenL);
    }
} //showCorrectAddressForm()

<!-- mp_trans_disable_end -->
