


function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function P7_hideDiv(evt) { //v1.2 by PVII
    var b, relT, mT = false;
    if (document.layers) {
        b = evt.target; if (b.p7aHide) {
            b.visibility = "hidden";
        } else { routeEvent(evt); }
    } else if (document.all && !window.opera) {
        b = event.srcElement;
        while (b != null) { if (b.tagName == "DIV" && b.p7ahD) { mT = true; break; } b = b.parentElement; }
        if (!b.contains(event.toElement)) { b.style.visibility = "hidden"; }
    } else if (document.getElementById) {
        b = evt.currentTarget; relT = evt.relatedTarget;
        while (relT != null) {
            if (b == relT) { mT = true; break; }
            relT = relT.parentNode;
        } if (!mT) { b.style.visibility = "hidden"; }
    }
}

function P7_autoHide() { //v1.2 by PVII
    var i, g, args = P7_autoHide.arguments;
    for (i = 0; i < args.length; i++) {
        if ((g = MM_findObj(args[i])) != null) {
            g.p7aHide = true; if (document.layers) {
                g.captureEvents(Event.MOUSEOUT);
            } g.onmouseout = P7_hideDiv; g.p7ahD = true;
        }
    }
}

function P7_autoLayers() { //v1.2 by PVII
    var g, b, k, f, args = P7_autoLayers.arguments;
    var a = parseInt(args[0]); if (isNaN(a)) a = 0;
    if (!document.p7setc) {
        p7c = new Array(); document.p7setc = true;
        for (var u = 0; u < 10; u++) { p7c[u] = new Array(); }
    }
    for (k = 0; k < p7c[a].length; k++) {
        if ((g = MM_findObj(p7c[a][k])) != null) {
            b = (document.layers) ? g : g.style; b.visibility = "hidden";
        }
    }
    for (k = 1; k < args.length; k++) {
        if ((g = MM_findObj(args[k])) != null) {
            b = (document.layers) ? g : g.style; b.visibility = "visible"; f = false;
            for (j = 0; j < p7c[a].length; j++) {
                if (args[k] == p7c[a][j]) { f = true; }
            }
            if (!f) { p7c[a][p7c[a].length++] = args[k]; }
        }
    }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}


function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function validateSelEducation() {
    if (document.getElementById("selEducation")) {
        if (document.getElementById("selEducation").value == "0") {
            document.getElementById("selEducationOther").innerHTML = "<BR><input type=text name=txtEducationOther class=reg_items1 value=''>";

        }
        else {
            document.getElementById("selEducationOther").innerHTML = "";
        }

    }
}
function validateSelProf() {
    if (document.getElementById("selProf")) {

        if (document.getElementById("selProf").value == "0") {
            document.getElementById("selProfOther").innerHTML = "<BR><input type=text name=txtProfOther class=reg_items1 value=''>";

        }
        else {
            document.getElementById("selProfOther").innerHTML = "";
        }

    }
}
function validateSelOrg() {
    if (document.getElementById("selOrg")) {

        if (document.getElementById("selOrg").value == "0") {
            document.getElementById("selOrgOther").innerHTML = "<BR><input type=text name=txtOrgOther class=reg_items1 value=''>";

        }
        else {
            document.getElementById("selOrgOther").innerHTML = "";
        }

    }
}

function borderMouseover(id) {
    var dashSpot = id.lastIndexOf("_");
    if (document.getElementById(id.substring(0, dashSpot + 1) + "divBorder")) {
        document.getElementById(id.substring(0, dashSpot + 1) + "divBorder").style.borderColor = "#8D0022";
    }
}
function borderMouseout(id) {
    var dashSpot = id.lastIndexOf("_");
    if (document.getElementById(id.substring(0, dashSpot + 1) + "divBorder")) {
        document.getElementById(id.substring(0, dashSpot + 1) + "divBorder").style.borderColor = "#FBF698";
    }
}

