$(function(){
    var words=[];
	words['store_address'] = [' ', '地址输入正确', '请输入贵公司经营地址，方便客户找到您的商铺', '最多可输入30个字', '建议您使用中文填写具体地址']
	words['province_id'] = [' ', '地址选择正确', '请选择贵公司所在地址'];
//	words['channelid'] = [' ', '主营行业选择正确', '请选择贵公司主营行业'];
//	words['topcate'] = [' ', '主营行业选择正确', '请选择贵公司主营行业'];
    words['mobile'] = [' ', '手机号码输入正确', '手机号码长度有误', '只能为数字，请您重新填写', '请输入手机号码'];
//    words['facsimile'] = [' ', '传真输入正确', '传真号码长度有误', '请输入数字，如0356-12345678', '请输入数字，如0356-12345678'];
    words['name'] = [' ', '输入正确', '请您输入联系人真实姓名，最多可输入7个字', '请您输入联系人真实姓名，最多可输入7个字', '建议您使用中文填写具体联系人姓名', '请填写您的真实姓名，以便能及时为您提供服务'];
    words['position'] = [' ', '输入正确', '请您输入职务，最多可输入7个字', '最多可输入7个字', '您的职务输入不符合规范'];
    words['phone'] = [' ', '电话输入正确', '号码长度有误', '请输入数字，如0356-12345678', '请输入区号和号码，如0356-12345678'];
    words['swqq'] = [' ', 'QQ输入正确', 'QQ号码长度有误', '请输入数字，如12345678', '请输入数字，如12345678'];
//    words['type'] = [' ', '选择正确','请选择公司类型'];
//    words['mail'] = [' ', '邮箱输入正确', '请输入邮箱', '请输入正确的邮箱'];
//    words['agr'] = [' ', '感谢您的阅读','请详细查看用户协议和版权说明，如有疑问，欢迎反馈给我们'];
	var error = 0;

//	
//	$(":checkbox[@name=agr]").click(function(){
//        notice(this.name, this.checked ? 1 : 2);
//    });
//	
	$("input[@name=store_address]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
        if (value==''){
            notice(n, 2);
        } else if (number(value)){ 
            notice(n, 4);
        } else if (len(value)>30){ 
            notice(n, 3);
        } else {
			notice(n, 1);
        }
    });
	
	function province_id_change() {
		var a = $("select[@name=province_id]");
		notice(a.attr('name'), a.attr('value') !=0 ? 1 : 2);
	}

	$("select[@name=province_id]").change(function(){
		province_id_change();
    });
	
//	function channelid_change() {
//		var c = $("select[@name=channelid]");
//		notice(c.attr('name'), c.attr('value') !=0 ? 1 : 2);
//	}
	
//	$("select[@name=channelid]").change(function(){
//        channelid_change();
//    });
	
//	function topcate_change() {
//		var z = $("select[@name=topcate]");
//		notice(z.attr('name'), z.attr('value') !=0 ? 1 : 2);
//	}
//	
//	$("select[@name=topcate]").change(function(){
//		topcate_change();
//    });
	
	$("input[@name=mobile]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
		if (value !==''){
			if (len(value)<8 || len(value)>15) {
				notice(n, 2);
			}else if (!number(value)) {
				notice(n, 3);
			}else {
				notice(n, 1);
			}
		} else {
			notice(n, 0);
		}
        
    });
//	$("input[@name=facsimile]").blur(function(){
//		var n = this.name;
//		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
//		if (value !==''){
//			if (len(value)<8 || len(value)>23) {
//				notice(n, 2);
//			}else if (!number(value)) {
//				notice(n, 3);
//			}else {
//				notice(n, 1);
//			}
//		} else {
//			notice(n, 0);
//		}
//    });
	$("input[@name=phone]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
		var aa = this.value.replace(/-/g, '');
		if (!number(aa)) {
			notice(n, 3);
		}else {
			if (!number(value)) {
				notice(n, 3);
			}else if (len(value)<8 || len(value)>23) {
				notice(n, 2);
			}else {
				notice(n, 1);
			}
		}
    });

	$("input[@name=swqq]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
		var aa = this.value.replace(/-/g, '');
		if (!number(aa)) {
			notice(n, 3);
		}else {
			if (!number(value)) {
				notice(n, 3);
			}else if (len(value)<4 || len(value)>13) {
				notice(n, 2);
			}else {
				notice(n, 1);
			}
		}
    });

	$("input[@name=name]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
        if (value==''){
            notice(n, 2);
        } else if (number(value)){ 
            notice(n, 4);
        } else if (len(value)>7){ 
            notice(n, 3);
        } else {
			notice(n, 1);
        }
    });
	
	$("input[@name=position]").blur(function(){
		var n = this.name;
		var value = this.value.replace(/((^\s+)|(\s+$))/g, '');
        if (value==''){
            notice(n, 2);
        } else if (len(value)>7){ 
            notice(n, 3);
        } else if (number(value)) {
			notice(n, 4);
		} else {
			notice(n, 1);
        }
    });
	

    function len(word){
        return word.replace(/ |　/ig, '').length;
    }
	function number(val){
		return /^[\d\-]+$/.test(val)
	}
    function notice(pos, n){
        var target = $("p[@name=notice_"+pos+"]");
        target.html(words[pos][n]);
        if (n>1){
            target.attr({className:'check_error'});
            target.show();
        } else if(n==1) {
            target.attr({className:'check_right'});
            target.show();
        } else if( n == 0) {
        	target.attr({className:'check_right'});
        	target.hide();
        }
    }
    $("form").submit(function(){
		checka();
		if (($("p.check_error").length>0)){
			return false;
        } else {
            return true;
        }
    });
//    
//    function chktype() {
//    	var t = $(':radio[name=type]');
//    	var checked = false;
//    	$(':radio[name=type]').each(function() {
//    		if (this.checked) {
//    			checked = true;
//    			return;
//    		}
//    	})
//    	if(checked == false){
//    		notice('type', 2);
//    	}else{
//    		notice('type', 0);
//    	}
//    }

//    $(':radio[name=type]').change(function(){
//    	chktype();
//    });
//    
//    $("input[@name=mail]").blur(function(){
//        var n = this.name;
//        if (this.value==''){
//            notice(n, 2);
//        } else if (!/^[\w-+\.]+@([\w-]+\.)+[\w-]{2,}$/i.test(this.value)){ 
//            notice(n, 3);
//        }else {
//			notice(n, 1);
//		}
//    });
//
	function checka() {
		//$("input[@name=cname]").blur();
		$("input[@name=store_address]").blur();
		$("input[@name=phone]").blur();
		$("input[@name=swqq]").blur();
		$("input[@name=name]").blur();
		$("input[@name=position]").blur();
		province_id_change();
//		chktype();
//		if(checktype == 1){
//			channelid_change();
//		}else if(checktype == 2){
//			topcate_change();
//		}
	}

})

