$(function(){
	//1获取数据
	loginStatus();
	 	var userid = $.cookie("userid");
	 	if(userid){
			//填充学术领域
	 		var subjectShow = function (data){
				if(data != undefined &&  data.length != 0 ){
					var subs = new Array();				
					if(data.indexOf(',')){	
						subs = data.split(',');			
					}else{
						subs[0] = data;
					}
					if(subs.length>0){
						for (var i = 0; i < subs.length; i++) {
							$("#subjectList").append("<div class='acad'>"+ subs[i] +"<span class='remove'><img src='images/move.png'></span></div>");
							$("#subjectShow").append("<div class='acad'>"+subs[i]+"</div>");			
						};
					}	
				}			
			}
	 		//填充应用行业
			var industryShow = function (data){

				if(data != undefined && data.length != 0  ){
					var subs = new Array();
					if(data.indexOf(',')){
						subs = data.split(',');
					}else{
						subs[0] = data;
					}
					if(subs.length>0){
						for (var i = 0; i < subs.length; i++) {
							$("#industryList").append("<div class='acad'>"+ subs[i] +"<span class='remove'><img src='images/move.png'></span></div>");
							$("#industryShow").append("<li>"+subs[i]+"</li>");		
								
						};
					}	
				}			
			}
			//填充教育背景
			var eduBgShow = function(data) {

				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#eduBgShow").append("<li>"+data[i].school+"－"+data[i].college+"－"+data[i].major+"－"+data[i].degree+"－"+data[i].year+"</li>");						
						$("#eduBgList").append("<li class='eg'>"+data[i].school+"－"+data[i].college+"－"+data[i].major+"－"+data[i].degree+"－"+data[i].year+"<span class='modi' title='"+data[i].id+"'><img src='images/madify.png'></span><span class='remove' title='"+data[i].id+"' ><img src='images/move.png'></span></li>");
					}
				}
			}
			//填充社会兼职
			var timeJobShow = function(data) {

				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#timeJobShow").append("<li>"+data[i].company+"－"+data[i].title+"－"+data[i].startMonth+"-"+data[i].stopMonth+"</li>");
						$("#timeJobList").append("<li class='tj'>"+data[i].company+"－"+data[i].title+"－"+data[i].startMonth+"-"+data[i].stopMonth+"<span class=\"modi\"  title='"+data[i].id+"'><img src=\"images/madify.png\"></span><span class=\"remove\" title='"+data[i].id+"' ><img src=\"images/move.png\" ></span></li>");


					}
				}
			}
			//填充项目经历
			var projectShow = function(data){
				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#projectShow").append("<li>名称："+data[i].name+"<br>内容："+data[i].descp+"</li>");						
						$("#projectList").append("<li class='pro'>"+data[i].name+"<br>"+data[i].descp+"<span class=\"modi\"  title='"+data[i].id+"'><img src=\"images/madify.png\"></span><span class=\"remove\" title='"+data[i].id+"' ><img src=\"images/move.png\" ></span></li>");
					}
				}
			}
			//填充著作论文文章
			var paperShow = function(data){
				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#paperShow").append("<li>"+data[i].name+"</li>");
						$("#paperList").append("<li class='pap'>"+data[i].name+"<span class=\"modi\"  title='"+data[i].id+"'><img src=\"images/madify.png\"></span><span class=\"remove\" title='"+data[i].id+"' ><img src=\"images/move.png\" ></span></li>");
					}
				}
			}
			//填充专利
			var patentShow = function(data){
				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#patentShow").append("<li>"+data[i].name+"－"+data[i].year+"</li>");					
						$("#patentList").append("<li class='pat'>"+data[i].name+"－"+data[i].year+"<span class=\"modi\"  title='"+data[i].id+"'><img src=\"images/madify.png\"></span><span class=\"remove\" title='"+data[i].id+"' ><img src=\"images/move.png\" ></span></li>");
					}
				}
			}
			//填充荣誉
			var honorShow = function(data){
				if(data.length>0){
					for (var i = 0; i < data.length; i++) {
						$("#honorShow").append("<li>"+data[i].name+"－"+data[i].year+"</li>");					
						$("#honorList").append("<li class='hon'>"+data[i].name+"<span class=\"modi\"  title='"+data[i].id+"'><img src=\"images/madify.png\"></span><span class=\"remove\" title='"+data[i].id+"' ><img src=\"images/move.png\" ></span></li>");
					}
				}
			}
			//填充研究方向
			var researchAreaShow = function ($datas,$datarecords){
				if($datas != undefined &&  $datas.length != 0 ){
					for(var i =0 ; i< $datas.length;++i){
						var $data = $datas[i];
						var $photos = [];
						//获取头像
						if($datarecords.length>0){
							$photos = getRecords($datarecords,$data.caption);
						}
						var showDiv= "<div class='listbox listbox-browse clear'><div class='list-browse'><span class='like'>"+$data.count+"</span>"+$data.caption+"</div><div class='like-num'>";
						if($photos.length>10){
							showDiv += "<div class='triangleR'></div>";
						}
						if($photos.length>0){
							for(var j =0 ; j< $photos.length;++j){
								showDiv += "<span class='like-people'><img class='like-h' src='/images/head/"+$photos[j]+"_s.jpg'></span>";
							} 
						}
						showDiv += "</div></div>";
						$("#researchAreaShow").append(showDiv);
						$("#researchAreaList").append("<div class='list'><span class='like'>"+$data.count+"</span><span class='ra'>"+$data.caption+"</span><span class='remove'><img src='images/move.png'></span></div>");
						// $("#researchAreaList").append("<div class=\"list\"><span class=\"like\">");
						// $("#researchAreaList").append($data.count);
						// $("#researchAreaList").append("</span>");
						// $("#researchAreaList").append($data.caption);
						// $("#researchAreaList").append("<span class=\"remove\"><img src=\"images/move.png\"></span></div>");
						
						$(".like-h").load(function(){								
						})
						.error(function(){
							$(this).attr("src","/images/default-photo.jpg");
						});	
					}
				}			
			}
			//填充研究方向
			var getRecords = function ($researchAreaLogs,caption){
			     var ret=[];
			     for(var i = 0 ;i < $researchAreaLogs.length ; i++){
			     	if(caption==$researchAreaLogs[i].caption){
			     		ret.push($researchAreaLogs[i].opreteProfessorId);
			     	}
			     }
			     return ret;
			}
