/*
 * http://www.thinkhu.com/ 
 * Copyright (c) 2011 ThinkHu @hzpyy@foxmail.com
 * Date: 20011-05-07 09:19:21 QQ:415480171
 * v 1.1 job.thk.js,
 */
var register_box = null;
if(typeof APP_URL == "undefined"){
	var APP_URL = "http://127.0.0.1/";
}
var personservice_navhtml = '<div class="convenient_title fb fred tl">个人服务</div>\
				<div class="convenient_list of f6e tl">\
					<ul>\
					<li><a href="'+APP_URL+'?s=resume">简历中心</a></li>\
					<li><a target="_blank" href="'+APP_URL+'?s=news/lists&type=list&tid=9">求职宝典</a></li>\
					<li><a target="_blank" href="'+APP_URL+'?s=news/lists&type=list&tid=1">学历招生</a></li>\
					<li><a target="_blank" href="'+APP_URL+'?s=news/lists&type=list&tid=6">技能培训</a></li>\
					<li><a href="javascript:void(0)" onclick="person_recommend()">申请自荐</a></li>\
					<li><a target="_blank" href="'+APP_URL+'?s=news/lists&type=list&tid=12">政策法规</a></li>\
					<li><a target="_blank" href="'+APP_URL+'javascript:void(0);">薪酬调查</a></li>\
					<li><a target="_blank" href="'+APP_URL+'?s=news/lists&type=list&tid=10">职业经理人</a></li>\
					</ul>\
				<div class="cl"></div></div><div class="y_10"></div><div class="convenient_title fb tr"><a href="#" class="fred">更多服务</a></div>';
var companyservice_navhtml = '<div class="convenient_title fb fred tl">企业服务</div>\
						<div class="convenient_list of f6e">\
							<ul>\
								<li><a target="_blank" href="'+APP_URL+'html/about/ad.shtml?3,2">收费标准</a></li>\
								<li><a target="_blank" href="'+APP_URL+'html/about/client.shtml?3,1">广告服务</a></li>\
								<li><a target="_blank" href="'+APP_URL+'html/about/process.shtml?3,3">招聘流程</a></li>\
								<li><a target="_blank" href="'+APP_URL+'html/about/client.shtml?3,1">服务总览</a></li>\
								<li><a target="_blank" href="'+APP_URL+'html/about/index.shtml">HR社区</a></li>\
								<li><a target="_blank" href="'+APP_URL+'html/about/index.shtml">HR调研</a></li>\
							</ul>\
							<div class="cl"></div>\
						</div><div class="y_10"></div>\
						<div class="convenient_title fb tr"><a href="#" class="fred">更多服务</a></div>';
var trade_navhtml = '<div class="convenient_title fb fred tl" style="cursor:pointer">行业专区</div>\
						<div class="convenient_list of f6e tl">\
							<ul>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=waimao">外贸专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=fuzhuang">服装专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=yinshua">印刷专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=jieju">洁具专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=shipin">食品专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=famen">泵阀专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=xieyre">鞋业专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=dianzi">电子专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=dianqi">电气专区</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=build">建筑/装饰</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=jiaoyu">教育培训</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=qiche">汽车贸易</a></li>\
								<li><a href="'+APP_URL+'?s=zph/prefecture&&type=qmp">汽摩配</a></li>\
								<li><a href="http://www.chemjob.com.cn/">化工专区</a></li>\
							</ul>\
							<div class="cl"></div>\
						</div>\
						<div class="y_10"></div>\
						<div class="convenient_title fb tr"><a href="'+APP_URL+'?s=zph/prefecture&&type=waimao" class="fred">更多行业</a></div>';
