﻿function CreateLogin() {
    var msgw, msgh, bordercolor;
    msgw = 366; //提示窗口的宽度
    msgh = 210; //提示窗口的高度

    var isExist_msgDiv = document.getElementById("msgDiv");
    if (isExist_msgDiv) {
        return;
    }

    var msgObj = document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.style.backcolor = "white";
    msgObj.style.position = "absolute";
    msgObj.style.left = "50%";
    msgObj.style.top = "15%";
    msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px";
    msgObj.style.marginTop = window.document.documentElement.scrollTop + "px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height = msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight = "25px";
    msgObj.style.zIndex = "10001";

    window.document.body.appendChild(msgObj);

    var iframe = document.createElement("iframe");
    iframe.frameborder = "no"
    iframe.marginwidth = "0"
    iframe.marginheight = "0";
    iframe.width = msgw + "px";
    iframe.height = msgh + "px";
    iframe.scrolling = "no";
    iframe.setAttribute("frameborder", "0", 0);
    iframe.setAttribute("id", "iframeUserLogin");
    iframe.src = "/UserLoginDialog.aspx?dt=" + new Date().getTime().toString();
    window.document.getElementById("msgDiv").appendChild(iframe);
}

function Cancel() {
    document.body.removeChild(document.getElementById("msgDiv"));
}

function AlterHeight(msgh) {

    var msgObj = document.getElementById("msgDiv");
    var iframe = document.getElementById("iframeUserLogin");
    msgObj.style.height = msgh + "px";
    iframe.height = msgh;
}

function RefreshLogin(login) {
    Cancel();
    ChangeLogin(login);
}
function ChangeLogin(data) {
    if (data.State == 0) {
        $LoginBefor.css("display", "none");
        $LoginAfter.css("display", "block");

        $LoginUserName.html(data.UserName);
        $LoginBalance.html(data.Balance);
        $LoginPointsTotal.html(data.Scoring);
        UserID = data.UserID;
        $UserBalance && $UserBalance.text(data.Balance);
        $LoginInLetter.html(data.InLetter);
    }
    else {
        $LoginBefor.css("display", "block");
        $LoginAfter.css("display", "none");

        $LoginUserName.html("");
        $LoginBalance.html("");
        $LoginPointsTotal.html("");
        $LoginInLetter.html("0");
        UserID = -1;
        $UserBalance && $UserBalance.text(0);
    }
}

