//分类查询数据
var _origPois=new Array();//起点标点数组
var _destPois=new Array();//终点标点数组
var _odPois=new Array(2);//存放起点终点的标点
var _origIcon="sse/images/qd.gif";//起点图标
var _destIcon="sse/images/zd.gif";//终点图标
var _transfer="sse/images/shift.gif";//换乘图标
var _busStopIcon="sse/images/station.gif";//中间站点图标
var openImg ="sse/images/M_R_open011_icon.gif";//分类查询图标
var closeImg = "sse/images/M_R_coles011_icon.gif";//分类查询图标
var _smsContent="";//短信的内容
var _pringImage="sse/images/ico_print.gif";//打印图标
var _printContent="";//打印内容
var _drivePrintContent="";//驾车打印内容
var _driveSmsContent="";//驾车短信的内容
var _mailImage="sse/images/ico_mail.gif";//短信图标
var _allStation = new Array();//公交线路里所有的小站点
var _isBusLineShow=false;//是否已经显示线路内容
var _isBusLineShowIndex=0;//当前显示线路的下标值
var _searchType="";//起点终点查询类型（公交/驾车）
var _stopPoi="";//站点标点
var _routelatlon=null;//线经纬度数组
var _miniPoi=null;
var _over="";//画线数据
var _sms="http://searchbox.mapbar.com/channel/index.jsp";
var divFlag = 0;//分类查询下标
var driveStyle=0;//是否已经选择避开高速
var _smsDivShow="";//发送，地图工具层是否显示
var _poiKeywordList=new Array(3);//关键字查询历史记录
var _poiKeywordSList=new Array(3);//关键字查询历史记录截取串

//解析URL参数
function setUrlParam(){
	var params={};
	var href = decodeURIComponent(window.location.href);
	var pos= href.indexOf('#');
	if (pos<0){
		pos=href.indexOf('?');
	}
	if (pos>=0)
	{
		var ss = (href.indexOf("&amp;") >= 0) ? "&amp;" : "&";
		href = href.substring(pos+1).split(ss);
		for (var i=0;i<href.length;i++)
		{
			var pair = href[i].split('=');
			if (pair.length==2){
				try{
					params[pair[0]]=decodeURIComponent(pair[1]);
				}catch (e){
					params[pair[0]]=pair[1];
				}
			}
		}
	}
	var cityName=params["city"]||params["c"]||params["origCity"];

	if (!cityName || cityName==""){
		cityName=startcityname;
	}
	setSearchBoxCity(cityName);

	var pn=params['pn'];
	if(pn==null || pn==""){
		pn=1;
	}
	var maxMap=params['maxMap'];
	if(maxMap!=null && maxMap=="1"){
		show_switches();
	}
	var mapZoom=params['mapZoom'];
	if(mapZoom!=null && mapZoom>-1 && mapZoom<14){
		if(typeof maplet=="object"){
			maplet.setZoomLevel(mapZoom);
		}
	}

	if(params['action']=="lc" || params['ac']=="lc" ){
		show_class(1);
		show_keyword(params['keyword'],cityName,params['type'],pn);
	}else if(params['action']=="buslist" || params['ac']=="bsl" || params['ac']=="buslist" ){
		show_class(2);
		show_busOrigDest(cityName,params["origName"],params["origLatLon"],cityName,params["destName"],params["destLatLon"],"bus");
	}else if(params['ac']=="bsr" ){
		show_class(2);
		_searchType='bus';
		document.getElementById("busOrigName").value=params["origName"];
		document.getElementById("busDestName").value=params["destName"];
		show_driveOrigDest(params["origLatLon"],params["destLatLon"],params["origName"],params["destName"]);
	}else if(params['action']=="drivelist" || params['ac']=="nsl" || params['ac']=="drivelist"){
		show_class(3);
		show_busOrigDest(params["origCity"],params["origName"],params["origLatLon"],params["destCity"],params["destName"],params["destLatLon"],"drive");
	}else if(params['ac']=="nsr" ){
		show_class(3);
		_searchType='drive';
		document.getElementById("driveOrigName").value=params["origName"];
		document.getElementById("driveDestName").value=params["destName"];
		setSelectCity("driveOrigCity",params["origCity"]);
		setSelectCity("driveDestCity",params["destCity"]);
		show_driveOrigDest(params["origLatLon"],params["destLatLon"],params["origName"],params["destName"],params["origCity"],params["destCity"],"");
	}else if((params['range']!=null && params['range']!="") || params['ac']=="nb"){
		show_class(4);
		var ppid=params["pid"];
		if(ppid==null || ppid==""){
			ppid=params["name"];
		}
		show_nearSearch(params["strlatlon"],params["name"],ppid,params["poitype"],cityName,pn);
	}else if(params['buslinelist']=="bll"){
		show_class(2);
		show_form(2);
		document.getElementById("RadioGroup1_2").checked=true;
		document.getElementById("busLineKeyword").value=params['keyword'];
		show_busLine(params['keyword'],cityName);
	}else if(params['type']=="公交车站"){
		show_class(2);
		show_form(3);
		document.getElementById("RadioGroup1_3").checked=true;
		document.getElementById("busStopKeyword").value=params['keyword'];
		show_busStopSearch(params['keyword'],cityName,"1")
	}else{
		if(params['pageType']=="3"){
			show_class(4);
		}else if(params['pageType']=="2"){
			show_class(3);
		}else if(params['pageType']=="1"){
			show_class(2);
		}else if(params['pageType']=="0"){
			show_class(1);
		}else{
			show_class(1);
		}
	}
	if(params['errorpid']!=null && params['errorpid']!=""){
		window.open(contextPath+"/errorpid.jsp?errorpid="+params['errorpid']+"&city="+encodeURIComponent(params['errorcity']),'_blank');
	}
}

//头部菜单效果
function show_class(top){
	$("rsContainer").style.display="none";
	$('infoBox').style.display='';
	document.getElementById('rightTitle').innerHTML="请参看以下帮助信息";
	if(typeof maplet=="object"){
		maplet.clean();
		maplet.clearOverlays(true);
	}
	if(top!="5"){
		bpp[0]="http://img.mapbar.com/maplite/mapbank/base/";
		bpp[1] = 12;
		if(typeof maplet=="object"){
			maplet.refresh();
		}
	}else{
		document.getElementById("hreferrorid").href="http://www.mapbar.com/feedback/feedback.jsp?reffer="+encodeURIComponent("http://searchbox.mapbar.com/channel/index.jsp?pageType=4");
	}
	for(var i=1;i<6;i++){
		if(document.getElementById('link'+i)){
			document.getElementById('link'+i).className='';
			document.getElementById('tBox'+i).style.display='none';
			document.getElementById('infobox_contentMain'+i).style.display='none';
		}
	}
	document.getElementById('link'+top).className='topNavonclick';//点击以后链接样式
	document.getElementById('tBox'+top).style.display='block';//点击以后链接对应表单
	document.getElementById('infobox_contentMain'+top).style.display='block';//点击后链接对应右部信息
}
//头部菜单效果
function showSearchBoxDiv(top){
	if(typeof maplet=="object"){
		maplet.clean();
		maplet.clearOverlays(true);
	}
	if(top!="5"){
		bpp[0]="http://img.mapbar.com/maplite/mapbank/base/";
		bpp[1] = 12;
		if(typeof maplet=="object"){
			maplet.refresh();
		}
	}
	for(var i=1;i<6;i++){
		if(document.getElementById('link'+i)){
			document.getElementById('link'+i).className='';
			document.getElementById('tBox'+i).style.display='none';
			document.getElementById('infobox_contentMain'+i).style.display='none';
		}
	}
	document.getElementById('link'+top).className='topNavonclick';//点击以后链接样式
	document.getElementById('tBox'+top).style.display='block';//点击以后链接对应表单
	document.getElementById('infobox_contentMain'+top).style.display='block';//点击后链接对应右部信息
}

//公交查询表单切换效果
function show_form(top){
	for(i=0;i<4;i++){
		if(document.getElementById('radioBox'+i)){
			document.getElementById('radioBox'+i).style.display='none';
		}
	}
	document.getElementById('radioBox'+top).style.display='block';//点击以后链接对应表单
}

