﻿addLoadEvent(navEvent);
addLoadEvent(loadSearchBar);

var post_handle = 'entry.asp'; //POST ACTION 中省略的文件名
var site_domain = 'yl.3job.com'; //当前站点域名
var system_domain = '3job.com'; //主站域名
var vedio_url = 'http://vedio.3job.com/vedio'; //视频请求URL根目录

//处理子站域名跳转
function domain_referer(){
	if( -1 == location.href.indexOf(site_domain) )
		location.href = location.href.replace(document.domain,site_domain);
}
domain_referer();

function navsLink(event,model,root_path,url,islogin,iscompany,isperson){
	eval('var islogin='+islogin);
	eval('var iscompany='+iscompany);
	eval('var isperson='+isperson);
	if( url.indexOf('desktop/company') != -1 ){
		//是否登录
		if( !islogin ){
			//location.href = root_path+'login';
			return true;
		}
		//会员类型是否正确
		if( iscompany )
			window.location.href = url;
		else
			alert('您目前的身份为人才会员，只有单位会员才可以使用该功能。');
		return false;
	}else{
		//是否登录
		if( !islogin ){
			//location.href = root_path+'login';
			return true;
		}
		//会员类型是否正确
		if( isperson )
			window.location.href = url;
		else
			alert('您目前的身份为单位会员，只有人才会员才可以使用该功能。');
		
		return false;
	}
	
	return true;
}


function loadSearchType(path,type,o,e){
	var form = $I('form_qsearch');
	if( !form ) return;
	if(e && $.browser.msie) event.cancelBubble=true;
	else if(e) e.stopPropagation();
	form.action = path + type;
	if(o) $I('search-type-value').innerHTML = o.innerHTML;
	$('#search-type-item').slideUp(100);
	if($I('search-limit')) $I('search-limit').innerHTML = $I('search-limit-'+type).innerHTML;
	return false;
}

function loadSearchBar(){
	var box = $I('search_keys');
	var tip = '请您输入要查询职位的核心关键词...';
	if( !box ) return;
	if( box.value == '' ){box.value=tip; box.style.color='#aaa';}
	box.onfocus = function(){
		if( this.value == tip ) this.value = '';
		this.style.color = '#000';
	}
	box.onblur=function(){
		if( this.value.trim() == '' ){this.style.color='#aaa'; this.value=tip;}
	}

}

function quickSearch(key){
	$I('search_keys').value = key;
	$I('form_qsearch').submit();
}

function searchHelpBox(event){
	if( $I('qsearch_help_box') ){$('#qsearch_help_box').slideToggle("fast");return;}
	var htm = '<div id="qsearch_help_box" style="position:absolute;z-index:9999;display:none;width:180px;height:340px;border:4px solid #ffbdbb;background:#fff;padding:12px 8px 8px 8px;">';
	htm    +=   '<a href="#" onclick="$(\'#qsearch_help_box\').slideUp(\'fast\');return false;" style="font-size:14px;font-weight:bold;color:#f00;position:absolute;margin-top:-10px;margin-left:170px;">×</a>';
	htm    +=   '<h1 style="font:bold 14px;color:#000;padding:0; margin:16px 0;text-align:center; font-family:\'黑体\'">搜索小技巧</h1>';
	htm    +=   '<strong>一、关键词技巧</strong>';
	htm    +=   '<p style="margin:6px; line-height:1.8em;">◇ 搜索时请尽量用简短的核心关键词，如您搜索“销售经理”只需输入“销售”二字即可；<br />这样您即可获得与“销售”相关的所有信息，如：销售总监、销售经理、销售工程师、销售助理……</p>';
	htm    +=   '<strong>二、查询技巧</strong>';
	htm    +=   '<p style="margin:6px; line-height:1.8em;">◇ 请在查询时尽量尝试多次用不同的关键词搜索，如您搜索“销售”后，可再搜索“业务”或“营销”则可得到不同的搜索结果！</p>';
	htm    +=   '<h6 style="font:bold 12px;color:#000;padding:0;margin:8px 0;text-align:center;"><a href="#" onclick="$(\'#qsearch_help_box\').slideUp(\'fast\');return false;">【关闭】</a></h6>';
	htm    += '</div>';
	$(document.body).append(htm);
	event = event || window.event;
	var box = $I('qsearch_help_box');
	box.style.left = event.clientX - 140 + 'px';
	box.style.top  = event.clientY + document.documentElement.scrollTop + 20 + 'px';
	$(box).slideDown("fast");
}

