// JavaScript Document
var xmlHttp;
var objHTML;
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();
 window.location.href=url;
      /* 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="Account created succeed. <br>Wait 3-5 minutes to login<br>Please go to vote for the site,<br> you will get vote point.<br> And you can use the vote point to exchange for Super gears and God.<br><a href=votep.html>Vote for Eternion-wow now</a>.";
			} else if (xmlHttp.responseText == "0") {
        		document.getElementById("username_verdict").innerHTML="This username is used by other player.<br>Please use some else to retry.<br>Good luck!<br><input type=reset value=Retry onclick=window.location.href='Account.html'>";
			} else if (xmlHttp.responseText == "2") {
        		document.getElementById("username_verdict").innerHTML="You've succeed to change your password.<br>Please storage it carefully!";
			} else if (xmlHttp.responseText == "3"){
        		document.getElementById("username_verdict").innerHTML="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 == "") {
		alert("Please make sure that ur password 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 != 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;*/
default :
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
}
if(inputCode != 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,num){ 
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();
}
checkCode.value = code;
}
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;
default :
	name = document.sitevote1.char.value;
	code = document.sitevote1.checkCode.value;	
	inputCode = document.sitevote1.code.value;
	break;
}
if (name == "") {
	alert("please insert u account!");
	return false;
}
if(inputCode != code ){
	alert("please insert into current code!");
	return false;
}
}