document.write("<script type='text/javascript' src='dwr/interface/Account.js'></script>");
document.write("<script type='text/javascript' src='dwr/engine.js'></script>");
document.write("<script type='text/javascript' src='dwr/util.js'></script>");

function CheckAccount(){
	var account=trim(document.getElementById("txtName").value);
	if(account==""){
		alert("Account can't be blank.");
		return;
	}else{
		if(account.length<6 || account.length>15){
			alert("Account length should be between 6 to 15 characters.");
			return;
		}
		var mac =/^[A-Za-z0-9]+$/;
		if(!account.match(mac)){
			alert("Account can only use numbers and letters.");
			return;
		}
	}
	Account.checkName(account,function(bool){
		if(bool){
			alert("Account has already existed.")
			return;
		}else{
			alert("Account is available.");
			return;
		}
	});
}

function trim(s)   
{   
    try  
    {   
        return s.replace(/^\s+|\s+$/g,"");   
    }   
    catch(e)   
    {   
       return s;   
    }   
}
function flashImg(){
	var timenow = new Date().getTime();
	document.getElementById("Vcode").src="verifyCode.jsp?d="+timenow;
}
function checkNameEmail(){
	acc=document.getElementById("txtAccount").value;
	email=document.getElementById("txtEmail").value;
	pwd=document.getElementById("txtPwd").value;
	if(acc=="" || email=="" || pwd==""){
		alert("Please check the integrality of your input.");
		return;
	}
	Account.checkEmailPwdAcc(acc,email,pwd,function(back){
		if(back!=0){
			Account.getUserInoById(back,function(userdao){
				if(userdao.length>0){
					document.getElementById("txtAccount").readOnly=true;
					document.getElementById("txtEmail").readOnly=true;
					document.getElementById("txtPwd").readOnly=true;
					document.getElementById("btnNext").style.display="none";
					birthday=userdao[0];
					country=userdao[1];
					sex=userdao[2];
					msn=userdao[3];
					name=userdao[4];
					yahoo=userdao[5];
					skype=userdao[6];
					rbsex=document.getElementsByName("rbGender");
					if(sex=="Female"){
						rbsex[1].checked=true;
					}else{
						rbsex[0].checked=true;
					}
					document.getElementById("txtName").value=name;
					document.getElementById("txtBirthday").value=birthday;
					document.getElementById("txtCountry").value=country;
					document.getElementById("txtMsn").value=msn;
					document.getElementById("txtYahoo").value=yahoo;
					document.getElementById("txtSkype").value=skype;
					document.getElementById("showInfo").style.display="inline";
				}else{
					alert("There is an error.");
					return;
				}
			});
		}else{
			alert("Account,password or email error.");
			return;
		}
	});
}

function gotoSum(){
	email1=document.getElementById("txtEmail2").value;
	email2=document.getElementById("txtEmail3").value;
	if(email1!="" || email2!="")
	{
			if(email1!=email2){
				alert("Email not matched.");
				return;
			}else{
				var pattern = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; 
				if(!pattern.test(email1))
				{
					alert("Email format error.");
					return;
				}
			}
	}
	document.getElementById("form1").submit();
}

function addPOPServer(){
		alert("bbs");
	var first=document.getElementById("selServer");
	first.options.length=1;
	var option = new Option("Atom Storm","Atom Storm"); 
	first.options.add(option); 
}

