﻿$(document).ready(function(){
    if($.cookie("CustomerEmail"))
    {
        $("#EmailName").val($.cookie("CustomerEmail"));
    }
    if($.cookie("CustomerPsd"))
    {
        $("#Psd").val($.cookie("CustomerPsd"));
    }
});

function JoinNow(){
    location.href = "JoinUs.aspx";
}

function CancelSubmit(){
    $("#BackgroundDiv").fadeOut("fast");
    $("#ErrorMessage").fadeOut("fast");
    $("#EmailName").focus();
}

function LoginSubmit(){
    if($("#EmailName").val() == ""){
        alert("Email is empty!");
        $("#EmailName").focus();
        return;
    }
    if(!EmailValider($("#EmailName").val()))
    {
        alert("Please enter a valid email.");
        $("#EmailName").focus();
        return;
    }
    if( $("#Psd").val() == ""){
        alert("Password is empty!");
        $("#Psd").focus();
        return;
    }
    ShowBackground();
    $.get($("#HomeLink").val() + "/Ajax/ProcessLogin.ashx", { IsRemember: $("#RememberBox").attr("checked"), ReturnUrl: GetQueryStringRegExp("ReturnUrl"), Password: $("#Psd").val(), Email: $("#EmailName").val(), time: (new Date()).getTime() }, function(data) {
        if(data == "true"){
            $("#CustomerLogin").html("Welcome! <span style=\"color:#E3D11E;\">" + $("#EmailName").val() + "</span>, <a href=\"javascript:void(null);\" onclick=\"javascript:SignOut();\" style=\"text-decoration:none;\">Sign Out!</a>");
            $("#HaveLoginEmail").html($("#EmailName").val());
            RemoveBackground();
            $("#SignInForm").fadeOut("fast");
            $("#SuccessContent").fadeIn("fast");
            $("#SuccessTitle").fadeIn("fast");
            pageTracker._trackPageview("/JoinUs/LoginSuccess.aspx");
        }else if(data == "false"){
            alert("Login failed.Please check your email and password and try again.");
            RemoveBackground();
            pageTracker._trackPageview("/JoinUs/LoginError.aspx");
        }else{
            location.href = ".." + data;
        }
    });
}

function GotoHome(){
    location.href = $("#HomeLink").val();
}

function GotoMyAccount(){
    location.href = $("#HomeLink").val() + "/Secure/MyAccount.aspx";
}

//自动提交登陆
function FilterEnter(){
    if ( window.event.keyCode == 13){
        LoginSubmit();
    }
}