var $pc = jQuery;
var agt = navigator.userAgent.toLowerCase();
var pcj_isIe = agt.indexOf("msie") != -1;
var pcj_isIe6under = false;
if (pcj_isIe) {
    pcj_isIe6under = (agt.indexOf("msie 6") != -1 || agt.indexOf("msie 5") != -1 || agt.indexOf("msie 4") != -1)
}
var pcj_isSaf = agt.indexOf("safari") != -1;
var pcj_isFf = agt.indexOf("firefox") != -1;
var pcj_isMac = agt.indexOf("mac") != -1;
var pcj_isOpera = agt.indexOf("opera") != -1;
var pcj_pageready = false;
var pcj_dataready = false;
var pcj_processed = false;
var pcShopperId;
var pcIsTrusted;
var pcFirstName;
var pcRepName;
var pcRepExt;
var pcRepEmail;
var pcCartCt;
var pcExpDomCt;
var pcIsDiscount;

var pcj_name="Nuesion";
var pcj_pl_id="429849";
var pcj_url_fos="http://www.securepaynet.net/";
var pcj_args = "?ci=";
var pcj_prog_id = "nuesion";
var pcj_inApp = "salesweb";
var pcj_url_help="http://help.securepaynet.net/";
var pcj_url_img="https://img5.wsimg.com/";
var pcj_url_mya="https://mya.securepaynet.net/";
var pcj_login_root_url="https://idp.securepaynet.net/login.aspx?ci=9106&prog_id=nuesion&spkey=SPSWNET-CORPWEB149"
var pcj_ssoTargetKey = "target";
var pcj_isCart = false;
var pcj_cname = "ShopperId429849";
var pcj_cdomain = ".securepaynet.net";
var pcj_callov = false; var pcj_call = true;
var pcj_isMgr = false;
var pcj_idpredirect = "";
var pct_loginnameDone = false;
var pct_loginnameField;


function redirectToDomainSearch() {
        var domainNamesTextBox = jQuery('#ctl00_MainContent_ctl00_ctl00_Domain_Search_domainNames').val();
        var ddlTLDList = jQuery('#ctl00_MainContent_ctl00_ctl00_Domain_Search_ddlTLDList :selected').val();
        if (domainNamesTextBox != null && ddlTLDList != null) {
            var domainToCheck = domainNamesTextBox;
            var selectedTLD = ddlTLDList;
            if (selectedTLD) {
                var url = 'https://www.securepaynet.net/domains/search.aspx?ci=13495&prog_id=nuesion';
                if (url.indexOf("?") > 0)
                    url = url + "&";
                else
                    url = url + "?";

                location.href = url + 'domainToCheck=' + escape(domainToCheck) + '&tld=.' + escape(selectedTLD) + '&checkAvail=1&ci=12014';
            }
        }
    }



function pcj_callext(b, a) {
    $pc.ajax({
        dataType: "jsonp",
        jsonp: b,
        url: a
    })
}


var secSet = null;
var activeTimer = null;
var bHover = "";
var img = "";
var pcj_date = new Date();
var pcj_msgCt = 0;