$(function(){
	//tabshow 
	$("a[tab=1]").each(function(){
		$(this).bind("mouseover",function(){
			var htmlstr = "";
			var showid = $(this).attr("showid");
			switch(showid){
				default:
				break;
				case "tab_personservice":
				case "tab_navweb":
				htmlstr = personservice_navhtml;
				break;
				case "tab_companyservice":
				htmlstr = companyservice_navhtml;
				break;
				case "tab_trade":
				htmlstr = trade_navhtml;
				break;
				case "nav_easy":
				htmlstr = personservice_navhtml+companyservice_navhtml;
				break;
			}
			$("#"+showid).find(".convenient_content").html(htmlstr);
			$("#"+showid).show().bind("mousemove",function(event){$(this).show();event.stopPropagation();}).bind("mouseover",function(event){$(this).show();event.stopPropagation();}).bind("mouseout",function(event){
						$("#"+showid).hide();
						event.stopPropagation();
			});
		});
	});
	//body单击事件
	$(document.body).bind("click",function(){
	});
});
var login_err = [];
login_err["err_username"] = "请填写合法的用户名5-20个字符";
login_err["err_password"] = "请填写合法的密码5-20个字符";
//登录类型改变
function chang_usertype(obj){
	var usertype = $(obj).attr("t");
    $("#hid_usertype").val(usertype);
	$("#loginnav").find("a").each(function(){
		$(this).removeClass("dis");
	});
	$(obj).addClass("dis");
}

