var branchId = "";
function setBranchId(obj){
	branchId = obj.id;
}

var bmdm="";
function setBmdm(obj){
	bmdm = obj.id;
}

function selpro(e){
	$("#search-select-province").val($(e).attr("scode"));
	findCity($(e).attr("scode"));
}
//根据所选省份获取市
function findCity(provinceCode){
	 $("#citySpan").html("请选择市");
	 $("#cityContext").html("");
	 $.ajax({
		 type:"POST",
		 url:"findCity.do",
		 data:{"provinceCode":provinceCode},
		 error:function(){
			 alert("获取市级单位失败");
			 return;
		 },
		 success:function(data){
			 $("#display-city").html("请选择");
			 $("#city-context").empty();
			 for(var i=0;i<data.length;i++){
				 var city = data[i];
				 
				 $("#city-context").append("<li id=\""+city.cityCode+"\" onclick=\"getCityCode(this)\">"+city.cityName+"</li>");
			 }
			 //选中
			 $(".select").find(".sel_list li").hover( function (){
					$(this).addClass("sel_hov");		
				},function (){
					$(this).removeClass("sel_hov");	
				}).on('click',function(){
					var _this = $(this).html();
					
					var _thisText = $(this).closest(".select").find(".sel_text");
					_thisText.html(_this);
					
				});
		 }
	 });
}



function getCityCode(obj){
	 $("#search-select-city").val(obj.id);
}

function changeMenu(e){
	$("#menu-id").val($(e).attr("id"));
	var t = $(e).attr("id");
	$("#context").html("");
	if(t=="1"){
		$("#fff").attr("style","display:none");
		$("#group-list").attr("style","display:none");
		$("#branch-menu").attr("style","display:block");
		$("#sch-btn").attr("onclick","queryHospital()");
//		$("#custom-list").html("");
//		$("#custom-list").append("<th>医院名称</th><th>总院/分院</th><th>医保类别</th><th>级别</th><th>医院属性</th><th>医院经济类别</th><th>医院所在省</th><th>医院所在市</th><th>重点科室</th><th>是否黑名单</th>");
	}else if(t=="2"){
		$("#branch-menu").attr("style","display:none");
		$("#group-list").attr("style","display:none");
		$("#fff").attr("style","display:block");
		$(".class-menu").attr("id","class-code");
		$(".class-menu").attr("name","class-code");
		$("#sch-btn").attr("onclick","searchByClassCode()");
//		$("#custom-list").html("");
//		$("#custom-list").append(" <th>医院名称</th><th>所属分公司</th><th>所属中支</th><th>医院所在省</th><th>医院所在市</th><th>地址</th><th>等级</th><th>组别</th>");
	}else if(t=="3"){
		$("#branch-menu").attr("style","display:none");
		$("#group-list").attr("style","display:none");
		$("#fff").attr("style","display:block");
		$(".class-menu").attr("name","class-name");
		$(".class-menu").attr("id","class-name");
		$("#sch-btn").attr("onclick","searchByClassName()");
//		$("#custom-list").html("");
//		$("#custom-list").append(" <th>医院名称</th><th>所属分公司</th><th>所属中支</th><th>医院所在省</th><th>医院所在市</th><th>地址</th><th>等级</th><th>组别</th>");
	}else if(t=="4"){
		$("#branch-menu").attr("style","display:none");
		$("#fff").attr("style","display:none");
		$("#group-list").attr("style","display:block");
		$("#sch-btn").attr("onclick","searchByGroup()");
	}
	
}


    function queryHospital(f){
    	$("#context").html("");
    	
 		$.ajax({
 			type:"POST",
 			url:"queryDesignatedHospital.do",
 			data:{'branchId':branchId,'bmdm':bmdm,"pageNumber":f},
 			error:function(){
 				alert("医院信息获取出错");
 				return ;
 			},
 			success:function(data){
 				if(data != null && data != ""){
 					$("#total-pages").val(data.totalPages);
 					$("#current-page-number").val(data.pageNumber);
 					$("#context").empty();
 					$("#hospital-nav").empty();
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'hospital')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");

 					var hospitalList = data.hospitalList;
 					for ( var i = 0; i < hospitalList.length; i++) {
 						var hospital = hospitalList[i];
 						$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
 					}
 					/*for ( var i = 1; i <= data.total; i++) {
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'company')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 					}*/
 					
 					
 					//////
 					var j = 1;
 					for( var i = data.pageNumber ; i <= data.total; i++){
 						if(j <= data.pageNumber+3){
 	 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'hospital')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 						}else{
 							break;
 						}
 						j++;
 					}
 					
 					if(data.total > data.pageNumber+3 ){
 						$("#hospital-nav").append("<span>...</span>");
 					}
 					
 					if(data.total == data.pageNumber+7 ){
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'hospital')\" style=\"cursor:pointer;\"><span>"+data.total+"</span></a>");
 					}
 					
 					if(data.total > data.pageNumber+7 ){
 						for ( var k = data.total-2 ; k <= data.total; k++) {
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'hospital')\" style=\"cursor:pointer;\"><span>"+k+"</span></a>");
 					}
 				}
 					//////
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'company')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
 					
 	                $("#hospital-nav .turn_cur").removeAttr("class");
 	            	$("#hospital-nav").find("span").each(function(){
 	            		if($(this).html()==data.pageNumber){
 	            			$(this).attr("class","turn_cur");
 	            		}
 	            	});
 				}
 			}
 		});
    }
  function getIsNull(val){
 	 if(val==null||val=="null"){
 		 return "";
 	 }
 	 return val;
  }
  
  
