﻿// JScript File
var XmlHttp = null;

function CreateXmlHttp() {
    //Creating object of XMLHTTP in IE
    try {
        XmlHttp = null;
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (o) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }
}

function CheckSubscriptionOption() {
    var elem = document.getElementById("aspnetForm").elements;
    var flag = false;
    for (var i = 0; i < elem.length; i++) {
        if (elem[i].type == "radio") {
            if (elem[i].checked) {
                flag = true;
            }
        }
    }
    if (flag == false) {
        alert('Please Choose one subscription option');
    }
    return flag;
}
function abc(dropdown, txtbox) {
    var spandd = document.getElementById('spanddl');
    var spantxt = document.getElementById('spantb');
    var ddl = document.getElementById(dropdown);
    var txt = document.getElementById(txtbox);
    alert(spandd);
    alert(spantxt);
    alert(ddl);
    alert(txt);
    if (ddl.value == '1') {
        spandd.style.visibility = "hidden";
        spantxt.style.visibility = "visible";
    }
    else {
        spandd.style.visibility = "visible";
        spantxt.style.visibility = "hidden";
    }
}
function ShowHearSubOptions(DLL, pLblOption, pTxtOptionValue, pDDLSearchEngine) {
    var ddlHear = document.getElementById(DLL);
    var SelectedValue = ddlHear.value;
    var TR = document.getElementById("TRHearOptions");
    var LblOption = document.getElementById(pLblOption);
    var TxtOptionValue = document.getElementById(pTxtOptionValue);
    var DDLSearchEngine = document.getElementById(pDDLSearchEngine);
    HideCtr(TxtOptionValue);
    HideCtr(DDLSearchEngine);

    TR.style.visibility = "visible";
    TR.style.display = "block";
    if (SelectedValue == 0) {
        TR.style.visibility = "hidden";
        TR.style.display = "none";
    }
    else if (SelectedValue == 1) {
        LblOption.innerHTML = "Article Source";
        ShowCtr(TxtOptionValue);
    }
    else if (SelectedValue == 2) {
        LblOption.innerHTML = "Please Select";
        ShowCtr(DDLSearchEngine);
    }
    else if (SelectedValue == 3) {
        LblOption.innerHTML = "Referral Name";
        ShowCtr(TxtOptionValue);
    }
    else if (SelectedValue == 4) {
        LblOption.innerHTML = "Directory Name";
        ShowCtr(TxtOptionValue);
    }
    else if (SelectedValue == 99) {
        LblOption.innerHTML = "Please Specify";
        ShowCtr(TxtOptionValue);
    }
}

function HideCtr(Ctr) {
    Ctr.style.visibility = "hidden";
    Ctr.style.display = "none";
}
function ShowCtr(Ctr) {
    Ctr.style.visibility = "visible";
    Ctr.style.display = "block";
}


function getemployeename(txtLogin) {
    var LoginName = null;
    //alert(txtLogin.type);
    if (txtLogin.type == "text") {
        LoginName = txtLogin;
    }
    else {
        LoginName = document.getElementById(txtLogin);
    }
    if (LoginName.value.length > 0) {
        var requestUrl = "reghndl.aspx?CheckUserExist=" + LoginName.value;
        CreateXmlHttp();
        if (XmlHttp) {
            XmlHttp.onreadystatechange = HandleCheckUserExist;
            XmlHttp.open("GET", requestUrl, true);
            XmlHttp.send('');
        }
    }
    else {
        document.getElementById("SpanLoginName").innerHTML = "Required";
    }
}
function HandleCheckUserExist() {
    if (XmlHttp.readyState == 4) {
        if (XmlHttp.status == 200) {
            var a = document.getElementById("SpanLoginName");
            var response = XmlHttp.responseText;
            var arr = response.split(";");

            if (arr[1] == "true") {
                if (arr[0].length > 0) {
                    a.innerHTML = arr[0] + " is not available";
                }
                else {
                    a.innerHTML = "Required";
                }
            }
            else {
                if (arr[0].length > 0) {
                    a.innerHTML = arr[0] + " is available";
                }
                else {
                    a.innerHTML = "";
                }
            }
        }
    }

}