//登录提交
function toploginsubmit(formid){
	    var is_error = false;
	    var errmsg = "";
	    var formurl = APP_URL+"index.php?s=login";
	    var JQform = $("#"+formid);
	    var isgo = parseInt(JQform.find("input[name='isgo']").val());
	    var user_type = parseInt(JQform.find("input[name=user_type]").val());
	    if(typeof user_type == "undefined"){
	    	alert("请先选择会员类型");
	    	return false;
	    }else if(user_type == 0){
	    	formurl += "/person";
	    }else if(user_type == 1){
	    	formurl += "/company";
	    }
	    JQform.attr("action",formurl+"&isgo="+isgo);
		JQform.find("input[check=1]").each(function(){
			if(!toplogincheck(this)){
				is_error = true;
				errmsg = login_err["err_"+$(this).attr("name")];
				alert(errmsg);
			    return false;
			}
		});
		if(is_error == true)return false;
		JQform.find(".btn_loginsubmit").attr("disabled",true);
		JQform.find(".ajaxmsg").html("<span>正在登录，请稍后……</span>").show();
		App.form(JQform[0],function(res){
			JQform = $("#"+formid);
			if(res.error == 1){
				JQform.find(".ajaxmsg").html("<span>"+res.message+"</span>").show();
				JQform.find(".btn_loginsubmit").attr("disabled",false);
				setTimeout("$('.ajaxmsg').hide()",1000);
				return false;
			}else{
				JQform.find(".ajaxmsg").html("<span>"+res.content+"</span>").show();
				if(res.htmlval){
					setTimeout(function(){
						JQform.find(".ajaxmsg").hide();
						$("#logininfo").html(res.htmlval);
					},500);
				}else if(res.url){
					setTimeout("App.redirect('"+res.url+"')",1000);
				}
				return false;
			}
		});
	    return false;
}
//检查值
function toplogincheck(obj){
	var check_item = $(obj).attr("name");
	var check_length = $(obj).attr("len");
	var check_val = $(obj).val();
	var is_check = $(obj).attr("error");
	var is_error = false;
	if(check_val == "" || $.mb_strlen(check_val) < check_length)is_error = true;
	if(is_error == false && is_check != 0){

	}
	return !is_error;
}
//收藏职位
function fav_post(post_id){
	var url = "index.php?s=person/favpost&app=appname-favpost-post_id-"+post_id;
	App.get(url,function(res){
		if(res.type == "login"){
			POPS["login_box"] = App.html(res.message,"个人登录",300);
		}else if(res.error == 1){
			alert(res.message);
		}else{
			alert(res.content);
		}
	});
}
//申请职位
function apply_post(post_id,type,page){
	//var spage = typeof page == "undefined"?"in":page;
	var url = "index.php";//(spage == "in")?"index.php":"../../index.php";
	var type = (typeof type == "undefined")?0:type;
	url += "?s=person/applypost&app=appname-applypost-post_id-"+post_id;
	if(type == 0){
		App.get(url,function(res){
			if(res.type == "login"){
				POPS["login_box"] = App.html(res.message,"个人登录",300);
			}else if(res.type == "qzx"){
				POPS["qzx"] = App.html(res.content,"申请职位",500);
			}else{
				alert(res.message);
			}
		});
	}else if(type == 1){
		$("#div_qzx").find("input[type='submit']").attr("disabled",true);
		App.form($("#form_qzx")[0],function(res){
			if(res.error == 1){
				alert(res.message);
			}else{
				alert(res.content);
			}
			POPS["qzx"].close();
		});
		return false;
	}
}
//检查用户是否已经登录
function check_person_login(appname,parm){
	var appname = typeof appname == "undefined"?"checklogin":appname;
	var url = "index.php?s=person/checkonline&app=appname-"+appname;
	var parms = parm.split("-");
	if(typeof parm != "undefined")url += "-"+parm;
	App.get(url,function(res){
		if(res.type == "login"){
			POPS["login_box"] = App.html(res.message,"个人登录",300);
		}else if(res.type == "online"){
			switch(appname){
				default:
				break;
				case "postop_more":
				postopmore(parms[1]);
				break;
			}
		}
	});
}
//加载最新职位
function load_post(box_id,type,num,pcount,clen,showloading){
	var num = typeof num == "undefined"?18:num;
	var type = typeof type =="undefined"?"new":type;
	var url = "index.php?s=findposts/companyjob&ptype="+type+"&num="+num+"&pcount="+pcount+"&clen="+clen;
	var showloading = (typeof showloading == "undefined")?1:showloading;
	var box = $("#"+box_id);
	if(showloading == 1 && box.find(".loading")[0]){
	    box.find(".loading").show();
	}else if(showloading == 1){
		var loading = $("<div class=\"loading\" style=\"width:32px; height:32px;\"><img src=\""+APP_URL+"common/images/loading2.gif\"></div>").css({"z-index":999,"position":"absolute","left":((box.width()-32)/2),"top":30});
		box.css({"position":"relative"}).append(loading);
	}
	App.get(url,function(res){
		if(res.error == 1){
			alert(res.message);
			box.find(".loading").hide();
		}else{
		    box.append(res.content);
		    box.attr("load",1);
		    box.find(".loading").hide();
		}
	})
}
//加载最新简历
function load_resume(box_id,type,num,other,showloading){
	var num = typeof num == "undefined"?18:num;
	var type = typeof type =="undefined"?"tuijian":type;
	var other = typeof other == "undefined"?"":other;
	var url = "index.php?s=findresume/resumes&ptype="+type+"&num="+num+other;
	var showloading = (typeof showloading == "undefined")?1:showloading;
	var box = $("#"+box_id).show();
	if(showloading == 1 && box.find(".loading")[0]){
	    box.find(".loading").show();
	}else if(showloading == 1){
		var loading = $("<div class=\"loading\" style=\"width:32px; height:32px;\"><img src=\""+APP_URL+"common/images/loading2.gif\"></div>").css({"z-index":999,"position":"absolute","left":((box.width()-32)/2),"top":30});
		box.css({"position":"relative"}).append(loading);
	}
	App.get(url,function(res){
		if(res.error == 1){
			alert(res.message);
			box.find(".loading").hide();
		}else{
		    box.append(res.content);
		    box.attr("load",1);
		    box.find(".loading").hide();
		}
	})
}
//加载新闻
function load_news(box_id,type,num,other){
	var num = typeof num == "undefined"?18:num;
	var type = typeof type =="undefined"?0:type;
	var other = typeof other == "undefined"?"":other;
	var url = "index.php?s=news/getnews&type="+type+"&num="+num+other;
	//var showloading = (typeof showloading == "undefined")?1:showloading;
	var box = $("#"+box_id).show();
	showloading(2,box);
	App.get(url,function(res){
		if(res.error == 1){
			alert(res.message);
		}else{
		    box.append(res.content);
		    box.attr("load",1);
		}
		closeloading(box);
	})
}
//搜索关键词切换
function searchkey_select(obj){
	$("#searchkey_select").find(".dis").removeClass("dis");
	$(obj).addClass("dis");
	$("input[name='keywordstype']").val($(obj).attr('name'));
}
//全选，全不选函数
function selectall(obj){
	var selected = ($(obj).attr("checked") == true)?true:false;
	var names = $(obj).attr("_name");
    $("input[name='"+names+"[]'],input[_name='"+names+"']").attr("checked",selected);
}
//加载相关行业
function load_relative(box_id,type,num,otherstr,isshowloading){
	var num = typeof num == "undefined"?18:num;
	var type = typeof type =="undefined"?"new":type;
	var otherstr = typeof otherstr == "undefined"?"":("&"+otherstr);
	var url = "index.php?s=findposts/companyjob&ptype="+type+"&num="+num+otherstr;
	var isshowloading = (typeof isshowloading == "undefined")?1:isshowloading;
	var box = $("#"+box_id);
	showloading(2,box);
	App.get(url,function(res){
		if(res.error == 1){
			alert(res.message);
		}else{
		    box.append(res.content);
		    box.attr("load",1);
		}
		closeloading(box);
	})
}
//
function formcheck(obj){
	        var checktype = $(obj).attr("checktype");
        	var val = $(obj).val();
        	var errormsg = $(obj).attr("errmsg");
        	var okmsg = $(obj).attr("okmsg");
        	var msg = $(obj).attr("msg");
        	var id = $(obj).attr("id");
        	var iserror = 0;
        	var min = parseInt($(obj).attr("min"));
            var max = parseInt($(obj).attr("max"));
        
        	errormsg = typeof errormsg == "undefined"?"":errormsg;
        	okmsg = typeof okmsg == "undefined"?"":okmsg;
        	msg = typeof msg == "undefined"?"":msg;
        	
        	
        	switch(checktype){
        		case "email":
        		    if(!$.is_email(val))iserror = 1;
        		    break;
        		case "tel":
        		    if(val != ''){
	        		    val = $("#"+id+"_pre").val()+"-"+val;
	        		    if(val && !$.is_tel(val))iserror = 1;
        		    }
        		    break;
        		case "mobile":
        		    if(!$.is_mobile(val))iserror = 1;
        		    break;
        		case "number":
        		    if(!$.is_int(val) || val<min || val>max)iserror = 1;
        		    break;
        		case "neq":
        		    var neqval = $(obj).attr("neq");
        		    if(val == neqval)iserror = 1;
                    break;
                case "compare":
                    var comparetype = $(obj).attr("comparetype");
                    var gtval = $("#"+$(obj).attr("compareobj")).val();
                    if(comparetype == "gt"){
                    	if(val != '0' && val != 0 && val<gtval){
                    		iserror = 1;
                    	}else if(val != '0' && val != 0 && val == gtval){
                    		var v2 = $("#"+$(obj).attr("id").replace("endy","endm")).val();
                    		var gtv2 = $("#"+$(obj).attr("compareobj").replace("starty","startm")).val();
                    		if(parseInt(v2) < parseInt(gtv2)){
                    			iserror = 1;
                    		}
                    	}
                    }
                    break;
        		default:
           		    if($.is_empty(val))iserror = 1;
        		    break;
        	}
        	if(iserror == 1){
       			$("#"+id+"_tip").html(errormsg).addClass("input_onerror").show();
       			$(obj).focus();
        	}else{
        		$("#"+id+"_tip").html(errormsg).removeClass("input_onerror").hide();
        		iserror = 0;
        	}
        	return iserror;
}
function toggle(obj){
			var dis = $(obj).attr("_dis");
	        var showid = $(obj).attr("_showid");
			if(dis == 0){
				$("#"+showid).hide();
				$(obj).attr("_dis","1");
				$(obj).removeClass("dis1").addClass("dis2").html("展开");
			}else{
				$("#"+showid).show();
				$(obj).attr("_dis","0");
				$(obj).removeClass("dis2").addClass("dis1").html("收起");
			}
}
//缩放图片
function reloadimage(obj,width,heght){
	 var image=new Image();
	 var iwidth = typeof width == "undefeind"?500:width;
	 var iheight = typeof width == "undefeind"?325:heght; 
	 image.src=obj.src;
	 if(image.width>0 && image.height>0){
	  	flag=true;
	  	if(image.width/image.height>= iwidth/iheight){
		   if(image.width>iwidth){ 
		    obj.width=iwidth;
		    obj.height=(image.height*iwidth)/image.width;
		   }else{
		    obj.width=image.width; 
		    obj.height=image.height;
		   }
	  	}else{
		   if(image.height>iheight){ 
		    obj.height=iheight;
		    obj.width=(image.width*iheight)/image.height; 
		   }else{
		    obj.width=image.width; 
		    obj.height=image.height;
		   }
	  	}
	 }
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function JM_cc(ob){
	var obj=MM_findObj(ob); if (obj) { 
	obj.select();js=obj.createTextRange();js.execCommand("Copy");}
	alert("复制成功！您可以将信息发布到论坛或者朋友的QQ上！");
}
