// z(ne)viditelneni prvku
function showElement(name1, fields) {
	var obj1 = document.getElementById(name1);
	if (obj1==null) {
		return;
	}
	obj1.style.display = 'block';

	name1=name1+'-tb';
	var obj1 = document.getElementById(name1);
	obj1.className='tab-sel';

	// projdeme vsechny zalozky v poli ktere se maji schovat
	for (var i=0; i<fields.length; i++) {
		field_name=fields[i];
		obj=document.getElementById(field_name);

		if (obj!=null) {
			obj.style.display = 'none';

			name2=field_name+'-tb';
			var obj2 = document.getElementById(name2);
			if (obj2!=null) {
				obj2.className='sel-tab';
			}
		}
	}

}

function initializeGoogleMap(parID) {
	if (parID==706) {
		initialize(50.004484, 14.404857, 'praha-map', '<h3>Tyros Loading Systems CZ, s.r.o.</h3><p>Komořanská 43/10<br />143 00 Praha 12, Modřany</p>');
	} else if (parID==707) {
		initialize1(50.130056, 16.183634, 'castolovice-map', '<h3>Tyros Loading Systems CZ, s.r.o.</h3><p>Husova 181<br />517 50 Častolovice</p>');
	} else if (parID==715) {
		initialize2(49.60092, 18.023586, 'novy-jicin-map', '<h3>Tyros Loading Systems CZ, s.r.o.</h3><p>Dostojevského 5<br />741 01 Nový Jičín</p>');
	} else if (parID==713) {
		initialize3(50.004484, 14.404857, 'sidlo-map', '<h3>Tyros Loading Systems CZ, s.r.o.</h3><p>Komořanská 43/10<br />143 00 Praha 12, Modřany</p>');
	} else if (parID==709) {
		initialize(48.618306, 17.721142, 'sidlo-map', '<h3>Tyros Loading Systems SK s. r. o.</h3><p>Šteruská cesta 21<br />922 03 Vrbové</p>');
	} else if (parID==710) {
		initialize(49.212847, 18.775631, 'zilina-map', '<h3>Tyros Loading Systems SK s. r. o.</h3><p>Osloboditelov 22<br />01001 Žilina</p>');
	} else if (parID==711) {
		initialize(48.733186, 21.252481, 'rozhanovce-map', '<h3>Tyros Loading Systems SK s. r. o.</h3><p>Družstevná 5/454<br />04442 Rozhanovce</p>');
	}
}

