﻿  var sh;
Ajax = function() {
    var xmlhttp;           //xmlhttp 对象用于取xml文档
    var failed;            //xmlhttp 获取失败标致
    var elementObj;        //DOM对象名
    var method;            //传递方法　GET　POST
    var responseStatus;    //xmlhttp　状态
    var url;               //请求服务地址
    var domObj;
    var display;

    this.xmlhttp = null;
    this.failed = true;
    this.element = 'hiddenDIV';
    this.method = 'GET';
    this.createAJAX();
}
Ajax.prototype.onLoading = function() {
    //document.getElementById('showchkname').innerHTML= 'Loading,please waited ...';
};
Ajax.prototype.onLoaded = function() {
    //document.getElementById('showchkname').innerHTML= 'loaded';
};
Ajax.prototype.onFail = function() {
    //document.getElementById('showchkname').innerHTML= 'Loading,please wait ...';
};
Ajax.prototype.onInteractive = function() {
    //alert('Loading,please wait ...');
    //document.getElementById('hiddenDIV').innerHTML= 'Loading,please wait a...';
};
Ajax.prototype.createAJAX = function() {
    try {
        this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
        try {
            this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
            this.xmlhttp = null;
        }
    }

    if (!this.xmlhttp) {
        if (typeof XMLHttpRequest != "undefined") {
            this.xmlhttp = new XMLHttpRequest();
        } else {
            this.failed = true;
        }
    }
};
//执行Ajax的请求
Ajax.prototype.runAJAX = function(urlstring, querystring, method, display) {

    var self = this;
    this.url = urlstring;
    this.display = display;
    this.xmlhttp.onreadystatechange = function() { self.process.call(self) };

    if (method.toLowerCase() == 'get') {
        this.xmlhttp.open("GET", this.url, true);
        this.xmlhttp.send(null);
    }
    else if (method.toLowerCase() == 'post') {
        this.xmlhttp.open("POST", querystring, true);
        this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        this.xmlhttp.send(querystring);
    }
};
Ajax.prototype.process = function() {
    switch (this.xmlhttp.readyState) {
        case 1:
            this.onLoading();
            break;
        case 2:
            this.onLoaded();
            break;
        case 3:
            this.onInteractive();
            break;
        case 4:
            this.response = this.xmlhttp.responseText;
            this.responseXML = this.xmlhttp.responseXML;
            this.responseStatus = this.xmlhttp.status;
         //   alert(this.response);
            if (this.responseStatus == 200) {
                xmlDoc = this.xmlhttp.responseXML;
                if (this.display == 1000)	//获取系统左边功能列表
                    this.GetLeft(this.response);
                if (this.display == 1001)	//获取系统左边功能列表
                    this.CheckCode(this.response);
                if (this.display == 1002)
                    this.UserLogin(this.response);
                if (this.display == 1003)
                    this.GetUserInfo(this.response);
                if (this.display == 1004)
                    this.ShowInfo(this.response);
                if (this.display == 1005)
                    this.Logout(this.response);
                if (this.display == 1006)
                    this.rLogin(this.response);
                if (this.display == 1007)
                    this.Reg(this.response);
                if (this.display == 1008)
                    this.GetUserName(this.response);
                if (this.display == 1009)
                    this.GetInnerHTML(this.response);
                if (this.display == 1010)
                    this.Modify(this.response);
                if (this.display == 1011)
                    this.ActiveGame(this.response);
                if (this.display == 1014)//
                    this.AdReg(this.response);
                if (this.display == 1015)//
                    this.AdLogin(this.response);
                if (this.display == 1016)//
                    this.AddGameInfo(this.response);
                ////////
                if (this.display == 2000) //没有验证码的登陆
                    this.NoCheckLogin(this.response);
                if (this.display == 2001) //根据TypeId显示游戏列表   分页
                    this.GetTypeGame(this.response);
                if (this.display == 2002)
                    this.GetNewsListFiv(this.response); //根据TypeId显示新闻列表   分页
                if (this.display == 2003)
                    this.GetSearchList(this.response);  //根据搜索结果   分页
                if (this.display == 2004)//
                    this.SetTitle(this.response);
                if (this.display == 2005)
                    this.DocumentWrite(this.response);
                if (this.display == 2006)//网站联盟开通禁用支付方式
                    this.AddPayType(this.response);
                if (this.display == 2007)
                    this.NewIndexDHInfo(this.response);
                if (this.display == 2008)
                    this.GetNewInnerHTML(this.response);
                if (this.display == 3001)
                    this.shownewmessage(this.response);
                if (this.display == 3002)
                    this.gettakemessages(this.response);
                if (this.display == 3004)
                    this.show(this.response);
                if (this.display == 3003)
                    ;
                if (this.display == 3005)
                    this.havefrilis(this.response);
                if (this.display == 3006)
                    this.addfrilis(this.response);
                if (this.display == 3007)
                    this.stoptalk_back(this.response);
                if (this.display == 3008)
                    this.NewGold_ExchangePrzie_back(this.response);
                if (this.display == 3009)
                    this.NewGold_havePrzie_back(this.response);
                if (this.display == 3010)
                    this.NewGold_GoldMes_back(this.response);

            }
            else {
                alert("There is a problem!" + this.responseStatus + " " + this.display);
            }
            break;
    }
};

