// GOOGLE MAPS:

var map_inited='no';
var map;
var gdir;
var geocoder = null;
var addressMarker;

function map_init() {
      if (GBrowserIsCompatible()) {  
	document.getElementById("googlemap").innerHTML="";
	document.getElementById("image_outer").style.display="none";
        map = new GMap2(document.getElementById("googlemap"));
        map.setUIToDefault();
		map_inited='yes';
				
        gdir = new GDirections(map, document.getElementById("route_content"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

				map.setCenter(new GLatLng(51.030802,13.729981),13);
        var MBIcon = new GIcon(G_DEFAULT_ICON);
//        MBIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        MBIcon.iconSize = new GSize(100, 57);
        MBIcon.shadowSize = new GSize(0, 0);
        MBIcon.iconAnchor = new GPoint(82, 57);
        MBIcon.infoWindowAnchor = new GPoint(9, 2);
        MBIcon.image = "http://mb.crewcreations.de/images/marker.png";
        var marker = new GMarker(new GLatLng(51.030802,13.729981), { icon:MBIcon });
        map.addOverlay(marker);


// 				document.getElementById('staticmap').style.display="none";
      //  setDirections("San Francisco", "Mountain View", "en_US");
      }
}
    function setDirections() {
			document.getElementById('error').style.display="none";
			if(map_inited!='yes')map_init();
			var fromAddress=document.getElementById('dir_from').value;
			var toAddress="51.030802,13.729981";
			var locale="de_DE";
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
// 			document.getElementById('route_head').style.display="";
			document.getElementById('route_content').style.display="";
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		{
	     		document.getElementById('error').innerHTML="Es konnte kein Abfahrtort gefunden werden. Bitte &uuml;berpr&uuml;fen Sie Ihre Adresse und erg&auml;nzen Sie gegebenenfalls Postleitzahl oder Ort.";
			document.getElementById('error').style.display="";
		}
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		{
	     		document.getElementById('error').innerHTML="Aufgrund technischer Probleme konnte keine Route berechnet werden.";
			document.getElementById('error').style.display="";
	   	}
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		{
			document.getElementById('error').innerHTML="Aufgrund technischer Probleme konnte keine Route berechnet werden.";
			document.getElementById('error').style.display="";
		}

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}


function k2p(s)
{
  var
    stelle;
  stelle = s.indexOf(',');
  while (stelle > -1)
  {
    s = s.substring(0,stelle)+'.'+s.substring(stelle+1,s.length);
    stelle = s.indexOf(',');
  };
  return s;
}

function p2k(q)  
{
  var a;
  var b;
  var c;
	
  a=Math.round(q-0.5);
  b=Math.round((q-a)*100);
  if(Math.round(b/100)==b/100)b=b+'0';
	c=a+',';
	if (b<10)c=c+'0';
	c=c+b;
  return c; 
  
}

function komma_setzen(f,m)
{
var s;
var x=k2p(document.alk.elements[f].value);
x=x*100;
x=Math.round(x)
x=x/100;
s=p2k(x);
if(m=='2')s=s.substring(0,s.length-1);
document.alk.elements[f].value=s;
document.alk.elements[f].focus();
}
function leeren(f)
{
document.alk.elements[f].value='';
document.alk.elements[f].focus();
}

function alc_err(elm,text)
{
	alert(text);

}