function navEvent(){
	if( !$I('nav') ) return;
	var navs = $I('nav').getElementsByTagName('LI');
	for(var i=0; i<navs.length; i++){
		if( navs[i].className != 'l' && navs[i].className != 'line' && navs[i].className != 'c' && navs[i].className != 'lc' ){
			navs[i].onmouseover = function(){this.className += ' c';}
			navs[i].onmouseout  = function(){this.className = this.className=='r c'?'r':'';}
		}else if( navs[i].className == 'l' ){
			navs[i].onmouseover = function(){this.className = 'lc';}
			navs[i].onmouseout  = function(){this.className = 'l';}
		}
	}
}

function loading(flag,message,second){
	if( !message ) var message = '正在与服务器通信...';
	if( flag == 1 ){
		if( $I('loading') ) return;
		var layer = document.createElement('DIV');
		layer.id = 'loading';
		layer.className = 'loading';
		layer.innerHTML = message;
		document.body.appendChild(layer);
	}else if( flag == 0 ){
		function remove(){if($I('loading'))document.body.removeChild($I('loading'));}
		var layer = $I('loading'); if( layer ) layer.innerHTML = message;
		if( second!=null && typeof(second)=='number' )
			window.setTimeout(remove,second*1000);
		else
			remove();
	}
}

function ifrmLoad(boxid,frmid,frmurl,width,height,scrolling,ext,time){
	var w = null==width?'width="360"':width; if( typeof(w)=='number' ) w = 'width="'+w+'"';
	var h = null==height?'height="22"':height; if( typeof(w)=='number' ) h = 'height="'+h+'"';
	var s = scrolling || 'no'; ext = ext || ''; time = time || 100;
	function tfunc(){
		$I(boxid).innerHTML = '<iframe id="'+frmid+'" '+ext+' name="'+frmid+'" src="'+frmurl+'" '+w+' '+h+' scrolling="'+s+'" frameborder="0"></iframe>';
	}
	window.setTimeout(tfunc,time);
}

function upload(){
	if($I('file_data').value.trim() == ''){alert('请选择要上传的文件'); return false;}
	window.parent.loading(1,'请稍候 文件上传中...'); return true;
}

function imgLoad(img,loading,model){
	loading.style.display = 'none';
	$(img).slideDown('slow',tfunc);
	function tfunc(){
		var width = 120-2;
		var height = 150-2;
		if( model == 'banner' ) width = 400;
		else if( model == 'logo' ) width = 400;
		var w = img.offsetWidth;
		var h = img.offsetHeight;
		if( w/h > width/height )
			img.width = w>width?width:w;
		else
			img.height = h>height?height:h;
	}
}

function callback(model,flag,message,field,fname,furl){
	loading(0);
	var fpath = furl.replace(furl.substr(furl.indexOf('upload/')),'images/');
	switch( flag ){
		case 'error':
			alert(message);
			history.back();
			break;
		case 'ready':
			if( fname && furl ){
				var htm = '<span id="view_loading_'+model+'"><img src="'+fpath+'loading.gif" border="0" align="absmiddle" /> 图片载入中...</span>';
				htm += '<a href="'+furl+'" target="_blank" title="点击查看原图"><img src="'+furl+'" border="0" style="display:none;" onload="imgLoad(this,$I(\'view_loading_'+model+'\'),\''+model+'\');" /></a>';
				$I('view_box_'+model).innerHTML = htm;
				$I('view_box_'+model).style.display = 'block';
				$I(field).value = fname;
			}else{
				$I(field).value = '';
				$('#view_box_'+model).slideUp('fast');
			}
			break;
	}
}

