﻿function showDetail(id){
	if( $.browser.msie ){
		$('#detail_'+id).slideToggle('fast',function(){
			$I('detail_lk_'+id).className = $I('detail_'+id).style.display=='none' ? 'detail_lk_close' : 'detail_lk_open';
			borDetail();
		});
	}else{
		$I('detail_'+id).style.display = $I('detail_'+id).style.display=='none' ? '' : 'none';
		$I('detail_lk_'+id).className=$I('detail_'+id).style.display=='none'?'detail_lk_close':'detail_lk_open';
		borDetail()
	}
	//处理边框虚线
	function borDetail(){
		if( !$I('borT_'+id) ) return;
		if( $I('detail_'+id).style.display == 'none' ){
			$I('borT_'+id).className = $I('borT_'+id).className.replace(' sT','');
			$I('borB_'+id).className = $I('borB_'+id).className.replace(' sB','');
			$I('borN_'+id).className = $I('borN_'+id).className.replace(' sN','');
		}else{
			$I('borT_'+id).className = $I('borT_'+id).className + ' sT';
			$I('borB_'+id).className = $I('borB_'+id).className + ' sB';
			$I('borN_'+id).className = $I('borN_'+id).className + ' sN';
		}
	}
}

function setCheckbox(model){
	model = model==0 ? false : true;
	$(':checkbox').each(function(){this.checked=model;});
}

function sendFavorite(isLogin,isPerson,rootPath,event){
	if( !isLogin ){
		loginBox(event,rootPath,'company','../');
	}else if( isPerson ){
		alert('您当前身份为本站个人会员，无权使用该功能。');
	}else{
		loading(1);
		var url = 'control/'+post_handle+'?do=favorite';
		var data = $('#form_list').serialize();
		post(url,data,'操作成功：已成功将所选简历保存到您的收藏夹中！',null,null,'setCheckbox(0)');
	}
}

function sendApply(isLogin,isPerson,isVip,rootPath,event){
	if( !isLogin ){
		loginBox(event,rootPath,'company','../');
	}else if( isPerson ){
		alert('您当前身份为本站个人会员，无权使用该功能。');
	}else if( !isVip ){
		if(confirm('本站“正式单位会员”方可使用该功能，请升级为“正式单位会员”！')) window.open('../about/?page=price');
	}else{
		loading(1);
		function tfun(){$(':checkbox').each(function(){this.checked=false;});}
		var url = 'control/'+post_handle+'?do=apply';
		var data = $('#form_list').serialize();
		post(url,data,'邀请信件已成功发送！',null,null,'setCheckbox(0)');
	}
}

function singleApply(isLogin,isPerson,isVip,rootPath,event,itemid){
	$(':checkbox').each(function(){this.checked=false;});
	$I('list_'+itemid).checked = true;
	sendApply(isLogin,isPerson,isVip,rootPath,event);
}

function filter(url,isLogin,isPerson,event){
	if( !isLogin ){
		loginBox(event,'../','company','../');
		return ;
	}else if( isPerson ){
		alert('您当前身份为本站个人会员，无权使用该功能。');
		return ;
	}
	window.location = url;
	return;
}

function filterByArea(url){
	if( url.trim() == '' ) url='?'; else url = '?'+url+'&';
	var htm = '<select name="search_area_" onchange="location.href=\''+url+'search_area=\'+encodeURI(this.value)+\'&search_model=0\';document.body.focus();">';
	htm += '<option value="">按地区显示</option>';
	for( var i=1; i<area.length; i++ ){
		var t = area[i][1];
		if( area[i][0] == 0 )
			//t = t +'★';
			t = area[i][1]=='全国' ? '==='+t+'===' : '★'+t;
		else if( area[i][0] == 1 )
			//t = '&nbsp; ' + t;
			t = '' + t;
		var s = '';
		if( decodeURIComponent(getQuery('search_area')) == area[i][2] )
			s = ' selected="selected"';
		htm += '<option value="'+area[i][2]+'"'+s+'>'+t+'</option>';
	}
	htm += '</select>';
	$I('slink').innerHTML = htm;
}

