function checkCity(a) {
	var b;
	return $.ajax({
		type: "POST",
		async: !1,
		url: ctx + "/jobs/checkCity.json",
		data: {
			city: a
		}
	}).done(function(a) {
		b = a.success
	}), b
}

function img_check(a, b, c, d) {
	var e = $("#" + d).val();
	this.AllowExt = ".jpg,.gif,.jpeg,.png,.pjpeg", this.FileExt = a.value.substr(a.value.lastIndexOf(".")).toLowerCase(), 0 != this.AllowExt && -1 == this.AllowExt.indexOf(this.FileExt) ? $("#" + c + "_error").text("只支持jpg、gif、png、jpeg格式，请重新上传").show() : ($("#" + c + "_error").text("").hide(), $.ajaxFileUpload({
		url: b,
		secureuri: !1,
		fileElementId: c,
		data: {
			type: e
		},
		dataType: "text",
		success: function(a) {
			"" != a ? ($("#logoShow img").attr("src", ctx + "/" + a), $("#logoNo").hide(), $("#logoShow").show(), $("#logo").val(a)) : $("#" + c + "_error").text("上传失败，请重新上传").show()
		},
		error: function() {
			$("#" + c + "_error").text("上传失败，请重新上传").show()
		}
	}))
}
$(function() {
	var b, c, a = !1;
	// window.onbeforeunload = function() {
	// 	return a ? void 0 : "内容还未保存，确认离开该页面吗？ "
	// }, 
	$("#stepTip a").bind("click", function() {
		$(this).parent("#stepTip").remove()
	}), b = {
		expires: 1
	}, null == $.cookie("viewTimes") ? ($("#stepTip img").attr("src", ctx + "/images/tiponce.jpg").parent("#stepTip").fadeIn(200), $.cookie("viewTimes", "1", b)) : (c = parseInt($.cookie("viewTimes")) + 1, $("#stepTip img").attr("src", ctx + "/images/tipagain.jpg").parent("#stepTip").fadeIn(200), $.cookie("viewTimes", c, b)), $(document).click(function() {
		var a = [];
		$("#box_industry li.current").length > 2 ? alert("行业领域最多可选2个") : ($("#box_industry li.current").each(function() {
			a.push($(this).text())
		}), "" == a.join() ? $("#select_industry").val("请选择行业领域") : $("#select_industry").val(a.join()), $("#select_industry_hidden").val(a.join()), $("#box_industry").hide()), $("#box_industry").hide(), $("#box_scale").hide(), $("#stagesList .box_invest").hide()
	}), $("#select_industry").bind("click", function(a) {
		a.stopPropagation(), $("#box_industry").show(), $("#box_scale").hide(), $("#stagesList .box_invest").hide()
	}), $("#box_industry").on("click", "ul li", function(a) {
		a.stopPropagation();
		var b = [];
		$(this).hasClass("current") ? ($(this).removeClass("current"), $("#box_industry li.current").each(function() {
			b.push($(this).text())
		}), $("#select_industry").val(b.join()), $("#select_industry_hidden").val(b.join())) : 0 == $(this).siblings("li.current").length ? ($(this).addClass("current"), b.push($(this).text()), $("#select_industry").val(b.join()), $("#select_industry_hidden").val(b.join())) : 1 == $(this).siblings("li.current").length ? ($(this).addClass("current"), $("#box_industry li.current").each(function() {
			b.push($(this).text())
		}), $("#select_industry").val(b.join()), $("#select_industry_hidden").val(b.join()), $("#box_industry").hide()) : $(this).siblings("li.current").length >= 2 && alert("行业领域最多可选2个"), $("#stepForm").validate().element("#select_industry_hidden")
	}), $("#select_scale").bind("click", function(a) {
		a.stopPropagation(), $("#box_scale").show(), $("#box_industry").hide(), $("#stagesList .box_invest").hide()
	}), $("#box_scale").on("click", "ul li", function(a) {
		a.stopPropagation();
		var b = $(this).text();
		$("#select_scale,#select_scale_hidden").val(b), $("#box_scale").hide(), $("#stepForm").validate().element("#select_scale_hidden")
	}), $("#box_industry,#box_scale").bind("click", function(a) {
		a.stopPropagation()
	}), $(".s_radio li").click(function() {
		var b = $(this).text();
		$("#s_radio_hidden").val(b), $(this).addClass("current").append("<em></em>").siblings().removeClass("current").find("em").remove(), $("#stepForm").validate().element("#s_radio_hidden")
	}), $("#stagesList").on("click", ".select_invest", function(a) {
		a.stopPropagation(), $("#box_scale").hide(), $("#box_industry").hide(), $(this).parents("li").siblings().children(".box_invest").hide(), $(this).siblings(".box_invest").show()
	}), $("#stagesList").on("click", ".box_invest li", function(a) {
		var b, c;
		a.stopPropagation(), b = $(this).html(), c = $(this).parents("li"), $(".select_invest,.select_invest_hidden", c).val(b), $(this).parents(".box_invest").hide(), c.index() == $("#stagesList > li").length - 1 && $("#stagesList > li").length < 10 && c.children(".select_invest").trigger("change")
	}), $("#stagesList").on("change", ".select_invest", function() {
		var a = $("#cloneInvest").html();
		$("#stagesList").append("<li>" + a + "</li>")
	}), $("#stepForm").validate({
		onkeyup: !1,
		focusCleanup: !0,
		rules: {
			name: {
				required: !0,
				specialchar: !0,
				maxlenStr: 100
			},
			myfiles: {
				required: !1
			},
			website: {
				required: !0,
				checkUrl: !0,
				maxlength: 120
			},
			city: {
				required: !0,
				cityAvailable: !0,
				maxlenStr: 20
			},
			select_industry_hidden: {
				required: !0
			},
			select_scale_hidden: {
				required: !0
			},
			s_radio_hidden: {
				required: !0
			},
			select_invest_hidden: {
				required: !1
			},
			stageorg: {
				required: !1,
				maxlenStr: 100
			},
			temptation: {
				required: !0,
				checkNum: !0,
				minlength: 5,
				maxlenStr: 50
			}
		},
		messages: {
			name: {
				required: "请输入有效的公司简称",
				specialchar: "请输入有效的公司简称",
				maxlenStr: "请输入100字以内的公司简称"
			},
			website: {
				required: "请输入公司网址，如：www.lagou.com",
				checkUrl: "请输入有效的公司网址",
				maxlength: "请输入120字符以内的网址"
			},
			city: {
				required: "请输入公司所在城市，如：北京",
				maxlenStr: "请输入有效的公司所在城市"
			},
			select_industry_hidden: {
				required: "请选择公司行业领域"
			},
			select_scale_hidden: {
				required: "请选择公司规模"
			},
			s_radio_hidden: {
				required: "请选择公司发展阶段"
			},
			stageorg: {
				maxlenStr: "请输入100字以内的投资机构"
			},
			temptation: {
				required: "请一句话概括公司亮点，如：公司愿景、领导团队等，限50字",
				minlength: "请输入5-50字的一句话介绍",
				maxlenStr: "请输入5-50字的一句话介绍"
			}
		},
		errorPlacement: function(a, b) {
			"hidden" == b.attr("type") ? a.insertAfter($(b).parent()) : a.insertAfter(b)
		},
		submitHandler: function(b) {
			var c, d, e, f, g, h, i, j, k, l, m, n, o;
			a = !0, c = $("#companyId").val(), d = $("#companyName").val(), e = $("#name").val(), f = $("#logoShow img").attr("src"), g = $("#website").val(), "http://" != g.substring(0, 7) && (g = "http://" + g), h = $("#city").val(), i = $("#select_industry_hidden").val(), j = $("#select_scale_hidden").val(), k = $("#s_radio_hidden").val(), l = "", l += "[", $("#stagesList > li").each(function(a) {
				m = $(this).children('input[name="select_invest_hidden"]').val(), n = $(this).children('input[name="stageorg"]').val() != $(this).children('input[name="stageorg"]').attr("placeholder") ? $(this).children('input[name="stageorg"]').val() : "", l += a == $("#stagesList > li").length - 1 ? '{"stage":"' + m + '","org":"' + n + '"}' : '{"stage":"' + m + '","org":"' + n + '"},'
			}), l += "]", o = $("#temptation").val(), $(b).find(":submit").attr("disabled", !0), $.ajax({
				type: "POST",
				data: {
					companyId: c,
					companyName: d,
					companyShortName: e,
					logo: f,
					companyUrl: g,
					city: h,
					industryField: i,
					companySize: j,
					financeStage: k,
					stages: l,
					companyFeatures: o
				},
				dataType: "json",
				url: "?r=company/setone"
			}).done(function(a) {
				a.success == true ? window.location.href = "?r=company/settwo" : $("#beError").text(a.msg).show(), $(b).find(":submit").attr("disabled", !1);
				
				// a.success ? window.location.href = "?r=company/settwo" : $("#beError").text(a.msg).show(), $(b).find(":submit").attr("disabled", !1)
			})
		}
	}), jQuery.validator.addMethod("cityAvailable", function(a, b) {
		return this.optional(b) || checkCity(a)
	}, "请输入有效的公司所在城市，如：北京")
});