function searchByClassCode(f){
	$("#context").html("");
	var classCode = $("#class-code").val();
	$.ajax({
		type:"POST",
		url:"findHospital.do",
		data:{"classCode":classCode,"pageNumber":f},
		error:function(){
			alert("查询出错");
		},
		success:function(data){
 				if(data != null && data != ""){
 					$("#total-pages").val(data.totalPages);
 					$("#current-page-number").val(data.pageNumber);
 					$("#context").empty();
 					$("#hospital-nav").empty();
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'class-code')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");

 					var hospitalList = data.hospitalList;
 					for ( var i = 0; i < hospitalList.length; i++) {
 						var hospital = hospitalList[i];
 						$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
 					}
 					for ( var i = 1; i <= data.total; i++) {
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'class-code')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 					}
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'class-code')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
 					
 	                $("#hospital-nav .turn_cur").removeAttr("class");
 	            	$("#hospital-nav").find("span").each(function(){
 	            		if($(this).html()==data.pageNumber){
 	            			$(this).attr("class","turn_cur");
 	            		}
 	            	});
 				}
 			}
	});
	
}
  // id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"
function searchByClassName(f){
	$("#context").html("");
	var className = $("#class-name").val();
	$.ajax({
		type:"POST",
		url:"findHospital.do",
		data:{"className":className,"pageNumber":f},
		error:function(){
			alert("查询出错");
		},
		success:function(data){
 				if(data != null && data != ""){
 					$("#total-pages").val(data.totalPages);
 					$("#current-page-number").val(data.pageNumber);
 					$("#context").empty();
 					$("#hospital-nav").empty();
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'class-name')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");

 					var hospitalList = data.hospitalList;
 					for ( var i = 0; i < hospitalList.length; i++) {
 						var hospital = hospitalList[i];
 						$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
 					}
 					for ( var i = 1; i <= data.total; i++) {
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'class-name')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 					}
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'class-name')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
 					
 	                $("#hospital-nav .turn_cur").removeAttr("class");
 	            	$("#hospital-nav").find("span").each(function(){
 	            		if($(this).html()==data.pageNumber){
 	            			$(this).attr("class","turn_cur");
 	            		}
 	            	});
 				}
 			}
	});
	
}  
function searchByGroup(f){
	$("#context").html("");
	var groupNo = $("#group-no").val();
	$.ajax({
		type:"POST",
		url:"findHospital.do",
		data:{"groupNo":groupNo,"pageNumber":f},
		error:function(){
			alert("查询出错");
		},
		success:function(data){
 				if(data != null && data != ""){
 					$("#total-pages").val(data.totalPages);
 					$("#current-page-number").val(data.pageNumber);
 					$("#context").empty();
 					$("#hospital-nav").empty();
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'group')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");

 					var hospitalList = data.hospitalList;
 					for ( var i = 0; i < hospitalList.length; i++) {
 						var hospital = hospitalList[i];
 						$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
 					}
 					/*for ( var i = 1; i <= data.total; i++) {
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'group')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 					}*/
 					///////
 					var j = 1;
 					for( var i = data.pageNumber ; i <= data.total; i++){
 						if(j <= data.pageNumber+3){
 	 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'group')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 						}else{
 							break;
 						}
 						j++;
 					}
 					
 					if(data.total > data.pageNumber+3 ){
 						$("#hospital-nav").append("<span>...</span>");
 					}
 					
 					if(data.total == data.pageNumber+7 ){
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'group')\" style=\"cursor:pointer;\"><span>"+data.total+"</span></a>");
 					}
 					
 					if(data.total > data.pageNumber+7 ){
 						for ( var k = data.total-2 ; k <= data.total; k++) {
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'group')\" style=\"cursor:pointer;\"><span>"+k+"</span></a>");
 					    }
 				    }
 					///////
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'group')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
 					
 	                $("#hospital-nav .turn_cur").removeAttr("class");
 	            	$("#hospital-nav").find("span").each(function(){
 	            		if($(this).html()==data.pageNumber){
 	            			$(this).attr("class","turn_cur");
 	            		}
 	            	});
 				}
 			}
	});
	
} 
  

