
// This function is for stripping leading and trailing spaces
String.prototype.trim = function() {
	return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};


// Show the document's title on the status bar
window.defaultStatus = document.title;

/* This function is used to set cookies */
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value)
			+ ((expires) ? "; expires=" + expires.toGMTString() : "")
			+ ((path) ? "; path=" + path : "")
			+ ((domain) ? "; domain=" + domain : "")
			+ ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
	var prefix = name + "="
	var start = document.cookie.indexOf(prefix)

	if (start == -1) {
		return null;
	}

	var end = document.cookie.indexOf(";", start + prefix.length)
	if (end == -1) {
		end = document.cookie.length;
	}

	var value = document.cookie.substring(start + prefix.length, end)
	return unescape(value);
}

/* This function is used to delete cookies */
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "")
				+ ((domain) ? "; domain=" + domain : "")
				+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function jSelectAll(select) {
	if ($("input[name='" + select + "']").length == 0) {
		alert("没有可选记录!");
	}
	$("input[name='" + select + "']").each(function() {
				$(this).attr("checked", true);
			});
}
function jReverseAll(select) {
	if ($("input[name='" + select + "']").length == 0) {
		alert("没有可选记录!");
	}
	$("input[name='" + select + "']").each(function() {
				$(this).attr("checked", !$(this).attr('checked'));
			});
}

// ajax提交
function submitForm(id){
	var v = $("#" + id).validate();
	if(v.valid()) $("#" + id).submit();
}

/* This function is used to open a pop-up window */
function openWindow(url, winTitle, winParams) {
	winName = window.open(url, winTitle, winParams);
	winName.focus();
}

function openWindow(url, windowName, width, height){
		var top = 0;
		var left = 0;
		var winWidth = window.screen.availWidth-12;
		var winHeight = window.screen.availHeight-50;
		var scrollNorY='no';
		var fullScreen = false;
		if(parseInt(height) == 9999){
			// full screen		
			fullScreen = true;
			width=window.screen.availWidth-12;
			height=window.screen.availHeight-50;}
		else {
			// center
			top = (window.screen.availHeight-parseInt(height))/2;
			left = (window.screen.availWidth-parseInt(width))/2;
			if (top < 30)	top = 0;
			if (left < 30)	left = 0;
		}
		if(width > winWidth) {
		  width = winWidth;
			scrollNorY='yes';
		}
		if(height > 699) scrollNorY='yes';
		if(height >= winHeight) {
			if(fullScreen) scrollNorY='no';
			else scrollNorY = 'yes';
			height = winHeight;
		}
		var config = "status=no,scrollbars=" + scrollNorY + ",top="+ top +",left="+ left  +",resizable=1,width=" + width + ",height=" + height;
		var win = window.open(url, windowName, config);
		if(win)	{
			win.focus();
			return win;
		}
	}

/* This function is to open search results in a pop-up window */
function openSearch(url, winTitle) {
	var screenWidth = parseInt(screen.availWidth);
	var screenHeight = parseInt(screen.availHeight);

	var winParams = "width=" + screenWidth + ",height=" + screenHeight;
	winParams += ",left=0,top=0,toolbar,scrollbars,resizable,status=yes";

	openWindow(url, winTitle, winParams);
}

/* This function is to open view results in a pop-up window  eg: view-cv/view-recruit/view-company etc*/
function openView(url, winTitle) {
	var screenWidth = parseInt(screen.availWidth);
	var screenHeight = parseInt(screen.availHeight);
	
	var winParams = "width=800,height=720";
	winParams += ",left=0,top=0,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes";
	
	//openWindow(url, winTitle, winParams);
	openWindow(url, winTitle, 800, 720);
}

