


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 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 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 = $('.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($(".privateLabelTxt").val());

            args.IsValid = (matches != null && $(".privateLabelTxt").val() == matches[0]);

        } else {
            args.IsValid = true;
        }
    } else {
        args.IsValid = true;
    }
}
function validatePrivateLabelTerms(sender, args) {
    if ($('#mask').css("display") == "none") {
        args.IsValid = true;
    } else {
        var selectedIndex = $('.privateLabelDdl')[0].selectedIndex;
        if (selectedIndex > 0) {
            args.IsValid = $('.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) == "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) == "Over") {
        return newUrl.substr(0, newUrl.length - 4) + "Up" + url.substring(url.lastIndexOf("."));
    } else {
        return url;
    }
}
function setActive(control) {
    url = $(control).attr("src");
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 6, 6) == "Grayed") {
        $(control).attr("src", newUrl.substr(0, newUrl.length - 6) + "Active" + url.substring(url.lastIndexOf(".")));
    }
}
function setGrayed(control) {
    url = $(control).attr("src");
    var newUrl = url.substring(0, url.lastIndexOf("."));
    if (newUrl.substr(newUrl.length - 6, 6) == "Active") {
        $(control).attr("src", newUrl.substr(0, newUrl.length - 6) + "Grayed" + url.substring(url.lastIndexOf(".")));
    }
}
if (window.jQuery) {
    function ie8SafePreventEvent(e) {
        if (e.preventDefault) { e.preventDefault() }
        else { e.stop() };

        e.returnValue = false;
        e.stopPropagation();
    }

    $(document).ready(function () {
    	var overUpImages = $(".overUp img, input.overUp, img.overUp");
	        for (var i = 0; i < overUpImages.length; i++) {
	            var img = new Image;
	            img.src = getOverImageUrl(overUpImages[i].src);
        }
    
        $(".overUp img, input.overUp").mouseover(function (e) {
            this.src = getOverImageUrl(this.src);
        });
        $(".overUp img, input.overUp").mouseout(function (e) {
            this.src = getUpImageUrl(this.src);
        });
        $(".closeModal").click(function (e) {
            e.preventDefault();
            $('#mask, .dialog').hide();
        });
        $(".updateProfileBtn").click(function (e) {
            ie8SafePreventEvent(e)
            if (($('.privateLabelDdl').length > 0) && ($('.privateLabelDdl')[0].selectedIndex > 0) && (($('.privateLabelDdl').val() != privateLabelOrgId) || ($('.privateLabelTxt').val() != privateLabelEmployeeId))) {
                if (Page_ClientValidate("")) {
                    showPrivateLabelModal("../");
                }
            } else {
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(this.name, "", true, "", "", false, true));
            }
            return false;
        });
        $(".registerBtn").click(function (e) {
            ie8SafePreventEvent(e)
            if (($('.privateLabelDdl').length == 0) || ($('.privateLabelDdl')[0].selectedIndex == 0)) {
                WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(this.name, "", true, "", "", false, true));
            } else {
                if (Page_ClientValidate("")) {
                    showPrivateLabelModal("");
                }
            }
            return false;
        });
        $(".privateLabelToolTip").ready(function () {
            if ($(".privateLabelToolTip").length > 0) {
                $(".privateLabelToolTip").tooltip({ showURL: false });
            }
        });
        $('.privateLabelDdl').change(function () {

            if (this.selectedIndex == 0) {
                $(".privateLabelTxt").text = "";
                $(".privateLabelTxt").attr("disabled", "true");
                $(".privateLabelToolTip").css("display", "none");
            } else {
                if (privateLabelRequireId[this.selectedIndex - 1] == true) {
                    $(".privateLabelTxt").attr("disabled", "");
                    $(".privateLabelToolTip").css("display", "inline");
                    $(".privateLabelToolTip").attr("title", privateLabelToolTip[this.selectedIndex - 1]);
                    $(".privateLabelToolTip").tooltip({ showURL: false });
                } else {
                    $(".privateLabelTxt").attr("disabled", "true");
                    $(".privateLabelToolTip").css("display", "none");
                }
            }
        });
        $('.termsChk>input').change(function () {
            if ($(this).is(":checked")) {
                $(".termsAcceptBtn").attr("disabled", "");
                setActive($(".termsAcceptBtn"));
            } else {
                $(".termsAcceptBtn").attr("disabled", "true");
                setGrayed($(".termsAcceptBtn"));
            }
        });
    });

    function showPrivateLabelModal(UrlPrefix, id) {
        id = "#privateLabelDialog";

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        
        $('#mask').fadeTo("slow", 0.8);

        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        $(id).fadeIn(2000);
        scroll(0, 0);
        $.ajax({
            type: "POST",
            url: UrlPrefix + "ajaxpro/StonehouseMedia.LearningNetwork.PrivateLabel.Web.Helpers.PrivateLabelHelper,StonehouseMedia.LearningNetwork.PrivateLabel.Web.ashx",
            data: '{"PrivateLabelOrgId":"' + $('.privateLabelDdl').val() + '"}',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("X-AjaxPro-Method", "GetTerms");
            },
            success: function (s) {
                var response = JSON.parse(s);
                if (response.value != undefined) {
                    $(".terms").html(response.value);
                    $(".termsChk").attr("disabled", "");
                    $(".termsChk").children().attr("disabled", "");
                    $(".termsChk").children().attr("checked", "");
                    $(".termsAcceptBtn").attr("disabled", "true");
                }
            }
        });
    }
}