﻿


var isBus=0;

var isDrive=0;

var nodot=0;

var iszd="";


function drawDrive()
{
	if(pathArray!="undefined")
	{
		clean();


















	}
};


function drawDrivezj()
{
	if(pathArray!="undefined")
	{
		clean();
	}
};


function removeBusline()
{
	if(bmap.buslineDiv)
	{
	    bmap.buslineDiv.clear();
	}
};


function Driveisshowstartend() 
{
    alert(startxy);alert(endxy);
    var start_xy = startxy.split(':');
    var end_xy = endxy.split(':');
    alert(start_xy[1]+"~~~"+start_xy[0]);alert(end_xy[1]+"~~~~"+end_xy[0]);
    setCenter(start_xy[1],start_xy[0]);
    alert(111);
	addPoint(start_xy[1],start_xy[0],startname,startname,'images/qidian.gif','1');
	addPoint(end_xy[1],end_xy[0],endname,endname,'images/zhongdian.gif','1')
	alert(222);
	refresh();
};


function isshowstartend()
{
	var startxy;
	var endxy;
	var temp_lat = latArray[lineNum].split(',');
	var temp_lon = lonArray[lineNum].split(',');
	var temp1=nameArray[lineNum].split(',');
	if(typeof (begininfo)!="undefined")
	{
		if(temp1[0]!=begininfo[0])
		{
			bmap.addPoint('../images/marker1.gif',begininfo[1],begininfo[2],begininfo[0],begininfo[0]);
		}
	}
    if(typeof (endinfo)!="undefined")
	{
		if(temp1[temp1.length-1]!=endinfo[0])
		{
			bmap.addPoint('../images/marker.gif',endinfo[1],endinfo[2],endinfo[0],endinfo[0]);
		}
	}
}


function drawBusline(divName,strlat,strlon)
{
    removeBusline();
	var xyValue='';
	var pArray_lat=strlat.split(',');
	var pArray_lon=strlon.split(',');
	for(var i=0;i<pArray_lat.length;i++)
	{
		if(pArray_lat[i].length>0)
		{
			var left=bmap.toImageX(pArray_lon[i]);
			var top=bmap.toImageY(pArray_lat[i]);
			if(i>0)
			{
			    xyValue+=',';
			}
			xyValue+=(parseInt(left)+','+parseInt(top));
		}
	};
	var objDiv=document.createElement("div");
	objDiv.unselectable="on";
	objDiv.style.zIndex=10;
	objDiv.id='buslineDiv1';
	var myBusline=document.createElement("v:polyline");
	myBusline.filled=false;
	myBusline.style.zIndex=9;
	myBusline.style.position="absolute";
	myBusline.strokecolor=color1;
	myBusline.strokeweight="4pt";
	if(myBusline.points)
	{
		myBusline.points.value=xyValue;
	}
	else 
	{
		myBusline.points=xyValue;
	};
	var strokeobj=document.createElement("v:stroke");
	strokeobj.opacity=(60/100);
	strokeobj.joinstyle="round";
	strokeobj.endcap="round";
	strokeobj.fill="false";
	myBusline.appendChild(strokeobj);
	objDiv.appendChild(myBusline);
	divName.appendChild(objDiv);
};


function drawp2p(args)
{
    var arrpois = args.split(',');
    if(arrpois.length>0)
    {
        for(var i=0; i<arrpois.length-1;i++)
        {
            if(i==0)
            {
                var x1 = arrpois[i].split('-')[1];
                var y1 = arrpois[i].split('-')[0];
                var x2 = arrpois[i+1].split(':')[1];
                var y2 = arrpois[i+1].split(':')[0];
                var ar = x1+','+y1+','+x2+','+y2;
                drawLineByCoordinates(ar,'','');
            }
            else if(i==arrpois.length-1)
            {
                var x1 = arrpois[i].split(':')[1];
                var y1 = arrpois[i].split(':')[0];
                var x2 = arrpois[i+1].split('-')[1];
                var y2 = arrpois[i+1].split('-')[0];
                var ar = x1+','+y1+','+x2+','+y2;
                drawLineByCoordinates(ar,'','');
            }
            else
            {
                var x1 = arrpois[i].split(':')[1];
                var y1 = arrpois[i].split(':')[0];
                var x2 = arrpois[i+1].split(':')[1];
                var y2 = arrpois[i+1].split(':')[0];
                var ar = x1+','+y1+','+x2+','+y2;
                drawLineByCoordinates(ar,'','');
            }
        }
    }
};


