// Javascript functions

// Set the Rules for the PNG Files and Backgrounds
function addPNGRule() {
	if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
		document.styleSheets[0].addRule('.png', 'behavior: url(/css/iepngfix.htc)');
	}
}

// Show functions in list
// Show the next element
function toggle_funcs(elm) {
	
	var elm_a = elm.getChildren()[1];
	//alert(elm_a);return;
	
	if (elm_a.getStyle('display') == 'none') {
		elm_a.setStyle('display', 'block');
	} else {
		elm_a.setStyle('display', 'none');
	}
}

// Show and Hide Google Map in View
function showMap( div, a ) {
	if ($(div).getStyle('display') == 'none' ) {
		$(div).setStyle('display', 'block');
		$(a).setText(ItalianLang.showGoogleMap);
	} else {
		$(div).setStyle('display', 'none');
		$(a).setText(ItalianLang.hideGoogleMap);
	}
}

function initializeGoogleMap() {
	
	property = 'Event';
	
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map_canvas"));

		map.addControl(new GSmallMapControl());

		var center = new GLatLng(lt, ln);
		map.setCenter(center, zm);

		var marker = new GMarker(center, {draggable: true});

		GEvent.addListener(map, "click", function(overlay, point) {
			marker.setPoint( point );
			setMapPoint( marker.getPoint().toString(), property );
		});

		GEvent.addListener(marker, "dragend", function() {
			setMapPoint( marker.getPoint().toString(), property );
		});

		GEvent.addListener(map, "zoomend", function() {
			$(property+'GoogleZm').value = map.getZoom();
		});

		map.addOverlay(marker);

	}
}

// Set Map Poing for Google Map
function setMapPoint( p, property ) {
	
	re = /^\(([\d\.]+), ([\d\.]+)\)$/;

	var point = p.match(re);

	$(property+'GoogleLt').value = RegExp.$1;
	$(property+'GoogleLn').value = RegExp.$2;
}

// Initialization Function
function init() { addPNGRule(); }

// Set DOMReady Events
window.addEvent('domready', init);