﻿
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;

			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 ==1012)//
				    this.AddGameInfo(this.response);
				if(this.display ==1013)//一卡通充值
				    this.CardChongZhi(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.AgentCheckCode(this.response); 
				if(this.display==2007)//首页兑换信息
				    this.NewIndexDHInfo(this.response); 
				if(this.display==2008)//首页兑换信息
				    this.GetNewInnerHTML(this.response);
				
}
			else
			{
				alert("There is a problem!" + this.responseStatus);
			}
			break;
	}
};
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.AgentCheckCode = function(obj)
{
    if(obj.split('|')[0]==1&&obj.split('|')[1]==1)
    {
        document.getElementById('CC').src="/code.aspx";
        CodeFrom="/code.aspx";        
    }

};
Ajax.prototype.GetSearchList = function(obj)
{
    if(document.getElementById(obj.split('@@')[1]))
        document.getElementById(obj.split('@@')[1]).innerHTML = obj.split('@@')[2]; 
//        alert( obj.split('@@')[1]);
//        alert(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];   
//        alert(document.getElementById(obj.split('#')[1]));
//        alert(obj.split('#')[2]);
};
Ajax.prototype.NoCheckLogin = function(obj)
{
  //  alert(obj);
    if(parseInt(obj.split('|')[0])>=0)
    {
        GetUserInfo();
    }
    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)
{
  //  alert(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];
        
         
};
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='/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]);
        if(document.getElementById("CodeBox"))
        {
            document.getElementById("CodeBox").value='';
            document.getElementById("CodeBox").focus();
        }
        if(document.getElementById("CodeImg"))
        {
            document.getElementById("CodeImg").src="/CustomerCode.aspx?rnd="+Math.random();
        }
    }
};
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.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.CardChongZhi = function(obj)
{
    if(parseInt(obj.split('|')[0])>=0)
    {
        alert('恭喜您充值成功，请查看您的余额');
        location.href='/';
    }    
    else
    {
        alert(obj.split('|')[1]);
        document.getElementById("CodeImg").src="/CustomerCode.aspx?rand="+Math.random();
        document.getElementById("CodeBox").value="";
        document.getElementById("Button1").value = "进入游戏";    
    }
};
Ajax.prototype.SetTitle = function(obj)
{
   document.title=obj;
};
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',1012); 
    
}
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',1012); 
    
}
function AddGameInfo_Sx(nick)
{
    var obj = new Ajax();
    url = "/Page/sx_nicename.aspx?us="+nick+"&rnd="+Math.random();
    obj.runAJAX(url,url,'get',1012); 
    
}
function AddGameInfo_hdsj(nick)
{
    var obj = new Ajax();
    url = "/Page/hdsj.aspx?GameId=101&uname="+nick;
    obj.runAJAX(url,url,'get',1012); 
    
}
function AddGameInfo_Uchome(nick)
{
    var obj = new Ajax();
    url = "/Page/Uchome.aspx?uname="+nick+"&rnd="+Math.random();
    obj.runAJAX(url,url,'get',1012); 
    
}
function  CardChongZhi(username1,username2,cardno,cardpwd,code)
{
    var obj = new Ajax();
    url = "/Page/CardChongZhi.aspx?UserName1="+username1+"&UserName2="+username2+"&CardNo="+cardno+"&CardPwd="+cardpwd+"&VCode="+code+"&rnd="+Math.random();
    obj.runAJAX(url,url,'get',1013);     
}