function getQueryString(queryStringName){
	var	returnValue="";
	var	URLString=new	String(document.location);
	var	serachLocation=-1;
	var	queryStringLength=queryStringName.length;
	do	{
		serachLocation=URLString.indexOf(queryStringName+"\=");
		if	(serachLocation!=-1) {
			if	((URLString.charAt(serachLocation-1)=='?')	||	(URLString.charAt(serachLocation-1)=='&')) {
				URLString=URLString.substr(serachLocation);
				break;
			}
			URLString=URLString.substr(serachLocation+queryStringLength+1);
		}
	}
	while	(serachLocation!=-1)
	if	(serachLocation!=-1){
		var	seperatorLocation=URLString.indexOf("&");
		if	(seperatorLocation==-1)	{
			returnValue=URLString.substr(queryStringLength+1);
		}
		else{
			returnValue=URLString.substring(queryStringLength+1,seperatorLocation);
		}	
	}
	returnValue   =   returnValue.replace(/#/g,''); 
	return	returnValue;
}
//getQueryString('adid');

function LogRegKeyPress(aFrmObj){//兼容IE和Firefox获得keypress
	var currKey=0,CapsLock=0; 
	var e = arguments[1];
	e=e||window.event; 
	var kCode=e.keyCode||e.which||e.charCode; 
	if(kCode == '13'){
		regDataChk(aFrmObj);
	}
}

function getAgentInfo()
{
	var currUrl = window.location.href;
	agenttmp = currUrl.split("?adid=");
	if (agenttmp.length>1)
		document.getElementById('adid').value = agenttmp[1];
}

function chkUserName()
{
	var username=document.getElementById('username').value;
	if(!username)
	{
		SHPromptDiv('Email can not be empty');
		return false;
	}else if (!emailCheck('username','1')){
		return false;	
	}else{
		var paras='&username='+username;
		regSvrChk("http://www.77.net/include/ChkUserInfo.php",paras);
	}
}

function regSvrChk(url,paras) {
//	var isRegindex = arguments[2];
	$.ajax(
    {
			type:"POST",
			url:url,
			data:paras,
			success: function(result)
			{  
				if(result=='0') // 可以注册；
				{
					SHPromptDiv();
					return true;
				}else if(result=='1')
				{
					SHPromptDiv("The Email have been registered!please try another!");					
					return false;
				}else if(result=='2')
				{
					SHPromptDiv('The Email can not be empty!please enter your Email!');
					return false;
				}
			},
			error:function()
			{
					SHPromptDiv('login has failed!Please check your net status!');
					return false;
			}
    });
}
function chkPwdClt()
{
	var login_pwd=document.getElementById('new_password').value;
	var password_confirm=document.getElementById('password_confirm').value;
	if(!login_pwd)
	{
		SHPromptDiv('password can not be empty');
		return false;
	}
	if(!password_confirm)
	{
		SHPromptDiv('confirm password can not be empty');
		return false;
	}
	if (login_pwd!=password_confirm)
	{
		SHPromptDiv('Please enter the same password!');
		return false;		
	}
	return true;
}

function regDataChk(theform) //注册
{
	var username=document.getElementById('username').value;
	var login_pwd=document.getElementById('new_password').value;
	var password_confirm=document.getElementById('password_confirm').value;
	var chkAgree=document.getElementById('chkAgree').checked;	
	var canSub = document.getElementById('Layer4').innerHTML ? false:true;
	var paras='&username='+username;
	
	if (!chkAgree)
	{
		SHPromptDiv("Please choose 'I agree to receive and notification from Majesty'");
		return false;		
	}else	if(!username){
		SHPromptDiv('Email can not be empty');
		return false;
	}	else if (!emailCheck('username','1')){
	   return false;
	}else if (!chkPwdClt()){
	   return false;		
	}else if (regSvrChk("http://www.77.net/include/ChkUserInfo.php",paras,"1")){
	   return false;				
	}else{
		<!--需要js补充的数据-->
		document.getElementById('email').value = username;
		document.getElementById('email_confirm').value = username;
		if (canSub){
			theform.submit();
		}
  };
}

function emailCheck(emailObj){//邮箱验证；
    var theEmail=document.getElementById(emailObj).value;
    var Email = theEmail.toLowerCase();
    var ok = false;
    var count = 0;
    var fullEmail;
		var isRegPage = arguments[1] ?  arguments[1] :"";
    if (Email.length!=0 && Email.indexOf('@') != -1 ){// && (Email.indexOf('.') - Email.indexOf('@') > 1) && Email.indexOf('.') != -1
        if ((Email.length-1) != Email.indexOf('@') && (Email.length-1) !=Email.indexOf('.') && Email.indexOf('@')!=0 && Email.indexOf('.')!=0){
            for (var i=0;i<Email.length;i++){
            fullEmail=Email.charAt(i);
              if ((fullEmail>= 'a' && fullEmail<= 'z') || (fullEmail >= 0 && fullEmail<= 9) || (fullEmail == '-')|| (fullEmail == '_') || (fullEmail == '@') || (fullEmail == '.')){
								if (fullEmail == '@'){
									 count++;
								}
              }else{
								if (isRegPage){
									SHPromptDiv("the Email has illegal character");
								}else{
									alert("the Email has illegal character");										
								}
               return false;
              }
          }
					if((Email.indexOf('@')+1)<3 || (Email.indexOf('@')+1)>45){
						if (isRegPage){
							SHPromptDiv("the number that the left of character '@' have to from 3 to 45");
						}else{
							alert("the number that the left of character '@' have to from 3 to 45");
						}						
						return false;
					}
					if (count != 1){
						if (isRegPage){
							SHPromptDiv("the Email can not have two '@' character!");
						}else{
							alert("the Email can not have two '@' character!");
						}							
  					return false;
					}
        }else{
					if (isRegPage){
						SHPromptDiv("the first of the Email can not be @or . and the end can not be @or '.'");
					}else{
         alert("the first of the Email can not be @or . and the end can not be @or '.'");
					}						
		 return false;
        }
    }else{
			if (isRegPage){
				SHPromptDiv("The email you entered is illegal!Please enter legal Email");
			}else{
					alert("The email you entered is illegal!Please enter legal Email");
			}						
			return false;
    }
    return true;
   }

function getCurDate(aObjName)//以太平洋时间显示；
{
	$.get("http://www.77.net/Common/GetServerDt.php",{localdt:new Date().getTime()},function(data){ //new Date().getTime() 为了解决get相同url时读取IE的问题；
    if (data){
			eval("var serverDtTmp = "+unescape(data));
			document.getElementById(aObjName).innerHTML= serverDtTmp;
	  }
	});	
	window.setTimeout("getCurDate('"+aObjName+"')", 8000);			
}

function AfterLoad()
{
	getCurDate("localdate");
	}

//获取cookie值；
function getCookie(sName)
{
  var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		
		if (encodeURIComponent(sName) == aCrumb[0])
		{
			return decodeURIComponent(aCrumb[1]);
		}
	}
  return null;
}

