/*
 *Name：	地图接口文档
 *Date：	2008-11-04
 *Version：	0.00001
 *Author：	zc
 */
function Point(id,x,y,icon,name,city,contents,icon1){
/*功能：定义一个点
 *参数：
 *	x：点的经度
 *	y：点的纬度
 *	icon：图标的url
 *	name：名称
 *	city：城市
 */
  	this.id=id;
	this.x=x;
	this.y=y;
	this.name=name;
	this.city=city;
	this.icon=icon;
	if(contents&&contents!=""){
 	var cont=contents.split(";");
 	for(var i=0;i<cont.length;i++){
		var conts=cont[i].split(":");
		//eval("this."+conts[0]+"='"+conts[1]+"'")
		this[conts[0]]=conts[1];
	}
	}
	if(icon1&&icon1!="")this.icon1=icon1
	
}
var g_map;
function myOperator(city,cxy,zoomlevel,hasOverview,maptool,hasCross,hasFull)
{
	g_map = new SinaMap(city,cxy,zoomlevel,hasOverview,maptool,hasCross,hasFull);
	var operator=this;
	var drawObjs=new Array();
	var drawPois=new Array();
	this.map=g_map;
	g_map.addInitMenu();
	this.addSinglePoi = function(poi,GetNameHtml,GetLabelHtml,tipWidth,anchor,hidTail,picAgent)
	{   
		if(hidTail&&hidTail!="")tail="";
                else tail=getTail;
		var marker=g_map._addSinglePoi(poi,GetNameHtml,GetLabelHtml,tail,tipWidth,anchor,picAgent);
		var count=drawObjs.length;
		drawObjs[count]=marker;
		drawPois[count]=poi;
		return marker;
	} 
	
        this.addSinglePoiLabel =function(poi,GetNameHtml,GetLabelHtml,tipWidth,anchor,content,fontstyle,x,y,picAgent){
		var marker=g_map._addSinglePoiLabel(poi,GetNameHtml,GetLabelHtml,getTail,tipWidth,anchor,content,fontstyle,x,y,picAgent);
                var count=drawObjs.length;
                drawObjs[count]=marker;
                drawPois[count]=poi;
                return marker;
	}
	this.addPois = function(pois,GetNameHtml,GetLabelHtml,tipWidth,anchor,hidTail,dmColor,isLayOut,picAgent){
		if(hidTail&&hidTail!="")tail="";
		else tail=getTail;
		var overs=g_map._addPois(pois,GetNameHtml,GetLabelHtml,tail,tipWidth,anchor,dmColor,isLayOut,picAgent);
		for(var i=0;i<pois.length;i++){
			drawPois.push(pois[i]);
			drawObjs.push(overs[i]);
		}
		return overs;
	}
	this.addPoisLabel = function(pois,GetNameHtml,GetLabelHtml,tipWidth,anchor,content,fontstyle,x,y,isLayOut,picAgent){
		var overs=g_map._addPoisLabel(pois,GetNameHtml,GetLabelHtml,getTail,tipWidth,anchor,content,fontstyle,x,y,isLayOut,picAgent);
                for(var i=0;i<pois.length;i++){
                        drawPois.push(pois[i]);
                        drawObjs.push(overs[i]);
                }
                return overs;
	}
	this.addMarker=function(id,x,y,picurl,isCen,isDrag,callBack,picAgent){
		g_map.addMarker(id,x,y,picurl,isCen,isDrag,callBack,picAgent)
	}
	this.addTip=function(pois,GetNameHtml,GetLabelHtml,tipWidth,hidTail){
		if(hidTail&&hidTail!="")tail="";
                else tail=getTail;
		 g_map._onMouseClick(pois,GetNameHtml,GetLabelHtml,tail,tipWidth,true)
		 g_map.map.addEventListener(g_map.map,MAP_MOVING,map_Move=function(){ g_map.setDivTipPosition();});
        	 g_map.map.addEventListener(g_map.map,MAP_MOVE_END,map_move_end=function(){g_map.setDivTipPosition();});
		 g_map.map.addEventListener(g_map.map,ZOOM_CHANGED,map_zoom=function(){g_map.setDivTipPosition();});
	}
	this.setArea=function(pois){
		g_map.setArea(pois);
	}
	this.removePoi = function(poi,strict)
	{   
		if (poi==null||drawObjs.length == 0) return;
		if(strict==null)strict=true;
		for(var i = 0 ; i < drawPois.length; ++i)
		{
			if(drawPois[i]==null)continue;
			if((strict&&cmpObj(poi,drawPois[i])) || (strict==false && poi.x==drawObjs[i].x&&poi.y==drawObjs[i].y))
			{
				g_map.map.removeOverlay(drawObjs[i],true);
				delete drawPois[i];
				delete drawObjs[i];
			}
		}
	} 
	this.removePoint=function(id){
		g_map.remove(id);
		}
	this.removeAllPois= function()
	{
		if (drawObjs.length == 0) return;
		for(var i = 0 ; i < drawObjs.length; ++i){
			if(drawObjs[i])
				g_map.map.removeOverlay(drawObjs[i],true);
		}
		drawObjs = []; 
		drawPois = [];
	}
	this.removeAll=function()
	{
		g_map.removeAll();
		}
	/*this.moveToCenter=function(poi)
	{
		g_map.moveToCenter(poi.x,poi.y);
	}*/

   this.getXY= function(iconUrl,callBack,isCen,picAgent)
  {
	g_map.getXY('getPoint',iconUrl,callBack,isCen,picAgent);
}
	this.getCircleXY=function(callBack)
	{
		g_map.getCircleXY('getPoint',callBack);
	}
	this.getRectXY=function(callBack)
	{
		g_map.getRectXY('getPoint',callBack);
	}
	this.getFrameXY=function(callBack){
			g_map.getFrameXY('getPoint',callBack);
		}
	this.getCircleArea=function(cx,cy,r,callBack){
		g_map.addCircleArea('getPoint',cx,cy,r,callBack);
	}
	this.MCluster=function(grid,maxzoom){
		g_map.MCluster(grid,maxzoom);
	}
	this.setAnchor = function(w,h)
    {
		AnchorWidth=w;
		AnchorHeight=h;
	}
	

		this.setMouseTools = function(drawType)
	{
		g_map.setMouseTools(drawType);
	}
	
	this.getLngLatBounds=function(){
		return g_map.getLngLatBounds();
	}
	
	this.setMapTools=function(ctrlName,state){
		g_map.map.setCtrlPanelState(ctrlName,state);
	}
	this.setTipWidth=function(wid){
		if(document.getElementById("tip"))
		document.getElementById("tip").style.width=wid+"px";
	}
	this.fontStyle=function(name,size,color,bold){
		var style=g_map.fontStyle(name,size,color,bold);
		return style;
	}
	this.labelOption=function(fontStyle,hasBackground,hasBorder,backgroundColor,borderColor,zoomLevels,alpha){
		var labelOption=g_map.labelOption(fontStyle,hasBackground,hasBorder,backgroundColor,borderColor,zoomLevels,alpha)
		//var labelOption=g_map.MLabelOpt(content,fontStyle,hasBackground,hasBorder,backgroundColor,borderColor,alpha,zoomLevels);
		return labelOption;
	}
	this.lineStyle=function(thic,color,alpha){
     	   	linestyle = new MLineStyle();
        	linestyle.thickness = thic;
        	linestyle.color = color;
        	linestyle.alpha = alpha;
        	return linestyle;
    	}
    	this.addLine=function(id,points,linestyle,picUrl,speed){
            g_map.addLine(id,points,linestyle,picUrl,speed);
    	}
	
	this.printMap=function(){
		g_map.printMap();
	}

	this.addLabel = function(id,x,y,txt,bgColor,borderColor,fontStyle){
		 g_map.addLabel(id,x,y,txt,bgColor,borderColor,fontStyle);
	}
	this.addMarkLabel=function(id,content,fontstyle,x,y){
        	g_map.addMarkLabel(id,content,fontstyle,x,y);
    	}
	 this.removeMarkLabel=function(id){
		g_map.removeMarkLabel(id);
	}
	this.changeMark=function(overlay,icon,txt,fontstyle,x,y){
    	g_map._onMouseOver(overlay,icon,txt,fontstyle,x,y);
	}
	this.getCenter=function(){
		return g_map.getCenter();
	}
	this.moveToCenter=function(x,y){
		g_map.moveToCenter(x,y);
	}	
	this.moveToCity=function(code){
		g_map.moveToCity(code);
	}
	this.panTo=function(x,y){
		g_map.panTo(x,y);
	}
	this.addMenuItems=function(menu){
		g_map.addMenuItems(menu);
	}
	this.zoomTo = function(zoomLevel){
         g_map.zoomTo(zoomLevel);
    }

    this.zoomOut = function(x,y,bool){
        g_map.zoomOut(x,y,bool);
    }
    this.zoomIn = function (x,y,bool){
        g_map.zoomIn(x,y,bool)
    }
	this.centerAndZoom = function(cx,cy,level){
        g_map.centerAndZoom(cx,cy,level);
    }
	this.setZoomdisabled=function(isZoom){
		g_map.setZoomEnabled(isZoom);
	}
	this.setMaxZoomLevel=function(level){
		if(g_map.map.getZoomLevel()>level){g_map.zoomTo(level)}
	}
	this.addListener = function(obj,listener,hanler){
        g_map.addListener(obj,listener,hanler);
    }
    this.removeListener = function(listener,hanler){
        g_map.removeListener(this.map,listener,hanler);
    }
	function cmpObj(a,b)
	{
		for(var c in a)
		{
			if(a[c]!=b[c])return false;
		}
		return true;
	}
}
	
