
	var map;
	var gLocos=[];
	var gMarkers=[];
	var gInfoTabs=[];
	var gSections=[];
	var TimerID = 0;
	var ReloudNr = 0;
	var gNR = "";
	var cLog = "";
	var nWindowOpened = -1;
	var nWindowOpenedNew = -1;
	var nIWTab = 0;
	var gFolders=[];
	var geoTrack;
	var geoSection;
	var geoPP;

	function LogErr(ErrText) {
//		GLog.write("ERROR:"+ErrText);
	}
	function LogInfo(InfoText) {
//		GLog.write("INFO:"+InfoText);
	}

	function CenterOnLoco(NR) {
		if (NR != "") {
			for (var k = 0; k < gLocos.length; k++) {
				if (gLocos[k][1] == NR) {
					var point = gLocos[k][2];	
					map.setCenter(point);
					return k;
				}
			}					
		}
	}

	function GetgLocoIndex(NR) {
		if (NR != "") {
			for (var k = 0; k < gLocos.length; k++) {
				if (gLocos[k][1] == NR) {
					return k;
				}
			}					
		}
		return -1;
	}

	function nullCnv(vvalue, vnull) {
		if (vvalue == null) {
			return vnull;
		} else {
			return vvalue;
		}
	}
	

	function GetCargoName(cInput, nWag) {
		var cRet;
		
		cRet = "";
		if (nWag > 0) {
			switch (cInput) {
			case '1':
				cRet = "z rudą";
				break;
			case '2':
				cRet = "próżne węglarki";
				break;
			case '3':
				cRet = "zdawczy";
				break;
			case '4':
				cRet = "roboczy";
				break;
			case '5':
				cRet = "intermodalny";
				break;
			default:
				cRet = "inny: '"+cInput+"'";
			}
		} else {
			switch (cInput) {
			case '1':
				cRet = "czynna";
				break;
			case '2':
				cRet = "manewrowa";
				break;
			case '3':
				cRet = "po pchaniu";
				break;
			case '4':
				cRet = "nieczynna";
				break;
			default:
				cRet = "inna: '"+cInput+"'";
			}
		}
		return cRet;
	}

	function GetDangerousName(cInput) {
		if (cInput == '1') {
			return 'tak';
		} else {
			return 'nie';
		}

	}

	function getTBRow(Desc, Value2, styleNo) {
                          var strStyle;
                          if (styleNo == 0) {
                             strStyle = " style=\"background-color: #EEEEEE; \"";
                          }
                          else if (styleNo == 1) {
                             strStyle = " style=\"background-color: #FEFEFE; \"";
                          }
                          else {
                             strStyle = " style=\"background-color: #C6DBFF; \"";
                          }


		return '<tr><td width="50%" align=left ' + strStyle + '><font face="Verdana, Tahoma, Arial" size="1">' + Desc + '</font></td><td align=left ' + strStyle + '><b><font color="#002277" face="Verdana, Tahoma, Arial" size="1">' + Value2 + '</font></td></tr>';
	}

	function GetPopupTabs(number) {
		var infoTabs = [];
		var cText;
		var cWLad, cWProz;

		cText = '<table width=300 border="0" cellpadding=0 cellspacing=0 bordercolorlight="#000000" bordercolordark="#0000FF">';
		cText = cText + getTBRow( "Numer", gLocos[number][1], 2 );
		cWLad = nullCnv(gLocos[number][11],0);
		cWProz = nullCnv(gLocos[number][12],0);
		if (cWLad != 0 && cWProz != 0) {
		   cText = cText + getTBRow( "Ładunek", GetCargoName(gLocos[number][4], Number(cWLad)+Number(cWProz) ), 1);
		   cText = cText + getTBRow( "Ład. niebezp.", GetDangerousName(gLocos[number][13]), 0 );
		   cText = cText + getTBRow( "Wagony", "Ład:" + cWLad + " / Pr:" + cWProz, 1);
                }
		else {
                   cText = cText + getTBRow( "Ładunek", "", 1);
		   cText = cText + getTBRow( "Ład. niebezp.", "", 0 );
		   cText = cText + getTBRow( "Wagony", "", 1);
                }

		var sID = parseFloat(gLocos[number][16]);
		var cID = "";
		cID = gSections[sID-1];

		cText = cText + getTBRow( "Położenie", cID+" ("+sID+")", 0 );
		cText = cText + getTBRow( "&nbsp;", "&nbsp;", 1 );
		cText = cText + getTBRow( "&nbsp;", "&nbsp;", 0 );
		cText = cText + "</table>";
		infoTabs.push(new GInfoWindowTab("Pociąg", cText));

		cText = '<table width=300 border="0" cellpadding=0 cellspacing=0 bordercolorlight="#000000" bordercolordark="#0000FF">';
		cText = cText + getTBRow( "Numer", gLocos[number][1] ,2);
		cText = cText + getTBRow("Pierwsza", nullCnv(gLocos[number][7],"") , 1);
		cText = cText + getTBRow("Druga", nullCnv(gLocos[number][8],"") , 0);
		cText = cText + getTBRow("Pchająca 1", nullCnv(gLocos[number][9],"") , 1);
		cText = cText + getTBRow("Pchająca 2", nullCnv(gLocos[number][10],"") , 0);
		cText = cText + getTBRow( "&nbsp;", "&nbsp;", 1 );
		cText = cText + getTBRow( "&nbsp;", "&nbsp;", 0 );
		cText = cText + "</table>";
		infoTabs.push(new GInfoWindowTab("Lokomotywy", cText));

		cText = '<table width=300 border="0" cellpadding=0 cellspacing=0 bordercolorlight="#000000" bordercolordark="#0000FF">';
		cText = cText + getTBRow("Numer", gLocos[number][1], 2 );
		cText = cText + getTBRow("Szerokość geogr.", gLocos[number][2].lat() , 1);
		cText = cText + getTBRow("Długość geogr.", gLocos[number][2].lng() , 0);
		cText = cText + getTBRow("Prędkość", gLocos[number][5] + "&nbsp;&nbsp;km/h", 1);
		cText = cText + getTBRow("Kierunek", GetVDIR(gLocos[number][6]) , 0);
		cText = cText + getTBRow("Status odczytu GPS", (gLocos[number][15]=="A"?"Poprawny":"Błędny") , 1);
		cText = cText + getTBRow("Ostatni sygnał", gLocos[number][14] , 0);
		cText = cText + "</table>";
		infoTabs.push(new GInfoWindowTab("GPS", cText));

		return infoTabs;
	}

	function OpenInfoWindow(NR, nTab)
	{
		if (NR != "") {
			for (var k = 0; k < gLocos.length; k++) {
				if (gLocos[k][1] == NR) {

					nWindowOpenedNew = k;
					nIWTab = nTab;
					var opts = {
						onOpenFn  : function(){ nWindowOpened = nWindowOpenedNew; nWindowOpenedNew = -1} ,
						onCloseFn : function(){ nWindowOpened = -1; },
						selectedTab : nIWTab
					};
					map.closeInfoWindow();
					map.openInfoWindowTabsHtml(gLocos[k][2], gInfoTabs[k], opts);
					return k;
				}
			}
		}
		return -1;
	}


	 function ppOrder(marker, nieuzywany)  
	 {  
	     return Math.floor(100000);  
	 } 


	function CreateMarker(number, icon) {
		var marker = new GMarker(gLocos[number][2], {icon:icon, zIndexProcess: ppOrder});
		var pics = gLocos[number][1];

		try {
			gInfoTabs.push(GetPopupTabs(number));
			GEvent.addListener(marker, "click", function() {
				OpenInfoWindow(gLocos[number][1], 0);
			});

			GEvent.addListener(marker, "dblclick", function() {
				map.setCenter(marker.getPoint(), 13);;
				//marker.showMapBlowup();
			});
			return marker;
		}
		catch (err)
		{
			LogErr("Błąd tworzenia markera:" + number.toString());
		}
	}


	//function CreateIcon(number) {
	function CreateIcon(id_loco) {	
		var icon = new GIcon();
		
		//if (number == "0") icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
		//else if (number =="10") icon.image = "http://labs.google.com/ridefinder/images/mm_20_gray.png";
		//else if (number =="11") icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
                //else               icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
                
//                icon.image = "http://labs.google.com/ridefinder/images/mm_20_green.png";
                icon.image = "http://qpilot.quantum.pl/slhs/images/loco1.png";
                
		//icon.image = "http://qpilot2.quantum.pl/slhs/mm_20_red.png";
		
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";

//		icon.iconSize = new GSize(12, 20);
//		icon.shadowSize = new GSize(22, 20);

		icon.iconSize = new GSize(35, 36);
		icon.iconAnchor = new GPoint(18, 1);
		icon.infoWindowAnchor = new GPoint(5, 1);
		return icon;
	}
	

	function DrawLocos() {
		for (var k = 0; k < gLocos.length; k++) {
		
		  if (gLocos[k][17] == "0") {
			try {

			var icon;
			var marker;
			if (gMarkers.length <= k) {
			
			        // poprzednia wersja, rożnicujaca kolor lokomotywy w zaleznosci od stanu łacznosci: 
                                //if (gLocos[k][15] != "A" ) {
                                //  if (gLocos[k][17] == "0") icon = CreateIcon("10");
                                //  else if (gLocos[k][17] == "1") icon = CreateIcon("11");
                                //  else icon = CreateIcon("10");
                                //}
				//else {
                                //  if (gLocos[k][17] == "0") icon = CreateIcon(gLocos[k][3]);
                                //  else if (gLocos[k][17] == "1") icon = CreateIcon("11");
                                //  else icon = CreateIcon("10");
                                //}
                                
                                // do CreateIcon jest przekazywany id lokomotywy - do ewentualnych przyszłych zastosowan
                                icon = CreateIcon(gLocos[k][0]);
                                
				marker = CreateMarker(k,icon);
				gMarkers.push(marker);
				map.addOverlay(marker);
				marker.getIcon().image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
				marker.redraw(true);
			} else {
				marker = gMarkers[k];
				gInfoTabs[k] = GetPopupTabs(k);
				marker.setPoint(gLocos[k][2]);
				marker.getIcon().image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
				marker.redraw(true);
			}

			// jesli jakies okno jest otwarte...
			if (nWindowOpened >= 0) {
				nWindowOpenedNew = nWindowOpened;
				var iW = map.getInfoWindow();
				OpenInfoWindow(gLocos[nWindowOpenedNew][1], iW.getSelectedTab());
			}

			}
			catch (err)
			{
				LogErr("DrawLocos:" + gLocos[k][1]);
			}	
                  } else
                  {
                    LogInfo("Brak łączności z obiektem: " + gLocos[k][1] + " Ost. sygn.: " + gLocos[k][14]);
                  };
		}
	}

	  

	function RemoveLocos() {

		document.getElementById("message").innerHTML = "<font face=\"Verdana, Tahoma, Arial\" size=1>Usuwam, moment...";
		for (var k = 0; k < gMarkers.length; k++) {
			try {
				GEvent.clearInstanceListeners(gMarkers[k]);
			}
			catch (err)
			{
				LogErr("Błąd usunięcia listenera markera (" + k.toString() + "):" + err.description);
			};

			try {
				map.removeOverlay(gMarkers[k]);
			}
			catch (err)
			{
				LogErr("Błąd usunięcia markera (" + k.toString() + "):" + err.description);
			}

			try {
				map.clearOverlays();
			}
			catch (err)
			{
				LogErr("Błąd usunięcia wszystkich markerow:" + err.description);
			}
		}
		gLocos = [];
		gMarkers = [];
		gInfoTabs = [];
		document.getElementById("message").innerHTML = "<font face=\"Verdana, Tahoma, Arial\" size=1>Usunąłem !";
	}

	function LoadData(data, responseCode) {

		ReloudNr++;
		cLog = "";
		LogInfo("Odczyt:" + ReloudNr.toString());

//		RemoveLocos();

		document.getElementById("message").innerHTML = "<font face=\"Verdana, Tahoma, Arial\" size=1>Przetwarzam, moment...";
		var xml = GXml.parse(data);
		var pLokomotives = xml.documentElement.getElementsByTagName("LOCOMOTIVE");

//		var oSel = document.getElementById("Select1");

                var txtLocoList = "<table width=90% border=0 cellspacing=0 cellpadding=1>";
                var txtRailList = "<table width=90% border=0 cellspacing=0 cellpadding=1>";
                txtLocoList += "<tr style=\"background-color: #C6DBFF;\"><th colspan=2 align=left>Lokomotywa";
                txtLocoList += "<th wrap>V";
                txtLocoList += "<th width=2>&nbsp;";
                txtRailList += "<tr style=\"background-color: #C6DBFF;\"><th colspan=2 align=left>Pociąg";
                txtRailList += "<th wrap>V";
                txtRailList += "<th width=2>&nbsp;";

//                oSel.length = 0;
                var nLoc = 0;
                var nRail = 0;
                for (var k = 0; k < pLokomotives.length; k++)  
                {
                  if ( pLokomotives[k].getAttribute("CLIENT") == "LHS" ) 
                    {
                    if ( pLokomotives[k].getAttribute("GPSSTATE") == "A" ) 
                      {
                      if ( pLokomotives[k].getAttribute("SIGNALSTAT") == "0" ) 
                        {
                    
			var xLoco = pLokomotives[k];
			var nLon = parseFloat(xLoco.getAttribute("LONG"));
			var nLat = parseFloat(xLoco.getAttribute("LAT"));

			var nLoco = GetgLocoIndex(xLoco.getAttribute("NR"));
			var cID = xLoco.getAttribute("ID")	

			var pLoco = [];
			if ( nLoco >= 0) {
				gLocos[nLoco][2] = new GLatLng(nLat, nLon);
				gLocos[nLoco][3] = xLoco.getAttribute("ISLOCO");
				gLocos[nLoco][4] = xLoco.getAttribute("LOCO_TYPE");
				gLocos[nLoco][5] = xLoco.getAttribute("SPEED");
				gLocos[nLoco][6] = xLoco.getAttribute("DIR");
				gLocos[nLoco][7] = xLoco.getAttribute("LOCO1");
				gLocos[nLoco][8] = xLoco.getAttribute("LOCO2");
				gLocos[nLoco][9] = xLoco.getAttribute("LOCO3");
				gLocos[nLoco][10] = xLoco.getAttribute("LOCO4");
				gLocos[nLoco][11] = xLoco.getAttribute("WAG_LAD");
				gLocos[nLoco][12] = xLoco.getAttribute("WAG_PRO");
				gLocos[nLoco][13] = xLoco.getAttribute("LAD_NIEBEZP");
				gLocos[nLoco][14] = xLoco.getAttribute("LMDATE");
				gLocos[nLoco][15] = xLoco.getAttribute("GPSSTATE");
				gLocos[nLoco][16] = xLoco.getAttribute("SECTION");
				gLocos[nLoco][17] = xLoco.getAttribute("SIGNALSTAT");				
				gLocos[nLoco][18] = xLoco.getAttribute("CLIENT");

			} else {
				pLoco.push(cID);
				pLoco.push(xLoco.getAttribute("NR"));
				pLoco.push(new GLatLng(nLat, nLon));
				pLoco.push(xLoco.getAttribute("ISLOCO"));
				pLoco.push(xLoco.getAttribute("LOCO_TYPE"));
				pLoco.push(xLoco.getAttribute("SPEED"));
				pLoco.push(xLoco.getAttribute("DIR"));
				pLoco.push(xLoco.getAttribute("LOCO1"));
				pLoco.push(xLoco.getAttribute("LOCO2"));
				pLoco.push(xLoco.getAttribute("LOCO3"));
				pLoco.push(xLoco.getAttribute("LOCO4"));
				pLoco.push(xLoco.getAttribute("WAG_LAD"));
				pLoco.push(xLoco.getAttribute("WAG_PRO"));
				pLoco.push(xLoco.getAttribute("LAD_NIEBEZP"));
				pLoco.push(xLoco.getAttribute("LMDATE"));
				pLoco.push(xLoco.getAttribute("GPSSTATE"));
				pLoco.push(xLoco.getAttribute("SECTION"));
				pLoco.push(xLoco.getAttribute("SIGNALSTAT"));

				gLocos.push(pLoco);
			}
//			oSel.length = oSel.length + 1;
//			oSel.options[oSel.length-1].text = xLoco.getAttribute("NR");


                        var strStyle = "";
                        var strIcon = "";
                        if (xLoco.getAttribute("ISLOCO") == "0") {
                          if ((nRail % 2) == 0) {
                             strStyle = " style=\"background-color: #EEEEEE; cursor: pointer;cursor: hand;";
                          }
                          else {
                             strStyle = " style=\"background-color: #FFFFFF; cursor: pointer;cursor: hand;";
                          }
                          strIcon = "<img src='images/pc.ico' border=0>"
                          if (xLoco.getAttribute("SIGNALSTAT") == "0" && xLoco.getAttribute("GPSSTATE") != "A") {
//                             strStyle += " color: #FF7070; "
                             strIcon = "<img src='images/pci.ico' border=0>"
                          }
                          if (xLoco.getAttribute("SIGNALSTAT") == "1") {
//                             strStyle += " color: #FF7070; "
                             strIcon = "<img src='images/pci.ico' border=0>"
                          }
                          if (xLoco.getAttribute("SIGNALSTAT") == "2"){
//                             strStyle += " color: #777777; "
                             strIcon = "<img src='images/pcn.ico' border=0>"
                          }
                          strStyle += "\"";
                          nRail += 1;

                          txtRailList += "<tr onclick=\"findLoco('" + xLoco.getAttribute("NR") + "')\"" + strStyle + ">";
                          txtRailList += "<td width=6>" + strIcon;
                          txtRailList += "<td>" + xLoco.getAttribute("NR");
                          txtRailList += " (" + xLoco.getAttribute("LOCO1") + ")";
                          txtRailList += "<td align=center>" + xLoco.getAttribute("SPEED");
                          txtRailList += "<td width=2>";
                        } 
                        else {
                          if ((nLoc % 2) == 0) {
                             strStyle = " style=\"background-color: #EEEEEE; cursor: pointer;cursor: hand;";
                          }
                          else {
                             strStyle = " style=\"background-color: #FFFFFF; cursor: pointer;cursor: hand;";
                          }
                          strIcon = "<img src='images/loko_1_lista.png' border=0>"
                          if (xLoco.getAttribute("SIGNALSTAT") == "0" && xLoco.getAttribute("GPSSTATE") != "A" ) {
//                                strStyle += " color: #FF7070; "
                                strIcon = "<img src='images/loko_2_lista.png' border=0>"
                          }
                          if (xLoco.getAttribute("SIGNALSTAT") == "1") {
//                             strStyle += " color: #FF7070; "
                             strIcon = "<img src='images/loko_2_lista.png' border=0>"
                          }
                          if (xLoco.getAttribute("SIGNALSTAT") == "2") {
//                             strStyle += " color: #777777; "
                             strIcon = "<img src='images/loko_3_lista.png' border=0>"
                          }
                          strStyle += "\"";
                          nLoc += 1;
                          txtLocoList += "<tr onclick=\"findLoco('" + xLoco.getAttribute("NR") + "')\"" + strStyle + ">";
                          txtLocoList += "<td width=8>" + strIcon;
                          txtLocoList += "<td>" + xLoco.getAttribute("NR");
                          txtLocoList += "<td align=center>" + xLoco.getAttribute("SPEED");
                          txtLocoList += "<td width=2>";
                        }

                      } else
                      {
                        LogInfo("Brak łączności z obiektem: " + pLokomotives[k].getAttribute("NR") + " Ostatni sygnał: " + pLokomotives[k].getAttribute("LMDATE"));
                      }
                      
                     } else
                     {
                       LogInfo("Obiekt: " + pLokomotives[k].getAttribute("NR") + " GPSSTATE: " + pLokomotives[k].getAttribute("GPSSTATE"));
                     }                      
                      
                    } else
                    {
                      LogInfo("nieobsługiwana wartość parametru CLIENT: " + pLokomotives[k].getAttribute("CLIENT"));
                    }
		}

                txtLocoList += "</table>";
                txtRailList += "</table>";
                document.getElementById("LocoList").innerHTML = txtLocoList;
                //document.getElementById("RailList").innerHTML = txtRailList;		


		DrawLocos();
		//DrawLocoList();
		
		CenterOnLoco(gNR);
		document.getElementById("message").innerHTML = "<font face=\"Verdana, Tahoma, Arial\" size=1>" + xml.documentElement.getAttribute("DATE") + " (" + ReloudNr.toString() + ")";

//		document.getElementById("error").innerHTML = cLog;
	};

	function GetLocosID(ID)	{
		var nRet = -1;
		for (var k = 0; k < gLocos.length; k++) {
			if (gLocos[k][0] == ID) {
				nRet = k;
			}
		}		
		return nRet;
	}
				
	function ReloadLocos() {
	
			document.getElementById("message").innerHTML = "<font face=\"Verdana, Tahoma, Arial\" size=1>Ładuję, moment...";

                        var currentTime = new Date(); 
			var cHTTP = "http://qpilot.quantum.pl/slhs/load_vehicles_lhs.php?ID="+ currentTime.getTime();
			LogInfo('Pobieram:'+cHTTP);
			GDownloadUrl(cHTTP, LoadData);
	}
	

	function ReloadLocosT() {
		if (TimerID) {
			clearTimeout(TimerID);
		}
		ReloadLocos();
		TimerID = setTimeout("ReloadLocosT()", 60000);
	}

	function DrawTracks() {
		for (var k = 0; k < gFolders.length; k++) {
			var polygons = gFolders[k];
			for (var i = 0; i < polygons.length; i++) {
				var polyline = polygons[i];
				map.addOverlay(polyline);
			}
		}
	};


    function load() {
		LogInfo("QguarPilot Google Map API ver. 1.0.1a");	
		GUnload();
		if (GBrowserIsCompatible()) {
					
			map = new GMap2(document.getElementById("map"));
			map.addControl(new GLargeMapControl());
//			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
			map.addControl(new GOverviewMapControl());
			
			gSections.push("Huta - Sławków Płd.");
			gSections.push("Sławków Południowy");
			gSections.push("Sławków Płd. - Bukowno");
			gSections.push("Bukowno");
			gSections.push("Zarzecze - Kępie");
			gSections.push("Kępie");
			gSections.push("Kępie - Sędziszów");
			gSections.push("Sędziszów");
			gSections.push("Sędziszów - Łączyn");
			gSections.push("Łączyn");
			gSections.push("Łączyn - Gołuchów");
			gSections.push("Gołuchów");
			gSections.push("Gołuchów - Raczyce");
			gSections.push("Raczyce");
			gSections.push("Raczyce - Grzybów");
			gSections.push("Grzybów");
			gSections.push("Grzybów - Staszów");
			gSections.push("Staszów");
			gSections.push("Staszów - Niekrasow");
			gSections.push("Wola Baranowska");
			gSections.push("Wola Baranowska - Drozdów");
			gSections.push("Drozdów");
			gSections.push("Drozdów - Puszcza");
			gSections.push("Puszcza");
			gSections.push("Puszcza - Huta Deręgowska");
			gSections.push("Huta Deręgowska");
			gSections.push("Huta Deręgowska - Biłgoraj");
			gSections.push("Biłgoraj");
			gSections.push("Biłgoraj - Zwierzyniec");
			gSections.push("Zwierzyniec");
			gSections.push("Zwierzyniec - Szczebrzeszyn");
			gSections.push("Szczebrzeszyn");
			gSections.push("Szczebrzeszyn - Zamość");
			gSections.push("Zamość");
			gSections.push("Zamość - Miączyn");
			gSections.push("Miączyn");
			gSections.push("Miączyn - Werbkowice");
			gSections.push("Werbkowice");
			gSections.push("Werbkowice - Hrubieszów");
			gSections.push("Hrubieszów");
			gSections.push("Bukowno - Zarzecze");
			gSections.push("Zarzecze");
			gSections.push("Niekrasów - Wola Baranowska");
			gSections.push("Niekrasów");

			var point = new GLatLng(50.46, 21.75);
			map.setCenter(point, 8);
			map.setMapType(G_NORMAL_MAP);

			CreateSectionList();
			LoadTrack(true); 

			ReloadLocos();
			if (!TimerID) TimerID = setTimeout("ReloadLocosT()", 60000);

		}
	}

