function startAnimate(num){
	if(num == undefined) num = 0;
	var myColor = new Array("#136EB0", "#FE9301", "#59B002", "#0188A5");
	changeColor(myColor[num]);
	num++;
	if(num > (myColor.length - 1)) num = 0;
	setTimeout("startAnimate("+num+")", 5000);
}

function changeColor(myNewColor){
	jq('#backgroundSearch').animate({ backgroundColor: myNewColor }, 500);
	jq('#claim').animate({ backgroundColor: myNewColor }, 500);
}

function fbsShare(setLocal) {
	var u = window.location.href;
	var t = document.title;
	Shadowbox.open({player:'iframe', title:'Facebook', content:'http://www.facebook.com/sharer.php?locale='+ setLocal +'&u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t), width:'626', height:'436'});
	return false;
}

function IE6(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if (ievs){
		var iev = new Number(RegExp.$1);
		if (iev < 7) return true;
	}
	return false;
}

function IE8(){
	var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
	if (ievs){
		var iev = new Number(RegExp.$1);
		if (iev >= 8) return true;
	}
	return false;
}

var resetBox = {
	options:{
		myBlock: "boxSearch",
		myHeight: 60,
		myLiHeight: 37,
		myPadding: 27,
		myAction: ""
	},
	init: function(opts) {
		for (name in opts) resetBox.options[name] = opts[name];
	},
	enlargeBox: function(numRow) {
		var myHeightEnlarge = (resetBox.options.myHeight + resetBox.options.myPadding + (resetBox.options.myLiHeight*numRow))+"px";
		document.getElementById(resetBox.options.myBlock).style.height = myHeightEnlarge;
		callToActionscript('out');
	},
	hide: function(hiding) {
		if(hiding!=true) {
			callToActionscript('in');
		} else {
			callToActionscript('out');
		}
	},
	set: function(myValue){
		if(document.getElementById(resetBox.options.myBlock)){
			myValuePassReal = parseInt(myValue);
			myValuePass = (parseInt(myValue)==1)? 1 : 4;
			myValuePass = parseInt(myValue);
			if(myValuePassReal > 1){
				resetBox.openBox(myValuePassReal, document.getElementById(resetBox.options.myBlock).offsetHeight, (resetBox.options.myHeight + resetBox.options.myPadding + (resetBox.options.myLiHeight*myValuePass)));
			} else {
				resetBox.openBox(myValuePassReal, document.getElementById(resetBox.options.myBlock).offsetHeight, resetBox.options.myHeight);
			}
		} else {
			alert("attenzione: "+ resetBox.options.myBlock +"non esiste.");
		}
		return false;
	},
	setChild: function(myValue){
		if(document.getElementById(resetBox.options.myBlock)){
			myValuePassReal = parseInt(myValue);
			myValuePass = (parseInt(myValue)==0)? 0 : 4;
			if(myValuePassReal > 0){
				resetBox.openBoxChild(myValuePassReal, document.getElementById(resetBox.options.myBlock).offsetHeight, (resetBox.options.myHeight + resetBox.options.myPadding + (resetBox.options.myLiHeight*1)));
			} else {
				resetBox.openBoxChild(myValuePassReal, document.getElementById(resetBox.options.myBlock).offsetHeight, resetBox.options.myHeight);
			}
		}
		return false;
	},
	openBox: function(myVal, height_nowB, heightB){
		myValuePassReal = parseInt(myVal);
		myValuePass = (parseInt(myVal)==1)? 1 : 4;
		myValuePass = parseInt(myVal);
		if(heightB > height_nowB){
			new_heightB = Math.round((heightB-height_nowB)/6)*1+1;
			if(resetBox.options.myAction == ""){
				setRoom(myValuePassReal, name_adults, name_children, name_childage, name_room);
				resetBox.options.myAction = "opening";
			}
		} else {
			new_heightB = Math.round((heightB-height_nowB)/6)*1-1;
			resetBox.options.myAction = "closing";
		}
		my_heightB = heightB;
		my_height_resultB = height_nowB + new_heightB;
		if ((heightB-height_nowB) > 3 || (heightB-height_nowB) < -3){
			setTimeout("resetBox.openBox(myValuePass, my_height_resultB, my_heightB)", 20);
			document.getElementById(resetBox.options.myBlock).style.height = my_height_resultB +"px";
		} else {
			if(heightB == resetBox.options.myHeight) {
				resetBox.hide(false);
			} else {
				resetBox.hide(true);
			}
			document.getElementById(resetBox.options.myBlock).style.height = heightB+"px";
			if(resetBox.options.myAction == "closing") setRoom(myValuePassReal, name_adults, name_children, name_childage, name_room);
			resetBox.options.myAction = "";
			return false;
		}
		return true;
	},
	openBoxChild: function(myVal, height_nowB, heightB){
		myValuePassReal = parseInt(myVal);
		myValuePass = (parseInt(myVal)==1)? 1 : 4;
		if(heightB > height_nowB){
			new_heightB = Math.round((heightB-height_nowB)/6)*1+1;
			if(resetBox.options.myAction == ""){
				document.getElementById('contOption').innerHTML = '<ul><li class="childAgeList"><span id="chdAge_1" class="childAge"></span></li></ul>';
				setChildAge(myVal, 'chdAge_1', 1, name_childage);
				resetBox.options.myAction = "opening";
			}
		} else {
			new_heightB = Math.round((heightB-height_nowB)/6)*1-1;
			resetBox.options.myAction = "closing";
		}
		my_heightB = heightB;
		my_height_resultB = height_nowB + new_heightB;
		if ((heightB-height_nowB) > 3 || (heightB-height_nowB) < -3){
			setTimeout("resetBox.openBoxChild(myValuePassReal, my_height_resultB, my_heightB)", 20);
			document.getElementById(resetBox.options.myBlock).style.height = my_height_resultB +"px";
		} else {
			document.getElementById(resetBox.options.myBlock).style.height = heightB+"px";
			if(heightB == resetBox.options.myHeight) {
				resetBox.hide(false);
			} else {
				resetBox.hide(true);
			}
			if(resetBox.options.myAction == "closing") {
				if(myVal>0){
					document.getElementById('contOption').innerHTML = '<ul><li class="childAgeList"><span id="chdAge_1" class="childAge"></span></li></ul>';
					setChildAge(myVal, 'chdAge_1', 1, name_childage);
				} else {
					document.getElementById('contOption').innerHTML = "";
				}
			}
			resetBox.options.myAction = "";
			return false;
		}
		return true;
	}
}
var numChildAge_1 = 0;
function setChildAge(nchild, chdid, roomn, label_children_age, replace_row){
	if(replace_row == true){
		resetBox.setChild(nchild);
		numChildAge_1 = nchild;
	} else {
		var selectHtml = "";
		selectHtml = '<label>'+ label_children_age +'</label>';
		for (var cc=1; cc<=4; cc++) {
			var disabled = (cc > nchild) ? ' disabled="disabled"' : '';
			selectHtml =  selectHtml + '<select name="bform[reqRooms]['+roomn+'][childAge][' + cc + ']"'+ disabled +'>';
				 (cc > nchild) ? selectHtml =  selectHtml + '<option value="">&nbsp;-</option>' : '';
				selectHtml =   selectHtml + '<option value="0">&lsaquo; 1</option>';
				for(var k=1; k<=18; k++){
					k_opt = k<10 ? "&nbsp;"+ k : k;
					selectHtml =  selectHtml + "\n" + '<option value="'+ k +'">'+ k_opt +'</option>';
				}
				selectHtml =  selectHtml + '</select>';
		}
		if(document.getElementById(chdid)){
			document.getElementById(chdid).innerHTML = selectHtml;
		}
		numChildAge_1 = 0;
	}
}

function createSelect(num, init, label, selected){
	if(label != "")	label = " "+ label;
	var mySel = "";
	for(var k=init; k<=num; k++){
		if (selected != 0 && selected == k){
			mySel = mySel + "\n" + '<option value="'+ k +'" selected="selected">'+ k + label +'</option>';
		} else {
			mySel = mySel + "\n" + '<option value="'+ k +'">'+ k + label +'</option>';
		}
	}
	return mySel;
}

function setRoom(nrooms, label_adults, label_children, label_children_age, label_room){
	var myResults = "";
	if(nrooms>1){
		myResults = myResults + '<ul>\n';
		for (var i=1; i<=nrooms; i++){
			myResults = myResults + '	<li><strong>'+ label_room +' '+i+'</strong>\n';
			myResults = myResults + '		<span>\n'+
			'			<label>'+ label_adults +'</label>\n'+
			'			<select name="bform[reqRooms]['+ i +'][adults]">\n'+
			'			'+ createSelect(6, 1, '', 2) + 
			'			</select>\n'+
			'		</span>\n'+
			'		<span>\n'+
			'			<label>'+ label_children +'</label>\n'+
			'			<select name="bform[reqRooms]['+ i +'][child]" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\');">\n'+
			'			'+ createSelect(4, 0, '', 0) + 
			'			</select>\n'+
			'		</span>\n'+
			'		<span class="childAge" id="chdAge_'+ i +'"></span>\n'+
			'	</li>\n';
		}
		myResults = myResults + '</ul>\n';
		document.getElementById('numAdults').innerHTML = "";
		document.getElementById('numChildren').innerHTML = "";
	} else {
		document.getElementById('numAdults').innerHTML = '<label>'+ name_adults +'</label><select name="bform[reqRooms][1][adults]">\n'+ createSelect(6, 1, '', 2) + '</select>';
		document.getElementById('numChildren').innerHTML = '<label>'+ name_children +'</label><select name="bform[reqRooms][1][child]" onchange="setChildAge(this.value,\'chdAge_1\', 1,\''+ label_children_age +'\', true)";>\n'+ createSelect(4, 0, '', 0) + '</select>';
	}
	if (document.getElementById('contOption')){
		document.getElementById('contOption').innerHTML = myResults;
		//alert("cont: "+myResults);
		if(myResults != ""){
			for (var i=1; i<=nrooms; i++){
				//setChildAge(nchild, chdid, roomn, label_children_age);
				setChildAge(0, 'chdAge_'+i, i, name_childage);
			}
		}
	} else {
		alert("blocco non valido");
	}
}

var checkCallback = {
	send: function(form){
		var testo_err = varCallError+'\n\n';
		var mancato_ins = false;
		var myForm = document.getElementById(form);
		if(myForm){
			if (myForm['callPhone'].value == varPhone || myForm['callPhone'].value == "") {
				testo_err = testo_err + '<strong>'+ varPhoneLabel +'</strong>\n';
				mancato_ins = true; 
			} else {
				if(!checkValue(myForm['callPhone'].value, "number")){
					testo_err = testo_err + '<strong>'+ varPhoneLabel +'</strong>\n';
					mancato_ins = true;
				}
			}
			if (mancato_ins == true) {
				jAlert(testo_err, 'Call Back', function(){
					myForm['callPhone'].value = "";
					myForm['callPhone'].focus();
				});
				return false;
			}
			myForm.setAttribute("action", "/assets/mailerCallBack.php");
			return true;
		} else {
			alert(form +" non esiste.");
		}
	},
	init: function(form){
		var myForm = document.getElementById(form);
		if(myForm){
			var ie = false;
			if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
				ie = true;
			}
			document.getElementById('callPhone').value = varPhone;
			if(!ie) {
				myForm.setAttribute("onsubmit", "return checkCallback.send('callForm');");
				document.getElementById('callPhone').setAttribute("onfocus", "checkCallback.change(this, true);");
				document.getElementById('callPhone').setAttribute("onblur", "checkCallback.change(this, false);");
				document.getElementById('callPhone').setAttribute("onchange", "checkCallback.change(this, 'writing');");
			} else {
				myForm.onsubmit = function() {return checkCallback.send('callForm'); };
				document.getElementById('callPhone').onfocus = function() { checkCallback.change(this, true); };
				document.getElementById('callPhone').onblur = function() { checkCallback.change(this, false); };
				document.getElementById('callPhone').onchange = function() { checkCallback.change(this, 'writing'); };
			}
		}
	},
	change: function(myInput, status){
		var validi = "0123456789+";
		if(status == true && (myInput.value == "" || myInput.value == varPhone)){
			myInput.value = "";
		} else if(status == false && (myInput.value == "")){
			myInput.value = varPhone;
		} else if(status == 'writing'){
			var myValue = "";
			var myNewValue = "";
			myValue = myInput.value.replace(/\ /g, "");
			myValue = myValue.replace(/\./g, "");
			myValue = myValue.replace(/\-/g, "");
			for(var i = 0; i < myValue.length; i++ ){
				if( validi.indexOf( myValue.charAt(i) ) != -1 ){
					myNewValue = myNewValue + "" + myValue.charAt(i);
				}
			}
			myInput.value = myNewValue;
		}
	}
}

var newsletterSub = {
	options:{
		myform: "",
		myUrl:""
	},
	send: function(){
		var testo_err = varCallError+'\n\n';
		var mancato_ins = false;
		var thisForm = document.getElementById(newsletterSub.options.myForm);
		if(thisForm){
			if (thisForm['qwerty'].value == 'email@email.it' || thisForm['qwerty'].value == "") {
				testo_err = testo_err + '<strong>Email</strong>\n';
				mancato_ins = true; 
			} else {
				if(!checkValue(thisForm['qwerty'].value, "mail")){
					testo_err = testo_err + '<strong>Email</strong>\n';
					mancato_ins = true;
				}
			}
			if (mancato_ins == true) {
				jAlert(testo_err, 'Newsletter', function(){
					thisForm['qwerty'].value = "";
					thisForm['qwerty'].focus();
				});
				return false;
			}
			thisForm.setAttribute("action", newsletterSub.options.myUrl);
			return true;
		} else {
			alert(form +" non esiste.");
		}
	},
	init: function(form, url){
		newsletterSub.options.myForm = form;
		newsletterSub.options.myUrl = url;
		var thisForm = document.getElementById(form);
		if(thisForm){
			var ie = false;
			if ((/MSIE (\d+\.\d+);/.test(navigator.userAgent))){
				ie = true;
			}
			if(!ie) {
				thisForm.setAttribute("onsubmit", "return newsletterSub.send();");
			} else {
				thisForm.onsubmit = function() {return newsletterSub.send(); };
			}
		}
	}
}

function checkValue(string, type){
	if(type == undefined || type == "number"){
		var validi = "0123456789";
		var myNumberNew = string;
		myNumberNew = myNumberNew.replace(/\ /g, "");
		myNumberNew = myNumberNew.replace(/\+/g, "");
		myNumberNew = myNumberNew.replace(/\./g, "");
		myNumberNew = myNumberNew.replace(/\-/g, "");
		if(myNumberNew == ''){
			return false;
		}
		for(var i = 0; i < myNumberNew.length; i++ ){
			if( validi.indexOf( myNumberNew.charAt(i) ) == -1 ){
				return false;
			}
		}
	} else if(type == "mail") {
		if (string.length > 9){
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(string)) {
				return false;
			}
		} else {
			return false;
		}
	} else if(type == "text") {
		var filter = /^([a-zA-Z\ \'])/;
		if (!filter.test(string)) {
			return false;
		}
	}
	return true;
}

function localTime(myId, timeNow) {
	var timeResetNow = new Date();
	var mySplitData = timeNow.split(":");
	if(document.currenttimeItaly === undefined){
		timeResetNow.setHours(mySplitData[0]);
		timeResetNow.setMinutes(mySplitData[1]);
		timeResetNow.setSeconds(mySplitData[2]);
		document.currenttimeItaly = timeResetNow.getTime();
	}else{
		document.currenttimeItaly  += 1000;
	}
	timeResetNow.setTime(document.currenttimeItaly);
	var hours_passed = timeResetNow.getHours();
	if(hours_passed < 10) hours_passed = "0" + hours_passed;
	var minutes_passed = timeResetNow.getMinutes();
	if(minutes_passed < 10)	minutes_passed = "0" + minutes_passed;
	var seconds_passed = timeResetNow.getSeconds();
	if(seconds_passed < 10)	seconds_passed = "0" + seconds_passed;
	document.getElementById(myId).innerHTML = hours_passed + ":" + minutes_passed + "<em>:" + seconds_passed + "</em>";
	setTimeout('localTime("'+myId+'", "'+timeResetNow+'")', 1000);
}

function minimizeOfferBox(){
	jq("#claim").css({'background':'url("/images/bgClaimHomeMin.gif") repeat-x center bottom #6C0000', 'padding-bottom':'135px'});
	jq("#boxOffersHome ul").height(95);
	jq("#boxOffersHome").height(117);
}

// FUNZIONI PER LA MAPPA V3

var i, infoBox;
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,
    	mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId[mapType]
    };
	
    var 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/blank.gif',
						zIndex: 20000000000
					});
					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"), markers_def[i_def].getAttribute("idImg"));
						attachURL(marker, markers_def[i_def].getAttribute("url"));
					} else {
						if(showBox) attachInfoBox(marker, base_64.decode(markers_def[i_def].getAttribute("ballon")), maps, 'javascript:;', markers_def[i_def].getAttribute("idImg"));
					}
					myZindex++;
				}
			}
			if(openBox == false){
				if(markers_def.length > 1){
					markerBounds.extend(new google.maps.LatLng(myMarker['lat'], myMarker['lon']));
					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(myMarker['lat'], myMarker['lon']),
		map: maps,
		title: "Hotel San Marco",
		icon:'/images/iconHotel.png',
		zIndex: 1000
	});
	
}
var infowindow;
function attachURL(marker, url) {
	google.maps.event.addListener(marker, "click", function() {
		location.href = url;
	});
}
function attachInfoBox(marker, text, myMap, url, icon) {
	google.maps.event.addListener(marker, "mouseover", function() {
		myZindex = myZindex + 1;
		this.setZIndex(myZindex);
		infoBox.setContent(text);
		if(url != 'javascript:;') infoBox.setUrl(url);
		infoBox.open(myMap, this);
		//this.setIcon('/images/icon_big.png');
	});
	google.maps.event.addListener(marker, "mouseout", function() {
		//this.setIcon(icon);
		//setTimeout("infoBox.close()", 100);
		infoBox.close();
	});
}
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,
			provideRouteAlternatives: 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: true,
    	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);
		});
	}
}

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;
	}
}