function getemail(txtEmail) {
    var email = document.getElementById(txtEmail);
    if (ValidateEmailAddress(email, "emailStatus")) {
        var requestUrl = "reghndl.aspx?EmailExist=" + email.value;
        CreateXmlHttp();
        if (XmlHttp) {
            XmlHttp.onreadystatechange = HandleCheckEmailExist;
            XmlHttp.open("GET", requestUrl, true);
            XmlHttp.send('');
        }
    }
}
function HandleCheckEmailExist() {
    if (XmlHttp.readyState == 4) {
        if (XmlHttp.status == 200) {
            var a = document.getElementById("emailStatus");
            var response = XmlHttp.responseText;
            var arr = response.split(";");

            if (arr[1] == "true") {
                if (arr[0].length > 0) {
                    a.innerHTML = "E-mail already exists";
                }
            }
            /*else
            {
            a.innerHTML = "";
            }*/
        }
    }
}

function getConfirmEmail(confirmEmail, email) {
    var ConfEmail = document.getElementById(confirmEmail).value;
    var EmailCompWith = document.getElementById(email).value;
    document.getElementById("emailStatus1").innerHTML = "";
    if (ConfEmail != EmailCompWith) {
        document.getElementById("emailStatus1").innerHTML = "Email do not match";
    }
}
function getgroupid(txtGroupID) {
    var groupid = document.getElementById(txtGroupID);
    var requestUrl = "reghndl.aspx?GroupUserExist=" + groupid.value;

    CreateXmlHttp();
    if (XmlHttp) {
        XmlHttp.onreadystatechange = HandleGroupIDExist;
        XmlHttp.open("GET", requestUrl, true);
        XmlHttp.send('');
    }
}
function HandleGroupIDExist() {
    if (XmlHttp.readyState == 4) {
        if (XmlHttp.status == 200) {
            var spanGrpID = document.getElementById("SpanGroupID");
            var param = XmlHttp.responseText;

            if (param == 0) {
                spanGrpID.innerHTML = "No License Left for this GroupID";
            }
            else if (param == 1) {
                spanGrpID.innerHTML = "GroupID is valid";
            }
            else if (param == 2) {
                spanGrpID.innerHTML = "Ask the GroupID owner to update number of Licenses";
            }
            else if (param == 3) {
                spanGrpID.innerHTML = "GroupID is not valid";
            }
        }
    }
}

function RegistrationValidation1(txtLoginName, txtfname, txtpass, txtpass2, txtemail, txtConfirmEmail, chkAgreeBox, trGroupUserID, txtGroupUserID) {
    var s = document.getElementById("SpanLoginName").innerHTML;
    if (s.indexOf("not") > "-1") {
        return false;
    }
    var s1 = document.getElementById("emailStatus").innerHTML;
    if ((s1.indexOf("already") > "-1") || (s1.indexOf("Not Valid") > "-1")) {
        return false;
    }
    var obj8 = document.getElementById(txtLoginName);
    var obj7 = document.getElementById(txtfname);
    var obc1 = document.getElementById(txtpass);
    var objp1 = document.getElementById(txtpass);
    var objp2 = document.getElementById(txtpass2);
    var flag = true;

    if (IsEmpty(obj8, "SpanLoginName") == false) {
        flag = false;
    }
    if (checkFirstPassword(obc1, "firstPasswordStatus") == false) {
        flag = false;
    }
    if (checkPassword1(txtpass2, txtpass, "firstPasswordStatus", "passwordStatus") == false) {
        flag = false;
    }
    if (IsEmpty(obj7, "SpanfName") == false) {
        flag = false
    }
    if (ValidateEmailAddress(document.getElementById(txtemail), "emailStatus") == false) {
        flag = false;
    }
    var ConfEmail = document.getElementById(txtemail).value;
    var EmailCompWith = document.getElementById(txtConfirmEmail).value;
    if (ConfEmail != EmailCompWith) {
        document.getElementById("emailStatus1").innerHTML = "Email do not match";
        flag = false;
    }
    else {
        document.getElementById("emailStatus1").innerHTML = "";
    }

    if (document.getElementById(chkAgreeBox).checked == false) {
        alert("Please confirm Terms of Use");
        flag = false;
    }

    var trGroupUserID = document.getElementById(trGroupUserID);

    var txtGroupUserID = document.getElementById(txtGroupUserID);
    if (txtGroupUserID != null && txtGroupUserID.value == "") {
        document.getElementById("SpanGroupID").innerHTML = "Required.";
        flag = false;
    }


    return flag;
}

