/*行业选择弹出层填充数据*/
function trade_filldata(fillID, data_resources, determinebtn, deselectbtn, showID, resultshowID, resultID, resultCN) {
	var tradhtm = '';
	var sourse_length = parseInt(data_resources.length);
	var rows = 0;
	var subscriptnum = 0;
	if((sourse_length%3) == 0) {
		rows = sourse_length / 3;
	} else {
		rows = (sourse_length / 3) + 1;
	}
	for (var i = 0; i < rows; i++) {
		tradhtm += '<tr>';
		for (var j = 0; j < 3; j++) {
			if (data_resources[subscriptnum]) {
				var trad_array = data_resources[subscriptnum].split(",");
				tradhtm += '<td><label><input type="checkbox" data="'+trad_array[0]+','+trad_array[1]+'" name="item-list" class="input-checkbox">'+trad_array[1]+'</label></td>';
				subscriptnum ++;
			};
		};
		tradhtm += '</tr>';
	};
	$(fillID).html(tradhtm);
	// 恢复选中
	if ($(resultID).val().length > 0) {
		var idarray = $(resultID).val().split(",");
		$.each(idarray, function(index, val) {
			$(fillID+" :checkbox").unbind().each(function() {
				var boxdata_array = $(this).attr("data").split(",");
				if(val == boxdata_array[0]) {
					$(this).attr('checked',true);
				}
			});
		});
		copy_selected();
		isexceed($(fillID+" :checkbox[checked]").length);
	};
	// 单选
	$(fillID+" label :checkbox").unbind().on("click",function(event) {
		if ($(this).find(":checkbox").attr('checked')) {
			$(this).find(":checkbox").attr('checked',false);
			isexceed($(fillID+" :checkbox[checked]").length);
		} else {
			$(this).find(":checkbox").attr('checked',true);
			isexceed($(fillID+" :checkbox[checked]").length);
		}
	});
	/*判断选中的数量是否超出最大限制*/
	function isexceed(num) {
		if(num >= 3) {
			$(fillID+" :checkbox").each(function(index, el) {
				if (!$(this).attr('checked')) {
					$(this).attr('disabled',"disabled");
				}
			});
		} else {
			$(fillID+" :checkbox").each(function(index, el) {
				$(this).attr('disabled',false);
			});
		}
	}
	// 确定
	$(determinebtn).unbind().click(function() {
		copy_selected();
		close_dialog();
		searchHistory();
	});
	// 取消
	$(deselectbtn).unbind().click(function() {
		close_dialog();
	});
	// 弹出框关闭
	function close_dialog() {
		$("#maskLayer").remove();
		$(showID).hide();
	}
	// 复制选中 赋值
	function copy_selected() {
		var selectedhtm = "";
		var selectedid_array = new Array();
		var selectedcn_array = new Array();
		$(fillID+" :checkbox[checked]").unbind().each(function(index) {
			var data_array = $(this).attr("data").split(",");
			selectedhtm += '<span data-id="'+data_array[0]+'">'+data_array[1]+'<a class="close" style="top: 2px;"></a></span>';
			selectedid_array[index]=data_array[0];
			selectedcn_array[index]=data_array[1];
		});
		$(resultshowID + " .items").html(selectedhtm);
		var spanwidth = 0, itemswidth = $(resultshowID).width()-28, widtharray = new Array();
		if($(resultshowID + " .items span")) {
			$(resultshowID + " .items span").each(function(index) {
				spanwidth = spanwidth + $(this).outerWidth(true);
				widtharray[index] = $(this).outerWidth(true);
			})
		}
		var difwidth=spanwidth-itemswidth;
		if (widtharray.length == 2) {
			if(widtharray[0] + widtharray[1] > itemswidth) {
				setHeightCss(40);
			} else {
				setHeightCss(20);
			}
		} else if (widtharray.length == 3) {
			if(widtharray[0] + widtharray[1] + widtharray[2] > itemswidth) {
				if(widtharray[0] + widtharray[1] > itemswidth) {
					if(widtharray[1] + widtharray[2] > itemswidth) {
						setHeightCss(60);
					} else {
						setHeightCss(40);
					}
				} else {
					setHeightCss(40);
				}
			}
		} else {
			setHeightCss(20);
		}
		function setHeightCss (val) {
			$(resultshowID).css("height",val+"px");
			$(resultshowID + " .items").css("height",val+"px");
			$(resultshowID + " em").css("height",val+10+"px");
		}
		$(resultshowID + " span").unbind().click(function() {
			var dtid = $(this).attr("data-id");
			$(fillID+" :checkbox[checked]").unbind().each(function() {
				var dt_array = $(this).attr("data").split(",");
				if(dtid == dt_array[0]) {
					$(this).attr('checked',false);
				}
			});
			isexceed($(fillID+" :checkbox[checked]").length);
			copy_selected();
		});
		$(resultID).val(selectedid_array.join(","));
		$(resultCN).val(selectedcn_array.join(","));
	}
}
/*职位选择弹出层填充数据*/
function job_filldata(fillID, data_resourcesP, data_resources, resultlist, determinebtn, deselectbtn, showID, resultshowID, resulthidId, resulthidCN) {
	var jobhtm = '', result_datapool = new Array();
	$.each(data_resourcesP, function(indexp, valp) {
		 var pjob_array = valp.split(",");
		 if (indexp%2 == 0) {
		 	jobhtm += '<div class="data-row data-row-odd item-list">';
		 } else {
		 	jobhtm += '<div class="data-row item-list">';
		 }
		 jobhtm += '<div style="width:160px" class="data-row-side">'+pjob_array[1]+'</div>';
		 jobhtm += '<div style="margin-left:160px"><ul>';
		 var job_array = data_resources[pjob_array[0]].split("|");
		 $.each(job_array, function(index, val) {
		 	 var joblist_array = val.split(",");
		 	 jobhtm += '<li style="width:190px"><a title="'+joblist_array[1]+'" href="javascript:;" data="'+pjob_array[0]+'.'+joblist_array[0]+'.0,'+joblist_array[1]+'" rel="'+pjob_array[0]+'.'+joblist_array[0]+'" class="cat"><i class="data-icon data-icon-expend"></i>'+joblist_array[1]+'</a><a href="javascript:;" class="cat-touch"><label title="'+joblist_array[1]+'"><input type="checkbox" data="'+pjob_array[0]+'.'+joblist_array[0]+'.0,'+joblist_array[1]+'" rel="'+pjob_array[0]+'.'+joblist_array[0]+'" class="checkbox" name="LocalDataMultiC">'+joblist_array[1]+'</label></a></li>';
		 });
		 jobhtm += '</ul></div>';
		 jobhtm += '</div>';
	});
	$(fillID).html(jobhtm);
	// 全部恢复
	if ($(resulthidId).val().length > 0) {
		var recoverid_array = $(resulthidId).val().split(","),
			recovercn_array = $(resulthidCN).val().split(",");
		for (var i = 0; i < recoverid_array.length; i++) {
			result_datapool[i] = recoverid_array[i]+","+recovercn_array[i];
		};
		copyitem();
		copy_selected();
		var cata_array = $(fillID + " a.cat");
		$.each(cata_array, function() {
			var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
			$.each(result_datapool, function(indexdp,valdp) {
				var rdatapool_array = splitdata(valdp);
				if (catcheckedid_array[1]==rdatapool_array[1] && rdatapool_array[2] !=0) {
					catcobj.addClass('cat-checked');
				} else if(catcheckedid_array[1]==rdatapool_array[1] && rdatapool_array[2] ==0) {
					catcobj.addClass('cat-checked');
					catcobj.next().find("input").attr("checked", !0);
				}
			})
		});
	}
	$(fillID + " a.cat").unbind().on("click",function() {
		var ace = $(this), jobarrayid_array = ace.attr("rel").split(".");
		if (data_resources[jobarrayid_array[1]]) { // 判断是否有三级分类
			var tjobhtm = '<div class="data-sub"><table cellpadding="0" cellspacing="0"><tbody>';
			var tjob_array = data_resources[jobarrayid_array[1]].split("|");
			var sourse_length = parseInt(tjob_array.length);
			var rows = 0;
			var subscriptnum = 0;
			if((sourse_length%2) == 0) {
				rows = sourse_length / 2;
			} else {
				rows = (sourse_length / 2) + 1;
			}
			for (var i = 0; i < rows; i++) {
				tjobhtm += '<tr>';
				for (var j = 0; j < 2; j++) {
					if (tjob_array[subscriptnum]) {
						var tjoblist_array = tjob_array[subscriptnum].split(",");
						tjobhtm += '<td><a class="cat" data="'+jobarrayid_array[0]+'.'+jobarrayid_array[1]+'.'+tjoblist_array[0]+','+tjoblist_array[1]+'" href="javascript:;"><label title="'+tjoblist_array[1]+'"><input type="checkbox" class="checkbox" rel="'+jobarrayid_array[0]+'.'+jobarrayid_array[1]+'.'+tjoblist_array[0]+'" data="'+jobarrayid_array[0]+'.'+jobarrayid_array[1]+'.'+tjoblist_array[0]+','+tjoblist_array[1]+'" />'+tjoblist_array[1]+'</label></a></td>';
						subscriptnum ++;
					}
				};
				tjobhtm += '</tr>';
			};
			tjobhtm += '</tbody></table></div>';
			$(fillID).append(tjobhtm);
			var d = $(".data-sub"), l = $(this).closest("li");
			var g = l.find(".cat-touch input"), s = d.find("input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[2] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							 	s.prop({"checked":idsc, "disabled":idsc});
							}
						})
					} else {
						$.each(s, function() {
							if (dsc == $(this).attr("data")) {
							 	$(this).attr("checked", !0);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			var pleft = $(fillID).offset().left,
				ptop = $(fillID).offset().top,
				pwidth = $(fillID).outerWidth(),
				pheight = $(fillID).outerHeight(),
				ileft = $(this).offset().left,
				itop = $(this).offset().top,
				iwidth = $(this).outerWidth(),
				iheight = $(this).outerHeight(),
				dwidth = d.outerWidth(),
				dheight = d.outerHeight(),
				comparetop = parseInt(itop - ptop),
				dcleft = parseInt(ileft - pleft);
			l.addClass('cat-active');
			var n = $(this).next();
			pheight - dheight - iheight < comparetop ? (n.removeClass("sub").addClass("sup"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight)-dheight-iheight + 1})) : (n.removeClass("sup").addClass("sub"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight) - 1}));
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			d.bind('mouseenter', function() {
				l.attr("data-active", !0)
			}).bind('mouseleave', function() {
				l.removeAttr("data-active"), setTimeout(function() {
					l.attr("data-active") || (d.remove(), l.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				s.prop({"checked":ic, "disabled":ic});
				if (ic) {
					var gdata_array = splitdata(gdata);
					for (var i = 0; i < result_datapool.length; i++) {
						if (result_datapool[i]) {
							var icgdata_array = splitdata(result_datapool[i]);
							if (gdata_array[1] == icgdata_array[1]) {
								result_datapool.splice(i,1);
								i = -1;
							}
						}
					}
					result_datapool.push(gdata);
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
			s.unbind('click').bind('click', function() {
				var sic = $(this).is(':checked'), sdata = $(this).attr("data");
				if (sic) {
					result_datapool.push(sdata);
					isexceed() ? ace.addClass('cat-checked') : result_datapool.splice($.inArray(sdata,result_datapool),1);
				} else {
					result_datapool.splice($.inArray(sdata,result_datapool),1);
					var chnum = d.find(' :checkbox[checked]').length;
					if (chnum <= 0) {
						ace.removeClass('cat-checked');
					}
				}
				copyitem();
			});
		} else{
			var l = $(this).closest("li");
			var g = l.find(".cat-touch input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[2] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			l.addClass('cat-active');
			var n = $(this).next();
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				if (ic) {
					result_datapool.push(gdata);
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
		};
	});
	// 确定
	$(determinebtn).unbind().click(function() {
		copy_selected();
		close_dialog();
		searchHistory();
	});
	// 取消
	$(deselectbtn).unbind().click(function() {
		close_dialog();
	});
	// 弹出框关闭
	function close_dialog() {
		$("#maskLayer").remove();
		$(showID).hide();
	}
	// 复制选中项目
	function copyitem() {
		// $(fillID + " :checkbox[checked]").not(':disabled')
		var resulthtm = '';
		resulthtm += '<strong class="result-name">';
		result_datapool.length > 0 ? resulthtm += '已选择' : resulthtm += '请选择';
		resulthtm += '</strong>';
		$.each(result_datapool, function(indexrd,valrd) {
			var result_data_array = valrd.split(",");
			resulthtm += '<span>'+result_data_array[1]+'<i class="data-icon data-icon-close" data-code="'+result_data_array[0]+','+result_data_array[1]+'"></i></span>';
		});
		$(resultlist).html(resulthtm);
		var spi = $(resultlist + " span i");
		spi.unbind().bind('click', function() {
			var spidata = $(this).attr("data-code"),
				apid_array = splitdata(spidata);
			result_datapool.splice($.inArray(spidata,result_datapool),1);
			var catchecked_array = $(fillID + " a.cat-checked");
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if(apid_array[1]==catcheckedid_array[1] && apid_array[2]==0){
					catcobj.removeClass('cat-checked');
					catcobj.next().find("input").attr("checked", false);
				} else if (apid_array[1]==catcheckedid_array[1] && apid_array[2]!=0) {
					var rdanum = 0;
					$.each(result_datapool, function(indexdp,valdp) {
						var rdatapool_array = splitdata(valdp);
						if (apid_array[1]==rdatapool_array[1] && apid_array[2]!=0) {
							rdanum ++;
						}
					});
					if (rdanum <= 0) {
						catcobj.removeClass('cat-checked');
					}
				}
			});
			copyitem();
		});
	}
	// 分割data 返回数组
	function splitdata(arr) {
		if(arr) {
			var arrs_array = arr.split(","),
				arrid_array = arrs_array[0].split(".");
			return arrid_array;
		}
	}
	// 判断选择数量是否超出
	function isexceed() {
		if(result_datapool.length > 3) {
			alert("最多可选3个");
			return false;
		} else {
			return true;
		}
	}
	// 复制选中 赋值
	function copy_selected() {
		var selectedhtm = "";
		var selectedid_array = new Array();
		var selectedcn_array = new Array();
		for (var i = 0; i < result_datapool.length; i++) {
			if (result_datapool[i]) {
				var data_array = result_datapool[i].split(",");
				selectedhtm += '<span data-code="'+data_array[0]+','+data_array[1]+'">'+data_array[1]+'<a class="close" style="top: 2px;"></a></span>';
				selectedid_array[i]=data_array[0];
				selectedcn_array[i]=data_array[1];
			};
		};
		$(resultshowID + " .items").html(selectedhtm);style="top: 2px;"
		var spanwidth = 0, itemswidth = $(resultshowID).width()-28, widtharray = new Array();
		if($(resultshowID + " .items span")) {
			$(resultshowID + " .items span").each(function(index) {
				spanwidth = spanwidth + $(this).outerWidth(true);
				widtharray[index] = $(this).outerWidth(true);
			})
		}
		var difwidth=spanwidth-itemswidth;
		if (widtharray.length == 2) {
			if(widtharray[0] + widtharray[1] > itemswidth) {
				setHeightCss(40);
			} else {
				setHeightCss(20);
			}
		} else if (widtharray.length == 3) {
			if(widtharray[0] + widtharray[1] + widtharray[2] > itemswidth) {
				if(widtharray[0] + widtharray[1] > itemswidth) {
					if(widtharray[1] + widtharray[2] > itemswidth) {
						setHeightCss(60);
					} else {
						setHeightCss(40);
					}
				} else {
					setHeightCss(40);
				}
			}
		} else {
			setHeightCss(20);
		}
		function setHeightCss (val) {
			$(resultshowID).css("height",val+"px");
			$(resultshowID + " .items").css("height",val+"px");
			$(resultshowID + " em").css("height",val+10+"px");
		}
		$(resultshowID + " span").unbind().click(function() {
			var dtid = $(this).attr("data-code"),
				dtid_array = splitdata(dtid);
			for (var i = 0; i < result_datapool.length; i++) {
				if(dtid == result_datapool[i]) {
					result_datapool.splice($.inArray(dtid,result_datapool),1);
					i = -1;
				}
			}
			var catchecked_array = $(fillID + " a.cat-checked");
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if (dtid_array) {
					if(dtid_array[0]==catcheckedid_array[0] && dtid_array[1]==0){
						catcobj.removeClass('cat-checked');
						catcobj.next().find("input").attr("checked", false);
					} else if (dtid_array[0]==catcheckedid_array[0] && dtid_array[1]!=0) {
						var rdanum = 0;
						$.each(result_datapool, function(indexdp,valdp) {
							var rdatapool_array = splitdata(valdp);
							if (dtid_array[0]==rdatapool_array[0] && dtid_array[1]!=0) {
								rdanum ++;
							}
						})
						if (rdanum <= 0) {
							catcobj.removeClass('cat-checked');
						}
					}
				}
			});
			copyitem();
			copy_selected();
		});
		$(resulthidId).val(selectedid_array.join(","));
		$(resulthidCN).val(selectedcn_array.join(","));
	}
}
/*地区选择弹出层填充数据*/
function city_filldata(fillID, data_resourcesP, data_resources, resultlist, determinebtn, deselectbtn, showID, resultshowID, resulthidId, resulthidCN) {
	var cityhtm = '', result_datapool = new Array();

	var sourse_city_length = parseInt(data_resourcesP.length);
	var rows_city = 0;
	var subscriptnum_city = 0;
	if((sourse_city_length%3) == 0) {
		rows_city = sourse_city_length / 3;
	} else {
		rows_city = (sourse_city_length / 3) + 1;
	}
	for (var i = 0; i < rows_city; i++) {
		if (i%2 == 0) {
		 	cityhtm += '<div class="data-row data-row-odd item-list">';
		} else {
		 	cityhtm += '<div class="data-row item-list">';
		}
		cityhtm += '<div><ul>';
		for (var j = 0; j < 3; j++) {
			if (data_resourcesP[subscriptnum_city]) {
				var citylist_array = data_resourcesP[subscriptnum_city].split(",");
				cityhtm += '<li style="width:190px"><a title="'+citylist_array[1]+'" href="javascript:;" data="'+citylist_array[0]+'.0,'+citylist_array[1]+'" rel="'+citylist_array[0]+'.0" class="cat"><i class="data-icon data-icon-expend"></i>'+citylist_array[1]+'</a><a href="javascript:;" class="cat-touch"><label title="'+citylist_array[1]+'"><input type="checkbox" data="'+citylist_array[0]+'.0,'+citylist_array[1]+'" rel="'+citylist_array[0]+'.0" class="checkbox" name="LocalDataMultiC">'+citylist_array[1]+'</label></a></li>';
				subscriptnum_city ++;
			};
		};
		cityhtm += '</ul></div>';
		cityhtm += '</div>';
	};
	$(fillID).html(cityhtm);
	// 全部恢复
	if ($(resulthidId).val().length > 0) {
		var recoverid_array = $(resulthidId).val().split(","),
			recovercn_array = $(resulthidCN).val().split(",");
		for (var i = 0; i < recoverid_array.length; i++) {
			result_datapool[i] = recoverid_array[i]+","+recovercn_array[i];
		};
		copyitem();
		copy_selected();
		var cata_array = $(fillID + " a.cat");
		$.each(cata_array, function() {
			var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
			$.each(result_datapool, function(indexdp,valdp) {
				var rdatapool_array = splitdata(valdp);
				if (catcheckedid_array[0]==rdatapool_array[0] && rdatapool_array[1] !=0) {
					catcobj.addClass('cat-checked');
				} else if(catcheckedid_array[0]==rdatapool_array[0] && rdatapool_array[1] ==0) {
					catcobj.addClass('cat-checked');
					catcobj.next().find("input").attr("checked", !0);
				}
			})
		});
	}
	$(fillID + " a.cat").unbind().on("click",function() {
		var ace = $(this), cityarrayid_array = ace.attr("rel").split(".");
		if (data_resources[cityarrayid_array[0]]) { // 判断是否有二级地区
			var tcityhtm = '<div class="data-sub"><table cellpadding="0" cellspacing="0"><tbody>';
			var tcity_array = data_resources[cityarrayid_array[0]].split("|");
			var sourse_length = parseInt(tcity_array.length);
			var rows = 0;
			var subscriptnum = 0;
			if((sourse_length%2) == 0) {
				rows = sourse_length / 2;
			} else {
				rows = (sourse_length / 2) + 1;
			}
			for (var i = 0; i < rows; i++) {
				tcityhtm += '<tr>';
				for (var j = 0; j < 2; j++) {
					if (tcity_array[subscriptnum]) {
						var tcitylist_array = tcity_array[subscriptnum].split(",");
						tcityhtm += '<td><a class="cat" data="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+','+tcitylist_array[1]+'" href="javascript:;"><label title="'+tcitylist_array[1]+'"><input type="checkbox" class="checkbox" rel="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+'" data="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+','+tcitylist_array[1]+'" />'+tcitylist_array[1]+'</label></a></td>';
						subscriptnum ++;
					}
				};
				tcityhtm += '</tr>';
			};
			tcityhtm += '</tbody></table></div>';
			$(fillID).append(tcityhtm);
			var d = $(".data-sub"), l = $(this).closest("li");
			var g = l.find(".cat-touch input"), s = d.find("input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[1] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							 	s.prop({"checked":idsc, "disabled":idsc});
							}
						})
					} else {
						$.each(s, function() {
							if (dsc == $(this).attr("data")) {
							 	$(this).attr("checked", !0);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			var pleft = $(fillID).offset().left,
				ptop = $(fillID).offset().top,
				pwidth = $(fillID).outerWidth(),
				pheight = $(fillID).outerHeight(),
				ileft = $(this).offset().left,
				itop = $(this).offset().top,
				iwidth = $(this).outerWidth(),
				iheight = $(this).outerHeight(),
				dwidth = d.outerWidth(),
				dheight = d.outerHeight(),
				comparetop = parseInt(itop - ptop),
				dcleft = parseInt(ileft - pleft);
			l.addClass('cat-active');
			var n = $(this).next();
			pheight - dheight - iheight < comparetop ? (n.removeClass("sub").addClass("sup"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight)-dheight-iheight + 1})) : (n.removeClass("sup").addClass("sub"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight) - 1}));
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			d.bind('mouseenter', function() {
				l.attr("data-active", !0)
			}).bind('mouseleave', function() {
				l.removeAttr("data-active"), setTimeout(function() {
					l.attr("data-active") || (d.remove(), l.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				s.prop({"checked":ic, "disabled":ic});
				if (ic) {
					var gdata_array = splitdata(gdata);
					for (var i = 0; i < result_datapool.length; i++) {
						if (result_datapool[i]) {
							var icgdata_array = splitdata(result_datapool[i]);
							if (gdata_array[0] == icgdata_array[0]) {
								result_datapool.splice(i,1);
								i = -1;
							}
						}
					}
					result_datapool.push(gdata);
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
			s.unbind('click').bind('click', function() {
				var sic = $(this).is(':checked'), sdata = $(this).attr("data");
				if (sic) {
					result_datapool.push(sdata);
					isexceed() ? ace.addClass('cat-checked') : result_datapool.splice($.inArray(sdata,result_datapool),1);
				} else {
					result_datapool.splice($.inArray(sdata,result_datapool),1);
					var chnum = d.find(' :checkbox[checked]').length;
					if (chnum <= 0) {
						ace.removeClass('cat-checked');
					}
				}
				copyitem();
			});
		} else{
			var l = $(this).closest("li");
			var g = l.find(".cat-touch input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[0] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			l.addClass('cat-active');
			var n = $(this).next();
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				if (ic) {
					result_datapool.push(gdata);
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
		};
	});
	// 确定
	$(determinebtn).unbind().click(function() {
		copy_selected();
		close_dialog();
		searchHistory();
	});
	// 取消
	$(deselectbtn).unbind().click(function() {
		close_dialog();
	});
	// 弹出框关闭
	function close_dialog() {
		$("#maskLayer").remove();
		$(showID).hide();
	}
	// 复制选中项目
	function copyitem() {
		// $(fillID + " :checkbox[checked]").not(':disabled')
		var resulthtm = '';
		resulthtm += '<strong class="result-name">';
		result_datapool.length > 0 ? resulthtm += '已选择' : resulthtm += '请选择';
		resulthtm += '</strong>';
		$.each(result_datapool, function(indexrd,valrd) {
			var result_data_array = valrd.split(",");
			resulthtm += '<span>'+result_data_array[1]+'<i class="data-icon data-icon-close" data-code="'+result_data_array[0]+','+result_data_array[1]+'"></i></span>';
		});
		$(resultlist).html(resulthtm);
		var spi = $(resultlist + " span i");
		spi.unbind().bind('click', function() {
			var spidata = $(this).attr("data-code"),
				apid_array = splitdata(spidata);
			result_datapool.splice($.inArray(spidata,result_datapool),1);
			var catchecked_array = $(fillID + " a.cat-checked");
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if(apid_array[0]==catcheckedid_array[0] && apid_array[1]==0){
					catcobj.removeClass('cat-checked');
					catcobj.next().find("input").attr("checked", false);
				} else if (apid_array[0]==catcheckedid_array[0] && apid_array[1]!=0) {
					var rdanum = 0;
					$.each(result_datapool, function(indexdp,valdp) {
						var rdatapool_array = splitdata(valdp);
						if (apid_array[0]==rdatapool_array[0] && apid_array[1]!=0) {
							rdanum ++;
						}
					});
					if (rdanum <= 0) {
						catcobj.removeClass('cat-checked');
					}
				}
			});
			copyitem();
		});
	}
	// 分割data 返回数组
	function splitdata(arr) {
		var arrs_array = arr.split(","),
			arrid_array = arrs_array[0].split(".");
		return arrid_array;
	}
	// 判断选择数量是否超出
	function isexceed() {
		if(result_datapool.length > 3) {
			alert("最多可选3个");
			return false;
		} else {
			return true;
		}
	}
	// 复制选中 赋值
	function copy_selected() {
		var selectedhtm = "";
		var selectedid_array = new Array();
		var selectedcn_array = new Array();
		for (var i = 0; i < result_datapool.length; i++) {
			if (result_datapool[i]) {
				var data_array = result_datapool[i].split(",");
				selectedhtm += '<span data-code="'+data_array[0]+','+data_array[1]+'">'+data_array[1]+'<a class="close" style="top: 2px;"></a></span>';
				selectedid_array[i]=data_array[0];
				selectedcn_array[i]=data_array[1];
			};
		};
		$(resultshowID + " .items").html(selectedhtm);
		var spanwidth = 0, itemswidth = $(resultshowID).width()-28, widtharray = new Array();
		if($(resultshowID + " .items span")) {
			$(resultshowID + " .items span").each(function(index) {
				spanwidth = spanwidth + $(this).outerWidth(true);
				widtharray[index] = $(this).outerWidth(true);
			})
		}
		var difwidth=spanwidth-itemswidth;
		if (widtharray.length == 2) {
			if(widtharray[0] + widtharray[1] > itemswidth) {
				setHeightCss(40);
			} else {
				setHeightCss(20);
			}
		} else if (widtharray.length == 3) {
			if(widtharray[0] + widtharray[1] + widtharray[2] > itemswidth) {
				if(widtharray[0] + widtharray[1] > itemswidth) {
					if(widtharray[1] + widtharray[2] > itemswidth) {
						setHeightCss(60);
					} else {
						setHeightCss(40);
					}
				} else {
					setHeightCss(40);
				}
			}
		} else {
			setHeightCss(20);
		}
		function setHeightCss (val) {
			$(resultshowID).css("height",val+"px");
			$(resultshowID + " .items").css("height",val+"px");
			$(resultshowID + " em").css("height",val+10+"px");
		}
		$(resultshowID + " span").unbind().click(function() {
			var dtid = $(this).attr("data-code"),
				dtid_array = splitdata(dtid);
			for (var i = 0; i < result_datapool.length; i++) {
				if(dtid == result_datapool[i]) {
					result_datapool.splice($.inArray(dtid,result_datapool),1);
					i = -1;
				}
			}
			var catchecked_array = $(fillID + " a.cat-checked");
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if (dtid_array) {
					if(dtid_array[0]==catcheckedid_array[0] && dtid_array[1]==0){
						catcobj.removeClass('cat-checked');
						catcobj.next().find("input").attr("checked", false);
					} else if (dtid_array[0]==catcheckedid_array[0] && dtid_array[1]!=0) {
						var rdanum = 0;
						$.each(result_datapool, function(indexdp,valdp) {
							var rdatapool_array = splitdata(valdp);
							if (dtid_array[0]==rdatapool_array[0] && dtid_array[1]!=0) {
								rdanum ++;
							}
						})
						if (rdanum <= 0) {
							catcobj.removeClass('cat-checked');
						}
					}
				}
			});
			copyitem();
			copy_selected();
		});
		$(resulthidId).val(selectedid_array.join(","));
		$(resulthidCN).val(selectedcn_array.join(","));
	}
}
/*单选 地区选择弹出层填充数据*/
function city_filldata_alone(fillID, data_resourcesP, data_resources, resultlist, determinebtn, deselectbtn, showID, resultshowID, district, sdistrict, resulthidCN, resultshowID) {
	var cityhtm = '', result_datapool = new Array();

	var sourse_city_length = parseInt(data_resourcesP.length);
	var rows_city = 0;
	var subscriptnum_city = 0;
	if((sourse_city_length%3) == 0) {
		rows_city = sourse_city_length / 3;
	} else {
		rows_city = (sourse_city_length / 3) + 1;
	}
	for (var i = 0; i < rows_city; i++) {
		if (i%2 == 0) {
		 	cityhtm += '<div class="data-row data-row-odd item-list">';
		} else {
		 	cityhtm += '<div class="data-row item-list">';
		}
		cityhtm += '<div><ul>';
		for (var j = 0; j < 3; j++) {
			if (data_resourcesP[subscriptnum_city]) {
				var citylist_array = data_resourcesP[subscriptnum_city].split(",");
				cityhtm += '<li style="width:190px"><a title="'+citylist_array[1]+'" href="javascript:;" data="'+citylist_array[0]+'.0,'+citylist_array[1]+'" rel="'+citylist_array[0]+'.0" class="cat"><i class="data-icon data-icon-expend"></i>'+citylist_array[1]+'</a><a href="javascript:;" class="cat-touch"><label title="'+citylist_array[1]+'"><input type="checkbox" data="'+citylist_array[0]+'.0,'+citylist_array[1]+'" rel="'+citylist_array[0]+'.0" class="checkbox" name="LocalDataMultiC">'+citylist_array[1]+'</label></a></li>';
				subscriptnum_city ++;
			};
		};
		cityhtm += '</ul></div>';
		cityhtm += '</div>';
	};
	$(fillID).html(cityhtm);
	// 全部恢复
	if ($(resulthidCN).val().length > 0) {
		var recovercn_array = $(resulthidCN).val();
		result_datapool[0] = $(district).val()+"."+$(sdistrict).val()+","+$(resulthidCN).val();
		copyitem();
		copy_selected();
		var cata_array = $(fillID + " a.cat");
		$.each(cata_array, function() {
			var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
			var rdatapool_array = splitdata(result_datapool[0]);
			if (catcheckedid_array[0]==rdatapool_array[0] && rdatapool_array[1] !=0) {
				catcobj.addClass('cat-checked');
			} else if(catcheckedid_array[0]==rdatapool_array[0] && rdatapool_array[1] ==0) {
				catcobj.addClass('cat-checked');
				catcobj.next().find("input").attr("checked", !0);
			}
		});
	}
	$(fillID + " a.cat").unbind().on("click",function() {
		var ace = $(this), cityarrayid_array = ace.attr("rel").split(".");
		if (data_resources[cityarrayid_array[0]]) { // 判断是否有二级地区
			var tcityhtm = '<div class="data-sub"><table cellpadding="0" cellspacing="0"><tbody>';
			var tcity_array = data_resources[cityarrayid_array[0]].split("|");
			var sourse_length = parseInt(tcity_array.length);
			var rows = 0;
			var subscriptnum = 0;
			if((sourse_length%2) == 0) {
				rows = sourse_length / 2;
			} else {
				rows = (sourse_length / 2) + 1;
			}
			for (var i = 0; i < rows; i++) {
				tcityhtm += '<tr>';
				for (var j = 0; j < 2; j++) {
					if (tcity_array[subscriptnum]) {
						var tcitylist_array = tcity_array[subscriptnum].split(",");
						tcityhtm += '<td><a class="cat" data="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+','+tcitylist_array[1]+'" href="javascript:;"><label title="'+tcitylist_array[1]+'"><input type="checkbox" class="checkbox" rel="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+'" data="'+cityarrayid_array[0]+'.'+tcitylist_array[0]+','+tcitylist_array[1]+'" />'+tcitylist_array[1]+'</label></a></td>';
						subscriptnum ++;
					}
				};
				tcityhtm += '</tr>';
			};
			tcityhtm += '</tbody></table></div>';
			$(fillID).append(tcityhtm);
			var d = $(".data-sub"), l = $(this).closest("li");
			var g = l.find(".cat-touch input"), s = d.find("input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[1] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							 	s.prop({"checked":idsc, "disabled":idsc});
							}
						})
					} else {
						$.each(s, function() {
							if (dsc == $(this).attr("data")) {
							 	$(this).attr("checked", !0);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			var pleft = $(fillID).offset().left,
				ptop = $(fillID).offset().top,
				pwidth = $(fillID).outerWidth(),
				pheight = $(fillID).outerHeight(),
				ileft = $(this).offset().left,
				itop = $(this).offset().top,
				iwidth = $(this).outerWidth(),
				iheight = $(this).outerHeight(),
				dwidth = d.outerWidth(),
				dheight = d.outerHeight(),
				comparetop = parseInt(itop - ptop),
				dcleft = parseInt(ileft - pleft);
			l.addClass('cat-active');
			var n = $(this).next();
			pheight - dheight - iheight < comparetop ? (n.removeClass("sub").addClass("sup"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight)-dheight-iheight + 1})) : (n.removeClass("sup").addClass("sub"), d.css({left:(pwidth-dwidth < dcleft ? (pwidth-dwidth-((pleft+pwidth)-(ileft+iwidth))) + 1 : dcleft),top:(comparetop + iheight) - 1}));
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			d.bind('mouseenter', function() {
				l.attr("data-active", !0)
			}).bind('mouseleave', function() {
				l.removeAttr("data-active"), setTimeout(function() {
					l.attr("data-active") || (d.remove(), l.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				s.prop({"checked":ic, "disabled":ic});
				if (ic) {
					var gdata_array = splitdata(gdata);
					for (var i = 0; i < result_datapool.length; i++) {
						if (result_datapool[i]) {
							var icgdata_array = splitdata(result_datapool[i]);
							if (gdata_array[0] == icgdata_array[0]) {
								result_datapool.splice(i,1);
								i = -1;
							}
						}
					}
					result_datapool.splice(0,result_datapool.length);
					result_datapool.push(gdata);
					var rem_catchecked_array = $(fillID + " a.cat");
					$.each(rem_catchecked_array, function() {
						 $(this).removeClass('cat-checked');
					});
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
			s.unbind('click').bind('click', function() {
				var sic = $(this).is(':checked'), sdata = $(this).attr("data");
				if (sic) {
					result_datapool.splice(0,result_datapool.length);
					result_datapool.push(sdata);
					var rem_catchecked_array = $(fillID + " a.cat");
					$.each(rem_catchecked_array, function() {
						 $(this).removeClass('cat-checked');
					});
					isexceed() ? ace.addClass('cat-checked') : result_datapool.splice($.inArray(sdata,result_datapool),1);
				} else {
					result_datapool.splice($.inArray(sdata,result_datapool),1);
					var chnum = d.find(' :checkbox[checked]').length;
					if (chnum <= 0) {
						ace.removeClass('cat-checked');
					}
				}
				copyitem();
			});
		} else{
			var l = $(this).closest("li");
			var g = l.find(".cat-touch input");
			// 判断是否有选中
			var rco_resultlist = $(resultlist + " span i");
			if (rco_resultlist.length > 0) {
				$.each(rco_resultlist, function() {
					var dsc = $(this).attr("data-code"),
					 	dscode_array = splitdata(dsc);
					if(dscode_array[0] == 0) {
						$.each(g, function() {
							if (dsc == $(this).attr("data")) {
							 	var idsc = $(this).is(':checked');
							 	$(this).attr("checked", idsc);
							}
						})
					}
				})
			} else {
				g.prop("checked", false);
			}
			l.addClass('cat-active');
			var n = $(this).next();
			n.bind('mouseenter', function() {
				var e = $(this).closest("li");
				e.attr("data-active", !0)
			}).bind('mouseleave', function() {
				var a = $(this).closest("li");
				a.removeAttr("data-active"), setTimeout(function() {
					a.attr("data-active") || ($(fillID).find(".data-sub").remove(), a.removeClass("cat-active"))
				}, 200)
			});
			g.unbind('click').bind('click', function() {
				var ic = $(this).is(':checked'), gdata = $(this).attr("data");
				if (ic) {
					result_datapool.push(gdata);
					if(isexceed()) {
						ace.addClass('cat-checked');
					} else {
						$(this).attr("checked",false);
						result_datapool.splice($.inArray(gdata,result_datapool),1);
					}
				} else {
					result_datapool.splice($.inArray(gdata,result_datapool),1);
					ace.removeClass('cat-checked');
				}
				copyitem();
			});
		};
	});
	// 确定
	$(determinebtn).unbind().click(function() {
		copy_selected();
		close_dialog();
	});
	// 取消
	$(deselectbtn).unbind().click(function() {
		close_dialog();
	});
	// 弹出框关闭
	function close_dialog() {
		$("#maskLayer").remove();
		$(showID).hide();
	}
	// 复制选中项目
	function copyitem() {
		var resulthtm = '';
		resulthtm += '<strong class="result-name">';
		result_datapool.length > 0 ? resulthtm += '已选择' : resulthtm += '请选择';
		resulthtm += '</strong>';
		$.each(result_datapool, function(indexrd,valrd) {
			var result_data_array = valrd.split(",");
			resulthtm += '<span>'+result_data_array[1]+'<i class="data-icon data-icon-close" data-code="'+result_data_array[0]+','+result_data_array[1]+'"></i></span>';
		});
		$(resultlist).html(resulthtm);
		var spi = $(resultlist + " span i");
		spi.unbind().bind('click', function() {
			var spidata = $(this).attr("data-code"),
				apid_array = splitdata(spidata);
			result_datapool.splice($.inArray(spidata,result_datapool),1);
			var catchecked_array = $(fillID + " a.cat-checked");
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if(apid_array[0]==catcheckedid_array[0] && apid_array[1]==0){
					catcobj.removeClass('cat-checked');
					catcobj.next().find("input").attr("checked", false);
				} else if (apid_array[0]==catcheckedid_array[0] && apid_array[1]!=0) {
					var rdanum = 0;
					$.each(result_datapool, function(indexdp,valdp) {
						var rdatapool_array = splitdata(valdp);
						if (apid_array[0]==rdatapool_array[0] && apid_array[1]!=0) {
							rdanum ++;
						}
					});
					if (rdanum <= 0) {
						catcobj.removeClass('cat-checked');
					}
				}
			});
			copyitem();
		});
	}
	// 分割data 返回数组
	function splitdata(arr) {
		if (arr) {
			var arrs_array = arr.split(","),
				arrid_array = arrs_array[0].split(".");
			return arrid_array;
		}
	}
	// 判断选择数量是否超出
	function isexceed() {
		if(result_datapool.length >= 1) {
			// alert("最多可选3个");
			// return false;
			copy_selected();
			close_dialog();
			return true;	
		} else {
			return true;
		}
	}
	// 复制选中 赋值
	function copy_selected() {
		var selectedhtm = "";
		var selectedid_array = new Array();
		var selectedcn_array = new Array();
		for (var i = 0; i < result_datapool.length; i++) {
			if (result_datapool[i]) {
				var data_array = result_datapool[i].split(",");
				selectedhtm += '<span data-code="'+data_array[0]+','+data_array[1]+'">'+data_array[1]+'<a class="close" style="top: 2px;"></a></span>';
				selectedid_array[i]=data_array[0];
				selectedcn_array[i]=data_array[1];
			};
		};
		$(resultshowID + " .items").html(selectedhtm);
		var spanwidth = 0, itemswidth = $(resultshowID).width()-28, widtharray = new Array();
		if($(resultshowID + " .items span")) {
			$(resultshowID + " .items span").each(function(index) {
				spanwidth = spanwidth + $(this).outerWidth(true);
				widtharray[index] = $(this).outerWidth(true);
			})
		}
		var difwidth=spanwidth-itemswidth;
		if (widtharray.length == 2) {
			if(widtharray[0] + widtharray[1] > itemswidth) {
				setHeightCss(40);
			} else {
				setHeightCss(20);
			}
		} else if (widtharray.length == 3) {
			if(widtharray[0] + widtharray[1] + widtharray[2] > itemswidth) {
				if(widtharray[0] + widtharray[1] > itemswidth) {
					if(widtharray[1] + widtharray[2] > itemswidth) {
						setHeightCss(60);
					} else {
						setHeightCss(40);
					}
				} else {
					setHeightCss(40);
				}
			}
		} else {
			setHeightCss(20);
		}
		function setHeightCss (val) {
			$(resultshowID).css("height",val+"px");
			$(resultshowID + " .items").css("height",val+"px");
			$(resultshowID + " em").css("height",val+10+"px");
		}
		$(resultshowID + " span").unbind().click(function() {
			var dtid = $(this).attr("data-code"),
				dtid_array = splitdata(dtid);
			for (var i = 0; i < result_datapool.length; i++) {
				result_datapool.splice($.inArray(dtid,result_datapool),1);
				i = -1;
			};
			copyitem();
			var catchecked_array = $(fillID + " a.cat-checked");style="top: 2px;"
			$.each(catchecked_array, function() {
				var catcobj = $(this), catcheckedid_array = splitdata(catcobj.attr("data"));
				if(dtid_array[0]==catcheckedid_array[0] && dtid_array[1]==0){
					catcobj.removeClass('cat-checked');
					catcobj.next().find("input").attr("checked", false);
				} else if (dtid_array[0]==catcheckedid_array[0] && dtid_array[1]!=0) {
					var rdanum = 0;
					$.each(result_datapool, function(indexdp,valdp) {
						var rdatapool_array = splitdata(valdp);
						if (dtid_array[0]==rdatapool_array[0] && dtid_array[1]!=0) {
							rdanum ++;
						}
					});
					if (rdanum <= 0) {
						catcobj.removeClass('cat-checked');
					}
				}
			});
			copy_selected();
		});
		if (selectedid_array.length > 0) {
			var dsid_array = selectedid_array[0].split(".");
			$("#district").val(dsid_array[0]);
			$("#sdistrict").val(dsid_array[1]);
		}
		$(resulthidCN).val(selectedcn_array.join(","));
	}
}
/*职位亮点弹出层填充数据*/
function tag_filldata(fillID, data_resources, showID, determinebtn, deselectbtn, resultlist, resulthidId, resultshowID) {
	var taghtm = '', result_datapool = new Array();
	for (var j = 0; j < data_resources.length; j++) {
		if (data_resources[j]) {
			var tag_array = data_resources[j].split(",");
			taghtm += '<span data-code="'+tag_array[0]+','+tag_array[1]+'" title="'+tag_array[1]+'" class="tag">'+tag_array[1]+'</span>';
		};
	}
	$(fillID).html(taghtm);
	// 全部恢复
	if ($(resulthidId).val().length > 0) {
		result_datapool = $(resulthidId).val().split("|");
		var cata_array = $(fillID + " span");
		$.each(cata_array, function() {
			var catcobj = $(this), catcheckedval = catcobj.attr("data-code");
			$.each(result_datapool, function(indexdp,valdp) {
				if (valdp == catcheckedval) {
					catcobj.addClass('tag-disabled');
				}
			})
		})
		copyitem();
		copy_selected();
	}
	$(fillID + " span").unbind().on("click",function() {
		var sdata = $(this).attr("data-code");
		if ($(this).hasClass('tag-disabled')) {
			$(this).removeClass('tag-disabled');
			result_datapool.splice($.inArray(sdata,result_datapool),1);
			copyitem();
		} else {
			if (isexceed()) {
				$(this).addClass('tag-disabled');
				result_datapool.push(sdata);
				copyitem();
			}
		}
	});
	// 复制选中项
	function copyitem() {
		var resulthtm = '';
		resulthtm += '<p class="no-tag muted text-center"';
		result_datapool.length > 0 ? resulthtm += ' style="display: none;"' : resulthtm += ' style="display: block;"';
		resulthtm += '>暂无亮点</p>';
		$.each(result_datapool, function(indexrd,valrd) {
			var result_data_array = valrd.split(",");
			resulthtm += '<span class="tag"><cite>'+result_data_array[1]+'</cite><i title="移除" class="icn-close" data-code="'+result_data_array[0]+','+result_data_array[1]+'">×</i></span>';
		});
		$(resultlist).html(resulthtm);
		var spi = $(resultlist + " span i");
		spi.unbind().bind('click', function() {
			var spidata = $(this).attr("data-code");
			result_datapool.splice($.inArray(spidata,result_datapool),1);
			var catchecked_array = $(fillID + " span.tag-disabled");
			$.each(catchecked_array, function() {
				if(spidata == $(this).attr("data-code")){
					$(this).removeClass('tag-disabled');
				}
			})
			copyitem();
		});
	}
	// 复制选中 赋值
	function copy_selected() {
		var selectedhtm = "";
		var selectedid_array = new Array();
		if(result_datapool.length > 0) {
			selectedhtm+='<article class="tag-list" style="display: block;">';
			for (var i = 0; i < result_datapool.length; i++) {
				if (result_datapool[i]) {
					var data_array = result_datapool[i].split(",");
					selectedhtm += '<span title="'+data_array[1]+'" class="tag">'+data_array[1]+'</span>';
					selectedid_array[i]=result_datapool[i];
				};
			}
			selectedhtm+='<a class="edit-tag" id="trad_window_tag" data-selector="oprator-tag" href="javascript:;">编辑</a></article>';
		} else {
			selectedhtm+='<span class="fuli link_blue">增加亮点可以吸引求职者快速应聘职位，<a id="trad_window_tag" href="javascript:;">立即增加亮点</a></span>';
		}
		$(resultshowID).html(selectedhtm);
		$(resulthidId).val(selectedid_array.join("|"));
	}
	// 分割data 返回数组
	function splitdata(arr) {
		var arrs_array = arr.split(",");
		return arrs_array;
	}
	// 判断选择数量是否超出
	function isexceed() {
		if(result_datapool.length >= 6) {
			alert("最多可选6个");
			return false;
		} else {
			return true;
		}
	}
	// 确定
	$(determinebtn).unbind().click(function() {
		copy_selected();
		close_dialog();
	});
	// 取消
	$(deselectbtn).unbind().click(function() {
		close_dialog();
	});
	// 弹出框关闭
	function close_dialog() {
		$("#maskLayer").remove();
		$(showID).hide();
	}
}
/*有关搜索页面列出当前搜索条件*/
function searchHistory() {
	if($("#search_history")) {
		var history_input_array = $("#search_history").find('input'),
			history_array = new Array(),
			historyhtm = '';
		$.each(history_input_array, function(index, val) {
			if ($(this).val()) {
				history_array.push($(this).val());
			}
		});
		history_array.length > 0 ? historyhtm += '当前搜索条件：' : historyhtm += '';
		for (var i = 0; i < history_array.length; i++) {
			historyhtm += history_array[i];
			i+1 == history_array.length ? historyhtm += "" : historyhtm += " + ";
		};
		$("#search_history").find('span').html(historyhtm);
	}
}