function setRoomHome(nrooms, label_adults, label_children, label_children_age, label_room, element) {
	var form = element.parents('form');
	var myResults = '';
	
	if (nrooms > 1)	// se viene scelta più di una camera...
	{
		for (var i=2; i<=nrooms; i++)	// preparo la stringa da accodare alla prima camera, contenente i campi necessari
		{
			myResults = myResults + '<li class="room'+ i +' roomTitle">'+ label_room +' '+ i +'</li>';
			
			myResults = myResults +	'<li class="room'+ i +' adults">'+
										'<label>'+ label_adults +':</label>'+
										'<select name="bform[reqRooms]['+ i +'][adults]">'+
											createSelect(6, 1, label_adults, "", 2)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +' children">'+
										'<label>'+ label_children +':</label>'+
										'<select name="bform[reqRooms]['+ i +'][child]" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\', $(this));">'+
											createSelect(4, 0, label_children, "", 0)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +' childAge chdAge_'+ i +'"></li>';
		}
		
		$('li.room1.roomTitle', form).remove();				// rimuovo il titolo della camera 1 (per evitare duplicazioni nel caso sia già presente: vedi istruzione successiva)
		$('li.room1:first', form).before('<li class="room1 roomTitle">'+ label_room +' 1</li>');		// aggiungo il titolo della camera 1, prima del primo campo della camera 1
		$('li.room1:last', form).nextAll().remove();		// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
		$('li.room1:last', form).after(myResults);			// aggiungo dopo l'ultimo elemento della camera 1, la stringa preparata in precedenza
	}
	else			// se viene scelta una sola camera...
	{
		$('li.room1.roomTitle', form).remove();				// rimuovo il titolo della camera 1
		$('li.room1:last', form).nextAll().remove();		// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
	}
}


