var startName_bus,endName_bus,routeType = "0";
var citycode = "010";
var sis,start,end,bus;
var gold = 1;
var start_x="",start_y="",start_name="",start_type="",start_address="",start_tel="",start_pid="",start_citycode="",start_cityname="";
var end_x="",end_y="",end_name="",end_type="",end_address="",end_tel="",end_pid="",end_citycode="",end_cityname="";
var xy_array ;
var xy_hc_array="";
var start_temp="",end_temp="";
var bus_NN=0;
function bus_setQdvalue(s_x,s_y,s_n,s_t,s_a,s_tel,s_poi)
{
	bus_NN=1;
	start_x = s_x;
	start_y = s_y;
	start_name = s_n;
	start_type = s_t;
	start_address = s_a;
	start_tel = s_tel;
	startName_bus = start_name;
	$('#startBusName').html(start_name + '<img src="../elements/image/map/map_new/to_icon.gif" align="absmiddle" style="margin:0px 2px 0px 2px" />');
	$('#searchStartBusName').html(start_name);
}
function bus_setZdvalue(e_x,e_y,e_n,e_t,e_a,e_tel,e_poi)
{
	bus_NN=1;
	end_x = e_x;
	end_y = e_y;
	end_name = e_n;
	end_type = e_t;
	end_address = e_a;
	end_tel = e_tel;
	endName_bus = end_name;
	$('#endBusName').html(end_name);
	$('#searchEndBusName').html(end_name);
}   
function reSearchType_bus_map(pType)
{
	bus.setStartXY(start_x,start_y);
	bus.setEndXY(end_x,end_y);
	bus.setCitycode(citycode);
	if($("input[name='bus_type']:checked").val() == "5")
	{
		bus.setRouteType(5);
	}else{
		bus.setRouteType(pType);
	}	
	bus.setType("bus");
	sis.searchBusAndDrive(bus); 
	$("#overlay").show();
	$("#loading").show();
	modal("show");
	mapObj.removeAllOverlays(); 
	drawHistoryPoint();
	$("#start_detail ul").remove();
	$("#end_detail ul").remove();
	$("#txtStartSearch").val(start_name);
	$("#txtEndSearch").val(end_name);
	$("#route_setting").show();	
	$("#bus_result_info").show();	
	$("#result").show();
	$("#bus_search_btn").hide();
	$("#start_detail").hide();
	$("img#img_start_header").attr("src","../elements/image/map/map_new/green_icon_expand.gif");
	$("img#img_start_header").attr("title",strExpand);
	$("#end_detail").hide();
	$("img#img_end_header").attr("src","../elements/image/map/map_new/green_icon_expand.gif");
	$("img#img_end_header").attr("title",strCollapse);
}
function reSearch_bus_map(pType)
{
		$("#overlay").show();
		$("#loading").show();
		modal("show");
		$("#route_setting").hide();	
		$("#bus_result_info").hide();	
		$("#result").hide();
		bus_NN=0;
		$("#bus_search_btn").hide();
		if(pType == "start")
		{
			start_x="";start_y="";start_name="";start_type="";start_address="";start_tel="";start_pid="";start_citycode="";start_cityname="";
			startName_bus = $("#txtStartSearch").val(); 
			start_batch = 0;
			start_cur_num = 0;
	
		}else if(pType == "end"){   
			end_x="";end_y="";end_name="";end_type="";end_address="";end_tel="";end_pid="";end_citycode="";end_cityname="";
			endName_bus = $("#txtEndSearch").val();      
			end_batch = 0;
			end_cur_num = 0;
		}
		routeType = $("#routeType a").attr("rel");
		var busSearchNum = 30;
		sis = new MSISSearch();
		start = new MSearchPointPara();
		end = new MSearchPointPara();
		bus = new MSearchRoutPara();
		sis.setSISCallbackFunction(searchBusCallBack);
		gold=1;
		start.setCitycode(citycode);
		start.setKeyword(startName_bus);
		start.setSearchType(sortedType);
		start.setPageSum(1);
		start.setBatch(start_batch + 1);	
		start.setNumber(busSearchNum);
		sis.searchByKeyword(start); 
		errMsg = true;
}
function switchRoute()
{
	var e_x,e_y,e_n,e_t,e_a,e_tel;
	start_batch = 0;
	end_batch = 0;
	start_cur_num = 0;
	end_cur_num = 0;
	e_x = start_x;
	e_y = start_y;
	e_n = start_name;
	e_t = start_type;
	e_a = start_address;
	e_tel = start_tel;
	start_x = end_x;
	start_y = end_y;
	start_name = end_name;
	start_type = end_type;
	start_address = end_address;
	start_tel = end_tel
	startName_bus = start_name;
	$('#startBusName').html(start_name + '<img src="../elements/image/map/map_new/to_icon.gif" align="absmiddle" style="margin:0px 2px 0px 2px" />');
	$('#searchStartBusName').html(start_name);
	end_x = e_x;
	end_y = e_y;
	end_name = e_n;
	end_type = e_t;
	end_address = e_a;
	end_tel = e_tel;
	endName_bus = end_name;
	$('#endBusName').html(end_name);
	$('#searchEndBusName').html(end_name);
	
	reSearchType_bus_map(routeType);
}
var start_batch=0;end_batch=0,e_total_page=0,s_total_page=0;
function search_bus_map()
{
		map_stat('1');
		$("#overlay").show();
		$("#loading").show();
		modal("show");
		$("#bus_search_btn").hide();
		start_x="";start_y="";start_name="";start_type="";start_address="";start_tel="";start_pid="";start_citycode="";start_cityname="";
		end_x="";end_y="";end_name="";end_type="";end_address="";end_tel="";end_pid="";end_citycode="";end_cityname="";
		switchSearch("1");
		fullscreenMode("2");
		$("#route_setting").hide();	
		$("#bus_result_info").hide();	
		$("#result").hide();
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		bus_NN=0;   
		startName_bus = $("#startName_bus").val();
		endName_bus = $("#endName_bus").val();
		routeType = $("#routeType a").attr("rel");
	    $("#researchType").val(routeType);
		var busSearchNum = 30;
		sis = new MSISSearch();
		start = new MSearchPointPara();
		end = new MSearchPointPara();
		bus = new MSearchRoutPara();
		sis.setSISCallbackFunction(searchBusCallBack);
		gold=1;
		start.setCitycode(citycode);		
		start.setKeyword(startName_bus);
		start.setSearchType(sortedType);
		start.setPageSum(1);
		start.setBatch(start_batch + 1);	
		start.setNumber(busSearchNum);
		sis.searchByKeyword(start); 
		errMsg = true;
	
}
function start_end_bus()
{
	if(gold==1){
		gold=0;
		var busSearchNum = 30;
		end.setCitycode(citycode);
		end.setKeyword(endName_bus);
		end.setSearchType(sortedType);
		end.setPageSum(1);
		end.setBatch(end_batch + 1);	
		end.setNumber(busSearchNum);
		sis.searchByKeyword(end);
	}else{
		gold=2;
		$("#overlay").hide();
		$("#loading").hide();
		modal("hide");
		setResultHeight();
		$("#result_container").show();
		vBusSearchBool = false;
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		$("#start_detail").show();
		$("#end_detail").show();
		if(start_name !="" && end_name !="")
		{
			$("#bus_search_btn").show();
		}
		if(start_name =="" && end_name =="")
		{
			$("#overlay").hide();
			$("#loading").hide();
			modal("hide");
			$("#bus_result_info").hide();	
			$("#route_setting").hide();	
			$("#bus_search_btn").hide();
			$("#result_container").show();
			$("#bus_result_count em").html('0');
			$('#result_start_name').html(' ');
			$('#startBusName').html(' ');
			$('#result_end_name').html(' ');
			$('#endBusName').html(' ');
			$('#result').html(errLayoutStr);
			$('#result').show();
			setResultHeight();
			mapObj.removeAllOverlays();
			drawHistoryPoint();
		}
	}
}
function search_bus_line()
{
	var busSearchNum = $("#busSearchNum").val();
	bus.setStartXY(start_x,start_y);
	bus.setEndXY(end_x,end_y);
	bus.setCitycode(citycode);
    bus.setPageSum(1);
	bus.setBatch(1);
	bus.setNumber(busSearchNum);
	routeType = $("#routeType a").attr("rel");
	$("#researchType").val(routeType);
	if($("input[name='bus_type']:checked").val() == "5")
	{
		bus.setRouteType(5);
	}else{
		bus.setRouteType(routeType);	
	}
	bus.setType("bus");
	sis.searchBusAndDrive(bus); 
	$("#overlay").show();
	$("#loading").show();
	modal("show");
	mapObj.removeAllOverlays(); 
	drawHistoryPoint();
	$("#start_detail ul").remove();
	$("#start_page").remove();
	$("#end_detail ul").remove();
	$("#end_page").remove();
	$("#txtStartSearch").val(start_name);
	$("#txtEndSearch").val(end_name);
	$("#bus_instruction").hide();
	$("#start_search").show();	
	$("#end_search").show();	
	$("#route_setting").show();	
	$("#bus_result_info").show();	
	$("#result").show();
	$("#bus_search_btn").hide();
	$("#start_detail").hide();
	$("img#img_start_header").attr("src","../elements/image/map/map_new/green_icon_expand.gif");
	$("img#img_start_header").attr("title",strCollapse);
	$("#end_detail").hide();
	$("img#img_end_header").attr("src","../elements/image/map/map_new/green_icon_expand.gif");
	$("img#img_end_header").attr("title",strCollapse);
}
var start_cur_num = 0;  
var end_cur_num = 0;
var str_x_array;
var str_y_array;
var hc_x_array;
var hc_y_array;
var errMsg = true;
function open_passDepot(k,i,passN)
{
	if(passN!="0"){
		var id = "passDepot_div"+k+"_"+i;
		$("#"+id).toggle();
	}
}
function result_next(pagenum,pType)
{
	if(pType == "end")
	{
		if(end_cur_num == 4)
		{
			if(end_batch < e_total_page-1)
			{
				end_batch++;
				search_bus_map();
				end_cur_num = 0;
			}
		}else{
			if(end_cur_num<pagenum-1)
			{
				for(var i = 0;i<pagenum;i++)
				{
					var id="end_list_"+i;
					$("#"+id).hide();
				}
				end_cur_num = end_cur_num+1;
				var show_id="end_list_"+end_cur_num;
				$("#"+show_id).show();
			}else{
				
				var show_id="end_list_"+pagenum;
				$("#"+show_id).show();
			}
		}
	}else{
		if(start_cur_num == 4)
		{
			if(start_batch < s_total_page-1)
			{
				start_batch++;
				if(vTabIndex == "5")
				{
					searchByCenterKeyword()
				}else{
					search_bus_map();
				}
				start_cur_num = 0;
			}
		}else{
			if(start_cur_num<pagenum-1)
			{
				for(var i = 0;i<pagenum;i++)
				{
					var id="start_list_"+i;
					$("#"+id).hide();
				}
				start_cur_num = start_cur_num+1;
				var show_id="start_list_"+start_cur_num;
				$("#"+show_id).show();

			}else{
				
				var show_id="start_list_"+pagenum;
				$("#"+show_id).show();
			}
		}
	}
}
function result_pre(pagenum,pType)
{
	if(pType == "end")
	{
		if(end_cur_num == 0)
		{
			if(end_batch != 0 && end_batch < e_total_page)
			{
				end_batch--;
				search_bus_map();
				end_cur_num = 4;
			}
		}else{
			if(end_cur_num==0){}else{
				if(end_cur_num<pagenum){
					for(var i = 0;i<pagenum;i++){
				
						var id="end_list_"+i;
						$("#"+id).hide();
					}
					end_cur_num = end_cur_num-1;
					var show_id="end_list_"+end_cur_num;
					$("#"+show_id).show();
				}
			}
		}
	}else{
		if(start_cur_num == 0)
		{
			if(start_batch != 0 && start_batch < s_total_page)
			{
				start_batch--;
				if(vTabIndex == "5")
				{
					searchByCenterKeyword()
				}else{
					search_bus_map();
					
				}
				start_cur_num = 4;
			}
		}else{
			if(start_cur_num==0){}else{
				if(start_cur_num<pagenum){
					for(var i = 0;i<pagenum;i++){
				
						var id="start_list_"+i;
						$("#"+id).hide();
					}
					start_cur_num = start_cur_num-1;
					var show_id="start_list_"+start_cur_num;
					$("#"+show_id).show();
				}
			}    
		}
	}
}
function bus_open(b,allb,pId)
{
	$("#result li a").removeClass("active");
	$("#busline_link"+b).addClass("active");
	
	var src = $("#"+pId).css("display");
	$("#result div.detail").hide();
	setResultHeight();
	if(src == "none")
	{
		$("#overlay").show();
		$("#loading").show();
		modal("show");
		$("#"+pId).show();
		drawABusLine(str_x_array[b],str_y_array[b],start_x,start_y,end_x,end_y,hc_x_array[b],hc_y_array[b]);
		drawFoldline(b);
	}
	else
	{
		$("#"+pId).hide();
	}
	
	
}

