// JavaScript Document
var x,y  
var drag_=false  
var D=new Function('obj','return document.getElementById(obj);')  
var IE=new Function('','if(navigator.appName.indexOf("Explorer")>=0)return 1;if(navigator.appName.indexOf("Netscape")>=0)return 2') 
var bodyScrollWidth = 0;
var bodyScrollHeight = 0;


(function (bool) {
//兼容FF一些方法
    var html;
    if (bool) {
        html = window.HTMLElement.prototype;
        window.__defineGetter__("event", function () {
        //兼容Event对象
            var o = arguments.callee;
            do {
                if (o.arguments[0] instanceof Event) return o.arguments[0];
            
            } while (o = o.caller);
            return null;
        });
        Event.prototype.__defineGetter__("fromElement", function () {
        /*
        这里：
        onmouseover的时候relatedTarget为鼠标离开（onmouseout）的对象
        onmouseout的时候relatedTarget为鼠标当前（onmouseover）的对象
        */
            return this.relatedTarget;

        });
        html.contains = function (o) {
            do {
                if (o == this) return true;
            } while (o = o.parentNode);
            return false;
        };
    }
})(/Firefox/.test(window.navigator.userAgent));
      
if(navigator.appName.indexOf("Explorer") > -1){//ie
	var exp = 1;
}else{//for ff
	var exp = 2;
}

function buildGlobalDiv(){
		var globalDiv = document.createElement( 'listDiv' );
		globalDiv.id = 'globalDiv';
		globalDiv.style.display = 'none';
		globalDiv.style.zIndex = '98';
		globalDiv = set_div_style( globalDiv , 'globalDiv' , '0px' , '0px' , bodyScrollWidth + 'px' , bodyScrollHeight + 'px' , 'absolute' , '#333333 0px solid' , 'default' , 'darkgray' );
		if( 1 == exp ){
			globalDiv.style.filter = 'alpha(opacity=30)';
		}else{
			globalDiv.style.opacity = 30/100;
		}
		document.body.appendChild( globalDiv );
}

function set_div_style( obj , id , top , left , width , height , position , border , cursor , background ){
	var obj = obj;
	obj.id = id ? id : null;
	obj.style.top = top ? top : '0px';
	obj.style.left = left ? left : '0px';
	obj.style.width = width ? width : '0px';
	obj.style.height = height ? height : '0px';
	obj.style.position = position ? position : 'static';
	obj.style.border = border ? border : '1px #000 solid';
	obj.style.cursor = cursor ? cursor : 'default';
	obj.style.background = background ? background : '';
	return obj;
}


function hide(){

	synSizeByBody( 'globalDiv' );
	document.getElementById( 'globalDiv' ).style.display = 'block';
	
	if ( 1 == exp ) {
		hideElementAll();
	}
}

function synSizeByBody() {
	reCalBodySize();
	var argArr = synSizeByBody.arguments;
	for( i = 0 ; i < argArr.length ; i++ ) {
		if( document.getElementById( argArr[i] ) != null ){
			document.getElementById( argArr[i] ).style.width = ( bodyScrollWidth ) + 'px';
			document.getElementById( argArr[i] ).style.height = ( bodyScrollHeight ) + 'px';
		}
	}
}

function hideElementAll(){
	HideElement( 'SELECT' );
	HideElement( 'OBJECT' );
	HideElement( 'IFRAME' );
}


function HideElement( strElementTagName ){
	try{
		for( i = 0 ; i < window.document.all.tags( strElementTagName ).length ; i++ ){
			var objTemp = window.document.all.tags( strElementTagName )[i];
			objTemp.style.visibility = 'hidden';
		}
	}catch( e ){
		//alert( e.message );
	}
}

function reCalBodySize(){
	bodyScrollWidth = document.documentElement.scrollWidth;
	bodyScrollHeight = document.documentElement.scrollHeight;
}

//取消锁定主页面
function cancel() {
	document.getElementById( 'globalDiv' ).style.display = 'none';
	if ( 1 == exp ) {
		showElementAll();
	}
}
//显示所有对象
function showElementAll(){
	ShowElement( 'SELECT' );
	ShowElement( 'OBJECT' );
	ShowElement( 'IFRAME' );
}
//显示主页面对象
function ShowElement( strElementTagName ){
	try{
		for( i = 0 ; i < window.document.all.tags( strElementTagName ).length; i++ ){
			var objTemp = window.document.all.tags( strElementTagName )[i];
			objTemp.style.visibility = 'visible';
		}
	}catch( e ){
		//alert( e.message );
	}
}

 //拖动层