function drawbusp2p(lons,lats)
{
    var arrlon = lons.split(',');
    var arrlat = lats.split(',');
    if(arrlon.length>0&&arrlat.length>0)
    {
        for(var i=0; i<arrlon.length-1;i++)
        {
            var x1 = arrlon[i];
            var y1 = arrlat[i];
            var x2 = arrlon[i+1];
            var y2 = arrlat[i+1];
            var ar = x1+','+y1+','+x2+','+y2;
            drawLineByCoordinates(ar,'','');
        }
    }
    setZoomTo(9);
};



function draw(num)
{
	lineNum=num;
	if(latArray!="undefined")
	{
		if(latArray[lineNum]!="undefined")
		{
			
			clean();
			var temp_lat=latArray[lineNum].split(',');
			var temp_lon=lonArray[lineNum].split(',');
			var temp1=nameArray[lineNum].split(',');
			
			addPoint(temp_lon[0],temp_lat[0],temp1[0],temp1[0],'images/qidian.gif',1);
			addPoint(temp_lon[temp_lon.length-1],temp_lat[temp_lat.length-1],temp1[temp1.length-1],temp1[temp1.length-1],'images/zhongdian.gif','1');
			if(iszd!="")
			{
			    var k=0;
			    for(var j =0;j<temp1.length;j++)
			    {
			        if(temp1[j]==iszd)
			        {
			            k=j;
			            break;
			        }
			    }
			    var temp = new Image();
			    temp.src = 'images/marker_small.png';
			    addPoint(temp_lon[k],temp_lat[k],temp1[k],temp1[k],'images/marker_small.png',1);
			}
			refresh();
			
			var temprate=rateArray[lineNum].split(',');
			for(var i=0;i<temprate.length;i++)
			{
				if(temprate[i]==1)
				{
					addPoint(temp_lon[i],temp_lat[i],temp1[i],temp1[i],'images/transfer.gif','1');
				}
			};
			drawbusp2p(lonArray[lineNum],latArray[lineNum]);
			var cx;
			var cy;
			if(temp_lat[0]>temp_lat[temp_lat.length-1])
			cx=temp_lat[temp_lat.length-1]+(temp_lat[0]-temp_lat[temp_lat.length-1])/2;
			else
			cx=temp_lat[0]+(temp_lat[temp_lat.length-1]-temp_lat[0])/2;
			if(temp_lon[0]>temp_lon[temp_lon.length-1])
			cy=temp_lon[temp_lon.length-1]+(temp_lon[0]-temp_lon[temp_lon.length-1])/2;
			else
			cy=temp_lon[0]+(temp_lon[temp_lon.length-1]-temp_lon[0])/2;
			setCenter(cy,cx);
			
		}
	}
};


function Show(i,num,position)
{
	var showwait="showwait"+i;
	document.getElementById(showwait).style.display="block";
	var temp="table"+i;
	if(document.getElementById(temp).style.display=="none")
	{
	    document.getElementById(temp).style.display="block";
	}
	else 
	{
		document.getElementById(temp).style.display="none";
	}
	for(var a=0;a<num;a++)
	{
		temp="table"+a;
		if(a!=i)
		{
		    document.getElementById(temp).style.display="none";
	    }
	}
   document.getElementById(showwait).style.display="none";
};


function ShowDistance(distance)
{

	document.getElementById("showdistance").innerHTML="\u5927\u7ea6"+(distance/1000)+"\u516c\u91cc";




};


