var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1 && !isOpera;
/* 鼠标拖动 */
var oDrag = "";
var ox,oy,nx,ny,dy,dx;
function drag(e,o){
	var e = e ? e : event;
	var mouseD = document.all ? 1 : 0;
	if(e.button == mouseD)
	{
		oDrag = o.parentNode;
		ox = e.clientX;
		oy = e.clientY;		
	}
}

function dragPro(e){
	if(oDrag != "")
	{	
		var e = e ? e : event;
		dx = parseInt($(oDrag).style.left);
		dy = parseInt($(oDrag).style.top);
		nx = e.clientX;
		ny = e.clientY;
		$(oDrag).style.left = (dx + ( nx - ox )) + "px";
		$(oDrag).style.top = (dy + ( ny - oy )) + "px";
		ox = nx;
		oy = ny;
	}
}
document.onmouseup = function(){oDrag = "";}
document.onmousemove = function(event){dragPro(event);}

var xmlHttp = false;

function createXMLHTTP(){ 
	if(window.XMLHttpRequest){ 
 		xmlHttp=new window.XMLHttpRequest(); 
		//XMLHttp.overrideMimeType("text/xml"); 
		return xmlHttp; 
	} 
	else if(window.ActiveXObject){ 
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		return xmlHttp; 
	} 
}
createXMLHTTP();

function $(o){ //获取对象
	if(typeof(o) == "string")
	return document.getElementById(o);
	return o;
}

function openBg(state){ //遮照打开关闭控制
	if(state == 1)
	{
		$("bg").style.display = "block";
		var h = document.body.offsetHeight > document.documentElement.offsetHeight ? document.body.offsetHeight : document.documentElement.offsetHeight;
		$("bg").style.height = h + "px";
	}
	else
	{
		$("bg").style.display = "none";
	}	
}

function getAbsoluteOffsetTop(obj) 
{
	var y = obj.offsetTop;
	while (obj = obj.offsetParent) y += obj.offsetTop;
	if(isIE)
	{
		return y+20;
	}
	else{
		return y+20+"px";
	}
}

function getAbsoluteOffsetLeft(obj,dwidth) 
{
	var x = obj.offsetLeft;
	while (obj = obj.offsetParent) x += obj.offsetLeft;
	var wwidth=document.body.clientWidth;
	if(wwidth<800)wwidth=800;
	dwidth=wwidth-dwidth;
	if(x>dwidth)x=dwidth
	if(x<200)x=200;
	
	if(isIE)
	{
		return x;
	}
	else{
		return x+"px";
	}
}

function openSelect(state,strlayer,obj,dwidth){ //选择城市层关闭打开控制
	var layer=$(strlayer);
	if(dwidth==null)dwidth=0;
	if(state == 1)	
	{
		var y=getAbsoluteOffsetTop(obj);
		var x=getAbsoluteOffsetLeft(obj,dwidth);
		layer.style.display = "block";
		layer.style.left = x ;		
		layer.style.top = y ;	
		layer.focus();
	}
	else
	{
		layer.style.display = "none";
	}
}

function closeLayers(){
	openBg(0);
	if($('selectJob')!=null){
		openSelect(0,'selectJob',null);
	}
	if($('selectMajor')!=null){
	openSelect(0,'selectMajor',null);
	}
	if($('selectAddress')!=null){
	openSelect(0,'selectAddress',null);
	}
	if($('selectOthers')!=null){
	openSelect(0,'selectOthers',null);
	}	
}

function getTop(obj,offset)
{
	var y = obj.offsetTop;
	while (obj = obj.offsetParent) y += obj.offsetTop;
	if(isIE)
	{
		return y+offset;
	}
	else{
		return y+offset+"px";
	}
}

function getLeft(obj,dwidth,offset) 
{
	var x = obj.offsetLeft;
	while (obj = obj.offsetParent) x += obj.offsetLeft;
	var wwidth=document.body.clientWidth;
	if(wwidth<800)wwidth=800;
	dwidth=wwidth-dwidth;
	if(x>dwidth)x=dwidth
	if(isIE)
	{
		return x+offset;
	}
	else{
		return x+offset+"px";
	}
}

function showpost(jid){
	openBg(1);
	openSelect(1,'selectOthers',$('li'+jid),185);
	showOthData('190px','175px',1,jid-10,'请选择查询职位');
}

function highbright(jid,zt){
	if(zt==1){
		$("li"+jid).style.backgroundColor="#ff9249";
		$("li"+jid).style.color="#FFFFFF";
		$("li"+jid).style.fontWeight="bold";
	}else{
		$("li"+jid).style.backgroundColor="#f3fbf9";
		$("li"+jid).style.color="#0b7b08";
		$("li"+jid).style.fontWeight="";
	}
}

function Others_Selected(e)
{
	var ev = window.event|| e;
   	if(ev.keyCode==27){
		openBg(0);
		openSelect(0,'selectOthers',null);
	}
	if( 13 == ev.keyCode )
	{
		transAddress();
	}
}

function showOthData(dwidth,lwidth,lcols,d,title){
	var qry="&whichfile=" + $("menuid").value + "&jobregion=" + $("atplace").value+"&verifycode=" +$("verifycode").value;
	if(d==89){
		window.open("personjobsearch_list_ns2.asp?fstquery=1&jobtype=99" + qry ,"_self","");
		return;
	}	
	$("div_Oth_Title").innerHTML="<label>"+title+"</label>";
	$("selectOthers").style.width=dwidth;

	var j=0;
	var cnt="<li style='width:"+lwidth+";height:20px;line-height:20px;font-weight:bold;overflow:hidden'><img src='images/text_8.gif' style='padding-right:7px'/><a  href='personjobsearch_list_ns2.asp?fstquery=1&jobtype=" + post_v[d] + qry + "'>" + "(全部)"+post_s[d]+"类" +"</a></li>";
	for(var i=0;i<subpost_v[d].length;i++){
		if(j==0){
			cnt=cnt+"<ul class='uloth'>";
		}
		cnt=cnt+"<li style='width:"+lwidth+";height:20px;line-height:20px;'><img src='images/text_8.gif' style='padding-right:7px'/><a  href='personjobsearch_list_ns2.asp?fstquery=1&jobtype=" + subpost_v[d][i] + qry + "'>" + subpost_s[d][i] +"</a></li>";
		j=j+1;
		if(j>=lcols){
			cnt=cnt+"</ul>";
			j=0;
		}	
	}
	if(j>=0){
		cnt=cnt+"</ul>";
		j=0;
	}
	$("oth_Data").innerHTML=cnt;
}
