$(function(){
	
	/**
     * 确定操作
     */
    $(".okbtn").click(function(){
    	$(".popupmask").hide();
    	WeixinJSBridge.call("closeWindow"); 
    });
    
    /**
     * 提交企业信息资料
     */
    $(".btnclass").click(function(){
    	var organizationId=$("#organizationId").val();
    	var address=$("#address").val();
    	var virtualArchitectureName=$("#virtualArchitectureName").val();
    	var employees=$("#employees").val();
    	var contacts=$("#contacts").val();
    	var phone=$("#phone").val();
    	var regPhone=/^1(3|4|5|7|8)\d{9}$/;
    	if($.trim(address)==""){
   		 layer.open({
     			content : "请输入地址房号",
     			skin : 'msg',
     			time : 2
     		});
   		 	$("#address").focus();
   		 	return;
    	}
    	if($.trim(virtualArchitectureName)==""){
      		 layer.open({
        			content : "请填写公司全称",
        			skin : 'msg',
        			time : 2
        		});
      		 	$("#virtualArchitectureName").focus();
      		 	return;
       	}
    	if($.trim(employees)==""){
     		 layer.open({
       			content : "请填写人数",
       			skin : 'msg',
       			time : 2
       		});
     		 	$("#employees").focus();
     		 	return;
      	}
    	if($.trim(contacts)==""){
    		 layer.open({
      			content : "请输入真实姓名",
      			skin : 'msg',
      			time : 2
      		});
    		 	$("#contacts").focus();
    		 	return;
     	}
    	if($.trim(phone)==""){
   		 layer.open({
     			content : "请输入手机号码",
     			skin : 'msg',
     			time : 2
     		});
   		 	$("#phone").focus();
   		 	return;
    	}
    	var mob_num=/^(\d{3,4}\-)?\d{7,8}$/i;
	    	if(regPhone.test(phone) || mob_num.test(phone)){
	    
		    }else{
		    	layer.open({
	     			content : "手机号码有误，请重新输入",
	     			skin : 'msg',
	     			time : 2
	     		});
	   		 	$("#phone").focus();
	   		 	return;
		    }
	    var contextPath=$("#contextPath").val();
	    var openId=$("#openId").val();
	    $.ajax({
			url:contextPath+"/wechat/property/saveVirtualArchitecture",
			type:"POST",
			data:{organizationId:organizationId,address:address,virtualArchitectureName:virtualArchitectureName,
				employees:employees,contacts:contacts,phone:phone,openId:openId},
			success : function(data) {
				if("success"==data){
		        	$(".popupmask").show();
		        }else{
		        	layer.open({
		     			content : "申请失败，请检查网络",
		     			skin : 'msg',
		     			time : 2
		     		});
		        }
			}, error : function(xhr,textStatus){
				layer.open({
	     			content : "申请失败，请检查网络",
	     			skin : 'msg',
	     			time : 2
	     		})
		    }
	    });
    });
})


