﻿function createAjax() {//该函数将返回XMLHTTP对象实例
	var _xmlhttp;
	try { 
		_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	}catch (e) {
		try {
   			_xmlhttp=new XMLHttpRequest(); 
		}catch (e) {
			_xmlhttp=false; 
		}
	}
	return _xmlhttp; 
}

function register_check_all(){
	this.country = true;
	this.member = true;
	this.password = false;
	this.c_password = true;
	this.email = false;
	this.first_name = true;
	this.last_name = true;
	this.company_name = false;
	this.address = true;
	this.state = true;
	this.tel =false;
	this.fax = false;
	this.mobile = false;
	this.web = true;
	this.business = true;
	this.buyer_seller = true;
}

var bln_check = new register_check_all();

function check_Email(){
	var str=byId('email').value;
	byId('email_a').style.display='none';
	byId('email_n').style.display='none';
	byId('email_e').style.display='none';
	byId('email_t').style.display='none';	
	byId('email_o').style.display='none';
	if (isEmpty(str)){
		byId('email_n').style.display='block';
		bln_check.email=false;
	}else{
		if (isEmail(str)){
			var xmlhttp1=createAjax(); 
			if (xmlhttp1) { 
				xmlhttp1.open('get','check.asp?action=check_user&email='+str,false);
				xmlhttp1.onreadystatechange=function() { 
					if (xmlhttp1.readyState==4 && xmlhttp1.status==200) {
						//alert(xmlhttp1.responseText);
						if (xmlhttp1.responseText=="success"){
							bln_check.email = false;
							byId('email_t').style.display='block';
						}else if (xmlhttp1.responseText=="failure"){
							bln_check.email = true;
							byId('email_o').style.display='block';
						}
					}
				}
				xmlhttp1.send(null); 
			}		
		}else{
			byId('email_e').style.display='block';
			bln_check.email = false;
		}
	}
}


function check_password(){
	var str=byId('password').value;
	var Modes=0;
	byId('password_a').style.display='none';
	byId('password_e').style.display='none';
	byId('password_o').style.display='none';
	if (isEmpty(str)){
		byId('password_a').style.display='block';
		bln_check.password = false;		
	}else if(str.length<6||str.length>15){
		byId('password_e').style.display='block';
		bln_check.password = false;
	}else{
		if(inNum(str))Modes++;
		if(inLetter(str))Modes++;
		if(inChar(str))Modes++;
		if (Modes==1){
			byId('spanbar').style.width="33%";
			byId('password_o').style.display='block';
		}else if (Modes==2){
			byId('spanbar').style.width="66%";
			byId('password_o').style.display='block';	
		}else if (Modes==3){
			byId('spanbar').style.width="100%";
			byId('password_o').style.display='block';	
		}else{
			byId('spanbar').style.width="0px";
		}	
		bln_check.password = true;
	}
}


function check_c_password(){
	var str=byId('c_password').value;
	byId('passwordc_a').style.display='none';
	byId('passwordc_e').style.display='none';
	byId('passwordc_o').style.display='none';
	if(str.length<6||str.length>15){
		byId('passwordc_a').style.display='block';
		bln_check.c_password = false;	
	}else if(str==byId('password').value&&str!=""){
		byId('passwordc_o').style.display='block';
		bln_check.c_password = true;
	}else{
		byId('passwordc_e').style.display='block';
		bln_check.c_password = false;		
	}
}


function check_o_password(){
	var str=byId('o_password').value;
	byId('passwordo_a').style.display='none';
	byId('passwordo_e').style.display='none';
	byId('passwordo_o').style.display='none';
	if (isEmpty(str)){
		byId('passwordo_a').style.display='block';
		bln_check.o_password = false;
	}else{
		var xmlhttp1=createAjax(); 
		if (xmlhttp1) { 
			xmlhttp1.open('get','check.asp?action=check_password&password='+str,true);
			xmlhttp1.onreadystatechange=function() { 
				if (xmlhttp1.readyState==4 && xmlhttp1.status==200) {
					if (xmlhttp1.responseText=="success"){
						byId('passwordo_o').style.display='block';
						bln_check.o_password = true;
					}else if (xmlhttp1.responseText=="failure"){
						byId('passwordo_e').style.display='block';
						bln_check.o_password = false;
					}
				}
			}
			xmlhttp1.send(null); 
		}		
	}
}


function check_first_name(){
	byId('first_name_e').style.display='none';
	byId('first_name_o').style.display='none';	
	var str=byId('first_name').value;
	if((!/[a-zA-Z\.\_\s0-9]+$/.test(str))||(!/[x00-xff]+/.test(str))||str.length < 1||str.length > 100 ){
		bln_check.first_name = false;
		byId('first_name_e').style.display = 'block';
	}else{
		bln_check.first_name = true;
		byId('first_name_o').style.display = 'block';
	}
}

