function GetQueryString(name)
{ 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 	
		var r = window.location.search.substr(1).match(reg);  
		var context = ""; 
		if (r != null) 
			 context = r[2]; 
		reg = null; 
		r = null; 
		return context == null || context == "" || context == "undefined" ? "" : decodeURI(context); 
}
var id=GetQueryString("id");
var namePass=false;
var orgPass=false;

$("#name").blur(function(){
	var name=$("#name").val();
	if(name.length==0 && name==""){
		$(".basicmsg1").text("请输入您的真实姓名");
	}else{
		$(".basicmsg1").text("");
		 namePass=true;
	}
});

$("#orgName").blur(function(){
	var num = $(".boxnav li.set span").attr("data-num");
	var org=$("#orgName").val();
	if(org.length==0 && org==""){
		if(num==1){
			$(".basicmsg2").text("请输入您的机构");
		}else if(num==2){
			$(".basicmsg2").text("请输入您的企业");
		}else{
			$(".basicmsg2").text("请输入您的高校");
		}
		
	}else{
		$(".basicmsg2").text("");
		orgPass=true;
	}
});
	
$("#saveProfessor").on("click",	function() {
	
	var $data = {};
	$data.name = $("#name").val();				
	$data.orgName = $("#orgName").val();//机构名称
	$data.title = $("#title").val();//职称
	$data.office = $("#office").val();//职位
	$data.department = $("#department").val();//部门
	var province = $("#Province input[name=cho_Province]").val();
	var address = $("#City input[name=cho_City]").val();//市
	if(province=="请选择省份"){
		$data.province = "";
	}else{
		$data.province = province;//省
	}
	if(address=="请选择城市"){
		$data.address = "";
	}else{
		$data.address = address;//省
	}
	$data.id = id;
	$data.authentication = $(".boxnav li.set span").attr("data-num");//用户角色
	console.log($data);
	if(orgPass&&namePass){
			$.ajax({"url" : "../ajax/professor",
				"type" :  "POST",
				"success" : function(rdata) {
					
					if (rdata.success) {
							$.cookie('userName', $data.name,{path:"/"}); 
							location.href="index.html";								
					} else {
						$.MsgBox.Alert("message",rdata.msg);
					}
				},
				"data" : $data,
				"contentType" :"application/x-www-form-urlencoded",
				dataType : "json"
			});
	}else{
		$(".basicmsg1").text('请输入您的真实姓名');
		var label1 = $(".label1").text();
		$(".basicmsg2").text('请输入您的'+label1);
	}
});	