var map;
    var map1;
    var map2;
    var map3;
    var gdir;
    var gdir1;
    var gdir2;
    var gdir3;
    var geocoder = null;
    var addressMarker;
    var addressMarker1;
    var addressMarker2;
    var addressMarker3;

    function initialize(latitude, longitude, div_id, address) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById(div_id));
        gdir = new GDirections(map, document.getElementById("directions-"+div_id));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        map.setCenter(new GLatLng(latitude, longitude), 14);
        map.addControl(new GLargeMapControl());


        var icon = new GIcon(G_DEFAULT_ICON);
        //icon.image = '/imgs/ukazatel.png';
        icon.iconSize = new GSize(25, 35);

        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
        var marker = new GMarker(new GLatLng(latitude, longitude), icon);

        map.addOverlay(marker);


        GEvent.addListener(marker, "mouseover", function() {
        marker.openInfoWindowHtml(address);
});

      GEvent.addListener(marker, "mouseout", function() { map.closeInfoWindow(); });

        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
      }
    }
    
    function initialize1(latitude, longitude, div_id, address) {
      if (GBrowserIsCompatible()) {
        map1 = new GMap2(document.getElementById(div_id));
        gdir1 = new GDirections(map, document.getElementById("directions-"+div_id));
        GEvent.addListener(gdir1, "load", onGDirectionsLoad);
        GEvent.addListener(gdir1, "error", handleErrors);
        map1.setCenter(new GLatLng(latitude, longitude), 14);
        map1.addControl(new GLargeMapControl());


        var icon1 = new GIcon(G_DEFAULT_ICON);
        //icon.image = '/imgs/ukazatel.png';
        icon1.iconSize = new GSize(25, 35);

        var mapControl1 = new GMapTypeControl();
        map1.addControl(mapControl1);
        var marker1 = new GMarker(new GLatLng(latitude, longitude), icon1);

        map1.addOverlay(marker1);


        GEvent.addListener(marker1, "mouseover", function() {
        marker1.openInfoWindowHtml(address);
});

      GEvent.addListener(marker1, "mouseout", function() { map1.closeInfoWindow(); });

        var mapControl1 = new GMapTypeControl();
        map1.addControl(mapControl1);
      }
    }
    
    function initialize2(latitude, longitude, div_id, address) {
      if (GBrowserIsCompatible()) {
        map2 = new GMap2(document.getElementById(div_id));
        gdir2 = new GDirections(map, document.getElementById("directions-"+div_id));
        GEvent.addListener(gdir2, "load", onGDirectionsLoad);
        GEvent.addListener(gdir2, "error", handleErrors);
        map2.setCenter(new GLatLng(latitude, longitude),14);
        map2.addControl(new GLargeMapControl());


        var icon2 = new GIcon(G_DEFAULT_ICON);
        //icon.image = '/imgs/ukazatel.png';
        icon2.iconSize = new GSize(25, 35);

        var mapControl2 = new GMapTypeControl();
        map2.addControl(mapControl2);
        var marker2 = new GMarker(new GLatLng(latitude, longitude), icon2);

        map2.addOverlay(marker2);


        GEvent.addListener(marker2, "mouseover", function() {
        marker2.openInfoWindowHtml(address);
});

      GEvent.addListener(marker2, "mouseout", function() { map2.closeInfoWindow(); });

        var mapControl2 = new GMapTypeControl();
        map2.addControl(mapControl2);
      }
    }
    
    function initialize3(latitude, longitude, div_id, address) {
      if (GBrowserIsCompatible()) {
        map3 = new GMap2(document.getElementById(div_id));
        gdir3 = new GDirections(map, document.getElementById("directions-"+div_id));
        GEvent.addListener(gdir3, "load", onGDirectionsLoad);
        GEvent.addListener(gdir3, "error", handleErrors);
        map3.setCenter(new GLatLng(latitude, longitude),14);
        map3.addControl(new GLargeMapControl());


        var icon3 = new GIcon(G_DEFAULT_ICON);
        //icon.image = '/imgs/ukazatel.png';
        icon3.iconSize = new GSize(25, 35);

        var mapControl3 = new GMapTypeControl();
        map3.addControl(mapControl3);
        var marker3 = new GMarker(new GLatLng(latitude, longitude), icon3);

        map3.addOverlay(marker3);


        GEvent.addListener(marker3, "mouseover", function() {
        marker3.openInfoWindowHtml(address);
});

      GEvent.addListener(marker3, "mouseout", function() { map3.closeInfoWindow(); });

        var mapControl3 = new GMapTypeControl();
        map3.addControl(mapControl3);
      }
    }

    function setDirections(fromAddress, toAddress, locale) {
      $('#odstavec-directions').hide();
      gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": "cs" });
    }

    function setDirections1(fromAddress, toAddress, locale) {
      $('#odstavec-directions').hide();
      gdir1.load("from: " + fromAddress + " to: " + toAddress, { "locale": "cs" });
    }

    function setDirections2(fromAddress, toAddress, locale) {
      $('#odstavec-directions').hide();
      gdir2.load("from: " + fromAddress + " to: " + toAddress, { "locale": "cs" });
    }

    function setDirections3(fromAddress, toAddress, locale) {
      $('#odstavec-directions').hide();
      gdir3.load("from: " + fromAddress + " to: " + toAddress, { "locale": "cs" });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Vámi zvolené místo nejspíše neexistuje. Zkuste se podívat, zda jste se nepřeklepli nebo zkuste zadat jiné ve vaší blízkosti.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Jejda... stala se chyba někde u Google Map, zkuste zadat jiné místo ve vaší blízkosti, nebo opakujte váš požadavek pozdeji.");

	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Chyba HTTP  parametr q buď chybí, nebo není zadána jeho hodnota. Pro určení místa lokace to znamená že byla zadáno prázdné pole pro vepsání lokace. Pro vyhledání cesty se tato chyba jeví jako nespecifikovaný dotaz.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("Vložený klíč není buď validní, nebo neodpovídá oblasti, pro kterou byl vydán.");

	   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.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Cesta nemohla být nalezena. Zkuste zadat jiné místo.");

	   else alert("Vámi zvolené místo nejspíše neexistuje. Zkuste se podívat zda jste se nepřeklepli nebo zkusite zadat jiné ve vaší blízkosti.");

	}

	function onGDirectionsLoad(){
    $('#odstavec-directions').show();
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}