/********************************************************************/
function RegistrationValidation2(txtLoginName, txtfname, txtlname, txtpass, txtpass2, txtemail, txtConfirmEmail, chkAgreeBox) {
    var s = document.getElementById("SpanLoginName").innerHTML;
    if (s.indexOf("not") > "-1") {
        return false;
    }
    var s1 = document.getElementById("emailStatus").innerHTML;
    if ((s1.indexOf("already") > "-1") || (s1.indexOf("Not Valid") > "-1")) {
        return false;
    }
    var obj8 = document.getElementById(txtLoginName);
    var obj7 = document.getElementById(txtfname);
    var obj9 = document.getElementById(txtlname);
    var obc1 = document.getElementById(txtpass);
    var objp1 = document.getElementById(txtpass);
    var objp2 = document.getElementById(txtpass2);
    var flag = true;

    if (IsEmpty(obj8, "SpanLoginName") == false) {
        flag = false;
    }
    if (checkFirstPassword(obc1, "firstPasswordStatus") == false) {
        flag = false;
    }
    if (checkPassword1(txtpass2, txtpass, "firstPasswordStatus", "passwordStatus") == false) {
        flag = false;
    }
    if (IsEmpty(obj7, "SpanfName") == false) {
        flag = false;
    }
    if (IsEmpty(obj9, "SpanlName") == false) {
        flag = false;
    }
    if (ValidateEmailAddress(document.getElementById(txtemail), "emailStatus") == false) {
        flag = false;
    }
    var ConfEmail = document.getElementById(txtemail).value;
    var EmailCompWith = document.getElementById(txtConfirmEmail).value;
    if (ConfEmail != EmailCompWith) {
        document.getElementById("emailStatus1").innerHTML = "Email do not match";
        flag = false;
    }
    else {
        document.getElementById("emailStatus1").innerHTML = "";
    }
    if (document.getElementById(chkAgreeBox).checked == false) {
        alert("Please confirm Terms of Use");
        flag = false;
    }
    return flag;
}
/***************************************************************************/
function checkPassword1(em0, em2, id1, id2) {
    var em = document.getElementById(em2);
    var em1 = document.getElementById(em0);
    checkFirstPassword(em, id1);
    var obj1 = document.getElementById(id1);
    var obj3 = document.getElementById(id2);
    if (em1.value.trim().length == 0) {
        setErrorColor(em1);
        setError(obj3, "Required");
        return false;
    }
    else {

        if (em1.value.trim().length < 5) {
            setErrorColor(em1);
            setError(obj3, "Minimum is 5 characters");
            return false;
        }
    }
    if (em.value == em1.value) {
        setSuccessColor(em);
        setSuccessColor(em1);
        setSuccess(obj1);
        setSuccess(obj3);
        return true;
    }
    else {
        setErrorColor(em);
        setError(obj3, "Passwords do not match");
        return false;
    }
}
function selectState(ddlstate, divstate) {
    var ddl = document.getElementById(ddlstate);
    var div = document.getElementById(divstate);
    var span = document.getElementById("SpanState");
    if (ddl.value == "0") {
        span.innerHTML = "Required";
        div.style.visibility = "hidden";
        div.style.display = "none";
    }
    else if (ddl.value == "Other") {
        div.style.visibility = "visible";
        div.style.display = "block";
        span.innerHTML = "";
    }
    else {
        div.style.visibility = "hidden";
        div.style.display = "none";
        span.innerHTML = "";
    }
}