function check_last_name(){
	byId('last_name_e').style.display='none';
	byId('last_name_o').style.display='none';		
	var str=byId('last_name').value;
	if((!/[a-zA-Z\.\_\s0-9]+$/.test(str))||(!/[x00-xff]+/.test(str))||str.length < 1||str.length > 100 ){
		bln_check.last_name = false;
		byId('last_name_e').style.display = 'block';
	}else{
		bln_check.last_name = true;
		byId('last_name_o').style.display = 'block';
	}
}


function check_Company(){
	var str=byId('company_name').value;
	byId('company_a').style.display='none';
	byId('company_e').style.display='none';
	byId('company_o').style.display='none';
	if (isEmpty(str)){
		byId('company_a').style.display='block';
		bln_check.company_name=false;
	}else{
		var xmlhttp1=createAjax(); 
		if (xmlhttp1) { 
			xmlhttp1.open('get','check.asp?action=check_company&company='+str,false);
			xmlhttp1.onreadystatechange=function() { 
				if (xmlhttp1.readyState==4 && xmlhttp1.status==200) {
					if (xmlhttp1.responseText=="success"){
						byId('company_e').style.display='block';
						bln_check.company_name = false;
					}else if (xmlhttp1.responseText=="failure"){
						byId('company_o').style.display='block';
						bln_check.company_name = true;
					}
				}
			}
			xmlhttp1.send(null); 
		}		
	}
}





function check_tel() {
	byId('tel_e').style.display='none';
	byId('tel_o').style.display='none';	
	if (isInteger(byId('tel_1').value)&&isInteger(byId('tel_2').value)&&isInteger(byId('tel_3').value)){
		byId('tel_o').style.display='block';
		bln_check.tel = true;
	}else{
		byId('tel_e').style.display='block';
		bln_check.tel = false;
	}
}

function check_fax() {
	byId('fax_e').style.display='none';
	byId('fax_o').style.display='none';	
	if (isInteger(byId('fax_1').value)&&isInteger(byId('fax_2').value)&&isInteger(byId('fax_3').value)){
		byId('fax_o').style.display='block';
		bln_check.fax = true;
	}else{
		byId('fax_e').style.display='block';
		bln_check.fax = false;
	}
}


function check_business(){
	byId('business_o').style.display='none';
	byId('business_e').style.display='none';
	obj=document.getElementsByName("business1");
	byId("business").value="";
    if(obj!=null){
        var i,j;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                byId("business").value= document.getElementById("business").value+obj[i].value+"/"; 
            }
        }
    }
	if(isEmpty(byId("business").value)){
		byId('business_e').style.display='block';
		bln_check.business = false;
	}else{
		byId('business_o').style.display='block';
		bln_check.business = true;
	}
}















function check_buy(){
	var buyer_seller_id = $('buyer_seller').value;
	if (buyer_seller_id!=''){
		bln_check.buyer_seller = true;
		$('info_buyer_seller').style.display='none';
	}
	else {
		bln_check.buyer_seller = false;
		$('info_buyer_seller').style.display='block';
	}
}


function check_focus(id) {
	var obj = $(id);
	if (obj.value == "country code") {
		obj.focus();
		obj.select();
	}
}



function check_selbuy(){
obj=document.getElementsByName("selbuy");
    if(obj!=null){
        var i,j;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                j= obj[i].value;            
            }
        }
    }
if (j==0){
$('seller').style.display='none';
$('buyer').style.display='';
}else{
if (j==1){
$('seller').style.display='';
$('buyer').style.display='none';
}else{
	if (j==2){
$('seller').style.display='';
$('buyer').style.display='';
	}
}
}
}


function sellerselect(){
obj=document.getElementsByName("seller");
document.getElementById("sellers").value="";
    if(obj!=null){
        var i,j;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                document.getElementById("sellers").value= document.getElementById("sellers").value+obj[i].value+"/"; 
            }
        }
    }
}
function buyerselect(){
obj=document.getElementsByName("buyer");
document.getElementById("buyers").value="";
    if(obj!=null){
        var i,j;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                document.getElementById("buyers").value= document.getElementById("buyers").value+obj[i].value+" / "; 
            }
        }
    }
}



function on_submit(){
	check_Email();
	check_password();
	check_c_password();
	check_first_name();
	check_last_name();
	check_Company();
	check_tel();
	check_fax();
	check_business();
	if( bln_check.password == true && bln_check.c_password == true && bln_check.email == true && bln_check.first_name == true && bln_check.last_name == true && bln_check.company_name == true && bln_check.tel == true && bln_check.fax == true && bln_check.business == true){
		return true;
	}else{
		return false;
	}	
}