function createXmlHttpRequest(){
	try {
		if (typeof ActiveXObject != 'undefined') {
			return new ActiveXObject('Microsoft.XMLHTTP');
		} else if (window["XMLHttpRequest"]) {
			return new XMLHttpRequest();
		}
	} catch (e) {
		changeStatus(e);
	}
	return null;
}

function downloadUrl(url, callback) {
	var status = -1;
	var request = createXmlHttpRequest();
	if (!request) {
		return false;
	}
	
	request.onreadystatechange = function(){
		if (request.readyState == 4) {
			try {
				status = request.status;
			} catch (e) {
			}
			if (status == 200) {
				callback(request.responseXML, request.status);
				request.onreadystatechange = function() {};
			}
		}
	}
	request.open('GET', url, true);
	try {
		request.send(null);
	} catch (e) {
		changeStatus(e);
	}
}

// FINE MAPPA

// ALERT
(function($){$.alerts={verticalOffset:-75,horizontalOffset:0,repositionOnResize:true,overlayOpacity:.7,overlayColor:'#000',draggable:true,okButton:'&nbsp;OK&nbsp;',cancelButton:'&nbsp;Cancel&nbsp;',dialogClass:null,alert:function(message,title,callback){if(title==null)title='Alert';$.alerts._show(title,message,null,'alert',function(result){if(callback)callback(result);});},confirm:function(message,title,callback){if(title==null)title='Confirm';$.alerts._show(title,message,null,'confirm',function(result){if(callback)callback(result);});},prompt:function(message,value,title,callback){if(title==null)title='Prompt';$.alerts._show(title,message,value,'prompt',function(result){if(callback)callback(result);});},_show:function(title,msg,value,type,callback){$.alerts._hide();$.alerts._overlay('show');$("BODY").append('<div id="popup_container">'+'<h1 id="popup_title"></h1>'+'<div id="popup_content">'+'<div id="popup_message"></div>'+'</div>'+'</div>');if($.alerts.dialogClass)$("#popup_container").addClass($.alerts.dialogClass);var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed';$("#popup_container").css({position:pos,zIndex:99999,padding:0,margin:0});$("#popup_title").text(title);$("#popup_content").addClass(type);$("#popup_message").text(msg);$("#popup_message").html($("#popup_message").text().replace(/\n/g,'<br />'));$("#popup_container").css({minWidth:$("#popup_container").outerWidth(),maxWidth:$("#popup_container").outerWidth()});$.alerts._reposition();$.alerts._maintainPosition(true);switch(type){case 'alert':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /></div>');$("#popup_ok").click(function(){$.alerts._hide();callback(true);});$("#popup_ok").focus().keypress(function(e){if(e.keyCode==13||e.keyCode==27)$("#popup_ok").trigger('click');});break;case 'confirm':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_ok").click(function(){$.alerts._hide();if(callback)callback(true);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(false);});$("#popup_ok").focus();$("#popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});break;case 'prompt':$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_prompt").width($("#popup_message").width());$("#popup_ok").click(function(){var val=$("#popup_prompt").val();$.alerts._hide();if(callback)callback(val);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(null);});$("#popup_prompt, #popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});if(value)$("#popup_prompt").val(value);$("#popup_prompt").focus().select();break;}if($.alerts.draggable){try{$("#popup_container").draggable({handle:$("#popup_title")});$("#popup_title").css({cursor:'move'});}catch(e){}}},_hide:function(){$("#popup_container").remove();$.alerts._overlay('hide');$.alerts._maintainPosition(false);},_overlay:function(status){switch(status){case 'show':$.alerts._overlay('hide');$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({position:'absolute',zIndex:99998,top:'0px',left:'0px',width:'100%',height:$(document).height(),background:$.alerts.overlayColor,opacity:$.alerts.overlayOpacity});break;case 'hide':$("#popup_overlay").remove();break;}},_reposition:function(){var top=(($(window).height()/2)-($("#popup_container").outerHeight()/2))+$.alerts.verticalOffset;var left=(($(window).width()/2)-($("#popup_container").outerWidth()/2))+$.alerts.horizontalOffset;if(top<0)top=0;if(left<0)left=0;if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop();$("#popup_container").css({top:top+'px',left:left+'px'});$("#popup_overlay").height($(document).height());},_maintainPosition:function(status){if($.alerts.repositionOnResize){switch(status){case true:$(window).bind('resize',$.alerts._reposition);break;case false:$(window).unbind('resize',$.alerts._reposition);break;}}}};jAlert=function(message,title,callback){$.alerts.alert(message,title,callback);};jConfirm=function(message,title,callback){$.alerts.confirm(message,title,callback);};jPrompt=function(message,value,title,callback){$.alerts.prompt(message,value,title,callback);};})(jQuery);