//检测视频面试请求
var vedio_timer;
function vedioCheck(islogin,us_username,us_group,us_name,us_jobs){
	if( !islogin ) return;
	function v_c(){
		loadScript(vedio_url+'/control?model=check_request&u='+us_username+'&g='+us_group+'&n='+us_name+'&j='+us_jobs+'&'+Math.random());
		//window.open(vedio_url+'/control?model=check_request&u='+us_username+'&g='+us_group+'&n='+us_name+'&j='+us_jobs);
	}
	vedio_timer = window.setInterval(v_c,5000);
}

//弹出视频请求提示
function vedioRequest(isperson,iscompany,channel,uid,uid2,aid,aid2){
	if( window.window_vedio ) return;
	var w = '', g = '';
	if( isperson ){
		w = '邀请您';
		g = 'Candidate';
	}
	else if( iscompany ){
		w = '申请';
		g = 'Enterprise';
	}
	var htm = '<div id="vedio_request" class="vedio_request" style="display:none;">';
	htm +=      '<h1><span><a href="#shutdown" onclick="vedioAlert(true);$(\'#vedio_request\').slideUp(\'slow\',function(){document.body.removeChild($I(\'vedio_request\'))});return false;">关闭</a></span></h1>';
	htm +=      '<p>3JOB远程现场招聘提示</p>';
	htm +=      '<p><a href="#" onclick="vedioAlert(true);window.open(\''+vedio_url+'/talking/?status=getrequest&vc='+channel+'&group='+g+'&uid='+uid+'&uid2='+uid2+'&aid='+aid+'&aid2='+escape(aid2)+'\',\'_blank\',\'width=786,height=583\');$(\'#vedio_request\').slideUp(\'slow\',function(){document.body.removeChild($I(\'vedio_request\'))});return false;" style="color:#1f336b;font-weight:bold;" title="'+aid2+'">'+aid2.substr(0,15)+'</a><br />'+w+'进行远程现场面试</p>';
	htm +=      '<p><a href="#" onclick="vedioAlert(true);window.open(\''+vedio_url+'/talking/?status=getrequest&vc='+channel+'&group='+g+'&uid='+uid+'&uid2='+uid2+'&aid='+aid+'&aid2='+escape(aid2)+'\',\'_blank\',\'width=786,height=583\');$(\'#vedio_request\').slideUp(\'slow\',function(){document.body.removeChild($I(\'vedio_request\'))});return false;" style="color:#f00;font-weight:bold;">进入查看</a></p>';
	htm +=    '</div>';
	$(document.body).append(htm);
	if( window.vedio ){
		if( !window.vedio.isOwn(aid) ){
			$('#vedio_request').slideDown('slow',function(){window.vedio.push(aid);});
			vedioAlert();
		}
	}else{
		$('#vedio_request').slideDown('slow',function(){window.vedio=new Array(aid)});
		vedioAlert();
	}
}

//请求提示
var vediotimer = 0;
function vedioAlert(clear){
	if( clear ){
		window.clearInterval(vediotimer);
		document.title=window.doctitle;
		return;
	}
	if( !vediotimer ) window.doctitle = document.title;
	var flag = true;
	function t(){
		document.title = flag ? '☆您有新的面试请求！☆' : '■■■■■■■■■■■■■■■';
		flag = !flag;
	}
	vediotimer = window.setInterval(t,500);
}

//打开视频窗口
function startTalk(islogin,iscompany,isperson,uid,uid2,aid,aid2,group){
	if( typeof islogin == 'string' ) eval('islogin='+islogin+';');
	if( typeof iscompany == 'string' ) eval('iscompany='+iscompany+';');
	if( typeof isperson == 'string' ) eval('isperson='+isperson+';');
	if( !islogin ){alert('您还没有登录，请先登录再使用远程面试功能。'); try{$I('login_username').focus();}catch(e){}; return;}
	if( iscompany ){alert('您目前的身份为企业会员，无权进行职位申请。'); return;}
	uid2 = escape(uid2); aid2 = escape(aid2);
	window.open(vedio_url+"/talking?status=request&group="+group+"&uid="+uid+"&uid2="+uid2+"&aid="+aid+"&aid2="+aid2,"_blank","width=786,height=583");
}

