﻿
/// <reference path="GmrJsLib.js" />
/// <reference path="user.js" />
/// <reference path="Admin.js" />

function initTopMenu()
{
    /// <summary>初始化菜单</summary>

    var divTopMenu = $("divTopMenu");
    var menuItems = $C("menuItem", divTopMenu, "div");
    for (var i = 0; i < menuItems.length; i++)
    {
        var menuItem = menuItems[i];
        menuItem.onmouseover = function()
        {
            this.style.backgroundPosition = "left bottom";
            var itemChild = $C("menuItemChild", this, "div")[0];
            itemChild.style.backgroundPosition = "right bottom";
        };
        menuItem.onmouseout = function()
        {
            this.style.backgroundPosition = "left top";
            var itemChild = $C("menuItemChild", this, "div")[0];
            itemChild.style.backgroundPosition = "right top";
        };
        menuItem.onclick = function()
        {
            window.location = this.attributes["href"].value;
        }
    }
}

function showVcode()
{
    /// <summary>显示验证码</summary>
    var txtVcode = $("txtVcode");
    var imgVcode = $("imgVcode");
    if (txtVcode.isShow)
    {
        return;
    }
    else
    {
        txtVcode.value = "正在加载中...";
        txtVcode.disabled = true;
        imgVcode.onload = function()
        {
            txtVcode.value = "";
            txtVcode.disabled = false;
            txtVcode.style.color = "black";
            txtVcode.focus();
        };
        imgVcode.src = "/App_Controls/Common/image.aspx?id=" + Math.random();
        txtVcode.isShow = true;
    }

}

function userLogin()
{
    /// <summary>用户登录</summary>
    var username = $("txtUsername").value.Trim();
    var password = $("txtPassword").value.Trim();
    var vcode = $("txtVcode").value.Trim();
    var isrememberpassword = $("chkRememberPassword").checked;
    var message = "";
    if (username == "")
    {
        message += "请输入用户名\n";
    }
    if (password == "")
    {
        message += "请输入密码\n";
    }
    if (vcode == "")
    {
        message += "请输入验证码\n";
    }
    if (message != "")
    {
        alert(message);
        return;
    }
    Gmr.User.Login(username, password, vcode, isrememberpassword, function(code, mes, response)
    {
        if (code == 0)
        {
            alert("登录成功");
            window.top.location.reload();
        }
        else
        {
            alert("登录失败\\n" + mes);
        }
    });
}
function userLogout()
{
    /// <summary>用户注销</summary>

    Gmr.User.Logout(function(code, mes, response)
    {
        if (code == 0)
        {
            alert("注销成功");
            window.top.location.reload();
        }
        else
        {
            alert("注销失败\n" + mes);
        }
    });
}

function showRegist()
{
    /// <summary>显示注册</summary>
    Gmr.MessageBox.OpenWindow("", "regist1.aspx", "width:500px;height:280px;border: 6px solid #44270E;background-color: #FFF5E8;", "", "");
    
}
function showLogin()
{
    /// <summary>显示登录</summary>
    Gmr.MessageBox.OpenWindow("", "login1.aspx", "width:400px;height:235px;border: 6px solid #44270E;background-color: #FFF5E8;", "", "");
}
function showLogout()
{
    /// <summary>注销</summary>
    Gmr.MessageBox.OpenWindow("", "logout.aspx", "width:400px;height:235px", "", "");
}
function showChangePassword()
{
    /// <summary>显示修改密码</summary>
Gmr.MessageBox.OpenWindow("", "changepassword.aspx", "width:400px;height:235px", "", "");

}
/*订单部分*/
function showByTicketPanel(playId)
{
    
    Gmr.MessageBox.OpenWindow("订单", "chooseticket.aspx?pid=" + playId,"","","");
}

/*订单部分*/

/*搜索部分*/
function ticketSearch()
{
    var selTime = $("selSearchTime");
    var selSearchCategory = $("selSearchCategory");
    var txtKeywords = $("txtKeywords");
    var time = selTime ? selTime.value : "";
    var category = selSearchCategory ? selSearchCategory.value : "";
    var keywords = txtKeywords ? txtKeywords.value.Trim() : "";
    if (keywords == "请输入关键词") {keywords = "";}
    var dtNow = new Date();
    var dtStart = dtNow.getFullYear() + "-" + (dtNow.getMonth() + 1) + "-" + dtNow.getDate();
    var dtEnd;
    switch (time)
    {
        case ("1"):
            dtNow.setDate(dtNow.getDate() + 2);
            break;
        case ("2"):
            dtNow.setDate(dtNow.getDate() + 6);
            break;
        case ("3"):
            dtNow.setMonth(dtNow.getMonth() + 1);
            break;
        case ("4"):
            dtNow.setMonth(dtNow.getMonth() + 3);
            break;
        case ("5"):
            dtNow.setMonth(dtNow.getMonth() + 6);
            break;
        default: dtNow.setFullYear(2020, 1, 1);
            break;
    }
    dtEnd = dtNow.getFullYear() + "-" + (dtNow.getMonth() + 1) + "-" + dtNow.getDate();
    window.open("/search.aspx?dt1=" + dtStart + "&dt2=" + dtEnd + "&category=" + encodeURI( category) + "&keywords=" + encodeURI(keywords));
}

