function findObj(n, d) 
{
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function display_div(divname,nvisual)
{
   try
   {
	   if(nvisual == 0)
	   {
	   	eval(divname + ".className='cshidden'");
	        eval("close" + divname + ".className='cshidden'");
	        eval("open" + divname + ".className='csvisual'");
	   }
	   else
	   {
	   	eval(divname + ".className='csvisual'");     
	        eval("open" + divname + ".className='cshidden'");
	        eval("close" + divname + ".className='csvisual'");
	   }
   }
   catch(e)
   {
      alert("没有子类！");
   }
}

function showSelect(objName)
{
	var objTarget = findObj(objName);
	var xPos,yPos;
	var lstDiv = findObj("mstListDiv");
	var lstSel = findObj("mstListSel");
	if (lstDiv.style.visibility=="visible" && curObjTarget == objTarget)
		lstDiv.style.visibility = "hidden";
	else
	{
		xPos = getLstDivShowLeft(objTarget);
		yPos = getLstDivShowTop(objTarget);
		lstDiv.style.pixelLeft = xPos;
		if(yPos - document.body.scrollTop + 100>document.body.clientHeight)
			//lstDiv.style.pixelTop = yPos - 140;			
			lstDiv.style.pixelTop = yPos - 5;
		else
			lstDiv.style.pixelTop = yPos + 20;
		lstSel.style.pixelWidth = objTarget.size*8;
		lstDiv.style.visibility = "visible";
	}
	curObjTarget = objTarget;
}

function mst_usrSelect(objName,varName)
{	
	resetSelect();	
	addSelOpts(eval(varName));	
	showSelect(objName);	
}

function resetSelect()
{
	var sel = document.all.mstListSel;
	for(;sel.options.length>0;)
		sel.options.remove(0);
	cur_sel = null;
}

function getLstDivShowTop(objTarget)
{
	var ret = 0;
	if (objTarget==document.body) return 0;
	ret += objTarget.offsetTop;
	ret -= objTarget.scrollTop;
	if (objTarget.offsetParent)
		ret += getLstDivShowTop(objTarget.offsetParent);
	return ret;
}

function getLstDivShowLeft(objTarget)
{
	var ret = 0;
	if (objTarget==document.body) return 0;
	ret += objTarget.offsetLeft;
	if (objTarget.offsetParent)
		ret += getLstDivShowLeft(objTarget.offsetParent);
	return ret;
}

function addSelOpts(opts)
{
	var selOpt,sel;
	sel = findObj("mstListSel");		
	var nStartPos=0,nEndPos = -1,nFieldPos = 0;
	var vField = null;
	while((nEndPos = opts.indexOf("~",nStartPos)) != -1)
	{
		vField = opts.substring(nStartPos,nEndPos);
		
		nFieldPos = vField.indexOf("^");
		selOpt = document.createElement("OPTION");
		sel.options.add(selOpt);					
		selOpt.innerText = vField.substring(0,nFieldPos);			
		selOpt.value = vField.substring(nFieldPos+1);	
		
		nStartPos = nEndPos + 1;
	}		
}

function getOptValue(obj)
{
	var selOpt;
	if (curObjTarget==null) return;
	selOpt = obj.options[obj.selectedIndex];
	curObjTarget.value = selOpt.text;	
	//用From和To的名称来区别存贮对象
	if(curObjTarget.name.indexOf("From") != -1)
	   curObjFromValue = selOpt.value;
	else
	   curObjToValue = selOpt.value;
	hideSelOpt();
}

function hideSelOpt()
{
   document.all.mstListDiv.style.visibility = "hidden";	
}

function hideMstListDiv()
{
	document.all.mstListDiv.style.visibility = "hidden";	
}

function mst_calcBusPath(fromObjName,toObjName)
{
	var objFrom = findObj(fromObjName);
	var objTo = findObj(toObjName);	
	if(objFrom == null || objFrom.value.length == 0 || objTo == null || objTo.value.length == 0)
	{
		alert("请输入地址！");
		return;	
	}
	var objFromValue = null, objToValue = null;
	if(objFrom.value==m_DbAddrLabelOrg)
	      objFromValue = m_DbAddrValueOrg;	      
	else
	      objFromValue = objFrom.value;	   

	if(objTo.value==m_DbAddrLabelOrg)
	      objToValue = m_DbAddrValueOrg;
	else
	      objToValue = objTo.value;
	
	if(objFromValue == objToValue)
	{
	   alert("请输入不同的起始点！");
	   return;
	}	
	window.open("http://www.gsuo.com/mstmap50007/g_detail.jsp?g_mapid=21&g_label=%C8%CB%C3%F1%B9%E3%B3%A1&g_cmdpathtype=buspath&g_from=" + objFromValue + "&g_to=" + objToValue + "&g_pathstyle=1&g_pathDistance=100","MST");
}

function showDcDetail(dcid)
{
   location = "dd_adv_detail.jsp?dc_id=" + dcid;
}

function showBFFriendDetail(bfid)
{
   location = "blog_friend_detail.jsp?bf_id=" + bfid;
}

function showBFDiaryDetail(bfid)
{
   location = "blog_diary_detail.jsp?bd_id=" + bfid;
}

function showDcDetailEx(dcid)
{
   location = "dd_adv_detail.jsp?dc_id_ex=" + dcid;
}

function maxit()
{
   //self.moveTo(0,0);
   self.resizeTo(screen.availWidth,screen.availHeight);
}

function mst_attach(pid,mname)
{
   window.open("fileutil/index.jsp?dc_pid=" + pid + "&dc_mname=" + mname,"MSTATTACH","height=400,width=550,top=100,left=350,status=1,scrollbars=1");
}