function GetVDIR(GDir) {
     var retVal = "?";
     var dblDir = parseFloat(GDir);
     switch ( Math.round(dblDir/45.0) % 8 ) {
            case 0: retVal = "Północ"; break;
            case 1: retVal = "Północny/Wschód"; break;
            case 2: retVal = "Wschód"; break;
            case 3: retVal = "Południowy/Wschód"; break;
            case 4: retVal = "Południe"; break;
            case 5: retVal = "Południowy/Zachód"; break;
            case 6: retVal = "Zachód"; break;
            case 7: retVal = "Północny/Zachód"; break;
     }
     return retVal;
}

function LoadTrack(xset) {

	if (xset) {
		geoPP = new GGeoXml("http://qpilot.quantum.pl/slhs/kml/pp1.kml");
		map.addOverlay(geoPP);	

		geoTrack = new GGeoXml("http://qpilot.quantum.pl/slhs/kml/szlak.kml",
			function GCenter(geo) {
			    center = geoTrack.getDefaultCenter();
			    map.setCenter(center,map.getBoundsZoomLevel(geoTrack.getDefaultBounds())); 
			} 
		);
		map.addOverlay(geoTrack);

//		var geoPKP = new GGeoXml("http://qpilot2.quantum.pl/slhs/kml/pkp.kml");		
//		map.addOverlay(geoPKP);	

	} else {	
		map.removeOverlay(geoTrack);	
		map.removeOverlay(geoPP);	
	}

}