$(function() {
    InitLogin();
    $LoginMyAccount.bind({
        mouseover: function() {
            document.getElementById("div_qyhNav").style.zIndex = "-1";
            $LoginDivMyAccount.css("display", "block");
	    Special_zIndex_Ope("-1");
        },
        mouseout: function() {
            $LoginDivMyAccount.css("display", "none");
            document.getElementById("div_qyhNav").style.zIndex = "1000";
	    Special_zIndex_Ope("1")
        }
    });
    $LoginDivMyAccount.bind({ mouseover: function() {
        $(this).css("display", "block");
        document.getElementById("div_qyhNav").style.zIndex = "-1";
    },
        mouseout: function() {
            $(this).css("display", "none");
            document.getElementById("div_qyhNav").style.zIndex = "1000";
        }
    });

    //特殊页面的zIndex处理
    function Special_zIndex_Ope(zIndex) {
        //当前访问的url
        var thisUrl = window.location.href.toLowerCase();

        //合买中心
        if (thisUrl.indexOf("/JoinAllBuyNew.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".shareTitle", zIndex);
        }

        //包月套餐
        if (thisUrl.indexOf("/LotteryPackageNew.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".shareTitle", zIndex);
            SetIndex_Special(".Package_typelabel", zIndex);
            SetIndex_Special(".Package_typebottom", zIndex);
            SetIndex_Special("#tdTC1", zIndex);
        }

        //竞彩足球
        if (thisUrl.indexOf("/Lottery/Buy_JCZQ.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".line8 wrap", zIndex);
            SetIndex_Special(".ZCjincai-Touzhu", zIndex);
            SetIndex_Special("#MatchTypeDiv", zIndex);
        }
        
        //焦点资讯
        if (thisUrl.indexOf("/newscenter/index.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".ZiXun-SSQDH", zIndex);
            SetIndex_Special("#ZiXun-flash", zIndex);
        }
        
        //
        if (thisUrl.indexOf("/bs/index.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".wapper0419", zIndex);
            SetIndex_Special("#wapper04199", zIndex);
        }

        //
        if (thisUrl.indexOf("/bs/index.aspx".toLowerCase()) > 0) {
            SetIndex_Special(".wapper0419", zIndex);
            SetIndex_Special("#wapper04199", zIndex);
        }
    }

    //购买彩票一行
    $Qyhcz.bind(
    {
        mouseover: function() {
            $('#divLottery').bgiframe();
            $('#divLottery').css("display", "block");
            Special_zIndex_Ope("-1");
        },
        mouseleave: function() {
            $('#divLottery').css("display", "none");
            Special_zIndex_Ope("1");
        }
    });

    //购买彩票:全部彩种区域
    $DivLottery.bind(
    {
        mouseover: function() {
            //$('#divLottery').bgiframe();
            $(this).css("display", "block");
            Special_zIndex_Ope("-1");
        },
        mouseleave: function() {
            $(this).css("display", "none");
            Special_zIndex_Ope("1");
        }
    });

    LoginHandle("check");
});

function LoginHandle(action) {
    $.getJSON(UserHandleUrl, { "action": action }, function(data) {
        ChangeLogin(data);
    });
    if (action == "logout" && IsNeedHrefHome == "True") {
        top.location.href = BaseUrl;
    }
}

function startmarquee(id, lh, speed, delay) {
    var t;
    var p = false;
    var o = document.getElementById(id);
    o.innerHTML += o.innerHTML;
    o.onmouseover = function() { p = true }
    o.onmouseout = function() { p = false }
    o.scrollTop = 0;
    function start() {
        t = setInterval(scrolling, speed);
        if (!p) o.scrollTop += 2;
    }
    function scrolling() {
        if (o.scrollTop % lh != 0) {
            o.scrollTop += 2;
            if (o.scrollTop >= o.scrollHeight / 2) o.scrollTop = 0;
        } else {
            clearInterval(t);
            setTimeout(start, delay);
        }
    }
    setTimeout(start, delay);
}

function GetVouchers(lotteryName, orderAmount,castType) {
    var result;
    $.ajax({
        type: "POST",
        url: "/Ajax/VouchersHandler.ashx?dt=" + new Date().getTime().toString(),
        data: "action=GetVouchersInfo&ltyname=" + lotteryName + "&orderAmount=" + orderAmount+"&castType="+castType,
        async: false,
        error: function() {
            alert("数据库繁忙，请重试!");
        },
        success: function(response) {
            result = response;
        }
    });
    return result;
}

var $LoginBefor;
var $LoginAfter;
var $LoginUserName;
var $LoginBalance;
var $LoginPointsTotal;
var $LoginMyAccount;
var $LoginDivMyAccount;
var $Qyhcz;
var $DivLottery;
var UserHandleUrl;
var IsNeedHrefHome = false;
var BaseUrl;
var UserID = -1;
var $LoginInLetter;
var $UserBalance;

function InitLogin() {
    $LoginBefor = $("#Login_Befor");
    $LoginAfter = $("#Login_After");
    $LoginUserName = $("#Login_UserName");
    $LoginBalance = $("#Login_Balance");
    $LoginPointsTotal = $("#Login_PointsTotal");
    $LoginMyAccount = $("#Login_MyAccount");
    $LoginDivMyAccount = $("#Login_DivMyAccount");
    $Qyhcz = $("#qyhcz");
    $DivLottery = $("#divLottery");
    $LoginInLetter = $("#LoginInLetter");
    $UserBalance = $("#spn_Balance");
}

//设置特殊页面的zIndex
function SetIndex_Special(jID, zIndex) {
    try {
        $(jID).css("zIndex", zIndex);
    }
    catch (err) {
        ;
    }
}
