﻿function load() 
{		    
  	if (GBrowserIsCompatible()) 
	{	
		var map = new GMap2(document.getElementById("map"));
		
    	map.setCenter(new GLatLng(38.41978, 27.12886), 11);
    	map.addControl(new GLargeMapControl());
		map.enableDoubleClickZoom();
    	var mapControl = new GMapTypeControl();
    	map.addControl(mapControl);		
		map.addControl(new GScaleControl());
		map.setMapType(G_NORMAL_MAP);

		
		GEvent.addListener(map, "zoomend", function() 
		{ 
      		var zoomLevel = 19; 				
        	if (map.getZoom() == zoomLevel) 
			{           		
				map.zoomOut();
        	} 
     	}
		); 	
  	}
}

//-------------------------------------------------------------------------------------------------
// Creates a marker at the given point with the given number label
function createMarker(point, info, iicon) 
{
	var marker = new GMarker(point, { icon: iicon });		
	GEvent.addListener(marker, "click", function() 
	{
		marker.openInfoWindowHtml("<b>" + info + "</b>");			
	});
	return marker;
}
	var str = null;	
	//Display Bus Stops of Bus Line...
	function goster(form, hatNo)  
	{		
	    if (GBrowserIsCompatible()) 
		{				    
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(38.41978, 27.12886), 11);			
        	map.addControl(new GLargeMapControl());
 			map.enableDoubleClickZoom();
        	var mapControl = new GMapTypeControl();
        	map.addControl(mapControl);
			map.addControl(new GScaleControl());
			map.setMapType(G_SATELLITE_MAP);
			
			GEvent.addListener(map, "zoomend", function() 
			{ 
          		var zoomLevel = 19; 				
            	if (map.getZoom() == zoomLevel) 
				{           		
					map.zoomOut();
            	} 
         	}
			); 	
 				
//			if (form.yon[0].checked) 
//			{
//				str = "gidis";				
//			}
//			else
//			{
//				str = "donus";
//			}	
            
            str = yon;
			
		    hatNo = "" + hatNo;
		    //if(hatNo.length == 1) hatNo = "00" + hatNo;
		    //else if (hatNo.length == 2) hatNo = "0" + hatNo;
			
		    GDownloadUrl("./Hatlar/" + hatNo + "_" + str + ".xml", function(data, responseCode) 
		    {					
  			    var xml = GXml.parse(data);
      			
  			    var markers = xml.documentElement.getElementsByTagName("marker");

			    if(hatNo != 811)
			    {

			        //Display Middle Bus Stop on Center of Map... 
			        map.setCenter(new GLatLng(parseFloat(markers[parseInt(markers.length/2)].getAttribute("lat")), parseFloat(markers[parseInt(markers.length/2)].getAttribute("lng"))), 13);				
    			
			        //Display Bus Stops One by One...
  			        for (var i = 0; i < markers.length; i++) 
			        {
    				
    			        var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
            		                        parseFloat(markers[i].getAttribute("lng")));
            		
				        var icon = new GIcon();
	        	        icon.image ="Icons\\" +(markers[i].getAttribute("ico")) + ".png";
				        icon.iconAnchor = new GPoint(16, 16);
				        icon.infoWindowAnchor = new GPoint(16, 0);
				        icon.iconSize = new GSize(16, 16);

				        map.addOverlay(createMarker(point, (markers[i].getAttribute("inf")), icon));
  			        }			
  			    }
  			    else
  			    {
  			        map.setCenter(new GLatLng(parseFloat(markers[parseInt(markers.length/2)].getAttribute("Enlem")), parseFloat(markers[parseInt(markers.length/2)].getAttribute("Boylam"))), 13);				
  			        //Display Bus Route as a Polyline
  			        for (var i = 0; i < markers.length - 1; i++) 
			        {
    			        var point1 = new GLatLng(parseFloat(markers[i].getAttribute("Enlem")),
            		                        parseFloat(markers[i].getAttribute("Boylam")));
            		                        
                        var point2 = new GLatLng(parseFloat(markers[i + 1].getAttribute("Enlem")),
            		                        parseFloat(markers[i + 1].getAttribute("Boylam")));            		                        
            		                        
            		    var polyline = new GPolyline([point1, point2], "#ff0000", 5);
		                map.addOverlay(polyline);
		                
		                		                
		                if(markers[i].getAttribute("Adres") != undefined && markers[i].getAttribute("Adres") != "")
		                {
    		                var point = new GLatLng(parseFloat(markers[i].getAttribute("Enlem")),
            		                            parseFloat(markers[i].getAttribute("Boylam")));
                		
				            var icon = new GIcon();
	        	            icon.image ="Icons\\Bayrak.png";
				            icon.iconAnchor = new GPoint(16, 16);
				            icon.infoWindowAnchor = new GPoint(16, 0);
				            icon.iconSize = new GSize(16, 16);

				            map.addOverlay(createMarker(point, (markers[i].getAttribute("Adres")), icon));
				        }

  			        }		
  			    }
    	    });	
		}
	}	
	//-------------------------------------------------------------------------------------------------	
