﻿$(document).ready(function () {
    //绑定登录按钮的单击事件
    $(".logonBtn").click(function () {
        login();
    });

    //绑定回车事件
    $(".logon").keydown(function (event) {
        if (event.keyCode == 13) {
            login();
            return false;
        }
    });
});
function login() {
    var memberId = $("#txtUserName").val();
    var loginPwd = $("#pwdPassWord").val();
    var loginCode = $("#txtValidCode").val();
    $(".logon-form").hide();
    $(".loading").show();    
    //$(".logonBtn").enabled;按钮不可点
    $.post("/helper/LoginOperate.ashx", { userName: memberId, pwd: loginPwd, checkCode: loginCode }, function (d) {
        if (d != null) {
            var jsonObj = eval(d);
            if (jsonObj[0].error == undefined && jsonObj[0].isSuccess == "true") {
//                try {
//                    SeachData();
//                } catch (ex) {
//                }

                $(".logon-form").hide();
                $(".loading").hide();
                $(".logon-txt").show();
                $("#spanMemberName").html(jsonObj[0].memberName);
                $("#spanMileage").html(jsonObj[0].mileage);
//                //修改个人信息
//                $("#aModifyPwd").click(function () {
//                    var url = jsonObj[0].serviceUrl + "FFPSCService.pgm?memberId=" + memberId + "&fun=1&lan=CN&md5=" + jsonObj[0].md5;
//                    window.open(url);
//                });
//                //个人信息查询
//                $("#aModifyInfo").click(function () {
//                    var url = jsonObj[0].serviceUrl + "FFPSCService.pgm?memberId=" + memberId + "&fun=4&lan=CN&md5=" + jsonObj[0].md5;
//                    window.open(url);
//                });
//                //里程查询
//                $("#aSearchMileage").click(function () {
//                    var url = jsonObj[0].serviceUrl + "FFPSCService.pgm?memberId=" + memberId + "&fun=2&lan=CN&md5=" + jsonObj[0].md5;
//                    window.open(url);
                //修改个人信息
                $("#aModifyPwd").click(function () {
                    var url ="http://www.airchina.com.cn/www/jsp/userManager/login.jsp"
                    window.open(url);
                });
                //个人信息查询
                $("#aModifyInfo").click(function () {
                    var url = "http://www.airchina.com.cn/www/jsp/userManager/login.jsp"
                    window.open(url);
                });
                //里程查询
                $("#aSearchMileage").click(function () {
                    var url = "http://www.airchina.com.cn/www/jsp/userManager/login.jsp"
                    window.open(url);
                });
                //地址管理
                $("#aSearchMileage").next().click(function () {
                    var url = "http://" + location.host + "/UserAddressManager.aspx?memberId=" + memberId;
                    window.open(url);
                });
                //退出登录
                $("#spanMemberName").parent().next().click(function () {
                    $.post("/helper/LoginOut.ashx", { opreate: "loginOut" }, function (d) {
                        var jsonObjForLoginOut = eval(d);
                        if (jsonObjForLoginOut[0].isSuccess == "true") {
                            //document.execCommand('Refresh');
                            location.href = "/Index.htm";
                        }
                    })
                });
                //我能兑换的商品查询
                $(".logonBtn2:eq(0)").click(function () {
                    var url = "/default/goodsList.aspx?speci=" + jsonObj[0].mileage + "-" + jsonObj[0].birthDayMonth;
                    window.open(url);
                });
                //兑换记录查询
                $(".logonBtn2:eq(1)").click(function () {
                    var url = "/OrderList.aspx"; // jsonObj[0].serviceUrl + "FFPSCService.pgm?memberId=" + memberId + "&fun=3&lan=CN&md5=" + jsonObj[0].md5;
                    window.open(url);
                });
                $(".logonBtn2:eq(1)").html("换购中心");
                $(".logonBtn2:eq(1)").parent().parent().append("<a href='/AuctionList.aspx' target='_blank' class='logon-news' title='我的竞拍'></a>");
                var spanMileageHtml = $("#spanMileage").html();
                $("#spanMileage").parent().html("目前里程：<span id='spanMileage'>" + spanMileageHtml + "</span>里程");
            }
            else {
                alert(jsonObj[0].error);
                if (jsonObj[0].error == "验证码已过期") {
                    var varCode = $("#txtValidCode").next("img")[0];
                    varCode.src = varCode.src + "?";
                }
                $("#txtUserName").focus();
                $(".logon-form").show();
                $(".loading").hide();
                $(".logon-txt").hide();
            }
        }
        else {
            alert("登录失败");
            $("#txtUserName").focus();
            $(".logon-form").show();
            $(".loading").hide();
            $(".logon-txt").hide();
        }
        //$("#count").html(d);
    });
}
function CutImageUrl(domainName, url, imgw, imgh) {
    var _imgWidth = "_" + imgw;
    var _imgHeight = "_" + imgh;
    var _reUrl = "";
    var _filename = url.substring(url.lastIndexOf("/") + 1);
    var _fileext = url.substring(url.lastIndexOf("."));
    var _imagename = _filename.substring(0, _filename.indexOf(_fileext));
    var _lastfirst = _imagename.substring(_imagename.length - 1);
    var _lastsec = _imagename.substring(_imagename.length - 2, _imagename.length - 1);
    _reUrl = domainName + "/upload/imgcache/" + _lastfirst + "/" + _lastsec + "/" + _imagename + _imgWidth + _imgHeight + _fileext;
    return _reUrl;
}
