// JavaScript Document

//Globale Variablen: Arrays in denen die Polygone, Linien und Punkte gespeichert werden.
	var g_DoMa = null;
	var g_map = null;
	var Dosis = new Array();
	var Colors = new Array();
	var Global = null;
	var anfrage = null;
	var BackURI = null;
	var anfrage = null;
	
	//Beim laden der Webseite wird colors gefuellt.
	Dosis.push(0);
	Colors.push("#FF0000");
	Dosis.push(10);
	Colors.push("#FFA500");
	Dosis.push(20);
	Colors.push("#FFFF00");
	Dosis.push(30);
	Colors.push("#CDFF00");
	Dosis.push(40);
	Colors.push("#7FFF00");
	Dosis.push(50);
	Colors.push("#00FF00");
	Dosis.push(60);
	Colors.push("#00EE00");
	Dosis.push(70);
	Colors.push("#00CD00");
	Dosis.push(80);
	Colors.push("#008B00");
	Dosis.push(90);
	Colors.push("#006400");
	Dosis.push(100);
	Colors.push("#FFFFFF");
	Dosis.push(110);
	Colors.push("#00FFFF");
	Dosis.push(120);
	Colors.push("#00F5FF");
	Dosis.push(130);
	Colors.push("#00EEEE");
	Dosis.push(140);
	Colors.push("#87CEFF");
	Dosis.push(150);
	Colors.push("#6CA6CD");
	Dosis.push(160);
	Colors.push("#0000FF");
	Dosis.push(170);
	Colors.push("#0000EE");
	Dosis.push(180);
	Colors.push("#0000CD");
	Dosis.push(190);
	Colors.push("#00008B");
	Dosis.push(200);
	Colors.push("#000000");
	
	//schaltet die Moeglichkeit, die Karte mit der Maus zu bewegen an und aus.
	//gibt false zurueck, wenn die Karte auf nicht bewegbar gestellt wurde, sonst true.
	function MapMoveOnOut()
	{
		if(g_map.draggingEnabled())
		{
			g_map.disableDragging();
			return false;
		}
		else
		{
			g_map.enableDragging();
			return true;
		}
	}
	
	function getColorValue(ds)
	{
		dosi = parseInt(ds);
		switch (dosi)
		{
			case 0:
				return Colors[0];
				break;
			case 10:
				return Colors[1];
				break;
			case 20:
				return Colors[2];
				break;
			case 30:
				return Colors[3];
				break;
			case 40:
				return Colors[4];
				break;
			case 50:
				return Colors[5];
				break;
			case 60:
				return Colors[6];
				break;
			case 70:
				return Colors[7];
				break;
			case 80:
				return Colors[8];
				break;
			case 90:
				return Colors[9];
				break;
			case 100:
				return Colors[10];
				break;
			case 110:
				return Colors[11];
				break;
			case 120:
				return Colors[12];
				break;
			case 130:
				return Colors[13];
				break;
			case 140:
				return Colors[14];
				break;
			case 150:
				return Colors[15];
				break;
			case 160:
				return Colors[16];
				break;
			case 170:
				return Colors[17];
				break;
			case 180:
				return Colors[18];
				break;
			case 190:
				return Colors[19];
				break;
			case 200:
				return Colors[20];
				break;
			default:
				//alert("No color found!");
				return 0;
		}
	}

	
	function resize()
	{	
		alert("resize");
		var map_obj=document.getElementById("map_canvas");	
		var disp=getDispSize();	
		map_obj.style.width=(disp.width - 20)+"px";	
		map_obj.style.height=(disp.height - 30)+"px";	
		if( g_map )
		{	       
			g_map.checkResize();	       
			//g_map.panTo(new GLatLng(0, 0));	
		}
	}
	
	function getDispSize()
	{	
		alert("getDispSize");
		if(document.all)
		{	       
			if(window.opera)
			{		   
				return {width:document.body.clientWidth,height:document.body.clientHeight};
			}
			else
			{		   
				return {width:document.documentElement.clientWidth,height:document.documentElement.clientHeight};
			}	
		} 
		else if(document.layers || document.getElementById)
		{	       
			return {width:window.innerWidth,height:window.innerHeight};	
		}    
	}
	
	function GetLatlngfromAdress(address)
	{
		Geocoder = new GClientGeocoder();
		Geocoder.getLatLng(address, ZoomtoAddress)
	}
	
	function ZoomtoAddress(latlng)
	{
		if(latlng)
		{
			g_map.setZoom(15);
			g_map.panTo(latlng);
		}
		else
		{
			alert("Adresse wurde nicht gefunden.");
		}
	}
	
function OnMoveEnd()
{
	g_DoMa.CheckArray();
	g_DoMa.IsOnMap();
	g_DoMa.RemoveText();
	g_DoMa.WriteText();
}
	
  function initialize() 
	  {
      if (GBrowserIsCompatible()) {
		  //resize();
		var agent=navigator.userAgent.toLowerCase();
		var is_iphone = (agent.indexOf('iphone')!=-1);
		if(is_iphone)		
		{
			alert("Diese Webseite kann auf dem IPhone nicht angezeigt werden.");
			OnBtBack();
		}
        g_map = new GMap2(document.getElementById("map_canvas"));
		//g_map.addMapType(G_PHYSICAL_MAP);
		//g_map.addMapType(G_SATELLITE_3D_MAP);
        g_map.setCenter(new GLatLng(49.46140225, 8.621649742), 15);
		g_map.disableDoubleClickZoom();
		
        g_map.addControl(new GSmallMapControl());
        g_map.addControl(new GMapTypeControl());
		g_map.setMapType(G_HYBRID_MAP)
		g_DoMa = new DosiMap();
		g_DoMa.Init(Global);
		
		SetBetriebHa(g_DoMa.GetBetriebHa());
		
		DemoResetButtons();
		
		CalcDuengerSparer();
		
		GEvent.addListener(g_map,"moveend", function() 
		{
			OnMoveEnd();
		});
		GEvent.addListener(g_map,"movestart", function()
		{
			g_DoMa.RemoveText();
		});
		
		if(g_DoMa.getPolyCount() != 0)
		{
			//alert(g_DoMa.getPolyCount());
			g_DoMa.Zoom();
		}
		else
		{
			g_DoMa.Zoom2Init();
		}
      }
	  else
	  {
	  	alert("Diese Webseite ist zu ihrem Browser nicht kompatibel.");
	  }
	  //g_map.checkResize()
    }
