var g_dx = 100, g_dy = 100;
var g_cusAddPt = null;
var g_mapId = 21;
var g_poitype = "";
var g_keyname = "";

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 changeImg(eleName,imgName) 
{ 
  var x = findObj(eleName);
  if(x != null)
  	x.src = "images/" + imgName;	  
}

function mst_zoom(classType)
{
	var retClassType = document.MSTMAP.mst_zoom(classType);
	var i=1;
	for(i=1;i<=15;i++)
		changeImg("z"+i,"zoom_n.gif");
	changeImg("z" + retClassType,"zoom_i.gif");
}

function mst_moveMap(dx,dy)
{
	document.MSTMAP.mst_panMap(dx,dy);
}

function mst_prevMap()
{
	document.MSTMAP.mst_go2HisMap();
}

function mst_printMap()
{
	window.open("mst_print.jsp?g_mapFullCmd=" + document.MSTMAP.mst_getMapFullCmdParams(),"PRINTMAP","height=" + (document.MSTMAP.height*1+80) + ",width=" + (document.MSTMAP.width*1+20) + ",top=0,left=0");	
}

function mst_simpleMailMap()
{
	window.open("mst_simplemail.jsp","MAILMAP","height=200,width=500,top=0,left=0");	
}

function mst_startAddPoint(toolname)
{
	document.MSTMAP.removeAll();	
	document.MSTMAP.mst_setTool2("mst_mapctrl." + toolname);
	g_cusAddPt = null;
}

function mst_pointAdded(obj)
{
	document.MSTMAP.mst_setTool2(null);		
	obj.setLabel("地点名称");	
	g_cusAddPt = obj;
}

function mst_clear()
{
	document.MSTMAP.removeAll();	
	document.MSTMAP.repaint();
	g_cusAddPt = null;
	document.MSTMAP.mst_setTool2(null);
}

function mst_pan2map(inputObjName)
{
	var obj = findObj(inputObjName);
	if(obj == null || obj.value.length == 0)
	{
		alert("请输入地址！");
		return;	
	}
	document.MSTMAP.mst_panMapByCmd("g_mapid=" + g_mapId,"&g_addr=" + obj.value,"");
}

function mst_addPtByCmd(inputObjName,labelObjName)
{
	var objLabel = findObj(labelObjName);
	if(objLabel == null || objLabel.value.length == 0)
	{
		alert("请填写信息名称!");
		objLabel.focus();		
		return;	
	}
	var obj = findObj(inputObjName);
	if(obj == null || obj.value.length == 0)
	{
		alert("请输入地址！");
		obj.focus();
		return;	
	}
	var retPt = document.MSTMAP.mst_addPtByCmd("g_mapid=" + g_mapId,"&g_addr=" + obj.value,objLabel.value);
	if(retPt == null)
	   alert("请您确定您输入了正确的地址！");
	else
	   g_cusAddPt = retPt;
}

function mst_addDbPt(id,x,y,label,imgUrl)
{
	document.MSTMAP.mst_addDbPoint(id,x,y,label,imgUrl);
}

function mst_mapDbPtClick(id)
{
}

function mst_setCusPtImg(imgUrl)
{
	document.MSTMAP.mst_setCusPtImg(imgUrl);	
}

function mst_showCusPoints(poiData)
{
	document.MSTMAP.mst_showCusPoints(poiData,true);
}

function mst_getZoomClass()
{
	var nClassType = document.MSTMAP.mst_getZoomClass();
	return nClassType;
}

function mst_setZoomClass(nZoomClass)
{
	document.MSTMAP.mst_setZoomClass(nZoomClass);	
}

var wPoiDetail = null;

function mst_mapDbPtClick(id,label)
{
	return;
	
	var obj = findObj("PTURLDIV");
	obj.innerHTML = "<a href=\"javascript:showPoi('" + g_mapId + "','" + label + "','" + id + "')\">点这里打开：<font color=red>" + label + "</font>的详细信息</a>";
}

function mst_startSearch()
{
	var cx = document.MSTMAP.mst_getCenterPX();
	var cy = document.MSTMAP.mst_getCenterPY();
	var cscope = findObj("env_scope");
	var cpoitype = findObj("env_type");
	var urlPost = "http://www.gsuo.com/mstmap50007/g_search.jsp?poitype=" + cpoitype.value + "&g_mapid=" + g_mapId + "&g_env_cx=" + cx + "&g_env_cy=" + cy + "&g_scope=" + cscope.value;	
	window.open(urlPost);
}

