Ext.onReady(function(){
	Ext.QuickTips.init();
	
	var comname = new Ext.form.TextField({
        allowBlank:false,
        minLength :3,
        maxLength :20,
        blankText:'请输入公司名称'
  });
  comname.applyTo('comname');
  
	var comename = new Ext.form.TextField({
        allowBlank:false,
        blankText:'请输入公司英文名称'
  });
  comename.applyTo('comename');

  var certCode = new Ext.form.NumberField({
        allowBlank:false,
        minLength :4,
        maxLength:4,
        blankText:'请输入验证码'
  });
  certCode.applyTo('certCode');

  var isUserid = new Ext.form.TextField({
        allowBlank:false,
        minLength :4,
        maxLength :20,
        blankText:'请输入用户名'
  });
  isUserid.applyTo('isUserid');
  
  //var Password = new Ext.form.TextField({
  //      allowBlank:false,
  //      minLength :6,
  //      maxLength :20,
  //      blankText:'请输入密码'
  //});
  //Password.applyTo('Password');
  var isPassword = new Ext.form.TextField({
        allowBlank:false,
        minLength :6,
        maxLength :20,
        blankText:'请输入确认密码'
  });
  isPassword.applyTo('isPassword');  
  
  var comfirmPassword = new Ext.form.TextField({
        allowBlank:false,
        minLength :6,
        maxLength :20,
        blankText:'请输入确认密码'
  });
  comfirmPassword.applyTo('comfirmPassword');
    
	Ext.get('comname').on('blur', function(){
	var msg0 = Ext.get('msg0');
	var reg_cn=/^[0-9!\@\#\$%^&*()+|\\{}:;?<>`]/gi;  //开头为数字和特殊字符
		if(Ext.get('comname').dom.value==''){
			Ext.MessageBox.alert('信息提示', '公司中文全称不能为空，请输入公司中文全称!');
		}
		if(reg_cn.test(Ext.get('comname').dom.value)){
		  Ext.get('comname').dom.value='';
		  Ext.MessageBox.alert('信息提示', '中文公司名称首字不能为数字或特殊符号，请改正。');
		}else{
		msg0.load({
			url: 'comc_isrepeat.jsp', //换成你的URL
			params: "comname="+encodeURI(encodeURI(Ext.get('comname').dom.value)),
			text: "Updating..."
		});
		msg0.show();
		msg0.highlight();
    format("comc_isrepeat.jsp","comname="+encodeURI(encodeURI(Ext.get('comname').dom.value)));
		}
	});
	
	Ext.get('comename').on('blur', function(){
	    var regen = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;//匹配中文和全角
	    if (regen.test(Ext.get('comename').dom.value)){
	        Ext.get('comename').dom.value='';
          Ext.MessageBox.alert('信息提示', '该栏不能输入中文及全角符号，请改正。');
      }  
	});
	
	
	Ext.get('isUserid').on('blur', function(){
	var msg2 = Ext.get('msg2');
		if((Ext.get('isUserid').dom.value.length<4)||(Ext.get('isUserid').dom.value.length>20)){
			Ext.MessageBox.alert('信息提示', '用户名长度请控制在4-20个字符,请重新输入。');
		}else{
			msg2.load({
			url: 'comuser_isrepeat.jsp', //换成你的URL
			params: "userid="+ encodeURI(encodeURI(Ext.get('isUserid').dom.value)),
			text: "Updating..."
		});
		}
		msg2.show();
		msg2.highlight();
		//msg2.addClass('style1');
		format("comuser_isrepeat.jsp","userid="+ encodeURI(encodeURI(Ext.get('isUserid').dom.value)));
	});
	
	Ext.get('isPassword').on('blur', function(){
		var password=Ext.get('isPassword').dom.value;
		if(password=='') Ext.MessageBox.alert('信息提示', '请输入密码!');
		else if(password.length<6||(password.length>20)){
		  Ext.get('isPassword').dom.value='';
		  Ext.MessageBox.alert('信息提示', '密码长度应控制在6-20个字符，请重新输入!'); 
		}
	});
	
	Ext.get('comfirmPassword').on('blur', function(){
		if(Ext.get('isPassword').dom.value!=Ext.get('comfirmPassword').dom.value){
		    Ext.get('comfirmPassword').dom.value='';
				Ext.MessageBox.alert('信息提示', '密码和确认密码应该保持一致,请重新填写确认密码。');
		}
	});
});
function chk(){
var regcn=/[^\u4E00-\u9FA5]/g;//匹配非中文
if(Ext.get('comname').dom.value==''){Ext.get('comname').focus();return false;}
if(Ext.get('comename').dom.value==''){Ext.get('comename').focus();return false;}
if(Ext.get('certCode').dom.value==''){Ext.MessageBox.alert('信息提示', '请填写验证码。');Ext.get('certCode').focus();return false;}
if(Ext.get('isUserid').dom.value==''){Ext.get('isUserid').focus();return false;}
if(Ext.get('isPassword').dom.value==''){Ext.get('isPassword').focus();return false;}
if(Ext.get('comfirmPassword').dom.value==''){Ext.get('comfirmPassword').focus();return false;}
if(document.getElementById("checkbox").checked==false){Ext.MessageBox.alert('信息提示', '请查看并同意中国机电贸易网入会协议。');return false;}
return ture;
}
var http_request = false;
function format(url,post) {//初始化、指定处理函数、发送请求的函数
  http_request = false;
  //开始初始化XMLHttpRequest对象
  if(window.XMLHttpRequest) { //Mozilla 浏览器
　　http_request = new XMLHttpRequest();
　　if (http_request.overrideMimeType) {//设置MiME类别
　　http_request.overrideMimeType('text/xml');
　　}
  }else if (window.ActiveXObject) { // IE浏览器
　　try {
　　    http_request = new ActiveXObject("Msxml2.XMLHTTP");
　　} catch (e) {
　　    try {
　      　      http_request = new ActiveXObject("Microsoft.XMLHTTP");
　　    } catch (e) {}
　　}
  }
if (!http_request) { // 异常，创建对象实例失败
　　Ext.MessageBox.alert('异常','不能创建XMLHttpRequest对象实例。');
　　return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("post", url, true);
http_request.setrequestheader("cache-control","no-cache");
http_request.setrequestheader("Content-Type","application/x-www-form-urlencoded");
http_request.send(post);
}
// 处理返回信息的函数
function processRequest() {
　　if (http_request.readyState == 4) { // 判断对象状态
　　    if (http_request.status == 200) { // 信息已经成功返回，开始处理信息
		        if((http_request.responseText.indexOf("已经注册")!=-1)&&(http_request.responseText.indexOf("中文")!=-1)) Ext.get('comname').dom.value='';
		        if(http_request.responseText.indexOf("请更换用户名")!=-1) Ext.get('userid').dom.value='';
　　    } else { //页面不正常
　　        Ext.MessageBox.alert('异常','您所验证请求的页面有异常。');
　　    }
　　}
}