function TrackShow(xset) {
	if (xset) {
		geoPP.show();
		geoTrack.show();
	} else {	
		geoPP.hide();
		geoTrack.hide();
	}
}


function CreateSectionList() {

        var txtSectionList = "<table class=table_HeaderRow width=80% border=0 cellspacing=0 cellpadding=1>";

	txtSectionList += "<tr wrap><th colspan=2 align=left>Stacja / Mijanka";
	txtSectionList += "<th >";
        txtSectionList += "<th width=2>&nbsp;";

	var strStyleE = " class=table_EvenRow ";
        var strStyleO = " class=table_OddRow ";


	txtSectionList += CreateSectionElem( "02", "Sławków Południowy", strStyleE);
	txtSectionList += CreateSectionElem( "04", "Bukowno", strStyleO);
	txtSectionList += CreateSectionElem( "42", "Zarzecze", strStyleE);
	txtSectionList += CreateSectionElem( "06", "Kępie", strStyleO);
	txtSectionList += CreateSectionElem( "08", "Sędziszów", strStyleE);
	txtSectionList += CreateSectionElem( "10", "Łączyn", strStyleO);
	txtSectionList += CreateSectionElem( "12", "Gołuchów", strStyleE);
	txtSectionList += CreateSectionElem( "14", "Raczyce", strStyleO);
	txtSectionList += CreateSectionElem( "16", "Grzybów", strStyleE);
	txtSectionList += CreateSectionElem( "18", "Staszów", strStyleO);
	txtSectionList += CreateSectionElem( "44", "Niekrasów", strStyleE);
	txtSectionList += CreateSectionElem( "20", "Wola Baranowska", strStyleO);
	txtSectionList += CreateSectionElem( "22", "Drozdów", strStyleE);
	txtSectionList += CreateSectionElem( "24", "Puszcza", strStyleO);
	txtSectionList += CreateSectionElem( "26", "Huta Deręgowska", strStyleE);
	txtSectionList += CreateSectionElem( "28", "Biłgoraj", strStyleO);
	txtSectionList += CreateSectionElem( "30", "Zwierzyniec", strStyleE);
	txtSectionList += CreateSectionElem( "32", "Szczebrzeszyn", strStyleO);
	txtSectionList += CreateSectionElem( "34", "Zamość", strStyleE);
	txtSectionList += CreateSectionElem( "36", "Miączyn", strStyleO);
	txtSectionList += CreateSectionElem( "38", "Werbkowice", strStyleE);
	txtSectionList += CreateSectionElem( "40", "Hrubieszów", strStyleO);

        document.getElementById("SectionList").innerHTML = txtSectionList;

}