function LogKeyPress(aFrmObj){//兼容IE和Firefox获得keypress
	var currKey=0,CapsLock=0; 
	var e = arguments[1];
	e=e||window.event; 
	var kCode=e.keyCode||e.which||e.charCode; 
	if(kCode == '13'){
		checkLogin(aFrmObj);
	}
}


function checkLogin(theform) //登录验证；
{
	var username=document.getElementById('username').value;
	var login_pwd=document.getElementById('password').value;
	var gotoUrl = "http://www.77.net/list/";
	try{
		gotoUrl=document.getElementById('gotoUrl').value;
	}catch(e){ ; }
	if(!username){
		alert('Email can not be empty');
		return false;
	}else{
	    if (!emailCheck('username'))
		   return false;
	}
	if(!login_pwd){
		alert('password can not be empty');
		return false;
	}
	var login_id_tem=getCookie('loginreg');
    if(login_id_tem){
			alert('Hello '+username+'! Please choose the server!');
			location.href = gotoUrl;	
	}
	var url = theform.action; 
	var paras='&isMReg=1&act=2&username='+username+'&password='+login_pwd+"&t="+new Date().getTime();
	loginChk(url,paras,gotoUrl);		
	return false;	
}

function loginChk(url,paras) {
	var gotoUrl = arguments[2] ? arguments[2]:"http://www.77.net/list/";
	$.ajax(
    {
		type:"POST",
		url:url,
		data:paras,
        success: function(result)
        {  
			var resCode = result.substring(0,2);
			var resTxt = result.substring(3,result.length);
			resCode = Number(resCode);
			if(resCode==1){
				window.location.href = gotoUrl;
				return true;
			}else {
				alert('Error! Please check you Email and password and try again!');
				return false;
			}
        },
        error:function()
        {
            alert('login has failed!Please check you Email or password!');
            return false;
        }
    });
}

