
var startJnb=0 ;
var stopJnb=0 ;
var startDataJ ;
var stopDataJ ;
var stop_JJJ= "" ;
var xx_j=yy_j=xx1_j=yy1_j= "" ;
function doGJ_j(s)
{
	var sis = new MSISSearch();
	var searchroutpara=new MSearchRoutPara ();
	sis.setSISCallbackFunction(dG_j); 
	searchroutpara.setCitycode("0411");
	$('startJt').innerHTML=startDataJ.poilist[startJnb].name;
	$('stopJt').innerHTML=stopDataJ.poilist[stopJnb].name;
	$('ssJ').style.display="";
	$('dddx').style.display="none";
	$('dddq').style.display="";
	$('xqJ').style.display="";
	xx_j=startDataJ.poilist[startJnb].x;
	yy1_j=stopDataJ.poilist[stopJnb].y;
	xx1_j=stopDataJ.poilist[stopJnb].x;
	yy_j=startDataJ.poilist[startJnb].y;
	searchroutpara.setType("drive");
	searchroutpara.setStartXY(xx_j,yy_j);
	searchroutpara.setEndXY(xx1_j,yy1_j);
	sis.searchBusAndDrive(searchroutpara);	
}
function getXY_j(searchKeys,ba)
{
	if(searchKeys != "")
	{
		var sis = new MSISSearch();
		var searchpointpara = new MSearchPointPara();
		sis.setSISCallbackFunction(ba); 
		searchpointpara.setCitycode("0411");
		searchpointpara.setKeyword(searchKeys);
		searchpointpara.setNumber(15);
		sis.searchByKeyword(searchpointpara);
	}
}
function getStartG_j(data)
{
	startDataJ=data ;
	if(data.count != 0)
	{
		$('Jstartshowlist').innerHTML = "" ;
		for ( var sil = 0 ; sil < data.poilist.length ;  sil++)
		{
			if(sil == 0)
			{
				$('startJt').innerHTML=data.poilist[0].name;
				startJnb = 0 ;
				$('Jstartshowlist').innerHTML += '<li class="ons" id="Jstartshowlist'+sil+'" onclick=chooseq("Jstartshowlist",'+sil+',"start","'+data.poilist[sil].x+'","'+data.poilist[sil].y+'")>'+data.poilist[sil].name+'</li>' ;
			}
			else
				$('Jstartshowlist').innerHTML += '<li id="Jstartshowlist'+sil+'" onclick=chooseq("Jstartshowlist",'+sil+',"start","'+data.poilist[sil].x+'","'+data.poilist[sil].y+'")>'+data.poilist[sil].name+'</li>' ;
		}
		getXY_j(stop_JJJ,getStopG_j);
	}
	else{
		alert("输入的起点没有结果，请尝试修改。");
		$('xqJ').innerHTML="无结果！";
	}
}
function getStopG_j(data)
{
	stopDataJ=data ;
	if(data.count != 0)
	{
		$('Jstopshowlist').innerHTML = "" ;
		for ( var sil = 0 ; sil < data.poilist.length ;  sil++)
		{
			if(sil == 0)
			{
				$('stopJt').innerHTML=data.poilist[0].name;
				stopJnb = 0 ;
				$('Jstopshowlist').innerHTML += '<li class="ons" id="Jstopshowlist'+sil+'" onclick=chooseq("Jstopshowlist",'+sil+',"stop","'+data.poilist[sil].x+'","'+data.poilist[sil].y+'")>'+data.poilist[sil].name+'</li>' ;
			}
			else
				$('Jstopshowlist').innerHTML += '<li id="Jstopshowlist'+sil+'" onclick=chooseq("Jstopshowlist",'+sil+',"stop","'+data.poilist[sil].x+'","'+data.poilist[sil].y+'")>'+data.poilist[sil].name+'</li>' ;
		}
		$('ssJ').style.display="";
		$('dddx').style.display="";
		$('dddq').style.display="none";
		$('xqJ').style.display="none";
		/*$('stopJt').innerHTML=data.poilist[0].name;
		$('ssJ').style.display="";
		if(stopDataJ)
			doGJ_j('g');*/
		var ss=new Array () ;
		var pointStyle1 = new MStyle() ;
		pointStyle1.showTip = false; 
		var customPoint = new MCustomPointOverlay(new MLatLng(startDataJ.poilist[0].y,startDataJ.poilist[0].x), "http://baohuali.com.cn/dalian/images/start.gif", pointStyle1 ,"1");
		mapObj.addOverlay(customPoint, false);
		ss.push(customPoint);
		var customPoint = new MCustomPointOverlay(new MLatLng(stopDataJ.poilist[0].y,stopDataJ.poilist[0].x), "http://baohuali.com.cn/dalian/images/end.gif", pointStyle1 ,"2");
		mapObj.addOverlay(customPoint, false);
		ss.push(customPoint);
		mapObj.drawCustomPoints(ss, true);
	}
	else
	{
		alert("输入的终点点没有结果，请尝试修改。");
		$('xqJ').innerHTML="无结果！";
	}
}