function selectCountry(ddl, divstate) {
    var div = document.getElementById(divstate);

    if (ddl.value == "0") {
        div.innerHTML = "Required";
    }
    else {
        div.innerHTML = "";
    }
}
function selectCreditCardType(ddl, divCCType) {
    var div = document.getElementById(divCCType);

    if (ddl.value == "0") {
        div.innerHTML = "Required";
    }
    else {
        div.innerHTML = "";
    }
}
function BuyValidation(ptxtfname, ptxtlname, ptxtaddress1, ptxtcity, ptxtstate, pddlstate, ptxtzip, pddlcountry, ptxtphone, pddlCardType, ptxt_CreditcardNo, ptxt_CardVerificationNo, ptrLicenseForUser, ptxt_LicenseForUser, pddExpiryMonth, pddExpiryYear) {

    var txtFirstName = document.getElementById(ptxtfname);
    var txtLastName = document.getElementById(ptxtlname);
    var txtaddress1 = document.getElementById(ptxtaddress1);
    var txtCity = document.getElementById(ptxtcity);
    var txtState = document.getElementById(ptxtstate);
    var ddlState = document.getElementById(pddlstate);
    var txtZip = document.getElementById(ptxtzip);
    var ddlCountry = document.getElementById(pddlcountry);
    var txtphone = document.getElementById(ptxtphone);
    var ddlCCType = document.getElementById(pddlCardType);
    var txt_CreditcardNo = document.getElementById(ptxt_CreditcardNo);
    var txt_CardVerificationNo = document.getElementById(ptxt_CardVerificationNo);
    var ddlExpMonth = document.getElementById(pddExpiryMonth);
    var ddlExpYear = document.getElementById(pddExpiryYear);

    var Status = true;
    if (!IsEmpty(txtFirstName, "SpanFName")) {
        Status = false;
    }
    if (!IsEmpty(txtLastName, "SpanLName")) {
        Status = false;
    }
    if (!IsEmpty(txtaddress1, "SpanAddress")) {
        Status = false;
    }
    if (!IsEmpty(txtCity, "SpanCity")) {
        Status = false;
    }

    var divProvince = document.getElementById("divState");
    if (ddlState.value == "0") {
        var span = document.getElementById("SpanState");
        span.innerHTML = "Required";
        Status = false;
    }
    else if (ddlState.value == "Other") {
        divProvince.style.visibility = "visible";
        divProvince.style.display = "block";
        if (!IsEmpty(txtState, "SpanProvince")) {
            Status = false;
        }
    }
    else {
        divProvince.style.visibility = "hidden";
        divProvince.style.display = "none";
    }
    if (!IsEmpty(txtZip, "SpanZip")) {
        Status = false;
    }

    if (ddlCountry.value == "0") {
        var spanCnt = document.getElementById("SpanCountry");
        spanCnt.innerHTML = "Required";
        Status = false;
    }

    if (!IsEmpty(txtphone, "SpanPhone")) {
        Status = false;
    }

    if (ddlCCType.value == "0") {
        var spanCCType = document.getElementById("SpanCardType");
        spanCCType.innerHTML = "Required";
        Status = false;
    }

    if (!OnlyNumeric(txt_CardVerificationNo, "NumericStatusCCno")) {
        Status = false;
    }

    if (!OnlyNumeric(txt_CreditcardNo, "NumericStatusCCvno")) {
        Status = false;
    }
    var expDate = new Date();
    var spanExpireDate = document.getElementById("SpanExpDate");

    if (parseInt(ddlExpYear.value) == parseInt(expDate.getFullYear())) {
        if (parseInt(ddlExpMonth.value) <= parseInt(expDate.getMonth())) {
            Status = false;
            spanExpireDate.innerHTML = "Expiration Date is not valid";
        }
        else {
            spanExpireDate.innerHTML = "";
        }
    }
    else {
        spanExpireDate.innerHTML = "";
    }


    var trLicenseForUser = document.getElementById(ptrLicenseForUser);
    if (trLicenseForUser != null) {
        if (trLicenseForUser.style.display == "block") {
            var txtbox = document.getElementById(ptxt_LicenseForUser);
            if (txtbox != null && txtbox.value == "") {
                Status = false;
                alert("Please enter valid number of licenses");
            }
        }
    }
    return Status;
}