/*functions for popupDiv begin*/
function checkSelectItem(sObj,fname,limit){
	function setValue(){
		var values = '', shows = '', t1='', t2 = '';
		$(':checkbox[@name=select_item_'+fname+']:checked').each(function(){
			values += (t1+this.value); t1=',';
			shows  += (t2+this.value); t2=' + ';
		});//构建Value
		$I(fname).value = values;//更新Value到控件
		if( shows.trim() == '' ){
			$I(fname+'_1').value = $('#'+fname).data('title');
			$I(fname+'_1').title = $('#'+fname).data('title');
		}else{
			showNum = Math.floor( $I(fname+'_1').offsetWidth/12 );
			$I(fname+'_1').value = ' ' + ( shows.len()/2>showNum ? shows.substr(0,showNum)+'...' : shows );
			$I(fname+'_1').title = shows;
		}//显示到按钮
	}
	sObj.blur();//虚线框
	var items = $I(fname).value.split(',');
	if( $I(fname).value.trim() == '' ) items=Array();
	limit = limit || 3;
	if( !sObj.checked ){
		sObj.parentNode.style.color = '#000';//文字变色
		setValue();
	}else{
		if(items.length >= limit){
			alert('最多可以选择 '+limit+' 项！');
			sObj.checked = false;
		}else{
			sObj.parentNode.style.color = '#f60';//文字变色
			setValue();
			if(limit == 1){$('#dialog_'+fname).slideToggle("fast",function(){$('#mask_div').slideToggle('fast');$I(fname+'_1').focus();});selectDisplay(fname);}//如果只能选择一项->自动关闭
		}
	}
	//if( $I(fname).value.trim() == '' )$I(fname+'_1').value = $('#'+fname).data('title');
}

function selectDisplay(fname){
	if(! ($.browser.msie && $.browser.version=='6.0')  ) return;
	$('select').each(function(){
		this.style.display=(!$I('dialog_'+fname) || $I('dialog_'+fname).style.display=='none')?'none':'';
	}); 	
}

function popupClose(fname){
	selectDisplay(fname);
	$('#dialog_'+fname).slideUp('fast',function(){$('#mask_div').slideToggle('fast');try{$I(fname+'_1').focus();}catch(e){};});
}