var roadend="";
function getTail(poi)
{
	var html = "";
	var list=poi.id.split("_");
	html+='<div class="sep"></div>';
html+='<ul id="ulsh" class="ulh"><li id="tip_tab_0"  onclick="showTail(\''+poi.id+'\',3,\'tip\');goTab(0,3,\'tip\')">到这里去</li>';
	html+='<li id="tip_tab_1" onclick="showTail(\''+poi.id+'\',3,\'tip\');goTab(1,3,\'tip\')">从这里出发</li>';
	html+='<li id="tip_tab_2" onclick="showTail(\''+poi.id+'\',3,\'tip\');goTab(2,3,\'tip\')">在附近找</li></ul>';
	html+='<div id="sh" style="display:none;position: relative;text-align:center;"><blockquote class="f14 lh23"><div id="tip_info_0">';
	html+='<span class="fl">出发:</span> <input id="tipbegin" type="text" class="text" />';
	html+='<div class="spacer"></div>';
	html+='<span class="fl">到达:</span> <span class="gray2">'+poi.name+'</span>';
	html+='<div class="spacer"></div><div align="center">';
	html+='<input type="button" class="btn" value="公 交" onclick="goIndex(2,\''+poi.city+',\'+document.getElementById(\'tipbegin\').value+\',,'+poi.name+','+poi.x+':'+poi.y+',\')"/>&emsp;';
	html+='<input type="button" class="btn" value="驾 车" onclick="goIndex(3,\''+poi.city+','+poi.city+',\'+document.getElementById(\'tipbegin\').value+\',,'+poi.name+','+poi.x+':'+poi.y+',\')" />';
	html+='</div></div>';
	html+='<div id="tip_info_1" style="display:none">';
	html+='<span class="fl">出发:</span> <span class="gray2">'+poi.name+'</span>';
	html+='<div class="spacer"></div>';
	html+='<span class="fl">到达:</span> <input id="tipend" type="text" class="text"/>';
	html+='<div class="spacer"></div>';
	html+='<div align="center">';
	html+='<input type="button" class="btn" value="公 交"  onclick="goIndex(2,\''+poi.city+','+poi.name+','+poi.x+':'+poi.y+',\'+document.getElementById(\'tipend\').value+\',\')"/>&emsp;';
	html+='<input type="button" class="btn" value="驾 车"  onclick="goIndex(3,\''+poi.city+','+poi.city+','+poi.name+','+poi.x+':'+poi.y+',\'+document.getElementById(\'tipend\').value+\',\')"/>';
	html+='</div></div>';
	html+='<div id="tip_info_2" style="display:none">';
	html+='<span class="flr">查找范围 </span><select id="s_'+poi.id+'"><option value="500" >500米</option><option value="1000" >1千米</option><option value="2000" selected="true">2千米</option><option value="5000" >5千米</option><option value="10000" >10千米</option></select>';
	html+='<div class="spacer"></div>';
	html+='<p class="flr"><a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:160100,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">银行</a> <a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:100100,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">宾馆</a> <a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:050000,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">饭店</a> <a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:060100,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">商场</a> <!--a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:060400,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">超市</a--> <a href="javascript:void(0);"  onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:70300,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')">售票处</a></p>';
	html+='<div class="spacer"></div>';
	html+='<p><span class="flr">其他：</span><input id="fkey" type="text" class="text1" /> <input type="button" value="搜 索" onclick="goIndex(1,\''+poi.city+',\'+document.getElementById(\'fkey\').value+\','+poi.name+','+poi.x+':'+poi.y+',,dr,\'+document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')"/></p>';