function fillInGroupNo(e){
	$("#group-no").val($(e).attr("id"));
	$("#sch-btn").attr("onclick","searchByGroup()");
//	$("#custom-list").html("");
//	$("#custom-list").append(" <th>医院名称</th><th>所属分公司</th><th>所属中支</th><th>医院所在省</th><th>医院所在市</th><th>地址</th><th>等级</th><th>组别</th>");

}

function fillInCustom(e){
	$("#custom-list").html("");
	$("#context").html();
	$("#group-custom").val($(e).attr("id"));
	$("#sch-btn").attr("onclick","searchByCustom()");
	$("#custom-list").append(" <th>医疗机构名称</th><th>地址</th><th>门诊时间</th><th>网络类型</th><th>医疗机构属性</th><th>联系人</th><th>联系电话</th><th>传真号</th><th>折扣方式</th><th>折扣率</th><th>有效起期</th><th>有效止期</th>");
}

function searchByCustom(){
	$("#context").html("");
	var partnerType = $("#group-custom").val();
	$.ajax({
		type:"POST",
		url:"searchByPartnerType.do",
		data:{"partnerType":partnerType},
		error:function(){
			alert("查询出错");
		},
		success:function(data){
			if(data==""||data==null){
				$("#context").append("<tr><td>没有相关内容</td></tr>");
			}
			for(var i=0;i<data.length;i++){
				var hospital=data[i];
 				$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\">" +
	 						              "<td width=\"160px\">"+getIsNull(hospital.partnerName)+"<br>"+getIsNull(hospital.partnerEngName)+"</td>" +
	 									  "<td width=\"160px\">"+getIsNull(hospital.partnerAddr)+"<br>"+getIsNull(hospital.partnerEngAddr)+"</td>" +
	 									  "<td>"+getIsNull(hospital.clinicTime)+"</td>" +
	 									  "<td>"+getIsNull(hospital.netType)+"</td>" +
	 									  "<td>"+getIsNull(hospital.hospitalAttrString)+"</td>" +
	 									  "<td>"+getIsNull(hospital.contactPerson)+"</td>" +
	 									  "<td>"+getIsNull(hospital.contactPhone)+"</td>" +	 									  
	 									  "<td>"+getIsNull(hospital.faxNo)+"</td>" +
	 									  "<td>"+getIsNull(hospital.discountType)+"</td>" +
	 									  "<td>"+getIsNull(hospital.discountRate)+"</td>" +
	 									  "<td>"+getIsNull(hospital.startEffectDateString)+"</td>" +
	 									  "<td>"+getIsNull(hospital.endEffectDateString)+"</td>" +
 									  "<tr>");
			}
		}
	});
}
  
  //获取机构信息