function IsEmpty(v){
	switch (typeof v){
		case 'undefined' : return true;break;
		case 'string' : if(v.length == 0) return true; break;
		case 'boolean' : if(!v) return true; break;
		case 'number' : if(0 === v) return true; break;
		case 'object' :
			if(null === v) return true;
			if(undefined !== v.length && v.length==0) return true;
			for(var k in v)
				{return false;} 
			return true;
			break;
	}
	return false;
}

function MakeServerUrl(asid){
	var uname = unescape(getCookie('login_name'));
	if (!IsEmpty(uname)){
		window.location.href = "http://www.77.net/list/";
		//window.location.href = "http://www.77.net/user/LoginApi.php?act=login&u="+uname+"&sid="+asid;
	}else{
		alert('Please login!');		
	}
}

function MakeChargeUrl(){
	var uname = unescape(getCookie('login_name'));
	if (!IsEmpty(uname)){
		window.location.href = "http://www.77.net/pay/";
	}else{
		alert('Please login!');		
	}
}

function SHPromptDiv(){
	var amsg = arguments[0] ? arguments[0] : "";
	var divObj = document.getElementById('Layer4');
	divObj.innerHTML = '';
	if (amsg==""){
		divObj.style.display ="none";
	}else{
		divObj.innerHTML = amsg;
		divObj.style.display ="block";		
	}
}

function getOpenIDStatus(){
	var url = "http://www.77.net/facebookapi/FBLoginAPI.php"; 
	var paras="?t="+new Date().getTime();
	chkOpenIDStatus(url,paras);	
}
	
function chkOpenIDStatus(url,paras){
	$.ajax({
		type:"POST",
		url:url,
		data:paras,
		success: function(result){  
			var reCode =result.substring(0,2);
			var reTxt = result.substring(3,result.length);	
			if(reCode=='01'){ //注册或登录成功；
				var currUrl = window.location.href ;
				if (currUrl.indexOf("/user/LoginCom/") != -1){  // 控制登录框页面中fb帐号登录后直接进入list页面
					window.location.href = "http://www.77.net/list/";
					return true;
				}
				window.location.href = "http://www.77.net/list/";//登录和注册成功后，直接登录游戏； http://www.77.net/user/LoginApi.php?act=login&sid=1   
				return true;
			}
		},
		error:function(){
				alert('check your openID stats failed!Please check your net status!');
				return false;
		}
	});
}	

function listLogSvrLst(){
	var lstHtml = '';
	var logsvrLstCookie = getCookie('LstLogSvrLst');	
	if (logsvrLstCookie){
		var logSvrLst = logsvrLstCookie.split("_");		
	}
	if (logSvrLst){
		for(i=0;i<logSvrLst.length;i++){
			if (logSvrLst[i] > 0){
				lstHtml += "<li class=\"flflastlogin\"><a href=\"/user/userLogin.php?gameID=1&svrID="+logSvrLst[i]+"\" target=\"_blank\" class=\"whiteA\">SERVER "+logSvrLst[i]+"</a></li><li class=\"flfdays\"></li>";
			}
		}	
	}else{  //取不到值就显示1服的。
		lstHtml += "<li class=\"flflastlogin\"><a href=\"/user/userLogin.php?gameID=1&svrID=1\" target=\"_blank\" class=\"whiteA\">SERVER 1</a></li><li class=\"flfdays\"></li>";		
	}
	try{
		document.getElementById('LogSvrLst').innerHTML = lstHtml;
	}catch(e){;	}	
}