function Move_obj(obj)
{//1  
	var o=document.getElementById(obj);
	D(obj).onmousedown=function(e){drag_=true//4  
			  with(this){style.position="absolute";temp1=offsetLeft;temp2=offsetTop;//5  
			  if(exp==1){x=event.clientX;y=event.clientY//6  
				  document.onmousemove=function(e){//7  
						if(drag_==false)return false  
					 with(this){style.left=temp1+event.clientX-x+"px";if((parseInt(style.left)+parseInt(o.offsetWidth))>bodyWidth)style.left=bodyWidth-parseInt(o.offsetWidth)+"px";if(parseInt(temp1+event.clientX-x)<0)style.left=0+"px";style.top=temp2+event.clientY-y+"px";if(parseInt(temp2+event.clientY-y)<0)style.top=0+"px";}  
					 }//7  
			  }//6  
			  if(exp==2){x=e.pageX;y=e.pageY;//8  
				  document.onmousemove=function(e){//9  
						if(drag_==false)return false  
					 with(this){style.left=temp1+e.pageX-x+"px";if((parseInt(style.left)+parseInt(o.offsetWidth))>bodyWidth)style.left=bodyWidth-parseInt(o.offsetWidth)-1+"px";if(parseInt(temp1+e.pageX-x)<0)style.left=0+"px";style.top=temp2+e.pageY-y+"px";if(parseInt(temp2+e.pageY-y)<0)style.top=0+"px";}  
					 }//9  
			  }//8  
		}//5  
document.onmouseup=new Function("drag_=false")  
	 }//4  
}//1  


function show_area_div(obj)
{
   
    tableArea = document.getElementById('table_area');
    tableArea.style.left=  getPosition(obj).x + 195 + 'px';    
	//alert(tableArea.style.left);
    tableArea.style.top = getPosition(obj).y + document.documentElement.scrollTop + 90 + 'px';
    tableArea.style.display = 'block';    
}
function show_index_city()
{
    inputCity = document.getElementById('input_city');
    tableArea = document.getElementById('tb_index_city');
    tableArea.style.left= getPosition(inputCity).x + document.documentElement.scrollLeft + 'px';    
    tableArea.style.top = getPosition(inputCity).y+getLTWH(inputCity).height  + 'px';
    tableArea.style.display = 'block';    
}

function saveNowCityHtml(area)
{
//alert(area);
   try{
  document.getElementById('input_city').value = area;
   }
   catch(e){alert(e.message)};
   
	try{
    document.getElementById('table_area').style.display ='none';
document.getElementById('tb_index_city').style.display ='none';
	}
	catch(e){alert(e.message)};
	
	try
	{
		document.getElementById('addr').focus();
	}
	catch(e){alert(e.message)};
	if(area !="" )
	{
    xajax_set_current_area(area);
	}
}
function saveNowCityHtml1(area)
{
//alert(area);
   try{
  //document.getElementById('input_city').value = area;
   }
   catch(e){alert(e.message)};
   
	try{
    document.getElementById('table_area').style.display ='none';
//document.getElementById('tb_index_city').style.display ='none';
	}
	catch(e){alert(e.message)};
	
	try
	{
		//document.getElementById('addr').focus();
	}
	catch(e){alert(e.message)};
    xajax_set_current_area(area);
}
function getPosition(el)
{
	for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}
function getLTWH(o)
{
     var oLTWH=
     {
             "left":0,
             "top":0,
             "width":0,
             "height":0
     };
     //在IE中循环取offsetLeft、offsetTop将忽略border而产生误差，于是利用getBoundingClientRect()取值。-2是IE的2pxBUG。
     if(window.navigator.userAgent.indexOf("MSIE")>=1)
     {
             var oRect=o.getBoundingClientRect();
             oLTWH.left=oRect.left-2;
             oLTWH.top=oRect.top-2;
     }
     //利用FF的offsetLeft、offsetTop是相对于BODY的BUG取值。
     if(window.navigator.userAgent.indexOf("Firefox")>=1)
     {
             oLTWH.left=o.offsetLeft;
             oLTWH.top=o.offsetTop;
     }
     oLTWH.width=o.offsetWidth;
     oLTWH.height=o.offsetHeight;
     return oLTWH;
}