//获取数据，填充页面
$.get("/ajax/professor/info/" + userid, function($data) {
	if ($data.success) {
		var $info = $data.data;
		if ($info) {
			
			if($info.authentication==false) {
				$(".modify").css("background-image","url(../images/icon-unauth.png)");
			}
			//展示专家的信息
			$("#nameS").text($info.name);
			if($info.office) {
				$("#office").text($info.office+"，");
			}
			if($info.title) {
				$("#titleS").text($info.title);	
			}
			if($info.department) {
				$("#industryS").text($info.department+"，");
			}
			if($info.orgName) {
				$("#orgNameS").text($info.orgName);
			}
			if($info.address) {
				$("#address").text($info.address);
			}					
			
			$("#headImage").attr("src", "/images/head/" + userid + "_l.jpg");
			$("#headImage").load(function() {})
				.error(function() {
					$("#headImage").attr("src",  "/images/default-photo.jpg");
				});
			$("#orgImage").attr("src",  "/images/org/" + $info.orgId + ".jpg");
			$("#orgImage").load(function() {})
				.error(function() {
					$("#orgImage").attr("src",  "/images/default-icon.jpg");
				});
			$("#descpS").text($info.descp);
			//显示专家信息到保存数据
			$("#name").val($info.name);
			$("#title").val($info.title);
			$("#orgId").val($info.orgId);
			$("#orgName").val($info.orgName);
			$("#department").val($info.department);			
			$("#officeRevise").val($info.office);
			$("#addressRevise").val($info.address);
			if($info.descp){
				$("#descp").val($info.descp);
			}else{
				$("#descpS").css("min-height","0px");
			}
			//展示专家的学术领域
			subjectShow($info.subject);
			//研究方向
			if ($info.researchAreas) {
				researchAreaShow($info.researchAreas, $info.researchAreaLogs);
			}
			//应用行业
			industryShow($info.industry);
			//教育背景
			if ($info.edus) {
				eduBgShow($info.edus);
			}
			//社会兼职
			if ($info.jobs) {
				timeJobShow($info.jobs);
			}
			//项目经历
			if ($info.projects) {
				projectShow($info.projects)
			}

			//著作 论文 文章
			if ($info.papers) {
				paperShow($info.papers);
			}
			//专利
			if ($info.patents) {
				patentShow($info.patents);
			}
			//荣誉及奖项
			if ($info.honors) {
				honorShow($info.honors);
			}

			//下滑滚动不覆盖底部 
			var d;
			var t;
			
				/*向下滚动时，header背景变半透明*/
				var top5=$(".content-left").height();
				var top4 = $("#container").height();
				var top3 = $(window).height();
				$(document).scroll(function() {
					var top1 = $(document).scrollTop();
					var top2 = $("#container").height() - top3 + (top3 - 80 - top5) - 10; //变成绝对定位															
					if (top1 >= 300) {
						$(".content-left").css({
							"position": "fixed",
							"top": "80px"
						});
						if (top1 >= top2) {
							$('.information-content').css("position", "static");
							$(".content-left").css("position", "absolute");
							$(".content-left").css("top", top4 - top5 - 10 + "px");
						} else {
							$('.information-content').css("position", "relative");
							$(".content-left").css({
								"position": "fixed",
								"top": "80px"
							});
						}
					} else {
						$(".content-left").css({
							"position": "static"
						});

					}

				})
	
			//下滑滚动不覆盖底部 结束
		}
	}
});
}
else {
	location.href = "login.html";
	return;
}

	 //搜索框
 $("#hsearch").on("click", function() {
 	var searchContent = $("#hsearchContent").val();
 	location.href = "search.html?searchContent=" + searchContent;
 });
