﻿AjaxLogin = 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();	
}
AjaxLogin.prototype.onLoading = function(){
    //document.getElementById('hiddenDIV').innerHTML= 'Loading,please wait ...';
};
AjaxLogin.prototype.onLoaded = function(){   
    //document.getElementById('hiddenDIV').innerHTML= '<img src="../img/loading.gif"></img>';
};
AjaxLogin.prototype.onFail = function(){	
    //document.getElementById('hiddenDIV').innerHTML= 'Loading,please wait ...';	
};
AjaxLogin.prototype.onInteractive = function(){
     //alert('Loading,please wait ...');
    //document.getElementById('hiddenDIV').innerHTML= 'Loading,please wait a...';
};
AjaxLogin.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的请求	
AjaxLogin.prototype.runAJAX = function(urlstring,querystring,method,display) 
{
    var self = this;
	this.url = urlstring;
	this.display = display;
	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);
	}		
	this.xmlhttp.onreadystatechange = function(){self.process.call(self)};		
};
AjaxLogin.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;

			xmlDoc = this.xmlhttp.responseXML;
			if(this.display == 1)this.displayLogin(xmlDoc);
			break;
	}
};
AjaxLogin.prototype.displayLogin = function(obj)
{	
    flag = obj.getElementsByTagName("flag")[0].childNodes[0].nodeValue;
	uname = obj.getElementsByTagName("uname")[0].childNodes[0].nodeValue;
	
	var GetUrl = GetLink("getUrl").toLowerCase();
	var check = true;
	if(GetUrl.indexOf("clientweb")>0 || GetUrl.indexOf("onlyweb")>0)check = false;
	
	if(check){
		htmlstr1 = '<div id="ind_member"><a href="http://uc.53mq.com/member_login.shtml" class="ind_mem_join"></a><a href="http://paycenter.53mq.com/" class="ind_mem_pay"></a></div>';
		
		htmlstr2 = '<div id="ind_member">';
        htmlstr2 += '<div class="login_l">';
        htmlstr2 += '<div style=" width:169px; margin:50px auto 6px;  font-size:14px; ">'+ uname +'<a href="http://uc.53mq.com/program/logout.asp" style="color:#FFFFFF;">[退出登录]</a></div>';
        htmlstr2 += '	<ul style="width:169px;">'
        htmlstr2 += '   	<li><a href="http://uc.53mq.com/game_action.shtml">游戏激活</a></li>';
        htmlstr2 += '   	<li><a href="http://uc.53mq.com/member_edit.shtml">资料修改</a></li>';
        htmlstr2 += '   	<li><a href="http://uc.53mq.com/member_password.shtml">密码修改</a></li>';
        htmlstr2 += '   	<li><a href="http://uc.53mq.com/member_email.shtml">邮箱修改</a></li>';
        htmlstr2 += '   	<li><a href="http://paycenter.53mq.com/">我要充值</a></li>';
        htmlstr2 += '   	<li><a href="http://paycenter.53mq.com/cx.shtml">账户查询</a></li>';
        htmlstr2 += '  		<li><a href="http://paycenter.53mq.com/ls.shtml">历史充值</a></li>';
        htmlstr2 += '  		<li><a href="http://uc.53mq.com/member_pwds.shtml">密码保护</a></li>';
        htmlstr2 += '	</ul>';
        htmlstr2 += '</div>';
		
	}else{
		htmlstr1 = '<a href="javascript:GTUserLogin();" class="dl_01"></a><a href="javascript:GTUserReg();" class="dl_02"></a>';
		
		htmlstr2 = '<a style="float:left; margin:5px 5px auto auto;" href="javascript:GoToUserWeb();">您好!'+ uname +'&nbsp;[进入会员中心]</a><a href="/Program/logout.asp" style="float:left; margin:5px 5px auto auto;">[注销]</a>';
	}
	
	var geturl = location.href;
	var Yurl = new Array('http://uc.53mq.com/',
						 'http://uc.53mq.com/index.shtml',
						 'http://uc.53mq.com/member_edit.shtml',
						 'http://uc.53mq.com/member_email.shtml',
						 'http://uc.53mq.com/member_password.shtml',
						 'http://uc.53mq.com/member_ok.shtml',
						 'http://uc.53mq.com/game_action.shtml',
						 'http://uc.53mq.com/game_action_name.shtml',
						 'http://uc.53mq.com/clientweb/login_g_act_game.html',
						 'http://uc.53mq.com/onlyweb/login_g_act_game.html',
						 'http://uc.53mq.com/clientweb/login_r_edit.html',
						 'http://uc.53mq.com/onlyweb/login_r_edit.html',
						 'http://uc.53mq.com/clientweb/login_r_password.html',
						 'http://uc.53mq.com/onlyweb/login_r_password.html',
						 'http://uc.53mq.com/clientweb/login_r_mail.html',
						 'http://uc.53mq.com/onlyweb/login_r_mail.html');
	var Ifstr = -1;
	for(var i=0;i<=Yurl.length;i++){
		if(geturl.split('?')[0] == Yurl[i]){
			Yurl[i] = geturl;
			Ifstr = i;
			break;
		}
	}
	if (flag == "yes")
	{
		if(Ifstr != -1){
			if(geturl!=Yurl[Ifstr]){window.location = Yurl[Ifstr];return;}
			if(geturl==Yurl[0] || geturl==Yurl[1]){window.location = Yurl[2];return;}
		}
		RepLoginHtml(htmlstr2); 
		return;
	}
	else{
		if(Ifstr != -1){
			if(GetUrl.indexOf("clientweb")>0){
				window.location = "http://uc.53mq.com/clientweb/login_log.html?url="+ encodeURIComponent(Yurl[Ifstr]);
			}else if(GetUrl.indexOf("onlyweb")>0){
				window.location = "http://uc.53mq.com/onlyweb/login_log.html?url="+ encodeURIComponent(Yurl[Ifstr]);
			}else{
				window.location = "http://uc.53mq.com/login.shtml?url="+ encodeURIComponent(Yurl[Ifstr]);
			}
			return;
		}else{
			RepLoginHtml(htmlstr1);
		}
	}
    return;
};