function getDescription(val) {
    var div = document.getElementById("SubscriberDetails");

    if (val == "Monthly") {
        div.innerHTML = "<strong>Month-to-Month Plan:</strong>  Purchase a PhoneSheet account at the price of $12.95 per month, billed to your credit card in advance of each month of service.  Billing continues monthly unless canceled by subscriber.";
    }
    else if (val == "Promotional") {
        div.innerHTML = "<strong>6-Month Subscription:</strong> Subscribers will be billed $59.70 in advance for six continuous " +
                        " months of <em>PhoneSheet</em> service. Subscribers may cancel their accounts at any time" +
                        " without penalty. Prior to the end of the six months of services, subscribers will" +
                        " be given the option to either cancel their accounts" +
                        " or be automatically rolled over into the another 6-Month subscription.";
    }
    else if (val == "FreeTrial") {
        div.innerHTML = "<strong>30-Day Free Trial:</strong>  Try out a PhoneSheet account for 30-days free of charge. At the end of 30 days, you can either cancel your subscription or be automatically rolled over into the Month-to-Month plan. A credit card authorization is required to activate your free trial.";
    }
    else if (val == "PS2GO") {
        div.innerHTML = "<strong> PhoneSheet2Go </strong> - only subscribers will be billed $3.95 per month, in advance of each month of service.   Subscribers may cancel accounts at any time without penalty.";
    }
}

function showDiv(divLogInfo, divCusLog) {
    var divLog = document.getElementById(divLogInfo);
    var divCus = document.getElementById(divCusLog);
    divCus.style.display = "none";
    divLog.style.display = "block";
    return false;
}

function LoginCheck(txtUN, txtUP) {
    var Status = true;
    var txtUName = document.getElementById(txtUN);
    var txtPass = document.getElementById(txtUP);
    if (!IsEmpty(txtUName, "SpanUName")) {
        Status = false;
    }
    if (!IsEmpty(txtPass, "SpanPass")) {
        Status = false;
    }
    return Status;
}


// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

var popbackground = "lightskyblue" //specify backcolor or background image for pop window
var windowtitle = "Image Window"  //pop window title

function detectexist(obj) {
    return (typeof obj != "undefined")
}

function jkpopimage(imgpath, popwidth, popheight, textdescription) {
    function getpos() {
        leftpos = (detectexist(window.screenLeft)) ? screenLeft + document.body.clientWidth / 2 - popwidth / 2 : detectexist(window.screenX) ? screenX + innerWidth / 2 - popwidth / 2 : 0
        toppos = (detectexist(window.screenTop)) ? screenTop + document.body.clientHeight / 2 - popheight / 2 : detectexist(window.screenY) ? screenY + innerHeight / 2 - popheight / 2 : 0
        if (window.opera) {
            leftpos -= screenLeft
            toppos -= screenTop
        }
    }

    getpos()
    var winattributes = 'width=' + popwidth + ',height=' + popheight + ',resizable=yes,left=' + leftpos + ',top=' + toppos
    var bodyattribute = (popbackground.indexOf(".") != -1) ? 'background="' + popbackground + '"' : 'bgcolor="' + popbackground + '"'
    if (typeof jkpopwin == "undefined" || jkpopwin.closed)
        jkpopwin = window.open("", "", winattributes)
    else {
        //getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
        //jkpopwin.moveTo(leftpos, toppos)
        jkpopwin.resizeTo(popwidth, popheight + 50)
    }
    jkpopwin.document.open()
    jkpopwin.document.write('<html><title>' + windowtitle + '</title><body ' + bodyattribute + '><img src="' + imgpath + '" style="margin-bottom: 0.5em"><br />' + textdescription + '</body></html>')
    jkpopwin.document.close()
    jkpopwin.focus()
}



