var promptMsg = [];
promptMsg['code']=[];
promptMsg['code'][0]='If you can see "check code"clearly,please click to refresh';
promptMsg['code'][1]='check code can not be empty';
promptMsg['code'][2]='check code is incorrect';
promptMsg['code'][3]='waiting，setting up connection...';
promptMsg['account'] = [];
promptMsg['account'][0]='play fun account with the character &quot;g&quot;beginning，please use english（a-z）、number（0-9），suggest 3-5 bits characters';
promptMsg['account'][1]='play fun account can not be empty';
promptMsg['account'][2]='invalid！play fun account with the character&quot;g&quot;beginning，please use english（a-z）、number（0-9），suggest 3-5 bits characters';
promptMsg['account'][3]='waiting，setting up connection...';
promptMsg['account'][4]='sorry,the account you input is used by other person,please choose other to retry';
promptMsg['account'][5]='this account is available';
promptMsg['truename']=[];
promptMsg['truename'][0]="your name must be the same with the awardee's name,otherwise,you can not get the prize";
promptMsg['truename'][1]='name can not be empty';
promptMsg['truename'][2]='invalid！True name is too long,name must be less than 26 bits';
promptMsg['pwd'] = [];
promptMsg['pwd'][0]='please use the english（a-z、A-Z）、number（0-9），suggest 6-8 bits characters';
promptMsg['pwd'][1]='password can not be empty';
promptMsg['pwd'][2]='invalid！Please use the english（a-z、A-Z）、number（0-9），suggest 6-8 bits characters';
promptMsg['pwd'][3]='Safety degree: Weak';
promptMsg['pwd'][4]='Safety degree:Medium';
promptMsg['pwd'][5]='Safety degree:Strong';
promptMsg['pwd2'] = [];
promptMsg['pwd2'][0]='Type again to confrim the password';
promptMsg['pwd2'][1]='confrim password can not be empty';
promptMsg['pwd2'][2]='invalid！Passwords do not match, please check again';
promptMsg['email'] = [];
promptMsg['email'][0]='please type the true Email,your account information will be sent to your e-mail box';
promptMsg['email'][1]='e-mail can not be empty';
promptMsg['email'][2]='e-mail format is incorrect';
promptMsg['phone'] = [];
promptMsg['phone'][0]='please input your contact phone number,mobile and landline';
promptMsg['phone'][1]='telephone number can not be empty';
promptMsg['phone'][2]='invalid！Telephone number must begin by the number，please use the number（0-9）and the line（－）';
promptMsg['prov'] = [];
promptMsg['prov'][0]='input the province';
promptMsg['prov'][1]='province can not empty';
promptMsg['city'] = [];
promptMsg['city'][0]='input the city';
promptMsg['city'][1]='city can not be empty';
//AJAX
function createXMLHttpRequest(http) {
  if(window.ActiveXObject) {
    eval(http+" = new ActiveXObject(\"Microsoft.XMLHTTP\")");
  }
  else if(window.XMLHttpRequest) {
    eval(http+" = new XMLHttpRequest()");
  }
}
function responseAjax(url){
    createXMLHttpRequest("switchHttp");
    switchHttp.onreadystatechange = function handleChange(){
	  if(switchHttp.readyState == 4) {
	    if(switchHttp.status == 200) {
	    	 if(url.substring(0,url.lastIndexOf("."))=="userCheck")
		      	accountInfoChange(switchHttp.responseXML);
		     else if(url.substring(0,url.lastIndexOf("."))=="codeCheck")
		      	codeInfoChange(switchHttp.responseXML);
	    }else {
	      alert("switchHttp.status: "+switchHttp.status);
	    }
  		}
    };
    switchHttp.open("post", url, true);
    switchHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    switchHttp.send(null);
}



function accountInfoChange(doc) {
  if(doc!=null) {
  	 changed=false;
    if(doc.getElementsByTagName("message")[0]!=null)
    {
    	if(doc.getElementsByTagName("message")[0].childNodes[0].nodeValue=="0")
    	{
    		showInfo($("accountinfo"),"account'g"+document.getElementById(["account"]).value+"' "+promptMsg['account'][5],"pass");
    		//showInfo(info,promptMsg[obj.id][3],"pass");
		    return true;
    	}else{
    		showInfo($("accountinfo"),promptMsg['account'][4],"warn");
		    return true;
    	}
    }
  }
}
function codeInfoChange(doc) {
  if(doc!=null) {
  	 //changed=false;
    if(doc.getElementsByTagName("message")[0]!=null)
    {
    	if(doc.getElementsByTagName("message")[0].childNodes[0].nodeValue=="0")
    	{
    		showInfo($("codeinfo"),"","pass");
    		//showInfo(info,promptMsg[obj.id][3],"pass");
		    return true;
    	}else{
    		showInfo($("codeinfo"),promptMsg['code'][2],"warn");
		    return true;
    	}
    }
  }
}
//去掉两边空格
String.prototype.Trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}  
//验证是否为空
function emptyTest(_obj,_info,flag){
	if(flag){
         if(_obj.value.Trim().length == 0){
	            showInfo(_info,promptMsg[_obj.id][1],"warn")
	            return false;
           }else{
           		return true;
           }
    }else{
        showInfo(_info,promptMsg[_obj.id][0],"normal")
        return false;
    }    
} 

