function collapseMenu(menuId){
	var mySpace = jq("#"+menuId).width();
	var myWidth = 0;
	var myChild = 0;
	jq("#"+menuId+" > li").each(function() {
		myWidth += jq(this).width();
		myChild++;
	});
	var myPadding = Math.floor(((mySpace-myWidth)/myChild)/2);
	jq("#"+menuId+" > li > a").each(function() {
		jq(this).css({"padding-left":myPadding, "padding-right":myPadding});
	});
	jq("#"+menuId).css("width", "auto");
}

function checkIBrowser(){
	var isCSS, isW3C, isIE4, isIE6CSS, isNN4, isNN6, isOPR, widthWindow;
	isCSS = (document.body && document.body.style) ? true : false;
	isW3C = (isCSS && document.getElementById) ? true : false;
	isIE4 = (isCSS && document.all) ? true : false;
	isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	isNN4 = (document.layers) ? true : false;
	isNN6 = (document.getElementById && !document.all) ? true : false;
	isOPR = (window.opera) ? true : false;
	if (isW3C) {
		widthWindow = (isNN6)? window.innerWidth : (isIE4)? document.body.clientWidth : 800;		    	        
		var ad_right = document.getElementById("ADright");
		if(ad_right){
			if (widthWindow > 1260) {
				ad_right.style.display = "block";
			} else {
				ad_right.style.display = "none";						
			}
		}
		return true;		
	} else {
	 	return false;	
	}
}
function setAccomodation (mySelect){
	if(mySelect.value != "null"){
		if(mySelect.id == 'accomodation1'){
			document.getElementById('accomodation2').value = "null";
		} else {
			document.getElementById('accomodation1').value = "null";
		}
	}
}
function verifyEnrolment(){
	return false;
}

// FUNZIONI PER LA MAPPA V3
var i, infoBox, maps;
i = 1;
var myZindex = 0;
var changeZoom = false;

function setMarkers(mapId, optiones, zoom, mapType, showCursor, multiple, showBox, openBox) {
	if (multiple == undefined) multiple = false;
	var multipleCategory = "";
	if(multiple != false && multiple !== true){
		multipleCategory = multiple;
		multiple = true;
	}
	if (showBox == undefined) showBox = false;
	if (openBox == undefined) openBox = false;
	if (showBox || openBox != false) infoBox = new BFInfoWindow();
	var myMarker = new Array();
	myMarker['iconsize'] = "30,30";
	myMarker['iconhancor'] = "0,15";
	for (names in optiones) myMarker[names] = optiones[names];
	var latlng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	if(mapType == undefined) mapType = "ROADMAP"; //ROADMAP - SATELLITE - HYBRID - TERRAIN 
	if(showCursor == undefined) showCursor = false;
    var myOptions = {
		disableDefaultUI: showCursor,
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
	
    maps = new google.maps.Map(document.getElementById(mapId), myOptions);
	
	var markerBounds = new google.maps.LatLngBounds();
	
	var myLatLng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	
	if (multiple){
		if(multipleCategory != "") multipleCategory = "?sectionId="+ multipleCategory;
		downloadUrl("/assets/interestPoint.php"+ multipleCategory, function(data, responseCode) {

  			var markers_def = data.documentElement.getElementsByTagName("marker");
			for (var i_def=0; i_def<markers_def.length; i_def++) {
				
				markerBounds.extend(new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))));
				
				if(openBox != false && openBox == markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: '/images/iconMarkerBig.png',
						zIndex: 1000000000
					});
					openInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps);
				} else if(openBox != false && openBox != markers_def[i_def].getAttribute("id")){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						title: markers_def[i_def].getAttribute("name"),
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					attachURL(marker, markers_def[i_def].getAttribute("url"));
				} else if(openBox == false){
					var marker = new google.maps.Marker({
						position: new google.maps.LatLng(parseFloat(markers_def[i_def].getAttribute("lat")), parseFloat(markers_def[i_def].getAttribute("lng"))),
						map: maps,
						icon: markers_def[i_def].getAttribute("idImg"),
						zIndex: myZindex + 1
					});
					
					google.maps.event.addListener(marker, "mouseover", function() {
						this.setZIndex(myZindex + 1);
						myZindex = myZindex + 1;
					});
	
					if(markers_def[i_def].getAttribute("url") != "") {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps, markers_def[i_def].getAttribute("url"));
						attachURL(marker, markers_def[i_def].getAttribute("url"));
					} else {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps);
					}
					myZindex++;
				}
			}
			if(openBox == false){
				if(markers_def.length > 1){
					markerBounds.extend(new google.maps.LatLng(45.50382042918905, 12.327561378479004));
					maps.fitBounds(markerBounds);
				}
				google.maps.event.addListener(maps, 'zoom_changed', function() {
					if(changeZoom == false){
						if(markers_def.length < 2 && maps.getZoom() > 13) maps.setZoom(13);
						changeZoom = true;
					} 
				});
			}
		});
	} else {
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: maps,
			icon: myMarker['icon']
		});
	}
	var markerHotel = new google.maps.Marker({
		position: new google.maps.LatLng(45.50382042918905, 12.327561378479004),
		map: maps,
		title: "Annia Park Hotel",
		icon:'/images/iconHotel.png',
		zIndex: 10000000000
	});
	
}
var infowindow;
function attachURL(marker, url) {
	google.maps.event.addListener(marker, "click", function() {
		location.href = url;
	});
}
function attachInfoBox(marker, text, myMap, url) {
	google.maps.event.addListener(marker, "mouseover", function() {
		myZindex = myZindex + 1;
		this.setZIndex(myZindex);
		infoBox.setContent(text);
		infoBox.setUrl(url);
		infoBox.open(myMap, this);
		this.setIcon('/images/iconMarkerBig.png');
	});
	google.maps.event.addListener(marker, "mouseout", function() {
		this.setIcon('/images/iconMarker.png');
		setTimeout('infoBox.close()', 100);
	});
}
function openInfoBox(marker, text, myMap) {
	var myLatLan = marker.getPosition();
	myMap.setCenter(myLatLan);
	infoBox.setContent(text);
	infoBox.open(myMap, marker);
}