function popupDiv(event,fname,array,limit,title,width){
	limit = limit || 1;
	title = title || $I(fname+'_1').value;
	width = width || 520;
	var divstitle='';
	if(fname=='search_job_trade'){
		divstitle='请选择职位类别';
		}else{
		divstitle='请选择行业类别';
		}
	$('#'+fname).data('title',title);//缓存当前Title
	$('#'+fname).data('value',$I(fname).value);//缓存当前Value
	selectDisplay(fname);//隐藏select控件
	var vals = $I(fname).value.split(',');
	if( $I('dialog_'+fname) ){$('#dialog_'+fname).slideToggle("fast",function(){$('#mask_div').slideToggle('fast');$I(fname+'_1').focus();}); return;}//如果popupDIV已创建->显示
	//popupDIV
	var htm = '<div id="dialog_'+fname+'"  style="width:'+width+'px;  position:absolute; z-index:10000;">';
	htm    +='<div class="xxwstop zwlb" style=" margin-top:20px;"><ul><li class="top_left"></li><li class="top_center"><span>'+divstitle+'</span><a href="#" class="close" onclick="popupClose(\''+fname+'\');return false">关闭</a></li><li class="top_right"></li></ul></div>'
	htm    +='<div class="xxwscon zwlb_con"><ul><li class="bot_line tit">一次最多可以选择三项</li></ul><ul class="con_list">'
	for( var i=0; i<array.length; i+=2){
		try{
		var checkItA = '', colorA = ''; if( vals.isOwn(array[i][1]) ){ checkItA = ' checked="checked"'; colorA = ' style="color:#f60;"';};
		var checkItB = '', colorB = ''; if( array[i+1] && vals.isOwn(array[i+1][1]) ){ checkItB = ' checked="checked"';  colorB = ' style="color:#f60;"';}
		htm    +=   '<li><label for="select_item_'+fname+'_'+i+'"'+colorA+'><input onclick="checkSelectItem(this,\''+fname+'\','+limit+')" class="checkbox" type="checkbox" name="select_item_'+fname+'" id="select_item_'+fname+'_'+i+'" value="'+array[i][1]+'"'+checkItA+' />'+array[i][2]+'</label></li>'
		htm    +=   '<li><label  for="select_item_'+fname+'_'+(i+1)+'"'+colorB+'><input onclick="checkSelectItem(this,\''+fname+'\','+limit+')" class="checkbox" type="checkbox" name="select_item_'+fname+'" value="'+array[i+1][1]+'"'+checkItB+' id="select_item_'+fname+'_'+(i+1)+'" />'+array[i+1][2]+'</label></li>'
		}
		catch(e){
			}
	    }
		htm+='</ul><ul class="con_but"><LI><input name="button" type="button" class="xxwsbut01" onmouseover="this.className=\'xxwsbut02\'" onmouseout="this.className=\'xxwsbut01\'"   value="确 定"   onclick="popupClose(\''+fname+'\');return false"/></LI></ul></div>'
		htm+='<div class="xxwsbot zwlb"><ul><li class="bot_left"></li><li class="bot_center"></li><li class="bot_right"></li></ul></div>'
		htm+='</div>'
	//蒙板DIV
	if( !$I('mask_div') ) htm +='<div id="mask_div" style="position:absolute;left:0px;top:0px;width:'+$(document).width()+'px;height:'+$(document).height()+'px;z-index:999;background:#000;filter:alpha(opacity=10);opacity:0.1;"></div>';
	$(document.body).append(htm);
	//鼠标效果
	$('#dialog_'+fname+' label').each(function(){
		this.onmouseover = function(){this.style.background='#e3e4f5';};
		this.onmouseout  = function(){this.style.background='#fff';};
		this.style.cursor="pointer";
	});
	//显示位置
	event = event || window.event;
	var box = $I('dialog_'+fname);
	box.style.left = $(document).width()/2 - 290 + 'px';
	box.style.top  = event.clientY + document.documentElement.scrollTop - 100 + 'px';
	//显示
	$('#mask_div').slideDown('fast',function(){$('#dialog_'+fname).slideDown('fast');/*$I(fname+'_1').focus();*/});
}
/*functions for popupDiv end*/

function selectedValue(){
	var values = '', t = '';
	$(':checkbox:checked',$('#form_list')).each(function(){
		if( !this.disabled ){
			values += (t + this.value);
			t = ',';
		}
	});
	return values;
}