html+='</div></blockquote><div class="hideTotab" id="hideTotab"><ul><li onclick="hideTail(\''+poi.id+'\',3,\'tip\')"><img src="http://map.sina.com.cn/images/hide.gif"/></li><ul></div></div>';
	return html;
}

function showSearch(poi)
{
	html='<div class="changebox_tip_search_my" id="changebox_tip_search_my">'+
                '<ul>'+
                       	'<li id="tip_search_tab1" class="select" onclick="tabSelect(this);"><a href="#">以此为起点</a></li>'+
                        '<li id="tip_search_tab2" onclick="tabSelect(this);"><a href="#">以此为终点</a></li>'+
                        '<li id="tip_search_tab3" onclick="tabSelect(this);"><a href="#">在周边搜索</a></li>'+
                '</ul>'+
                '<div id="tip_search_tab1_div">'+
                        '输入终点:'+
                        '<input type="text" id="start_txt" class="inptxt"/>'+
                        '<input type="button" value="公交" class="inpbtn" onclick="goIndex(2,\''+poi.city+','+poi.name+','+poi.x+':'+poi.y+',\'+document.getElementById(\'start_txt\').value+\',\')"/>'+
                        '<input type="button" value="驾车" class="inpbtn" onclick="goIndex(3,\''+poi.city+','+poi.city+','+poi.name+','+poi.x+':'+poi.y+',\'+document.getElementById(\'start_txt\').value+\',\')"/>'+
                '</div>'+
                '<div id="tip_search_tab2_div" style="display:none">'+
                        '输入起点:'+
                        '<input type="text" id="end_txt" class="inptxt"/>'+
                        '<input type="button" value="公交" class="inpbtn" onclick="goIndex(2,\''+poi.city+',\'+document.getElementById(\'end_txt\').value+\',,'+poi.name+','+poi.x+':'+poi.y+',\')"/>'+
                        '<input type="button" value="驾车" class="inpbtn" onclick="goIndex(3,\''+poi.city+','+poi.city+',\'+document.getElementById(\'end_txt\').value+\',,'+poi.name+','+poi.x+':'+poi.y+',\')"/>'+
                '</div>'+
                '<div id="tip_search_tab3_div" style="display:none;">'+
                        '在附近找:'+
                        ' <input type="text" id="round_txt" class="inptxt min"/>'+
                        ' <input type="button" value="搜索" class="inpbtn" onclick=""goIndex(1,\''+poi.city+',\'+document.getElementById(\'round_txt\').value+\','+poi.name+','+poi.x+':'+poi.y+'document.getElementById(\'s_'+poi.id+'\').value+\',0,10\')"/>'+
                        ' <a href="javascript:void(0);" onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:050000,dr,2000,0,10\')">餐饮</a>'+
                        ' <a href="javascript:void(0);" onclick="goIndex(1,\''+poi.city+',\'+this.innerHTML+\','+poi.name+','+poi.x+':'+poi.y+',category:160100,dr,2000,0,10\')">银行</a>'+
               ' </div>'+
	'</div>';	
	return html;
}