/*
 * 功能:根据输入表达式返回日期字符串
 * 参数:dateFmt:字符串,由以下结构组成    
 *      yy:长写年,YY:短写年mm:数字月,MM:英文月,dd:日,hh:时,
 *      mi:分,ss秒,ms:毫秒,we:汉字星期,WE:英文星期.
 *      isFmtWithZero : 是否用0进行格式化,true or false
 * 返回:对应日期的中文字符串
*/
Date.prototype.toString = function(dateFmt,isFmtWithZero){
    dateFmt = (dateFmt == null ? "yy-mm-dd hh:mi:ss" : dateFmt);
    if(typeof(dateFmt) != "string" )
        throw (new Error(-1, 'toString()方法的第一个参数为字符串类型!'));
    isFmtWithZero = !!isFmtWithZero;
    var weekArr=[["日","一","二","三","四","五","六"],["SUN","MON","TUR","WED","THU","FRI","SAT"]];
    var monthArr=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
    var str=dateFmt;
    var o = {
        "yy" : this.getFullYear(),
        "YY" : this.getYear(),
        "mm" : this.getMonth()+1,
        "MM" : monthArr[this.getMonth()],
        "dd" : this.getDate(),
        "hh" : this.getHours(),
        "mi" : this.getMinutes(),
        "ss" : this.getSeconds(),
        "we" : "星期" + weekArr[0][this.getDay()],
        "WE" : weekArr[1][this.getDay()]
    }
    for(var i in o){
        str = str.replace(new RegExp(i,"g"),o[i].toString().fmtWithZero(isFmtWithZero));
    }
    str = str.replace(/ms/g,this.getMilliseconds().toString().fmtWithZeroD(isFmtWithZero));
    return str;
}
/**//*将一位数字格式化成两位,如: 9 to 09*/
String.prototype.fmtWithZero = function(isFmtWithZero){    
    return (isFmtWithZero && /^\d$/.test(this))?"0"+this:this;
}
String.prototype.fmtWithZeroD = function(isFmtWithZero){    
    return (isFmtWithZero && /^\d{2}$/.test(this))?"00"+this:((isFmtWithZero && /^\d$/.test(this))?"0"+this:this);
}

/* 已过时！推荐使用szhrDialog */
function myUI(id){
	
	// 设置blockUI
	$.blockUI.defaults.css.border = 'none';//'8px solid orange';
	//$.blockUI.defaults.fadeOut = 200;
	$.blockUI.defaults.css.width = '';
	$.blockUI.defaults.css.padding = '0';
	$.blockUI.defaults.css.cursor = 'normal';
	
	var ui = $("#" + id);
	
	$.blockUI({ message: ui });
	$('.blockOverlay').attr('title','点击此处关闭!').click($.unblockUI);
}

/* 已过时！推荐使用szhrDialog */
function agreeUI(id){
	var screenWidth = parseInt(screen.availWidth);
	var screenHeight = parseInt(screen.availHeight);
	$.blockUI.defaults.css.width = screenWidth/2;
	$.blockUI.defaults.css.height = screenHeight/2;
	$.blockUI.defaults.css.top = screenHeight/8;
	$.blockUI.defaults.css.left = screenWidth/4;
	myUI(id);
}

/* 已过时！推荐使用szhrDialog */
function custUI(id, width, height){
	
	var screenWidth = parseInt(screen.availWidth);
	var screenHeight = parseInt(screen.availHeight);
	
	$.blockUI.defaults.css.width = width;
	$.blockUI.defaults.css.height = height;
	
	var left = (screenWidth-width)/2;
	if(left < 0) left = 0;
	var top = (screenHeight-height-height/2)/2;
	if(top < 0) top = 0;
	$.blockUI.defaults.css.top = top;
	$.blockUI.defaults.css.left = left;
	
	//alert('sw:' + screenWidth + ' sh:' + screenHeight + ' w:' + width + ' h:' + height + ' t:' + top + ' l:' + left)
	myUI(id);
}

/* 已过时！推荐使用szhrDialog */
function popUI(id){
	custUI(id, 400, 300);
}

/* 已过时！推荐使用szhrDialog */
function uiDialog(id){
	var width,height;
	if($('#' + id).width()) width = $('#' + id).width();
	if($('#' + id).height()) height = $('#' + id).height();
	custUI(id, width, height);
}