//账号合法性分析
function accountTest(s) 
{ 
	var patrn=/^[a-z0-9]{4,6}$/; ///^(\w){4,6}$/ 
	if (!patrn.exec(s)) return false 
	return true 
}
//姓名合法性分析
function truenameTest(s){
	if(s.length<26 && s.length>0)
		return true;
	else
		return false;
}
//密码合法性分析
function pwdTest(s){
	var patrn=/^[A-Za-z0-9]{6,8}$/;
	if (!patrn.exec(s)) return false 
	return true 
}
/******* 密码安全性分析 *******/
//测试某个字符是属于哪一类. 
function CharMode(iN){ 
if (iN>=48 && iN <=57) //数字 
return 1; 
if (iN>=65 && iN <=90) //大写字母 
return 2; 
if (iN>=97 && iN <=122) //小写 
return 4; 
else 
return 8; //特殊字符 
} 

//计算出当前密码当中一共有多少种模式 
function bitTotal(num){ 
modes=0; 
for (i=0;i<4;i++){ 
if (num & 1) modes++; 
num>>>=1; 
} 
return modes; 
} 

//返回密码的强度级别 

function checkStrong(sPW){
if(sPW.length==0)
return -1;//密码为空 
if (!pwdTest(sPW))
return 0; //密码长度不符 
Modes=0; 
for (i=0;i<sPW.length;i++){ 
//测试每一个字符的类别并统计一共有多少种模式. 
Modes|=CharMode(sPW.charCodeAt(i)); 
} 

return bitTotal(Modes); 

} 

/******* 密码安全性分析End *************/
//确认密码合法性分析
function pwd2Test(s){
	if(s==document.formbill.pwd.value)
		return true;
	else
		return false;
}
//电子邮件合法性分析
function emailTest(s){
	 var reg =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	 return reg.test(s);
}
//电话合法性分析
function phoneTest(s){
	//var reg=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
	var reg=/^[0-9-]{4,18}$/;
	return reg.test(s);
	
}
function codeCheck(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(emptyTest(obj,info,flag)){//值不为空
    			showInfo(info,promptMsg[obj.id][3],"warn");
    			responseAjax("codeCheck.jsp?code="+obj.value);
		    return true;
    }
   	return false;
}
var oldStr;//保存之前的说明
var oldStyle;//保存之前的样式
function accountCheck(_obj,flag,tag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(tag){ //来自onblur而非submit
	    if(flag){//失去焦点时
	    	if(!changed)
	    		info.innerHTML = oldStr;
	    		info.className = oldStyle;
	    }else{
	    	oldStr = info.innerHTML;
	    	oldStyle = info.className;
	    }
	}
    if(emptyTest(obj,info,flag)){//值不为空
    	if(accountTest(obj.value)){ //值合法
    		if(changed){
    			showInfo(info,promptMsg[obj.id][3],"warn");
    			responseAjax("userCheck.jsp?account=g"+obj.value);
   			}
		    return true;
    	}else{ //值非法
    		showInfo(info,promptMsg[obj.id][2],"warn");
   			return false;
    	}
    }
   	return false;
}

function truenameCheck(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(emptyTest(obj,info,flag)){//值不为空
    	if(truenameTest(obj.value.Trim())){ //值合法
    		showInfo(info,"","pass");
		    return true;
    	}else{ //值非法
    		showInfo(info,promptMsg[obj.id][2],"warn");
   			return false;
    	}
    }
    return false;
}
function pwdCheck(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
	if(flag){ 
		S_level=checkStrong(obj.value);
		switch(S_level) {
			case -1:
				color="warn";
				break; 
			case 0: 
				color="warn";
				break;
			default: 
				color="pass"
		} 
		showInfo(info,promptMsg[obj.id][S_level+2],color);
		if(S_level==0)
			return false;
		else
			return true; 
	}else{
		showInfo(info,promptMsg[_obj.id][0],"normal");
		return false;
	}
}
function pwd2Check(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(emptyTest(obj,info,flag)){//值不为空
    	if(pwd2Test(obj.value)){ //值合法
    		showInfo(info,"","pass");
		    return true;
    	}else{ //值非法
    		showInfo(info,promptMsg[obj.id][2],"warn");
   			return false;
    	}
    }
    return false;
}
function emailCheck(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(emptyTest(obj,info,flag)){//值不为空
    	if(emailTest(obj.value)){ //值合法
    		showInfo(info,"","pass");
		    return true;
    	}else{ //值非法
    		showInfo(info,promptMsg[obj.id][2],"warn");
   			return false;
    	}
    }
    return false;
}
function phoneCheck(_obj,flag){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(emptyTest(obj,info,flag)){//值不为空
    	if(phoneTest(obj.value)){ //值合法
    		showInfo(info,"","pass");
		    return true;
    	}else{ //值非法
    		showInfo(info,promptMsg[obj.id][2],"warn");
   			return false;
    	}
    }
    return false;
}
function provCheck(_obj){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(obj.value=="please choose province"||obj.value==""){
    	showInfo(info,promptMsg[obj.id][1],"warn");
    	return false;
    }else{
    	showInfo(info,"","pass");
    	return true;
    }
}
function cityCheck(_obj){
	var obj = document.getElementById(_obj.id);
    var info = document.getElementById(_obj.id+"info");
    if(obj.value=="-1"||obj.value==""){
    	showInfo(info,promptMsg[obj.id][1],"warn");
    	return false;
    }else{
    	showInfo(info,"","pass");
    	return true;
    }
}
//显示信息
function showInfo(_info,msg,class_name){
    var info=_info;
    info.innerHTML = msg;
    info.className=class_name;
}