function getOrgInfo(){
	  //请求控制器返回所有数据
	  $.ajax({
		  
		  type:"POST",
		  url:"getOrgInfo.do",
		  data:{"":""},
		  error:function(){
			  alert("自动获取机构信息数据失败，请刷新页面重试！");
			  return ;
		  },
		  success:function(data){
			  
			  for(var i=0;0<data.length;i++){
				  var orgInfo = data[i];
				  if(orgInfo.orgLevel==2){
					  $("#orgSelectList").append("<ul><li>"+orgInfo.orgNameZh+"</li>");
				  }
				
			  }
			  
		  }
		  
	  });
	
  }


//获取机构代码
$(document).ready(function(){
	$("#fen").html("");
	$.ajax({
		
		type:"POST",
		url:"queryOrg.do",
		error:function(){
			alert("获取分公司失败");
		},
		success:function(data){
			for(var i=0;i<data.length;i++){
				$("#fen").append("<li id=\""+data[i].code+"\" onclick=\"choosed(this)\">"+data[i].name+"</li>");
				$("#zhi").html("");
			}
			 $(".select").find(".sel_list li").hover( function (){
					$(this).addClass("sel_hov");		
				},function (){
					$(this).removeClass("sel_hov");	
				}).on('click',function(){
					var _this = $(this).html();
					
					var _thisText = $(this).closest(".select").find(".sel_text");
					_thisText.html(_this);
					
				});
		}
		
	});
	
});


//choosEd(this)
var orgCode = null;
function choosed(obj){
	orgCode = obj.id;
	
	$("#zhi").html("");
	$("#selected-bmdm").val("");
	$("#zhiSpan").html("请选择中支公司");
	$.ajax({
		
		type:"POST",
		url:"queryOrg.do",
		data:{"orgCode":orgCode},
		error:function(){
			alert("获取中支公司失败");		
		},
		success:function(data){
			for(var i=0;i<data.length;i++){
				$("#zhi").append("<li id=\""+data[i].code+"\" onclick=\"level3Code(this)\">"+data[i].name+"</li>");
			}
			
			 $(".select").find(".sel_list li").hover( function (){
					$(this).addClass("sel_hov");		
				},function (){
					$(this).removeClass("sel_hov");	
				}).on('click',function(){
					var _this = $(this).html();
					
					var _thisText = $(this).closest(".select").find(".sel_text");
					_thisText.html(_this);
					
				});
		}
		
		
	});
	
	
}


//获取中支公司代码
var bmdm = "";
function level3Code(obj){
	bmdm = obj.id;
	$("#selected-bmdm").val(obj.id);
	
}


