function installSearchEngine() {
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.krakow.come2europe.eu/mapsearch.xml");
 } else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine("http://www.krakow.come2europe.eu/mapsearch.src",
                                  "http://www.krakow.come2europe.eu/favicon.png",
                                  "[c2e] Znajdz w Krakowie", "");
 }
}

function createMarker(id, point, icon, info1) {
	markers[id] = new GMarker(point,icon);
	infoTabs[id] = info1;
	GEvent.addListener(markers[id], "click", function() {
		markers[id].openInfoWindowHtml(infoTabs[id]);
	});
	return markers[id];
}

var lastElem=null;
function findAtMap(id, zoom) {
	window.setTimeout(function() {
		map.panTo(markers[id].getPoint());
		markers[id].openInfoWindowHtml(infoTabs[id]);
	}, 500);
	if(zoom!=0) {
	    map.setZoom(zoom);
	}
	if(lastElem!=null) {
		lastElem.className='';
	}
	lastElem=getElem("mresult_"+id);
	lastElem.className="activeresult";
	location.hash="#mapa";
}

function showDirections(id) {
	fromP = markers[document.getElementById("fromi_"+id).value].getPoint().toUrlValue(6);
	toId=document.getElementById("toi_"+id).value;
	if(toId!=-1) {
	    toP = markers[toId].getPoint().toUrlValue(6);
	} else {
	    toP = "Poland, Krakow, "+document.getElementById("toi2_"+id).value;
	}
	
    gdir.load("from: " + fromP + " to: " + toP, { "locale": "en-us" });
    return false;
}

function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Nie udalo sie odnalezc adresu pasujacego do zapytania");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Nie udalo sie zaprezentowac trasy obejmujacej zadane miejsca");
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Nie podano prawidlowego adresu punktow");
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("Nieprawidlowe wywolanie uslugi");
//gdir.getStatus().code
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Nieprawidlwe wywolanie uslugi 2");
	   else alert("Wystapil nieznany blad.");
	}

	function onGDirectionsLoad(){ 
	}
	
	function wheelevent(e) {
	    if (!e) e = window.event;
	    if (e.preventDefault) e.preventDefault();
	    e.returnValue = false;
	}
