// JavaScript Document
var xmlHttp;
var objHTML;
var user;
var myemail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
return xmlHttp;
}

function usernameCheck(u, p, b, e)
{
		var today = new Date(); 
		user = u;
        objHTML = document.getElementById("username_verdict").innerHTML;
        objHTML = "Loading...";
        xmlHttp = GetXmlHttpObject();
        //var xmlHttp = main.xmlHttp;
        if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}
        var url;
		if (b == 1) {
        url="my_user_reg.php";
        url+="?acct="+u+"&pswd="+p+"&mail="+e;
		} else {
        url="my_Mod_pswd.php";
        url+="?acct="+u+"&pswd="+p+"&newpswd="+e;
		}
	url+="&sn="+today.getTime();
        xmlHttp.onreadystatechange=ChangeCont;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
     
function ChangeCont()
{
    if(xmlHttp.readyState==4)
        {
			if (xmlHttp.responseText == "1") {
        		document.getElementById("username_verdict").innerHTML="<br>Success to create a new account(<font color=#ff0000>"+user+"</font>).<br>Please Login after 1 or 2 minutes.<br>Have a good travel here, boys!";
			} else if (xmlHttp.responseText == "0") {
        		document.getElementById("username_verdict").innerHTML="<br>This username is used by other player.<br>Please use some else to retry.<br>Good luck!<br><input type=button value=Retry onclick=window.location.href='page.php?9'>";
			} else if (xmlHttp.responseText == "2") {
        		document.getElementById("username_verdict").innerHTML="<br>You've succeed to change your password.<br>Please storage it carefully!";
			} else if (xmlHttp.responseText == "3"){
        		document.getElementById("username_verdict").innerHTML="<br>it's might the following make your request refushed:<ul><li>The account doesn't exsit.</li><li>You have submit a wrong password.</li><li>we will delete the accouts who havn't login for 3 monthes. Did you?</li><li>Your new password is the same as the old one.</li></ul>";
			} else {
        		document.getElementById("username_verdict").innerHTML=objHTML;
			}
        }
    }


function OnUserReg()
{
	if (document.reg.login.value == "") {
		alert("Please make sure that ur login is not empty!");
		return;
	}
	if (document.reg.password.value != document.reg.password2.value) {
		alert("Please sure ur [Retype Password] is the same to ur [Retype Password]!");
		return;
	}
	if (document.reg.email.value == "") {
		alert("Please make sure that ur email is not empty!");
		return;
	}
	usernameCheck(document.reg.login.value, document.reg.password.value, 1, document.reg.email.value);
}

function OnModPswd()
{
	if (document.mdpswd.account.value == "") {
		alert("Please make sure that ur [Account Name] is not empty!");
		return;
	}
	if (document.mdpswd.passwordOld.value == "") {
		alert("Please make sure that ur [Old-Password] is not empty!");
		return;
	}
	if (document.mdpswd.passwordNew.value == "") {
		alert("Please make sure that ur [Old-Password] is not empty!");
		return;
	}
	if (document.mdpswd.passwordNew.value != document.mdpswd.passwordNew1.value) {
		alert("Please sure ur [Re-Enter new password] is the same to ur [New-password]!");
		return;
	}
	usernameCheck(document.mdpswd.account.value, document.mdpswd.passwordOld.value, 0, document.mdpswd.passwordNew.value);
}

function GetPswdBack(){
	xmlHttp = GetXmlHttpObject();
	if (document.forgetpass.login.value == "") {
	 alert("Your account name is empty!");
	 return;
	}
	if (document.forgetpass.email.value == "") {
	 alert("Email is empty!");
	 return;
	}
	if(!myemail.test(document.forgetpass.email.value)) {
	 alert("You must have a valid e-mail address");
	 return;
	}
	var today = new Date(); 
	objHTML = document.getElementById("send_mail").innerHTML;
	objHTML = "Loading...";
	if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}
	var url;
	url="my_getbakpass.php";
	url+="?name="+document.forgetpass.login.value +"&email="+document.forgetpass.email.value;
	SendMail(url);
}
function SendMail(url)
{
	var today = new Date(); 
	document.getElementById("send_mail").innerHTML = "Loading...";
	xmlHttp = GetXmlHttpObject();
	//var xmlHttp = main.xmlHttp;
	if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}

	url+="&sn="+today.getTime();
	xmlHttp.onreadystatechange=ChangeContY;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function ChangeContY()
{
    if(xmlHttp.readyState==4)
    {
			if (xmlHttp.responseText == "0") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! Your mail not send!refresh and try again!</font>";
			} else if (xmlHttp.responseText == "1") {
        		document.getElementById("send_mail").innerHTML="We have received your email - please allow upto 5 business days for a reply.";
			} else if (xmlHttp.responseText == "2") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! This mail not send!<br>refresh and try again!</font>";
			}  else if (xmlHttp.responseText == "3") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! This mail not send!<br>The Login Name or your Email is not valid!<br> refresh and try again!</font>";
			}  else if (xmlHttp.responseText == "4") {
        		document.getElementById("send_mail").innerHTML="Success! Your password has been emailed to you!<br/>have good time!";
			}else {
        		document.getElementById("send_mail").innerHTML=xmlHttp.responseText;
			}
    }
}