



/*
 * ################ START BASE START ################ 
 */

//addEvent(window, "load", initBaseScripts);

function initBaseScripts() {
     step_select = document.getElementById("step_select");
     if (step_select) addEvent(step_select,"change",setStep);
     
     //search_form = document.getElementById("search");
     //if (search_form) addEvent(search_form,"submit",getCoordinates);
     
     submitbtn = document.getElementById("submitbtn");
     if (submitbtn) addEvent(submitbtn,"click",getCoordinates);

	var co = $$("div.cursorover");
	if( co.length ) {
		co.each( function(c) {
			Event.observe(c, "click", function(ev) {
				location.href = c.getAttribute("details");
			});
		});
	}
}

function setStep() {
     //alert(document.getElementById("step_url").value + "&step=" + document.getElementById("step_select").value);
     location.href = document.getElementById("step_url").value + "&step=" + document.getElementById("step_select").value;
}

//Google maps
var map = null;
var geocoder = null;
	
function initialize(w, h, z) {
	if (GBrowserIsCompatible()) {	
		map = new GMap2(document.getElementById("google_map"));
		map.setCenter(new GLatLng(w, h), z);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		geocoder = new GClientGeocoder();
		
		if (z != 7) {
               map.clearOverlays();
          	var marker = new GMarker(new GLatLng(w, h));
          	map.addOverlay(marker);
          }
	}
}

function getCoordinates() {
     address = document.getElementById("base_street").value ? document.getElementById("base_street").value : "";
     if (!address || address == 'NULL') {
          city = document.getElementById("base_city");
          index = city.selectedIndex;
          address = city.options[index].innerHTML;
     }
     address = address + ", Hungary";
     geocoder = new GClientGeocoder();
     //geocoder.getLatLng('Hungary, Budapest', testCallback);
     geocoder.getLocations(address, setCoordinateFields);
}

function setCoordinateFields(response) {
     if (!response || response.Status.code != 200) {
          alert("Nem találom a megadott címet!");
     }
     else {
          place = response.Placemark[0];
          lat   = place.Point.coordinates[1];
          lng   = place.Point.coordinates[0];
          //1072 Budapest, Klauzál utca 10, Magyarország
          //Budapest, Üllői út, Magyarország
          //alert('('+lat+','+lng+')');
          document.getElementById("coordX").value = lat;
          document.getElementById("coordY").value = lng;
          document.getElementById("search").submit();
     }
}



/*
 * ################ END BASE END ################ 
 */