function setChildAge(nchild, chdid, roomn, label_children_age, element){
	var form = element.parents('form');
	var selectHtml = "";
	
	if(nchild > 0){
		selectHtml = '<label>'+ label_children_age +':</label>';
		for (var cc=1; cc<=nchild; cc++) {
			selectHtml =  selectHtml + '<select name="bform[reqRooms]['+roomn+'][childAge][' + cc + ']">' +
                '<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($('.'+chdid, form)){
		$('.'+chdid, form).html(selectHtml);
	}
}


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

// ----------------------------------------------------
// ANALISI DATEPICKER
// ----------------------------------------------------

function updateDate(htmlel,day,month,year){
	$("#bform_"+htmlel+"_D").val(day);
	$("#bform_"+htmlel+"_MY").val((month+1)+"_"+year);
}

function updateminDate() { // update mindate checkout
     date1 = $(".bform_checkin").datepicker( 'getDate' );
     date2 = new Date(date1);
     date2.setDate(date1.getDate() + 1);
     $(".bform_checkout").datepicker('option', 'minDate',date2);

     newdate2 = $(".bform_checkout").datepicker( 'getDate' );
     day = newdate2.getDate();
     month = newdate2.getMonth();
     year = newdate2.getYear();
     if(year<1900)year=year+1900;

     days = getDaysinMonth(month+1,year);
     generateSelectDays('checkout',days,month+1,year,day);

     updateDate('checkout',day,month,year);
}

function reparserCalendar(htmlel,day,month,year) {
	if (day < 10) {
		day = "0"+day;
	}
	if (month < 10) {
		month = "0"+month;
	}
	$(".bform_"+htmlel).val(day+"-"+month+"-"+year);
	if (htmlel == "checkin") {
		updateminDate();
	}
}

function getDaysinMonth(month,year) {
	// month 0 -> 11, year 4 digits
	days = 32 - new Date(year, month-1, 32).getDate();
	return days;
}

function generateSelectDays(htmlel, days, month, year, selectday){
	myOptions = "";
	for (i=0 ;i<=days; i++){
		now = new Date(year, month-1, i).getDay();
		if (i == 0) {
			myOptions += '<option value="">&nbsp;</option>';
		} else if (i == selectday) {
			myOptions += '<option value="'+ i +'" selected="selected">'+ weekdays[now] +' '+ i +'</option>';
		} else {
			myOptions += '<option value="'+ i +'">'+ weekdays[now] +' '+ i +'</option>';
		}
	}
	$("#bform_"+htmlel+"_D").html(myOptions);
}

function goToUrl(encUrl){
	var decUrl = jbase64.decode(encUrl);
	location.href=''+decUrl+'';	
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function addslashes (str) {
    // http://kevin.vanzonneveld.net
    return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

//======================================	FUNZIONI PER LA MAPPA V3
var jbase64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=jbase64._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=jbase64._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;}};

var maps;var infowindow = new Array();var marker = new Array();var setDirectionMultiple = {options: {dirContainer: document.getElementById('dirContainer'),dirService: "",dirRenderer: "",myMarker: "",mapId: "",zoom: "",mapType: "",mapLat: "",mapLon: "",showCursor: "",point: new Array()},set: function (mapId, optiones, zoom, mapType, showCursor) {setDirectionMultiple.options.mapId = mapId;setDirectionMultiple.options.zoom = zoom;setDirectionMultiple.options.mapType = mapType;setDirectionMultiple.options.showCursor = showCursor;setDirectionMultiple.options.myMarker = new Array();var aryLat = new Array();var aryLon = new Array();for (names in optiones) {if (names == 'point') {for (name in optiones[names]) {setDirectionMultiple.options.point[name] = optiones[names][name];for (nameee in optiones[names][name]) {if (nameee == 'lat') aryLat[name] = optiones[names][name][nameee];if (nameee == 'lon') aryLon[name] = optiones[names][name][nameee];if (nameee == 'icon') {if (optiones[names][name]['iconAnchor'] != undefined && optiones[names][name]['iconSize'] != undefined) {var myPoint = optiones[names][name]['iconAnchor'].split(',');var mySize = optiones[names][name]['iconSize'].split(',');setDirectionMultiple.options.point[name]['icon'] = new google.maps.MarkerImage(optiones[names][name][nameee], new google.maps.Size(mySize[0] * 1, mySize[1] * 1), new google.maps.Point(0, 0), new google.maps.Point(myPoint[0] * 1, myPoint[1] * 1));}}}setDirectionMultiple.options.point[name]['infowindow'] = '<div class="balloon" id="balloon_' + name + '"><h5>' + setDirectionMultiple.addslashes(setDirectionMultiple.options.point[name]['labelTitle']) + '</h5>' + setDirectionMultiple.options.point[name]['infowindow'] + '<br /><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '<br /><a href="javascript:;" onclick="setDirectionMultiple.init(\'<h5>' + setDirectionMultiple.options.point[name]['labelTitle'] + '</h5><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelFrom']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelTo']) + '\', \'FROM\', \'' + setDirectionMultiple.options.point[name]['lat'] + ', ' + setDirectionMultiple.options.point[name]['lon'] + '\',' + name + ');" title="' + setDirectionMultiple.options.myMarker['labelCalculate'] + '"><strong>' + setDirectionMultiple.options.myMarker['labelFrom'] + '</strong></a> - <a href="javascript:;" onclick="setDirectionMultiple.init(\'<h5>' + setDirectionMultiple.options.point[name]['labelTitle'] + '</h5><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelFrom']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelTo']) + '\', \'TO\', \'' + setDirectionMultiple.options.point[name]['lat'] + ', ' + setDirectionMultiple.options.point[name]['lon'] + '\',' + name + ');" title="' + setDirectionMultiple.options.myMarker['labelCalculate'] + '"><strong>' + setDirectionMultiple.options.myMarker['labelTo'] + '</strong></a></div>';}} else {setDirectionMultiple.options.myMarker[names] = optiones[names];}}setDirectionMultiple.options.mapLon = setDirectionMultiple.setMiddlePoint(aryLon);setDirectionMultiple.options.mapLat = setDirectionMultiple.setMiddlePoint(aryLat);setDirectionMultiple.openMap();},setMiddlePoint: function (myAry) {var myMin, myMax;for (a in myAry) {if (myMin == undefined) {myMin = myAry[a];} else if (myAry[a] < myMin) {myMin = myAry[a];}if (myMax == undefined) {myMax = myAry[a];} else if (myAry[a] > myMax) {myMax = myAry[a];}}return myMin + ((myMax - myMin) / 2);},openMap: function () {var latlng = new google.maps.LatLng(setDirectionMultiple.options.mapLat, setDirectionMultiple.options.mapLon);if (setDirectionMultiple.options.mapType == undefined) setDirectionMultiple.options.mapType = "ROADMAP";if (setDirectionMultiple.options.showCursor == undefined) setDirectionMultiple.options.showCursor = false;var myOptions = {disableDefaultUI: setDirectionMultiple.options.showCursor,mapTypeControl: true,mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},zoom: setDirectionMultiple.options.zoom,center: latlng,mapTypeId: google.maps.MapTypeId[setDirectionMultiple.options.mapType]};maps = new google.maps.Map(document.getElementById(setDirectionMultiple.options.mapId), myOptions);for (punto in setDirectionMultiple.options.point) {var myLatLng = new google.maps.LatLng(setDirectionMultiple.options.point[punto]['lat'], setDirectionMultiple.options.point[punto]['lon']);marker[punto] = new google.maps.Marker({position: myLatLng,map: maps,title: setDirectionMultiple.options.point[punto]['labelTitle'],icon: setDirectionMultiple.options.point[punto]['icon'],zIndex: 10000});if (setDirectionMultiple.options.point[punto]['infowindow'] != "") {infowindow[punto] = new google.maps.InfoWindow({content: setDirectionMultiple.options.point[punto]['infowindow'],maxWidth: 350,position: myLatLng,zIndex: 100});attachInfoBox(marker[punto], maps, punto);}}},init: function (myText, from, to, direction, latLan, id) {fromS = setDirectionMultiple.addslashes(from);toS = setDirectionMultiple.addslashes(to);for (punto in setDirectionMultiple.options.point) {if (punto == id && document.getElementById('balloon_' + id)) {setDirectionMultiple.options.dirService = new google.maps.DirectionsService();setDirectionMultiple.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="setDirectionMultiple.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value, ' + id + ');" type="button" value=">" /></form>';textDirection = myText + '<br /><strong>' + from + '</strong> - <a href="javascript:;" onclick="setDirectionMultiple.init(\'' + myText + '\', \'' + fromS + '\', \'' + toS + '\', \'TO\', \'' + latLan + '\', ' + id + ');"><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="setDirectionMultiple.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value, ' + id + ');" type="button" value=">" /></form>';textDirection = myText + '<br /><a href="javascript:;" onclick="setDirectionMultiple.init(\'' + myText + '\', \'' + fromS + '\', \'' + toS + '\', \'FROM\', \'' + latLan + '\', ' + id + ');"><strong>' + from + '</strong></a> - <strong>' + to + '</strong>' + myFormDirection;}document.getElementById('balloon_' + id).innerHTML = textDirection;}}},getDirections: function (fromStr, toStr, id) {var dirRequest = {origin: fromStr,destination: toStr,travelMode: google.maps.DirectionsTravelMode.DRIVING,unitSystem: google.maps.DirectionsUnitSystem.METRIC,provideRouteAlternatives: true};setDirectionMultiple.options.dirService.route(dirRequest, setDirectionMultiple.showDirections);},showDirections: function (dirResult, dirStatus) {if (dirStatus != google.maps.DirectionsStatus.OK) {if (typeof (dirStatusError) != undefined) {alert(dirStatusError + "\n(Google reports: " + dirStatus + ")");} else {alert("The address entered was not found\n(Google reports: " + dirStatus + ")");}return;}setDirectionMultiple.openMap();if (typeof jq == 'function') {jq('html,body').animate({scrollTop: jq('#' + setDirectionMultiple.options.mapId).offset().top - 20}, 1000);} else if (typeof jQuery == 'function') {$('html,body').animate({scrollTop: $('#' + setDirectionMultiple.options.mapId).offset().top - 20}, 1000);}setDirectionMultiple.options.dirRenderer.setMap(null);setDirectionMultiple.options.dirRenderer.setMap(maps);document.getElementById('dirContainer').innerHTML = '';setDirectionMultiple.options.dirRenderer.setPanel(document.getElementById('dirContainer'));setDirectionMultiple.options.dirRenderer.setDirections(dirResult);},addslashes: function (str){return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');}};function attachInfoBox(marker, myMap, id) {google.maps.event.addListener(marker, "click", function () {for (infoBox in infowindow) {infowindow[infoBox].close();}infowindow[id].open(myMap, marker);});};
//======================================	FINE MAPPA


function openModal(url) {
	url = decodeURIComponent((jbase64.decode(url) + '').replace(/\+/g, '%20'));
	if (window.showModalDialog) {
		window.showModalDialog(url, "socials", "dialogHeight:450px;dialogWidth:880px");
	} else {
		window.open(url, 'socials', 'height=450,width=880,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
	}
}

/**
* funzione che carica le immagini
*/
function loadImages(){
	
    var myprev = $(".loading");
	
	if (myprev.length > 0) {
        
		myprev.each(function(i){
	        var myImg = this;
			myImgId = this.id;
			imgLink = 	structureImg[myImgId];
			
			var img = new Image();
			
			$(img).load(function (){
				$(this).hide();
				$(myImg).replaceWith(this);
				$(this).fadeIn();
			})
			
			.error(function(){
				noimage = "/resizer/resize.php?url=http://www.fortravel.it/images/no_preview.jpg&size=46x46c50";
				$(img).attr('src',noimage);
			})
			
			.attr({'src': imgLink, 'class':'thumb'});
        });
    }
}

function getSimulateBookingByStructureId(lang, order, limit, sorder, slimit, checkin, checkout, absUrl, fromText, structure_id) {

	var reqRooms = [{adults:2, child:0}];
   	   		
	var params =	{	method: 'getSimulateBookingByStructureId',
						params:	{	pid:	1,
									limit:		limit,
									order:		order,
									slimit:		slimit,
									sorder:		sorder,
									lang:		lang,
									checkin:	checkin,
									checkout:	checkout,
									numrooms:	1,
									reqrooms:	reqRooms,
									stid:		structure_id
								}
					};
					
	$.getJSON("http://"+absUrl+"/services/json.php?callback=?",
		params,
		function(data) {
			d = data.response;
			minPrice = '';
			
			if (d.length > 0)
			{
				n_solutions = d[0]['solutions'].length;
				
				for (i=0; i<n_solutions; i++) {	// stampo le strutture
					
					price = d[0]['solutions'][i]['price'];
					
					if (minPrice == '' || price < minPrice)
					{
						minPrice = price;
					}
				}
				
				$('.price', '#struct_'+structure_id).html(fromText+' <strong>'+minPrice+'<span>€</span></strong>');
			}
			
		}
	);
}

function startBlockUI(msg1,msg2,portal){
	img = "/images/ajax-loader.gif";
	colorborder = '#FF9400';
	colorbackground = '#6CA1BA';
	
	$.blockUI({ 
		message: '<h1>'+msg1+'<br />'+msg2+'</h1><br /><img src="'+img+'" />',
		css: { 
    		border: '2px solid '+colorborder+'', 
    		padding: '20px', 
    		backgroundColor: '#fff', 
    		'-webkit-border-radius': '10px', 
    		'-moz-border-radius': '10px', 
    		color: ''+colorborder+''
		},
		overlayCSS: { 
			backgroundColor: ''+colorbackground+'',
			opacity: .7
		}								 
	}); 
}


$(document).ready(function(){

	//=============================== SHADOWBOX
	
	$('.shadowbox').each(function(){
		params = $(this).attr('class').split('_');

		gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
		width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
		height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
		
		
		$(this).attr('rel', 'shadowbox'+gallery+width+height);
	});
	
	//=============================== GALLERYONE
	var gallery = $('#mask>div');
	var gallery_length = $('#galleryone img').length-2;
	var offset = 0;
	//var offset_width = $('#galleryone img').outerWidth(true);	//commentata a causa di un bug di jquery o chrome relativo a outerWidth che su chrome non rileva la larghezza totale ma solo la larghezza di margin, padding e border
	var offset_width = 190;
	
	$('#next').click(function(){
		if ((offset < gallery_length) && (!gallery.is(':animated'))) {
			gallery.stop(true).animate({left:'+=-'+offset_width},'normal');
			offset++;
		}
	});
	
	$('#prev').click(function(){
		if ((offset > 0) && (!gallery.is(':animated'))) {
			gallery.stop(true).animate({left:'+='+offset_width},'normal');
			offset--;
		}
		
	});
	
	//======================================	CALENDARIO EVENTI
	
	$('a.tenback').live('click',function(){
		var newtime = $(this).attr('id').replace('tenback-','');
		$.ajax({
			type: 'GET',
			url: '/assets/eventList.php',
			data: 'newtime='+newtime,
			success: function(myList){
				$('#eventCalendar').html(myList);
				$('.tabs', '#news').tabs();
			}
		});
	});
	
	$('a.tenforward').live('click',function(){				
		var newtime = $(this).attr('id').replace('tenforward-','');
		$.ajax({
			type: 'GET',
			url: '/assets/eventList.php',
			data: 'newtime='+newtime,
			success: function(myList){
				$('#eventCalendar').html(myList);
				$('.tabs', '#news').tabs();
			}
		});
	});
	
	$('a.eventInDay').live('click',function(){
		var day = $(this).attr('id').replace('forday-','');
		$(this).parent().siblings().children('a').removeClass('selected');
		$(this).addClass('selected');
		$.ajax({
			type: 'GET',
			url: '/assets/eventInDay.php',
			data: 'day='+day,
			success: function(myList){
				$('.tabs', '#news').replaceWith(myList);
				$('.tabs', '#news').tabs();
			}
		});
	});
	
	//======================================	 tooltip per il dettaglio Hotel
	
	var hideDelay = 300;
	var hideTimerHotel = null;
	var containerHotel = $('<div class="hotel_details"></div>');
	
	// inserisco il div fuori dall'area visibile
	$('body').append(containerHotel).css({left: '-1000px', display: 'block'});
	
	$('.hotel_name').live('mouseover', function(){
		link = $(this).attr('rel');
		
		if (hideTimerHotel) { clearTimeout(hideTimerHotel); }
		
		var pos = $(this).offset();
		var width = $(this).width();
		
		$.ajax({
			type: 'GET',
			url: link,
			success: function(data){
				var text = $(data).html();
				
				// inserisco il contenuto nel div del tooltip
				$('.hotel_details').html(text);
				
				// controllo che il div del tooltip non venga posizionato parzialmente fuori dal viewport
				if (pos.top + containerHotel.outerHeight(true) > $(window).height())
				{
					var containerHotelTop = pos.top + (($(window).height()+ $(window).scrollTop()) - (pos.top + containerHotel.outerHeight(true)) ) - 10;
				}
				else
				{
					var containerHotelTop = pos.top;
				}
				
				// posiziono il div del tooltip
				containerHotel.css({
					left: (pos.left + width ) + 'px',
					top: containerHotelTop +'px',
					width: 328
				});
				
				// visualizzo il div del tooltip
				containerHotel.fadeIn("slow");
			}
		});
	
	});
	
	$('.hotel_name').live('mouseout', function(){
		if (hideTimerHotel) { clearTimeout(hideTimerHotel); }
		hideTimerHotel = setTimeout(function(){
			containerHotel.removeAttr('style').css('display', 'none');
		}, hideDelay);
	});
	
	$('.hotel_details').mouseover(function(){
		if (hideTimerHotel) { clearTimeout(hideTimerHotel); }
	});
	
	$('.hotel_details').mouseout(function(){
		if (hideTimerHotel) { clearTimeout(hideTimerHotel); }
		hideTimerHotel = setTimeout(function(){
			containerHotel.removeAttr('style').css('display', 'none');
		}, hideDelay);
	});
	
	$('.offer_description').click(function(){
			if ($(this).parent().hasClass('short_description'))
			{
				var short_description = $(this).parent('.short_description');
				var long_description = $(this).parent().siblings('.long_description'); 	
				short_description.fadeOut();
				long_description.fadeIn('slow');
			}
			else if ($(this).parent().hasClass('long_description'))
			{
				var short_description = $(this).parent().siblings('.short_description');
				var long_description = $(this).parent('.long_description'); 	
				long_description.fadeOut();
				short_description.fadeIn('slow');
			}
		}
	);
	
	//=============================== TABS
	$( ".tabs" ).tabs();
	
	//=============================== EVIDENZIA NEWSLETTER IN HOME PAGE
	if ($('#main').hasClass('home'))
	{
		$('#newsletter_container').load('/assets/box_newsletter.php #newsletter', function(){
			//=============================== VALIDAZIONE FORM NEWSLETTER
			$('#newsletter').validate({
				focusInvalid: false,
				rules: {
					email: {
						required: true,
						email: true
					}
				},
				messages: {
					email: emailErrorMessage
				},
				errorPlacement: function(error, element) {
					console.log(error);
					$('#indirizzo_posta').val(error.text());
				}
			});
		});
		
	}

});

function changeSelectOne(mySelect){
	var myId = $(mySelect).attr('name');
	$(mySelect).attr('id', myId);
	$(mySelect).parent().css({display:'block'});
	var myPositionLeft = $(mySelect).position().left;
	var myPositionTop = $(mySelect).position().top + 5; //Alex
	var myOnChange = ($(mySelect).attr('onchange') === undefined)? '' : ($(mySelect).attr('onchange') +'').replace("function onchange()\n{\n", '').replace("\n}", '');
	$(mySelect).parent().append('<input type="hidden" value="'+ $('#'+ myId +' :selected').val() +'" name="'+ myId +'">');
	
	myImage = ($(mySelect).hasClass('haveImg'))? '<img src="/images/img-select.gif" alt="" width="17" height="17" class="imgSelect" id="'+ myId +'_img" style="cursor:pointer;" />' : '';
	$(mySelect).parent().append('<input type="text" class="selectRep" value="'+ $('#'+ myId +' :selected').text() +'" name="'+ $(mySelect).attr('name') +'_sel" readonly="readonly">'+ myImage);
	$(mySelect).parent().append('<div class="dropDownSelectOne" id="'+ myId +'_box"></div>');
	var countOpt = 0;
	$(mySelect).children('option').each(function(){
		isCheck = ($(this).val() == $(this).parent('select').val())? ' class="sel"' : '';
		$('#'+ myId +'_box').append('<a href="javascript:;" name="'+ myId +'_'+ countOpt +'" id="'+ myId +'_'+ countOpt +'" rel="'+ $(this).val() +'"'+ isCheck +'>'+ $(this).text() +'</a>');
		if(myOnChange!=''){
			if(myId=='archive'){
				$("#"+ myId +"_"+ countOpt).bind('click', function() {
					setTimeout(function(){
						$('#archiveNews').submit();
					}, 500);
				});
			} else {
				myOnChange = (myOnChange +'').replace('setAirport(', '').replace(');', '');
				myOnChange = (myOnChange +'').replace(/'/g, "").replace(/ /g, "");
				myOnChange = myOnChange.split(',');
				$("#"+ myId +"_"+ countOpt).bind('click', function() {
					setAirport(myOnChange[0].replace('functionanonymous()\n{\n',''), myOnChange[1], myOnChange[2], $(this).attr('rel'));
				});
			}
		}
		$("#"+ myId +"_"+ countOpt).bind('click', function() {
			$(this).parent().children('a.sel').removeClass('sel');
			$(this).addClass('sel');
		});
		countOpt++;
	});
	$('#'+ myId +'_box a').each(function(){
		$(this).click(function(){
			$("input[name='"+ myId +"_sel']").val('');
			$("input[name='"+ myId +"_sel']").val($(this).html());
			$("input[name='"+ myId +"']").val('');
			$("input[name='"+ myId +"']").val($(this).attr('rel'));
			$(this).parent('div').filter(':not(:animated)').slideUp(0);
		})
	});
	$("input[name='"+ myId +"_sel']").focus(function(){
		$('#'+ myId +'_box').filter(':not(:animated)').slideDown(0, function(){$(this).blur();});
	});
	$("input[name='"+ myId +"_sel'], #"+ myId +"_img").click(function(){
		$('#'+ myId +'_box').filter(':not(:animated)').slideDown(0, function(){$(this).blur();});
	});
	$('#'+ myId +'_box').css({'display':'none','position':'absolute', 'left':(myPositionLeft) +'px', 'top':((myPositionTop) + $("input[name='"+ myId +"_sel']").innerHeight() + 1) +'px'});
	$('#'+ myId +'_box').hover(
		function () {}, 
		function () {
			$(this).filter(':not(:animated)').slideUp(0);
		}
	);
	$('#'+ myId +'_box').parent().hover(
		function () {}, 
		function () {
			$('#'+ myId +'_box').filter(':not(:animated)').slideUp(0);
		}
	);
	$(mySelect).remove();
}