function SelectContact()
{
    /// <summary>订单地址选择</summary>
    var hid = $A(document.body, "input", "tid", "hidContact")[0];
    var selId = $A(document.body, "select", "tid", "selContactList")[0];
    if (!hid || !selId) { return; }
    var cs = hid.value.split("&&");
    var selectId = selId.value;
    for (var i = 0; i < cs.length; i++)
    {
        var csitem = cs[i].split("&");
        if (HtmlDecode(csitem[0]) == selectId)
        {
            $A(document.body, "input", "tid", "tboxUserName")[0].value = HtmlDecode(csitem[1]);
            $A(document.body, "select", "tid", "selSex")[0].value = HtmlDecode(csitem[2]);
            $A(document.body, "textarea", "tid", "tboxAddress")[0].value = HtmlDecode(csitem[3]);
            $A(document.body, "input", "tid", "tboxPostCode")[0].value = HtmlDecode(csitem[4]);
            $A(document.body, "input", "tid", "tboxMobile")[0].value = HtmlDecode(csitem[5]);
            $A(document.body, "input", "tid", "tboxPhone")[0].value = HtmlDecode(csitem[6]);
            return;
        }
    }
    $A(document.body, "input", "tid", "tboxUserName")[0].value = "";
    $A(document.body, "select", "tid", "selSex")[0].value = "";
    $A(document.body, "textarea", "tid", "tboxAddress")[0].value = "";
    $A(document.body, "input", "tid", "tboxPostCode")[0].value = "";
    $A(document.body, "input", "tid", "tboxMobile")[0].value = "";
    $A(document.body, "input", "tid", "tboxPhone")[0].value = "";
}
function ResizePostion(objBorder)
{
    /// <summary>调整Pannel布局</summary>
    if (!Gmr.Navigator.Info.IsIE6) { return; }
    var divBorder = $(objBorder);
    var oH = divBorder.offsetHeight;
    divBorder.style.height = oH + "px";
    divBorder.style.height = oH * 2 - divBorder.offsetHeight;
}

function chatGetList()
{
    /// <summary>查询购票夹列表</summary>
    PageAPI("", "getlist", new Array(), function(code, mes, response)
    {
        // alert(code);
        if (code == 0)
        {
            $("divList").innerHTML = response.GetParamValue("list");
            $("spSortCount").innerHTML = response.GetParamValue("sortcount");
            $("spCount").innerHTML = response.GetParamValue("count");
            $("spAmount").innerHTML = response.GetParamValue("amount");
        }
        else
        {
            alert(mes);
        }
    }
    );
}
function chatAdd(key)
{
    /// <summary>增加一次订票数</summary>
    //alert(key);
    PageAPI("", "chatAdd", new Array("key",key), function(code, mes, response)
    {
        if (code == 0)
        {
            $("divList").innerHTML = response.GetParamValue("list");
            $("spSortCount").innerHTML = response.GetParamValue("sortcount");
            $("spCount").innerHTML = response.GetParamValue("count");
            $("spAmount").innerHTML = response.GetParamValue("amount");
        }
        else
        {
            alert(mes);
        }
    }
    );
}
function chatReduce(key)
{
    /// <summary>增加一次订票数</summary>
    //alert(key);
    PageAPI("", "chatReduce", new Array("key", key), function(code, mes, response)
    {
        if (code == 0)
        {
            $("divList").innerHTML = response.GetParamValue("list");
            $("spSortCount").innerHTML = response.GetParamValue("sortcount");
            $("spCount").innerHTML = response.GetParamValue("count");
            $("spAmount").innerHTML = response.GetParamValue("amount");
        }
        else
        {
            alert(mes);
        }
    }
    );
}
function chatDelete(key)
{
    /// <summary>增加一次订票数</summary>
    //alert(key);
    if (!confirm("您确实要删除吗？"))
    {
        return;
    }
    PageAPI("", "chatDelete", new Array("key", key), function(code, mes, response)
    {
        if (code == 0)
        {
            $("divList").innerHTML = response.GetParamValue("list");
            $("spSortCount").innerHTML = response.GetParamValue("sortcount");
            $("spCount").innerHTML = response.GetParamValue("count");
            $("spAmount").innerHTML = response.GetParamValue("amount");
        }
        else
        {
            alert(mes);
        }
    }
    );
}