$(document).ready(function(){
	var ctx = $("#ctx").val();//获取服务器地址
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	
	/***************************    选择行业    ***************************/
	
	if($("#fatherId").val() == "" && $("#industryId").val() != ""){
		$('.industry_oper').val("上一步");
		parent.layer.title("选择行业");
		$('.industry_save').removeClass("industry_change");
	}
	if(($("#fatherId").val() == ""  && $("#industryId").val() == "" ) || ($("#fatherId").val() != "" && $("#industryId").val() == "")){
		$('.industry_oper').val("下一步");
		parent.layer.title("选择父行业");
		$('.industry_save').addClass("industry_change");
	}
	
	$(".industry_oper").click(function(){
		if($(this).val() == "下一步"){
			var industryId = $("#selectIndustryDiv input[name='industry']:checked").val();
			if(industryId == undefined){
				alert("请选择父行业之后，在进行下一步操作！");
				return false;
			}
			$("#fatherId").val(parseInt(industryId));
			$("#selectIndustryForm").attr("action", "getIndustry");
			$('#selectIndustryForm').submit();
		}else if($(this).val() == "上一步"){
			$("#selectIndustryForm").attr("action", "getAllFatherIndustry");
			$('#selectIndustryForm').submit();
		}
	});
	
	$(".industry_save").click(function(){
		var industryId = $("#selectIndustryDiv input[name='industry']:checked").val();
		if(industryId == undefined){
			alert("请选择行业！");
			return false;
		}
		parent.$('#industryFatherId').val($("#industryId").val());
		parent.$('#industryId').val(industryId);
		parent.$("#selectIndustry_span").text("已选择行业 —— "+ $("#selectIndustryDiv input[name='industry']:checked").attr("title"));
		parent.$("#industryul_selectdiv").find('span.spanVaildate').html("");
		parent.layer.close(index);//再执行关闭
	});
	
	$("#selectIndustryDiv input[name='industry']").each(function(){
		if($(this).val() == $('#fatherId').val() || $(this).val() == $('#industryId').val() || 
				$(this).val() == parent.$('#industryFatherId').val() || $(this).val() == parent.$('#industryId').val()){
			$(this).attr('checked',true);
		}
	});
	
	$("#selectIndustryDiv input[name='industry']").click(function(){
		if($(".industry_oper").val() == "下一步"){
			$('#industryId').val($(this).val());
			$("#fatherId").val($(this).val());
		}else if($(".industry_oper").val() == "上一步"){
			$("#fatherId").val($(this).val());
		}
	});
	
	// 分页中超链接跳转
	$('#selectIndustryForm .pagination ul li a[href]').click(function(){
		var _page = $(this).attr('href').substr(1);
		$('#selectIndustryForm').find('input:hidden[name="page"]').val(_page);
		$('#selectIndustryForm').submit();
	});

});