﻿var displayLogin = 0;
function CheckSignJoinUpButton() {


    var lbl = document.getElementById('errLable');
    if (lbl.innerHTML == "Please check your email and password.") {
        // this is login error we need to display login div
        if (displayLogin == 0) {
            toggle();
            displayLogin++;
        }
       
    }
    else {


        var btLogin = document.getElementById('ibtJoin');

        var btLogindisabled = checkEmail() && checkPassword() && checkAgreement();
        //alert("userName:"+checkUserName() +" Email:"+ checkEmail() +" Password:"+ checkPassword() +" Agrrement:"+ checkAgreement());

        if (btLogindisabled) {
            btLogin.src = 'images/Landing/Homepage_DealsSignUpSection_btn_Join.png';
            btLogin.style.cursor = 'pointer';
            btLogin.disabled = false;
        }
        if (!btLogindisabled) {
            btLogin.src = 'images/Landing/Homepage_DealsSignUpSection_btn_Join_hl.png';
            btLogin.style.cursor = 'default';
            if (!btLogin.disabled)
                btLogin.disabled = true;


        }
    }
}

function checkUserName() {
    var txt = document.getElementById('exbUserName');
    return txt.value.length > 0 && txt.value != "Choose Username";
}

function checkEmail() {
    var txt = document.getElementById('txbEmail');
    return isEmailAddr(txt.value);
    }

function checkTheEmail() {
    var txt = document.getElementById('txbEmail');
    var lbl = document.getElementById('errLable');
    if (txt.value == "") return false;
    if (isEmailAddr(txt.value)) {
        txt.style.color = '';
        lbl.innerHTML = '';
        lbl.style.display = "none";
        return true;
    }
    else {
        txt.style.color = "red";
        lbl.innerHTML = "Check your Email.";
        lbl.style.display = "block";
        return false;

    }
}

function checkPassword() {
    var txt = document.getElementById('txJPassword');
    return txt.value.length > 5;
}

function checkAgreement() {
    var cb = document.getElementById('cbAgree');
    return cb.checked==1;
}

function checkErrorLable() {
     var lbl=document.getElementById('errLable');
     if (lbl.innerText == "Account already exists.") {
         
         lbl.innerHTML = '';
         lbl.style.display = "none";
     }
     else {
         lbl.innerHTML = '';
         lbl.style.display = "block";
     }

 }

 function PasswordWaterMark() {
     $("#txtPlainPassword").show();
     $("#txJPassword").hide();
     $("#txtPlainPassword").focus(function () {
         $(this).hide();
         $("#txJPassword").show();
         $("#txJPassword").focus();
     });

     $("#txJPassword").blur(function () {

         if ($(this).val().length == 0) {
             $(this).hide();
             $("#txtPlainPassword").show();
         }
     });

 }


 function PasswordLoginWaterMark() {
     $("#txtLoginPlainPassword").show();
     $("#txbPassword").hide();
     $("#txtLoginPlainPassword").focus(function () {
         $(this).hide();
         $("#txbPassword").show();
         $("#txbPassword").focus();
     });

     $("#txbPassword").blur(function () {

         if ($(this).val().length == 0) {
             $(this).hide();
             $("#txtLoginPlainPassword").show();
         }
     });

 }


 function PasswordLightBoxWaterMark() {

     $("#txtLightboxLoginPlainPassword").focus(function () {
         $(this).hide();
         $("#txbLightboxPassword").show();
         $("#txbLightboxPassword").focus();
     });

     $("#txbLightboxPassword").blur(function () {

         if ($(this).val().length == 0) {
             $(this).hide();
             $("#txtLightboxLoginPlainPassword").show();
         }
     });

     $("#txtLightboxPlainPassword").focus(function () {
         $(this).hide();
         $("#txJLightboxPassword").show();
         $("#txJLightboxPassword").focus();
     });

     $("#txJLightboxPassword").blur(function () {

         if ($(this).val().length == 0) {
             $(this).hide();
             $("#txtLightboxPlainPassword").show();
         }
     });

     $("#txtLightboxFBPlainPassword").focus(function () {
         $(this).hide();
         $("#facebookPassword").show();
         $("#facebookPassword").focus();
     });

     $("#facebookPassword").blur(function () {

         if ($(this).val().length == 0) {
             $(this).hide();
             $("#txtLightboxFBPlainPassword").show();
         }
     });

 }

function isEmailAddr(EMailAddr) {
    var EmailAddressRX = /^(.+)@(.+)\.(.+)$/;  // Check for pattern string.string

    var matches = EMailAddr.match(EmailAddressRX);
    if (matches == null) // IT'S BAD TO THE BONE.
        return false;
    if (EMailAddr.indexOf("<") !=-1 || EMailAddr.indexOf(">") !=-1 )
        return false;
    // MORE CHECKING MAY BE REQUIRED -
    return true;
}


function toggle() {

   
    var dvLogin = document.getElementById("dvLogin");
    var dvJoin = document.getElementById("dvJoin");
    var toggle = document.getElementById("toggle");
    if (dvJoin.style.display == "block") {
        dvJoin.style.display = "none";
        dvLogin.style.display = "block";
        toggle.innerHTML = "Sign Up";
    }
    else {
        dvJoin.style.display = "block";
        dvLogin.style.display = "none";
        toggle.innerHTML = "Login";
    }
}

function ClearLable() {

    document.getElementById('errLable').innerHTML = '';
}

function checkLoginEmail() {
    var txt = document.getElementById('txbLogin');
    var lbl = document.getElementById('errLable');
    if (txt.value == "") return false;
    if (isEmailAddr(txt.value)) {
        txt.style.color = '';
        lbl.innerHTML = '';
        lbl.style.display = "none";
        return true;
    }
    else {
        txt.style.color = "red";
        lbl.innerHTML = "Check your Email.";
        lbl.style.display = "block";
        return false;

    }
}