function post(url,data,message,from,second,callback){
	$.ajax({
		type : 'post',
		url : url,
		cache : false,
		dataType : 'text',
		data : data,
		timeout : 20000,
		beforeSend : function(XMLHttpRequest){
			//loading(1);
			$(':button').each(function(){this.disabled=true;});
			$(':submit').each(function(){this.disabled=true;});
		},
		success: function(text){
			var a = text.split('|');
			if( a[0] == 'OK' ){
				window.ready = null;
				if(second!=null && typeof(second)=='number'){
					loading(0,message,second);
				}else{
					if(message)alert(message);
					loading(0);
				}
				if( -1 == from ) history.back();
				else if( 0 == from ) location.reload();
				else if( from ) location.href = from;
				eval(callback);//if( callback )try{eval(callback)}catch(e){};
			}else if( 'ERR'==text ){
				alert('操作失败：没有权限！');
			}else{
				alert(a[0]);
				try{if(a[1]){$I(a[1]).disabled=false;$I(a[1]).focus()}}catch(e){};
				loading(0);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert('请求超时，请重试。');
			loading(0);
		},
		complete: function(XMLHttpRequest){
			$(':button').each(function(){this.disabled=false;});
			$(':submit').each(function(){this.disabled=false;});
		}
	});
}

function get(url,message,removeid,from,callback){
	$.ajax({
		type : 'get',
		url : url,
		cache : false,
		dataType : 'text',
		timeout : 20000,
		beforeSend : function(XMLHttpRequest){
			//loading(1);
			$(':button').each(function(){this.disabled=true;});
			$(':submit').each(function(){this.disabled=true;});
		},
		success: function(text){
			var a = text.split('|');
			if( a[0] == 'OK' ){
				window.ready = null;
				if(message)alert(message);
				loading(0);
				try{
					if( removeid != null ){
						var arr = removeid.toString().split(',');
						for( var i=0; i<arr.length; i++ ){
							var tr = $I('info_list_'+arr[i].trim());
							if( tr ){
								$I('info_list').removeChild( tr );
								$I('total').innerHTML = parseInt($I('total').innerHTML)-1;
							}
						}
					}
				}catch(e){}
				if( -1 == from ) history.back();
				else if( 0 == from ) location.reload();
				else if( from ) location.href = from;
				if( callback )try{eval(callback)}catch(e){};
			}else if( 'ERR'==text ){
				alert('操作失败：没有权限！');
				loading(0);
			}else{
				alert(a[0]);
				loading(0);
				try{if(a[1]){$I(a[1]).disabled=false;$I(a[1]).focus()}}catch(e){};
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert('请求超时，请重试。');
			loading(0);
		},
		complete: function(XMLHttpRequest){
			$(':button').each(function(){this.disabled=false;});
			$(':submit').each(function(){this.disabled=false;});
		}
	});
}

//CY CHECK 时间
function cyCheckBox(ob,str){
	var limit=3;
	var num=0;
	var inputs = document.getElementsByName(str+"_ck");
	var Trade=$I(str);
	var Trade1=$I(str+"_1");
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].checked){
			num=num+1;
			}
		}
	if(num>limit){
		alert("最多职能选中"+limit+"个！");
		ob.checked=false;
		return;
		}
	if(ob.checked){
		 if(Trade.value.indexOf(ob.value)<0){
			 if(Trade.value==""){
				 Trade.value=ob.value;
				 }else{
				 Trade.value=Trade.value+","+ob.value;
				 Trade1.value=Trade.value;
				}
			 }
		}else{
		         Trade.value=Trade.value.replace(ob.value+",","");
			 Trade.value=Trade.value.replace(","+ob.value,"");
			 Trade.value=Trade.value.replace(ob.value,"");
			 Trade1.value=Trade.value;
		}
	}

//CY 背景不可用函数
function removeObj(ob){//点击标题栏触发的事件
document.getElementById(ob).style.display="none";
document.body.removeChild(document.getElementById('bgDiv'));
}
function ShowClass(ob){
	var msgw,msgh,bordercolor;
	msgw=500;//提示窗口的宽度
	msgh=500;//提示窗口的高度
	titleheight=25//提示窗口标题高度
	
	var sWidth,sHeight;
	sWidth=document.body.scrollWidth;//浏览器工作区域内页面宽度 或使用 screen.width//屏幕的宽度
	sHeight=document.body.scrollHeight;//屏幕高度（垂直分辨率）
	
	
	//背景层（大小与窗口有效区域相同，即当弹出对话框时，背景显示为放射状透明灰色）
	var bgObj=document.createElement("div");//创建一个div对象（背景层） //动态创建元素，这里创建的是 div
	//定义div属性，即相当于(相当于，但确不是，必须对对象属性进行定义
	//<div id="bgDiv" style="position:absolute; top:0; background-color:#777; filter:progid:DXImagesTransform.Microsoft.Alpha//f(style=3,opacity=25,finishOpacity=75); opacity:0.6; left:0; width:918px; height:768px; z-index:10000;"></div>
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#777";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "10001";
	document.body.appendChild(bgObj);//在body内添加该div对象
	var ob = document.getElementById(ob);
	ob.style.display="";
	}
//CY AJAX 完

// 批量申请的发邮件
function AjaxFor(ob,url){
	$.ajax({
              type: "POST",
              url: url,
              data:ob
              });
	}

