﻿//forgot password --> vali
var ErrMsg = "";
var ErrMsg1 = "";
var SubmitS = {"AjaxS":false, "ButtomS":false};
$(function(){
    $("#ctl00_ContentPlaceHolder1_ForgotEmail").focus(function(){
        theValue = "N";
        SubmitS.AjaxS = false;
        SubmitS.ButtomS = false;
    });
    $("#ctl00_ContentPlaceHolder1_LoginEmail").focus(function(){
        SubmitS.AjaxS = false;
        SubmitS.ButtomS = false;
    });
    $("#ctl00_ContentPlaceHolder1_ImageButton1").click(function(){
        SubmitS.ButtomS = true;
    });
    $("#ctl00_ContentPlaceHolder1_LoginB").click(function(){
        SubmitS.ButtomS = true;
    });
})
function Forgot_Client(oSrc, args)
{
    var temp;
    $(".vali").css("color","#000000");
    $("input[@type!=image]").attr("style","");
    ErrMsg = ""
    $("#ctl00_ContentPlaceHolder1_ForgotErr").html("");
    for (var i = 0; i < Page_Validators.length; i++)
    {
        if (Page_Validators[i].validationGroup == "Forgot" && Page_Validators[i].controltovalidate != undefined)
        {
            temp = Page_Validators[i].controltovalidate;
            temp = temp.replace("ctl00_ContentPlaceHolder1_","f");
             if(!Page_Validators[i].isvalid)
             {
                 $("#"+temp).css("color","#C82D4B");
                 ErrMsg = Page_Validators[i].errormessage;
                 $("#"+Page_Validators[i].controltovalidate).attr("style","border-color:#C82D4B");
             }
        }
        $("#ctl00_ContentPlaceHolder1_ForgotErr").html(ErrMsg);
    }
}
$(function(){
    $("#ctl00_ContentPlaceHolder1_ForgotEmail").blur(function(){
        if(SubmitS.ButtomS && SubmitS.AjaxS)
        {
            $("#ctl00_ContentPlaceHolder1_ImageButton1").click();
        }
    });
    $("#ctl00_ContentPlaceHolder1_LoginEmail").blur(function(){
        if(SubmitS.ButtomS && SubmitS.AjaxS)
        {
            $("#ctl00_ContentPlaceHolder1_LoginB").click();
        }
    })
})

// check the email is exist
function EmailCheck_2(oSrc, args)
{
   var myreg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   $("#ctl00_ContentPlaceHolder1_ForgotErr").html("");
   if(myreg.test(args.Value) && !SubmitS.AjaxS)
   {
       var mydate = new Date().toLocaleString();
       $.get("common/CheckEmail.ashx?UserEmail="+args.Value+"&date="+mydate, function(data){
            if(data == "Y")
            {
                SubmitS.AjaxS = true;
                if(SubmitS.ButtomS)
                {
                    $("#ctl00_ContentPlaceHolder1_ImageButton1").click();
                }
            }
            else
            {
                SubmitS.AjaxS = false;
                $("#ctl00_ContentPlaceHolder1_ForgotErr").html("Your e-mail address is not on file.");
                $("#ctl00_ContentPlaceHolder1_ForgotEmail").attr("style","border-color:#C82D4B");
                $("#fForgotEmail").css("color","#C82D4B");
            }
       });
       if(SubmitS.AjaxS)
       {
            args.IsValid  = true;
       }
       else
       {
            args.IsValid  = false;
       }
   }
   
}


//login --> vali
function Login_Client(oSrc, args)
{
    var temp;
    $(".vali").css("color","#000000");
    $("input[@type!=image]").attr("style","");
    $("#ctl00_ContentPlaceHolder1_LoginErr").html("");
    $("#ctl00_ContentPlaceHolder1_LoginErr1").html("");
    ErrMsg = "";
    ErrMsg1 = "";
    for (var i = 0; i < Page_Validators.length; i++)
    {
        if (Page_Validators[i].validationGroup == "Login" && Page_Validators[i].controltovalidate != undefined)
        {
            temp = Page_Validators[i].controltovalidate;
            temp = temp.replace("ctl00_ContentPlaceHolder1_","f");
            
            if(!Page_Validators[i].isvalid)
            {
                 $("#"+temp).css("color","#C82D4B");
                 $("#"+Page_Validators[i].controltovalidate).attr("style","border-color:#C82D4B");
                 if(temp == "fLoginEmail")
                 {
                        ErrMsg = Page_Validators[i].errormessage;
                 }
                 else
                 {
                        ErrMsg1 = Page_Validators[i].errormessage;
                 }
            }
        }
    }
    $("#ctl00_ContentPlaceHolder1_LoginErr").html(ErrMsg);
    $("#ctl00_ContentPlaceHolder1_LoginErr1").html(ErrMsg1);
}

// check the email is exist
function EmailCheck_1(oSrc, args)
{
   var myreg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    $("#ctl00_ContentPlaceHolder1_LoginErr").html("");
   if(myreg.test(args.Value) && !SubmitS.AjaxS)
   {
       var mydate = new Date().toLocaleString();
       $.get("common/CheckEmail.ashx?UserEmail="+args.Value+"&date="+mydate, function(data){
            if(data == "Y")
            {
                $("#ctl00_ContentPlaceHolder1_LoginEmail").attr("style","");
                $("#fLoginEmail").css("color","#333333");
                $("#ctl00_ContentPlaceHolder1_LoginErr").html("");
                SubmitS.AjaxS = true;
                if(SubmitS.ButtomS)
                {
                    $("#ctl00_ContentPlaceHolder1_LoginB").click();
                }
            }
            else
            {
                SubmitS.AjaxS = false;
                $("#ctl00_ContentPlaceHolder1_LoginEmail").attr("style","border-color:#C82D4B");
                $("#fLoginEmail").css("color","#C82D4B");
                $("#ctl00_ContentPlaceHolder1_LoginErr").html("Your e-mail address is not on file.");
            }
       });
       if(SubmitS.AjaxS)
       {
            args.IsValid  = true;
       }
       else
       {
            args.IsValid  = false;
       }
   }
   
}
