globalWebKey="";

function setWebKey(key){
    globalWebKey=key;
}

//route
    function setDirections(fromAddress, toAddress, locale) {
		
	  if (locale == ""){  
	    locale ="nl";
	  }
	  
	  gdir.fromAddress = fromAddress;
	  gdir.toAddress = toAddress;
	  
	  if(fromAddress == "" || fromAddress =="straat, plaatsnaam"){
		  
	  }
	  else{
	      gdir.load("from: " + fromAddress +",nl" + " to: " + toAddress +",nl" ,
	                { "locale": locale, "getSteps": true /*,  "travelMode": travelMode*/});	  
	  }
	  
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Onbekend adres!");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	    alert("De route kan niet berekend worden door een fout op de server");
	   /*
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	    // alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\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("De route kan niet berekend worden");
	   
	}

	function onGDirectionsLoad(){ 
    
	try {
	    document.getElementById("directions").style.display='block';
	    //document.getElementById("detailLeft").style.display='none';
	}
	catch (e){
	    alert("onGDirectionsLoad in route.js kon de elementen niet vinden");
	}
	
	// MaxLayout.AnimateClose();
	 styleRoute();
	 map.setMapType(G_NORMAL_MAP);
	 makeRouteDescription(document.getElementById("directions"));
	  
	
	}
	
	function styleRoute(){
	
	//verberg de start marker
	//gdir.getMarker(0).getIcon().image="";
	//gdir.getMarker(0).getIcon().shadow="";
	
	//verberg de eind marker
	gdir.getMarker(1).getIcon().image=""; 
	gdir.getMarker(1).getIcon().shadow="";
	
	//overige
	gdir.getPolyline().color="blue";
	
	}
	
	function showOnMap(step){
	latLng = step.getLatLng();
    map.showMapBlowup(latLng);	
	}
	
	var fullDescriptionPrint ="";
	
	
	function makeRouteDescription(targetDiv){
	
	targetDiv.scrollTop = 0;
	targetDiv.innerHTML = "";
	
	targetDiv.style.display = "block";
	var numSteps = gdir.getRoute(0).getNumSteps();
	var htmlStringDescription = "";
	var htmlStringDescriptionPrint ="";
	var htmlStringInfo = "";
	//var printLink = "<a href=\"javascript:printPage(document.getElementById('detailLeft').innerHTML);\">print</a>";
	var start = "<tr><td><span class=\"label\">Van:</span></td><td><span class=\"text\">"+gdir.fromAddress+"</span></td></tr>";
	var eind =  "<tr><td><span class=\"label\">Naar:</span></td><td><span class=\"text\">"+gdir.toAddress+"</span></td></tr>";
	var afstand = "<tr><td><span class=\"label\">Afstand:</span></td><td><span class=\"text\">"+gdir.getDistance().html+"</span></td></tr>";
	var duur = "<tr><td><span class=\"label\">Duur:</span></td><td><span class=\"text\">"+gdir.getDuration().html+"</span></td></tr>";

	htmlStringInfo = "<table id=\"routeInfo\">"+start+eind+afstand+duur+"</table>";
	
	for(var i=0; i < numSteps; i++){

		htmlStringDescription += "<tr><td><span class=\"label\"><a href=\"javascript:showOnMap(gdir.getRoute(0).getStep("+i+"));\">"+(i+1)+ "</a></span></td><td><span class=\"text\"><a href=\"javascript:showOnMap(gdir.getRoute(0).getStep("+i+"));\">" + gdir.getRoute(0).getStep(i).getDescriptionHtml() + "</a></span></td></tr>";
        
		
		
		htmlStringDescriptionPrint += "<tr><td><span class=\"label\">"+(i+1)+ "</span></td><td><span class=\"text\">" + gdir.getRoute(0).getStep(i).getDescriptionHtml() + "</span></td></tr>";	
	    
		}
	
	
	var toonaardExtra = "";	
	
		htmlStringDescription += toonaardExtra;
		htmlStringDescriptionPrint += toonaardExtra;
	
	
	printMap = writeMapScreen(printLat,printLng,15,600,350,'mobile',printLat,printLng,globalWebKey);
	
	var printLink = "<div id=\"printDiv\"><h2>Routebeschrijving:</h2><a href=\"javascript:printPage(fullDescriptionPrint);\"><img src='/img/printYellow.gif' alt='print' title='printvriendelijke routebeschrijving' ></a></span></div>";
	
	
	var fullDescription = printLink+htmlStringInfo+"<table id=\"routeDescription\">" + htmlStringDescription + "</table>";
    
    fullDescriptionPrint = htmlStringInfo + "<br/><br/><table id=\"routeDescription\">" + htmlStringDescriptionPrint + "</table><br/>"+printMap;
	/*
	createCookie("routeDescription","",1);
	createCookie("routeDescription",escape(fullDescription),1);
	*/
	targetDiv.innerHTML = fullDescription; 


	
	// sla de string op in een cookie voor de route.html pagina
	//

	}




	function printPage(iHtml){

	    var htmlStart ="<html><head><title>Routebeschrijving - Print<\/title><link href='\/css\/detail.css' type='text\/css' rel='stylesheet'/><\/head><body onload='window.print();'>";
	    
		var logo="<div class='logodiv'><img src='/img\/logo.gif'><br\/><br\/><div class='label'>Schadenet Rijnders, Tel. 033 - 461 38 58 <\/div><br\/><\/div>";
	    
		var htmlEnd ="<\/body><\/html>";

	    var opts = 'toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,copyhistory=1,resizable=1,width=650,height=500';
	    
		var w = window.open("", "route", opts);
	    //w.document.write(htmlStart+logo+fullDescriptionPrint+image+htmlEnd);
	    w.document.write(htmlStart+logo+iHtml+htmlEnd);
	    w.document.close(); 

	}
	var printLat;
	var printLng;
		
	function setPrintLatLng(lat,lng){
	    printLat = lat.replace(",",".");
	    printLng = lng.replace(",",".");	
	}

	
	
    function writeMapScreen(centerLat,centerLong,zoom,width,height,maptype,markerLat,markerLong,key) {
        return '<img src="http://maps.google.com/staticmap?center='+centerLat+','+centerLong+'&zoom='+zoom+'&size='+width+'x'+height+'&maptype='+maptype+'&markers='+markerLat+','+markerLong+'&key='+key+'" border="0" width="'+width+'+"&height="'+height+'" />'; 
    }
	
//route



