// 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 UnstuckCheck(u, p, r, c)
{
	user = u;
	pswd = p;
	realm = r;
	char = c;
	var today = new Date(); 
	objHTML = document.getElementById("username_verdict").innerHTML;
	objHTML = "Loading...";
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}
	var url;
	url="my_unstuck.php";
	url+="?acct="+u+"&pswd="+p+"&realm="+r+"&char="+c;
	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>Account(<font color=#ff0000>"+user+"</font>)has been successfully created.<br>Please wait 2 - 3 minutes, then login.<br>Set realmlist logon.wowge.com!";
			} 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='account.html'>";
			} 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><li>The account has been banned!</li></ul>";
			} else {
        		document.getElementById("username_verdict").innerHTML=objHTML;
			}*/
		
			switch(xmlHttp.responseText)
			{
				case "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='account.html'>";
				break;
				case "1":
				document.getElementById("username_verdict").innerHTML="<br>Account(<font color=#ff0000>"+user+"</font>)has been successfully created.<br>Please wait 2 - 3 minutes, then login.<br>Set realmlist logon.wowge.com!";
				break;
				case "2":
        		document.getElementById("username_verdict").innerHTML="<br>You've succeed to change your password.<br>Please storage it carefully!";
				break;
				case "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>";
				break;
				case "6":
        		document.getElementById("username_verdict").innerHTML="<center><br><font color=#FF9900 size=+1  style=\"font-weight:bold;\">Error!<br>Please try later!.<br>Good luck!<br></font></center>";
				break;
				case "7":
				document.getElementById("username_verdict").innerHTML="<center><br> <font color=#FF9900 size=+1><br><br>ACCOUNT:"+user+"is not existent or password is incorrect!<br/><a href='unstuck.html'>retry</a></font></center>";
				break;
				case "8":
        		document.getElementById("username_verdict").innerHTML="<center><br><font color=#FF9900 size=+1  style=\"font-weight:bold;\">Error!<br>Account and password are correct!.<br>Chcarcter is  incorrect!.<br></font><a href='unstuck.html'>retry</a></center>";
				break;
				case "9":
        		document.getElementById("username_verdict").innerHTML="<center><br> <font color=#FF9900 size=+2>Your character has been summoned to the birth place.Have fun.</font></center>";
				break;
				default:
        		document.getElementById("username_verdict").innerHTML=objHTML;
				break;
			}
	}
    }


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 OnUnstuck()
{
	if (document.unstuck.login.value == "") {
		alert("* Error, You forgot to enter an account name!");
		return false;
	}
	if (document.unstuck.password.value == "") {
		alert("* Error, You forgot to enter  password!");
		return false;
	}
	if (document.unstuck.char.value == "") {
		alert("* Error, You forgot to enter a character name!");
		return false;
	}
	UnstuckCheck(document.unstuck.login.value,document.unstuck.password.value,1, document.unstuck.char.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;
			}
    }
}