function checkField(id) {
    var aspnetID;
    if (document.getElementById(id).value == 0) {
        aspnetID = id.replace("_", "$");
        aspnetID = aspnetID.replace("_", "$");
        setTimeout('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("' + aspnetID + '", "", false, "", "", true, true))', 0);
    }
    else {
        if (document.getElementById(id.replace("ddl", "txt"))) {
            aspnetID = id.replace("_", "$");
            aspnetID = aspnetID.replace("_", "$");
            setTimeout('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("' + aspnetID + '", "", false, "", "", true, true))', 0);
        }
    }

}

function CreateControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, AUTOSTART, showCaptioning, uiMode) {
    var d = document.getElementById(DivID);
    d.innerHTML = '<object classid=' + CLSID + ' id=' + ObjectID + ' width=' + WIDTH + ' height=' + HEIGHT + '><param name="URL" value="' + URL + '" /><param name="autoStart" value=' + AUTOSTART + ' /><param name="ShowCaptioning" value="' + showCaptioning + '" /><param name="uiMode" value="' + uiMode + '" /><EMBED type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" id="' + ObjectID + '" name="' + ObjectID + '"  autosize="' + AUTOSTART + '" ShowCaptioning="' + showCaptioning + '" uiMode="' + uiMode + '" width="' + WIDTH + '" height="' + HEIGHT + '" src="' + URL + '" autostart="1" loop="0" autoresize="1"></embed></object>';
    //d.innerHTML += '
    //alert(d.innerHTML);


}
function DisplayMemberCertTimeoutWarning(SecondsRemaining) {
    //clearInterval(window["memberCertInterval"]);
    if (SecondsRemaining == 0) {
        jQuery(".programQuizTimeExpired").css("display", "block");
        clearInterval(window["memberCertInterval"]);
    } else {
        var display = false;
        if (SecondsRemaining < 120) {
            if ((jQuery(".programQuizTimeWarning .close").attr("rel") != "viewedBoth") && (jQuery(".programQuizTimeWarning .close").attr("rel") != "viewedTwoMinute")) {
                display = true;
                if (jQuery(".programQuizTimeWarning .close").attr("rel") == "viewedQuarter") {
                    jQuery(".programQuizTimeWarning .close").attr("rel", "viewedBoth");
                } else {
                    jQuery(".programQuizTimeWarning .close").attr("rel", "viewedTwoMinute");
                }
            }
        } else if (SecondsRemaining < (testLength * 60 * 0.25)) {
            if ((jQuery(".programQuizTimeWarning .close").attr("rel") != "viewedBoth") && (jQuery(".programQuizTimeWarning .close").attr("rel") != "viewedQuarter")) {
                display = true;

                if (jQuery(".programQuizTimeWarning .close").attr("rel") == "viewedTwoMinute") {
                    jQuery(".programQuizTimeWarning .close").attr("rel", "viewedBoth");
                } else {
                    jQuery(".programQuizTimeWarning .close").attr("rel", "viewedQuarter");
                }
            }
        }
        if (display) {
            jQuery(".programQuizTimeWarning").css("display", "block");
            jQuery(".programQuizTimeWarning .minutes").text(Math.floor(SecondsRemaining / 60));
            if ((SecondsRemaining % 60) < 10) {
                jQuery(".programQuizTimeWarning .seconds").text("0" + SecondsRemaining % 60);
            } else {
                jQuery(".programQuizTimeWarning .seconds").text((SecondsRemaining % 60));
            }
        }
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}
function hidePINHelp() {
    document.getElementById("divPINHelp").style.visibility = "hidden";
}
function showPINHelp(x) {
    document.getElementById("divPINHelp").style.top = findPos(x)[1];
    document.getElementById("divPINHelp").style.left = findPos(x)[0];
    document.getElementById("divPINHelp").style.visibility = "visible";
}
function validatePrivateLabel(sender, args) {
    var selectedIndex = jQuery('.privateLabelDdl')[0].selectedIndex;
    if (selectedIndex > 0) {
        if ((privateLabelRequireId[selectedIndex - 1] == true) && (privateLabelIdFormat[selectedIndex - 1].length > 0)) {

            var rx = new RegExp(privateLabelIdFormat[selectedIndex - 1]);
            var matches = rx.exec(jQuery(".privateLabelTxt").val());

            args.IsValid = (matches != null && jQuery(".privateLabelTxt").val() == matches[0]);

        } else {
            args.IsValid = true;
        }
    } else {
        args.IsValid = true;
    }
}
function validatePrivateLabelTerms(sender, args) {
    if (jQuery('#mask').css("display") == "none") {
        args.IsValid = true;
    } else {
        var selectedIndex = jQuery('.privateLabelDdl')[0].selectedIndex;
        if (selectedIndex > 0) {
            args.IsValid = jQuery('.termsChk>input').is(":checked");
        } else {
            args.IsValid = true;
        }
    }
}
function getOverImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 2, 2).toLowerCase() == "up") {
        return newUrl.substr(0, newUrl.length - 2) + "Over" + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function getUpImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 4, 4).toLowerCase() == "over") {
        return newUrl.substr(0, newUrl.length - 4) + "Up" + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function getf2OverImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));

    return newUrl + "_f2" + url.substring(url.lastIndexOf("."));

}
function getf2UpImageUrl(url) {
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 3, 3) == "_f2") {
        return newUrl.substr(0, newUrl.length - 3) + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function setActive(control) {
    url = jQuery(control).attr("src");
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 6, 6) == "Grayed") {
        jQuery(control).attr("src", newUrl.substr(0, newUrl.length - 6) + "Active" + url.substring(url.lastIndexOf(".")));
    }
}
function setGrayed(control) {
    url = jQuery(control).attr("src");
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 6, 6) == "Active") {
        jQuery(control).attr("src", newUrl.substr(0, newUrl.length - 6) + "Grayed" + url.substring(url.lastIndexOf(".")));
    }
}
function validatePasswordRequired(sender, args) {
    args.IsValid = (jQuery(".oldPassword").val().length > 0) || (jQuery(".securityQuestion").val() == jQuery(".securityQuestion").attr("rel") && jQuery(".securityAnswer").val().length == 0);
}
function securityAnswerRequired(sender, args) {
    args.IsValid = (jQuery(".securityQuestion").val() == jQuery(".securityQuestion").attr("rel") || jQuery(".securityAnswer").val().length > 0)
}
function ie8SafePreventEvent(e) {
    if (e.preventDefault) { e.preventDefault() }
    else { e.stop() };

    e.returnValue = false;
    e.stopPropagation();
}
if (window.jQuery) {
    jQuery.noConflict();

    
   
    function checkMemberCertTimeout() {
        var action = new RemoteMethod('MemberCertHelper', 'GetTimeRemaining', memberCertId);
        action.LocalAction = function (args) {
            //if (args < 300) {
            DisplayMemberCertTimeoutWarning(args);
            //}
        }
        action.Invoke();
    }
    function f2Over() {
        this.src = getf2OverImageUrl(this.src);
    }
    function f2Out() {
        this.src = getf2UpImageUrl(this.src);
    }
    function overUpOver() {
        this.src = getOverImageUrl(this.src);
    }
    function overUpOut() {
        this.src = getUpImageUrl(this.src);
    }
    function loadImages() {
        var overUpImages = jQuery(".overUp img, input.overUp, img.overUp");
        for (var i = 0; i < overUpImages.length; i++) {
            var img = new Image;
            img.src = getOverImageUrl(overUpImages[i].src);
            
        }
        var f2Images = jQuery(".f2 img, input.f2, img.f2");
        for (var i = 0; i < f2Images.length; i++) {
            var img = new Image;
            img.src = getf2OverImageUrl(f2Images[i].src);
        }
        jQuery(".f2 img, input.f2, img.f2").unbind("mouseover", f2Over);
        jQuery(".f2 img, input.f2, img.f2").unbind("mouseout", f2Out);
        jQuery(".f2 img, input.f2, img.f2").mouseover(f2Over);
        jQuery(".f2 img, input.f2, img.f2").mouseout(f2Out);
        jQuery(".overUp img, input.overUp, img.overUp").unbind("mouseover", overUpOver);
        jQuery(".overUp img, input.overUp, img.overUp").unbind("mouseout", overUpOut);
        jQuery(".overUp img, input.overUp, img.overUp").mouseover(overUpOver);
        jQuery(".overUp img, input.overUp, img.overUp").mouseout(overUpOut);
    }
    jQuery(document).ready(function () {
        if ((jQuery(".programQuiz").length > 0) && (jQuery(".programQuizTimeExpired").length > 0)) {
            jQuery(".programQuiz").ready(function () {
                window["memberCertInterval"] = setInterval(checkMemberCertTimeout, 10000);
                jQuery(".programQuizTimeWarning .close").click(function () {
                    jQuery(this).parent().css("display", "none");
                });
            });
        }
        if (jQuery(".missingInfo").length > 0) {
            Page_ClientValidate("");
        }
        loadImages();

        jQuery(".closeModal").click(function (e) {
            e.preventDefault();
            jQuery('#mask, .mask, .dialog').hide();
        });

        jQuery(".updateProfileBtn").click(function (e) {
            ie8SafePreventEvent(e)
            if ((jQuery('.privateLabelDdl').length > 0) && (jQuery('.privateLabelDdl')[0].selectedIndex > 0) && ((jQuery('.privateLabelDdl').val() != privateLabelOrgId) || (jQuery('.privateLabelTxt').val() != privateLabelEmployeeId))) {
                if (Page_ClientValidate("")) {
                    showPrivateLabelModal("../");
                }
            } else {
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(this.name, "", true, "", "", false, true));
            }
            return false;
        });
        jQuery(".registerBtn").click(function (e) {
            ie8SafePreventEvent(e)
            if ((jQuery('.privateLabelDdl').length == 0) || (jQuery('.privateLabelDdl')[0].selectedIndex == 0)) {
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(this.name, "", true, "", "", false, true));
            } else {
                if (Page_ClientValidate("")) {
                    showPrivateLabelModal("");
                }
            }
            return false;
        });
        jQuery(".pollResults .close").click(function (e) {
            e.preventDefault();
            jQuery(".pollResults").hide();
            jQuery(".pollResults .inner>img").attr("src", jQuery(".pollResults .inner>img").attr("rel"));
            if (window["nextPoll"] != null) {
                jQuery(".poll .question span:first-child, .pollResults .question").html(window["nextPoll"].Text);
                var name = jQuery(".answers>span input:first-child").attr("name");
                var nextPoll = window["nextPoll"];
                var id = jQuery(".answers>span input:first-child").attr("id");
                id = id.substring(0, id.length - 2);

                jQuery(".answers span").html("");
                var answerSpan = jQuery(".answers>span")[0];
                for (var i = 0; i < nextPoll.Answers.length; i++) {
                    var input = document.createElement("input");
                    input.type = "radio";
                    input.value = nextPoll.Answers[i].Id;
                    input.name = name;
                    input.id = id + "_" + i;
                    answerSpan.appendChild(input);
                    var label = document.createElement("label");
                    label.htmlFor = id + "_" + i;
                    label.innerHTML = nextPoll.Answers[i].Value;
                    answerSpan.appendChild(label);
                    answerSpan.appendChild(document.createElement("br"));
                }
                jQuery(".submitPoll").attr("disabled", "");
            } else {
                jQuery(".poll").hide();
            }
        });
        jQuery(".submitPoll").click(function (e) {
            ie8SafePreventEvent(e)
            if (Page_ClientValidate("pollVg")) {

                var action = new RemoteMethod('PollHelper', 'Submit', jQuery(".poll .answers input:checked").val());
                action.LocalAction = function (args) {
                    if ((args != null) && (args.SubmittedQuestionId > 0)) {
                        if (jQuery(".pollResults .inner>img").attr("rel") == null) {
                            jQuery(".pollResults .inner>img").attr("rel", jQuery(".pollResults .inner>img").attr("src"))
                        }
                        jQuery(".pollResults").show();
                        jQuery(".pollResults .inner>img").attr("src", applicationRoot + "images/poll/poll" + args.SubmittedQuestionId + ".png");
                        window["nextPoll"] = args.NewQuestion;
                        jQuery(".submitPoll").attr("disabled", "true");
                        jQuery(".submitPoll").attr("src", getf2UpImageUrl(jQuery(".submitPoll").attr("src")));
                    }
                }
                action.Invoke();
            }
        });
        jQuery(".submitPoll").ready(function (e) {
            jQuery(".submitPoll").attr("disabled", "");
            var radio = jQuery(".poll .answers input:checked");
            for (var i = 0; i < radio.length; i++) {
                radio[i].checked = false;
            }

        });
        jQuery(".tooltip").ready(function () {
            if (jQuery(".tooltip").length > 0) {
                jQuery(".tooltip").tooltip({ showURL: false });
            }
        });
        jQuery(".privateLabelToolTip").ready(function () {

            if (jQuery(".privateLabelToolTip").length > 0) {
                jQuery(".privateLabelToolTip").tooltip({ showURL: false });


            }
            if (jQuery(".privateLabelOverviewToolTip").length > 0) {
                jQuery(".privateLabelOverviewToolTip").tooltip({ showURL: false });
            }
        });
        jQuery('.privateLabelDdl').change(function () {
            if (this.selectedIndex == 0) {
                jQuery(".privateLabelTxt").text = "";
                jQuery(".privateLabelTxt").attr("disabled", "true");
                jQuery(".privateLabelToolTip").css("display", "none");
            } else {
                if (privateLabelRequireId[this.selectedIndex - 1] == true) {
                    jQuery(".privateLabelTxt").attr("disabled", "");
                    jQuery(".privateLabelToolTip").css("display", "inline");
                    jQuery(".privateLabelToolTip").attr("title", privateLabelToolTip[this.selectedIndex - 1]);
                    jQuery(".privateLabelToolTip").tooltip({ showURL: false })
                } else {
                    jQuery(".privateLabelTxt").attr("disabled", "true");
                    jQuery(".privateLabelToolTip").css("display", "none");
                }
            }
        });
        jQuery('.termsChk>input').change(function () {
            if (jQuery(this).is(":checked")) {
                jQuery(".termsAcceptBtn").attr("disabled", "");
                setActive(jQuery(".termsAcceptBtn"));
            } else {
                jQuery(".termsAcceptBtn").attr("disabled", "true");
                setGrayed(jQuery(".termsAcceptBtn"));
            }
        });
    });

    function showPrivateLabelModal(UrlPrefix, id) {
        id = "#privateLabelDialog";

        var maskHeight = jQuery(document).height();
        var maskWidth = jQuery(window).width();

        jQuery('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        jQuery('#mask').fadeIn(1000);
        jQuery('#mask').fadeTo("slow", 0.8);

        var winH = jQuery(window).height();
        var winW = jQuery(window).width();

        jQuery(id).css('top', winH / 2 - jQuery(id).height() / 2);
        jQuery(id).css('left', winW / 2 - jQuery(id).width() / 2);

        jQuery(id).fadeIn(2000);
        scroll(0, 0);
        jQuery.ajax({
            type: "POST",
            url: UrlPrefix + "ajaxpro/StonehouseMedia.LearningNetwork.PrivateLabel.Web.Helpers.PrivateLabelHelper,StonehouseMedia.LearningNetwork.PrivateLabel.Web.ashx",
            data: '{"PrivateLabelOrgId":"' + jQuery('.privateLabelDdl').val() + '"}',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("X-AjaxPro-Method", "GetTerms");
            },
            success: function (s) {
                var response = JSON.parse(s);
                if (response.value != undefined) {
                    jQuery(".terms").html(response.value);
                    jQuery(".termsChk").attr("disabled", "");
                    jQuery(".termsChk").children().attr("disabled", "");
                    jQuery(".termsChk").children().attr("checked", "");
                    jQuery(".termsAcceptBtn").attr("disabled", "true");
                }
            }
        });
    }
}
