
var counting = 0;

var regGetData;
var which;

var map			= null;
var geocoder	= null;

var bounds		= new GLatLngBounds();





function getData(id)
	{


	url	= "getData.asp?id=" +  id + "&rand=" + Math.floor(Math.random()*1000000);


	if (window.XMLHttpRequest) 
		{ // Non-IE browsers

		regGetData = new XMLHttpRequest();

		regGetData.onreadystatechange = stateChangeData;

		try 
			{
			regGetData.open("GET", url, true);
			
			} 
		catch (e) 
			{
			alert(e);
			}
	
		regGetData.send(null);
		} 
	
	else if (window.ActiveXObject) 
		{ // IE

		regGetData = new ActiveXObject("Microsoft.XMLHTTP");

		if (regGetData) 
			{
			regGetData.onreadystatechange = stateChangeData;

			regGetData.open("GET", url, true);

			regGetData.send();

			}	

		}


	//return viewSchool.returnMessage.value;
	}


function stateChangeData(field) 
	{

	if (regGetData.readyState == 4) 
		{ // Complete

		if (regGetData.status == 200) 
			{ // OK response
			var newString					= regGetData.responseText;

			document.getElementById("message").innerHTML				= newString

			
			} 
		else 
			{
			alert("Problem: " + regGetData.responseText);
			}
		}
	
	}


function GUnload()
	{
	//alert(counting);
	}


function createMarker(point, id) 
	{

	var icon = new GIcon();


	iconPath	= "images/leaf3.png";



	icon.image				= iconPath;
	icon.shadow				= iconPath;
	

	icon.iconSize			= new GSize(30, 29);
	icon.shadowSize			= new GSize(30, 29);


	icon.iconAnchor			= new GPoint(15, 28);
	icon.infoWindowAnchor	= new GPoint(20, 15);



	//map.setCenter(point, 2);

	var marker				= new GMarker(point, icon);



	GEvent.addListener(marker, "click", function() 
		{
		getData(id);

		
		marker.openInfoWindowHtml('<div align="left" style="width:430px; height:200px;" id="message"></div>');


		GEvent.addListener(marker, "infowindowclose", function() 
			{
	
				//alert("hej");
			

			map.setCenter(new GLatLng(20,22),2);


			});
		

		});
	

	return marker;
	
	}



	function load() 
		{

		if (GBrowserIsCompatible()) 
			{
			map			= new GMap2(document.getElementById("map"));

			map.enableScrollWheelZoom();

			map.enableContinuousZoom();

			geocoder	= new GClientGeocoder();

			map.addControl(new GLargeMapControl());
			}
	

		map.setCenter(new GLatLng(20,22),2);

		inputString			= form1.data.value;

		addresses			= inputString.split("%");

		//alert(addresses.length);

		for (i = 0; i < addresses.length; i++)
			{

			data			= addresses[i].split(";");

			id				= data[2];
			//address			= data[1];
			x				= data[0];
			y				= data[1];
			//type			= data[4];

			if (x)
				{
				
				//alert("Point : " + x + " " + y);

				var g_point	= new GPoint(x, y);


				//var g_point = new GLatLng(x, y);

				//map.addOverlay(new GMarker(g_point));
				
				//bounds.extend(point);


				map.addOverlay(createMarker(g_point, id));	
				}
			else
				{
				//showAddress(address, id);
				}
			}

		

		}


	function showAddress(address, id) 
		{

		if (geocoder) 
			{
			geocoder.getLatLng(address, function(point) 
				{

				if (!point) 
					{
					//alert(address + " not found");
					} 
				else 
					{
					counting++;

					//alert(point.x);
					//alert(point.y);
					//alert(point);


					savePoint(point.x, point.y, id);

					bounds.extend(point);

					map.addOverlay(createMarker(point, id));
					
					}
				}

			);
		}





	}
