//<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var pass_from;
    var pass_to;
    var newwindow;
//    var trafficInfo;
	
    google.setOnLoadCallback(initialize);
    
    function initialize() {
      if (google.maps.BrowserIsCompatible()) {      
        map = new google.maps.Map2(document.getElementById("map_canvas"));
        gdir = new google.maps.Directions(map, document.getElementById("directions"));
        google.maps.Event.addListener(gdir, "load", onGDirectionsLoad);
        google.maps.Event.addListener(gdir, "error", handleErrors);
        map.addControl(new google.maps.LargeMapControl());
        map.addControl(new google.maps.MapTypeControl());
        var pline = new google.maps.Polyline([
          new google.maps.LatLng(parseFloat("57.33"),parseFloat("37")),
          new google.maps.LatLng(parseFloat("57.33"),parseFloat("41")),
          new google.maps.LatLng(parseFloat("54.67"),parseFloat("41")),
          new google.maps.LatLng(parseFloat("54.67"),parseFloat("40")),
          new google.maps.LatLng(parseFloat("54"),parseFloat("40")),
          new google.maps.LatLng(parseFloat("54"),parseFloat("38")),
          new google.maps.LatLng(parseFloat("54.67"),parseFloat("38")),
          new google.maps.LatLng(parseFloat("54.67"),parseFloat("35")),
          new google.maps.LatLng(parseFloat("56.67"),parseFloat("35")),
          new google.maps.LatLng(parseFloat("56.67"),parseFloat("37")),
          new google.maps.LatLng(parseFloat("57.33"),parseFloat("37"))
          ], "#0000FF", 5, 1);
				map.setCenter(new google.maps.LatLng(55.8,38),10);
        setDirections(ifrom,ito,'ru');
        map.addOverlay(pline);
// Traffic is not available yet for Russia
//        var trafficOptions = {incidents:true};
//			  trafficInfo = new GTrafficOverlay(trafficOptions);
//			  map.addOverlay(trafficInfo);
      }
    }

    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
    }

		function showBorders(){
			map.setCenter(new google.maps.LatLng(55.8,38),7);
			window.location.href="#show_map";
		}
    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert(M_UA + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert(M_SE + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert(M_MQ + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)
	//     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 Номер ошибки: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert(M_BK + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert(M_BR + gdir.getStatus().code);
	    
	   else if (gdir.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
	     alert(M_UD + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_TOO_MANY_QUERIES)
	     alert(M_TMQ + gdir.getStatus().code);

	   else alert(M_UE + gdir.getStatus().code);
	   
	}

	function onGDirectionsLoad(){ 
        document.ddform.s_street_name.focus();
	}
	function OnSubmitddForm(from, to, locale){
		setDirections(from, to, locale);
	}
	function OnSubmitForm(from, to, locale){
		pass_from = from;
		pass_to = to;
		newwindow = window.open('http://www.marwrut.ru/dd_horiz.html','results','location=1,status=1,scrollbars=1,resizable=yes,width=800,height=560');
	}
	function OnSubmitFormSwitch(from, to, locale){
		switch(document.pressed){
			case 'show':
				setDirections(from, to, locale);
			break
			case 'print':
				pass_from = from;
				pass_to = to;
				newwindow = window.open('http://www.marwrut.ru/dd_horiz.html','results','location=1,status=1,scrollbars=1,width=800,height=560');
		}
	}