//////////////////////
Ajax.prototype.NewGold_GoldMes_back = function(obj) {
    if (obj.split('|')[0] == "0") {
        document.getElementById("NewGold_Mes").innerHTML = obj.split('|')[1];
        showGold();
    }

};
Ajax.prototype.NewGold_havePrzie_back = function(obj) {
    document.getElementById("box1").innerHTML =document.getElementById("box1").innerHTML+ obj;

};
Ajax.prototype.NewGold_ExchangePrzie_back = function(obj) {
    if (obj == "-1") {
        alert("金币不足");
    }
    else if (obj == "-2") {
        alert("产品已下架");

    }
    else if (obj == "-3") {
        alert("库存不足");
    }
    else if (obj == "0") {
        alert("兑换成功");
        location.href = '/bargame/member/vipGameLog.aspx';
    }
    else if(obj == "-4") {
        alert("已超过该礼品限制兑换次数");
    }
    else {
        alert("未知错误");
    }
};
Ajax.prototype.stoptalk_back = function(obj) {
    if (obj == "-1") {
        alert("操作失败");
        
    }
    else if (obj == "1") {
    alert("操作成功");
    havefrilist();
    }
    else if (obj == "-2") {
        alert("无此操作权限");
    }


};

Ajax.prototype.gettakemessages = function(obj) {
    if (obj.split('|')[0] == "-1") {
        alert("金币不足");
    }
    else if (obj.split('|')[0] == "-2") {
    alert("请勿刷屏");
    
    }


};
Ajax.prototype.addfrilis = function(obj) {
    if (obj == "-1") {
        alert("您已经添加了该好友");

    }
    else if (obj == "1") {
        alert("添加成功");
        havefrilist();
    }
    else if (obj == "2") {
        alert("修改成功");
        havefrilist();
    }
    else if (obj == "3") {
        alert("删除成功");
        havefrilist();
    }
    else if (obj == "-2") {
    alert("该用户与您非同一网站");
    havefrilist();
    
    }
};
Ajax.prototype.havefrilis = function(obj) {
document.getElementById("friend_m").innerHTML = obj.split('|')[0];
document.getElementById("friend_b").innerHTML = obj.split('|')[1];
document.getElementById("friend_admin").innerHTML = obj.split('|')[2];
};
Ajax.prototype.shownewmessage = function(obj) {

document.getElementById("Fdmessage").innerHTML = obj.split('|')[1];
    if (obj.split('|')[0] == "0")
        chickAutodiv();
        onscrolls();
    };
    Ajax.prototype.show = function(obj) {
     
        document.getElementById("channel_case0").innerHTML = obj;

    };