//头像旁保存
$("#saveProfessor").on("click",function () {
	var $data = {};
	$data.name = $("#name").val();
	$data.orgId = $("#orgId").val();
	$data.orgName = $("#orgName").val();
	$data.title = $("#title").val();
	$data.department = $("#department").val();
	$data.address=$("#addressRevise").val();
	$data.office=$("#officeRevise").val();	
	var userid = $.cookie("userid");
	if (userid) {
		$data.id = userid;
	}
	$.ajax({"url" : "../ajax/professor",
		"type" : userid ? "PUT" : "POST",
		"success" : function(rdata) {
			
			if (rdata.success) {
				if (userid) {
				  	$.get("/ajax/professor/info/" + userid, function($data) {
				  		if ($data.success) {		
				  			var $info = $data.data;
				  			if ($info) {
				  				//展示专家的信息
				  				$(".modifybox").css("display","none");
				  				$(".infor-browse").css("display","block");
				  							$("#nameS").text($info.name);
				  							if($info.office) {
				  								$("#office").text($info.office+"，");
				  							}
				  							if($info.title) {
				  								$("#titleS").text($info.title);	
				  							}
				  							if($info.department) {
				  								$("#industryS").text($info.department+"，");
				  							}
				  							if($info.orgName) {
				  								$("#orgNameS").text($info.orgName);
				  							}
				  							if($info.address) {
				  								$("#address").text($info.address);
				  							}														
				  							//显示专家信息到保存数据
				  							$("#name").val($info.name);
				  							$("#title").val($info.title);
				  							$("#orgId").val($info.orgId);
				  							$("#orgName").val($info.orgName);
				  							$("#department").val($info.department);
				  							$("#officeRevise").val($info.office);
				  							$("#addressRevise").val($info.address);
				  					}
				  				}

				  		})
				}
				else {
					location.href = "information.html?id="+ rdata.data;
				}
			} else {
				alert(rdata.msg);
			}
		},
		"data" : userid ? JSON.stringify($data) : $data,
		"contentType" : userid ? "application/json": "application/x-www-form-urlencoded",
		dataType : "json"
	});
})

