// 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>Account (<font color=#ff0000>"+user+"</font>) has been successfully created.<br>Please wait 2 - 3 minutes, then login.<br>Set realmlist <font color=#ff0000>logon.wowolympc.com </font>!";
			} 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>Your account has been banned!</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 SubmitVote(url,form)
{
var code;
var inputCode;
switch(form) {
case "1":
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
case "2":
	code = document.sitevote2.checkCode.value;	
	inputCode = document.sitevote2.code.value;
	break;
case "3":
	code = document.sitevote3.checkCode.value;	
	inputCode = document.sitevote3.code.value;
	break;
case "4":
	code = document.sitevote4.checkCode.value;	
	inputCode = document.sitevote4.code.value;
	break;

case "5":
	code = document.sitevote5.checkCode.value;	
	inputCode = document.sitevote5.code.value;
	break;
default :
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
}
if(inputCode != code ){
	alert("Please insert correct code!");
	return false;
}
var today = new Date();
xmlHttp = GetXmlHttpObject();
if (xmlHttp==null)
	return;
url+="&sn="+today.getTime();
xmlHttp.onreadystatechange=ChangeContX;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function ChangeContX()
{

}

var code = new Array();
function createCode(id){ 
code = "";
var codeLength = 4;//验证码的长度
var checkCode = document.getElementById(id);
checkCode.value = "";

var selectChar = new Array(0,1,2,3,4,5,6,7,8,9);

for(var i=0;i<codeLength;i++) {
   var charIndex = Math.floor(Math.random()*10);
   code +=selectChar[charIndex];
}
if(code.length != codeLength){
   createCode(id);
}
checkCode.value = code;
//alert(document.sitevote3.checkCode3.value);
}
function onVote(form)
{
var code;
var inputCode;

switch(form) {
case "1":
	name = document.sitevote1.char.value;
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
case "2":
	name = document.sitevote2.char.value;
	code = document.sitevote2.checkCode.value;	
	inputCode = document.sitevote2.code.value;
	break;
case "3":
	name = document.sitevote3.char.value;
	code = document.sitevote3.checkCode.value;	
	inputCode = document.sitevote3.code.value;
	break;
	
case "4":
	name = document.sitevote4.char.value;
	code = document.sitevote4.checkCode.value;	
	inputCode = document.sitevote4.code.value;
	break;
	
case "5":
	name = document.sitevote5.char.value;
	code = document.sitevote5.checkCode.value;	
	inputCode = document.sitevote5.code.value;
	break;
default :
	name = document.sitevote1.char.value;
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
}
if (name == "") {
	alert("please insert u character name!");
	return false;
}
if(inputCode != code ){
	alert("please insert into current code!");
	return false;
}
}
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="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> Or your account has been banned!<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;
			}
    }
}