function selectArea(fname){
	var htm = '<select name="'+fname+'" id="'+fname+'">';
	htm += '<option value="">请选择求职地区</option>';
	for( var i=1; i<area.length; i++ ){
		var t = area[i][1];
		if( area[i][0] == 0 )
			t = t +'★';
		else if( area[i][0] == 1 )
			t = '├ ' + t;
		htm += '<option value="'+area[i][2]+'">'+t+'</option>';
	}
	htm += '</select>';
	return htm;
}

function selectVisible(flag){
	if(! ($.browser.msie && $.browser.version=='6.0')  ) return;
	$('select').each(function(){
		this.style.visibility = flag==1?'visible':'hidden';
	}); 	
}

/*高级搜索类*/
function searchClass(){
	//搜索条件项
	this.items = new Array(
		['<li><a href="javascript:advSearch.begin(0,\'0,1,2,3,4,5\');" style="color:#f00;">全文自定义搜索</a></li>','<input name="search_keys" id="search_keys" type="text" value="请输入关键字" onfocus="if(this.value==\'请输入关键字\')this.value=\'\';" size="25" maxlength="30" />'],
		['<li><a href="javascript:advSearch.begin(1,\'1,2,3,4,5\');">按职位类别搜索</a></li>','<input type="hidden" name="search_job_trade" id="search_job_trade" /><input name="search_job_trade_1" id="search_job_trade_1" type="button" class="button" value="请选择职位类别" onclick="popupDiv(event,\'search_job_trade\',job_trade,3,\'请选择职位类别\');" /><input name="search_keys" type="text" value="请输入关键字" onfocus="if(this.value==\'请输入关键字\')this.value=\'\';" size="25" maxlength="30" style="margin-top:4px;" />'],
		['<li><a href="javascript:advSearch.begin(2,\'0,2,3,4,5\');">按年龄条件搜索</a></li>','从<input name="search_age_from" id="search_age_from" type="text" size="8" maxlength="4" style="margin:0 4px;" />到<input name="search_age_to" id="search_age_to" type="text" size="8" maxlength="4" style="margin:0 4px;" />岁<input name="search_keys" type="text" value="请输入关键字" onfocus="if(this.value==\'请输入关键字\')this.value=\'\';" size="25" maxlength="30" style="margin-top:4px;" />'],
		['<li><a href="javascript:advSearch.begin(3,\'0,1,3,4,5\');">按性别条件搜索</a></li>','<select name="search_sex" id="search_sex"><option value="">请选择性别条件</option><option value="">不限</option><option value="男">男</option><option value="女">女</option></select><input name="search_keys" type="text" value="请输入关键字" onfocus="if(this.value==\'请输入关键字\')this.value=\'\';" size="25" maxlength="30" style="margin-top:4px;" />'],
		['<li><a href="javascript:advSearch.begin(4,\'0,1,2,4,5\');">按身高条件搜索</a></li>','从<input name="search_height_from" id="search_height_from" type="text" size="6" maxlength="4" style="margin:0 4px;" />到<input name="search_height_to" id="search_height_to" type="text" size="8" maxlength="4" style="margin:0 4px;" />厘米<input name="search_keys" type="text" value="请输入关键字" onfocus="if(this.value==\'请输入关键字\')this.value=\'\';" size="25" maxlength="30" style="margin-top:4px;" />'],
		['<li><a href="javascript:advSearch.begin(5);">按简历编号搜索</a></li>','<input name="search_keys" id="search_keys" type="text" value="请输入简历编号" onfocus="if(this.value==\'请输入简历编号\')this.value=\'\';" size="25" maxlength="30" />']
	);
	//添加条件项
	this.limits = new Array(
		['<li id="limit0"><a href="javascript:advSearch.add(0);">职位类别</a></li>','<li><input type="hidden" name="search_job_trade" id="search_job_trade" /><input name="search_job_trade_1" id="search_job_trade_1" type="button" class="button" value="请选择职位类别" onclick="popupDiv(event,\'search_job_trade\',job_trade,3,\'请选择职位类别\');" /></li>'],
		['<li id="limit1"><a href="javascript:advSearch.add(1);">年龄条件</a></li>','<li>从<input name="search_age_from" id="search_age_from" type="text" size="8" maxlength="4" style="margin:0 4px;" />到<input name="search_age_to" id="search_age_to" type="text" size="8" maxlength="4" style="margin:0 4px;" />岁</li>'],
		['<li id="limit2"><a href="javascript:advSearch.add(2);">性别条件</a></li>','<li><select name="search_sex" id="search_sex"><option value="">请选择性别条件</option><option value="">不限</option><option value="男">男</option><option value="女">女</option></select></li>'],
		['<li id="limit3"><a href="javascript:advSearch.add(3);">身高条件</a></li>','<li>从<input name="search_height_from" id="search_height_from" type="text" size="6" maxlength="4" style="margin:0 4px;" />到<input name="search_height_to" id="search_height_to" type="text" size="8" maxlength="4" style="margin:0 4px;" />厘米</li>'],
		['<li id="limit4"><a href="javascript:advSearch.add(4);">更新时间</a></li>','<li><select name="search_time" id="search_time"><option value="">请选择更新时间</option><option value="">不限</option><option value="0">今天</option><option value="3">最近三天</option><option value="7">最近一周</option><option value="30">最近一个月</option></select></li>'],
		['<li id="limit5"><a href="javascript:advSearch.add(5);">求职地区</a></li>','<li>'+selectArea('search_area')+'</li>']
	);
	//显示区块
	this.boxA = $I('search_type_box');
	this.boxB = $I('search_keys_box');
	this.boxC = $I('search_limit');
	this.boxD = $I('search_limit_list');
	this.boxE = $I('search_add');
	this.boxF = $I('search_go');
	//选择条件
	this.begin = function(n,ext){
		if( this.boxB.style.display != 'none' ) return;
		$(this.boxA).empty();
		this.boxA.innerHTML = this.items[n][0];
		this.boxA.className = 'type2';
		this.boxB.innerHTML = this.items[n][1];
		$I('search_model').value = n;
		if( ext ){
			var a = ext.split(',');
			for(var i=0; i<a.length; i++){
				if(this.limits[a[i]]) $(this.boxD).append(this.limits[a[i]][0]);
			}
			$(this.boxE).show('fast');
		}
		$(this.boxB).show('fast');
		$(this.boxF).show('fast');
	}
	//添加条件
	this.add_lk = $I('search_add');
	this.add_box = function(obj){
		selectVisible(0);
		var pos = new getPosition(obj);
		this.boxD.style.left = pos.left - 5 + 'px';
		this.boxD.style.top  = pos.top + 16 + 'px';
		if($(this.boxD).children('li').length>0) $(this.boxD).show('fast');
	}
	this.add_close = function(){
		selectVisible(1);
		function tfun(){$(advSearch.boxD).slideUp('fast');}
		window.setTimeout(tfun,100);
	}
	this.add = function(n){
		$(this.boxC).append(this.limits[n][1]);
		$(this.boxC).show('fast');
		$('LI').remove('#limit'+n);
		if($(this.boxD).children('li').length==0){
			$(this.boxD).hide();
			$(this.boxE).hide();
		}
	}
	//初始化
	this.build = function(model){
		this.boxA.className = 'type';
		this.boxA.style.display = 'none';
		this.boxB.style.display = 'none';
		this.boxC.style.display = 'none';
		this.boxD.style.display = 'none';
		this.boxE.style.display = 'none';
		this.boxF.style.display = 'none';
		
		$(this.boxA).empty();
		for(var i=0; i<this.items.length; i++){
			$(this.boxA).append(this.items[i][0]);
		}
		$(this.boxA).show('fast');
		
		$(this.boxC).empty();
		
		$(this.boxD).empty();
		
		$(this.boxE).empty();
		$(this.boxE).append('+<a href="javascript:void(0);" onclick="advSearch.add_box(this);" onblur="advSearch.add_close();">增加其它条件</a>');
		
		$(this.boxF).empty();
		$(this.boxF).append('<input type="hidden" name="search_model" id="search_model" /><input type="button" name="button_search_adv" class="button" value="立即搜索" onclick="$I(\'form_search_adv\').submit();" />&nbsp; <a href="javascript:advSearch.build(0);">重新选择条件</a>');
		
		if( model == 0 ) return;
		
		//搜索结果状态显示
		var n = getQuery('search_model');
		if( this.items[n] ){
			//记录搜索模式
			$I('search_model').value = n;
			//显示搜索模式
			this.boxA.innerHTML = this.items[n][0];
			this.boxB.innerHTML = this.items[n][1];
			//显示搜索条件
			var str = this.boxA.getElementsByTagName('A')[0].href;
			str = str.replace('javascript:advSearch.begin('+n+',\'','');
			str = str.replace('\');','');
			var a = str.split(',');
			for(var i=0; i<a.length; i++){
				if(this.limits[a[i]]) $(this.boxD).append(this.limits[a[i]][0]);
			}
			if( $I('search_keys') )$I('search_keys').value = decodeURIComponent(getQuery('search_keys')).replace(/[+]/g,' ');
			if( n!=1 && getQuery('search_job_trade').trim()!='' ){
				$(this.boxC).append(this.limits[0][1]);
				$('LI').remove('#limit0');
				str = decodeURIComponent(getQuery('search_job_trade')).trim();
				if( str != '' ){
					$I('search_job_trade').value = str; $I('search_job_trade_1').value = str;
				}
			}else if( n == 1 ){
				str = decodeURIComponent(getQuery('search_job_trade')).trim();
				if( str != '' ){
					$I('search_job_trade').value = str; $I('search_job_trade_1').value = str;
				}
			}
			if( n!=2 && getQuery('search_age_from').trim()!='' ){
				$(this.boxC).append(this.limits[1][1]);
				$('LI').remove('#limit1');
				str = decodeURIComponent(getQuery('search_age_from')).trim();
				if( str != '' ){
					$I('search_age_from').value = str;
				}
				str = decodeURIComponent(getQuery('search_age_to')).trim();
				if( str != '' ){
					$I('search_age_to').value = str;
				}
			}else if( n == 2 ){
				str = decodeURIComponent(getQuery('search_age_from')).trim();
				if( str != '' ){
					$I('search_age_from').value = str;
				}
				str = decodeURIComponent(getQuery('search_age_to')).trim();
				if( str != '' ){
					$I('search_age_to').value = str;
				}
			}
			if( n!=3 && getQuery('search_sex').trim()!='' ){
				$(this.boxC).append(this.limits[2][1]);
				$('LI').remove('#limit2');
				setSelect($I('search_sex'),'value',decodeURIComponent(getQuery('search_sex')));
			}else if( n == 3 ){
				setSelect($I('search_sex'),'value',decodeURIComponent(getQuery('search_sex')));
			}
			if( n!=4 && getQuery('search_height_from').trim()!='' ){
				$(this.boxC).append(this.limits[3][1]);
				$('LI').remove('#limit3');
				str = decodeURIComponent(getQuery('search_height_from')).trim();
				if( str != '' ){
					$I('search_height_from').value = str;
				}
				str = decodeURIComponent(getQuery('search_height_to')).trim();
				if( str != '' ){
					$I('search_height_to').value = str;
				}
			}else if( n == 4 ){
				str = decodeURIComponent(getQuery('search_height_from')).trim();
				if( str != '' ){
					$I('search_height_from').value = str;
				}
				str = decodeURIComponent(getQuery('search_height_to')).trim();
				if( str != '' ){
					$I('search_height_to').value = str;
				}
			}
			if( getQuery('search_time').trim() != '' ){
				$(this.boxC).append(this.limits[3][1]);
				$('LI').remove('#limit3');
				setSelect($I('search_time'),'value',getQuery('search_time'));
			}
			if($(this.boxC).children('li').length>0) $(this.boxC).show('fast');
			if($(this.boxD).children('li').length>0) $(this.boxE).show('fast');
			//显示其他项
			$(this.boxB).show('fast');
			$(this.boxF).show('fast');
			
			//alert($I('form_search_adv').innerHTML);
		}
	}
}
var advSearch;
function loadSearchAdv(){
	advSearch = new searchClass;
	advSearch.build();
}
//addLoadEvent(loadSearchAdv);