﻿// JavaScript Document
var industry_text_id = ".industry";		//页面用来显示选中行业的表单
var industry_ids_id = "#Industry_id";	//页面用来记录选中行业id的表单

$(document).ready( function() {
	var industry_map = "";
	industry_map += "<div id='float_industry' style='width:400px;position:absolute;z-index:100;top:0;left:0;border:2px #D3E3EA solid;background:#FFF url(/images/industry_bg.jpg) repeat-x;padding-bottom:10px;display:none;'>";
		industry_map += "<div style='margin:0 15px 10px 15px;text-align:right;height:35px;border-bottom:1px #000 solid;'>";
			industry_map += "<img src='/images/checkall.gif' style='margin:5px;cursor:pointer;' onclick='checkthemall(true);' /><img src='/images/uncheckall.gif' style='margin:5px;cursor:pointer;' onclick='checkthemall(false);' /><img src='/images/apply.gif' style='margin:5px;cursor:pointer;' onclick='checkthemapply();' />";
		industry_map += "</div>";
		industry_map += "<ul style='margin:0;padding:0 15px;list-style-type:none;'></ul>";
	industry_map += "</div>";
	$(document.body).append(industry_map);
	
	//点击其他位置关闭
	$("#body").click( function() {
		if ( industry_click ) {
			$("#float_industry").fadeOut("fast",function() { industry_click = false; });
		}
	} );
	//触发
	$(industry_text_id + " .keyword").click( function() {
		showIndustry($(industry_ids_id).attr("value"));
	} );
	$(window).resize( function() {
		if ( industry_click ) {
			$("#float_industry").css( { "left" : $(industry_text_id + " .keyword").offset().left + "px" , "top" : ( $(industry_text_id + " .keyword").offset().top + 23 ) + "px"  } );
		}
	} );
} );

var industry_click = false;
//显示
function showIndustry(defaults) {
	if ( !industry_click ) {
		$.ajax( {
			type: "post",
			url: "/ajax/industry.asp",
			cache: false,
			data: "",
			dataType: ($.browser.msie) ? "text" : "xml",
			success: function(result) {
				if ( typeof result == "string" ) {
					var xml = new ActiveXObject("Microsoft.XMLDOM");
					xml.async = false;
					xml.loadXML(result);
				}
				else {
					var xml = result;
				}
				var industry = xml.getElementsByTagName("root")[0].getElementsByTagName("industry") , xmldate;
				$("#float_industry ul:first").empty();
				for ( var x = 0 ; x < industry.length ; x++ ) {
					xmldate = "<li style='width:175px;height:30px;padding:0 5px;float:left;text-align:left;font-size:14px;color:#222;overflow:hidden;'>";
						xmldate += "<input type='checkbox' value='" + industry[x].getAttribute("id") + "'";
						if ( defaults != "" ) {
							for ( var i = 0 ; i < defaults.split(",").length ; i++ ) {
								if ( defaults.split(",")[i] === industry[x].getAttribute("id") ) {
									xmldate += " checked='checked'";
								}
							}
						}
						xmldate += " style='cursor:default;' onfocus='this.blur();' />　<span style='cursor:pointer;'>" + industry[x].getAttribute("I_Name") + "</span>";
					xmldate += "</li>";
					$("#float_industry ul:first").append(xmldate);
				}
				$("#float_industry ul:first").find("span").click( function() {
					setcheckbox($(this).parent());
				} );
			}
		} );
		$("#float_industry").css( { "left" : $(industry_text_id + " .keyword").offset().left + "px" , "top" : ( $(industry_text_id + " .keyword").offset().top + 23 ) + "px"  } );
		$("#float_industry").fadeIn("fast",function() {
			industry_click = true;
			////////scrollgoto((this.offsetTop - 20),5);
		} );
	}
}

//点击文字，复选框选中
function setcheckbox(obj) {
	if ( obj.find("input").attr("checked") ) {
		obj.find("input").attr("checked",false);
	}
	else {
		obj.find("input").attr("checked",true);
	}
}

//全选与取消
function checkthemall(type) {
	$("#float_industry ul:first :checkbox").attr("checked",type);
}

//接受
function checkthemapply() {
	var applys = $("#float_industry ul:first :checkbox:checked") , industry_text = "" , industry_ids = "" , i = 0;
	applys.each( function() {
		industry_text += $(this).parent().text().replace("　","");
		industry_ids += $(this).attr("value");
		if ( i < applys.length - 1 ) {
			industry_text += "｜" , industry_ids += ",";
		}
		i++;
	} );
	$(industry_text_id + " .keyword marquee").text(industry_text);
	$(industry_ids_id).attr("value",industry_ids);
	$("#float_industry ul:first :checkbox").attr("checked",false);
	$("#float_industry").fadeOut("fast",function() { industry_click = false; $("#searchForm").submit(); });
}