/*
function seach(obj,formid)
{
	document.getElementById('search_obj').value=obj;
	if(seach_smt(obj)==true)
	{
		document.getElementById(formid).submit();
	}
}
*/
function seach_smt()
{
	var kw=document.getElementById('keyword').value;
	var city=document.getElementById('input_city').value;
	kw=kw.replace(/\s/g,"");
	city=city.replace(/\s/g,"");
	
	if(kw=='请输入公司名称或职位关键字')
	{
		alert('请您输入关键字或选择职位名称！');
		//kw.focus();
		return false;
	}
	else if(kw=='')
	{
		alert('请您输入关键字或选择职位名称！');
		//kw.focus();
		return false;
	}
	else
	{
		if(city==''||city=='请选择工作地点')
		{
			alert('您没有选择地区！');
			//aer.focus();
			return false;
		}
		else
		{
			document.getElementById('qeury').style.display='block';
			return true;
		}
	}
}


function getJobClass()
{

	var job_fun_html="<div style='float:left;background:url(http://www.boleme.com/images/search3_9.gif) repeat-x;width:100%;height:35px;'><span style='float:left;color:#ffffff;line-height:30px;font-weight:bold;padding-left:10px;'>请单击职位类别</span><span class='JobsClass_close'><a href='#' onClick=\"CloseDiv('JobsClass');\">关闭</span></div>";
	jQuery.getJSON("http://www.boleme.com/job-seekers/getJobs.php?pid=0",
		function(data){
		for(i=0;i<data.funs.length;i++)
		{
			//$("#area").append();
			job_fun_html+="<li id='"+data.funids[i]+"'><a href='javascript:;' onclick=\"getJobs('"+data.funids[i]+"');\">"+data.funs[i]+"</a></li>";
		}
		var obj=document.getElementById('JobsClass');
		obj.style.display='block';
		obj.innerHTML=job_fun_html;
	}); 
	
}

function getJobs(pid)
{
	focuid=document.getElementById(pid);
	Layer=document.getElementById('jobs');

	var jobs_html='';
	jQuery.getJSON("http://www.boleme.com/job-seekers/getJobs.php?pid="+pid,
	function(data){
	for(i=0;i<data.funs.length;i++)
	{
		//$("#area").append();
		jobs_html+="<div id='jobsty'><a href=\"javascript:getJob('"+data.funs[i]+"','keyword');\">"+data.funs[i]+"</a></div>";
	}
	Layer.innerHTML=jobs_html;
	Layer.style.left= getPosition(focuid).x + 'px';
	Layer.style.top = getPosition(focuid).y +20+'px';
	Layer.style.display='block';
	Layer.onmouseout = function()
		{
			var e = window.event;
			if( !Layer.contains(e.toElement || e.fromElement) && !focuid.contains(e.toElement || e.fromElement)){Layer.style.display = 'none'; }
			
		}
		focuid.onmouseout = function()
		{
			var e = window.event;
			if( !Layer.contains(e.toElement || e.fromElement) && !focuid.contains(e.toElement || e.fromElement)){Layer.style.display = 'none'; }
			
		}
	}); 
	
}

function getJob(value,domid)
{
	document.getElementById(domid).value=value;
}

function CloseDiv(objid)
{
	var obj=document.getElementById(objid);
	obj.style.display='none';
}


function getPosition(el)
{
	for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}

function getPwd()
{
	var type;
	var ReturnHtml='';
	var person=document.getElementById("person");
	var usrname=document.getElementById("usrname").value;
	usrname=usrname.replace(/\s/g,"");
	if(usrname=='')
	{
		alert("帐号不能为空！");
	}
	else
	{
		if(person.checked==true)
		{
			type="person";
		}
		else
		{
			type="company";
		}
		$.getJSON("http://www.boleme.com/getPwds.php?type="+type+"&usrname="+usrname,
		function(data){
		for(i=0;i<data.Rs.length;i++)
		{
			//$("#area").append();
			ReturnHtml+=data.Rs[i];
		}
		alert(ReturnHtml);
		document.getElementById("forgetPwd").style.display="none";
		}); 
	}
}