/**
 * szhrDialog - 对话框1.0(逐步改进中)
 * 使用说明：
 * 将页面内一个隐藏div使用blockUI插件弹出来，最好在div中定义好宽度(如：<div id="test" style="display:none;width:400px">内容...</div>)
 * @param {} id - 元素id，注意不要加#
 * @param {} title - 可选，定义title文字
 */
function szhrDialog(id,title,UIHeight){
	var $ui = $('#' + id);
	var width = $ui.width();
	
	if(!$ui.hasClass("ui-dialog")){
		var cp = width - 40;//关闭按钮位置
		var tit = "";
		if(title) tit = title;
		var $tit = '<div class="ui-dialog-title">' + tit + '<div class="ui-dialog-close" onclick="$.unblockUI();" style="left:'+ cp + 'px;top:0"></div></div>';
		var $cont = '<div class="ui-dialog-con"><ul class="ui-dialog-con-bg">' + $ui.html() + '</ul></div>';
		$ui.empty().addClass("ui-dialog").html($tit + $cont);
	}

	var height = $ui.height();
	if(UIHeight){
		height = UIHeight;
	}
	var screenWidth = parseInt(screen.availWidth);
	var screenHeight = parseInt(screen.availHeight);
	var left = (screenWidth-width)/2;
	if(left < 0) left = 0;
	var top = screenHeight/2-height*3/2;
	if(top < 0) top = 0;
	
	$.blockUI.defaults.css.width = width;
	$.blockUI.defaults.css.height = height;
	$.blockUI.defaults.css.top = top;
	$.blockUI.defaults.css.left = left;
	$.blockUI.defaults.css.border = 'none';
	$.blockUI.defaults.css.padding = '0';
	$.blockUI.defaults.css.cursor = 'normal';
	
	$.blockUI({ message: $ui });
}

/*预览个人简历*/
function previewCv(personId){
	openView('../view-cv.action?ajax=true&id=' + personId);
}

/*预览招聘信息*/
function previewRecruit(recruitId){
	openView('../view-recruit.action?ajax=true&id=' + recruitId);
}

/*查看招聘信息并增加点击*/
function viewRecruit(recruitId){
	$.get("../view-recruit!addClickedTimes.action?ajax=true&id=" + recruitId, function(result) {
		// eval("json=" + result);
		// alert(json.map.msg);
	});
	openView('../view-recruit.action?ajax=true&id=' + recruitId);
}

/*查看公司信息*/
function viewCompany(companyId){
	openView('../view-company.action?ajax=true&id=' + companyId);
}

/*查看高级人才简历*/
function viewAdvCv(email){
	openView('../view-adv.action?ajax=true&personEmail=' + email);
}

/*其他职位*/
function othersjob(companyId){
	window.location='view-company.action?ajax=true&id=' + companyId;
}

/*其他现场招聘职位*/
function othersReqjob(companyId, recruitDate){
	window.location='view-req-company.action?ajax=true&id=' + companyId + '&recruitDate=' + recruitDate;
}

/*立即申请*/
function saveApply(){
	var options = {
		success: function(result) {
			$.unblockUI();
			eval("json=" + result);
			alert(json.map.msg);
		}
	}
	var v = $("#form_msg").validate({
		submitHandler: function(form){
			$(form).ajaxSubmit(options);
		}
	});
	
	$("#form_msg").submit();
}

/*收藏职位*/
function favorite(recruitId){
	$.get("seekjob/recruit-handle!favorite.action?ajax=true", {recruitId:recruitId}, function(result) {
			eval("json=" + result);
			alert(json.map.msg);
		});
}

/*推荐给朋友*/
function send2friend(recruitId){
	
	var options = {		
		success: function(result) {
			eval("json=" + result);
			alert(json.map.msg);
		}
	}
	var v = $("#form_send").validate({
		submitHandler: function(form){
			$(form).ajaxSubmit(options);
		}
	});
	
	$("#form_send").submit();
	if(v.valid()) $.unblockUI();
}