function ShowBusDot(b_x,b_y,h,b_name)
{
	var str_of_chk='chk'+lineNum;
	if(document.getElementById(str_of_chk).checked)
	{
		alert("\u663e\u793a\u5168\u90e8\u8f66\u7ad9\u6a21\u5f0f\u4e0b\x2c\u8bf7\u76f4\u63a5\u67e5\u770b\u5730\u56fe\x21");
		return 
	}
    var temp_lat;
    var temp_lon;
	temp_lat = latArray[lineNum].split(',');
	temp_lon = lonArray[lineNum].split(',');
	temp=nameArray[lineNum].split(',');
	delAllPoi();
    addPoint(temp_lon[0],temp_lat[0],temp[0],temp[0],'images/qidian.gif','1');
    addPoint(temp_lon[temp_lon.length-1],temp_lat[temp_lat.length-1],temp[temp.length-1],temp[temp.length-1],'images/zhongdian.gif','1');
	if(b_x!=temp_lat[temp_lat.length-1]&&b_x!=temp_lat[0])
	{

		var startxy;
		var endxy;
        var temp1_lat = latArray[lineNum].split(',');
		var temp1_lon = lonArray[lineNum].split(',');
		var temprate=rateArray[lineNum].split(',');
        if(temprate[h]=='1')
        {
            addPoint(b_y,b_x,b_name,b_name,'images/transfer.gif','1');
		}
		else
		{
		    addPoint(b_y,b_x,b_name,b_name,'images/station.gif','1');
		}
		setCenter(b_y,b_x);
		refresh();
		for(var i=0;i<temprate.length;i++)
		{
		
		    if(temp1_lat[i]!=b_x)
			{
				if(temprate[i]==1)
				{
					addPoint(temp1_lat[i],temp1_lon[i],temp[i],temp[i],'images/transfer.gif',1);
				}
			}
		}
        
		refresh()
	}
	setCenter(b_y,b_x);
};


function showAlzmMinLevelithoutSE()
{
	var str_of_chk='chk'+lineNum;
	if(document.getElementById(str_of_chk).checked)
	{
		var temp_lat=latArray[lineNum].split(',');
		var temp_lon=lonArray[lineNum].split(',');
		delAllPoi();
		tempname=nameArray[lineNum].split(',');
		addPoint(temp_lon[0],temp_lat[0],tempname[0],tempname[0],'images/qidian.gif','1');
		addPoint(temp_lon[temp_lon.length-1],temp_lat[temp_lat.length-1],tempname[tempname.length-1],tempname[tempname.length-1],'images/zhongdian.gif','1');
		var temprate=rateArray[lineNum].split(',');
		for(i=1;i<temprate.length-1;i++)
		{
			if(tempname[i]!='')
			{
				if(temprate[i]==1)
				{
					addPoint(temp_lon[i],temp_lat[i],tempname[i],tempname[i],'images/transfer.gif','1');
				}else 
				{
					addPoint(temp_lon[i],temp_lat[i],tempname[i],tempname[i],'images/station.gif','1');
				}
			}
		}
	}
	else 
	{
		var temp_lat=latArray[lineNum].split(',');
		var temp_lon=lonArray[lineNum].split(',');
		delAllPoi();
		tempname=nameArray[lineNum].split(',');
		addPoint(temp_lon[0],temp_lat[0],tempname[0],tempname[0],'images/qidian.gif','1');
		addPoint(temp_lon[temp_lon.length-1],temp_lat[temp_lat.length-1],tempname[tempname.length-1],tempname[tempname.length-1],'images/zhongdian.gif','1');
		var temprate=rateArray[lineNum].split(',');
		for(var i=0;i<temprate.length;i++)
		{
			if(temprate[i]==1)
			{
				addPoint(temp_lon[i],temp_lat[i],tempname[i],tempname[i],'images/transfer.gif','1');
			}
		}
	}
    
	refresh();
};


function redraw()
{
    if((typeof (latArray)!="undefined"))
    {
	    if(typeof (latArray[lineNum])!="undefined")
	    {
		    removeBusline();
		    drawBusline(bmap.buslineDiv,latArray[lineNum],lonArray[lineNum]);
	    }
    }
	if(isDrive==1)
    {
	    if((typeof (pathArray)!="undefined"))
	    {
		    if(typeof (pathArray)!="undefined")
		    {
			    removeBusline();
			    paintDriveLine(bmap.buslineDiv,pathArray);
		    }
	    }
	}
};


