function getXMLR(){ 
	var xmlhttp,alerted ;
	try { 
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") 
	} catch (e) { 
		try { 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") 
		} catch (e) { 
			alert("please install Microsofts XML parsers") 
		} 
	} 
	if (!xmlhttp && !alerted) { 
		try { 
			xmlhttp = new XMLHttpRequest(); 
		} catch (e) { 
			alert("Your browser isn\'t sport XMLHttpRequest£¬please update."); 
		} 
	} 
	return xmlhttp; 
} 


function getDATA(name){
var xmlhttp = getXMLR(); 
	if (xmlhttp){ 
		var gotourl = 'check_username.asp?name=' + name; 
		xmlhttp.Open("POST",gotourl,false);
		xmlhttp.send();
		if (xmlhttp.readyState==4){ 
			if(parseInt(xmlhttp.responseText)==1){
				document.getElementById('u_words').innerHTML = "Congratulations,you can use it!";
				document.getElementById('u_words').className='color_green';
				return true;
			}else{
				document.getElementById('u_words').innerHTML = "Sorry,the account has been used!";
				document.getElementById('u_words').className='color_red';
				return false;
			}
		}
	} 
}

function checkform(){
	if(!check_username()){
		alert('Username is wrong,please check it.');
		reg.User_account.focus();
		return false;
	}	
	if(!reg.User_password.value){
		alert('Please enter password.');
		reg.User_password.focus();
		return false;
	}
	if(reg.check_password.value != reg.User_password.value){
		alert('Password is wrong,please check it.');
		reg.check_password.focus();
		return false;
	}
	
	if(!reg.User_truename.value){
		alert('Please enter your whole name.');
		reg.User_truename.focus();
		return false;
	}
	if(!check_mail('User_mail','mail_words')){
		alert('E-mail is unlawful,please check it.');
		reg.User_mail.focus();
		return false;
	}
	if(!check_phone('User_telphone','p_words','telphone')){
		alert('Telphone is unlawful,please check it.');
		reg.User_telphone.focus();
		return false;
	}
	if(!check_phone('User_fax','f_words','Fax')){
		alert('Fax is unlawful,please check it.');
		reg.User_fax.focus();
		return false;
	}
	return true;
}

function check_username(){
	if(reg.User_account.value){
		var name=reg.User_account.value
		var re=/[^A-Za-z0-9_]/g
		if (re.test(name))
		{
			name=name.match(re)
			document.getElementById('u_words').innerHTML = "Warning,the account is unlawful,account must make from English, numbers, underline!<br />error words:"+name;
			document.getElementById('u_words').className='color_red';
			return false
		}
		document.getElementById('u_words').innerHTML="Account checking..."
		return getDATA(name);
	}else{
		document.getElementById('u_words').innerHTML="* Please enter account!"
		document.getElementById('u_words').className='color_red';
		return false;
	}
}

function check_mail(obj,wordId){
	var obj=eval("document.reg."+obj);
	Id=document.getElementById(wordId);
	var str=new String(obj.value);
	if(str==""){
		Id.innerHTML="* Please enter your E-mail";
		Id.className="color_red";
		return false;
	}
	var re=/[A-Za-z0-9_-][@{1}][A-Za-z0-9_-]{2,}[.{1}][A-Za-z0-9_-]{2,}/;
	if(!re.test(str)){
		Id.innerHTML="* Your E-mail is unlawful!";
		Id.className="color_red";
		return false;
	}else{
		Id.innerHTML="E-mail check passed.";
		Id.className="color_green";
		return true;
	}
}

function check_phone(obj,wordId,title){
	var obj=eval("document.reg."+obj);
	Id=document.getElementById(wordId);
	var str=new String(obj.value);
	if(str==""){
		Id.innerHTML="* Please enter your "+title+".";
		Id.className="color_red";
		return false;
	}
	var re=/[^0-9-]/;
	if(re.test(str)){
		Id.innerHTML="* Your "+title+" is unlawful!";
		Id.className="color_red";
		return false;
	}else{
		Id.innerHTML=title+" Check passed.";
		Id.className="color_green";
		return true;
	}
}

