﻿$(function () {
    $("#txtUserName").keypress(function (event) {
        if (event.keyCode == 13 || event.which == 13) {
            if ($("#txtUserName").val() != "" && $("#txtUserPwd").val() != "") {
                checkUserLogin();
                return false;
            }
            if ($("#txtUserName").val() == "" || $("#txtUserName").val() == "手机号/会员卡号/用户名") {
                window.location.href = "/login.html?msg=MSG00034&url=" + escape(document.location.href);
                return false;
            }
            if ($("#txtUserPwd").val() == "") {
                window.location.href = "/login.html?msg=MSG00035&url=" + escape(document.location.href) + "&uname=" + $("#txtUserName").val();
                return false;
            }
            else {
                window.location.href = "/login.html?msg=MSG00035&url=" + escape(document.location.href) + "&uname=" + $("#txtUserName").val();
                return false;
            }

        }
    });
    $("#gopageFrme").css("display", "none");
    $("#txtUserPwd").keypress(function (event) {
        if (event.keyCode == 13 || event.which == 13) {
            if ($("#txtUserName").val() != "" && $("#txtUserPwd").val() != "") {
                checkUserLogin();
                return false;
            }
            if ($("#txtUserName").val() == "" || $("#txtUserName").val() == "手机号/会员卡号/用户名") {
                window.location.href = "/login.html?msg=MSG00034" + "&url=" + escape(document.location.href);
                return false;
            }
            if ($("#txtUserPwd").val() == "") {
                window.location.href = "/login.html?msg=MSG00035" + "&url=" + escape(document.location.href) + "&uname=" + $("#txtUserName").val();
                return false;
            }
            else {
                window.location.href = "/login.html?msg=MSG00035" + "&url=" + escape(document.location.href) + "&uname=" + $("#txtUserName").val();
                return false;
            }

        }
    });


    var url = window.location.href;
    var pagename = getUrlname(url.split("/")[3]);
    $("#otherli").removeClass("nav");
    $("#nav li[class='navli']").addClass("Nonenav");
    $("#nav li[lang='" + pagename + "']").removeClass("Nonenav").addClass("CurrentNav");
    $("#nav li[lang!='" + pagename + "']").mouseover(function () { $(this).removeClass("Nonenav").addClass("CurrentNav").siblings().removeClass("CurrentNav").addClass("Nonenav"); $("#otherli").removeClass("nav").removeClass("Nonenav").removeClass("CurrentNav"); $("#nav li[lang='" + pagename + "']").removeClass("Nonenav").addClass("CurrentNav"); });
    $("#nav li[lang!='" + pagename + "']").mouseout(function () { $(this).removeClass("CurrentNav").addClass("Nonenav"); $("#nav li[lang='" + pagename + "']").removeClass("Nonenav").addClass("CurrentNav"); });
});
var getUrlname = function (url) {
    if (url.toLowerCase() == "index.html" || url.toLowerCase() == "index.aspx")
        return "Index.html";
    if (url.toLowerCase() == "onlinebooking.html" || url.toLowerCase() == "onlinebooking.aspx")
        return "onlinebooking.html";
    if (url.toLowerCase() == "chexing.html" || url.toLowerCase() == "chexing.aspx")
        return "chexing.html";
    if (url.toLowerCase() == "outletmap.html" || url.toLowerCase() == "outletmap.aspx")
        return "OutletMap.html";
    if (url.toLowerCase() == "discountactivity.html" || url.toLowerCase() == "discountactivity.aspx")
        return "DiscountActivity.html";
    if (url.indexOf("monizuche") > -1)
        return "monizuche.html";
    return "Index.html";
}
function hrefPageCode(para) {
    window.location.href = para.url;;
}
function showhrefPageCode(para) {
    var urll = para.url;
    if (urll.indexOf("?") > 0)
        urll = urll + "&r=" + Math.random();
    else
        urll = urll + "?r=" + Math.random();

    $("#wBox").wBox({ show: true, drag: false, title: "", requestType: "iframe",
        iframeWH: { width: 480, height: 280 }, target: urll
    });
}
function showWindow() {

}
function close() {
    alert("dsd");
//    ab.close();
}
function goPage(url) {
    if (wBox)
        wBox.close();
    window.location.href = url;
}

//登录
function checkUserLogin() {
    var userName = $("#txtUserName").val();
    var userPwd = $("#txtUserPwd").val();
    if ($.trim(userName) == "" || $.trim(userName) == "手机号/会员卡号/用户名") {
        window.location.href = "/login.html?msg=MSG00034" + "&url=" + escape(document.location.href);
        return false;
    }
    else if ($.trim(userPwd) == "") {
        window.location.href = "/login.html?msg=MSG00035" + "&url=" + escape(document.location.href) + "&uname=" + $("#txtUserName").val();
        return false;
    }
    else {
        var clubServiceUrl = "/AjaxServices/UserAuthentication.aspx?action=ChekUser&url=" + window.location.href + "&username=" + escape(userName) + "&userpasw=" + userPwd + "&r=" + Math.random() + "&jsoncallback=?";

        $.ajax({
            async: false,
            type: "POST",
            contentType: 'application/x-www-form-urlencoded; charset=utf-8',
            dataType: 'json',
            url: clubServiceUrl,
            data: "{userName:'" + userName + "',userPwd:'" + userPwd + "'}",
            success: function (json) {
                if (json.Error == "true") {
                    if (json.MsgId == "0") {
                        $("html").addClass("hb");
                        Chesudi.Common.tip.confirm({ id: "DvNewCellDel", title: "", left: "33%", top: "35%", msg: "你还未进行手机认证，请确认", func: showhrefPageCode, param: { url: "/SecurityCode.aspx"} });
                    }
                    else {
                        window.location.href = "/login.html?msg=" + json.MsgId + "&url=" + escape(document.location.href) + "&uname=" + userName;
                    }
                    return false;
                }
                else {
                    if (json.MsgId == "false") {
                        var strurl = window.location.href;
                        if (strurl.indexOf('Register') > 0 || strurl.indexOf('Retrieve') > 0)
                            strurl = "index.html";
                        $("html").addClass("hb");
                        Chesudi.Common.tip.confirm({ id: "DvNewCellDel", title: "", left: "33%", top: "35%", msg: "请修改初始密码!", func: hrefPageCode, urli: strurl, param: { url: json.Url} });
                    } else {
                        window.location.href = json.Url;
                    }
                }
            }
        });
    }
}
function checkLogin() {
    var userName = $("#txtUserName").val();
    var userPwd = $("#txtUserPwd").val();
    var clubServiceUrl = "/AjaxServices/UserAuthentication.aspx?action=ChekUser&username=" + userName + "&userpasw="+userPwd+"&r=" + Math.random() + "&jsoncallback=?";
    $.getJSON(clubServiceUrl, function (result) {
        if (result.Error == "true") {
            alert(result.Msg);
        }
        else {
            $.ajax({
                async: false,
                type: "POST",
                contentType: "application/json;utf-8",
                url: "/AjaxServices/UserMember.aspx/LoginIn",
                data: "{userName:'" + userName + "',userPwd:'" + userPwd + "'}",
                success: function (data) {
                    if (data.d != null & data.d != "") {
                        if (data.d.split(',')[0] == "")
                            window.location.href = "/Member/UserInfo.html";
                           else
                                window.location.href = "/index.html";
                    }
                    else {
                        alert("登录失败！");

                    }
                }
            });
        }
    });
}