function drawABusLine(arrX,arrY,qdpoix,qdpoiy,zdpoix,zdpoiy,changex,changey)
{    
		$("#overlay").hide();
		$("#loading").hide();
		modal("hide");
		setResultHeight();
		$("#result_container").show();
		vBusSearchBool = false;
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		mapObj.quitMouseDraw();
		var startObj=new MStyle();
			startObj.maxZoomLevel = "500";	
		var endObj=new MStyle();
			endObj.maxZoomLevel = "500";
		var lineObj=new MStyle();
			lineObj.lineSize=6 ;
			lineObj.lineColor="0xFF2200";
			lineObj.lineOpacity="70";
			lineObj.changeDirection =  2;
		var startPoint = new MPointOverlay(new MLatLng(qdpoiy,qdpoix), start_name, startObj);
		var endPoint = new MPointOverlay(new MLatLng(zdpoiy,zdpoix), end_name, endObj);
		if(qdpoix == "" || qdpoix == "null" || zdpoix == "" || zdpoiy =="null"){ }else{
			mapObj.drawBusLine(arrX, arrY, changex, changey, startPoint, endPoint, lineObj,false);
		}
}
function removePoint()
{
	if(point=="" || point==" " ){}else{
		mapObj.removeOverlay(point);
		drawHistoryPoint();
	}
}
var sis3,sis4,buslinename,busstationname;
var busline_xy,busstation_xy;
var busline_poi;
var busline_cur_num= new Array();
function search_busl_map()
{
	$("#overlay").show();
	$("#loading").show();
	modal("show");
	var busSearchNum = $("#busSearchNum").val();
	map_stat('2');
	switchSearch("2");
	fullscreenMode("2");
	$("#result_container").show();
	$("#detailCont").show();
    $("#rectDetailCont").hide();            
    $("#catDetailCont").hide(); 
	$("#bus_instruction").hide();
	mapObj.removeAllOverlays();
	var line_v = $("#txtRouteSearch").val();
	sis3 = new MSISSearch();
	buslinename = new MSearchPointPara();
	sis3.setSISCallbackFunction(busLineNameCallBack); 
	buslinename.setCitycode(citycode);
	buslinename.setKeyword(line_v);
	buslinename.setPageSum(1);
	buslinename.setBatch(route_cur_num + 1);	
	buslinename.setNumber(vRecordPerPage);
	sis3.searchBusLineByKeyword(buslinename);
}
var xmlDoc;
function parseXML(pStr)
{
	var arrDoc = new Array();
		if(document.all)
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(pStr);
		}else{
		  try 
		  {
		  parser=new DOMParser();
		  xmlDoc=parser.parseFromString(pStr,"text/xml");
		  }
		  catch(e)
		  {
		  return;
		  }
		}
	var vItem = xmlDoc.getElementsByTagName("name");
	for(var i=0;i<vItem.length;i++)
	{
		arrDoc[i] = new Array();
		arrDoc[i]["name"] = xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;
		arrDoc[i]["station"] = xmlDoc.getElementsByTagName("StationNo")[i].childNodes[0].nodeValue;
		arrDoc[i]["x"] = xmlDoc.getElementsByTagName("X")[i].childNodes[0].nodeValue;
		arrDoc[i]["y"] = xmlDoc.getElementsByTagName("Y")[i].childNodes[0].nodeValue;
	}
	return arrDoc;
}

