	//Alap vltozók és vektorok
	var def_Lat = 47.5;
	var def_Lon = 19.06;
	var map;
	var akt_betu;
	var route;
	var location_list_helyszin = new Array();
	var location_list_vend = new Array();
	var address_list = new Array();
	var address_count = 0;
	var GPS_marker;

	//Gmap content
	var gmap_content = new Array();
	switch (lang)
	{
		case 'h':
			gmap_content[0] = 'A helyszín leírásáért, képeiért és programjaiért kattintson ';
			gmap_content[1] = 'ide';
			gmap_content[2] = 'Helyezze be az útvonaltervezőbe ';
			gmap_content[3] = 'indulásként ';
			gmap_content[4] = 'vagy ';
			gmap_content[5] = 'célállomásként';
			gmap_content[6] = 'Nagy térképért kattintson ';
			gmap_content[7] = 'Még nem keresett GPS pontokat';
			gmap_content[8] = 'Lat';
			gmap_content[9] = 'Lng';
		break;
		case 'g':
			gmap_content[0] = 'For further information, pictures and programmes click ';
			gmap_content[1] = 'here';
			gmap_content[2] = 'Put the address to the route planner';
			gmap_content[3] = 'as start location';
			gmap_content[4] = 'or';
			gmap_content[5] = 'as destination';
			gmap_content[6] = 'For larger map, click ';
			gmap_content[8] = 'Lat';
			gmap_content[9] = 'Lng';
		break;
		case 'e':
			gmap_content[0] = 'For further information, pictures and programmes click ';
			gmap_content[1] = 'here';
			gmap_content[2] = 'Put the address to the route planner';
			gmap_content[3] = 'as start location';
			gmap_content[4] = 'or';
			gmap_content[5] = 'as destination';
			gmap_content[6] = 'For larger map, click ';
			gmap_content[7] = 'There"s no GPS points to jump to';
			gmap_content[8] = 'Lat';
			gmap_content[9] = 'Lng';
		break;
	}
	
	//Megyék geokódjainak betöltése
	var megye_geocodes = new Array();
	megye_geocodes[0] = new Array(def_Lat,def_Lon,6);
	megye_geocodes[1] = new Array('47.56667','17.17722',9);
	megye_geocodes[2] = new Array('47.10361','16.83056',9);
	megye_geocodes[3] = new Array('46.73750','16.86778',9);
	megye_geocodes[4] = new Array('46.44167','17.55833',9);
	megye_geocodes[5] = new Array('46.04667','18.16694',9);
	megye_geocodes[6] = new Array('46.53000','18.51750',9);
	megye_geocodes[7] = new Array('47.22222','18.49861',9);
	megye_geocodes[8] = new Array('47.51944','18.57444',9);
	megye_geocodes[9] = new Array('47.11667','17.68056',9);
	megye_geocodes[10] = new Array('46.58333','19.36667',9);
	megye_geocodes[11] = new Array('46.48333','20.26667',9);
	megye_geocodes[12] = new Array('46.76667','21.38333',9);
	megye_geocodes[13] = new Array('47.55000','21.48333',9);
	megye_geocodes[14] = new Array('48.00000','22.00000',9);
	megye_geocodes[15] = new Array('48.35000','21.00000',9);
	megye_geocodes[16] = new Array('47.95000','20.20000',9);
	megye_geocodes[17] = new Array('47.96667','19.38333',9);
	megye_geocodes[18] = new Array(def_Lat,def_Lon,9);
	megye_geocodes[19] = new Array('47.36667','20.45000',9);
	megye_geocodes[20] = new Array(def_Lat,def_Lon,9);
	
	//Régiók geokódjai
	var regio_geocodes = new Array();
	regio_geocodes[1] = new Array('47.26389','16.76389');
	regio_geocodes[2] = new Array('47.28944','18.13722');
	regio_geocodes[3] = new Array('46.28333','18.00000');
	regio_geocodes[4] = new Array(def_Lat,def_Lon);
	regio_geocodes[5] = new Array('48.10000','20.20000');
	regio_geocodes[6] = new Array('47.68333','21.33333');
	regio_geocodes[7] = new Array('46.65000','19.91667');
	
	//Térkép betöltése
	function load(fullmap) 
	{
    	if (GBrowserIsCompatible()) 
		{
       		map = new GMap2(document.getElementById("terkep"));
			if (fullmap)
			{
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
			}
			map.setCenter(new GLatLng(def_Lat,def_Lon),6);
    	}
    }
		
	function mutat_hely(id)
	{
		if (location_list_helyszin[id]==null)
		{
			var xmlHttp = create_Ajax();
			var respText = new String();
			var point;
	
			xmlHttp.onreadystatechange=function()
   			{
   				if(xmlHttp.readyState==4)
   				{
					respText = xmlHttp.responseText;
					var result = respText.split('||');
					var Lat = result[0];
					var Lng = result[1];
					var Name = result[2];
					var Address = result[3];
					
					point = new GLatLng(Lat,Lng);
					location_list_helyszin[id] = new GMarker(point);
					map.addOverlay(location_list_helyszin[id]);
					location_list_helyszin[id].openInfoWindowHtml('<b>' + Name + '</b><br><br>'+Address+'<br><br>'+gmap_content[0]+'<a href="helyszin.gcw?id='+id+'" target="_blank"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a onclick="document.getElementById(\'honnan\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a onclick="document.getElementById(\'hova\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a>',{ maxWidth: 500 } );
					GEvent.addListener(location_list_helyszin[id],"click", function() { location_list_helyszin[id].openInfoWindowHtml('<b>' + Name + '</b><br><br>'+Address+'<br><br>'+gmap_content[0]+'<a href="helyszin.gcw?id='+id+'" target="_blank"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a onclick="document.getElementById(\'honnan\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a onclick="document.getElementById(\'hova\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a>',{ maxWidth: 500 }); } );
					document.getElementById('jump').checked?map.setCenter(location_list_helyszin[id].getPoint(), 13):'';
				}
			}
			
			xmlHttp.open("GET","ajax/helyszin_get_coords.php?id="+id,true);
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2;');
    		xmlHttp.send(null);
			xmlHttp.free;
		}
		else
		{
			location_list_helyszin[id].show();
			document.getElementById('jump').checked?map.setCenter(location_list_helyszin[id].getPoint(), 13):'';		
		}
	}
	
	function mutat_vend(id)
	{
		if (location_list_vend[id]==null)
		{
			var xmlHttp = create_Ajax();
			var respText = new String();
			var point;
	
			xmlHttp.onreadystatechange=function()
   			{
   				if(xmlHttp.readyState==4)
   				{
					respText = xmlHttp.responseText;
					var result = respText.split('||');
					var Lat = result[0];
					var Lng = result[1];
					var Name = result[2];
					var Address = result[3];
					
					point = new GLatLng(Lat,Lng);
					location_list_vend[id] = new GMarker(point);
					map.addOverlay(location_list_vend[id]);
					location_list_vend[id].openInfoWindowHtml('<b>' + Name + '</b><br><br>'+Address+'<br><br>'+gmap_content[0]+'<a href="vend.gcw?id='+id+'" target="_blank"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a onclick="document.getElementById(\'honnan\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a onclick="document.getElementById(\'hova\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a>',{ maxWidth: 500 });
					GEvent.addListener(location_list_vend[id],"click", function() { location_list_vend[id].openInfoWindowHtml('<b>' + Name + '</b><br><br>'+Address+'<br><br>'+gmap_content[0]+'<a href="vend.gcw?id='+id+'" target="_blank"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a onclick="document.getElementById(\'honnan\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a onclick="document.getElementById(\'hova\').value=\''+Address+'\'; return false;" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a>',{ maxWidth: 500 }); } );
					document.getElementById('jump').checked?map.setCenter(location_list_vend[id].getPoint(), 13):'';
				}
			}
			
			xmlHttp.open("GET","ajax/vend_get_coords.php?id="+id,true);
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=iso-8859-2;');
    		xmlHttp.send(null);
			xmlHttp.free;
		}
		else
		{
			location_list_vend[id].show();
			document.getElementById('jump').checked?map.setCenter(location_list_vend[id].getPoint(), 13):'';		}
	}
	
	function elrejt_hely(id)
	{
		location_list_helyszin[id].closeInfoWindow();
		location_list_helyszin[id].hide();
	}
	
	function elrejt_vend(id)
	{
		location_list_vend[id].closeInfoWindow();
		location_list_vend[id].hide();
	}
		
	function utvonal_tervez()
	{
		route = new GDirections(map, document.getElementById('utikalauz'));
		route.load('from: '+document.getElementById('honnan').value+' to: '+document.getElementById('hova').value);
	}
		
	function torles()
	{
		//Markerek
		var i;
		for(i in location_list_helyszin) { location_list_helyszin[i].hide(); }
		for(i in location_list_vend) { location_list_vend[i].hide(); }
		//Útvonaltervező
		if (route) { route.clear(); } 
		//A helyszínek checkboxai
		for(i in location_list_helyszin) { document.getElementById('cb'+i)!=null?document.getElementById('cb'+i).checked=false:''; }
		for(i in location_list_vend) { document.getElementById('cb'+i)!=null?document.getElementById('cb'+i).checked=false:''; }
	}
		
	function terkep_reload()
	{
		for(i in location_list_helyszin) 
		{ 
			document.getElementById('cb'+i)!=null&&location_list_helyszin[i]!=null&&!location_list_helyszin[i].isHidden()?document.getElementById('cb'+i).checked=true:''; 
		}
		for(i in location_list_vend) 
		{ 
			document.getElementById('cb'+i)!=null&&location_list_vend[i]!=null&&!location_list_vend[i].isHidden()?document.getElementById('cb'+i).checked=true:''; 
		}
	}

	function helyszin_listaz(betu, lang)
	{
		document.getElementById('helyszin_lista').innerHTML='Töltés...';
		run_Ajax('helyszin_lista','ajax/helyszin_lista.php?kinfolang='+lang+'&betu='+betu+'&megye_id='+document.getElementById('megye_terkep').options[document.getElementById('megye_terkep').selectedIndex].value);
	}
	
	function cimkereso()
	{
		address = document.getElementById('cimkereso_box').value;
		
		g = new GClientGeocoder();
		
		g.getLatLng(address,function(point) {
            if (!point) {
              alert("Hibás cím: "+ address);
            } else {
              map.setCenter(point, 13);
              address_list[address_count] = new GMarker(point);
              map.addOverlay(address_list[address_count]);
              address_list[address_count].openInfoWindowHtml(address);
			  address_count++;
            }
          }
        );
	}
	
	function submit_a_button(e,id)
	{
		var keynum;
		var keychar;
		
		if(window.event) { keynum = e.keyCode; }
		else if(e.which) { keynum = e.which; }
		keychar = String.fromCharCode(keynum);
	
		if (keynum==13) { document.getElementById(id).click(); }
		else { return keychar; }
	}
	
	//GPS koordináta kereső metódusai
	function show_gps()
	{
		if (typeof(GPS_marker)=='undefined') 
		{
			GPS_marker = new GMarker(new GLatLng(document.getElementById('GPS_Lat').value,document.getElementById('GPS_Lng').value), { draggable: true });
			GEvent.addListener(GPS_marker, "dragend", function() { var point; point=GPS_marker.getLatLng(); GPS_marker.openInfoWindowHtml('Lat: '+point.lat()+'<br>Lng: '+point.lng()); });
		}
		else
		{
			GPS_marker.setLatLng(new GLatLng(document.getElementById('GPS_Lat').value,document.getElementById('GPS_Lng').value));
			if (GPS_marker.isHidden()) { GPS_marker.show(); }
		}
		map.addOverlay(GPS_marker);
		GPS_marker.openInfoWindowHtml('Lat: '+document.getElementById('GPS_Lat').value+'<br>Lng:'+document.getElementById('GPS_Lng').value);
		map.setCenter(GPS_marker.getLatLng());
	}
	
	function jump_to_gps()
	{
		if (typeof(GPS_marker)=='undefined') { alert(gmap_content[7]); } else {	map.setCenter(GPS_marker.getLatLng()); }
	}
	
	function show_hide_marker()
	{
		if (typeof(GPS_marker)!='undefined') { GPS_marker.closeInfoWindow(); GPS_marker.hide(); }	
	}
	
	//Weboldalon térkép betöltés
	function load_map_if_needed()
	{
		var url = new String(window.location);
		
		if (url.indexOf('terkep.gcw')>0)
		{
			load(true);
			var hely_id = new String(window.location.search);
			if (hely_id.indexOf('hely_id')>0)
			{
				mutat_hely(hely_id.substr(hely_id.indexOf('=')+1,5));
			}
			
			if (hely_id.indexOf('vend_id')>0)
			{
				mutat_vend(hely_id.substr(hely_id.indexOf('=')+1,5));
			}
			
			if (hely_id.indexOf('varos_nev')>0)
			{
				var point;
				var marker; 
				var varos_nev = hely_id.substr(hely_id.indexOf('=')+1,41)
				g = new GClientGeocoder();
		
				g.getLatLng('Hungary, '+varos_nev,
				function(point)
				{
            		if (!point) 
					{ alert("Hibás cím: "+ varos_nev); } 
					else 
					{
            			map.setCenter(point, 10);
            			marker = new GMarker(point);
            			map.addOverlay(marker);
						marker.openInfoWindowHtml('<b>'+varos_nev+'</b>');
						GEvent.addListener(marker,"click", function() { marker.openInfoWindowHtml('<b>'+varos_nev+'</b>'); } );
            	}
          	});
			}
		}
		else if (url.indexOf('moreinfo.gcw')>0||url.indexOf('helyszin.gcw')>0)
		{		
			load(false);
			
			var point;
			var marker; 
			
			if (hely_coordx>0)
			{
				point = new GLatLng(hely_coordx,hely_coordy);
				marker = new GMarker(point);
				map.addOverlay(marker);
				map.setCenter(marker.getPoint(), 15);
				marker.openInfoWindow('<b>'+Name+'</b><br>'+address+'<br><br>'+gmap_content[6]+'<a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'&put_from" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'&put_to" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a><br>'+gmap_content[8]+': '+point.lat()+', '+gmap_content[9]+': '+point.lng(),{ maxWidth: 240 });
				GEvent.addListener(marker,"click", function() { marker.openInfoWindow('<b>'+Name+'</b><br>'+address+'<br><br>'+gmap_content[6]+'<a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'"><b>'+gmap_content[1]+'</b></a><br><br>'+gmap_content[2]+'<a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'&put_from" style="cursor:pointer; font-weight:bold;">'+gmap_content[3]+'</a> '+gmap_content[4]+' <a href="terkep.gcw?hely_id='+document.getElementById('hely_id').value+'&put_to" style="cursor:pointer; font-weight:bold;">'+gmap_content[5]+'</a><br>'+gmap_content[8]+': '+point.lat()+', '+gmap_content[9]+': '+point.lng(),{ maxWidth: 240 }); } );
				
			}
			else
			{
				g = new GClientGeocoder();
				
				g.getLatLng('Hungary, '+varos_nev,
					function(point,varos_nev)
					{
            			if (!point) 
						{ alert("Hibás cím: "+ varos_nev); } 
						else 
						{
              				map.setCenter(point, 13);
              				marker = new GMarker(point);
              				map.addOverlay(marker);
              				marker.openInfoWindowHtml(varos_nev);
							GEvent.addListener(marker,"click", function() { marker.openInfoWindowHtml(varos_nev); } );
            			}
          			}
				);
			}
		}
		else if (url.indexOf('varos.gcw')>0)
		{		
			load(false);
			
			var point;
			var marker;
			
			g = new GClientGeocoder();
		
			g.getLatLng('Hungary, '+varos_nev,
			function(point)
			{
            	if (!point) 
				{ alert("Hibás cím: "+ varos_nev); } 
				else 
				{
            		map.setCenter(point, 10);
            		marker = new GMarker(point);
            		map.addOverlay(marker);
            		marker.openInfoWindowHtml('<b>'+varos_nev+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw?varos_nev='+varos_nev+'"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 });
					GEvent.addListener(marker,"click", function() { marker.openInfoWindowHtml('<b>'+varos_nev+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 }); } );
            	}
          	});
		}
		else if (url.indexOf('megye.gcw')>0)
		{		
			load(false);
			
			var point;
			var marker; 
			
			point = new GLatLng(megye_geocodes[megye_id][0],megye_geocodes[megye_id][1]);
			marker = new GMarker(point);
			map.addOverlay(marker);
			map.setCenter(marker.getPoint(), 8);
			marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw?megye_id='+megye_id+'"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 });
			GEvent.addListener(marker,"click", function() { marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw?megye_id='+megye_id+'"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 }); } );
		}
		else if (url.indexOf('regio.gcw')>0)
		{		
			load(false);
			
			var point;
			var marker; 
			
			point = new GLatLng(regio_geocodes[regio_id][0],regio_geocodes[regio_id][1]);
			marker = new GMarker(point);
			map.addOverlay(marker);
			map.setCenter(marker.getPoint(), 7);
			marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 });
			GEvent.addListener(marker,"click", function() { marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 }); } );
		}
		else if (url.indexOf('vend.gcw')>0)
		{
			load(false);
			
			var point;
			var marker; 
			
			if (hely_coordx>0)
			{
				point = new GLatLng(hely_coordx,hely_coordy);
				marker = new GMarker(point);
				map.addOverlay(marker);
				map.setCenter(marker.getPoint(), 15);
				marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw?vend_id='+document.getElementById('vend_id').value+'"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 });
				GEvent.addListener(marker,"click", function() { marker.openInfoWindow('<b>'+Name+'</b><br><br>'+gmap_content[6]+'<a href="terkep.gcw?vend_id='+document.getElementById('vend_id').value+'"><b>'+gmap_content[1]+'</b></a>',{ maxWidth: 240 }); } );
			}
			else
			{
				g = new GClientGeocoder();
		
				g.getLatLng('Hungary, '+varos_nev,
					function(point)
					{
            			if (!point) 
						{ alert("Hibás cím: "+ varos_nev); } 
						else 
						{
              				map.setCenter(point, 13);
              				marker = new GMarker(point);
              				map.addOverlay(marker);
              				marker.openInfoWindowHtml(varos_nev);
							GEvent.addListener(marker,"click", function() { marker.openInfoWindowHtml(varos_nev); } );
            			}
          			}
				);
			}
		}
	}