//根据分公司查询医院
function queryHospital(f){
	
	var branchId = orgCode;
	
	if(branchId==""){
		alert("请选择分公司");
		return;
	}
	
	$("#context").html("");
	
	$.ajax({
			type:"POST",
			url:"queryDesignatedHospital.do",
			data:{'branchId':branchId,'bmdm':$("#selected-bmdm").val(),"pageNumber":f},
			error:function(){
				alert("医院信息获取出错");
				return ;
			},
			success:function(data){
 				if(data != null && data != ""){
 					$("#hospital-total").val(data.totalPages);
 					$("#total-pages").val(data.totalPages);
 					$("#current-page-number").val(data.pageNumber);
 					$("#context").empty();
 					$("#hospital-nav").empty();
 					
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'company')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");

 					var hospitalList = data.hospitalList;
 					for ( var i = 0; i < hospitalList.length; i++) {
 						var hospital = hospitalList[i];
 						$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
 					}
 					///////
 					var j = 1;
 					for( var i = data.pageNumber ; i <= data.total; i++){
 						if(j <= data.pageNumber+3){
 	 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'company')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 						}else{
 							break;
 						}
 						j++;
 					}
 					
 					if(data.total > data.pageNumber+3 ){
 						$("#hospital-nav").append("<span>...</span>");
 					}
 					
 					if(data.total == data.pageNumber+7 ){
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'company')\" style=\"cursor:pointer;\"><span>"+data.total+"</span></a>");
 					}
 					
 					if(data.total > data.pageNumber+7 ){
 						for ( var k = data.total-2 ; k <= data.total; k++) {
 							$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'company')\" style=\"cursor:pointer;\"><span>"+k+"</span></a>");
 					    }
 				    }
 					////////
 					/*for ( var i = 1; i <= data.total; i++) {
 						
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'company')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
 					}*/
 					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'company')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
 					
 	                $("#hospital-nav .turn_cur").removeAttr("class");
 	            	$("#hospital-nav").find("span").each(function(){
 	            		if($(this).html()==data.pageNumber){
 	            			$(this).attr("class","turn_cur");
 	            		}
 	            	});
 				}
 			}
		});
}


//点击弹出详情模块
function openDetails(elements){
	//获取元素Id里面的医院代码
	var hospitalCode = elements.id;
	//打开详情框
	showDiv('open2');
	//AJAX请求数据
	$.ajax({
		type:"POST",
		url:"findByHospitalCode.do",
		data:{"hospitalCode":hospitalCode},
		error:function(){
			alert("获取医院信息失败！");
			return;
		},
		success:function(data){
			var h = data;
			$("#details_hospitalName").html(h.hospitalName);
			$("#details_headOrBranch").html(h.headOrBranchCN);
			$("#details_medicalInsuranceType").html(h.medicalInsuranceTypeCN);  // 医保类别
			$("#details_hospitalLevelCode").html(h.hospitalLevelString);  // 级别
			$("#details_hospitalAttrCode").html(h.hospitalAttrString);  // 医院属性
			$("#details_hospitalEconomicType").html(h.hospitalEconomicTypeCN);  // 医院经济类别
			$("#details_province").html(h.hosProvinceString); //医院所在省
			$("#details_city").html(h.hosCityString); //医院所在市
			$("#details_hosAddress").html(h.hosAddress);//地址
			$("#details_hosContactPhone").html(h.hosContactPhone);//联系电话
			$("#details_keyDepartment").html(h.keyDepartment);//重点科室
			$("#details_isSpecialHospital").html(h.isSpecialHospital);//是否定点医院
			$("#details_isBlacklist").html(h.isBlacklist);//是否黑名单
			$("#details_addBlacklistReason").html(h.addBlacklistReason);//加入黑名单原因
			$("#details_addBlacklistDate").html(h.addBlacklistShowDate);//加入日期
			$("#details_addBlacklistUser").html(h.addBlacklistUserName);//加入操作员
			$("#details_delBlacklistDate").html(h.delBlacklistShowDate);//撤销日期
			$("#details_delBlacklistUser").html(h.delBlacklistUserName);//撤销操作员
		}
	});
}

//翻页
function cur_skip(e,func){
	var pn = $(e).find("span").html();
	if(func == "group"){//
		searchByGroup(pn);
		$("#group-nav .turn_cur").removeAttr("class");
	}else if(func == "company"){
		queryHospital(pn);
		$("#classcode-nav .turn_cur").removeAttr("class");
	}else if(func == "hospital"){
		queryHospital(pn);
		$("#hospital-nav .turn_cur").removeAttr("class");
	}else if(func == "advanced"){
		advancedQuery(pn);
	   $("#hospital-nav .turn_cur").removeAttr("class");
    }else if(func == "class-code"){
    	searchByClassCode(pn);
		$("#hospital-nav .turn_cur").removeAttr("class");
	}
	$(e).find("span").attr("class","turn_cur");
}