function getRouteNoXML(pStr)
{
		if(document.all)
		  {
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(pStr);
		  }else{
			  try
			  {
			  parser=new DOMParser();
			  xmlDoc=parser.parseFromString(pStr,"text/xml");
			  }
			  catch(e)
			  {
			  return;
			  }
		}
		try 
		  {
				if(typeof(xmlDoc.getElementsByTagName("DATA")[11]) != "undefined")
				{
					return xmlDoc.getElementsByTagName("DATA")[11].childNodes[0].nodeValue;
				}else{
					return "";
				}
		  }
		catch(e)
		  {
			
		  }
}
function getPostcodeXML(pStr)
{
		if(document.all)
		  {
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(pStr);
		  }else{
			  try
			  {
			  parser=new DOMParser();
			  xmlDoc=parser.parseFromString(pStr,"text/xml");
			  }
			  catch(e)
			  {
			  return;
			  }
		}
		try 
		  {
			if(typeof(xmlDoc.getElementsByTagName("DATA")[10]) != "undefined")
			{
				return xmlDoc.getElementsByTagName("DATA")[10].childNodes[0].nodeValue;
			}else{
				return "";
			}
		   }
		catch(e)
		  {
			
		  }
	
}
function busline_next(ids,pagenum){
	if(busline_cur_num[ids]<pagenum-1){
		for(var i = 0;i<pagenum;i++){
	
			var id="busline_"+ids+"_list_"+i;
			$("#"+id).hide();
		}
		busline_cur_num[ids] = busline_cur_num[ids] + 1;
		var show_id="busline_"+ids+"_list_"+busline_cur_num[ids];
		$("#"+show_id).show();
	}else{
		
		var show_id="busline_"+ids+"_list_"+pagenum;
		$("#"+show_id).show();
	}
}
function busline_all(ids){

	$("div#rou_"+ids+" ul").show();
	
}
function busline_pre(ids,pagenum){
	if(busline_cur_num[ids]==0){}else{
		if(busline_cur_num[ids]<pagenum){
			for(var i = 0;i<pagenum;i++){
		
				var id="busline_"+ids+"_list_"+i;
				$("#"+id).hide();
			}
			busline_cur_num[ids] = busline_cur_num[ids]-1;
			var show_id="busline_"+ids+"_list_"+busline_cur_num[ids];
			$("#"+show_id).show();
		}
	}
}
var stateOpen_id = "rou_1";
function open_busline(num,lineNum)
{
	$("#resultBusLine li a").removeClass("active");
	$("#resultRect li a").removeClass("active");
	$("#resultCat li a").removeClass("active");
	$("#busRoute_link"+num).addClass("active");
	var id = "rou_"+num;
	var src = $("#"+id).css("display");
	if(stateOpen_id==id ){
		if(src == "none")
		{
			$("#" + id).show();
		}else{
			$("#" + id).hide();
		}
	}else{
	 $("#overlay").show();
	 $("#loading").show();
	 modal("show");
		for(var i=1;i<=lineNum;i++){
			$("#rou_" + i).hide();
		}
		$("#" + id).show();
		drawLine(num - 1);
		drawallpoi(num - 1);
	}
	stateOpen_id = id;
	
	if(vTabIndex == "5")
	{
		drawCircle();	
	}
}
function getselected(n1,n2,num)
{
	var id = "line_li_"+n1+n2;
	for(var i =0;i<num;i++){
		var id1 = "line_li_"+n1+i;
		jQuery.DOM.removeClassName(id1,'selectid');
	}
	document.getElementById(id).className = "selectid";
}
function getStrX(num){
	 var poi_xy = busline_xy[num].split(",");
			var arrX = "";
			for(var e=0;e<poi_xy.length-1;e=e+2){   
				if(e==poi_xy.length-3){
					arrX += poi_xy[e];
				}else{
					arrX += poi_xy[e]+",";
				}
			}
	return arrX;
}
function getStrY(num)
{
	var poi_xy = busline_xy[num].split(",");
		var arrY = "";
		for(var e=0;e<poi_xy.length-1;e=e+2){   
			if(e==poi_xy.length-3){
				arrY += poi_xy[e+1];
			}else{
				arrY += poi_xy[e+1]+",";
			}
		}
	return arrY;    
}
function getStartX(num)
{
	var poi_xy = busline_xy[num].split(",");
	return poi_xy[0];
}
function getStartY(num)
{
	var poi_xy = busline_xy[num].split(",");
	return poi_xy[1];
}
function getEndX(num)
{
	var poi_xy = busline_xy[num].split(",");
	return poi_xy[poi_xy.length-3];
}
function getEndY(num)
{
	var poi_xy = busline_xy[num].split(",");
	return poi_xy[poi_xy.length-2];
}
function opentip(poiid)
{
	var point_id = poiid+1;
	mapObj.openTipById(point_id);
}
var station_v;
function search_buss_map()
{
	station_v = $("#txtStopSearch").val();
	$("#overlay").show();
	$("#loading").show();
	modal("show");
	var busSearchNum = $("#busSearchNum").val();
	map_stat('3');
	switchSearch("3");
	fullscreenMode("2");
	$("#result_container").show();
	$("#detailCont").show();
    $("#rectDetailCont").hide();            
    $("#catDetailCont").hide(); 
	$("#bus_instruction").hide();
	mapObj.removeAllOverlays();
	drawHistoryPoint();
	sis4 = new MSISSearch();
	busstationname = new MSearchPointPara();
	sis4.setSISCallbackFunction(busStationNameCallBack); 
	busstationname.setCitycode(citycode);
	busstationname.setKeyword(station_v);
	busstationname.setPageSum(1);
	busstationname.setNumber(busSearchNum);
	busstationname.setBatch(1);
	sis4.searchBusStationByKeyword(busstationname);
}
var sis5,stop_id,stationKeyword;
function search_line(lineid,linename,pMainId,pId,pTotal,pMainTotal)
{
	$("#overlay").show();
	$("#loading").show();
	modal("show");
	var id, parent;
	var busSearchNum = $("#busSearchNum").val();
	$("#resultStopLine li div.detail").empty();
	$("#resultStopLine li div.detail").hide();
	stop_id ="stop_detail_"+pMainId+"_" + pId;
	$("#resultStopLine li a").removeClass("station_active");
	$("#station_"+pMainId+"_"+ pId).addClass("station_active");
	stationKeyword = arrStationName[pMainId];
	sis5 = new MSISSearch();
	var buslineid = new MSearchPointPara();
	sis5.setSISCallbackFunction(busLineIdCallBack); 
	buslineid.setCitycode(citycode);
	buslineid.setId(linename);
	buslineid.setPageSum(1);
	buslineid.setNumber(busSearchNum);
	buslineid.setBatch(1);
	sis5.searchBusLineById(buslineid);
}
function search_line_by_rect(lineid,linename,pMainId,pId,pTotal,pMainTotal)
{
	$("#overlay").show();
	$("#loadingRect").show();
	modal("show");
	var id, parent;
	var rectSearchNum = $("#rectSearchNum").val();
	rectDataNum = rectSearchNum;
	hide_all_rect_poi();
	var poiShow = parseInt(pMainId) + 1;
	mapObj.showPointById(poiShow,true);
	$("#resultRect li div.detail").empty();
	$("#resultRect li div.detail").hide();
	stop_id ="stop_detail_"+pMainId+"_" + pId;
	$("#resultRect li a").removeClass("station_active");
	$("#station_"+pMainId+"_"+ pId).addClass("station_active");
	stationKeyword = arrRectData[pMainId]["name"];
	sis5 = new MSISSearch();
	var buslineid = new MSearchPointPara();
	sis5.setSISCallbackFunction(busLineIdCallBack); 
	buslineid.setCitycode(citycode);
	buslineid.setId(linename);
	buslineid.setPageSum(1);
	buslineid.setNumber(rectDataNum);
	buslineid.setBatch(1);
	sis5.searchBusLineById(buslineid);
}
function search_line_by_keyword(lineid,linename,pMainId,pId,pTotal,pMainTotal)
{
	$("#overlay").show();
	$("#loadingCat").show();
	modal("show");
	var id, parent;
	var catSearchNum = $("#keySearchNum").val();
	catDataNum = catSearchNum;
	hide_all_poi();
	var poiShow = parseInt(pMainId) + 1;
	mapObj.showPointById(poiShow,true);
	$("#resultCat li div.detail").empty();
	$("#resultCat li div.detail").hide();
	stop_id ="stop_detail_"+pMainId+"_" + pId;
	$("#resultCat li a").removeClass("station_active");
	$("#station_"+pMainId+"_"+ pId).addClass("station_active");
	stationKeyword = arrRectData[pMainId]["name"];
	sis5 = new MSISSearch();
	var buslineid = new MSearchPointPara();
	sis5.setSISCallbackFunction(busLineIdCallBack); 
	buslineid.setCitycode(citycode);
	buslineid.setId(linename);
	buslineid.setPageSum(1);
	buslineid.setNumber(20);
	buslineid.setBatch(1);
	sis5.searchBusLineById(buslineid);
}