function pcj_ralert(a) {
    if ($pc("#pcj_note").length && a) {
        pcj_msgCt = pcj_msgCt + 1;
        $pc("#pcj_note").append(pcj_msgCt + ". " + a + "<br>")
    }
}
function pcSetLogIn(b, a) {}
function pcSetLogInEx(e, d, c, a, b) {}
function pchj_setIdpRedirect(a) {
    pcj_idpredirect = a
}
function pchj_hov(a) {
    if (document.getElementById(a + "a")) {
        document.getElementById(a + "a").style.visibility = "hidden"
    } else {
        if (a == "pch_pwx") {
            document.getElementById("pch_pw_dd").className = "pchb pch_ov_ugo"
        } else {
            if (a == "pch_shx") {
                document.getElementById("pch_sh_dd").className = "pchb pch_ov_ugo"
            }
        }
    }
}
function pchj_off(a) {
    if (document.getElementById(a + "a")) {
        document.getElementById(a + "a").style.visibility = ""
    } else {
        if (a == "pch_pwx") {
            document.getElementById("pch_pw_dd").className = "pchb pch_ov_dgo"
        } else {
            if (a == "pch_shx") {
                document.getElementById("pch_sh_dd").className = "pchb pch_ov_dgo"
            }
        }
    }
}
function pcj_blurlogin(a) {
    if (a == "load") {
        if (document.getElementById("loginname").value != "") {
            document.getElementById("pch_undiv").style.display = "none"
        }
    } else {
        if (a == "over") {
            if (document.getElementById("pch_undiv").style.display == "block") {
                document.getElementById("pch_undiv").style.display = "none"
            }
        } else {
            if (document.getElementById("loginname").value == "") {
                if (document.getElementById("login_focus").value != "true") {
                    document.getElementById("pch_undiv").style.display = "block";
                    if (!pct_loginnameDone) {
                        document.getElementById("pch_login").onmousemove = ""
                    }
                }
            }
        }
    }
}
function pcj_blurpass(a) {
    if (a == "load") {
        if (document.getElementById("password").value != "") {
            document.getElementById("pch_pwdiv").style.display = "none";
            return true
        }
    } else {
        if (a == "over") {
            if (document.getElementById("pch_pwdiv").style.display == "block") {
                document.getElementById("pch_pwdiv").style.display = "none"
            }
        } else {
            if (document.getElementById("password").value == "") {
                if (document.getElementById("pass_focus").value != "true") {
                    document.getElementById("pch_pwdiv").style.display = "block";
                    pct_loginnameDone = false
                }
            }
        }
    }
}
function pcj_checkpass() {
    if (!pct_loginnameDone) {
        if (pcj_blurpass("load")) {
            pct_loginnameDone = true;
            document.getElementById("pch_login").onmousemove = ""
        }
    }
}
function pcj_passwatch() {

}
function pchj_login_action(b) {
    var c = (pcj_login_root_url);
    if (!pcj_isCart) {
        var a = (pcj_url_mya + "login_redirect.aspx");
        c += "&signalnonorig=" + encodeURIComponent(a);
        if (pcj_idpredirect != "") {
            c += "&" + pcj_ssoTargetKey + "=" + pcj_idpredirect
        }
    }
    b.action = c;
    return true
}
function pchj_login() {
    var a;
    if (document.pchFL) {
        a = document.pchFL
    } else {
        a = document.forms[0]
    }
    if (a.__VIEWSTATE) {
        a.__VIEWSTATE.name = "NOVIEWSTATE"
    }
    if (a.__EVENTTARGET) {
        a.__EVENTTARGET.name = "NOEVENTTARGET"
    }
    pchj_login_action(a);
    a.method = "POST";
    pchj_mout("pch_pw")
}
function pchj_login_submit(a) {
    a.submit()
}
function pcj_key(b, a) {
    if ((a && a.which && a.which == 13) || (a && a.keyCode && a.keyCode == 13)) {
        b
    }
}
function pchj_search(c) {
    var e;
    var a = true;
    if (document.pchFS) {
        e = document.pchFS
    } else {
        e = document.forms[0]
    }
    var b = e.pch_active_search.value;
    var d = e.elements[b + "_action"].value;
    var h = e.elements[b + "_field"].value;
    var g = e.searchField.value;
    if (e.elements[h]) {
        e.elements[h].value = g
    } else {
        e.searchField.name = h
    }
    if (b == "pch_sdomain") {
        if (!pchj_domain(g)) {
            a = false;
            e.searchField.value = ""
        }
    }
    if (b == "pch_swhois") {
        if (!pchj_whois(g)) {
            a = false;
            e.searchField.value = ""
        }
    }
    if (b == "pch_ssite") {
        if (!pchj_site(g)) {
            a = false;
            e.searchField.value = ""
        }
    }
    if (b == "pch_shelp") {
        var f = window.open(d + "&" + h + "=" + g, "_pch_help", "left=10,bottom=10,resizable=yes,scrollbars=yes,width=800,height=500");
        if (f) {
            f.focus()
        }
        document.getElementById("pch_active_text").value = "Help Center Search";
        e.searchField.value = document.getElementById("pch_active_text").value;
        e.searchField.className = "pch_t11 pch_ti pch_i_ss";
        a = false
    } else {
        e.target = "_self";
        e.method = "POST"
    }
    if (a) {
        if (e.__VIEWSTATE) {
            e.__VIEWSTATE.name = "NOVIEWSTATE"
        }
        e.action = d;
        e.submit()
    }
    return pchj_cancelEvent(c)
}
function pchj_cancelEvent(a) {
    if (!a) {
        return false
    }
    a.returnValue = false;
    a.cancelBubble = true;
    if (a.stopPropagation) {
        a.stopPropagation()
    }
    if (a.preventDefault) {
        a.preventDefault()
    }
    return false
}
function pchj_inApp_hideDDs(a) {
    pchjNav("pch_dn", a, "hide", "ov");
    pchjNav("pch_ho", a, "hide", "ov");
    pchjNav("pch_ws", a, "hide", "ov");
    pchjNav("pch_em", a, "hide", "ov");
    pchjNav("pch_sc", a, "hide", "ov");
    pchjNav("pch_bs", a, "hide", "ov")
}
function pchj_notaDD(a) {
    return false
}
function pchj_lnk(a) {
    if (a.match(pcj_url_help)) {
        window.open(a, "_pch", "left=20,top=20,resizable=yes,scrollbars=yes,width=800,height=620")
    } else {
        window.open(a, "_self")
    }
}
function pcj_win(a) {
    window.open(a, "_pct")
}
function pcj_pop(b, c, a, d) {
    window.open(b, c, "left=200,top=50,resizable=yes,scrollbars=yes,width=" + a + ",height=" + d)
}
function pchj_cartclose() {
    atlChiClose()
}
function pchj_internationalclose() {
    atlIsiClose()
}
function pchj_mout(a) {
    bHover = "";
    window.status = "";
    pchj_setDDTimeout(a)
}
function pchj_movr(b, a) {
    pcj_blurBox();
    if (pcj_isSaf) {
        bHover = a;
        window.status = a;
        pchj_setDD(b, a, false)
    } else {
        bHover = a;
        window.status = a;
        setTimeout("pchj_setDD('" + b + "', '" + a + "', false)", 400)
    }
}
function pchj_uout(a) {
    pchj_setDDTimeout(a)
}
function pchj_uovr(a) {
    pchj_setDD(a, "", true)
}
function pchj_pout(b, a) {
    window.status = "";
    pchj_setDDTimeout(b)
}
function pchj_povr(c, b, a) {
    window.status = b;
    document.getElementById(c).style.display = "";
    pchj_setDD(c, "", true)
}
function pchj_sout(c, d, a) {
    var b = document.getElementById(c).style.backgroundColor.toString();
    if ((b != "#bbb") && (b != "rgb(187, 187, 187)")) {
        document.getElementById(c).style.backgroundColor = "#fff"
    }
    window.status = "";
    pchj_setDDTimeout(d)
}
function pchj_sovr(d, e, c, b) {
    var a = document.getElementById(d).style.backgroundColor.toString();
    if ((a != "#bbb") && (a != "rgb(187, 187, 187)")) {
        document.getElementById(d).style.backgroundColor = "#eee"
    }
    window.status = c;
    pchj_setDD(e, "", true)
}
function pchj_findDiv(f, e) {
    var c, b, a;
    if (!e) {
        e = document
    }
    if ((c = f.indexOf("?")) > 0 && parent.frames.length) {
        e = parent.frames[f.substring(c + 1)].document;
        f = f.substring(0, c)
    }
    if (!(a = e[f]) && e.all) {
        a = e.all[f]
    }
    for (b = 0; !a && b < e.forms.length; b++) {
        a = e.forms[b][f]
    }
    for (b = 0; !a && e.layers && b < e.layers.length; b++) {
        a = pchj_findDiv(f, e.layers[b].document)
    }
    if (!a && document.getElementById) {
        a = document.getElementById(f)
    }
    return a
}
function pchjNav() {
    var e, a, d, b = pchjNav.arguments,
        c = 0;
    if (!((b[c] == b[c + 1]) && (b[c + 2] == "hide") && (b[c + 3] == "ov"))) {
        if ((d = pchj_findDiv(b[c])) != null) {
            a = b[c + 2];
            if (d.style) {
                d = d.style;
                a = (a == "show") ? "visible" : (a = "hide") ? "hidden" : a
            }
            d.visibility = a;
            if (a == "hidden") {
                pchj_off(b[c] + "x")
            }
            if (b[c] == "pch_sh") {
                a = (a == "visible") ? "" : (a = "hidden") ? "none" : a;
                d.display = a
            }
        }
    }
}
function pchj_hideDDs(a) {
    pchjNav("pch_pw", a, "hide", "ov");
    pchjNav("pch_sh", a, "hide", "ov");
    pchj_inApp_hideDDs(a);
    pchj_showElement("SELECT");
    pchj_showElement("OBJECT");
    pchj_showElement("EMBED")
}
function pchj_hideDD(a) {
    pchj_off(a + "x");
    pchjNav(a, "", "hide");
    pchj_hideDDs("")
}
function pchj_setDD(b, a, c) {
    pchj_hideDDs(b);
    if ((bHover == a) || (c)) {
        pchjNav(b, "", "show");
        pchj_hov(b + "x");
        if (secSet != null) {
            window.clearTimeout(secSet)
        }
        if (document.getElementById(b)) {
            if (pcj_isIe6under) {
                pchj_hideElement("SELECT", document.getElementById(b))
            }
        }
    }
}
function pchj_setDDTimeout(a) {
    if (secSet != null) {
        window.clearTimeout(secSet)
    }
    secSet = window.setTimeout('pchj_hideDD("' + a + '")', 400)
}
function pchj_hideElement(elmID, overDiv) {
    for (i = 0; i < document.getElementsByTagName(elmID).length; i++) {
        obj = document.getElementsByTagName(elmID)[i];
        if (!obj || !obj.offsetParent) {
            continue
        }
        objLeft = obj.offsetLeft - overDiv.offsetParent.offsetLeft;
        objTop = obj.offsetTop;
        objParent = obj.offsetParent;
        while ((objParent.tagName.toUpperCase() != "BODY") && (objParent.tagName.toUpperCase() != "HTML")) {
            objLeft += objParent.offsetLeft;
            objTop += objParent.offsetTop;
            objParent = objParent.offsetParent
        }
        objHeight = obj.offsetHeight;
        objWidth = obj.offsetWidth;
        if ((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft) {} else {
            if ((overDiv.offsetParent.offsetTop + overDiv.offsetHeight + 20) <= objTop) {} else {
                if (overDiv.offsetParent.offsetTop >= eval(objTop + objHeight)) {} else {
                    if (overDiv.offsetLeft >= eval(objLeft + objWidth)) {} else {
                        obj.style.visibility = "hidden"
                    }
                }
            }
        }
    }
}
function pchj_showElement(a) {
    for (i = 0; i < document.getElementsByTagName(a).length; i++) {
        obj = document.getElementsByTagName(a)[i];
        if (!obj || !obj.offsetParent) {
            continue
        }
        if (pcj_isIe && (obj.readyState == 4) && (obj.tagName.toUpperCase() == "OBJECT")) {
            continue
        }
        if ((obj.id.toLowerCase().indexOf("apollo") > 0) && (obj.tagName.toUpperCase() == "OBJECT")) {
            continue
        }
        obj.style.visibility = ""
    }
}
function pchj_key(b, c, d) {
    var a;
    if (window.event) {
        a = window.event.keyCode
    } else {
        if (c) {
            a = c.which
        }
    }
    if (a == 13) {
        pchj_search(c)
    }
}
function pchj_domain(b) {
    var a = false;
    if (b != "") {
        var c = /[^a-zA-Z0-9-\s.]+/;
        if (c.test(b)) {
            alert("Invalid character in domain.\n\nOnly letters, numbers or hyphens are allowed.")
        } else {
            a = true
        }
    } else {
        alert("Please enter a domain name.")
    }
    return a
}
function pchj_site(b) {
    var a = false;
    if ((b != "") && (b.replace(" ", "") != "Search")) {
        var c = /[^a-zA-Z0-9-\s."']+/;
        if (c.test(b)) {
            alert("Invalid characters in search.")
        } else {
            a = true
        }
    } else {
        alert("Please enter a search term.")
    }
    return a
}



function pcj_blurBox() {
    if (!pcj_isFf) {
        $pc("input[id*='domain']").blur()
    }
}

$pc(document).ready(function () {
    pcj_pageready = true;
    if (pcj_dataready && !pcj_processed) {
        pcj_setPage()
    }
    if (pcj_inApp != "parkweb") {
        $pc("#" + $pc("#pch_active_search").val()).css("backgroundColor", "#bbb");
        $pc("#searchField").val($pc("#pch_active_text").val())
    }
    if ((pcj_isIe || pcj_isFf) && ($pc("#bookLnk").length)) {
        $pc("#bookLnk").show();
        $pc("#pcf_bookmark").css("cursor", "pointer").click(function () {
            pcj_bookmark()
        }).hover(function () {
            $pc(this).addClass("pch_tu")
        }, function () {
            $pc(this).removeClass("pch_tu")
        })
    }

});
