function set_current_area(city){
	var cookieName=city;
	$.cookie("current_area",cookieName,{expires:365,domain:'.boleme.com'});
	return false;
}

function get_current_area(){
	var cookieName=$.cookie("current_area");
	return cookieName;
}

function search_job(obj){
	var keyword = obj.value;
	if(keyword=='')return;
	$.ajax( {
		type : "POST",
		url : '/search_job.php',
		dataType : "json",
		cache : true,
		data : {
			keyword:keyword
		},
		success : function(msg) {
			if(msg.status==200){
				show_job(msg,obj);
			}else if(msg.status==500){
				if($('#show_job_txt').length>1){
					$('#show_job_txt').hide();
				}
			}
		}
	});
}

function show_job(msg,obj){
	var margin_left = parseInt($(obj).css('margin-left').match(/[0-9]+/));
	var width = $(obj).width();
	var left = $(obj).position().left+margin_left;
	var top = $(obj).position().top+$(obj).height();
	if($('#show_job_txt').length<1){
		$('body').prepend("<div style='border:1px solid #aaa;position:absolute;overflow:hidden;background:#F8F8F8;' id='show_job_txt'></div>");
	}
	$('#show_job_txt').empty().width(width);
	for(var i=0;i<msg.company_name.length;i++){
		$('#show_job_txt').append('<div style="height:22px;line-height: 22px;font-size:14px;color:#000;cursor:pointer;overflow:hidden;">'+msg.company_name[i]+'</div>');
	}
	$('#show_job_txt div').width(width).mouseover(function(){
		$(this).css({'background':'#55D201','color':'#fff','font-weight':'bold'});
	}).mouseout(function(){
		$(this).css({'background':'#F8F8F8','color':'#000','font-weight':'normal'});
	}).click(function(){
		$(obj).val($(this).text());
		$(this).parent().hide();
	});
	$('#show_job_txt').css({'left':left,'top':top}).show();
}

function search_position(obj){
	var keyword = obj.value;
	if(keyword=='')return;
	$.ajax( {
		type : "POST",
		url : '/search_position.php',
		dataType : "json",
		cache : true,
		data : {
			keyword:keyword
		},
		success : function(msg) {
			if(msg.status==200){
				show_position(msg,obj);
			}else if(msg.status==500){
				if($('#show_job_txt').length>1){
					$('#show_job_txt').hide();
				}
			}
		}
	});
}

function show_position(msg,obj){
	var margin_left =0;
	try{
		margin_left = parseInt($(obj).css('margin-left').match(/[0-9]+/));
	}catch(e){
	}
	var width = $(obj).width();
	var left = $(obj).position().left+margin_left;
	var top = $(obj).position().top+$(obj).height();
	if($('#show_job_txt').length<1){
		$('body').prepend("<div style='border:1px solid #ccc;position:absolute;overflow:hidden;background:#eee;' id='show_job_txt'></div>");
	}
	$('#show_job_txt').empty().width(width);
	for(var i=0;i<msg.job_name.length;i++){
		$('#show_job_txt').append('<div style="height:22px;line-height: 22px;font-size:14px;color:#000;cursor:pointer;overflow:hidden;">'+msg.job_name[i]+'</div>');
	}
	$('#show_job_txt div').width(width).mouseover(function(){
		$(this).css({'background':'#55D201','color':'#fff','font-weight':'bold'});
	}).mouseout(function(){
		$(this).css({'background':'#eee','color':'#000','font-weight':'normal'});
	}).click(function(){
		$(obj).val($(this).text());
		$(this).parent().hide();
	});
	$('#show_job_txt').css({'left':left,'top':top}).show();
}

$(document).ready(function(){
	$('body').click(function(){
		if($('#show_job_txt').length>=1){
			$('#show_job_txt').hide();
		}
	});
});