//前一页
function pre(e,func){
	var funcTemp = func;
	if(func == "advanced") func = "hospital";
	var cur = $("#"+func+"-nav").find(".turn_cur").html();
	var maxPage = $("#"+func+"-total").val();
	if(funcTemp == "advanced") func = "advanced";
	if(cur>1){
		var pre = Number(cur)-Number(1);
		if(func == "group"){
			searchByGroup(pre);
		}else if(func == "hospital"){
			queryHospital(pre);
		}else if(func == "advanced"){
			advancedQuery(pre);
		}else if(func == "class-code"){
	    	searchByClassCode(pre);
		}else if(func == "class-name"){
			searchByClassName(pre);
		}
	}else{
		if(func == "group"){
			searchByGroup(maxPage);
		}else if(func == "hospital"){
			queryHospital(maxPage);
		}else if(func == "advanced"){
			advancedQuery(maxPage);
		}else if(func == "class-code"){
	    	searchByClassCode(maxPage);
		}else if(func == "class-name"){
			searchByClassName(maxPage);
		}
	}
	
}
//下一页
function next(e,func){
	var funcTemp = func;
	if(func == "advanced") func = "hospital";
	var cur = $("#"+func+"-nav").find(".turn_cur").html();
	var next = Number(cur)+Number(1);
	var maxPage = $("#"+func+"-total").val();
	if(funcTemp == "advanced") func = "advanced";
	if(parseInt(cur)<parseInt(maxPage)){
		if(func == "group"){
			searchByGroup(next);
		}else if(func == "hospital"){
			queryHospital(next);
		}else if(func == "advanced"){
			advancedQuery(next);
		}else if(func == "class-code"){
	    	searchByClassCode(next);
		}else if(func == "class-name"){
			searchByClassName(next);
		}
	}else{
		if(func == "group"){
			displayGroupInfo("1");
		}else if(func == "hospital"){
			queryHospital("1");
		}else if(func == "advanced"){
			advancedQuery("1");
		}else if(func == "class-code"){
	    	searchByClassCode("1");
		}else if(func == "class-name"){
			searchByClassName("1");
		}
	}
}
//跳转至
function custom(func){
	var pn = $.trim($("#turn_inp").val());
	if(pn == "") return;
	if(func == "group"){
		searchByGroup(pn);
	}else if(func == "class-code"){
    	searchByClassCode(pn);
	}else if(func == "class-name"){
		searchByClassName(pn);
	}
}

function displaybmdm(obj){
	var orgcode = $(obj).attr("scode");
	$("#search-select-branch").val($(obj).attr("scode"));//fengongsidaima
	$("#bmdm-list").empty();
	$("#bmdm-list").html("请选择中支公司");
	$.ajax({
		type:"POST",
		url:"queryOrg.do",
		data:{"orgCode":orgcode},
		error:function(){
			alert("获取中支公司失败");		
		},
		success:function(data){
			for(var i=0;i<data.length;i++){
				$("#bmdm-list").append("<li scode=\""+data[i].code+"\" onclick=\"fillInput(this)\">"+data[i].name+"</li>");
			}
			 $(".select").find(".sel_list li").hover( function (){
					$(this).addClass("sel_hov");		
				},function (){
					$(this).removeClass("sel_hov");	
				}).on('click',function(){
					var _this = $(this).html();
					var _thisText = $(this).closest(".select").find(".sel_text");
					_thisText.html(_this);
				});
		}
	});
}

function fillInput(e){
	$("#search-select-bmdm").val($(e).attr("scode"));
}

function selLevel(e){
	$("#search-select-level").val($(e).attr("scode"));
}

function selProperty(e){
	$("#search-select-property").val($(e).attr("scode"));
}

function selectedHospitalEconomicType(e){
	$("#search-hospital-economic-type").val($(e).attr("scode"));
}

function selAttr(e){
	$("#search-select-attr").val($(e).attr("scode"));
}

