﻿/// <reference path="jquery.min-vsdoc.js" />
///<reference name="MicrosoftAjax.js"/>
///**************************************************************************/
//if (typeof ('Sys') !== 'undefined') Sys.Application.notifyScriptLoaded();
/**************************************************************************/

// JScript File
/* ©2008 King Schools, Inc. */

// KSO.js 
// Description: Client-Side methods for manupulation of KLMS UI
// Version: Versioning will be tied to the deploy assembly of KLMS
// -----------------------------------------------------------------
// 09/25/08 - Rolando Carias 4.1.0.4
// 10/20/2008 - Rolando Carias 5.0.0.0

//Global Variables

var externalJSFiles = [];

//King Schools Namespace for client-side scripting
Type.registerNamespace('KLMS.Web.UI');

//Create an internal "private" Page object/class tied to the namespace.
KLMS.Web.UI._Page = function KLMSWebUI$_KLMS()
{ }

//Returns an instance of the internal _Page object/class
function KLMSWebUI$_Page$_getInstance() {
    if (!this._instance) {

        this._instance = new KLMS.Web.UI._Page();
    }
    
    return this._instance;
};


//Create the prototype for this client-side class
KLMS.Web.UI._Page.prototype = {


    _instance: null,
    _jQueryPrefixIdSelectorChar: '#',
    _errorControlHighlightCSS: {
        background: '#ffe3e3',
        border: '1px solid #ff0000'

    },
    _standardControlHighlightCSS: {
        background: '#ffffff',
        border: '1px solid #a7a6aa',
        fontweight: 'normal',
        color: '#000000'
    },

    _USCountryCode: '0000',
    _CanadianCountryCode: '0001',

    //Properties
    canadianProvinceList: function() {
        var list = ['Alberta', 'British Columbia',
										'Manitoba', 'New Brunswick',
										'Newfoundland', 'Nova Scotia',
										'Northwest Territories',
										'Ontario', 'Prince Edward Island',
										'Quebec', 'Saskatchewan', 'Yukon Territory'];
        return (list);

    },


    get_IsAuthenticated: function() {
        var authenticated = Sys.Services.AuthenticationService.get_isLoggedIn();
        return (authenticated);
    },

    get_RequestedPageName: function() {
        var pageName = '';
        var urlSegments;

        if (document.location.pathname == '/') {
            //It's the root of KLMS
            return (pageName = "KSOIndex.aspx");
        }

        urlSegments = document.location.pathname.split('/');
        for (var i = 0; i < urlSegments.length; i++) {
            if (urlSegments[i].indexOf(".aspx") >= 0 ||
               urlSegments[i].indexOf(".htm") >= 0 ||
               urlSegments[i].indexOf(".html") > -0) {

                pageName = urlSegments[i];
                break;
            }

        }

        return (pageName);
    },

    get_IsPostBack: function() {
        var isPostBack = $("#isPostBack").val();
        if (isPostBack != null) {

            isPostBack = Boolean.parse(isPostBack);
        }
        return (isPostBack);
    },
    /*Begin Public Methods to handle Browser Session Cookies*/
    get_SessionCookieValue: function(cookieName) {
        ///<summary>
        ///Get a Browser's Session Cookie value.
        ///</summary>    
        ///<returns>The value found in the document.cookie collection for the requested cookie name</returns>

        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i].trim();
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, cookieName.length + 1) == (cookieName + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(cookieName.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    },

    set_SessionCookieValue: function(strCookieName, strCookieValue, intExpire, strPath, strDomain, blnSecure) {
        ///<summary>
        ///Adds a cookie to the document.cookie collection. Method throws a null reference exception if cookie name is
        ///'undefined' or null.     
        ///</summary>
        ///<param name="strCookieName">String Name of the cookie to add. </param>
        ///<param name="strCookieValue">String Value associated with the cookie </param>
        ///<param name="intExpire">Integer value for how many days from Now to expire the cookie. Optional. If null or 'undefined' then the cookie will be destroyed when the browser is closed.</param>
        ///<param name="strPath">Cookie Path. Optional </param>
        ///<param name="strDomain">String cookie Domain. Optional </param>
        ///<param name="blnSecure">Boolean create a secure cookie. Optional </param>           
        ///<returns>this</returns>
        var expires;
        var date = new Date();
        var path;
        var domain;
        var secure;

        if (strCookieName !== null && typeof (strCookieName) != 'undefined') {
            //Check the options
            if (intExpire == null || typeof intExpire == undefined) {

                expires = String.format("; expires={0}", '');

            } else
                if (intExpire && typeof (intExpire) === 'number') {
                date.setTime(date.getTime() + (intExpire * 24 * 60 * 60 * 1000));
                expires = String.format("; expires={0}", date.toGMTString());

            }

            if (strPath == null || typeof strPath == undefined) {
                path = '';
            } else {
                path = String.format("; path={0}", strPath);
            }

            if (strDomain == null || typeof strDomain == undefined) {
                domain = '';

            } else {
                domain = String.format("; domain={0}", strDomain);
            }

            if (blnSecure == null || typeof blnSecure == undefined || !blnSecure) {
                secure = '';
            } else {
                secure = String.format("; {0}", blnSecure);
            }


            var cookie = [strCookieName, '=', encodeURIComponent(strCookieValue), expires, path, domain, secure].join('');
            document.cookie = cookie;

            return (this);

        } else {
            throw Error('Null or undefined reference for input parameters [strCookieName | strCookieValue]');
        }
    },

    delete_SessionCookie: function(strCookieName) {
        ///<summary>
        ///Remove the named cookie from the document.cookie collection.
        ///</summary>
        this.set_SessionCookieValue(strCookieName, '', null);
        return (this);
    },
    /*End Public Methods to handle Browser Session Cookies*/

    IsEmptyString: function(val) {
        if (typeof (val) === 'undefined' || val === null) {
            return true;
        }

        //first remove all spaces using the following regex
        val = val.replace(/^\s+|\s+$/, '');

        //then we check for the length of the string if its 0 or not
        if (val.length == 0)
            return true;
        else
            return false;
    },

    trimLeft: function(val) {
        return (val.replace(/^\s+/, ""));
    },

    trimRight: function(val) {
        return (val.replace(/\s+$/, ""));
    },

    trim: function(val) {
        return (val.replace(/^\s+|\s+$/g, ""));
    },

    supplant: function(htmlTemplate, data) {
        ///<summary>
        ///This method allows us to specify HTML template and replace the given tokens with the data provided.
        ///NOTE: the template must be in the exact format and the data must be JSON type.
        ///USAGE:
        ///var templateHTML = "<table width="{width}"> <tr><td>{firstname}</td></tr></table>";
        ///var datatoSupplant = {width: "100%" , firstname:"Rollo Pollo" };
        ///call: myDiv.innerHTML = KSO.Web.UI.Page.supplant(templateHTML,datatoSupplant);
        ///</summary>
        return htmlTemplate.replace(/{([^{}]*)}/g,
		    function(a, b) {
		        var r = data[b];
		        return typeof r === 'string' ? r : a;

		    }
	    );

    },

    set_ControlVisibility: function(objControl, isVisible) {

        if (objControl && typeof (isVisible) !== 'undefined') {
            if (isVisible == true) {
                $("#" + objControl.id).css("visibility", "visible").show();
            } else {
                $("#" + objControl.id).css("visibility", "hidden").hide();

            }
        }

        return (this);
    },

    clear_InputTextField: function(objTextControl) {
        if (objTextControl) {
            $("#" + objTextControl.id).val("");

        }

        return (this);
    },

    set_InputTextField: function(objTextControl, value) {
        if (objTextControl && val) {
            $("#" + objTextControl).val(value);
        }

        return (this);
    },

    set_ControlFocus: function(objControl) {
        if (objControl) {
            $("#" + objControl.id).focus();

        }

    },

    validate_RequiredInputTextField: function(objTextControl) {

        var isValid = true;
        if (objTextControl) {
            var value = $("#" + objTextControl.id).val();
            if (this.IsEmptyString(value)) {
                isValid = false;
            }
        }

        return (isValid);
    },

    set_InvalidInputFieldStyle: function(objControl) {

        if (objControl) {

            $("#" + objControl.id).removeClass("resetTextbox");


            $("#" + objControl.id).addClass("errorHighlightTextbox");
            $("#" + objControl.id).css(KLMSPage()._errorControlHighlightCSS);

        }

        return (this);
    },

    set_ValidInputFieldStyle: function(objControl) {

        if (objControl) {

            $("#" + objControl.id).removeClass("errorHighlightTextbox");

            $("#" + objControl.id).css(KLMSPage()._standardControlHighlightCSS);
            $("#" + objControl.id).addClass("resetTextbox");
        }

        return (this);
    },

    set_Opacity: function(objControl, opacityValue) {

        if (objControl) {
            var fractionalValue = opacityValue / 10;
            $("#" + objControl.id).css("opacity", fractionalValue.toString());


        }

        return (this);
    },

    set_ControlDisable: function(objControl, isDisabled) {

        if (objControl) {
            if (isDisabled == true) {
                $("#" + objControl.id).attr("disabled", "disabled");

            } else {

                $("#" + objControl.id).removeAttr("disabled");

            }

        }

        return (this);
    },


    get_SelectedDropdownListValue: function(objListControl) {
        var value;

        if (objListControl) {

            value = $("#" + objListControl.id + "  :selected").val();
        }

        return (value);
    },

    get_SelectedDropdownListText: function(objListControl) {
        var innerText;

        if (objListControl) {

            innerText = $("#" + objListControl.id + "  :selected").text();
        }

        return (innerText);
    },



    showCertificateAlert: function() { alert("When you have completed all the lessons, click here to print your course complete materials."); },

    showCourseCompleteMaterialAlert: function() { KLMSPage().showCertificateAlert(); },

    showQuestionAlert: function(questionCount) {

        var hiddenQuizPostBackLink = '';

        if ($("a.HiddenQuizPostBackLink").length > 0) {
            hiddenQuizPostBackLink = $("a.HiddenQuizPostBackLink")[0].id;
        }



        var agree = confirm("You have " + questionCount + " unanswered or incorrectly answered question(s) in this lesson.  Do you really want to exit the quiz?  (This lesson will not show complete until you have answered all questions correctly.) Click “Cancel” and use the “Previous” button to return to the unanswered or incorrectly answered questions. Click “Ok” to leave the quiz anyway.");

        var stayControl = $get("Stay");

        if (agree == true) {

            if (stayControl) { stayControl.value = "1"; }

            __doPostBack(hiddenQuizPostBackLink, '');

            //$("form").submit();

        } else if (agree == false) {

            if (stayControl) { stayControl.value = "0"; return false; }
        }


    },

    set_AnswerChoice: function(event, answerId) {
        var answerControl = $get("SelectedAnswerId");
        if (answerControl) {
            if (event && event.data) {
                answerId = event.data.AnswerId;

            }
            answerControl.value = answerId;
            if (answerId == -1) {
                KLMSPage().set_SessionCookieValue("playsound", "no");
            }
            else {

                KLMSPage().set_SessionCookieValue("playsound", "yes");
            }

            var hiddenQuizPostBackLink = '';

            if ($("a.HiddenQuizPostBackLink").length > 0) {
                hiddenQuizPostBackLink = $("a.HiddenQuizPostBackLink")[0].id;
            }

            __doPostBack(hiddenQuizPostBackLink, '');


        }


    },

    get_AudioPlayerObjectString: function(audioSource) {


        var objectTagStart = "<object {0} >";
        var objectTagEnd = "</object>";
        var objectTagID = "id='audioplayer'";
        var objectTagClassID = "classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B'";
        var objectTagMimeType = "type='audio/x-mpeg'";
        var objectTagHeight = "height='0'";
        var objectTagWidth = "width='0'";
        var objectTagAutoPlay = "autoplay='true'";
        var objectTagVisible = "visible='false'";
        var objectTagData = String.format("data='{0}'", audioSource);

        var objectTagParamSrc = String.format("<param name='src' value='{0}'/>", audioSource);
        var objectTagParamAutoStart = "<param name='autoplay' value='true'/>";
        var objectTagParamAutoPlay = "<param name='autoStart' value='1'/>";
        var objectTagProps = new Sys.StringBuilder();
        var objectTagString = new Sys.StringBuilder();

        objectTagProps.append(objectTagID);

        if ($.browser.msie || document.all) {
            objectTagProps.append(objectTagClassID);
        }

        objectTagProps.append(objectTagMimeType);
        objectTagProps.append(objectTagHeight);
        objectTagProps.append(objectTagWidth);
        objectTagProps.append(objectTagAutoPlay);
        objectTagProps.append(objectTagVisible);
        objectTagProps.append(objectTagData);

        objectTagString.append(String.format(objectTagStart, objectTagProps.toString()));
        objectTagString.appendLine(objectTagParamSrc);
        objectTagString.appendLine(objectTagParamAutoStart);
        objectTagString.appendLine(objectTagParamAutoPlay);
        objectTagString.appendLine(objectTagEnd);

        return (objectTagString.toString());
        
    },
    get_SoundManagerAudioFile: function(soundId) {

        var audioFileUrl = '';
        try {

            switch (soundId) {

                case "correct":
                    {
                        audioFileUrl = 'audio/correct.mp3';
                        break;

                    }
                case "incorrect":
                    {
                        audioFileUrl = 'audio/incorrect.mp3';
                        break;

                    }
                case "terrain_ahead":
                    {
                        audioFileUrl = 'audio/terrain_ahead_x2_f.mp3';

                        break;

                    }
                case "obstacle_ahead":
                    {

                        audioFileUrl = 'audio/obstacle_ahead_x2_f.mp3';
                        break;

                    } case "caution_terrain":
                    {
                        audioFileUrl = 'audio/caution_terrain_x2_f.mp3';
                        break;

                    }
                case "caution_obstacle":
                    {
                        audioFileUrl = 'audio/caution_obstacle_x2_f.mp3';
                        break;

                    }
                case "too_low_terrain":
                    {
                        audioFileUrl = 'audio/too_low_terrain_f.mp3';
                        break;

                    }
                case "pull_up":
                    {
                        audioFileUrl = 'audio/pull_up_f.mp3';
                        break;

                    } case "sink_rate":
                    {
                        audioFileUrl = 'audio/sink_rate_f.mp3';
                        break;

                    } case "500":
                    {
                        audioFileUrl = 'audio/500_f.mp3';
                        break;

                    } case "dont_sink":
                    {
                        audioFileUrl = 'audio/dont_sink_f.mp3';
                        break;

                    } case "check_altitude":
                    {
                        audioFileUrl = 'audio/CHECK_ALTITUDE_x2.mp3';
                        break;

                    }
                case "too_low_gear":
                    {
                        audioFileUrl = 'audio/TOO_LOW_GEAR_x2.mp3';
                        break;

                    }
                case "too_low_flaps":
                    {
                        audioFileUrl = 'audio/TOO_LOW_FLAPS_x2.mp3';
                        break;

                    }

                case "bank_angle":
                    {
                        audioFileUrl = 'audio/BANK_ANGLE_x2_m.mp3';
                        break;

                    }
                default:
                    break;
            }



        } catch (err) {

        }

        return (audioFileUrl);
    },


    playCorrectSound: function() {

        var soundMode = $("input[name$='SoundMode']");

        //        if (soundMode.length > 0) {
        //            if (soundMode.attr("checked") == true) {
        //                if (soundManager == null) {
        //                    return;
        //                }
        //                soundManager.play('correct');

        //            }
        //        }

    },

    playIncorrectSound: function() {

        var soundMode = $("input[name$='SoundMode']");

        //        if (soundMode.length > 0) {
        //            if (soundMode.attr("checked") == true) {
        //                if (soundManager == null) {
        //                    return;
        //                }
        //                soundManager.play("incorrect");

        //            }
        //        }


    },

    get_IndexOfUSACountryFromList: function(selectCountryControlList) {

        var index = 0;
        if (selectCountryControlList) {
            var selector = String.format("{0}{1} [value={2}]", "#", selectCountryControlList.id, this._USCountryCode);
            if ($(selector).length > 0) {
                index = $(selector)[0].index;

            }

        }

        return (index);

    },

    get_IndexOfCanadaCountryFromList: function(selectCountryControlList) {

        var index = 0;
        if (selectCountryControlList) {
            var selector = String.format("{0}{1} [value={2}]", "#", selectCountryControlList.id, this._CanadianCountryCode);
            if ($(selector).length > 0) {
                index = $(selector)[0].index;

            }

        }

        return (index);

    },

    set_CountryDropdownListValue: function(event, objStateListControlID, objCountryListContolID) {


        if (event) {
            objStateListControlID = event.data.StateControlId;
            objCountryListContolID = event.data.CountryControlId;

        }
        if (objCountryListContolID && objStateListControlID) {

            //query the controls
            //if the selectedIndex of the state list control is at zero, then return false
            var currentStateSelected = $("#" + objStateListControlID + " :selected");
            if (currentStateSelected) {
                if (currentStateSelected[0].index === 0) return (false);

                if (currentStateSelected[0].value.toLowerCase() == "fn") {
                    //It is a foreign nation, select the country's first item on the list
                    $("#" + objCountryListContolID).val("");
                    return (this);
                }

                //Is it a Canadian Province
                var retValue = $.inArray(currentStateSelected[0].text, KLMSPage().canadianProvinceList());
                if (retValue !== -1) {
                    //Then it's a Canadian Province Selection
                    $("#" + objCountryListContolID).val(KLMSPage()._CanadianCountryCode);
                } else {
                    //must be U.S.A
                    $("#" + objCountryListContolID).val(KLMSPage()._USCountryCode);

                }


            }



        }

        return (this);
    },


    set_StateDropdownListValue: function(event, objStateListControlID, objCountryListContolID) {

        if (event) {
            objStateListControlID = event.data.StateControlId;
            objCountryListContolID = event.data.CountryControlId;

        }

        if (objCountryListContolID && objStateListControlID) {

            //query the controls
            //if the selectedIndex of the state list control is at zero, then return false

            var currentCountrySelected = $("#" + objCountryListContolID + " :selected");
            var currentStateSelected = $("#" + objStateListControlID + " :selected");

            if (currentCountrySelected.length > 0 && currentStateSelected.length > 0) {
                if (currentCountrySelected[0].index === 0) return (false);

                if ((currentCountrySelected[0].value.toLowerCase() == KLMSPage()._CanadianCountryCode) ||
                    (currentCountrySelected[0].value.toLowerCase() == KLMSPage()._USCountryCode)) {
                    //It is a foreign nation, select the country's first item on the list
                    $("#" + objStateListControlID).val("");

                } else {

                    //probably a FN
                    $("#" + objStateListControlID).val("FN");

                }




            }



        }

        return (this);
    },

    ///<summary>
    ///Toggle the Pilot Type Dropdown list and all associated controls. This function is automatically
    /// bound to the Pilot Type control's change event, passing in the Event object as an argument, if the control is detected. Do not call directly.
    ///</summary>    
    ///<returns>false</returns>
    _togglePilotTypeControl: function(event) {

        if (event) {

            var currentSelectedOption = $(event.target).not("options:selected"); //remove all elements not selected

            var txtPilotCertificateNum = $("input[name$='" + event.data.PilotCertificateNumber + "']");

            if (currentSelectedOption.length > 0 && txtPilotCertificateNum.length > 0) {

                if (currentSelectedOption[0].value.toLowerCase() == "1" || currentSelectedOption[0].value.toLowerCase() == "3") {
                    //we disable all associated controls

                    $(KLMSPage()._jQueryPrefixIdSelectorChar + event.data.PilotLabel).css({ backgroundColor: 'silver', color: '#ffffff', fontWeight: 'bold' }).text("Pilot Certificate Number");

                    KLMSPage().set_ControlDisable(txtPilotCertificateNum[0], true);
                    KLMSPage().set_Opacity(txtPilotCertificateNum[0], 5);

                    $("input[name=" + event.data.PilotCheckBoxGroup + "]").attr("disabled", "disabled").css("opacity", ".50");

                    //Remember this state for page load events


                } else {

                    $(KLMSPage()._jQueryPrefixIdSelectorChar + event.data.PilotLabel).css({ backgroundColor: '#ffffff', color: '#800000', fontWeight: 'bold' }).text("Pilot Certificate Number*");
                    KLMSPage().set_ControlDisable(txtPilotCertificateNum[0], false);
                    KLMSPage().set_Opacity(txtPilotCertificateNum[0], 10);
                    $("input[name=" + event.data.PilotCheckBoxGroup + "]").removeAttr("disabled").css("opacity", "1");

                }

            }



        }

        return (false);

    }




} //End prototype

    //Register the internal class/prototype using ASP.net AJAX's method
    KLMS.Web.UI._Page.registerClass('KLMS.Web.UI._Page');
    //Create a global object set to a new instance of the internal prototype.
    //Makes this object ready for use in any page that references this script.
    //Sample USAGE:
    // KLMSPage().get_SessionCookieValue(...);
    var KLMSPage = function() {
        return new KLMSWebUI$_Page$_getInstance();
    };

    var KLMSInitialized = false;
    

    //Global PageLoad from ASP.net AJAX, equivalent to JQuery's $(document).ready. Mimics ASP.net page_load event server side/
    //Note in order to use any of the above javascript file, including the '$' object,
    //we must load the jquery.min.js first, then this one.
    function pageLoad(sender, args) {
    
        _pageInitializers(KLMSPage().get_RequestedPageName());
     
        
        if (!KLMSInitialized) {
           // alert('Initializing...');
            initKLMS();
            KLMSInitialized = true;
        }

    }

    function initKLMS() {

        try {

            //Hides from firefox the soundmanager debug console
            
           // $("#soundmanager-debug").hide();
            //Load any requested scripts
            for (var i = 0; i < externalJSFiles.length; i++) {
                var scriptElem = document.createElement("script");
                scriptElem.setAttribute("type", "text/javascript");
                scriptElem.setAttribute("src", externalJSFiles[i]);
                document.getElementsByTagName("head")[0].appendChild(scriptElem);

            }

            //Bind Side Rail UI events
           
            this._bindMenuEventsIE();

            //find all anchors that contain an href pointing to kingschools.com and set their target to a new window.
            $("a[href*='kingschools.com']").attr("target", "_blank");
        
            if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
             
                $("#homemenu").attr("href", "/default.aspx");
                

            } 


         

              //Set properties for IFRAME pages
              var objFrame = $("#oFrame");
              if (objFrame.length > 0) {
                
                  $("#footer").hide().css("visibility", "hidden");
                  $("#sideRail").hide();
                  var newH = $(document).innerHeight() - $("#header").innerHeight();
                  
                  
                  $("#oFrame").height(newH);
                  $("#oFrame").resize(function() {
                  var newH = $(window).innerHeight() - $("#header").innerHeight();
                     
                      $("#oFrame").height(newH);

                  });
              }

             
               
            //Set Pilot Control UI settings
            if ($("select[name$='PilotType']").length > 0) {
            
                var pilotData = { PilotCertificateNumber: 'PilotCertificateNumber',
                PilotLabel: 'lblPilotCertNum',
                    PilotCheckBoxGroup: 'pilot'
                };
            
                $("select[name$='PilotType']").bind("change", pilotData, KLMSPage()._togglePilotTypeControl);
                $("select[name$='PilotType']").trigger('change', pilotData);


            }

            _initCountryAndStateControls();

        } catch (error) {

          
        }
    }



    
    //private methods

    function _pageInitializers(pageName) {

        switch (pageName.toLowerCase()) {

            case "default.aspx":
                {
                    break;
                }
            case "quiz.aspx":
                {
                    
                    break;
                }
            case "ktcdefault.aspx":
                {
                    break;
                }

            case "ktciframe.aspx":
                {
                    break;
                }

            case "login.aspx":
                {
                   
                   
                    break;
                }

            case "externalcourseviewer.aspx":
                {

                    break;
                }
            case "coursecertificate.aspx":
                {

                    var boolRequestType = $("#IsTurbineType").val();
                    if (boolRequestType != null && typeof (boolRequestType) != 'undefined') {

                        if (!Boolean.parse(boolRequestType)) {
                            $(".linkMenu").remove();
                            $("#header").remove();
                            $("#pagerLinks").remove();
                        }

                    }
                    break;
                }
             
             case "myaccount.aspx":
             {
             
                
    			
			    if (Sys.Services.AuthenticationService.get_isLoggedIn()) {

				        if ($('#sideRail').length > 0) {
					        $("#sideRail").remove();
					        $("div#center").css("width", "760px").css("margin", "0 auto");
				        }

				   }
    				
			  
			    
			    break; 

			}	
		                
            default:
                break;     
                       
        }
    
     }
    
    function _initCountryAndStateControls() {
        
        //Set toggling of state dropdown and country for the EnrollStudentInfo and MyAccount
        //onchange="ChangeOfStateEnroll($get('hiddenState').value,$get('hiddenCountry').value)"
        if ($("select[name$='State']").length > 0) {

            var stateData = {
                StateControlId: $get('hiddenState').value,
                CountryControlId: $get('hiddenCountry').value
            };
            $("select[name$='State']").bind("change", stateData, KLMSPage().set_CountryDropdownListValue);
           // $("select[name$='State']").trigger('change', stateData);

        }

        //onchange="ChangeOfStateEnroll($get('hiddenState').value,$get('hiddenCountry').value)"
        if ($("select[name$='Country']").length > 0) {

            var stateData = {
                StateControlId: $get('hiddenState').value,
                CountryControlId: $get('hiddenCountry').value
            };
            $("select[name$='Country']").bind("change", stateData, KLMSPage().set_StateDropdownListValue);
            //$("select[name$='Country']").trigger('change', stateData);

        }

        //Set toggling of state dropdown and country for the EnrollStudentInfo and MyAccount shipping
        //onchange="ChangeOfStateEnroll($get('hiddenState').value,$get('hiddenCountry').value)"
        if ($("select[name$='ddlShippingStateProvince']").length > 0) {

            var stateData = {
            StateControlId: $get('hiddenShippingState').value,
            CountryControlId: $get('hiddenShippingCountry').value
            };
            $("select[name$='ddlShippingStateProvince']").bind("change", stateData, KLMSPage().set_CountryDropdownListValue);
            //$("select[name$='ddlShippingStateProvince']").trigger('change', stateData);

        }

        //onchange="ChangeOfStateEnroll($get('hiddenState').value,$get('hiddenCountry').value)"
        if ($("select[name$='ddlShippingCountry']").length > 0) {

            var stateData = {
                StateControlId: $get('hiddenShippingState').value,
                CountryControlId: $get('hiddenShippingCountry').value
            };
            
            $("select[name$='ddlShippingCountry']").bind("change", stateData, KLMSPage().set_StateDropdownListValue);
           // $("select[name$='ddlShippingCountry']").trigger('change', stateData);

        }
    }

    //Private method to bind the UI effects of the siderail
    function _bindMenuEventsIE() {

       try {
           if (document.all && document.getElementById) 
           {
             var navRoot = $("#rootMenuContainer");
             if (navRoot.length == 0) {
                  /*attempt by class name*/
                   navRoot = $(".rootMenuContainer")[0];
               }
             
               for (i = 0; i < navRoot.childNodes.length; i++) {
                  node = navRoot.childNodes[i];
                  if (node.nodeName == "LI") {
                     node.onmouseover = function() {
                          this.className += " over";
                       }

                       node.onmouseout = function() {
                         this.className = this.className.replace(" over", "");
                     }
                }
             }
      
           }
        } catch (err) { 
       
            }
    }


    /*Backward Compatible Methods*/

    function openWindow(url, width,height)
	{
	
	 window.open(url,"",String.format("width={0},height={1}",width,height));
	 return false;
	}
	
    function IsEmpty(stringValue) {


        return (KLMSPage().IsEmptyString(stringValue));
    }


    function StringTrim(stringToTrim) {
        return (KLMSPage().trim(stringToTrim));
    }

    function StringLeftTrim(stringToTrim) {
        return (KLMSPage().trimLeft(stringToTrim));
    }

    function StringRightTrim(stringToTrim) {
        return (KLMSPage().trimRight(stringToTrim));
    }

    function showCertificateAlert() {
        KLMSPage().showCertificateAlert();
        
    }
    
        

    /* Helper Page Methods */

    ///* Client-side access to querystring name=value pairs
    //Version 1.3
    //28 May 2008
    //	
    //License (Simplified BSD):
    //http://adamv.com/dev/javascript/qslicense.txt
    //*/
    
    function Querystring(qs) { // optionally pass a querystring to parse
        this.params = {};

        if (qs === null || typeof qs === 'undefined') qs = location.search.substring(1, location.search.length);
        if (qs.length == 0) return;

    //    // Turn <plus> back to <space>
    //    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
        qs = qs.replace(/\+/g, ' ');
        var args = qs.split('&'); // parse out name/value pairs separated via &

    //    // split out each name=value pair
        for (var i = 0; i < args.length; i++) {
            var pair = args[i].split('=');
            var name = decodeURIComponent(pair[0]);

            var value = (pair.length == 2)
    			? decodeURIComponent(pair[1])
    			: name;

            this.params[name] = value;
        }
    }

    Querystring.prototype.get = function(key, default_) {
        var value = this.params[key];
        return (value != null) ? value : default_;
    }

    Querystring.prototype.contains = function(key) {
        var value = this.params[key];
        return (value != null);
    }







    /*****************************************************/
    if (typeof ('Sys') !== 'undefined') Sys.Application.notifyScriptLoaded();
    //This is added so that this pageLoad will also be called along with any other specific pageLoad
    Sys.Application.add_load(this.pageLoad);
