﻿$(function() {
    $('#txtMail').focus();
    history.forward(); 
});

function changeKeyCode1(e) {
    if ($.browser.mozilla) {
        if (e.which == 13) {
            $('#txtPWD').focus();
        }
    }
    else if ($.browser.msie) {
        if (e.keyCode == 13) {
            $('#txtPWD').focus();
        }
    }
    else if ($.browser.safari) {
        if (e.keyCode == 13) {
            $('#txtPWD').focus();
        }
    }
    else if ($.browser.opera) {
        if (e.keyCode == 13) {
            $('#txtPWD').focus();
        }
    }
}
function changeKeyCode2(e) {
    if ($.browser.mozilla) {
        if (e.which == 13) {
            userLogin();
        }
    }
    else if ($.browser.msie) {
        if (e.keyCode == 13) {
            userLogin();
        }
    }
    else if ($.browser.safari) {
        if (e.keyCode == 13) {
            userLogin();
        }
    }
    else if ($.browser.opera) {
        if (e.keyCode == 13) {
            userLogin();
        }
    }
}

function btnChangPwd(e) {
    if ($.browser.mozilla) {
        if (e.which == 13) {
            changePWD();
        }
    }
    else if ($.browser.msie) { 
        if (e.keyCode == 13) {
            changePWD();
        }
    }
    else if ($.browser.safari) {
        if (e.keyCode == 13) {
            changePWD();
        }
    }
    else if ($.browser.opera) {
        if (e.keyCode == 13) {
            changePWD();
        }
    }
}

function checkUser() {
    login.CheckEmail($('#registerMail').val(), function(res) {
        if (res.value == 0) {
            showTips("无效的注册邮件");
            return;
        }
        else {
            login.sendMail($('#registerMail').val(), function(res1) {
                if (res.value) {
                    $('.forgetPWD #conBody1').addClass('hide');
                    $('.forgetPWD #conBody2').removeClass('hide');
                    showTips("请留意您的邮箱");
                }
                else {
                    showTips("请等待");
                }
            });
        }
    });
}

function changePWD() {
    if ($.trim($('#newPWD1').val()) == "") {
        showTips("新密码不能为空");
        return;
    }
    if ($.trim($('#newPWD1').val()).length > 16 || $.trim($('#newPWD1').val()).length < 6) {
        showTips("密码长度不能小于6位或者大于16位");
        return;
    }
    if ($('#newPWD1').val() != $('#newPWD2').val()) {
        showTips("确认密码与新密码不相同");
        return;
    }
    login.changePWD($('#newPWD1').val(), $('#HiddenField1').val(), function(res) {
        if (res.value) {
            showTips("修改成功");
            document.location = "login.aspx";
        }
        else {
            showTips("修改失败");
        }
    });
}

function userLogin() {
    login.userLogin($.trim($('#txtMail').val()), $.trim($('#txtPWD').val()), $('#rememberPWD').get(0).checked, function(res) {
        if (res.value == "请先激活用户") {
            showTips("请先激活用户");
        }
        else if (res.value == "用户名或密码不正确") {
            $('#txtMail').attr("class", "input inputErr w200");
            $('#txtPWD').attr("class", "input inputErr w200");
            $('#txtPWD').focus();
            showTips("用户名或密码不正确");
        }
        else {
            //           login.getUserSex($('#txtMail').val(), $('#txtPWD').val(), function(res) { });
            if (res.value == "null" || res.value == null) {
                document.location == "/login.aspx";
            }
            var sourceID = $("input[id*=sourceType]").val();
            var productID = $("input[id*=productId]").val();
            if (sourceID != "" && productID != "") {
                document.location = "/detail.aspx?SourceType=" + sourceID + "&pid=" + productID + "";
            } else {
                document.location = res.value;
            }
        }
    });
}

function returnlogin() {
    $('#showType').attr("class", "clearFix showBarA");
}