Ajax.prototype.GetNewInnerHTML = function(obj) {
    if (document.getElementById(obj.split('@@#*')[1]))
        document.getElementById(obj.split('@@#*')[1]).innerHTML = obj.split('@@#*')[2];

};
Ajax.prototype.NewIndexDHInfo = function(obj) {
    if (document.getElementById(obj.split('|')[1])) {
        document.getElementById(obj.split('|')[1]).innerHTML = obj.split('|')[2];
        document.getElementById("roll_te2").innerHTML = obj.split('|')[2];
        document.getElementById(obj.split('|')[1]).style.display = "";
    }

};

Ajax.prototype.GetSearchList = function(obj) {
    if (document.getElementById(obj.split('@@')[1]))
        document.getElementById(obj.split('@@')[1]).innerHTML = obj.split('@@')[2];

};

Ajax.prototype.GetNewsListFiv = function(obj) {

    if (document.getElementById(obj.split('##')[1]))
        document.getElementById(obj.split('##')[1]).innerHTML = obj.split('##')[2];


};
Ajax.prototype.GetTypeGame = function(obj) {
    if (document.getElementById(obj.split('#')[1]))
        document.getElementById(obj.split('#')[1]).innerHTML = obj.split('#')[2];

};
Ajax.prototype.NoCheckLogin = function(obj) {

    if (parseInt(obj.split('|')[0]) >= 0) {
       // GetUserInfo();
        if (parseInt(obj.split('|')[3]) > 0) {
            // location.href='/';
        }
        else {
            location.href = location.href;
        }
    }
    else {
        alert(obj.split('|')[1]);
        location.href = '/Member/login.aspx'
    }

};
///////////
Ajax.prototype.GetLeft = function(obj) {
    document.getElementById("LeftDiv").innerHTML = obj;
};
Ajax.prototype.CheckCode = function(obj) {
    if (document.getElementById(obj.split('|')[1]))
        document.getElementById(obj.split('|')[1]).innerHTML = obj.split('|')[2];
    // document.getElementById("LeftDiv").innerHTML=obj;    
};