function list_search_line(pId,pTotal)
{
	var id, parent;
	for(var i = 0;i<pTotal;i++)
	{
		$("#stop_"+i).hide();
		$("#list_station_" + +i).removeClass("active");
	}
	$("#list_station_" + pId).addClass("active");
	$("#stop_" + pId).show();
}

function list_next(pagenum){
	if(list_cur_num<pagenum-1){
		for(var i = 0;i<pagenum;i++){
	
			var id="station_list_"+i;
			$("#"+id).hide();
		}
		list_cur_num = list_cur_num+1;
		var show_id="station_list_"+list_cur_num;
		$("#"+show_id).show();
	}else{
		
		var show_id="station_list_"+pagenum;
		$("#"+show_id).show();
	}
}
function list_pre(pagenum){
	if(list_cur_num==0){}else{
		if(list_cur_num<pagenum){
			for(var i = 0;i<pagenum;i++){
		
				var id="station_list_"+i;
				$("#"+id).hide();
			}
			list_cur_num = list_cur_num-1;
			var show_id="station_list_"+list_cur_num;
			$("#"+show_id).show();
		}
	}
}
function list_selected(pIndex,pagenum)
{
	list_cur_num = pIndex;
	if(list_cur_num==0){}else{
		if(list_cur_num<pagenum){
			for(var i = 0;i<pagenum;i++){
		
				var id="station_list_"+i;
				$("#"+id).hide();
			}
			var show_id="station_list_"+list_cur_num;
			$("#"+show_id).show();
		}
	}
}
function list_all(pagenum){
		for(var i = 0;i<pagenum;i++){
	
			var id="station_list_"+i;
			$("#"+id).show();
		}
	
}
var coor;
var sis6;
var rectDataNum = 20;
function searchByRectAndPolygon()
{
	$("#overlay").show();
	$("#loadingRect").show();
	modal("show");
	fullscreenMode("2");
	map_stat('4');
    $("#rectDetailCont").show();            
    $("#catDetailCont").hide();
	$("#detailCont").hide();
	var keyword = $("#txtRectSearch").val();
	var searchType = $("#rectType a").attr("rel");
	var pageSum = "1";
	var buffer = "0";
	var type = "rect";
	if(keyword == strEnterRect || keyword == strEnterRectAll)
	{
		keyword = "";
	}
	var rectSearchNum = $("#rectSearchNum").val();
	rectDataNum = rectSearchNum;
	if(searchType == "公交线路")
	{	
		var vPointCoor = coor.replace(/;/g,",");
		sis6 = new MSISSearch();
		sis6.setSISCallbackFunction(myfunc_busLineInFigure); 
		var sp = new MSearchSpatialPara();
		sp.setKeyword(keyword);
		sp.setBounds(vPointCoor);
		sp.setPageSum(1);
		sp.setBatch(route_cur_num + 1);	
		sp.setNumber(vRecordPerPage);
		sis6.busLineInFigure(sp);
	}else{
		sis6 = new MSISSearch();
		sis6.setSISCallbackFunction(searchByRectAndPolygonCallBack); 
		var searchSpatialPara = new MSearchSpatialPara();
		searchSpatialPara.setKeyword(keyword);
		if($("#rectType a").html() == "全部单位")
		{
			searchType = searchType.replace(/\+摩托车服务/g,"");	
		}
		searchSpatialPara.setSearchType(searchType);
		searchSpatialPara.setPageNum(vRecordPerPage);
		searchSpatialPara.setPageSum(1);
		searchSpatialPara.setBatch(rect_cur_num + 1);
		searchSpatialPara.setNumber(rectDataNum);
		searchSpatialPara.setBuffer(buffer);
		searchSpatialPara.setType(type);
		if (gold == 1) {
			searchSpatialPara.setBounds(coor);
		} else if (gold == 2) {
			searchSpatialPara.setCoor(coor);
		}	
		sis6.searchByRectAndPolygon(searchSpatialPara);
	}
} 
var rect_cur_num = 0;
function rect_next(pagenum){

	if(rect_cur_num<pagenum-1){
		rect_cur_num = rect_cur_num+1;
		rect_to(rect_cur_num,pagenum);
	}
}
function rect_pre(pagenum){
	if(rect_cur_num==0){}else{
		if(rect_cur_num<pagenum){
			rect_cur_num = rect_cur_num-1;
			rect_to(rect_cur_num,pagenum);
		}
	}
}
function rect_to(pPage,pagenum)
{
		rect_cur_num = pPage;
		if(rect_cur_num<pagenum){
			rect_cur_num = pPage;
			searchByRectAndPolygon();
		}
}
function rect_draw_page(pagenum)
{
		var strPage = "";
		var startPageNo = 0;
		
		if(rect_cur_num == (pagenum-1))
		{
			startPageNo = (Math.ceil(rect_cur_num/4) - 1) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(rect_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}		
		}
		else if(rect_cur_num == 0 || rect_cur_num%4 == 0)
		{
			for(var i = rect_cur_num;i<pagenum;i++){
				if(i < (rect_cur_num + 5))
				{
					if(rect_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
					
				}else{
					break;	
				}
			}
		}else{
			startPageNo = Math.floor(rect_cur_num/4) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(rect_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:rect_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}		
		}
		var pMode = 0;
		if($("#rectType a").attr("rel") == "公交IC卡充值点" || $("#rectType a").attr("rel") == "公交ic卡充值点")
		{
			pMode = 1;
		}
		
		var k = rect_cur_num * vRecordPerPage;	
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		for(var i = 0;i<arrRectData.length;i++)
		{
				drawRectPoint(arrRectData[i]["name"],arrRectData[i]["type"],arrRectData[i]["address"],arrRectData[i]["tel"],arrRectData[i]["postcode"],arrRectData[i]["route_no"],arrRectData[i]["x"],arrRectData[i]["y"],k,pMode);
			k++;
		}
		$("#rect_paging").html(strPage);
		redrawRect();	
}
var route_cur_num = 0;
function route_next(pagenum){

	if(route_cur_num<pagenum-1){
		
		route_cur_num = route_cur_num+1;
		route_to(route_cur_num,pagenum);
	}
}
function route_pre(pagenum){
	if(route_cur_num==0){}else{
		if(route_cur_num<pagenum){
			route_cur_num = route_cur_num-1;
			route_to(route_cur_num,pagenum);
		}
	}
}
function route_to(pPage,pagenum)
{	
		route_cur_num = pPage;
		if(route_cur_num<pagenum){
			route_cur_num = pPage;
			if(trim($("#detailCont").css("display")) == "block" || trim($("#detailCont").css("display")) == "inline")
			{
				search_busl_map();
			}else{
				if(vTabIndex == "5")
				{
					searchCenterKeyword();	
				}else{
					
					searchByRectAndPolygon();
				}				
			}
		}
}
function route_draw_page(pagenum)
{
		var strPage = "";
		var startPageNo = 0;	
		
		if(route_cur_num == (pagenum-1))
		{
			startPageNo = (Math.ceil(route_cur_num/4) - 1) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(route_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}	
	
		}
		else if(route_cur_num == 0 || route_cur_num%4 == 0)
		{
			for(var i = route_cur_num;i<pagenum;i++){
				if(i < (route_cur_num + 5))
				{
					if(route_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
					
				}else{
					break;	
				}
			}
			
		}else{
			startPageNo = Math.floor(route_cur_num/4) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(route_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:route_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}	
		
		}
		if($("#detailCont").css("display") == "none")
		{
			if(vTabIndex == "5")
			{
				drawCircle();	
			}else if(vTabIndex == "2"){
				redrawRect();
			}	
		}
		$("#route_paging").html(strPage);
}
function openall_rect_div(){
	$("#rect_green_icon").attr("src","../elements/image/map/map_new/green_icon_minus.gif");
	$("#rect_green_icon").attr("title",strCollapseAll);
	var rectSearchNum = $("#rectSearchNum").val();
	for(var i=0;i<rectSearchNum;i++){
		var temp_divname = "#r"+i+"_div";
		$(temp_divname).show();     
	}

	$('#rect_op_cl').attr("href","javascript:clall_rect_div()");
}
function clall_rect_div(){
	$("#rect_green_icon").attr("src","../elements/image/map/map_new/green_icon_plus.gif");
	$("#rect_green_icon").attr("title",strExpandAll);
	var rectSearchNum = $("#rectSearchNum").val();
	for(var i=0;i<rectSearchNum;i++){
		var temp_divname = "#r"+i+"_div";
		$(temp_divname).hide(); 

	}

	$('#rect_op_cl').attr("href","javascript:openall_rect_div()");
}
function show_all_rect_poi(){
	var n = $("input[name='rect_poi']").length;
	for(var i=0;i<n;i++){
		var poi_id = i+1;
		mapObj.showPointById(poi_id,true);
		document.getElementsByName("rect_poi")[i].checked=true;
	}
}
function hide_all_rect_poi(){
	var n = $("input[name='rect_poi']").length;
	for(var i=0;i<n;i++){
		var poi_id = i+1;
		mapObj.showPointById(poi_id,false);
		document.getElementsByName("rect_poi")[i].checked=false;
	}
}
function check_all_rect_poi(){
	if(document.getElementsByName("all_rect_poi")[0].checked==true){
		show_all_rect_poi();
	}else{
		hide_all_rect_poi();
	}
}
function ad_rect_poi_one(e,myid){
	if(e.checked==true){
		mapObj.showPointById(myid,true);
		mapObj.openTipById(myid);
	}else{
		mapObj.showPointById(myid,false);
	}
}
function closs_rect_search(){
	mapObj.removeAllOverlays();
	drawHistoryPoint();
	$('#resultRect').html("");          
}
function output(event)
{
   var xy = event.args.substring("11",event.args.lastIndexOf(","));
   
   if (gold == 1) {
	   var poi_xy = xy.split(",");
	   var poiXY = poi_xy[0] + ";" + poi_xy[1] + ";" + poi_xy[2] + ";" + poi_xy[3];
	   coor = poiXY;

   } else if (gold == 2) {
	   var poi_xy = xy.split(",");
	   coor = xy + "," + poi_xy[0] + "," + poi_xy[1];

   }
}
function rectDrawn(event)
{
	output(event);
	rect_cur_num = 0;
	route_cur_num = 0;
	searchByRectAndPolygon();
}
function polygonDrawn(event)
{
	output(event);
}
function beginDrawRectOnMap()
{
	gold = 1;
	mapObj.removeAllOverlays();
	drawHistoryPoint();
	var rectStyle = new MStyle();
	rectStyle.lineColor = 0xFFFFFF;//0x00ff00;
	rectStyle.lineSize = 3;
	rectStyle.fillOpacity = 30;
	rectStyle.fillColor = 0xA57474;
	mapObj.beginDrawRectOnMap(rectStyle);
	mapObj.addEventListener(MMap.EVENT_RECT_DRAWN, rectDrawn);
}
var key_v;
var sis7;
var keyDataNum = 20;
function searchByCat()
{
	key_v = $("#txtCatSearch").val();
	var searchType = $("#catType a").attr("rel");
	var pageSum = "1";
	var batch = "1";
	var buffer = "0";
	var type = "rect";
	if(key_v == strEnterCat)
	{
		key_v = "";
	}
	$("#overlay").show();
	$("#loadingCat").show();
	modal("show");
	fullscreenMode("2");
    $("#catDetailCont").show();      
    $("#rectDetailCont").hide(); 
	$("#detailCont").hide();
	mapObj.removeAllOverlays();
	var keySearchNum = $("#keySearchNum").val();
	var keySearchRange = $("#keySearchRange").val();
	keyDataNum = keySearchNum;      
	sis7 = new MSISSearch();
	sp = new MSearchPointPara();
	sis7.setSISCallbackFunction(catNameCallBack);
	sp.setCitycode(citycode);
	sp.setKeyword(key_v);
	sp.setPageSum(1);
	sp.setBatch(cat_cur_num + 1);	
	sp.setNumber(vRecordPerPage);
	if(vTabIndex == "3")
	{
		var catVal = document.form1.txtCatSearch.value;
		if(catVal == strEnterCat)
		{
			catVal = "";
		}
		var catSearchType = $("#catType a").attr("rel");
		if(catVal == "")
		{
			catVal = catSearchType;
		}else{
			catVal = catSearchType + " - " + catVal;
		}
		$("#catName").html(catVal);
		sp.setSearchType(catSearchType);
		vCategoryBool = false;
		map_stat('5');
	}else{
		sp.setRange(keySearchRange);
		sp.setSearchType(sortedType);
		
		var catVal = document.form1.txtCatSearch.value;
		if(catVal == strEnterCat)
		{
			catVal = "";
		}
		$("#catName").html(catVal);
		vKeywordBool = false;	
		map_stat('6');
	}
	sis7.searchByKeyword (sp);  
}
function searchByCenterKeyword()
{
		$("#overlay").show();
		$("#loadingCat").show();
		modal("show");
		fullscreenMode("2");
		$("#catDetailCont").show();      
    	$("#rectDetailCont").hide(); 
		$("#detailCont").hide();
		map_stat('7');
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		var centerSearchNum = $("#keySearchNum").val();
		var centerKeyword = $("#txtCenterSearch").val();
		var centerSearchRange = $("#centerSearchRange a").attr("rel");
		var centerSearchType = $("#centerType a").attr("rel");
		$("#catName").html(centerKeyword);
		sis = new MSISSearch();
		start = new MSearchPointPara();
		sis.setSISCallbackFunction(centerKeywordCallBack);
		start.setCitycode(citycode);
		start.setKeyword(centerKeyword);
		start.setSearchType(sortedType);
		centerSearchNum = 50; 
		start.setPageSum(1);
		start.setBatch(start_batch + 1);	
		start.setNumber(centerSearchNum);
		sis.searchByKeyword(start); 
}
function searchCenterKeyword()
{
	$("#overlay").show();
	$("#loadingCat").show();
	modal("show");
	$("#center_search_btn").hide();
	fullscreenMode("2");
	mapObj.removeAllOverlays();
	var centerSearchNum = $("#keySearchNum").val();
	var centerSearchRange = $("#centerSearchRange a").attr("rel");
	var centerSearchType = $("#centerType a").attr("rel");
	$("#catName").html(cen_name);
	if(centerSearchType == "公交线路")
	{	
		sis6 = new MSISSearch();
		sis6.setSISCallbackFunction(busLineInFigure); 
		var sp = new MSearchRoutPara();
		sp.setCenterX(cen_x);
		sp.setCenterY(cen_y);
		sp.setPageSum(1);
		sp.setBatch(route_cur_num + 1);	
		sp.setNumber(vRecordPerPage);
		sp.setRange(centerSearchRange);
		sis6.searchLocalBusLineByPoint(sp);
	}else{
		sis7 = new MSISSearch();
		sis7.setSISCallbackFunction(catNameCallBack);
		spCenter = new MSearchPointPara();
		spCenter.setCitycode(citycode);
		spCenter.setPageSum(1);
		spCenter.setBatch(cat_cur_num + 1);	
		spCenter.setNumber(vRecordPerPage);
		spCenter.setSearchType(centerSearchType);
		spCenter.setCenX(cen_x);	
		spCenter.setCenY(cen_y);	
		spCenter.setRange(centerSearchRange);
		sis7.localSearchByXY(spCenter); 

	}
}
function closs_search(num){
	mapObj.removeAllOverlays();
	drawHistoryPoint();
	$('#resultCat').html("");           
}
function show_d_div(e){
	var show_div_name = e.id + "_div";
	var t0 = e.id+"_0";
	var t1 = e.id+"_1";
	var show_div_name_n = $("#" + show_div_name).css("display");
	 if(show_div_name_n=="none"){
		$("#" + show_div_name).show();
	 }else{
		$("#" + show_div_name).hide();
	 }
}
function show_div_c(e,num){
	var show_div_name = e.id + "_div";
	for(var i=0;i<num;i++){
		var str = "s"+i+"_div";
		$("#" + str).css("borderColor","#ffffff");
		$("#" + str).css("backgroundColor","#ffffff");
	}
	$("#" + show_div_name).css("borderColor","#ffffff");
	$("#" + show_div_name).css("backgroundColor","#ffffff");
}
var cat_cur_num = 0;
function cat_next(pagenum){

	if(cat_cur_num<pagenum-1){
		cat_cur_num = cat_cur_num+1;
		cat_to(cat_cur_num,pagenum);
	}
	
}
function cat_pre(pagenum){
	if(cat_cur_num==0){}else{
		if(cat_cur_num<pagenum){
			cat_cur_num = cat_cur_num-1;
			cat_to(cat_cur_num,pagenum);
		}
	}
}
function cat_to(pPage,pagenum)
{
		cat_cur_num = pPage;
		if(cat_cur_num<pagenum){
			cat_cur_num = pPage;
			if(vTabIndex == "5")
			{
				searchCenterKeyword();	
			}else{
				searchByCat();
			}
		}
}
function cat_draw_page(pagenum)
{
		var strPage = "";
		var startPageNo = 0;
		if(cat_cur_num == (pagenum-1))
		{
			startPageNo = (Math.ceil(cat_cur_num/4) - 1) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(cat_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}		
		}
		else if(cat_cur_num == 0 || cat_cur_num%4 == 0)
		{
			for(var i = cat_cur_num;i<pagenum;i++){
				if(i < (cat_cur_num + 5))
				{
					if(cat_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
					
				}else{
					break;	
				}
			}
		}else{
			startPageNo = Math.floor(cat_cur_num/4) * 4; 
			for(var i = startPageNo;i<pagenum;i++){
				if(i < (startPageNo + 5))
				{
					if(cat_cur_num == i)
					{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" class=\"active\">&nbsp;"+(i+1)+"</a>";
					}else{
						strPage += 	"<a href=\"javascript:cat_to("+i+","+pagenum+")\" >&nbsp;"+(i+1)+"</a>";
					}
				}else{
					break;	
				}
			}		
		}
		var pMode = 0;
		if(vTabIndex == "3" && ($("#catType a").attr("rel") == "公交IC卡充值点" || $("#catType a").attr("rel") == "公交ic卡充值点"))
		{
			pMode = 1;
		}
		var k = cat_cur_num * vRecordPerPage;	
		mapObj.removeAllOverlays();
		drawHistoryPoint();
		for(var i = 0;i<arrRectData.length;i++)
		{
			drawRectPoint(arrRectData[i]["name"],arrRectData[i]["type"],arrRectData[i]["address"],arrRectData[i]["tel"],arrRectData[i]["postcode"],arrRectData[i]["route_no"],arrRectData[i]["x"],arrRectData[i]["y"],k,pMode);
			k++;
		}
		if(vTabIndex == "5")
		{
			drawSinglePoint(cen_x,cen_y,"center_point",cen_name);
			drawCircle();
			
		}
		$("#cat_paging").html(strPage);
}
var tip_num = keyDataNum;
function show_div_tip(tip_i){
	tip_i = tip_i - 1 ;
	var show_div_name = "s"+tip_i+"_div";
	for(var i=0;i<tip_num;i++){
		var str = "s"+i+"_div";
		$("#" + str).css("borderColor","#ffffff");
		$("#" + str).css("backgroundColor","#ffffff");
	}
	$("#" + show_div_name).css("borderColor","#ffffff");
	$("#" + show_div_name).css("backgroundColor","#ffffff");
}
function borderize(what,color,color2){
	what.style.borderColor=color
	what.style.backgroundColor=color2
}
function borderize_on(e){
	if (document.all)
		source3=event.srcElement
	else if (document.getElementById)
		source3=e.target
	if (source3.className=="resultlist"){
		borderize(source3,"#999999","#EFEFEF")
	}
	else{
		while(source3.tagName!="DIV"){
			source3=document.getElementById? source3.parentNode : source3.parentElement
			if (source3.className=="resultlist")
				borderize(source3,"#999999","#EFEFEF")
		}
	}
}
function borderize_off(e){
	if (document.all)
		source4=event.srcElement
	else if (document.getElementById)
		source4=e.target
	if (source4.className=="resultlist")
		borderize(source4,"#D2CFDC","#D2CFDC")
	else{
		while(source4.tagName!="DIV"){
			source4=document.getElementById? source4.parentNode : source4.parentElement
			if (source4.className=="resultlist")
				borderize(source4,"#D2CFDC","#D2CFDC")
		}
	}
}
function openall_div(){
	$("#green_icon").attr("src","../elements/image/map/map_new/green_icon_minus.gif");
	$("#green_icon").attr("title",strCollapseAll);
	var keySearchNum = $("#keySearchNum").val();
	for(var i=0;i<keySearchNum;i++){
		var temp_divname = "#s"+i+"_div";
		$(temp_divname).show();     
	}
	$('#lc_op_cl').attr("href","javascript:clall_div()");
}
function clall_div(){
	$("#green_icon").attr("src","../elements/image/map/map_new/green_icon_plus.gif");
	$("#green_icon").attr("title",strExpandAll);
	 var keySearchNum = $("#keySearchNum").val();
	for(var i=0;i<keySearchNum;i++){
		var temp_divname = "#s"+i+"_div";
		$(temp_divname).hide(); 
	}
	$('#lc_op_cl').attr("href","javascript:openall_div()");
}
function zoom(y,x){
		mapObj.setCenterByLatLng(y,x);
		mapObj.setZoomLevel(17);
}
function show_div_ul(e,num){
		var show_div_name = e.id ;
		for(var i=0;i<num;i++){
			var str = "s"+i+"_div";
			$("#" + str).css("borderColor","#ffffff");
			$("#" + str).css("backgroundColor","#ffffff");
		}
		$("#" + show_div_name).css("borderColor","#ffffff");
		$("#" + show_div_name).css("backgroundColor","#ffffff");
}
function show_all_poi(){
	var n = $("input[name='ad_poi']").length;
	for(var i=0;i<n;i++){

		var poi_id = i+1;
		mapObj.showPointById(poi_id,true);
		document.getElementsByName("ad_poi")[i].checked=true;
	}
}
function hide_all_poi(){
	var n = $("input[name='ad_poi']").length;
	for(var i=0;i<n;i++){
		var poi_id = i+1;
		mapObj.showPointById(poi_id,false);
		document.getElementsByName("ad_poi")[i].checked=false;
	}
}
function check_all_ad_poi(){
	if(document.getElementsByName("all_ad_poi")[0].checked==true){
		show_all_poi();
	}else{
		hide_all_poi();
	}
}
function ad_poi_one(e,myid){
	if(e.checked==true){
		mapObj.showPointById(myid,true);
		mapObj.openTipById(myid);
	}else{
		mapObj.showPointById(myid,false);
	}
}
function resetMap()
{
	var centrePoint = new MLatLng(city_center_index);
	mapObj.setZoomAndCenter(10,centrePoint);

}
var boolMaptool = false;
function openMaptool()
{
	if(boolMaptool == true)
	{
		$('#maptool').slideDown();
		$('#maptoolArrow img').attr("src","../elements/image/map/map_new/grey_icon_up.gif");
		$('#maptoolArrow img').attr("title",strCollapse);
		boolMaptool = false;
	}else{
		$('#maptool').slideUp();
		$('#maptoolArrow img').attr("src","../elements/image/map/map_new/grey_icon_down.gif");
		$('#maptoolArrow img').attr("title",strExpand);
		boolMaptool = true;
	}
}
function setResultHeight()
{
	var ph;
	var res = document.getElementById("result");
	var set = document.getElementById("setting");   
	var cont = $("#detailCont").css("height");  

	cont =  cont.substr(0,cont.length - 2);
	ph = cont - (res.offsetTop  -  set.offsetTop) + "px";
	$("#result").css("height",ph);
	
	res = document.getElementById("resultBusLine");
	set = document.getElementById("setting");   
	ph = cont - (res.offsetTop  -  set.offsetTop) + "px";
	$("#resultBusLine").css("height",ph);
	
	res = document.getElementById("resultStopLine");
	set = document.getElementById("setting");   
	ph = cont - (res.offsetTop  -  set.offsetTop) + "px";
	$("#resultStopLine").css("height",ph);
	
	cont = $("#rectDetailCont").css("height");
	cont =  cont.substr(0,cont.length - 2);
	res = document.getElementById("resultRect");
	set = document.getElementById("rectSetting");   
	ph = cont - (res.offsetTop  -  set.offsetTop) + "px";
	$("#resultRect").css("height",ph);
	
	cont = $("#catDetailCont").css("height");
	cont =  cont.substr(0,cont.length - 2);
	res = document.getElementById("resultCat");
	set = document.getElementById("catSetting");    
	ph = cont - (res.offsetTop  -  set.offsetTop) + "px";
	$("#resultCat").css("height",ph);
}
function resizeApp()
{
	var bodyHeight  = getWindowHeight();
	var bodyWidth  = getWindowWidth();
	var pH, pW;
	var vH, vW;
	var display = $("#detailCont").css("display");
	if( bodyHeight - 595 > 0){
		vH = bodyHeight - 145;
		ph = vH + "px" ;
		$("#mapObj").css("height",ph);
		$("#fmptest").attr("height",vH);
		$("#detailCont").css("height",ph);
		$("#rectDetailCont").css("height",ph);
		$("#catDetailCont").css("height",ph);
		setResultHeight();
		ph = vH + 2 + "px" ;
		$("#divider").css("height",ph);
		ph = ((vH + 2) / 2) + "px" ;
		$("#divider").css("line-height",ph);
		ph = vH + 51 + "px" ;
		$("#left_border").css("height",ph);
		$("#right_border").css("height",ph);
  }else{
		vH = 595 - 145;
		ph = vH + "px" ;
		$("#mapObj").css("height",ph);
		$("#fmptest").attr("height",vH);
		$("#detailCont").css("height",ph);
		$("#rectDetailCont").css("height",ph);
		$("#catDetailCont").css("height",ph);
		setResultHeight();
		ph = vH + 2 + "px" ;
		$("#divider").css("height",ph);
		ph = ((vH + 2) / 2) + "px" ;
		$("#divider").css("line-height",ph);
		ph = vH + 51 + "px" ;
		$("#left_border").css("height",ph);
		$("#right_border").css("height",ph);
	}
	if( bodyWidth - 1014 > 0){
		vW = bodyWidth - 30;
		pW = vW + "px" ;
		$("#map_container").css("width",pW);
		$("#nav_container").css("width",pW);
		$("#container").css("width",pW);
		pW = vW - 16 + "px" ;
		$("#nav_bar").css("width",pW);
		pW = vW - 367 + "px" ;
		if(isFull)
		{
			pW = vW - 367 + 334 + "px" ;
			$("#mapObj").css("width",pW);
			pW = vW - 365 + 334 + "px" ;
			$("#overlay").css("width",pW);
		}else{
			pW = vW - 365 + 48 + "px" ;
			$("#mapObj").css("width",pW);
			pW = vW - 365 + 48 + "px" ;
			$("#overlay").css("width",pW);
		}
		pW = vW - 22 + "px" ;
		$("#search_box").css("width",pW);
	}else{
		vW = 1014 - 30;
		pW = vW + "px" ;
		$("#map_container").css("width",pW);
		$("#nav_container").css("width",pW);
		$("#container").css("width",pW);
		pW = vW - 16 + "px" ;
		$("#nav_bar").css("width",pW);
		pW = vW - 367 + "px" ;
		if(isFull)
		{
			pW = vW - 367 + 334 + "px" ;
			$("#mapObj").css("width",pW);
			pW = vW - 367 + 334 + "px" ;
			$("#overlay").css("width",pW);
		}else{
			pW = vW - 365 + 48 + "px" ;
			$("#mapObj").css("width",pW);
			pW = vW - 365 + 48 + "px" ;
			$("#overlay").css("width",pW);
		}
		pW = vW - 22 + "px" ;
		$("#search_box").css("width",pW);
	}
	$("#language_bar").show();	
}
function getWindowHeight() 
{
	if (window.self && self.innerHeight) {
		return self.innerHeight;
	}
	
	if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	}
	return 0;
}
function getWindowWidth() 
{
	if (window.self && self.innerWidth) {
		return self.innerWidth;
	}
	if (document.documentElement && document.documentElement.clientWidth) {
		return document.documentElement.clientWidth;
	}
	return 0;
} 
var switchSearchIndex = "1";
var vBusSearchBool = true;
var vRouteSearchBool = true;
var vStopSearchBool = true;
function switchSearchChk(pIndex)
{
	if(pIndex == "2"){
		$("#route_search").show();
		$("#bus_stop_search").hide();
	}else if(pIndex == "3"){
		$("#bus_stop_search").show();
		$("#route_search").hide();
	}
}
function switchSearch(pIndex)
{
	switchSearchIndex = pIndex;
	if(pIndex == "1")
	{
		$("#result").show();
		$("#result_start_name").show();
		$("#result_end_name").show();
		$("#bus_result_header").show();
		$("#img_switch").show();
		if(vBusSearchBool == false)
		{
			$("#route_setting").show();
			$("#bus_result_info").show();
		}
		$("#imgBusSetting").show();
		$("#resultBusLine").hide();
		$("#route_result_info").hide();
		$("#route_result_header").hide();
		$("#stop_result_info").hide();
		$("#resultStopLine").hide();
		$("#stop_result_header").hide();            
		$("#img_refresh").hide();   			
		$("#radioBusType1").attr("checked","checked");  
		setResultHeight();
	}else if(pIndex == "2"){
		$("#resultBusLine").show();
		if(vRouteSearchBool == false)
		{
			$("#route_result_info").show();
		}
		$("#route_result_header").show();
		$("#img_refresh").show();
		$("#result").hide();
		$("#result_start_name").hide();
		$("#result_end_name").hide();
		$("#bus_result_info").hide();
		$("#bus_result_header").hide();
		$("#stop_result_info").hide();
		$("#resultStopLine").hide();
		$("#stop_result_header").hide();
		$("#route_setting").hide();
		$("#bus_search_btn").hide();
		$("#img_switch").hide();    
		$("#radioBusType2").attr("checked","checked");          
		setResultHeight();
	}else if(pIndex == "3"){
		if(vStopSearchBool == false)
		{
			$("#stop_result_info").show();
		}
		$("#resultStopLine").show();
		$("#stop_result_header").show();
		$("#img_refresh").show();
		$("#route_result_header").hide();
		$("#route_result_info").hide();
		$("#result").hide();            
		$("#result_start_name").hide();
		$("#result_end_name").hide();
		$("#bus_result_info").hide();
		$("#bus_result_header").hide();
		
		$("#resultBusLine").hide();
		$("#img_switch").hide();    
		$("#route_setting").hide();
		$("#bus_search_btn").hide();
		$("#radioBusType3").attr("checked","checked");          
		setResultHeight();
	}
}
  
function refreshSearch()
{
	if(switchSearchIndex == "2")
	{
		search_busl_map();
	}else if(switchSearchIndex == "3")
	{
		search_buss_map();
	}
}

function openSetting(pId)
{
	if($("#"+pId).css("display") == "none")
	{
		$("#"+pId).show();
	}else{
		$("#"+pId).hide();
	}
	setResultHeight();
}
var boolTraffic = false;
function traffic_report(){
	if(boolTraffic == false)
	{
		$("div#traffic a").addClass("active");
		$("#chkTraffic").attr("checked","checked");
		boolTraffic = true;
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		$("#hours").html(h);
		$("#minutes").html(m);
		$("#trafficHeader").slideDown();
		mapObj.setZoomAndCenter(11, new MLatLng('hrlphplnJOOE','fjtekqrposNKGE'))
		mapObj.addTrafficLandscapePointLayer(true);
	}else{
		$("div#traffic a").removeClass("active");
		$("#chkTraffic").attr("checked","");
		mapObj.addTrafficLandscapePointLayer(false);
		boolTraffic = false;
		$("#trafficHeader").slideUp();
	}
}
function modal(pType)
{
	var pH, pW;

	if(pType == "show")
	{
		pH = $("#map_container").height();
		pW = $("#map_container").css("width");
		$("#overlayLoad img").css("height",pH);
		$("#overlayLoad img").css("width",pW);
		$("#overlayLoad").show();
	}else{
		$("#overlayLoad").hide();
	}
}
function refresh_search()
{
	if(vTabIndex == "5")
	{
		searchByCenterKeyword();
		
	}else{
		searchByCat();
	}
}
function printmap()
{
	window.print();
}
function map_stat(pCategory)
{
	if(vCaptureStatistic == true)
	{
		var data, url, pStrCondition, pKeyword;	
		switch(pCategory)
		{
			case '1': 
					pStrCondition = $("#startName_bus").val()+"|"+$("#endName_bus").val()+"|"+$("#routeType a").attr("rel");
					break;
			case '2': 
					pStrCondition = $("#txtRouteSearch").val();
					break;
			case '3': 
					pStrCondition = $("#txtStopSearch").val();
					break;
			case '4': 
					pKeyword = $("#txtRectSearch").val();
					if(pKeyword == strEnterRect || pKeyword == strEnterRectAll)
					{
						pKeyword = "";
					}
					if($("#rectType a").html() == "全部单位" || $("#rectType a").html() == "All Type")
					{
						pStrCondition = pKeyword+"|"+$("#rectType a").html();					
					}else{
						pStrCondition = pKeyword+"|"+$("#rectType a").attr("rel");				
					}
					break;
			case '5': 	
					pKeyword = $("#txtCatSearch").val();
					if(pKeyword == strEnterCat)
					{
						pKeyword = "";
					}
					pStrCondition = pKeyword+"|"+$("#catType a").attr("rel");
					break;
			case '6': 
					pStrCondition = $("#txtCatSearch").val();
					break;
			case '7': 
					if($("#centerType a").html() == "全部单位" || $("#centerType a").html() == "All Type")
					{
						pStrCondition = $("#txtCenterSearch").val()+"|"+$("#centerType a").html()+"|"+$("#centerSearchRange a").attr("rel");				
					}else{
						pStrCondition = $("#txtCenterSearch").val()+"|"+$("#centerType a").attr("rel")+"|"+$("#centerSearchRange a").attr("rel");			
					}
					break;
	   }
		url = "../tracker/map_statpool.php";
		data = "uFuncType=" + pCategory;
		data += "&uSearch=" + pStrCondition;
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			dataType: "html",
			async: true,
			beforeSend: function(){
			},
			success: function(data){
			},
			complete: function(){
				return false;
			}
		});
	}
}
function toFromOnChange(cmbId, cmbVal)
{
	var otherSelectId = (cmbId =="cmbVenueDirection") ? "#cmbTargetDirection" : "#cmbVenueDirection";
	var otherSelectVal = (cmbVal == "to") ? "from" : "to";
	$(otherSelectId).val(otherSelectVal);
}
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;
var vTop = -18;
var contHeight;
function headline_rotate() {
  $("div.headline:eq(0)").animate({top: vTop},"slow", function() {
			contHeight = $(this).height();
			if(contHeight > (vTop * -1))
			{
				vTop -= 18;
			}else{
				vTop = 0;
				$(this).css('top','18px');	
			}
			
    });
}