function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}

function logOn() {
    var div = $("#msg");
    var account = $("#txtAccount").val();
    var password = $("#txtPassword").val();
    var isCookies = $("#isSaveMsg").val(); //.is(":checked");
    var rememberMe = $('#isSaveMsg').is(":checked");

    var code = $("#txtCode").val();
    if (account == "" || password == "" || code == "") {
        if (account == "") {
            $("#txtAccount").focus();
        }
        else if (password == "") {
            $("#txtPassword").focus();
        }
        else if (code == "") {
            $("#txtCode").focus();
        }
        div.html(lang.InputAccountPwdVerifyCode);
        return;
    }

    var loading = "<img alt='" + lang.Loading + "' height='28' style='padding:0px;' width='28' src='/Images/loading.gif' />";
    div.html(loading + lang.Loading);
    var params = { account: account, password: password, code: code, rememberMe: rememberMe };
    $.ajax({
        type: "POST",
        url: "/Home/LogOnByAndPassword/",
        data: $.param(params),
        success: function (msg) {
            if (msg) {
                if (msg.IsSuccess) {
                    var href = unescape(request("ReturnUrl"));
                    if (href == "") {
                        href = "/";
                    }
                    window.location.href = href;
                    window.location.returnValue = false;
                    self.location = href;
                }
                else {
                    div.html(msg.Message);
                }
            }
            else {
                div.html(lang.LoadError);
            }
        }
    });
}
function reset() {
    $("#txtAccount").val("").focus();
    $("#txtPassword").val("");
    $("#txtCode").val("");
    $("#msg").html("");
}
//下拉框选中语言设置默认
function switchLanuage(lanuage) {
    window.location.href = "/Home/ChangeLanguage?language=" + lanuage;
}
//function switchLanuage(lanuage) {
//    if (lanuage == "cn" && !$("#btnCN").hasClass("selected")) {
//        $("#btnCN").addClass("selected");
//        $("#btnEN").removeClass("selected");
//        window.location.href = "/Home/ChangeLanguage?language=zh-cn";
//    } else if (lanuage == "en" && !$("#btnEN").hasClass("selected")) {
//        $("#btnEN").addClass("selected");
//        $("#btnCN").removeClass("selected");
//        window.location.href = "/Home/ChangeLanguage?language=en";
//    }
//}
$(function () {
    document.onkeydown = function (e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
            logOn();
        }
    };
});  