function Check_service_center(){
	this.str_onlick_submit_2	= false;
	this.str_country_id		= false;	
	this.str_province_id		= true;	
	this.str_cu_username	= true;	
	this.str_cu_company_name	= false;	
	this.str_cu_email		= false;	
	this.str_cu_tel			= false;	
	this.str_cu_subject		= false;	
	this.str_cu_content		= false;	
	this.str_cu_person		= false;
}

var Check_service_center = new Check_service_center();

function Client_service_center(method, url) {
	var ajax = new HttpRequest(method, url);
	var request;
	var images_right = '<img src="../../images/right.gif" alt="error"/>';
	var images_error = '<img src="../../images/error.gif" alt="error"/>';
	function post(callback,param){
		request = ajax.init();
		ajax.post(request,callback,param);
    }

	/***************改变省市***********************/
	this.change_country = change_country ;
	function change_country(){
		var country_id = ajax.Trim(ajax.$('str_country_id').value);
		if ( country_id==0 || country_id=="" ){
			ajax.$("str_country_id_tip").innerHTML = images_error+LANG_ARRAY_TRADELEADS['SELECTED_COUNTRY_AREA'];
			Check_service_center.str_country_id = false;

			ajax.$("hidden_str_province_id").value = "0";
			Check_service_center.str_province_id = true;
			ajax.$("str_province_id_option").innerHTML = '' ; 
			ajax.$("str_province_id_option_tip").style.display="none";//不显示省份选项
			ajax.$("str_province_tip").style.display="none";//不显示	(省份)			
			Check_service_center.str_onlick_submit_2 = false;		
			return false;
		}else{
			ajax.$("str_country_id_tip").innerHTML = images_right;
			Check_service_center.str_country_id = true;	
			
			if ( Check_service_center.str_onlick_submit_2 && Check_service_center.str_country_id && Check_service_center.str_province_id ){
				Check_service_center.str_onlick_submit_2 = false;
				return false;
			}	

			var param = "&str_action=change_area&str_country_id="+country_id;
			param+= "&str_province_id="+ajax.$('hidden_str_province_id').value;
			//alert("first" + ajax.$('hidden_str_province_id').value);
			post(country_result,param);		
		}
	}
	var country_result = function (){
		if ( request.readyState==4 ){
			if ( request.responseText==0 ) {	
				ajax.$("hidden_str_province_id").value = "0";
				Check_service_center.str_province_id = true;
				ajax.$("str_province_id_option").innerHTML = '' ; 
				ajax.$("str_province_id_option_tip").style.display="none";//不显示省份选项
				ajax.$("str_province_tip").style.display="none";//不显示	(省份)					
				return false;
			}	
			ajax.$("hidden_str_province_id").value = "1";
			Check_service_center.str_province_id = false;
			ajax.$("str_province_id_option").innerHTML = request.responseText ; 
			ajax.$("str_province_id_option").style.color="#000000";
			ajax.$("str_province_id_option_tip").style.display="block";
			ajax.$("str_province_tip").style.display="block";
			ajax.$('str_province_id').onblur  = new Client_service_center('post','contactus.php').change_province;
			ajax.$("str_contact_address_tip").innerHTML = images_error+LANG_ARRAY_TRADELEADS['SELECTED_PROVINCE'];
					//alert("second" + ajax.$('hidden_str_province_id').value);
			change_province();
			return false;				
			request = null;			
		}			
	}
	//省份
	this.change_province = change_province ;
	function change_province (){
		var province_id = ajax.Trim(ajax.$('str_province_id').value);
		if ( province_id==0 || province_id=="" ){
			ajax.$("str_contact_address_tip").innerHTML = images_error+LANG_ARRAY_TRADELEADS['SELECTED_PROVINCE'];
			Check_service_center.str_province_id = false;
			return false;
		}
		ajax.$("str_contact_address_tip").innerHTML = images_right;		
		Check_service_center.str_province_id = true;
	}

    //用户名
    this.check_cu_username = check_cu_username ;
    function check_cu_username(){
    	var cu_username = ajax.Trim(ajax.$('str_cu_username').value);
		if ( cu_username.length > 0 ){
			if ( !ajax.IsEnglighAndNumber(cu_username) ){
				ajax.$("str_cu_username_tip").innerHTML = images_error+LANG_ARRAY_COMPANY['USER_NAME_DETAIL'];
				Check_service_center.str_cu_username = false;
				return false;
			}
			var param = "str_action=change_username&str_cu_username="+cu_username;
			post(username_result,param);	
		}else{
			ajax.$('str_cu_username_tip').innerHTML = '';		
		}
		return true;
    }
	var username_result = function() {
		if(request.readyState==4){ 
			if ( request.responseText==0 ) {	
    			ajax.$("str_cu_username_tip").innerHTML = images_error+LANG_ARRAY_COMPANY['USER_NOT_EXISTS'];//不存在;
				Check_service_center.str_cu_username = false;			
			}else if ( request.responseText==1 ) {	
    			ajax.$("str_cu_username_tip").innerHTML = images_right;
    			Check_service_center.str_cu_username = true; 				
			}else{		
				alert(request.responseText);	
    			Check_service_center.str_cu_username = false; 				
			}	
			return false;				
			request = null;			
		}
	}    

	//验证公司名称
	this.check_cu_company_name = check_cu_company_name;
	function check_cu_company_name(){
		var cu_company_name = ajax.Trim(ajax.$('str_cu_company_name').value);
		if ( cu_company_name.length<4 || cu_company_name=="" || ajax.IsCompanyName(cu_company_name) ){
			ajax.$("str_cu_company_name_tip").innerHTML = images_error+LANG_ARRAY_COMPANY['COMPANY_NAME_EXACTITUDE'];
			Check_service_center.str_cu_company_name = false;
			return false;
		}
		ajax.$('str_cu_company_name_tip').innerHTML = images_right;
    	Check_service_center.str_cu_company_name = true;
    	return true;
	}

	//第一个EMAIL
	this.check_cu_email = check_cu_email ;
	function check_cu_email(){
		var cu_email = ajax.Trim(ajax.$('str_cu_email').value);
		if ( cu_email == "" || !ajax.ValidateEmail(cu_email) ){
    		ajax.$("str_cu_email_tip").innerHTML = images_error+LANG_ARRAY_COMPANY['EMAIL_FAIL'];
    		Check_service_center.str_cu_email = false; 
    		return false;				
		}
		ajax.$('str_cu_email_tip').innerHTML = images_right;
    	Check_service_center.str_cu_email = true;
    	return true;
	}

	//电话号码
	this.check_cu_tel = check_cu_tel ;
	function check_cu_tel(){
		var cu_tel = ajax.Trim(ajax.$('str_cu_tel').value);
		if ( cu_tel.length<1 || !ajax.ValidateTelNo(cu_tel) ){
			ajax.$('str_cu_tel_tip').innerHTML = images_error+LANG_ARRAY_COMPANY['TELEPHONE_FAIL'];
			Check_service_center.str_cu_tel = false ;
			return false;				
		}
		ajax.$('str_cu_tel_tip').innerHTML = images_right;
		Check_service_center.str_cu_tel = true ;	
		return true;	
	}

	//联系人
	this.check_cu_person = check_cu_person ;
	function check_cu_person(){
		var cu_person = ajax.Trim(ajax.$('str_cu_person').value);
		if ( cu_person.length <1 ){
			ajax.$('str_cu_person_tip').innerHTML = images_error+LANG_ARRAY_COMPANY['SELECT_INPUT_NAME'];
			Check_service_center.str_cu_person = false ;
			return false;				
		}
		ajax.$('str_cu_person_tip').innerHTML = images_right;
		Check_service_center.str_cu_person = true ;	
		return true;	
	}

    //地址
    this.check_cu_address = check_cu_address ;
    function check_cu_address(){
    	var cu_address = ajax.Trim(ajax.$('str_cu_address').value);
		if ( cu_address.length > 0 ){
			ajax.$('str_cu_address_tip').innerHTML = images_right;
		}else{
			ajax.$('str_cu_address_tip').innerHTML = '';		
		}
		return true;
    }

	//主题
	this.check_cu_subject = check_cu_subject ;
	function check_cu_subject(){
		var cu_subject = ajax.Trim(ajax.$('str_cu_subject').value);
		if ( cu_subject.length<5){
			ajax.$('str_cu_subject_tip').innerHTML = images_error+LANG_ARRAY_COMPANY['CI_SUBJECT'];
			Check_service_center.str_cu_subject = false ;
			return false;				
		}
		ajax.$('str_cu_subject_tip').innerHTML = images_right;
		Check_service_center.str_cu_subject = true ;	
		return true;	
	}

	//电话号码
	this.check_cu_content = check_cu_content ;
	function check_cu_content(){
		var cu_content = ajax.Trim(ajax.$('str_cu_content').value);
		if ( cu_content.length<10){
			ajax.$('str_cu_content_tip').innerHTML = images_error+LANG_ARRAY_COMPANY['CI_INFO'];
			Check_service_center.str_cu_content = false ;
			return false;				
		}
		ajax.$('str_cu_content_tip').innerHTML = images_right;
		Check_service_center.str_cu_content = true ;	
		return true;	
	}

	this.submit = submit;
	function submit(){
		Check_service_center.str_onlick_submit_2 = true;
		check_cu_username();
		check_cu_company_name();
		check_cu_email();
		check_cu_tel();
		check_cu_person();
		check_cu_address();
		check_cu_subject();
		check_cu_content();
		change_country();
		if(	Check_service_center.str_cu_username && Check_service_center.str_cu_company_name && 
			Check_service_center.str_cu_email && Check_service_center.str_cu_tel && 
			Check_service_center.str_country_id && Check_service_center.str_province_id && 
			Check_service_center.str_cu_subject && Check_service_center.str_cu_content && 
			Check_service_center.str_cu_person 
		){	
		   var param = ajax.form2param(document.getElementsByTagName('*'), Array('submit'));
			param+= '&str_action=do_submit';
			post(submit_result,param);
			ajax.$('do_submit').disabled = true;
		}else{
			alert(LANG_ARRAY_COMPANY['DO_SUBMIT_SHOW']);//信息不完整
			return false;
		}		
	}
	var submit_result = function() {
		if(request.readyState==4){
			//alert(request.responseText);return false;
			if ( request.responseText==2 ){
				alert(LANG_ARRAY_COMPANY['DO_SUBMIT_SHOW']);//信息不完整
			}else if ( request.responseText==1 ) {
				alert(LANG_ARRAY_COMPANY['DO_SUBMIT_SUCCEED']); //提交成功!
				window.location.href="/help/contactus.shtml"; 
			}else{
				alert(LANG_ARRAY_COMPANY['DO_SUBMIT_FAIL_SHOW']);//提交失败,请与我们联系
			}
			ajax.$('do_submit').disabled = false;
			return false;				
			request = null;			
		}
	}		
	
	//页面加载时
	this.page_load = page_load ;
	function page_load(){ 
		var cbi_id = ajax.$('hidden_cbi_id').value;
		if ( cbi_id ){
			new Client_service_center('post','contactus.php').check_cu_username();
			new Client_service_center('post','contactus.php').check_cu_company_name();
			new Client_service_center('post','contactus.php').check_cu_email();
			new Client_service_center('post','contactus.php').check_cu_tel();
			new Client_service_center('post','contactus.php').check_cu_person();
			new Client_service_center('post','contactus.php').check_cu_address();
			new Client_service_center('post','contactus.php').change_country();
		}
	}

	this.bind = bind;
	function bind() {
		ajax.$('str_cu_username').onblur  = new Client_service_center('post','contactus.php').check_cu_username;	
		ajax.$('str_cu_company_name').onblur  = new Client_service_center('post','contactus.php').check_cu_company_name;	
		ajax.$('str_cu_email').onblur  = new Client_service_center('post','contactus.php').check_cu_email;	
		ajax.$('str_cu_tel').onblur  = new Client_service_center('post','contactus.php').check_cu_tel;	
		ajax.$('str_cu_person').onblur  = new Client_service_center('post','contactus.php').check_cu_person;	
		ajax.$('str_cu_address').onblur  = new Client_service_center('post','contactus.php').check_cu_address;	
		ajax.$('str_cu_subject').onblur  = new Client_service_center('post','contactus.php').check_cu_subject;	
		ajax.$('str_cu_content').onblur  = new Client_service_center('post','contactus.php').check_cu_content;	
		ajax.$('str_country_id').onblur  = new Client_service_center('post','contactus.php').change_country;	
		//ajax.$('do_submit').onclick = new Client_service_center('post','contactus.php').submit(); 
	}
//
}