/*弹出层登录*/
function popLogon(){
	$.unblockUI();
	var options = {
		success: function(result) {
			eval("json=" + result);
			alert(json.map.msg);
		}
	}
	var v = $("#form_send").validate({
		submitHandler: function(form){
			$(form).ajaxSubmit(options);
		}
	});
	
	$("#form_send").submit();
}

/**
 *  加载广告 
 *  参数说明：
 *  id-显示div的id
 *  code-广告代码
 *  items-显示条数(0-表示全部)
 *  minutes-刷新间隔分钟数(0-表示强制刷新)
 *  reload-是否强制刷新(true-表示强制刷新；false-表示不强制刷新)
 */
function loadAd(id, code, items, minutes, reload){
	if(!items) items = 0;
	if(!reload) reload = false;
	$.get("../adsense/ad-item.action?ajax=true&code=" + code + "&items=" + items + "&minutes=" + minutes + "&reload=" + reload, function(result) {
		$("#" + id + " p").replaceWith(result);
		//$("#" + id).corner("5px");
	});		
}

function loadFrame(element, url, width, height){
	var $f = '<iframe src="' + url + '" width="' + width + '" height="' + height + '" marginheight="0" marginwidth="0" scrolling="no" frameborder="0"/>';
	$(element).html($f);
}

function subStr(str, len){
	return str.substring(0, len);
}

/**
 *  过滤关键字
 *  用法： onblur="fk(this.id);"
 * @param {} id
 */
function fk(id){
	var $f = $("#" + id);
	var val = $f.val();
	var key = new Array();
	key[1] = "法轮";
	key[2] = "falun";
	key[3] = "falundafa";
	key[4] = "zhuanfalu";
	key[5] = "六四";
	key[6] = "民运";
	key[7] = "dafa";
	key[8] = "唐人电视台";
	key[9] = "大法";
	key[10] = "新唐人电视台";
	key[11] = "李洪志";
	key[12] = "转法轮";
	key[13] = "共铲党";
	key[14] = "六合彩";
	key[15] = "六合采";
	key[16] = "共铲党";
	key[17] = "九评";
	key[18] = "九评共产党";
	key[19] = "人民报";
	key[20] = "退党";
	key[21] = "明慧";
	key[22] = "明慧网";
	key[23] = "大纪元";
	key[24] = "大 纪元";
	key[25] = "退党";
	key[26] = "六四";
	key[27] = "天安门事件";
	key[28] = "自由亚州";
	key[29] = "无界浏览";
	key[30] = "极景";
	key[31] = "无界";
	key[32] = "无网界浏览";
	key[33] = "无网界";
	key[34] = "美国之音";
	key[35] = "自由亚洲";
	key[36] = "色情网站";
	key[37] = "色情";
	key[38] = "情色";
	key[39] = "口交";
	key[40] = "阴茎";
	key[41] = "阴毛";
	key[42] = "性虐待";
	key[43] = "黄色网站";
	key[44] = "成人网站";
	key[45] = "成人小说";
	key[46] = "成人文学";
	key[47] = "成人电影";
	key[49] = "成人影视";
	key[50] = "黄色电影";
	key[51] = "黄色影视";
	key[52] = "黄色小说";
	key[53] = "黄色文学";
	key[54] = "成人图片";
	key[55] = "黄色图片";
	key[56] = "黄色漫画";
	key[57] = "成人漫画";
	key[58] = "成人电影";
	key[59] = "三级片";
	key[60] = "黄色电影";
	key[61] = "坐台";
	key[62] = "应召";
	key[63] = "应招";
	key[64] = "妓女";
	key[65] = "成人论坛";
	key[66] = "手机铃声下载";
	key[67] = "铃声下载";
	key[68] = "手机铃声";
	key[69] = "和弦";
	key[70] = "手机游戏";
	key[48] = "性免费电影";
	key[0] = "小电影";

	for(i = 0; i < key.length; i++){
		val = val.replace(key[i],"***");
	}
	$f.val(val);	
}

var menu=function(){
	var t=15,z=50,s=2,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();