function tabSelect(obj){
	var objs_id=new Array('tip_search_tab1','tip_search_tab2','tip_search_tab3');
	obj.className="select";
	document.getElementById(obj.id+"_div").style.display="block";
	for(var i=0;i<objs_id.length;i++){
		if(objs_id[i]!=obj.id){
			document.getElementById(objs_id[i]+"_div").style.display="none";
			document.getElementById(objs_id[i]).className="";
		}
	}
}

function showTail(poi_id,tab_num,pre){
	if(document.getElementById("sh").style.display=="none"){
		document.getElementById("sh").style.display="block";
		document.getElementById("ulsh").className="uls";
		for(var i=0;i<tab_num;i++){document.getElementById(pre+"_tab_"+i).className="tab_active";}
		g_map.setMapPan(poi_id);
		g_map.setDivTipPosition();
		roadend=document.getElementById("tipend");
	}
}
function hideTail(poi_id,tab_num,pre){
	if(document.getElementById("sh").style.display=="block"){
		document.getElementById("sh").style.display="none";
		document.getElementById("ulsh").className="ulh";
		for(var i=0;i<tab_num;i++){document.getElementById(pre+"_tab_"+i).className="";}
		g_map.setMapPan(poi_id);
		g_map.setDivTipPosition();
	}
}

function goTab(num,tab_num,pre){
	for(var i=0;i<tab_num;i++){document.getElementById(pre+"_info_"+i).style.display="none";}
	for(var i=0;i<tab_num;i++){document.getElementById(pre+"_tab_"+i).className="";}
	document.getElementById(pre+"_tab_"+num).className="tab_active";
	document.getElementById(pre+"_info_"+num).style.display="block";
	global_type=num;
	//if(citys[num]==global_city) return;
	/*switch(num*1)
	{	
		case 0:{
			//search
                        //Search();
			document.title="爱问地图搜索";
                        break;
		}
		case 2:
		{
			//bus
			document.title="公交查询--爱问地图搜素";
			//resetSearchBus();
			break;
		}
		case 3:
		{
			//navi	
			document.title="驾车查询--爱问地图搜索";
			//resetSearchRoute();
			break;
		}
		case 1:
		{
			//around
			document.title="周边查询--爱问地图搜索";
		//	resetSearchRound();
			break;
		}
		default:{
			alert(num);
		}
	}*/
}

function goIndex(index,pars){
        var url="http://map.sina.com.cn/#type="+index;
        url+="&pars="+pars;
        window.open(url,"_blank");
}