function cometoG_j()
{
		if($('jc_start').value != '' && $('jc_stop').value != '' )
	{
			$('jc_list').style.display="";
			$('ssJ').style.display="none";
			$('xqJ').innerHTML="正在查询。。。";
			mapObj.removeAllOverlays();
			$('xqJ').style.display="";
			startDataJ = null;
			stopDataJ = null;
			getXY($('jc_start').value,getStartG_j);
			stop_JJJ = $('jc_stop').value ;
	}
		else
			alert('起点和终点都不能为空。');
}



var xy_array_j ;
var xy_hc_array_j ;
function dG_j(data)
{
	if (data.count != 0) {
			xy_array_j = new Array();
			xy_hc_array_j = new Array();
			var road_length =0;
			var route_line ='<table width="95%" border="0" cellpadding="0" cellspacing="0" class="detail" style="display:;"><tbody><tr><td colspan="2" align="left" bgcolor="#0581C9" class="f_w"> 　驾车线路</td>                            </tr> <tr> <td width="74%" bgcolor="#F6F6F6">路线</td><td width="26%" bgcolor="#F6F6F6">里程</td> </tr><tr><td colspan="2" align="left"><table cellspacing="0" cellpadding="0" width="97%" bgcolor="#ffffff" class="xl_1">  <tbody  > <tr> <td colspan="2" bgcolor="#F6F6F6"  align="left"><img src="images/start.gif" width="11" height="13" align="absmiddle" /> 起点   '+startDataJ.poilist[startJnb].name+'</td> </tr>';
                        /*  */
			var phone_xin="";
			var str_xy="";

			var route_map = eval('(data)');
			 
			for(var i=0;i<route_map.segmengList.length;i++){
					var img ="";
					var a="";
					 var stmlp = "" ;
					if(a==""){}else{
						img = "<img src=\"html/images/r/"+a+"\" />";
					}
					var htjti = route_map.segmengList[i].coor;
					route_line +='<tr ><td  height="25" align="left"  valign="top" style="color:#000" style="cursor:hand" onclick="onchzh(\''+htjti+'\')"> '+(i+1)+'  '+route_map.segmengList[i].textInfo+' </td><td height="25"> </td></tr>';
					//route_line += "<tr bgcolor=\"#F8F7FF\"><td height=\"25\" bgcolor=\"#F8F7FF\" align=\"center\"><a href=\"#\">"+(i+1)+"</a></td><td height=\"25\" colspan=\"2\" bgcolor=\"#F8F7FF\">"+route_map.segmengList[i].textInfo+img+"</td></tr>";

					//phone_xin += route_map.segmengList[i].textInfo+"．";
								
					road_length = road_length + parseInt(route_map.segmengList[i].roadLength);
					
					str_xy += htjti;
				}

			if(road_length>1000){
				road_length = road_length/1000;
				route_line += '<tr> <td colspan="3"   bgcolor="#F6F6F6"  align="left"><img src="images/end.gif" width="11" height="13" align="absmiddle" /> 终点   '+stopDataJ.poilist[stopJnb].name+'</td> </tr><tr><td colspan="3" align="right">行驶：'+road_length+'公里</td></tr>';
			}
			else
				route_line += '<tr> <td colspan="3"   bgcolor="#F6F6F6"  align="left"><img src="images/end.gif" width="11" height="13" align="absmiddle" /> 终点   '+stopDataJ.poilist[stopJnb].name+'</td> </tr><tr><td colspan="3" align="right">行驶：'+road_length+'米</td></tr>';

			document.getElementById("xqJ").innerHTML=''+route_line+"</table>";
			//$('result').innerHTML="<div class=\"sresult\"><ul id=\"routedesc\" class=\"scroll\"><table width=\"243\" border=\"0\"><tr class=\"td1\"><td width=\"25\" align=\"center\"><b>起</b></td><td width=\"211\"><span id=\"qd_name_a\" class=\"STYLE5\">"+r_start_cityname+"&nbsp;&nbsp;&nbsp;&nbsp;"+r_start_name+"</span></td><td width=\"90\"></td></tr>"+route_line+"<tr class=\"td1\"><td><b>终：</b></td><td colspan=\"3\"><span class=\"STYLE5\" id=\"qd_name_b\">"+r_end_cityname+"&nbsp;&nbsp;&nbsp;&nbsp;"+r_end_name+"</span>	</td></tr><tr><td colspan=\"4\"><div align=\"right\"><span class=\"STYLE4\"><a href=\"javascript:void(0)\">行驶：</a>"+road_length+"公里</span> </div></td></tr></table></ul></div></div>";
			
			poi_xy_r = str_xy.split(",");
				arrX_r = "";//行车路线的X串
				arrY_r = "";//行车路线的Y串
				for(var e=0;e<poi_xy_r.length-1;e=e+2){	
					if(e==poi_xy_r.length-3){
						arrX_r += poi_xy_r[e];
						arrY_r += poi_xy_r[e+1];
					}else{
						arrX_r += poi_xy_r[e]+",";
						arrY_r += poi_xy_r[e+1]+",";
					}
				}						
			drawABusLine_j(arrX_r,arrY_r,yy_j,xx_j,yy1_j,xx1_j);
			
		} else {
			document.getElementById("xqJ").innerHTML="对不起！暂无数据!";
		}
}
function onchzh(jio)
{
	 mapObj.removePolylineById("10011");
	var temp = jio.split(",");
	var arr=new Array();
	for(var i = 0 ; i < temp.length-1 ; i +=2)
	{
		arr.push(new MLatLng(temp[i+1], temp[i])) ;
	}
	var polylineStyle = new MStyle();
	polylineStyle.lineColor = 0xff0000;
	polylineStyle.lineSize = 5;
	polylineStyle.showTip = false; //不显示tip

	var polyline = new MPolylineOverlay(arr, polylineStyle, "10011"); 
	mapObj.addOverlay(polyline,true);
	//mapObj.drawCustomPoints(arr, true);
}
function oncheck_J(i)
{
	var poi_xy = xy_array_j[i].split(",");
			var arrX = "";//行车路线的X串
			var arrY = "";//行车路线的Y串
			for(var e=0;e<poi_xy.length-1;e=e+2){	
				if(e==poi_xy.length-3){
					arrX += poi_xy[e];
					arrY += poi_xy[e+1];
				}else{
					arrX += poi_xy[e]+",";
					arrY += poi_xy[e+1]+",";
				}
			}
			var poi_xy_hc = xy_hc_array_j[i].split(",");
			var hcx = "";
			var hcy ="";
			for(var e=0;e<poi_xy_hc.length-1;e=e+2){	
				if(e==poi_xy_hc.length-3){
					hcx += poi_xy_hc[e];
					hcy += poi_xy_hc[e+1];
				}else{
					hcx += poi_xy_hc[e]+",";
					hcy += poi_xy_hc[e+1]+",";
				}
			}
			drawABusLine(arrX,arrY,xx,yy,xx1,yy1,hcx,hcy);
}
function drawABusLine_j(arrX,arrY,qdpoix,qdpoiy,zdpoix,zdpoiy,changex,changey)
{    
	mapObj.removeAllOverlays();
	var str ="";
	var startObj=new MStyle();
	startObj.lineColor="0xFFFFFF";
	startObj.lineOpacity="80";
	startObj.lineSize="2";
	startObj.fillOpacity="100";
	startObj.fillColor = "0x4b8bd9";
	startObj.labelColor="0xFFFFFF";
	startObj.textContent = "<font color=\"#FFFFFF\"><b>起点</b></font>　<br />"+str+"<br />";

	var str1 ="";
	var endObj=new MStyle();
	endObj.textContent="<font color=\"#FFFFFF\"><b>终点</b></font>　<br />"+str1+"<br />";
	endObj.lineColor="0xFFFFFF";
	endObj.lineOpacity="80";
	endObj.fillColor="0xEF501A";
	endObj.lineSize="2";
	endObj.fillOpacity="100";
	endObj.fillColor = "0x4b8bd9";
	endObj.labelColor="0xFFFFFF";
	var lineObj=new MStyle();
	lineObj.lineSize=6;
	lineObj.lineColor=0x0000ff;
	lineObj.lineOpacity="60";
	var startPoint = new MPointOverlay(new MLatLng(qdpoix,qdpoiy), startDataJ.poilist[startJnb].name, startObj);
	var endPoint = new MPointOverlay(new MLatLng(zdpoix,zdpoiy), stopDataJ.poilist[stopJnb].name, endObj);
	//mapObj.drawBusLine(arrX, arrY, changex, changey, startPoint, endPoint, lineObj,true);
	mapObj.drawDriveLine(arrX, arrY, startPoint, endPoint, lineObj , true);
}