function submitByHeadDiv(newUrl)
{
	location = newUrl;
}

var tipTitleColor = "#A6D5F6";
var tipDescColor = "#FFFFCC";
var xoffset = 400;
var yoffset = 135;
var toolTipFrame;
var bInitToolTip = false;

function CreateTip(strTitle, strContent)
{
	var ContentInfo = "<table border='0' id='tabletip' width='200' cellspacing='0' cellpadding='0'>"+
				"<tr><td width='100%' bgcolor='#000000'><table border='0' width='100%' cellspacing='1' cellpadding='0'>"+
				"<tr><td width='100%' bgcolor='"+tipTitleColor+"'>"+
				"<table border='0' width='90%' cellspacing='0' cellpadding='0' align='center'>"+
				"<tr><td id='tiptitle'width='100%' class='tiptitle'>"+strTitle+"</td>"+
				"<td style='cursor:hand' valign='top'><a href='javascript:hideTip();'><font color=#000000 size=2 face=arial  style='text-decoration:none'>x</font></a>"+
				"</td></tr></table></td></tr><tr><td width='100%' bgcolor='"+tipDescColor+"'>"+
				"<table border='0' width='100%' cellpadding='0' cellspacing='1' align='center'>"+
				"<tr><td id='tipcontent' width='100%' class='tipdesc'>"+strContent+"</td></tr>"+
			"</table></td></tr></table></td></tr></table>";

	ToolTipFrame.createMsgBody(ContentInfo);
}

function MoveTip(layerName, FromTop, FromLeft, e)
{
	eval("document.all." + layerName + ".style.top = "  + (eval(FromTop) + document.body.scrollTop));
	eval("document.all." + layerName + ".style.left = " + (eval(FromLeft)));
}

function UpdateTip(strTitle, strContent)
{
	if(!bInitToolTip)
	{
		CreateTip(strTitle, strContent);
		bInitToolTip = true;
	}
	else
	{
		if(document.getElementById("tiptitle"))
			document.getElementById("tiptitle").innerHTML = strTitle;
		if(document.getElementById("tipcontent"))
			document.getElementById("tipcontent").innerHTML = strContent;
	}
}

function showTip(pid,strTitle, strContent,x, y)
{
	//if(strContent == "null")
	strContent = "<a href='javascript:showDcDetail(" + pid + ")'>查看详情</a>";
	UpdateTip(strTitle,strContent);
	if(strTitle.length>9)
	   toolTipFrame.height = 50;
	else
	   toolTipFrame.height = 35;
	var ynew = y*1 + yoffset - document.body.scrollTop;
	var xnew = x*1 + xoffset;
	MoveTip("ToolTip",ynew,xnew);
	ToolTipFrame.updateMsg(strTitle, strContent);
	eval("document.all.ToolTip.style.visibility = 'visible'");
}

function showTipex(strContent,x,y)
{
   var strTitle = '该地点信息列表';
   var strNC = "";
   var eachline = new Array(), eachpoi = new Array();
   eachline = strContent.split('~~');
   for(var i=1;i<eachline.length;i++)
   {
      eachpoi = eachline[i].split('^');
      if(eachpoi.length == 2)
         strNC += "<li><a href='javascript:showDcDetail(" + eachpoi[0] + ")'>" + eachpoi[1] + "</a>";         
   }

   UpdateTip(strTitle,strNC);  	
   var ynew = y*1 + yoffset - document.body.scrollTop;
   var xnew = x*1 + xoffset;
   MoveTip("ToolTip",ynew,xnew);
   var h = ToolTipFrame.updateMsg(strTitle, strNC);
   toolTipFrame.height = h;
   eval("document.all.ToolTip.style.visibility = 'visible'");
}

function hideTip()
{
	eval("document.all.ToolTip.style.visibility = 'hidden'");
	MoveTip("ToolTip", 0, 0);
}

document.write('<DIV id="ToolTip" style="position:absolute;width:200px;left:600;top:300;visibility:hidden;z-index:10">');
document.write('<iframe id="ToolTipFrame" src="tooltip.htm" frameborder="0" width="200" height="40" scrolling="no"></iframe>');
document.write('</DIV>');
toolTipFrame = findObj("ToolTipFrame");