//上传图像的hover
$(".head-left").hover(function() {
	$(".replace-photo").animate({
		"bottom": "0px"
	});
}, function() {
	$(".replace-photo").animate({
		"bottom": "-50px"
	});
})
//专家信息点击换背景颜色
$(".subsidebar").click(function(){
	$(".subsidebar").removeClass("subcolor");
	$(".subsidebar").eq($(".subsidebar").index(this)).addClass("subcolor");						  
});
//拿到点击的顺序，然后求出局文档的距离
$(".subsidebar").click(function(){
	var index=$(".subsidebar").index(this);
	var offset=$(".introduction").eq(index).offset();

		$("body").animate({ 
			scrollTop:offset.top-80 //��body��scrollTop����pos��top����ʵ���˹��� 
			},1000); 
		 
		 });
//科研资源

	var $content = $(".sharescrollbox");
	var childcount = $content.find(".sharesrc").length; 
	Carousel(3,3, childcount, $content, $(".resounext"), $(".resouprev"));
	
	function Carousel(inde, num, childcount, obj, next, prev) {
		next.click(function() {	
			if (!obj.is(":animated")) { 
				if (num < childcount) { 
				
					num++;
					obj.animate({
						left: "-=212px"
					}, 600);
				}
			}
		});
		prev.click(function() {
			if (!obj.is(":animated")) {
				if (num > inde) { 
					num--;
					obj.animate({
						left: "+=212px"
					}, 600);
				}
			}
		});
	}

//放在编辑上面添加一个class和减少一个class
$("#container .edit").hover(function(){
	$(this).addClass("edit-position-left")	
	},function(){
	$(this).removeClass("edit-position-left")			
		});
//获取点击那个编辑，及
$("#container .edit").click(function(){
	var edit =$(".edit").index(this);
	$(".right-title span").eq(edit-1).css("color","#3e3e3e");
	$(".infor-browse").eq(edit).hide();
	$(".modifybox").eq(edit).show();
	//点击取消的操作
	$(".close").click(function(){
	$(".modifybox").eq(edit).hide();
	$(".infor-browse").eq(edit).show();	
	});	
});	//个人简介保存
 $("#saveDescp").on("click", function() {
 	$.ajax({
 		"url": "../ajax/professor/descp",
 		"type": "POST",
 		"data": {
 			"id": userid,
 			"descp": $("#descp").val()
 		},
 		"contentType": "application/x-www-form-urlencoded",
 		"success": function($data) {
 			//debugger;;
 			if ($data.success) {
 				$(".infor-browse").css("display","block");
 				$(".modifybox").css("display","none");
 				$("#descpS").text($("#descp").val());
 			} else {
 				$.MsgBox.Alert("message", $data.msg);
 			}
 		}
 	})
 })
//学术领域添加
$("#subjectAdd").click(function(){
	var val=$("#subject").val();
	$("#subjectList").append("<div class='acad'>"+ val +"<span class='remove'><img src='images/move.png'></span></div>")							
	})
//学术领域删除
$("#subjectList").on("click",".remove",function(){
	$(this).parent().remove();
	})