//高级查询
function advancedQuery(f){
	
	var hsptName = $("#hsptName").val();
	var hsptPro = $("#search-select-province").val();
	var hsptCity = $("#search-select-city").val();
	var hsptLevel = $("#search-select-level").val();
	var hsptCap = $("#search-select-property").val();
	var hsptAttr = $("#search-select-attr").val();
	var hsptImpoDep = $("#hsptImpoDep").val();
	var brchCom = $("#search-select-branch").val();
	var bmdmCom = $("#search-select-bmdm").val();
	var insuType = $("#insuType").val();
	var hospitalEconomicType = $("#search-hospital-economic-type").val();
	var groupName = $("#keyword-group-name").val();
	
	$.ajax({
		type:"POST",
		url:"advancedQuery.do",
		data:{"pageNumber":f,"groupName":groupName,"hsptName":hsptName,"hsptPro":hsptPro,"hsptCity":hsptCity,"hsptLevel":hsptLevel,"hsptCap":hsptCap,"hsptAttr":hsptAttr,"hsptImpoDep":hsptImpoDep,"brchCom":brchCom,"bmdmCom":bmdmCom,"insuType":insuType,"hospitalEconomicType":hospitalEconomicType},
		error:function(){
			alert("查询出错");
			return;
		},
		success:function(data){
			$("#context").empty();
			var designatedHospitalVoList = data.designatedHospitalVoList;
			if(designatedHospitalVoList != null && designatedHospitalVoList != ""){
				$("#hospital-total").val(data.total);
				$("#hospital-currentPage").val(data.pageNumber);
				
				$("#hospital-nav").empty();
				$("#context").empty();
				$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"pre(this,'advanced')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&lt;</span></a>");
				
				
				for ( var i = 0; i < designatedHospitalVoList.length; i++) {
					var hospital = designatedHospitalVoList[i];
					$("#context").append("<tr id=\""+hospital.hospitalCode+"\" style=\"cursor:pointer\" onclick=\"openDetails(this)\"><td>"+getIsNull(hospital.hospitalName)+"</td><td>"+getIsNull(hospital.headOrBranchCN)+"</td><td>"+getIsNull(hospital.medicalInsuranceTypeCN)+"</td><td>"+getIsNull(hospital.hospitalLevelString)+"</td><td>"+getIsNull(hospital.hospitalAttrString)+"</td><td>"+getIsNull(hospital.hospitalEconomicTypeCN)+"</td><td>"+getIsNull(hospital.hosProvinceString)+"</td><td>"+getIsNull(hospital.hosCityString)+"</td><td>"+getIsNull(hospital.keyDepartment)+"</td><td>"+getIsNull(hospital.isBlacklist)+"</td></tr>");
				}
				
				//////////////
				var j = 1;
				for( var i = data.pageNumber ; i <= data.total; i++){
					if(j <= data.pageNumber+3){
 						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'advanced')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
					}else{
						break;
					}
					j++;
				}
				
				if(data.total > data.pageNumber+3 ){
					$("#hospital-nav").append("<span>...</span>");
				}
				
				if(data.total == data.pageNumber+7 ){
						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'advanced')\" style=\"cursor:pointer;\"><span>"+data.total+"</span></a>");
				}
				
				if(data.total > data.pageNumber+7 ){
					for ( var k = data.total-2 ; k <= data.total; k++) {
						$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'advanced')\" style=\"cursor:pointer;\"><span>"+k+"</span></a>");
				}
			}
				/////
				
				
				/*for ( var i = 1; i <= data.total; i++) {
					$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"cur_skip(this,'advanced')\" style=\"cursor:pointer;\"><span>"+i+"</span></a>");
				}*/
				$("#hospital-nav").append("<a href=\"javascript:void(0);\" onclick=\"next(this,'advanced')\" style=\"cursor:pointer;\"><span class=\"turn_btn\">&gt;</span></a>");
				
                $("#hospital-nav .turn_cur").removeAttr("class");
            	$("#hospital-nav").find("span").each(function(){
            		if($(this).html()==data.pageNumber){
            			$(this).attr("class","turn_cur");
            		}
            	});
			}else{
				$("#context").append("<tr><td></td><td></td><td></td><td></td><td></td><td>查询结果为空</td><td></td><td></td><td></td><td></td><td></td></tr>");
			}
			
		}
	});
}