//显示驾车查询的城市下拉列表
var cityListRs = {
    initcityOption:function(defaultcity){
        for(var i=0;i<cityData.province.length;i++){
            document.writeln('<option value="">'+cityData.province[i].pname+'</option>\n');
            for(var j=0;j<cityData.province[i].city.length;j++){
				if(defaultcity==cityData.province[i].city[j].cityName){
					document.writeln('<option value='+cityData.province[i].city[j].cityName+' selected >&nbsp;├'+cityData.province[i].city[j].cityName+'</option>\n');
				}else{
					document.writeln('<option value='+cityData.province[i].city[j].cityName+' >&nbsp;├'+cityData.province[i].city[j].cityName+'</option>\n');
				}
            }
        }
    } 
}
//验证城市名称
function checkCity(id,cityName){
	if (cityName==null || cityName==""){
		var city=document.getElementById("cityName").value;
		setSelectCity(id,city);
		alert("请选择省份里的城市");
		return false;
	}
	if(id!="driveDestCity"){
		setSearchBoxCity(cityName,id);
	}
}
//设置select里的城市
function setSelectCity(id,city){
	var citySelect=document.getElementById(id);
	if(citySelect){
		for (var i=0;i<citySelect.length;i++){
			if(citySelect.options[i].value==city){
				citySelect.options[i].selected=true;
			}
		}
	}
}

//设置城市
function setSearchBoxCity(city,id){
	if(city!=null && city!="" && city.indexOf("<%")==-1){
		document.getElementById("keywordcity").innerHTML=city;
		document.getElementById("cityName").value=city;
		document.getElementById("indexcity").value=city;
		setSelectCity("driveOrigCity",city);
		setSelectCity("driveDestCity",city);
		if(typeof maplet=="object"){
			try{
				for(var i=0;i<cityData.province.length;i++){
					for(var j=0;j<cityData.province[i].city.length;j++){
						if(city==cityData.province[i].city[j].cityName){
							maplet.setCenter(cityData.province[i].city[j].citylatlon);
						}
					}
				}
			}catch(e){}
		}
	}
}

//根据城市名称返回英文城市名称
function getEnameCity(cityValue){
	var cv=decodeURIComponent(cityValue);
	for(var i=0;i<cityData.province.length;i++){
		for(var j=0;j<cityData.province[i].city.length;j++){
			if(cityData.province[i].city[j].cityName==cv){
				return cityData.province[i].city[j].esname;
			}
		}
	}
}

