﻿var ajaxurl = "/ZYWJAjax.ashx";
//*******************初始值定义***********************
var p_Category = null;
var p_Game = null;
var p_radioSimple = null;
var p_radioHigh = null;
var p_radioSuper = null;
var p_QQGroup = null;
var p_YZM = null;
//*******************Get方法**************************
function GetCategory() {
    if (p_Category == null)
        p_Category = $("#category");
    return p_Category;
}
function GetGame() {
    if (p_Game == null)
        p_Game = $("#game");
    return p_Game;
}
function GetRadioSimple() {
    if (p_radioSimple == null)
        p_radioSimple = $("#radioSimple");
    return p_radioSimple;
}
function GetRadioHigh() {
    if (p_radioHigh == null)
        p_radioHigh = $("#radioHigh");
    return p_radioHigh;
}
function GetRadioSuper() {
    if (p_radioSuper == null)
        p_radioSuper = $("#radioSuper");
    return p_radioSuper;
}
function GetQQGroup() {
    if (p_QQGroup == null)
        p_QQGroup = $("#txtQQGroup");
    return p_QQGroup;
}
function GetYZM() {
    if (p_YZM == null)
        p_YZM = $("#txtYZM");
    return p_YZM;
}

function GetElementById(id) {
    return $("#" + id);
}
//*******************Set方法**************************
function SetCategory(data) {
    $("#category").html(data);
}
function SetGame(data) {
    $("#game").html(data);
}
function SetQQGroup(data) {
    $("#txtQQGroup").val(data);
}
function SetYZM(data) {
    $("#txtYZM").val(data);
}
//****************************************************

//页面加载
$(document).ready(function() {
    $.post(ajaxurl, "action=GetCategory",
                    function(data) {
                        SetCategory(data);
                        BindGame();
                    });
});
//绑定游戏
function BindGame() {
    $.post(ajaxurl, "action=GetGame&categoryid=" + GetCategory().val(), function(data) {
        SetGame(data);
    }
                    );
}
function GetYZMImg() {
    var d = new Date();
    $("#checkcode").attr("src", "/CheckCode.aspx?" + d.getSeconds().toString());
}
function Type() {
    var type = null;
    if (GetRadioSimple().attr("checked"))
        type = "simple";
    if (GetRadioHigh().attr("checked"))
        type = "high";
    if (GetRadioSuper().attr("checked"))
        type = "super";
    return type;
}
function AddQQGroup() {
    if (GetYZM().val().length == 4 && GetQQGroup().val().length > 0) {
        $.post(ajaxurl, "action=AddQQGroup&yzm=" + GetYZM().val() + "&categoryid=" + GetCategory().val() + "&category=" + GetCategory().find("option:selected").text() + "&gameid=" + GetGame().val() + "&gamename=" + GetGame().find("option:selected").text() + "&qqgroup=" + GetQQGroup().val() + "&type=" + Type(), function(data) {
            SetQQGroup("");
            SetYZM("");
            GetYZMImg();
            alert(data);
        }
                    );
    } else {
        alert("请正确输入");
    }
}