Ajax.prototype.UserLogin = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        GetUserInfo();
    }
    else if (obj.split('|')[0] == "-2") {
        alert(obj.split('|')[1]);
        document.getElementById("CodeBox").value = '';
        document.getElementById("CodeBox").focus();
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.rLogin = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        if (obj.split('|')[2] != "" && obj.split('|')[2] != "undefined") {
            location.href = obj.split('|')[2];
        }
        else {
            location.href = '/';
        }
        //   GetUserInfo();
    }
    else if (obj.split('|')[0] == "-2") {
        alert(obj.split('|')[1]);
        document.getElementById("CodeBox").value = '';
        document.getElementById("CodeBox").focus();
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.Reg = function(obj) {
   
    if (parseInt(obj.split('|')[0]) >= 0) {
        alert('注册成功');
        if (obj.split('|')[2] != "") {
            location.href = obj.split('|')[2];
        }
        else {
            location.href = '/';
        }
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.Logout = function(obj) {
    GetUserInfo();
};
Ajax.prototype.ShowInfo = function(obj) {
    if (document.getElementById(obj.split('|')[1])) {
        document.getElementById(obj.split('|')[1]).innerHTML = obj.split('|')[2];
        document.getElementById(obj.split('|')[1]).style.display = ""
    }
    if (obj.split('|')[2] == "")
        document.getElementById(obj.split('|')[1]).style.display = "none"
    // document.getElementById("LeftDiv").innerHTML=obj;    
};
Ajax.prototype.GetUserInfo = function(obj) {
    if (document.getElementById(obj.split('|')[1]))
        document.getElementById(obj.split('|')[1]).innerHTML = obj.split('|')[2];
    //     GetTopUserInfo();


    // document.getElementById("LeftDiv").innerHTML=obj;    
};
Ajax.prototype.GetUserName = function(obj) {
    if (document.getElementById(obj.split('|')[1]))
        document.getElementById(obj.split('|')[1]).value = obj.split('|')[0];
    if (document.getElementById(obj.split('|')[2]))
        document.getElementById(obj.split('|')[2]).value = obj.split('|')[0];
    if (document.getElementById(obj.split('|')[3]))
        document.getElementById(obj.split('|')[3]).innerHTML = obj.split('|')[0];
    if (document.getElementById(obj.split('|')[4]))
        document.getElementById(obj.split('|')[4]).value = obj.split('|')[0];
    if (document.getElementById(obj.split('|')[5]))
        document.getElementById(obj.split('|')[5]).value = obj.split('|')[0];
    var ui = obj.split('|')[6];
    var ua = ui.split('$');
    for (var i = 0; i < ua.length; i++) {
        if (document.getElementById(ua[i].split('#')[0])) {
            if (document.getElementById(ua[i].split('#')[0]).tagName == "INPUT") {
                document.getElementById(ua[i].split('#')[0]).value = ua[i].split('#')[1];
            }
            if (document.getElementById(ua[i].split('#')[0]).tagName == "SPAN") {
                document.getElementById(ua[i].split('#')[0]).innerHTML = ua[i].split('#')[1];
            }
        }
    }
    //     GetTopUserInfo();


    // document.getElementById("LeftDiv").innerHTML=obj;    
};
Ajax.prototype.GetInnerHTML = function(obj) {
    //   alert(obj);
    if (document.getElementById(obj.split('|')[1])) {
        document.getElementById(obj.split('|')[1]).innerHTML = obj.split('|')[2];
        document.getElementById(obj.split('|')[1]).style.display = "";
    }
};
Ajax.prototype.Modify = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        alert(obj.split('|')[1]);
        if (obj.split('|')[2] != "") {
            location.href = obj.split('|')[2];
        }
        else {
            location.href = '/BarGame/Member/index.aspx';
        }
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.ActiveGame = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        alert(obj.split('|')[1]);
        if (obj.split('|')[2] != "" && obj.split('|')[2] != "undefined") {
            location.href = obj.split('|')[2];
        }
        else {
            location.href = '/';
        }
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.AddGameInfo = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        if (obj.split('|')[2] != "" && obj.split('|')[2] != "undefined") {
            parent.location.href = obj.split('|')[2];
        }
        else {
            parent.location.href = '/';
        }
    }
    else {
        alert(obj.split('|')[1]);
        document.getElementById("Button1").value = "进入游戏";
    }
};
Ajax.prototype.AdReg = function(obj) {
    //  alert(obj);
    if (parseInt(obj.split('|')[0]) >= 0) {
        var oa = obj.split('|');
        //  alert(oa[3]);
        if (oa.length >= 4) {
            location.href = '/WebGame.aspx?spid=' + oa[3] + '&server=1';
        }
        else {
            location.href = '/';
        }
    }
    else {
        alert(obj.split('|')[1]);
        if (parseInt(obj.split('|')[0]) == -2) {
            if (document.getElementById("AdCodeImg")) {
                document.getElementById("AdCodeImg").src = "/customercode.aspx?rnd=" + Math.random();
            }
            if (document.getElementById("CodeBox")) {
                document.getElementById("CodeBox").value = "";
                document.getElementById("CodeBox").focus();
            }
        }
    }
};
Ajax.prototype.AdLogin = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        var oa = obj.split('|');
        if (oa.length >= 4) {
            location.href = '/WebGame.aspx?spid=' + oa[3] + '&server=1';
        }
        else {
            location.href = '/WebGame.aspx?spid=70&server=1';
        }
    }
    else if (obj.split('|')[0] == "-2") {
        alert(obj.split('|')[1]);
        if (document.getElementById("LoginCodeBox")) {
            document.getElementById("LoginCodeBox").value = '';
            document.getElementById("LoginCodeBox").focus();
        }
    }
    else {
        alert(obj.split('|')[1]);
    }
};
Ajax.prototype.SetTitle = function(obj) {
    document.title = obj;
};
Ajax.prototype.AddPayType = function(obj) {
    if (parseInt(obj.split('|')[0]) >= 0) {
        alert(obj.split('|')[1]);
        if (obj.split('|')[2] != "" && obj.split('|')[2] != "undefined") {
            parent.location.href = obj.split('|')[2];
        }
        else {
            parent.location.href = '/Site/PayType.aspx';
        }
    }
    else {
        alert(obj.split('|')[1]);
        //  document.getElementById("Button1").value = "进入游戏";    
    }
};
function GetLeft() {
    var obj = new Ajax();
    url = "/NewLeft.aspx?rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1000);
}
function AddGameInfo(gid, nick, us) {
    var obj = new Ajax();
    url = "/Page/Wan1ba.aspx?GameId=" + gid + "&uname=" + nick + "&us=" + us + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1016);

}
function AddGameInfo_sx(nick) {
    var obj = new Ajax();
    url = "/Page/Sx_nicename.aspx?us=" + nick + "&rnd=" + Math.random();
    
    obj.runAJAX(url, url, 'get', 1016);

}
function AddGameInfo_drqp(gid, nick, us) {
    var obj = new Ajax();
    url = "/Page/drqp.aspx?GameId=" + gid + "&uname=" + nick + "&us=" + us + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1016);

}
function AddGameInfo_hdsj(nick) {
    var obj = new Ajax();
    url = "/Page/hdsj.aspx?GameId=101&uname=" + nick + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1016);

}
function AddGameInfo_Uchome(nick) {
    var obj = new Ajax();
    url = "/Page/Uchome.aspx?uname=" + nick + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1016);

}
function AddGameInfo_dzpk(gid, nick, us) {
    var obj = new Ajax();
    url = "/Page/dzpk.aspx?GameId=" + gid + "&uname=" + nick + "&us=" + us + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 1016);

}
function getnewmessage() {
    var obj = new Ajax();
    url = "/Page/usermessage.aspx?rnd=" + Math.random();
   
    obj.runAJAX(url, url, 'get', 3001);

}
function talkmessage(talkcontant, target, peoplename,color) {
    var obj = new Ajax();
    url = "talk.aspx?talkcontant=" + talkcontant + "&target=" + target + "&peoplename=" + peoplename + "&color=" + color + "&rnd=" + Math.random();

    obj.runAJAX(url, url, 'get', 3002);
}
function havefrilist() 
{
    var obj = new Ajax();
    url = "frilist.aspx?rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 3005);
}
function addfri(frimember, listtype, handle,id) {
    var obj = new Ajax();
    url = "addfriend.aspx?id="+id+"&frimember=" + frimember + "&listtype=" + listtype + "&handle=" +handle+ "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 3006);
}
function stoptalk(frimember, czcs) {
    var obj = new Ajax();
    url = "stoptalk.aspx?frimember=" + frimember + "&czcs=" + czcs + "&rnd=" + Math.random();

    obj.runAJAX(url, url, 'get', 3007);

}
function NewGold_ExchangePrzie(MemberId, PrizeId, Remark, PrizeName) {
    var obj = new Ajax();
    url = "exchange.aspx?MemberId=" + MemberId + "&PrizeId=" + PrizeId + "&Remark=" + Remark + "&PrizeName=" + PrizeName + "&rnd=" + Math.random();

   obj.runAJAX(url, url, 'get', 3008);

}

function NewGold_havePrzie(PrizeId) {
    var obj = new Ajax();
    url = "Prize.aspx?id=" + PrizeId + "&rnd=" + Math.random();
    obj.runAJAX(url, url, 'get', 3009);
}

function NewGold_GoldMes() {
    var obj = new Ajax();
    url = "/GoldMes.aspx?rnd=" + Math.random();

    obj.runAJAX(url, url, 'get', 3010);
}