//判断是否显示滚动信息
function isShowMsg(){
	if(msgcid==""){
		return false;
	}else{
		var cidchar=msgcid.substring(0,1);
		if(cidchar.match(/[A-Za-z_]/)==null){
			msgcid="rootmapbarxml"+msgcid;
		}
	}
	try {
		if(userUrl==""){
			return false;
		}
		var isUsers="";
		var myAjax = new Ajax.Request(contextPath+"/client/showmsg/showMsgUsers.xml", 
			{ method: 'post', asynchronous:false,parameters:"", 
				onComplete: function(originalRequest) {
					if (window.ActiveXObject){
						var xmlDoc=originalRequest.responseXML;
						isUsers=xmlDoc.getElementsByTagName(msgcid)[0].childNodes[0].nodeValue;
					}else if (document.implementation && document.implementation.createDocument){
						originalRequest.Charset="utf-8"; 
						originalRequest.ContentType="text/xml";
						var xmlDoc=originalRequest.responseXML;
						var root = xmlDoc.documentElement;
						var CONTENTITEM=root.getElementsByTagName(msgcid)[0];
						isUsers = (CONTENTITEM.firstChild == null)?"":CONTENTITEM.firstChild.data;
					}
				}
			}
		);
		var userArray=isUsers.split(",");
		if(userArray!=null && userArray.length>0){
			for(var i=0;i<userArray.length;i++){
				if(userArray[i]!=null && userArray[i]!="" && userUrl.indexOf(userArray[i])!=-1){
					return true;
				}
			}
		}
		return false;	
	} catch (e) {
		return false;
	}
}
//获取配置文件里的滚动消息信息
function getMsgUrl(){
	footermsg="";
	try {
		var myAjax = new Ajax.Request(contextPath+"/client/showmsg/msgUrl.xml", 
			{ method: 'post', asynchronous:false,parameters:"", 
				onComplete: function(originalRequest) {
					if (window.ActiveXObject){
						var xmlDoc=originalRequest.responseXML;
						var values = xmlDoc.documentElement.childNodes;
						if(values!=null){
							for(var i=0;i<values.length;i++){
								if(values[i].tagName!=null && values[i].tagName=="msg"){
									if(values[i].childNodes[0].text!=null && values[i].childNodes[1].text!=null){
										aArray[i]="<a href='"+values[i].childNodes[0].text+"' onmouseover='setshowmsg(1);' onmouseout='setshowmsg(0);' target='_blank'>"+values[i].childNodes[1].text+"</a>";
									}
								}else if(values[i].tagName!=null && values[i].tagName=="footermsg"){
									footermsg+="<a href='"+values[i].childNodes[0].text+"' target='_blank'>"+values[i].childNodes[1].text+"</a> ";
								}
							}
						}
					}else if (document.implementation && document.implementation.createDocument){
						originalRequest.Charset="utf-8"; 
						originalRequest.ContentType="text/xml";
						var xmlDoc=originalRequest.responseXML;
						var root=xmlDoc.documentElement.getElementsByTagName('msg');
						if(root!=null){
							for(var i=0;i<root.length;i++){
								var CONTENTITEM=root[i].getElementsByTagName('url')[0];
								var cc = (CONTENTITEM.firstChild == null)?"":CONTENTITEM.firstChild.data;
								CONTENTITEM=root[i].getElementsByTagName('msgname')[0];
								var ll = (CONTENTITEM.firstChild == null)?"":CONTENTITEM.firstChild.data;
								if(cc!=null && ll!=null)
									aArray[i]="<a href='"+cc+"' onmouseover='setshowmsg(1);' onmouseout='setshowmsg(0);' target='_blank'>"+ll+"</a>";
							}
						}
						root=xmlDoc.documentElement.getElementsByTagName('footermsg');
						if(root!=null){
							for(var i=0;i<root.length;i++){
								var CONTENTITEM=root[i].getElementsByTagName('url')[0];
								var cc = (CONTENTITEM.firstChild == null)?"":CONTENTITEM.firstChild.data;
								CONTENTITEM=root[i].getElementsByTagName('msgname')[0];
								var ll = (CONTENTITEM.firstChild == null)?"":CONTENTITEM.firstChild.data;
								if(cc!=null && ll!=null)
									footermsg+="<a href='"+cc+"' target='_blank'>"+ll+"</a> ";
							}
						}

					}
				}
			}
		);
	} catch (e) {
		//alert(e.message);
	}
}
//显示地图上的滚动信息
function showTimeMsg(){
	if(showmsg=="0"){
		document.getElementById("msgid").innerHTML=aArray[msgNum];
		msgNum+=1;
		if(msgNum==aArray.length) msgNum=0;
	}
	setTimeout(showTimeMsg,2000);
}
//设置信息是否滚动
function setshowmsg(val){
	showmsg=val;
}
//地图全屏切换按钮效果
function show_switches(){
	if(document.getElementById('rightPanel').style.display=='none'){
		document.getElementById('rightPanel').style.display='block'
		document.getElementById('rightPanel').style.right='6px'
		document.getElementById('leftPanel').style.marginRight='329px';
		document.getElementById('switches').style.right='319px';
		document.getElementById('switches').style.background='url(images/main_Marrow.gif) no-repeat 50%';
	}else{
		document.getElementById('rightPanel').style.display='none'
		document.getElementById('leftPanel').style.marginRight='19px';
		document.getElementById('switches').style.right='6px';
		document.getElementById('switches').style.background='url(images/main_Marrow2.gif) no-repeat 50%';
	}
	resizeAll();
}
//重新设置页面元素大小
function resizeAll(){
	//获得页面大小和窗口大小
	var mySize=getPageSize();
	var width=0;
	var height = (mySize[3]-document.getElementById("searchTitle").clientHeight-119);
	if(showfootermsg=="f"){
		height=height/1+22;
	}
	var ib=navigator.userAgent;
	if(ib.indexOf("Opera")!=-1 || ib.indexOf("Firefox")!=-1 ){
		height=height+65;
	}
	var infoBox=document.getElementById("infoBox");
	infoBox.style.height=height-22+"px";

	var rsContainer=document.getElementById("rsContainer");
	rsContainer.style.height=height-22+"px";


	var leftPanel=document.getElementById("leftPanel");
	leftPanel.style.height=height+"px";

	var switches=document.getElementById("switches");
	switches.style.height=height+"px";

	var rightPanel=document.getElementById("rightPanel");
	rightPanel.style.height=height+"px";
	
	/*var MTS_result=document.getElementById("MTS_result");
	MTS_result.style.height=height-56+"px";*/

	var mapbarMap =document.getElementById("mapbar");
	mapbarMap.style.width=document.getElementById("leftPanelTitle").clientWidth+"px";
	if(showfootermsg=="f"){
		mapbarMap.style.height=height-22+"px";
	}else{
		mapbarMap.style.height=height-44+"px";
	}
	document.getElementById("sendDivId").style.left=document.getElementById("leftPanelTitle").clientWidth-222+"px";
	document.getElementById("toolsDivId").style.left=document.getElementById("leftPanelTitle").clientWidth-102+"px";
	if(typeof maplet=="object"){
		var mw=mapbarMap.style.width;
		if(mw.indexOf("px")!=-1){
			mw=mw.substring(0,mw.length-2);
		}
		var mh=mapbarMap.style.height;
		if(mh.indexOf("px")!=-1){
			mh=mh.substring(0,mh.length-2);
		}
		maplet.resize(mw,mh);
	}

}
//获得页面大小
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { 
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

//关键字查询
function show_keyword(keyword,city,type,pn){
	if(keyword==null || keyword.trim()==""){
		alert("搜索条件不能为空");
		return;
	}
	if(city==null || city==""){
		alert("城市名称不能为空");
		return;
	}
	if(type==null){
		type="";
	}
	document.getElementById("keywordvalue").value=keyword;
	document.getElementById("keywordType").value=type;
	var width="";
	var height="";
	if(typeof maplet=="object"){
		width=maplet.width;
		height=maplet.height;
	}else{
		alert("没有找到地图无法显示查询结果！");
		return;
	}
	
	if(pn==null || pn==""){
		pn=1;
	}
	if(_poiKeywordList[0]==null || _poiKeywordList[0]==""){
		_poiKeywordList[0]=keyword;
		if(strlen(keyword)>12){
			_poiKeywordSList[0]=subPoiStr(keyword)+"...";
		}else{
			_poiKeywordSList[0]=keyword;
		}
		
	}else if(_poiKeywordList[1]==null || _poiKeywordList[1]==""){
		if(_poiKeywordList[0]!=keyword){
			_poiKeywordList[1]=keyword;
			if(strlen(keyword)>12){
				_poiKeywordSList[1]=subPoiStr(keyword)+"...";
			}else{
				_poiKeywordSList[1]=keyword;
			}
		}
	}else if(_poiKeywordList[2]==null || _poiKeywordList[2]==""){
		if(_poiKeywordList[0]==keyword){
			_poiKeywordList[0]=_poiKeywordList[1];
			_poiKeywordSList[0]=_poiKeywordSList[1];
			_poiKeywordList[1]=keyword;
			if(strlen(keyword)>12){
				_poiKeywordSList[1]=subPoiStr(keyword)+"...";
			}else{
				_poiKeywordSList[1]=keyword;
			}
		}else if(_poiKeywordList[1]!=keyword){
			_poiKeywordList[2]=keyword;
			if(strlen(keyword)>12){
				_poiKeywordSList[2]=subPoiStr(keyword)+"...";
			}else{
				_poiKeywordSList[2]=keyword;
			}
		}
	}else{
		if(_poiKeywordList[1]==keyword){
			_poiKeywordList[1]=_poiKeywordList[2];
			_poiKeywordSList[1]=_poiKeywordSList[2];
			_poiKeywordList[2]=keyword;
			if(strlen(keyword)>12){
				_poiKeywordSList[2]=subPoiStr(keyword)+"...";
			}else{
				_poiKeywordSList[2]=keyword;
			}
		}else if(_poiKeywordList[2]!=keyword){
			_poiKeywordList[0]=_poiKeywordList[1];
			_poiKeywordSList[0]=_poiKeywordSList[1];
			_poiKeywordList[1]=_poiKeywordList[2];
			_poiKeywordSList[1]=_poiKeywordSList[2];
			_poiKeywordList[2]=keyword;
			if(strlen(keyword)>12){
				_poiKeywordSList[2]=subPoiStr(keyword)+"...";
			}else{
				_poiKeywordSList[2]=keyword;
			}
		}
	}
	
	map.clear();
	sethash("ac=lc&keyword="+keyword+"&city="+city+"&width="+width+"&height="+height+"&type="+type+"&nlimit=11&pn="+pn+"&rn=10",false,"templLocalSearch1");
}
//关键字分页查询
function pagerCallback(nextPage, pageSize, totalCount, totalPage)
{

	if(nextPage > 10)
		nextPage = 10;
    map.clear();
	var keyword=document.getElementById('keywordvalue').value;
	var city=document.getElementById("cityName").value;
	var type=document.getElementById("keywordType").value;
    show_keyword(keyword,city,type,nextPage);
}

//起点终点查询
function show_busOrigDest(origCity,origName,origLatLon,destCity,destName,destLatLon,searchType){
	if(origCity==null) origCity="";
	if(origName==null) origName="";
	if(origLatLon==null) origLatLon="";
	if(destCity==null) destCity="";
	if(destName==null) destName="";
	if(destLatLon==null) destLatLon="";
	if(searchType==null) searchType="";
	if(origName.trim()=="" && origLatLon.trim()==""){
		alert("起点不能为空！");
		return false;
	}
	if(destName.trim()=="" && destLatLon.trim()==""){
		alert("终点不能为空！");
		return false;
	}
	_searchType=searchType;
	map.clear();
	var action="";
	if(searchType=="bus"){
		document.getElementById("busOrigName").value=origName;
		document.getElementById("busDestName").value=destName;
		action="buslist";
	}else if(searchType=="drive"){
		document.getElementById("driveOrigName").value=origName;
		document.getElementById("driveDestName").value=destName;
		action="drivelist";
	}
	sethash("origCity="+origCity+"&origName="+origName+"&origLatLon="+origLatLon+"&destCity="+destCity+"&destName="+destName+"&destLatLon="+destLatLon+"&ac="+action+"&type="+searchType);
}

//公交或驾车查询
function show_driveOrigDest(origLatLon,destLatLon,origName,destName,origCity,destCity,style){
	if(origLatLon==null) origLatLon="";
	if(destLatLon==null) destLatLon="";
	if(origName==null) origName="";
	if(destName==null) destName="";

	if((origName.trim()=="" && origLatLon.trim()=="") || origName=="没有找到结果!"){
		alert("起点不能为空！");
		return false;
	}
	if((destName.trim()=="" && destLatLon.trim()=="") || destName=="没有找到结果!"){
		alert("终点不能为空！");
		return false;
	}
	if(origName.trim()==destName.trim()){
		alert("请选择不同的起点终点！");
		return false;
	}
	if(origLatLon==null || origLatLon=="" || origLatLon=="undefined"){
		alert("起点经纬度不能为空，请重新选择起点！");
		return false;
	}else if(destLatLon==null || destLatLon=="" || destLatLon=="undefined"){
		alert("终点经纬度不能为空，请重新选择终点！");
		return false;
	}
	if(_searchType=='bus'){
		show_busSearch(origLatLon,destLatLon,origName,destName);
	}else if(_searchType=='drive'){
		if(origCity==null || origCity==""){
			origCity=document.getElementById("driveOrigCity").value;
		}
		if(destCity==null || destCity==""){
			destCity=document.getElementById("driveDestCity").value;
		}
		var orig="";
		var dest="";
		if(style=="1") {
			driveStyle=1;
		}else{
			style="";
			driveStyle=0;
		}
		var mid="";
		var width="";
		var height="";
		if(typeof maplet=="object"){
			width=maplet.width;
			height=maplet.height;
		}else{
			alert("没有找到地图无法显示查询结果！");
			return;
		}
		map.clear();
		sethash("ac=nsr&style="+style+"&origCity="+origCity+"&orig="+orig+"&origName="+origName+"&origLatLon="+origLatLon+"&destCity="+destCity+"&dest="+dest+"&destName="+destName+"&destLatLon="+destLatLon+"&mid="+mid+"&width="+width+"&height="+height+"&encode=UTF-8");
	}
}

//公交查询结果
function show_busSearch(origLatLon,destLatLon,origName,destName,city){
	if(origLatLon==null) origLatLon="";
	if(destLatLon==null) destLatLon="";
	if(origName==null) origName="";
	if(destName==null) destName="";
	if(city==null || city==""){
		city=document.getElementById("indexcity").value;
	}

	var width="";
	var height="";
	if(typeof maplet=="object"){
		width=maplet.width;
		height=maplet.height;
	}else{
		alert("没有找到地图无法显示查询结果！");
		return;
	}
	map.clear();
	sethash("ac=bsr&origLatLon="+origLatLon+"&origName="+origName+"&destLatLon="+destLatLon+"&destName="+destName+"&width="+width+"&height="+height+"&city="+city+"&encode=utf-8");
}

//公交线路查询
function show_busLine(keyword,city){
	if(keyword==null || keyword.trim()==""){
		alert("搜索条件不能为空");
		document.getElementById("busLineKeyword").focus();
		return;
	}
	if(city==null || city==""){
		city=document.getElementById("indexcity").value;
	}
	map.clear();
	_isBusLineShow=false;
	sethash("keyword="+keyword+"&city="+city+"&buslinelist=bll");
}

//按公交线路查询线路信息
function searchLine(keyword,city,index)
{
	if(keyword==null) keyword="";
	for(var i=0;i<routeNamesByKey.routes.item.length;i++){
		document.getElementById('icon'+index).src="sse/images/plusIcon.gif";
		document.getElementById('lineDetail'+i).style.display="none";
		document.getElementById('lineDetail'+i).innerHTML = "";
	}
	if(_isBusLineShow && _isBusLineShowIndex==index){
		_isBusLineShow=false;
		return;
	}else{
		_isBusLineShow=true;
		_isBusLineShowIndex=index;
	}
	var width="";
	var height="";
	if(typeof maplet=="object"){
		width=maplet.width;
		height=maplet.height;
	}else{
		alert("没有找到地图无法显示查询结果！");
		return;
	}
	//查询公交线路,只能返回线路名称
	sethashLine("keyword="+keyword+"&city="+city+"&width="+width+"&height="+height+"&buslineinfo=");
}

//公交站点查询
function show_busStopSearch(keyword,city,pn){
	if(keyword==null || keyword.trim()==""){
		alert("搜索条件不能为空");
		return;
	}
	if(city==null || city==""){
		alert("城市名称不能为空");
		return;
	}
	if(pn==null || pn==""){
		pn=1;
	}
	document.getElementById('busStopKeywordValue').value=keyword;
	map.clear();
	sethash("keyword="+keyword+"&city="+city+"&type=公交车站&pn="+pn+"&rn=10");
}
//公交站点分页查询
function busStopPagerCallback(nextPage, pageSize, totalCount, totalPage)
{
	if(nextPage > 10)
		nextPage = 10;
    map.clear();
	var keyword=document.getElementById('busStopKeywordValue').value;
	var city=document.getElementById("indexcity").value;
    show_busStopSearch(keyword,city,nextPage);
}

//周边查询
function show_nearSearch(strlatlon,name,pid,poitype,city,pn){
	if(strlatlon==null) strlatlon="";
	if(name==null) name="";
	if(pid==null) pid="";
	if(poitype==null) poitype="";
	if((strlatlon.trim()!="" || name.trim()!="" || pid.trim()!="") && poitype.trim()!=""){
	}else{
		alert("查询内容不能为空！");
		return false;
	}
	document.getElementById("nearStrlatlonValue").value=strlatlon;
	document.getElementById("nearNameValue").value=name;
	document.getElementById("nearPidValue").value=pid;
	document.getElementById("nearPoitypeValue").value=poitype;
	var width="";
	var height="";
	if(typeof maplet=="object"){
		width=maplet.width;
		height=maplet.height;
	}else{
		alert("没有找到地图无法显示查询结果！");
		return;
	}
	if(pn==null || pn==""){
		pn=1;
	}
	map.clear();
	sethash("nlimit=&strlatlon="+strlatlon+"&name="+name+"&pid="+pid+"&city="+city+"&poitype="+poitype+"&keytype=&range=1000&width="+width+"&height="+height+"&pn="+pn);
}
//周边分页查询
function nearPagerCallback(nextPage, pageSize, totalCount, totalPage)
{
	if(nextPage > 10)
		nextPage = 10;
    map.clear();
	var strlatlon=document.getElementById('nearStrlatlonValue').value;
	var name=document.getElementById("nearNameValue").value;
	var pid=document.getElementById("nearPidValue").value;
	var poitype=document.getElementById("nearPoitypeValue").value;
	var city=document.getElementById("indexcity").value;
    show_nearSearch(strlatlon,name,pid,poitype,city,nextPage);
}

//组件平台查询
function sethash(hash,isChangeLocation,extData)
{
	document.getElementById("hreferrorid").href="http://www.mapbar.com/feedback/feedback.jsp?reffer="+encodeURIComponent("http://searchbox.mapbar.com/channel/index.jsp?"+encodeURIComponent(hash));
	_sms="http://searchbox.mapbar.com/channel/index.jsp?"+encodeURIComponent(hash);

	document.getElementById('infoBox').style.display="none";
	document.getElementById('rightTitle').innerHTML="搜索结果";
	document.getElementById("rsContainer").style.display="";
	document.getElementById("rsContainer").innerHTML="&nbsp;&nbsp;&nbsp;数据加载中......";
	if(typeof isChangeLocation!="boolean") isChangeLocation = false;
	if(maplet) maplet.clearCache();
	mapbox.Manager.urlHashListener.setHash(new mapbox.UrlHash(hash),isChangeLocation,extData);
}

//组件平台查询
function sethashLine(hash,isChangeLocation,extData)
{
	if(typeof isChangeLocation!="boolean") isChangeLocation = false;
	mapbox.Manager.urlHashListener.setHash(new mapbox.UrlHash(hash),isChangeLocation,extData);
}

//创建一个标点数组
function drawMap(){
	if(maplet==null){
		return;
	}
	//清除在地图上画点
	maplet.clean();
	maplet.clearOverlays(true);
	if(station.kvps[0].item.length>0 && station.kvps[0].item[0].strlatlon!=null && station.kvps[0].item[0].strlatlon!="" && station.kvps[0].item[0].strlatlon!="undefined") busodpoi(0,1);
	if(station.kvps[1].item.length>0 && station.kvps[1].item[0].strlatlon!=null && station.kvps[1].item[0].strlatlon!="" && station.kvps[1].item[0].strlatlon!="undefined") busodpoi(0,2);
	
	maplet.setZoomLevel(8);
}

//显示公交起点终点图标
function busodpoi(pindex,pii){
	if(maplet==null){
		return;
	}
	if(pii==1){
		if(station.kvps[0].item[pindex]){
			if(station.kvps[0].item[pindex].strlatlon!=null && station.kvps[0].item[pindex].strlatlon!="" && station.kvps[0].item[pindex].strlatlon!="undefined"){
				maplet.removeOverlay(_odPois[0]);
				var point = new MPoint(station.kvps[0].item[pindex].strlatlon);
				var icon = new MIcon(_origIcon,19,22);
				var Mlable = new MLabel(station.kvps[0].item[pindex].name,16,-14);
				_odPois[0]=new MMarker(point,icon,null,Mlable);
				maplet.addOverlay(_odPois[0]);
				maplet.centerAndZoom(new MPoint(station.kvps[0].item[pindex].strlatlon),11);
			}else{
				alert("起点经纬度为空，请重新选择起点！");
				return false;
			}
		}else{
			return;
		}
	}else if(pii==2){
		if(station.kvps[1].item[pindex]){
			if(station.kvps[1].item[pindex].strlatlon!=null && station.kvps[1].item[pindex].strlatlon!="" && station.kvps[1].item[pindex].strlatlon!="undefined"){
				maplet.removeOverlay(_odPois[1]);
				var point = new MPoint(station.kvps[1].item[pindex].strlatlon);
				var icon = new MIcon(_destIcon,19,22);
				var Mlable = new MLabel(station.kvps[1].item[pindex].name,16,-14);
				_odPois[1]=new MMarker(point,icon,null,Mlable);
				maplet.addOverlay(_odPois[1]);
				maplet.centerAndZoom(new MPoint(station.kvps[1].item[pindex].strlatlon),11);
			}else{
				alert("终点经纬度为空，请重新选择终点！");
				return false;
			}
		}else{
			return;
		}
	}
}
//公交查询组件显示完模版后调用这个方法显示查询内容
function testShowBusResult(){
	showbusResult(0);
}

//显示公交查询画线及内容
function showbusResult(index){
	maplet.clean();
	maplet.clearOverlays(true);
	maplet.centerAndZoom(busResult.bus.item[index].routecenter,busResult.bus.item[index].routezoom-1);
			
	addPoint(_origIcon,busResult.orig.strlatlon,busResult.orig.name,'',true);
	addPoint(_destIcon,busResult.dest.strlatlon,busResult.dest.name,'',true);

	var routelatlons = busResult.bus.item[index].routelatlons;
	for(i=0;i<routelatlons.length;i++){
		var routelatlon = new Array(routelatlons[i].length);
		for(var j=0;j<routelatlons[i].length;j++){
			routelatlon[j] = new MPoint(routelatlons[i][j]);
		}
		addLine(routelatlon,'#FF0000',5);
	}

	var walkroutes = busResult.bus.item[index].walkroutes;
	for(i=0;i<walkroutes.length;i++){
		var walklatlon = new Array(walkroutes[i].length);
		for(j=0;j<walkroutes[i].length;j++){
			walklatlon[j] = new MPoint(walkroutes[i][j]);
		}
		addLine(walklatlon,'#FF99FF',5);
	}
	//显示下标是index的这条记录内容
	showRouteDiv(index);
}

//显示公交查询线路里的站点内容
function showRouteDiv(index){
	var str=setBusDetial(index);
	for(i=0;i<busResult.bus.item.length;i++){
		if(i == index){
			$('detail'+i).innerHTML = str;
		}else{
			$('detail'+i).innerHTML = '';
		}
	}
}

//显示公交查询内容
function setBusDetial(index){
	var route = busResult.bus.item[index].stations;
	var str = "";
	var strcon="";
	var busstr="";
	str="<p><strong>全程约"+busResult.bus.item[index].distance+"公里</strong></p>";
	for(var j=0;j<route.length;j++){
		if(j==0){
			str += "<p><img src='"+_origIcon+"'>";
		}else{
			str += "<p><img src='"+_transfer+"'>";
		}
		if(j==0){
			var param=new Array();
			param[0]=route[j].pois[0][1];
			param[1]=busResult.bus.item[index].routelatlons;
			str += "<a href='javascript:;' onclick='showMiniMap(\""+param+"\");'>"+route[j].pois[0][0]+"</a>";
			strcon+="<p>在 <font color=#0606ff >"+route[j].pois[0][0]+"</font>";
			busstr+="在"+checkBusString(route[j].pois[0][0]);
		}
		str=str+(j==0?" ":" 换")+"乘 <a href='javascript:;' title='显示该线路途径站点' onclick='addPoiByStation(\""+route[j].pois+"\");' >"+route[j].name+"</a>";
		strcon+=(j==0?" ":" 换")+"乘 <font color=#0606ff>"+route[j].name+"</font></p>";
		busstr+=","+(j==0?"":"换")+"乘"+checkBusString(route[j].name);
		var poi=route[j].pois[route[j].pois.length-1];
		if(j!=route.length-1){
			var param=new Array();
			param[0]=poi[1];
			param[1]=busResult.bus.item[index].routelatlons;
			addPoint(_transfer,poi[1],poi[0],'',true);
			str+=" 在 <a href='javascript:;' onclick='showMiniMap(\""+param+"\");'>"+poi[0]+"</a> 下车</p>";
		}else{
			var param=new Array();
			param[0]=poi[1];
			param[1]=busResult.bus.item[index].routelatlons;
			str+='</p><p><img src="'+_destIcon+'">';
			str+="在 <a href='javascript:;' onclick='showMiniMap(\""+param+"\");'>"+poi[0]+"</a> 下车</p>";
		}
		strcon+="<p> 在 <font color=#0606ff >"+busResult.bus.item[index].stations[j].pois[busResult.bus.item[index].stations[j].pois.length-1][0];
		strcon+="</font> 下车 途径 <font color=#0606ff >"+busResult.bus.item[index].stations[j].pois.length+"</font> 站</p>";

		busstr+="在"+checkBusString(busResult.bus.item[index].stations[j].pois[busResult.bus.item[index].stations[j].pois.length-1][0])+"下车";
	}
	_smsContent=busstr;
	var	title1="<p><font color=#ff0000 >"+strcon+"</font></p>";
	_printContent=title1;
	str+="<p class='cx004'><img src='"+_pringImage+"'>";
	str+="<a href='javascript:;' onclick='setPrintContent(\""+index+"\");return false;'>打印</a>";
	str+="<img src='"+_mailImage+"'>";
	str+="<a href='javascript:;' onclick='SMSContent();return false;'>发送短信</a></p>";
	return str;
}
function getBusName(title){
	var busname=title.substring(0,title.length-3);
	busname=busname.replace(new RegExp("\\(.{1,10}-.{1,10}\\)","gm"),"");
	return busname;
}

//线路查询后调用这个方法显示查询内容
function testShowBusLineResult(){
	showBusLineRoute(_isBusLineShowIndex);
}
//显示选中的公交线路
function showBusLineRoute(index){
	maplet.clearOverlays(true);
	maplet.centerAndZoom(routeByName.mapinfo.center,routeByName.mapinfo.scale);
	var routes=routeByName.route.stations.items;
	addPoint(_origIcon, routes[0].stationlatlon, routes[0].name,'',true);
	addPoint(_destIcon, routes[routes.length-1].stationlatlon, routes[routes.length-1].name,'',true);

	var strduo=routeByName.route.line[0].linelatlon;
	if(strduo.substring(strduo.length-1,strduo.length)==","){
		strduo=strduo.substring(0,strduo.length-1);
	}
	var sublines=strduo.split(',');

	var routelatlon=new Array(sublines.length);
	for(var i=0;i<sublines.length;i++){
		routelatlon[i] = new MPoint(sublines[i]);
	}
	addLine(routelatlon,'#FF0000',5);
	showBusLineDetial(index);
}

//显示线路内容
function showBusLineDetial(index){
	var route=routeByName.route.stations.items;
	var infomation=routeByName.route.infomation;
	var str = "<p>";
	if(infomation!=null || infomation!=''){
		str+=routeByName.route.infomation;
	}
	str+="</p><div class='station'>";
	for(var i=0;i<route.length;i++){
		str = str+ "<a href='javascript:;' onClick='addStopPoi(\""+route[i].stationlatlon+"\",\""+route[i].name+"\");'><em>"+(i+1)+"</em>"+route[i].name.substring(0,6)+"</a>" ;
	}
	str+="<div class='clearHide'></div></div>";
	$('icon'+index).src="sse/images/minusIcon.gif";
	$('lineDetail'+index).style.display="";
	$('lineDetail'+index).innerHTML = str;
}

//驾车查询后调用这个方法显示查询内容
function testShowDriveResult(){
	showRoute();
	setCarPrintSms();
}

//显示驾车线路
function showRoute(){
	maplet.clearOverlays(true);
	maplet.centerAndZoom(drive.mapinfo.center,drive.mapinfo.scale);
	addPoint(_origIcon,drive.orig.strlatlon,drive.orig.name,'',true);
	addPoint(_destIcon,drive.dest.strlatlon,drive.dest.name,'',true);
	var latlon = drive.routelatlon.split(',');
	_routelatlon = new Array(latlon.length);
	for(var i=0;i<latlon.length;i++){
		_routelatlon[i] = new MPoint(latlon[i]);
	}
	addLine(_routelatlon,'#FF0000',5);
	_over= maplet.getCurrentMap().substring(maplet.getCurrentMap().indexOf('overlays'));
	
};

//获取驾车打印和短信内容
function setCarPrintSms(){
	var carResultStr="";
	var result=drive.routes.item;
	_driveSmsContent="";
	if (result.length>0){
		carResultStr="<dl>";
		for(var i=0;i<result.length;i++){
			if(i%2==0){
				carResultStr+="<dt>";
			}else{
				carResultStr+="<dt style='background-color:#F5F5F5;'>";
			}
			carResultStr+=result[i].id+".&nbsp;"+result[i].strguide+"</dt>";
			_driveSmsContent+=result[i].strguide;
		}
		carResultStr+="</dl>";
		_drivePrintContent=carResultStr;
	}
}

//切换气泡内容中功能导航显示
function showTipPanel(panelId)
{
	$("tipdiv").style.display = "none";
	$("tipneardiv").style.display = "none";
	$("tiptoDiv").style.display = "none";
	$("tipfromDiv").style.display = "none";
		
	$(panelId).style.display = "block";
}

//添加站点
function addStopPoi(latlon,name){
	if(_stopPoi!=null && _stopPoi!=""){
		maplet.removeOverlay(_stopPoi);
	}
	var Mlable = new MLabel(name,16,-14);
	var point = new MPoint(latlon);
	var icon = new MIcon(_busStopIcon,20,20);
	var infoWindow = new MInfoWindow(name,'');
	var marker = new MMarker(point,icon,infoWindow,Mlable);
	_stopPoi=marker;
	maplet.addOverlay(marker);
}

//添加标点
function addPoint(icon,latlon,name,detail,isshow){
	var point = new MPoint(latlon);
	var icon = new MIcon(icon,20,20);
	if(isshow){
		var Mlable = new MLabel(name,16,-14);
		var marker = new MMarker(point,icon,null,Mlable);
		maplet.addOverlay(marker);
	}else{
		var marker = new MMarker(point,icon,infoWindow);
		maplet.addOverlay(marker);
	}
}

//向地图上添线
function addLine(latlon,color,weight){
	//var infoWindow = new MInfoWindow(null,null);
	var polyline = new MPolyline(latlon,new MBrush(color,weight),"");
	maplet.addOverlay(polyline);
}

//气泡
function showMiniMap(param){
	removeAllStations();
	var index=param.indexOf(',');
	var strlatlon=param.substring(0,index);
	var linelatlon=param.substring(index);
		
	//STD_TIP_HEIGHT=0;
	//MIN_BUBBLE_HEIGHT=130;
	miniPoiLatLon=strlatlon;
	miniLineLatLon=linelatlon;
	maplet.setCenter(new MPoint(strlatlon));
	hideMiniPoi();
	var point=new MPoint(strlatlon);
	var icon=new MIcon(contextPath+"/js/mapbar/images/miniMap.gif",1,1);
	var lable=null;
	var poiiframe="<div style='height:110px;width:200px;'><iframe id='minimapFrame' scrolling=no width=195 height=105 frameborder=0 src='js/mapbar/poimaplet.htm'></iframe></div>";
	var infoWindow=new MInfoWindow('缩略图',poiiframe);

	_miniPoi=new MMarker(point,icon,infoWindow,lable);
	maplet.addOverlay(_miniPoi);
	openMiniMapInfo();
}

//气泡
function showDriveMiniMap(param){
	maplet.clearOverlays(true);
	addLine(_routelatlon,'#FF0000',4);
	var strlatlon=param['strlatlon'];
	var strguide=param['strguide'];
	var i=param['id']-1;
	var j=parseInt(i)+1;
    var v1=drive.routes.item[i].turnlatlon;
    var v2=i==drive.routes.item.length-1?"":drive.routes.item[j].turnlatlon;
    var end=0;
    if(v2==""){
		end=drive.routelatlon.length
	}else{
        end=drive.routelatlon.indexOf(v2)+v2.length ;
    }
	var linelatlon=drive.routelatlon.substring(drive.routelatlon.indexOf(v1),end).split(',');
	var latlon = new Array(linelatlon.length);
	for(var i=0;i<linelatlon.length;i++){
		latlon[i] = new MPoint(linelatlon[i]);
	}
	addLine(latlon,'#00bb00',5);
		
	maplet.setCenter(new MPoint(strlatlon));
	if(_miniPoi!=null){
		try{
			maplet.removeOverlay(_miniPoi);
		}catch(e){}
	}
	addPoint(_origIcon,drive.orig.strlatlon,drive.orig.name,'',true);
	addPoint(_destIcon,drive.dest.strlatlon,drive.dest.name,'',true);

	var point=new MPoint(strlatlon);
	var icon=new MIcon(contextPath+"/js/mapbar/images/miniMap.gif",1,1);
	var infoWindow=new MInfoWindow("",strguide);
	_miniPoi=new MMarker(point,icon,infoWindow);
	maplet.addOverlay(_miniPoi);
	_miniPoi.openInfoWindow();
}


//气泡
function openMiniMapInfo(){
	_miniPoi.openInfoWindow();
	try{
		document.getElementById("minimapFrame").src=contextPath+"/js/mapbar/poimaplet.htm";
	}catch(e){}
	hideMiniPoi();
}

//清除点线
function hideMiniPoi(){
	if(_miniPoi!=null){
		try{
			maplet.removeOverlay(_miniPoi);
		}catch(e){}
	}
}

//添加公交线路中的站点
function addPoiByStation(param){
	var pois=param.split(',');
	removeAllStations();
	for(var i=0;i<pois.length;i++){
		var name=pois[i++];
		var Mlable = new MLabel(name,16,-14);
		var point = new MPoint(pois[i]);
		var icon = new MIcon(_busStopIcon,20,20);
		var infoWindow = new MInfoWindow(name,'');
		var marker = new MMarker(point,icon,infoWindow,Mlable);
		_allStation[i]=marker;
		maplet.addOverlay(marker);
	}
}

//删除所有站点里的图标
function removeAllStations(){
	maplet.clean();
	for(var i=0;i<_allStation.length;i++){
		maplet.removeOverlay(_allStation[i]);
	}
	_allStation = new Array();
}


//打印
function setPrintContent(index){
	var pline='';
	var routelatlons = busResult.bus.item[index].routelatlons;
	if(routelatlons.length>0){
		for(i=0;i<routelatlons.length;i++){
			for(var j=0;j<routelatlons[i].length;j++){
				pline+=routelatlons[i][j]+',';		
			}
			pline+=';';
		}
	}
	var walklatlon='';
	var walkroutes = busResult.bus.item[index].walkroutes;
	if(walkroutes.length>0){
		for(i=0;i<walkroutes.length;i++){
			for(j=0;j<walkroutes[i].length;j++){
				walklatlon+= walkroutes[i][j]+",";
			}
			walklatlon+=';';
		}
	}
	var title="";
	for(var j=0;j<busResult.bus.item[index].stations.length;j++){
		title=title+busResult.bus.item[index].stations[j].name;
		if(j<busResult.bus.item[index].stations.length-1)
			title=title+" 转 ";
	}
	title=title.replace(new RegExp("\\(.{1,10}-.{1,10}\\)","gm"),"");
	var submitForm = document.createElement("FORM");
	document.body.appendChild(submitForm);
	submitForm.method = "POST";
	var pcontent = document.createElement("INPUT");
	pcontent.name = "pcontent";
	pcontent.type="hidden";
	pcontent.value = _printContent;
	var overlays = document.createElement("INPUT");
	overlays.type="hidden";
	overlays.name = "overlays";
	var over= maplet.getCurrentMap().substring(maplet.getCurrentMap().indexOf('overlays'));
	var overIndex=over.indexOf("=")+1;
	if(over.substring(overIndex,overIndex+1)==";"){
		over=over.replace("overlays=;","overlays=");
	}
	overlays.value =over;
	var plines = document.createElement("INPUT");
	plines.type="hidden";
	plines.name = "plines";
	plines.value = pline;
	//walklatlons:公交跑车画站点到查询点之间的线,需要的经纬度2维数组,一级数组用';'号分离,二级数组用','号分离
	var walklatlons = document.createElement("INPUT");
	walklatlons.type="hidden";
	walklatlons.name = "walklatlons";
	walklatlons.value = walklatlon;
	var ptitle = document.createElement("INPUT");
	ptitle.type="hidden";
	ptitle.name = "ptitle";
	ptitle.value = title;
	var map = document.createElement("INPUT");
	map.type="hidden";
	map.name = "map";
	map.value = maplet.getZoomLevel()+','+maplet.getCurrentMap().split(',')[1];
	submitForm.appendChild(pcontent);
	submitForm.appendChild(overlays);
	submitForm.appendChild(plines);
	submitForm.appendChild(walklatlons);
	submitForm.appendChild(ptitle);
	submitForm.appendChild(map);
	submitForm.action= contextPath+"/js/mapbar/print2.jsp";
	submitForm.target="_blank";
	submitForm.submit();
}
//发送短信
/*function SMSContent(){
	var url='http://sms.mapbar.com/sms/sms.jsp?strMsg='+encodeURIComponent(_smsContent)+'&encode=utf-8';
	window.open(url,'','width=620,height=400');
}*/
//公交发送短信
	function SMSContent(){
		var options = {
			data:[
					{type:'sms',content:_smsContent}
			     ],
			openType:"showWin"
		}
		sendTools(options);
	}

//驾车打印
function drivePrintContent(){
	var submitForm = document.createElement("FORM");
	document.body.appendChild(submitForm);
	submitForm.method = "POST";
	//pcontent:需要显示的内容
	var pcontent = document.createElement("INPUT");
	pcontent.name = "pcontent";
	pcontent.type="hidden";
	pcontent.value = decodeURIComponent(_drivePrintContent);
	//overlays:maplet.getCurrentMap()的overlays参数
	var overlays = document.createElement("INPUT");
	overlays.type="hidden";
	overlays.name = "overlays";
	over=_over;
	var overIndex=over.indexOf("=")+1;
	if(over.substring(overIndex,overIndex+1)==";"){
		over=over.replace("overlays=;","overlays=");
	}
	overlays.value =over;
		
	//plines:画线用的经纬度2维数组,一级数组用';'号分离,二级数组用','号分离
	var plines = document.createElement("INPUT");
	plines.type="hidden";
	plines.name = "plines";
	plines.value = drive.routelatlon;

	//ptitle:标题内容
	var ptitle = document.createElement("INPUT");
	ptitle.type="hidden";
	ptitle.name = "ptitle";
	var divTitle="从&nbsp;<font color='#0000cc'>"+drive.orig.name+"</font>&nbsp;到&nbsp;<font color='#0000cc'>";
	divTitle+=drive.dest.name+"</font>&nbsp;,距离&nbsp;<font color='#0000cc'>"+drive.distance+"</font>&nbsp;公里";
	ptitle.value = decodeURIComponent(divTitle);

	//map:地图的中心经纬度及缩放比列(中间用逗号分离)
	var map = document.createElement("INPUT");
	map.type="hidden";
	map.name = "map";
	map.value = maplet.getZoomLevel()+','+maplet.getCurrentMap().split(',')[1];
	submitForm.appendChild(pcontent);
	submitForm.appendChild(overlays);
	submitForm.appendChild(plines);
	submitForm.appendChild(ptitle);
	submitForm.appendChild(map);
	submitForm.action= contextPath+"/js/mapbar/print2.jsp";
	submitForm.target="_blank";
	submitForm.submit();
}
//发送驾车短信
function driveSMSContent(){
	var submitForm = document.createElement("FORM");
	document.body.appendChild(submitForm);
	submitForm.method = "POST";

	var pcontent = document.createElement("INPUT");
	pcontent.name = "strMsg";
	pcontent.type="hidden";
		
	var encodestr = document.createElement("INPUT");
	encodestr.name = "encode";
	encodestr.type="hidden";
	encodestr.value = "utf-8";
		
	submitForm.appendChild(pcontent);
	submitForm.appendChild(encodestr);
	submitForm.action= "http://sms.mapbar.com/sms/sms.jsp";
	submitForm.target='msg';
	submitForm.onsubmit=window.open('','msg','width=620,height=400');
	pcontent.value = decodeURIComponent(_driveSmsContent);
	submitForm.submit();
}

//判断是返回公交还是驾车页
function reBusDriveDiv(){
	if(_searchType=='bus'){
		showSearchBoxDiv(2);
	}else if(_searchType=='drive'){
		showSearchBoxDiv(3);
	}
}

//设置公交或驾车
function setSearchType(st){
	_searchType=st;
}
function toolbutton(id){
	for(var i=1; i<8; i++){
	$('but0' + i).className='';
	}
	id.className='toolbut';
}

//回车触发事件
function checkSub(event,id){
	var keyCode = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
	if(keyCode=='13') {
		document.getElementById(id).onclick();
		return false;
	}
}

//回车跳到下一个控件
function toNext(event,id){
	var keyCode = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
	if(keyCode=='13') {
		document.getElementById(id).focus();
		return false;
	}
}

//发送短信
	function sendsms(){
		var options = {
			data:[
					{type:'sms',content:"[mapbar.com地图信息] "+_sms},
					{type:'im'},
					{type:'mail',title:"图吧真诚为您服务!",content:_sms,snapmode:'full'},
					{type:'gps',title:"图吧真诚为您服务!",content:_sms}
			     ],
			openType:"showWin"
		}
		sendTools(options);
	}

//发送邮件		
	function sendmail(){
		var options = {
			data:[
					{type:'mail',title:"图吧真诚为您服务!",content:_sms,snapmode:'full'},
					{type:'im'},
					//{type:'sms',title:"图吧真诚为您服务!",content:"[mapbar.com地图信息] "+_sms,snapmode:'no'},
					{type:'gps',title:"图吧真诚为您服务!",content:_sms}
			     ],
			openType:"showWin"
	    }
	    sendTools(options);
	}

//发送邮件		
	function sendmails(te,ct){
		var options = {
			data:[
					{type:'mail',title:te,content:ct,snapmode:'full'},
					{type:'im'},
					{type:'sms',title:te,content:te+'-'+ct,snapmode:'no'},
					{type:'gps',title:te,content:ct}
			     ],
			openType:"showWin"
	    }
	    sendTools(options);
	}

//发送IM
	function sendim(){
		var options = {
			data:[
					{type:'im',title:'',content:''},
					{type:'mail',title:"图吧真诚为您服务!",content:_sms,snapmode:'full'},
					//{type:'sms',title:"图吧真诚为您服务!",content:"[mapbar.com地图信息] "+_sms,snapmode:'no'},
					{type:'gps',title:"图吧真诚为您服务!",content:_sms}
			     ],
			openType:"showWin"
	    }
		sendTools(options);
	}
	//发送GPS
	function sendgps(){
			var title = "地图联盟真诚为您服务!";
			var options = {
				data:[
						{type:'gps',title:title,content:_sms},
						{type:'im'},
						{type:'mail',title:title,content:_sms,snapmode:'full'},
						//{type:'sms',title:title,content:"[mapbar.com地图信息] "+_sms,snapmode:'no'}
				     ],
				openType : "showWin" 
		    }
			sendTools(options);
		}

function copyCode(id){
	var testCode=document.getElementById(id).value;
	if(copy2Clipboard(_sms)!=false){
		//alert("生成的代码已经复制到粘贴板，你可以使用Ctrl+V 贴到需要的地方去了哦！  ");
	}
};
function copy2Clipboard(txt){
	if(window.clipboardData){
		window.clipboardData.clearData();
		window.clipboardData.setData("Text",txt);
	}
	else if(navigator.userAgent.indexOf("Opera")!=-1){
		window.location=txt;
	}
	else if(window.netscape){
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		catch(e){
			alert("您的firefox安全级别设置过高，请在地址栏打开’about:config’将页面列表中的signed.applets.codebase_principal_support’设置为true’之后重试。");
			return false;
		}
		var clip=Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if(!clip)return;
		var trans=Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if(!trans)return;
		trans.addDataFlavor('text/unicode');
		var str=new Object();
		var len=new Object();
		var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=txt;str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if(!clip)return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
};

//设置短信地图操作功能
function setNMode(val,pid,city){
	setDivNone();
	if(val==1){
		sendsms();
	}else if(val==2){
		sendmail();
	}else if(val==3){
		sendim();
	}else if(val==4){
		sendgps();
	}else if(val==5){
		maplet.setMode('zoomin',setModePan);
	}else if(val==6){
		maplet.setMode('zoomout',setModePan);
	}else if(val==7){
		maplet.setMode('measure');
	}else if(val==8){
		maplet.setMode('snapshot',setModePan);
	}else if(val==9){
		window.print();
	}else if(val==10){
		var erroru=encodeURIComponent("&errorpid="+pid+"&errorcity="+city);
		window.open(document.getElementById("hreferrorid").href+encodeURIComponent(erroru),"_blank");
	}
}

//设置拖动模式
function setModePan(){
	maplet.setMode('pan');
}

//设置发送层/地图工具显示层是否显示
function onShowSendTools(val){
	if(_smsDivShow==val){
		_smsDivShow="";
		setDivNone();
	}else{
		_smsDivShow=val;
		if(val=="sendDivId"){
			document.getElementById("sendDivId").style.display="block";
			document.getElementById("sendDivIdEm").className="arrow_deon";
			document.getElementById("toolsDivId").style.display="none";
			document.getElementById("toolsDivIdEm").className="arrow_de";
		}else{
			document.getElementById("sendDivId").style.display="none";
			document.getElementById("sendDivIdEm").className="arrow_de";
			document.getElementById("toolsDivId").style.display="block";
			document.getElementById("toolsDivIdEm").className="arrow_deon";
		}
	}
	
}

//设置弹出层隐藏
function setDivNone(){
	_smsDivShow="";
	document.getElementById('citypro_more').style.display='none';
	document.getElementById('sendDivId').style.display='none';
	document.getElementById('sendDivIdEm').className="arrow_de";
	document.getElementById('toolsDivId').style.display='none';
	document.getElementById('toolsDivIdEm').className="arrow_de";
}

//显示截图
function snapDone(url) {
    window.open(url);
}

//切换气泡公交驾车查询层
function showPoiSearchDiv(searchboxDiv){
	document.getElementById("liFromId").className="";
	document.getElementById("liToId").className="";
	document.getElementById("liNeighborId").className="";
	document.getElementById("li"+searchboxDiv+"Id").className="current";

	document.getElementById("poiDivTo").style.display="none";
	document.getElementById("poiDivNeighbor").style.display="none";
	document.getElementById("poiDivFrom").style.display="none";
	document.getElementById("poiDiv"+searchboxDiv).style.display="";

}

//设置气泡查询值
function setPoiSearchboxValue(poikeywrod){
	document.getElementById("txtDestName").value=poikeywrod;
	document.getElementById("txtOrigName").value=poikeywrod;
	document.getElementById("poitype").value=poikeywrod;
}

//设置关键字列表图标样式
function setKeywordListCss(lnum,settype){
	var mmpars=map.getMarker(lnum-1);
	if(mmpars){
		var pul="images/r"+lnum+".png";

		if(mmpars.icon.getImgUrl().indexOf(pul)==-1){
			setPoiIconAll();
			mmpars.icon.updateImage(pul);
			mmpars.icon.hilite();
			for(var i=1;i<11;i++){
				if(document.getElementById("keywordlist"+i)){
					document.getElementById("keywordlist"+i).className="poiContainer";
				}
				if(document.getElementById("keywordimg_"+i)){
					document.getElementById("keywordimg_"+i).className="mapbar_poi_qpnum mapbar_poi_qpnumR"+i;
				}
			}
			if(document.getElementById("keywordlist"+lnum))	document.getElementById("keywordlist"+lnum).className="poiContainer poiContainerOn";
			if(document.getElementById("keywordimg_"+lnum)) document.getElementById("keywordimg_"+lnum).className="mapbar_poi_qpnum mapbar_poi_qpnumB"+lnum;
		}
		if(!settype) document.getElementById("rsContainer").scrollTop=document.getElementById("rsContainer").scrollHeight*("0."+(lnum-1));

	}

}

//设置所有气泡图标
function setPoiIconAll(){
	for(var i=0;i<10;i++){
		var mmpars=map.getMarker(i);
		if(mmpars){
				var pul="images/g"+(1+i)+".png";
				
				if(mmpars.icon.getImgUrl().indexOf(pul)==-1){
					mmpars.icon.updateImage(pul);
				}
		}
	}
}

function showOrigBusSearch(city,name,strlatlon,searchName){
	window.open('http://bus.mapbar.com/mapview/index.jsp#ac=bus&city='+city+'&origName='+encodeURIComponent(name)+'&origLatLon='+strlatlon+'&destName='+encodeURIComponent(searchName)+'&destLatLon=','mapbar','');
}
function showDestBusSearch(city,name,strlatlon,searchName){
	window.open('http://bus.mapbar.com/mapview/index.jsp#ac=bus&city='+city+'&origName='+encodeURIComponent(searchName)+'&origLatLon=&destName='+encodeURIComponent(name)+'&destLatLon='+strlatlon,'mapbar','');
}
function showOrigCarSearch(city,name,strlatlon,searchName){
	window.open('http://nav.mapbar.com/mapview/index1.jsp#ac=nav&origCity='+city+'&origName='+encodeURIComponent(name)+'&origLatLon='+strlatlon+'&destCity='+city+'&destName='+encodeURIComponent(searchName)+'&destLatLon=','mapbar','');
}
function showDestCarSearch(city,name,strlatlon,searchName){
	window.open('http://nav.mapbar.com/mapview/index1.jsp#ac=nav&origCity='+city+'&origName='+encodeURIComponent(searchName)+'&origLatLon=&destCity='+city+'&destName='+encodeURIComponent(name)+'&destLatLon='+strlatlon,'mapbar','');
}

String.prototype.trim = function(){
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}

//判断字符是否为2个字节
function isChinese(str)
{
   var lst = /[u00-uFF]/;      
   return !lst.test(str);     
}
//判断字符串长度
function strlen(str){
   var strlength=0;
   for (i=0;i<str.length;i++)
	{
		if (isChinese(str.charAt(i))==true)
			strlength=strlength + 2;
		else
			strlength=strlength + 1;
	}
	return strlength;
}
//截取字符串
function subPoiStr(str){
   var strlength=0;
   var strsub="";
   for (i=0;i<str.length;i++)
	{
		if (isChinese(str.charAt(i))==true)
			strlength=strlength + 2;
		else
			strlength=strlength + 1;
		strsub+=str.charAt(i);
		if(strlength>8)
			return strsub;
	}
	return strsub;
}

//去掉公交信息里的外环/内环，上行/下行，环线，环形信息
function checkBusString(buss){
	var bs="";
	if(buss!=null && buss!=""){
		if(buss.indexOf("外环(")!=-1){
			bs=buss.substring(0,buss.indexOf("外环("));
		}else if(buss.indexOf("内环(")!=-1){
			bs=buss.substring(0,buss.indexOf("内环("));
		}else if(buss.indexOf("上行(")!=-1){
			bs=buss.substring(0,buss.indexOf("上行("));
		}else if(buss.indexOf("下行(")!=-1){
			bs=buss.substring(0,buss.indexOf("下行("));
		}else if(buss.indexOf("环线(")!=-1){
			bs=buss.substring(0,buss.indexOf("环线("));
		}else if(buss.indexOf("环形(")!=-1){
			bs=buss.substring(0,buss.indexOf("环形("));
		}else{
			bs=buss;
		}
	}
	return bs;
}