var setDirection = {
	options:{
		mapContainer: document.getElementById('mapBig'),
		dirContainer: document.getElementById('dirContainer'),
		dirService: "",
		dirRenderer: "",
		map: null
	},
	init: function (myText, from, to, direction, latLan){
		if(document.getElementById('ballon')){
			setDirection.options.dirService = new google.maps.DirectionsService();
			setDirection.options.dirRenderer = new google.maps.DirectionsRenderer();
			var myFormDirection, textDirection;
			if(direction == "FROM"){
				myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="hidden" value="'+ latLan +'" />';
				myFormDirection += '<input id="to-input" type="text" value="" class="inputE" />';
				myFormDirection += '<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';
				textDirection = myText +'<br /><strong>'+ from +'</strong> - <a href="javascript:;" onclick="setDirection.init(\''+ myText +'\', \''+ from +'\', \''+ to +'\', \'TO\', \''+ latLan +'\');"><strong>'+ to +'</strong></a>'+ myFormDirection;
			} else {
				myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="text" value="" class="inputE" />';
				myFormDirection += '<input id="to-input" type="hidden" value="'+ latLan +'" />';
				myFormDirection += '<input class="inputB" onclick="setDirection.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value);" type="button" value=">" /></form>';
				textDirection = myText +'<br /><a href="javascript:;" onclick="setDirection.init(\''+ myText +'\', \''+ from +'\', \''+ to +'\', \'FROM\', \''+ latLan +'\');"><strong>'+ from +'</strong></a> - <strong>'+ to +'</strong>'+ myFormDirection;
			}
			document.getElementById('ballon').innerHTML = textDirection;
		}
	},
	getDirections: function(fromStr, toStr){
		var dirRequest = {
			origin: fromStr,
			destination: toStr,
			travelMode: google.maps.DirectionsTravelMode.DRIVING,
			unitSystem: google.maps.DirectionsUnitSystem.METRIC,
			provideTripAlternatives: true
		};
		setDirection.options.dirService.route(dirRequest, setDirection.showDirections);
	},
	showDirections: function(dirResult, dirStatus) {
		if (dirStatus != google.maps.DirectionsStatus.OK) {
		  if(typeof(dirStatusError) != 'undefined') alert(dirStatusError +"\n(Google reports: "+ dirStatus +")");
		  return;
		}
		//if(infowindow) infowindow.close();
		jq('html,body').animate({scrollTop: jq('#mapBig').offset().top - 20}, 1000);
		setDirection.options.dirRenderer.setMap(null);
		setDirection.options.dirRenderer.setMap(maps);
		jq('#dirContainer').html('');
		setDirection.options.dirRenderer.setPanel(document.getElementById('dirContainer'));
		setDirection.options.dirRenderer.setDirections(dirResult);
	}

}
var infowindow;
function setPoint(mapId, optiones, zoom, mapType, showCursor) {
	var myMarker = new Array();
	myMarker['iconsize'] = "30,30";
	myMarker['iconhancor'] = "0,15";
	myMarker['infowindow'] = "";
	
	for (names in optiones) myMarker[names] = optiones[names];
	var latlng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);
	if(mapType == undefined) mapType = "ROADMAP"; //ROADMAP - SATELLITE - HYBRID - TERRAIN 
	if(showCursor == undefined) showCursor = false;
    var myOptions = {
		disableDefaultUI: showCursor,
		mapTypeControl: false,
    	mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
    maps = new google.maps.Map(document.getElementById(mapId), myOptions);
	
	var myLatLng = new google.maps.LatLng(myMarker['lat'], myMarker['lon']);

	var marker = new google.maps.Marker({
		position: myLatLng,
		map: maps,
		icon: myMarker['icon'],
        zIndex: 10000
	});

	if(myMarker['infowindow'] != ""){
		infowindow = new google.maps.InfoWindow({
			content: myMarker['infowindow'],
			maxWidth: 350,
			position: myLatLng,
			zIndex: 100
		});
		infowindow.open(maps, infowindow);
		google.maps.event.addListener(marker, "click", function() {
			infowindow.open(maps, infowindow);
		});
	}
}

function injectText(idBox, text){
	var myBox = document.getElementById(idBox);
	if(myBox){
		myBox.innerHTML = base_64.decode(text);
	}
}

var base_64 = {
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = base_64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) output = output + String.fromCharCode(chr2);
			if (enc4 != 64) output = output + String.fromCharCode(chr3);
		}
		output = base_64._utf8_decode(output);
		return output;
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}