
function InitAjax()
{ 
	var ajax=false; 
	try { 
		ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) { 
		try { 
			ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
		} catch (E) { 
			ajax = false; 
		}
	}
	if (!ajax && typeof XMLHttpRequest!='undefined') { 
		ajax = new XMLHttpRequest(); 
	}

	return ajax;
}


var xmlHttp; 

function createXMLHttpRequest()
{ 
	if (window.ActiveXObject)
	{ 
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}  
	else if(window.XMLHttpRequest)
	{ 
		xmlHttp = new XMLHttpRequest();
	} 
} 

function handleStateChange()
{ 
	if(xmlHttp.readyState == 4)
	{ 
		if(xmlHttp.status == 200)
		{ 
			//alert(xmlHttp.responseText);
			eval(xmlHttp.responseText);
		} 
	} 
}

function AjaxLogin()
{ 
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;

	var username = document.getElementById('username2').value;
	var password = document.getElementById('password2').value;
	var url = "username="+username+"&password="+password+"&time="+new Date().getTime();
	var qurl = "/ajax.php?AjaxType=login&"+url;
	
	xmlHttp.open("GET", qurl, true);
	xmlHttp.send(null);
	//setTimeout("AjaxLogin()",2000);
}
function AjaxLogin_new()
{ 
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;

	var username = document.getElementById('username2').value;
	var password = document.getElementById('password2').value;
	var url = "username="+username+"&password="+password+"&time="+new Date().getTime();
	var qurl = "/ajax.php?AjaxType=newlogin&"+url;
	
	xmlHttp.open("GET", qurl, true);
	xmlHttp.send(null);
	//setTimeout("AjaxLogin()",2000);
}
function newusercheck()
{ 
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;

	var pcode = document.getElementById('pcode').value;
	var url = "pcode="+pcode+"&time="+new Date().getTime();
	var qurl = "/ajax.php?AjaxType=newusercheck&"+url;
	
	xmlHttp.open("GET", qurl, true);
	xmlHttp.send(null);
	//setTimeout("AjaxLogin()",2000);
}


function AjaxLogout()
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	
	var qurl = "ajax.php?AjaxType=logout&time="+new Date().getTime();;
	
	xmlHttp.open("GET", qurl, true);
	xmlHttp.send(null);
	
	//setTimeout("AjaxLogin()",2000);
}

function AjaxLoginResponse(Status)
{
	switch(Status)
	{
		case 1:		// ????
			ShowHideUserInfo(1);
		  break;
		case 2:		// ??????
			ShowHideUserInfo(0);
		
			document.getElementById("username2").select();
			document.getElementById("username2").focus();
			
			alert("User: \"" + document.getElementById("username2").value + "\" doesn't exists!");
		  break;
		case 3:		// ????
			ShowHideUserInfo(0);
		
			document.getElementById("password2").select();
			document.getElementById("password2").focus();
			
			alert("Password error!");
		  break;
	}
}
function AjaxLoginResponse_new(Status)
{
	switch(Status)
	{
		case 1:		// ????
		//	ShowHideUserInfo(1);
		  break;
		case 2:		// ??????
		//	ShowHideUserInfo(0);
		
			document.getElementById("username2").select();
			document.getElementById("username2").focus();
			
			alert("User: \"" + document.getElementById("username2").value + "\" doesn't exists!");
		  break;
		case 3:		// ????
		//	ShowHideUserInfo(0);
		
			document.getElementById("password2").select();
			document.getElementById("password2").focus();
			
			alert("Password error!");
		  break;
	}
}
// ??????????
function ShowHideUserInfo(UserLogin)
{
	var divUserLogin = document.getElementById("divUserLogin");
	var divUserInfo = document.getElementById("divUserInfo");
	var divUserLoading = document.getElementById("divUserLoading");
    var divUserLogining = document.getElementById("divUserLogining");
	
	if(UserLogin)
	{
		divUserLoading.style.display = "none";
		divUserLogin.style.display = "none";
		divUserLogining.style.display = "none";
		divUserInfo.style.display = "";
	}
	else
	{
		divUserLoading.style.display = "none";
		divUserLogining.style.display = "none";
		divUserInfo.style.display = "none";
		divUserLogin.style.display = "";
	}
}

// ??????
function CheckLoginForm(form)
{
	var username = form.username;
	var password = form.password;
	//var re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	
	if(username.value.length == 0)
	{
		alert("Please input your e-mail first!");
		username.select();
		username.focus();
		return false;
	}
	
	if(!re.test(username.value))
	{
		alert("E-mail format Error!");
		username.select();
		username.focus();
		return false;
	}

	if(password.value.length == 0)
	{
		alert("Please input your password!");
		password.select();
		password.focus();
		return false;
	}
	
	return true;
}

// ??????
function SubmitLoginForm(form)
{

	if(CheckLoginForm(form)==false) return false;
		divUserLogining.style.display = "";
	divUserLogin.style.display = "none";
	AjaxLogin();
}
function SubmitLoginForm_new(form)
{

	if(CheckLoginForm(form)==false) return false;

	AjaxLogin_new();
}
//??????
function userview(k)
{ 
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
    str="document.getElementById('viewid"+k+"').value;";
	var view_id = eval(str);
	var url = "view_id="+view_id+"&time="+new Date().getTime();
	var qurl = "/ajax.php?AjaxType=userview&"+url;
	
	xmlHttp.open("GET", qurl, true);
	xmlHttp.send(null);
	//setTimeout("AjaxLogin()",2000);
}
function gameclass(n)
{ 
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
   	//var j_group=document.getElementById("game").value;
	var url = "j_group="+n+"&time="+new Date().getTime();
	var qurl = "ajax.php?AjaxType=class&"+url;
		xmlHttp.open("GET", qurl, true);
		xmlHttp.send(null);
	
}
function right_redirect()
{
  var type=document.getElementById('right_type').value;
  
  var g_name=document.getElementById('right_pro_game').value;
  if(type=='no'){
  alert('Please Select The Type');
  return false;
  }
  window.location.href='/fast-order.php?type='+type+'&g_name='+g_name;
}
//-->