function CreateSectionElem(SNr, SName, SStyle) {
var txtSectionElem = "";

	txtSectionElem += "<tr onclick=\"SectionShow('" + SNr + "')\"" + SStyle + " style='cursor: pointer;cursor: hand;'>";
	txtSectionElem += "<td width=1>";
        txtSectionElem += "<td wrap width=120>" + SName;
        txtSectionElem += "<td width=2>";
	return txtSectionElem ;
}

function SectionShow(Sid) {
var lOpera;

	lOpera = false;
	try
	{
		map.removeOverlay(geoSection);	
	}
	catch(err)
	{
		//moze nie byc elementu
	}

        LogInfo("SectionShow. START:"+Sid);

	geoSection = null;
	geoSection = new GGeoXml("http://qpilot.quantum.pl/slhs/kml/" + Sid + ".kml",
			function GCenter(geo) {
			    LogInfo("GCenter START:"+Sid);
				try
				{
				    var center = geoSection.getDefaultCenter();
				    map.setCenter(center,16); 
				    map.addOverlay(geoSection);
				    LogInfo("GCenter. Załadował");
				}
				catch(err)
				{
					LogErr("W operze jeszcze nie ma elementu");
				}

			    LogInfo("GCenter STOP");
			} 
		);

	if (geoSection.loadedCorrectly()) {
	        var center = geoSection.getDefaultCenter();
        	map.setCenter(center,16); 
	        map.addOverlay(geoSection);
	        LogInfo("SectionShow. Załadował");
	}

        LogInfo("SectionShow. STOP");

	return Sid;
}