//学术领域保存
 $("#subjectSave").on("click",function () {
			var subjects = $("#subjectList .acad");
			var subjectAll = "";
			if(subjects.size()>0){
				for (var i = 0; i <subjects.size(); i++) {
					subjectAll += subjects[i].innerText;
					subjectAll += ',';
				};				
				subjectAll = subjectAll.substring(0, subjectAll.length-1);				
			}
			$.ajax({"url" : "/ajax/professor/subject",
				"type" : "POST",
				"data" : {"id":userid,"subject":subjectAll},
				"contentType" : "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) {						
						$("#subject").val("");						
						$("#subjectShow").empty();
						$("#subjectList").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");									
						subjectShow(subjectAll);
					} else {
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//应用行业添加
$("#industryAdd").click(function(){
	var val=$("#industry").val();
	$("#industryList").append("<div class='acad'>"+ val +"<span class='remove'><img src='images/move.png'></span></div>")							
	})
//应用行业删除
$("#industryList").on("click",".remove",function(){
	$(this).parent().remove();
	})
//应用行业保存
		$("#industrySave").on("click",function () {
			var industrys = $("#industryList .acad");
			var industryAll = "";
			if(industrys.size()>0){
				for (var i = 0; i <industrys.size(); i++) {
					industryAll += industrys[i].innerText;
					industryAll += ',';
				};
				industryAll = industryAll.substring(0, industryAll.length-1);
			}
			$.ajax({"url" : "/ajax/professor/industry",
				"type" : "POST",
				"data" : {"id":userid,"industry":industryAll},
				"contentType" : "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) {
						$("#industry").val("");						
						$("#industryShow").empty();
						$("#industryList").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");									
						industryShow(industryAll);
					} else {
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//研究方向添加
$("#researchAreaAdd").click(function(){
	var researchArea=$("#researchArea").val();
	$("#researchAreaList").append("<div class='list'><span class='like'>0</span><span class='ra'>"+ researchArea +"</span><span class='remove'><img src='images/move.png'></span></div>")							
	});

//研究方向删除
$("#researchAreaList").on("click",".remove",function(){
	$(this).parent().remove();
})	
//研究方向保存
		$("#researchAreaSave").on("click",function () {
			//debugger;
			var $data=[];
			var researchAreas = $("#researchAreaList .list .ra");
			if(researchAreas.length>0){
				for (var i = 0; i <researchAreas.length; i++) {
					var $rd ={};
					$rd.professorId = userid;					
					$rd.caption= researchAreas[i].innerText;
					$data[i]=$rd;
				}
			}
			var $has = $data.length>0;
			$.ajax({
				"url" : $has?"../ajax/researchArea":"../ajax/researchArea/"+userid,
				"type" : $has? "PUT" : "DELETE",
				"data" : $has ? JSON.stringify($data) : null,
				"contentType" : $has ? "application/json": "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success)
					{
						$("#researchArea").val("");						
						$("#researchAreaList").empty();
						$("#researchAreaShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");
						$.get("/ajax/professor/info/" + userid, function($data) 
								{
								if ($data.success) 
								{
									researchAreaShow($data.data.researchAreas, $data.data.researchAreaLogs);
								}
							});
						
					} 
					else 
					{
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
/*Ӧ����ҵ�������*/
$("#other").click(function(){
 $(".addbox").toggle();						   
});
//教育背景最下面的例子
$("#eduBgList").on("mouseover mouseout",".eg",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})

//教育背景，对添加的进行编辑
var updateEdu = function(data){
	$.get("/ajax/edu/" + data, function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#year").val($info.year ? $info.year : "");
			$("#school").val($info.school ? $info.school : "");
			$("#college").val($info.college ? $info.college : "");
			$("#major").val($info.major ? $info.major : "");
			$("#degree").val($info.degree ? $info.degree : "");
			$("#eduId").val(data);
			if($info.student){
				$("input[name='student'][value='1']").attr("checked","checked");
			}else{
				$("input[name='student'][value='0']").attr("checked","checked");
			}
			
		} else {
			alert($data.msg);
		}
	});
}
$("#eduBgList").on("click",".eg .modi",function(){
	updateEdu($(this)[0].title);
});
//教育背景，对已经添加的背景删除
var delEdu = function(data){
	$.ajax({
		"url" : "/ajax/edu/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {				
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#eduBgList").on("click",".eg .remove",function(){
	$(this).parent().remove();
	delEdu($(this)[0].title);
})
//教育背景保存
		$("#saveEduBg").on("click",function () {
			var $data = {};
			var $id = $("#eduId").val();		
			if ($id){
				$data.id = $id;				
			}	
			$data.professorId = userid;
			$data.year = $("#year").val();
			$data.school = $("#school").val();
			$data.college = $("#college").val();
			$data.major = $("#major").val();
			$data.degree = $("#degree").val();
			$data.student = false;
			$.ajax({
				"url" : "/ajax/edu",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) 
					{
						$("#school").val("");
						$("#college").val("");
						$("#major").val("");
						$("#eduBgShow").empty();
						$("#eduBgList").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
									eduBgShow($data.data.edus);
											}
							});
					} 
					else
					{
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//社会兼职，mouseover的时候编辑和删除的标签显示
$("#timeJobList").on("mouseover mouseout",".tj",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})
//社会兼职，对添加的进行编辑
var updateTimeJob = function(data){
	$.get("/ajax/job/" + data, function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#jobId").val(data);
			$("#startMonth").val($info.startMonth);
			$("#stopMonth").val($info.stopMonth ? $info.stopMonth: "");
			$("#jobCompany").val($info.company ? $info.company: "");
			$("#jobTitle").val($info.title ? $info.title: "");
		} else {
			alert($data.msg);
		}
	});
}
$("#timeJobList").on("click",".tj .modi",function(){
	updateTimeJob($(this)[0].title);
})
//社会兼职，对添加的兼职删除
var delTimeJob = function(data){
	$.ajax({
		"url" : "/ajax/job/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#timeJobList").on("click",".tj .remove",function(){
	$(this).parent().remove();
	delTimeJob($(this)[0].title);
})
//社会兼职保存	
		$("#timeJobSave").on("click",function () {
			var $data = {};
			var $id = $("#jobId").val();
			if ($id){
				$data.id = $id;
			}	
			$data.professorId = userid;
			$data.company = $("#jobCompany").val();
			$data.startMonth = $("#startMonth").val();
			$data.stopMonth = $("#stopMonth").val();
			$data.title = $("#jobTitle").val();
			$.ajax({
				"url" : "/ajax/job",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) 
					{
						$("#jobCompany").val("");
						$("#jobTitle").val("");						
						$("#timeJobList").empty();
						$("#timeJobShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
							timeJobShow($data.data.jobs);
											}
							});
					}
					else
					{
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//项目经历，mouseover的时候编辑和删除的标签显示
$("#projectList").on("mouseover mouseout",".pro",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})
//项目经历，对添加的进行编辑
var updateProject = function(data){
	$.get("/ajax/project/" + data,function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#projectStartMonth").val($info.startMonth ? $info.startMonth: "");
			$("#projectStopMonth").val($info.stopMonth ? $info.stopMonth: "");
			$("#projectName").val($info.name ? $info.name: "");
			$("#projectDescp").val($info.descp ? $info.descp: "");
			$("#projectId").val(data);
		} else {
			alert($data.msg);
		}
	});
}
$("#projectList").on("click",".pro .modi",function(){
	updateProject($(this)[0].title);
})
//项目经历，对添加的项目删除
var delProject = function(data){
	$.ajax({
		"url" : "/ajax/project/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {
				location.reload(true);
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#projectList").on("click",".pro .remove",function(){
	$(this).parent().remove();
	delProject($(this)[0].title);
})
//项目经历保存		
		$("#projectSave").on("click",function () {
			var $data = {};
			var $id = $("#projectId").val();
			if ($id){
				$data.id = $id;
			}	
			$data.professorId = userid;
			$data.startMonth = $("#projectStartMonth").val();
			$data.stopMonth = $("#projectStopMonth").val();
			$data.name = $("#projectName").val();
			$data.descp = $("#projectDescp").val();
			$.ajax({
				"url" : "../ajax/project",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) {
						$("#projectName").val("");
						$("#projectDescp").val("");						
						$("#projectList").empty();
						$("#projectShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
							projectShow($data.data.projects);
											}
							});
					} else {
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//著作论文 文章 mouseover的时候编辑和删除的标签显示
$("#paperList").on("mouseover mouseout",".pap",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})
//著作论文 文章 ，对添加的进行编辑
var updatePaper = function(data){
	$.get("/ajax/paper/" + data, function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#paperYear").val($info.year ? $info.year : "");
			$("#paperName").val($info.name ? $info.name : "");
			$("#paperUrl").val($info.url ? $info.url : "");
			$("#paperDescp").val($info.descp ? $info.descp : "");
			$("#paperId").val(data);
		} else {
			alert($data.msg);
		}
	});
}
$("#paperList").on("click",".pap .modi",function(){
	updatePaper($(this)[0].title);
})
//著作论文 文章 ，对添加的论文删除
var delPaper = function(data){
	$.ajax({
		"url" : "../ajax/paper/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {
				
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#paperList").on("click",".pap .remove",function(){
	$(this).parent().remove();
	delPaper($(this)[0].title);
})
//著作 论文 文章 保存
		$("#paperSave").on("click",function () {
			var $data = {};
			var $id = $("#paperId").val();
			if ($id){
				$data.id = $id;
			}	
			$data.professorId = userid;
			$data.year = $("#paperYear").val();
			$data.name = $("#paperName").val();
			$data.descp = $("#paperDescp").val();
			$data.url = $("#paperUrl").val();
			$.ajax({
				"url" : "../ajax/paper",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) {
						$("#paperName").val("");
						$("#paperDescp").val("");
						$("#paperUrl").val("");						
						$("#paperList").empty();
						$("#paperShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
							paperShow($data.data.papers);
											}
							});
					} else {
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		});
//专利，mouseover的时候编辑和删除的标签显示
$("#patentList").on("mouseover mouseout",".pat",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})
//专利 ，对添加的进行编辑
var updatePatent = function(data){
	$.get("/ajax/patent/" + data, function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#patentYear").val($info.year ? $info.year : "");
			$("#patentName").val($info.name ? $info.name : "");
			$("#patentUrl").val($info.url ? $info.url : "");
			$("#patentDescp").val($info.descp ? $info.descp : "");
			$("#patentId").val(data);
		} else {
			alert($data.msg);
		}
	});
}
$("#patentList").on("click",".pat .modi",function(){
	updatePatent($(this)[0].title);
})
//专利 ，对添加的专利删除
var delPatent = function(data){
	$.ajax({
		"url" : "/ajax/patent/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {
				
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#patentList").on("click",".pat .remove",function(){
	$(this).parent().remove();
	delPatent($(this)[0].title);
})
//专利保存	
		$("#patentSave").on("click",function () {
			var $data = {};
			var $id = $("#patentId").val();
			if ($id){
				$data.id = $id;
			}	
			$data.professorId = userid;
			$data.year = $("#patentYear").val();
			$data.name = $("#patentName").val();
			$data.descp = $("#patentDescp").val();
			$data.url = $("#patentUrl").val();
			$.ajax({
				"url" : "../ajax/patent",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success) {
						$("#patentName").val("");
						$("#patentUrl").val("");
						$("#patentDescp").val("");						
						$("#patentList").empty();
						$("#patentShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
							patentShow($data.data.patents);
											}
							});
					} else {
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//荣誉及奖项，mouseover的时候编辑和删除的标签显示
$("#honorList").on("mouseover mouseout",".hon",function(even){
	if(event.type == "mouseover"){
		$(this).find("span").show();
	 }else if(event.type == "mouseout"){
	   $(this).find("span").hide();
	 }
})
//荣誉及奖项 ，对添加的进行编辑
var updateHonor = function(data){
	$.get("/ajax/honor/" + data, function($data) {
		if ($data.success) {
			$info = $data.data;
			$("#honorYear").val($info.year ? $info.year : "");
			$("#honorName").val($info.name ? $info.name : "");
			$("#honorDescp").val($info.descp ? $info.descp : "");
			$("#honorId").val(data);
		} else {
			alert($data.msg);
		}
	});
}
$("#honorList").on("click",".hon .modi",function(){
	updateHonor($(this)[0].title);
})
//荣誉及奖项 ，对添加的专利删除
var delHonor = function(data){
	$.ajax({
		"url" : "/ajax/honor/" + data,
		"type" : "DELETE",
		"success" : function($data) {
			if ($data.success) {				
			} else {
				alert($data.msg);
			}
		}
	});
}
$("#honorList").on("click",".hon .remove",function(){
	$(this).parent().remove();
	delHonor($(this)[0].title);
})

function getProfessorData(){
	$.get("/ajax/professor/info/" + userid, function($data) {
	if ($data.success) {
		
	}
	});
}
getProfessorData()


//荣誉及奖项保存
		$("#honorSave").on("click",function () {
			var $data = {};
			var $id = $("#honorId").val();
			if ($id){
				$data.id = $id;
			}	
			$data.professorId = userid;
			$data.year = $("#honorYear").val();
			$data.name = $("#honorName").val();
			$data.descp = $("#honorDescp").val();
			$.ajax({
				"url" : "../ajax/honor",
				"type" : $id ? "PUT" : "POST",
				"data" : $id ? JSON.stringify($data) : $data,
				"contentType" : $id ? "application/json"
						: "application/x-www-form-urlencoded",
				"success" : function($data) {
					if ($data.success)
					{
						$("#honorName").val("");											
						$("#honorList").empty();
						$("#honorShow").empty();						
						$(".modifybox").css("display","none");
						$(".infor-browse").css("display","block");															
						$.get("/ajax/professor/info/" + userid, function($data) 
						{
						if ($data.success) {
							honorShow($data.data.honors);
											}
							});
					} 
					else 
					{
						$.MsgBox.Alert("message",$data.msg);
					}
				}
			});
		})
//科研资源
	$.ajax({		
		"url":"/ajax/resource/qapro",
		"type":"get",
		"data":{"professorId":userid},
		"async": true,
		"success":function(data){
			//console.log(data);
			if(data.data.length==0){
				$("#infor-browse").css("display","none");
				$(".resoubtn").css("display","none");
			}
			if(data.data.length > 0 && data.data.length <= 3){
				$("#infor-browse").css("display","block");
				$(".resoubtn").css("display","none");
			}
			var add="";
			if(data.success)
				{console.log(data);
					for(var i=0;i<data.data.length;i++){
						add='<div class="sharesrc">'
						add+='<div class="shareshow">'
	                	add+='<a href=""><img src="/images/resource/'+data.data[i].resourceId+'.jpg" width="100%" height="100%" class="resouImage"></a>'
	                 	add+='<div class="shareopeart"></div>'
	             		add+='</div>'	             
	             		add+='<p>资源名称：<span class="presou">'+ data.data[i].resourceName+'</span></p>'
	             		if(data.data[i].descp==undefined){
	             			data.data[i].descp="";
	             		}
	             		add+='<p class="briefinfor">简介:'+data.data[i].descp+'</p>'
	        			add+='</div>'
	        			$(".sharescrollbox").append(add);	

						$(".resouImage").load(function(){})
							.error(function(){
								$(this).attr("src","/images/default-resource.jpg");
							});
	             		
						add="";
					}
					//资源轮播
					var $content = $(".sharescrollbox");
					var childcount = $content.find(".sharesrc").length; 
					Carousel(3,3, childcount, $content, $(".resounext"), $(".resouprev"));
					
					function Carousel(inde, num, childcount, obj, next, prev) {
						next.click(function() {	
							if (!obj.is(":animated")) { 
								if (num < childcount) { 
								
									num++;
									obj.animate({
										left: "-=212px"
									}, 600);
								}
							}
						});
						prev.click(function() {
							if (!obj.is(":animated")) {
								if (num > inde) { 
									num--;
									obj.animate({
										left: "+=212px"
									}, 600);
								}
							}
						});
					}
				}
				else
				{
					$.MsgBox.Alert("消息","系统异常!");
				}
		},
		"error":function(){$.MsgBox.Alert('message','failddd')}
	});
	$("#enterwork").on("click",function(){
		location.href="workspaces.html?"+userid;
	})
//到至今选中复选框的操作
/*$(".present").click(function(){
	var date = $(".present").index(this);
	$(".datebox").eq(date).find(".ago").remove();
	$(".datebox").eq(date).css("width","326px");
	})*/
$(".present").change(function(){
	if($(".present").is(":checked"))
	{
		$(this).parent().parent().find('.ago').hide();
		$(this).parent().parent().find('.inputno').hide();
		
	}else{
	
		$(this).parent().parent().find('.ago').show();
		$(this).parent().parent().find('.inputno').show();
	}
})	
	

/*ģ��Selectѡ���*/
 $(".input_select").click(function(){ 
      var ul = $(this).next();
      if(ul.css("display")=="none"){ 
        ul.slideDown("fast");
      }else{ 
        ul.slideUp("fast"); 
      } 
    });
     
    $(".divselect ul li a").click(function(){ 
      var txt = $(this).text(); 
      $(".divselect .input_select").val(txt); 
      var value = $(this).attr("rel"); 
      $(".divselect ul").hide(); 
      
    }); 
$("#aclick").on("click",function(){
	exit();
});
})
function exit(){
		$.cookie('userid', null); 
		$.cookie('userAuth', null); 
		location.href="login.html"
	}

//获取数据填充页面

/*����*/
