//This javascript is used to validate username

//generate XMLHttpRequest Object
	var securitycodexmlrequest;
	var securityCodeComponent;//security code component ,it maybe a input component.
	var contextPath;
function newSecurityXMLHttpRequest() {
  var xmlreq = false;  
  if (window.XMLHttpRequest) {  
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
  
    try {    
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");      
    } catch (e1) {
    
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
      }
    }
  }
  return xmlreq;
}
//send a request to server with url
function securitySendRequestToServer(url)
{	//alert(url);
	securitycodexmlrequest=newSecurityXMLHttpRequest();
	securitycodexmlrequest.onreadystatechange=validSecurityCodeCallback;
	securitycodexmlrequest.open("get",url,true);
	securitycodexmlrequest.send(null);
}
//if username is validate then return YES
// if not validate then return NO
function validSecurityCodeCallback(){
	if(securitycodexmlrequest.readyState==4){
		if(securitycodexmlrequest.status==200){
			dealSecurityCodeResponse(securitycodexmlrequest.responseText);
		}
	}
}
function dealSecurityCodeResponse(res){
	if(res=="NO"){
		document.getElementById("securityCodeImg").innerHTML="<img src='"+contextPath+"/servlet/imageCode' height='22'/>";
		securityCodeComponent.value="";
		document.getElementById("10111").style.display="";
	}
}
function validateSecurityCodeIsRight(context,securityComponent){
	securityCodeComponent=securityComponent;
	var code=securityComponent.value;
	contextPath=context;
	if(""==code || null==code){
		return;
	}else{
		var url=contextPath+"/servlet/securitycode?code="+code;
		//alert(url);
		securitySendRequestToServer(url);
	}
}
function setErrorPromptHide(code){
	document.getElementById(code).style.display="none";
}
function setErrorPromptShow(code){
	document.getElementById(code).style.display="";
}

function errorCodeFunction(){
	if(_valid_code!=""){
		if(_valid_code==10110){//验证码错误
			setErrorPromptShow(10110);
		}
		if(_valid_code==10111){//验证码错误
			setErrorPromptShow(10111);
		}
		if(_valid_code==10112){//用户名错误
			setErrorPromptShow(10112);
		}
		if(_valid_code==10210){//profile old pwd not correct.
			setErrorPromptShow(10210);
		}
		if(_valid_code==10211){//profile pre pwd == new pwd.
			setErrorPromptShow(10211);
		}
		
	}
}