﻿$(document).ready(function () {
    var $nameCookie = unescape($.cookie('memberName'));
    if ($nameCookie != null && $nameCookie != "null") {
        $.post("/helper/LoginOut.ashx", { opreate: "updateMileage" }, function (d) {
            var mileageEval = eval(d);
            if (mileageEval[0].mileage != undefined && mileageEval[0].mileage != null && mileageEval[0].mileage != "") {
                $.cookie('mileage', mileageEval[0].mileage);
                $("#spanMileage").html(mileageEval[0].mileage);
            }
        });
    }
    var $MileageCookie = $.cookie('mileage');
    var $memberId = $.cookie('memberId');
    var $serviceUrl = $.cookie('serviceUrl');
    var $md5 = $.cookie('md5ForCa');
    var $birthDayMonth = $.cookie('birthDayMonth');
    if ($nameCookie != null && $nameCookie != "null" && $MileageCookie != null && $memberId != null && $serviceUrl != null && $serviceUrl != null) {
        $(".logon-form").hide();
        $(".loading").hide();
        $(".logon-txt").show();
        $("#spanMemberName").html($nameCookie);
        $("#spanMileage").html($MileageCookie);
        //修改个人信息
        $("#aModifyPwd").click(function () {
            var url = $serviceUrl + "FFPSCService.pgm?memberId=" + $memberId + "&fun=1&lan=CN&md5=" + $md5;
            window.open(url);
        });
        //个人信息查询
        $("#aModifyInfo").click(function () {
            var url = $serviceUrl + "FFPSCService.pgm?memberId=" + $memberId + "&fun=4&lan=CN&md5=" + $md5;
            window.open(url);
        });
        //里程查询
        $("#aSearchMileage").click(function () {
            var url = $serviceUrl + "FFPSCService.pgm?memberId=" + $memberId + "&fun=2&lan=CN&md5=" + $md5;
            window.open(url);
        });
        //地址管理
        $("#aSearchMileage").next().click(function () {
            var url = "http://" + location.host + "/UserAddressManager.aspx?memberId=" + $memberId;
            window.open(url);
        });
        //我能兑换的商品查询
        $(".logonBtn2:eq(0)").click(function () {
            var url = "/default/goodsList.aspx?speci=" + $MileageCookie + "-" + $birthDayMonth;
            window.open(url);
        });
        //兑换记录查询
        $(".logonBtn2:eq(1)").click(function () {
            var url = "/OrderList.aspx"; //$serviceUrl + "FFPSCService.pgm?memberId=" + $memberId + "&fun=3&lan=CN&md5=" + $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>里程");
    }
    //退出登录
    $("#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');
                //alert(location);
                //location.reload();
                location.href = "/Index.htm";
            }
        });
    });
    $("#pwdPassWord").next().attr("style", "cursor:pointer;");
    $("#pwdPassWord").next().click(function () {
        var needOpenUrl = "http://ffp.airchina.com.cn/gd2042a.jsp";
        window.open(needOpenUrl);
    });
})

