function setCalendarNews(siteId, iso3){
	$("a.tenback").click(function(){
		$("#eventsContainer").fadeOut(300);
		$("#boxEventsHome").css({background: '#fff url(/images/loading.gif) no-repeat center center'});
		var newtime = $(this).attr("id").replace('tenback-','');
		$.ajax({
			type: "GET",
			url: "/assets/eventList.php",
			data: "language=it&newtime="+newtime+"&siteID="+ siteId +"&iso3="+ iso3,
			success: function(myList){
				$("#eventsContainer").remove();
				$("#boxEventsHome").append(myList);
				$("#eventsContainer").fadeOut(0);
				$("#eventsContainer").fadeIn(300, function() {
					$("#boxEventsHome").css({background: 'none'});
				});
			}
		});
	});
	
	$("a.tenforward").click(function(){
		$("#eventsContainer").fadeOut(300);
		$("#boxEventsHome").css({background: '#fff url(/images/loading.gif) no-repeat center center'});
		var newtime = $(this).attr("id").replace('tenforward-','');
		$.ajax({
			type: "GET",
			url: "/assets/eventList.php",
			data: "language=it&newtime="+newtime+"&siteID="+ siteId +"&iso3="+ iso3,
			success: function(myList){
				$("#eventsContainer").remove();
				$("#boxEventsHome").append(myList);
				$("#eventsContainer").fadeOut(0);
				$("#eventsContainer").fadeIn(300, function() {
					$("#boxEventsHome").css({background: 'none'});
				});
			}
		});
	});
	
	$("a.eventInDay").click(function(){
		$("#listEventsContainer").fadeOut(300);
		$("#listEvents").css({background: '#fff url(/images/loading.gif) no-repeat center center'});
		var day = $(this).attr("id").replace('forday-','');
		$.ajax({
			type: "GET",
			url: "/assets/eventInDay.php",
			data: "language=it&day="+day+"&siteID="+ siteId +"&iso3="+ iso3,
			success: function(myList){
				$("#listEventsContainer").remove();
				$("#listEvents").append(myList);
				$("#listEventsContainer").fadeOut(0);
				$("#listEventsContainer").fadeIn(300, function() {
					$("#listEvents").css({background: 'none'});
				});
			}
		});
	});				
}
$(document).ready(function(){
	share.init({FB:true, TW:true});
});
var choseLang  = {
	show: function(mydiv) {
		if (document.getElementById){
			document.getElementById(mydiv).style.height="auto";
			document.getElementById(mydiv).style.overflow="visible";
		}
	}, 
	hide: function (mydiv){
		if (document.getElementById){
			document.getElementById(mydiv).style.height="14px";
			document.getElementById(mydiv).style.overflow="hidden";
		}
	},
	init: function (mydiv){
		if (document.getElementById(mydiv)){
			document.getElementById(mydiv).style.height="14px";
			document.getElementById(mydiv).style.overflow="hidden";
		}
	}
};
var destinationsBox  = {
	show: function(my_id) {
		if (document.getElementById('box_hotel')){
			my_cont = document.getElementById('box_hotel');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta != my_id) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:destinationsBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
						my_blocks_ul[0].style.display = "block";
						my_blocks_a[0].setAttribute("href","javascript:destinationsBox.show('"+conta+"');");
					}
					conta++;
				}
			}
		}
	},
	init: function (){
		if (document.getElementById('box_hotel')){
			my_cont = document.getElementById('box_hotel');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta>0) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:destinationsBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
						my_blocks_a[0].setAttribute("href","javascript:destinationsBox.show('"+conta+"');");
					}
					conta++;
				}
			}
		}
	}
};

var offersBox  = {
	show: function(my_id) {
		if (document.getElementById('box_offerte_inner')){
			my_cont = document.getElementById('box_offerte_inner');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta != my_id) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:offersBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
						my_blocks_ul[0].style.display = "block";
						my_blocks_a[0].setAttribute("href","javascript:offersBox.show('"+conta+"');");
					}
					conta++;
				}
			}
		}
	},
	init: function (){
		if (document.getElementById('box_offerte_inner')){
			my_cont = document.getElementById('box_offerte_inner');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta>0) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:offersBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
						my_blocks_a[0].setAttribute("href","javascript:offersBox.show('"+conta+"');");
					}
					conta++;
				}
			}
		}
	}
};


var travelBox  = {
	show: function(my_id) {
		if (document.getElementById('box_travel')){
			my_cont = document.getElementById('box_travel');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			Search2.resetSearch();
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta != my_id) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:travelBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
						my_blocks_ul[0].style.display = "block";
						var my_input = my_blocks[i].getElementsByTagName("input");
						for (icont = 0; icont<my_input.length; icont++){
							my_input[icont].value = initSearchTravel;
						}
						var my_div = my_blocks[i].getElementsByTagName("div");
						for (icont_div = 0; icont_div<my_div.length; icont_div++){
							my_div[icont_div].style.display = "none";
						}
					}
					conta++;
				}
			}
		}
	},
	init: function (){
		if (document.getElementById('box_travel')){
			my_cont = document.getElementById('box_travel');
			var my_blocks = my_cont.getElementsByTagName("li");
			var conta = 0;
			for(i=0; i < my_blocks.length; i++){
				if (my_blocks[i].className == "block"){
					my_blocks_a = my_blocks[i].getElementsByTagName("a");
					my_blocks_ul = my_blocks[i].getElementsByTagName("ul");
					if (conta>0) {
						my_blocks_ul[0].style.display = "none";
						my_blocks_a[0].className = "unsel";
						my_blocks_a[0].setAttribute("href","javascript:travelBox.show('"+conta+"');");
					} else {
						my_blocks_a[0].className = "sel";
					}
					conta++;
				}
			}
		}
	}
};

var Search2 = {
	init:function(id1, id2, id3){
		var myIds = new Array(id1, id2, id3);
		myBlock = document.getElementById("box_travel");
		var my_li = myBlock.getElementsByTagName("li");
		var mySingleCount = 0;
		for (icont = 0; icont<my_li.length; icont++){
			if (my_li[icont].className == "block"){
				mySingleCount++;
				myForm = my_li[icont].getElementsByTagName("form");
				myForm[0].innerHTML = '<input type="text" id="search_inp_'+mySingleCount+'" maxlength="30" value="'+initSearchTravel+'" onfocus="Search2.start(this.value, \'search_div_'+ mySingleCount +'\',\''+ myIds[mySingleCount-1] +'\');" onkeyup="Search2.start(this.value, \'search_div_'+ mySingleCount +'\',\''+ myIds[mySingleCount-1] +'\');" onblur="Search2.closeSearch(this.id);" /><div class="wait_search"><img src="/images/wait.gif" alt="" border="0" /></div>';
				myDiv= my_li[icont].getElementsByTagName("div");
				for (icont2 = 0; icont2<myDiv.length; icont2++){
					if (myDiv[icont2].className == "wait_search"){
						myDiv[icont2].style.display = "none";
					}
					if (myDiv[icont2].id == ("search_div_"+mySingleCount)){
						myDiv[icont2].style.display = "none";
						myDiv[icont2].innerHTML = "&nbsp;";
					}
				}
			}
		}
	},
	start:function(str, containerid, myIdVal){
		if(str != initSearchTravel){
			query = "/assets/filtra_prodotti.php?id="+ myIdVal + "&q="+ str;
			if(str!="" && (str.length > 2)){
				if (document.getElementById(containerid)){
					document.getElementById(containerid).style.display = "block";
					var my_wait = document.getElementsByTagName("div");
					for (icont = 0; icont<my_wait.length; icont++){
						if (my_wait[icont].className == "wait_search"){
							my_wait[icont].style.display = "block";
						}
					}
					include_page(query, containerid);
					setTimeout("stop_wait()",1000);
				}
			} else {
				Search2.resetSearch();
			}
		} else {
			mySplit = containerid.split("_");
			if(document.getElementById("search_inp_"+mySplit[2])){
				document.getElementById("search_inp_"+mySplit[2]).value = "";
			}
		}
	},
	resetSearch:function(){
		for (iDiv = 1; iDiv <= 3; iDiv++){
			if (document.getElementById("search_div_"+iDiv)){
				document.getElementById("search_div_"+iDiv).style.display = "none";
			}
		}
	},
	closeSearch:function(myId){
		if (document.getElementById(myId)){
			if (document.getElementById(myId).value == ""){
				document.getElementById(myId).value = initSearchTravel;
			}
		}
	}
};

function stop_wait(){
	var my_wait = document.getElementsByTagName("div");
	for (icont = 0; icont<my_wait.length; icont++){
		if (my_wait[icont].className == "wait_search"){
			my_wait[icont].style.display = "none";
		}
	}
}
function setWeatherHome(weather, weatherLb){
	if (document.getElementById("cont_home_weather")){
		myBlockWeather = document.getElementById("cont_home_weather");
		myImg = document.getElementById("weatherImg");
		myInd = document.getElementById("weatherInd");
		myWeData = weather.split("#");
		myWe = myWeData[0].split("_");
		myImg.setAttribute('src', '/images/meteo/'+myWe[0]+'.png');
		var myTemp = myInd.getElementsByTagName("strong");
		for (icont = 0; icont<myTemp.length; icont++){
			myTemp[icont].innerHTML = myWe[icont+1]+" C°";
		}
		if (document.getElementById("home_weather_day_next")){
			document.getElementById("home_weather_day_next").setAttribute("href",myWeData[1]);
			document.getElementById("home_weather_day_next").innerHTML = weatherLb+" "+myWeData[2] ;
		}
		document.getElementById("myWeather").blur();
	} else if (document.getElementById("cont_Int_weather")){
		myBlockWeather = document.getElementById("cont_Int_weather");
		myImg = document.getElementById("weatherImg");
		myInd = document.getElementById("weatherInd");
		myWeData = weather.split("#");
		myWe = myWeData[0].split("_");
		myImg.setAttribute('src', '/images/meteo/'+myWe[0]+'.png');
		var myTemp = myInd.getElementsByTagName("strong");
		for (icont = 0; icont<myTemp.length; icont++){
			myTemp[icont].innerHTML = myWe[icont+1]+" C°";
		}
		if (document.getElementById("home_weather_day_next")){
			document.getElementById("home_weather_day_next").setAttribute("href",myWeData[1]);
			document.getElementById("home_weather_day_next").innerHTML = weatherLb+" "+myWeData[2];
		}
		document.getElementById("myWeather").blur();
	}
}

var drop_order = {
	show: function(mydiv) {
		if (document.getElementById){
			document.getElementById(mydiv).style.height="auto";
			document.getElementById(mydiv).style.overflow="visible";
		}
	},
	hide: function(mydiv){
		if (document.getElementById){
			document.getElementById(mydiv).style.height="20px";
			document.getElementById(mydiv).style.overflow="hidden";
		}
	},
	init: function(mydiv){
		if (document.getElementById(mydiv)){
			document.getElementById(mydiv).style.height="20px";
			document.getElementById(mydiv).style.overflow="hidden";
		}
		if (document.getElementById('my_radio')){
			document.getElementById('my_radio').style.display="none";
		}
	},
	set_send: function(mydiv){
		var mio_div = document.getElementById('my_radio');
		var elements = mio_div.getElementsByTagName("input");
		for (var i = 0; i < elements.length; ++i) {
			name_radio = (elements[i].getAttribute("name") + "[" + i + "]");
			if (name_radio == mydiv) {
				document.getElementById('struct_ord_'+i).setAttribute("checked","checked");
			} else {
				document.getElementById('struct_ord_'+i).removeAttribute("checked");
			}
		}
		drop_order.hide('dropdown_order');
		
		if (IE6()){
			document.Invia = function() {
				document.getElementById("searchForm").submit();
			}
			setTimeout("document.Invia();", 10);
		} else {
			document.forms['searchForm'].submit();
		}
	}
};

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

var searchOpen = {
	init: function() {
		if (document.getElementById("box_search")){
			mySearch = document.getElementById("box_search");
			if (IE6()){
				mySearch.style.background = "url(/images/box_search.gif) no-repeat left bottom";
			} else {
				mySearch.style.background = "url(/images/box_search_js.png) no-repeat left bottom";
			}
			var myDiv = mySearch.getElementsByTagName("div");
			for (var i =0; i < myDiv.length; i++){
				if (myDiv[i].className == "search_home"){
					myDiv[i].style.minHeight="98px";
					myDiv[i].style.paddingBottom="0";
					myDiv[i].style.height="98px";
				}
			}
		}
	},
	opening: function(fnc) {
		if (document.getElementById("box_search")){
			mySearch = document.getElementById("box_search");
			var myDiv = mySearch.getElementsByTagName("div");
			for (var i =0; i < myDiv.length; i++){
				if (myDiv[i].className == "search_home"){
					if (fnc=="open"){
						searchOpen.scrollOpen(98, 32);
					} else if (fnc=="close"){
						searchOpen.scrollClose(document.getElementById("search").offsetHeight, 0);
					}
				}
			}
		}
	},
	scrollOpen: function(height, height2) {
		myHeightMax = document.getElementById("search").offsetHeight;
		myHeightMin2 = 0;
		myNewHeight = height + (Math.round((myHeightMax-height)/6)*1) + 1;
		myNewHeight2 = height2 - (Math.round((height2-myHeightMin2)/8)*1) - 1;
		if (document.getElementById("box_search")){
			mySearch = document.getElementById("box_search");
			myButtonLi = document.getElementById("openSearch");
			myButtonLi.style.overflow = "hidden";
			var myDiv = mySearch.getElementsByTagName("div");
			for (var i =0; i < myDiv.length; i++){
				if (myDiv[i].className == "search_home"){
					if ((myHeightMax-myNewHeight)>2){
						myDiv[i].style.height=myNewHeight+"px";
						if (myNewHeight2<0){
							myButtonLi.style.height = "0";
							myButtonLi.style.display = "none";
						} else {
							myButtonLi.style.height = myNewHeight2 + "px";
						}
						setTimeout('searchOpen.scrollOpen(myNewHeight, myNewHeight2)', 20);
					} else {
						myButtonLi.style.height = "0";
						myButtonLi.style.display = "none";
						myDiv[i].style.height="auto";
					}
				}
			}
		}
	},
	scrollClose: function(height, height2) {
		myHeightMin = 98;
		myHeightMax2 = 32;
		myNewHeight = height - (Math.round((height-myHeightMin)/6)*1) - 1;
		myNewHeight2 = height2 + (Math.round((myHeightMax2-height2)/8)*1) + 1;
		if (document.getElementById("box_search")){
			mySearch = document.getElementById("box_search");
			myButtonLi = document.getElementById("openSearch");
			myButtonLi.style.overflow = "hidden";
			myButtonLi.style.display = "block";
			var myDiv = mySearch.getElementsByTagName("div");
			for (var i =0; i < myDiv.length; i++){
				if (myDiv[i].className == "search_home"){
					if ((myNewHeight-myHeightMin)>2){
						myDiv[i].style.height=myNewHeight+"px";
						if (myNewHeight2 > 1){
							myButtonLi.style.height = myNewHeight2 +"px";
						}
						setTimeout('searchOpen.scrollClose(myNewHeight, myNewHeight2)', 20);
					} else {
						myDiv[i].style.height = myHeightMin +"px";
						myButtonLi.style.height = myHeightMax2 +"px";
					}
				}
			}
		}
	}
};

function go_top(topper){
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
	}
	if (topper == "null"){
		topper = scrOfY;
	} else {
		topper = topper;
	}
	var new_topper = Math.round(topper/10)*1;
	
	if ((topper-new_topper)>5){
		scrollTo(0, (topper-new_topper));
		setTimeout('go_top('+((topper*1)-(new_topper*1))+')',10);
	} else {
		scrollTo(0, 0);
		return false;
	}
}

function go_to(id, initial){
	if (document.getElementById(id)){
		my_id = id;
		if (initial == undefined){
			//alert("123");
			setTimeout("go_to(my_id, 1)",1000);
			return;
		} else {
			var scrOfY = 0;
			var mio_blocco = document.getElementById(id);
			var scr2fY = mio_blocco.offsetTop;
			var mia_pagina = document.getElementById('page');
			var altezza_pagina = mia_pagina.offsetHeight + 150;
			var altezza_body = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
				scrOfY = window.pageYOffset;
				altezza_body = document.body.offsetHeight;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				scrOfY = document.body.scrollTop;
				altezza_body = document.body.offsetHeight;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				scrOfY = document.documentElement.scrollTop;
				altezza_body = document.body.offsetHeight;
			}
			
			var topper = -(scrOfY - scr2fY);
			var new_topper = scrOfY + (Math.round(topper/40)*1);
			if ((-new_topper + scr2fY) > 5){
				if (altezza_pagina > (new_topper + altezza_body)){
					scrollTo(0, new_topper);
					setTimeout("go_to(my_id, 1)",10);
				} else {
					return false;
				}
			} else {
				scrollTo(0, scr2fY);
				return false;
			}
		}
	} else {
		alert("Elemento " + id + " inesistente.");
	}
}


function checkSearch(alert1, alert2) {
	var errore = true;
	if(document.forms["searchForm"].cityId.value == '') {
		alert(alert1);
		errore = false;
	}
	return errore;
}

function CheckSS(form, message, iso2){
	hasDot = form.msn.value.indexOf(".");
	hasAt = form.msn.value.indexOf("@");
	if (hasDot == -1 || hasAt == -1 || form.msn.value=="email@email."+iso2){
		alert(message);
		form.msn.focus();
		form.msn.select();
		return false;
	}
	return true;
}

function allert(htm){
	var ne = document.createElement("div");
	ne.id = "myAlert";
	ne.innerHTML = '<div id="myAlertCont" style="position:relative; float:left; width:200px; padding:40px 60px; text-align:center;"><a title="Close" style="display:block; position:absolute; top:10px; right:10px; cursor:pointer;" onclick="closeAllert(\'myAlert\');">X</a><p>'+htm+'</p></div>';
	document.body.appendChild(ne);
	var myDiv = document.getElementById("myAlert");
	var myDivCont = document.getElementById("myAlertCont");
	myDiv.style.position = "absolute";
	myDiv.style.zIndex = "10000000";
	myDiv.style.width = "100%";
	myDiv.style.height = "100%";
	myDiv.style.top = "0";
	myDiv.style.left = "0";
	myDivCont.style.top = (document.body.offsetHeight/2 -(myDivCont.offsetHeight/2 +5))+"px";
	myDivCont.style.left = (document.body.offsetWidth/2 -(myDivCont.offsetWidth/2 +5))+"px";
	myDivCont.style.backgroundColor = "#fff";
	myDivCont.style.border = "1px solid #000";
	myDivCont.style.zIndex = "10000001";
	myDiv.setAttribute("onclick","closeAllert('myAlert')");
	
}
function closeAllert(childDiv){
	parentDiv = document.body;
	if (childDiv == parentDiv) {
		return false;
	} else if (document.getElementById(childDiv)) { 
		var child = document.getElementById(childDiv);
		var parent = parentDiv;
		parent.removeChild(child);
	} else {
		return false;
	}
}

function setChildAge(nchild, chdid, roomn, label_children_age){
	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 + ']"  class="child" >' +
				'<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;
	}
}

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 = "";
	for (var i=1; i<=nrooms; i++){
		myResults = myResults + '<ul>\n';
		if ( nrooms > 1){
			myResults = myResults + '	<li class="titleRoom"><span>'+ label_room +' '+ i +'</span></li>\n';
		}
		myResults = myResults + '	<li class="mezza">\n'+
		'		<label>'+ label_adults +'</label>\n'+
		'		<select name="bform[reqRooms]['+ i +'][adults]" class="select_small">\n'+
		'			'+ createSelect(6, 1, label_adults, 2) + 
		'		</select>\n'+
		'	</li>\n'+
		'	<li class="mezza2">\n'+
		'		<label>'+ label_children +'</label>\n'+
		'		<select name="bform[reqRooms]['+ i +'][child]" class="select_small" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\');">\n'+
		'			'+ createSelect(4, 0, label_children, 0) + 
		'		</select>\n'+
		'	</li>\n'+
		'	<li id="chdAge_'+ i +'">\n'+
		'	</li>\n'+
		'</ul>\n';
	}
	if (document.getElementById('contOption')){
		document.getElementById('contOption').innerHTML = myResults;
	} else {
		alert("blocco non valido");
	}
}

function set_room(select_id, value){
	var my_options = "";
	var my_block = document.getElementById(select_id);
	if (value=="5" || value=="6" || value=="7" || value=="8"){
		my_options = '<label>'+ name_apartment +"</label>\n";
		my_options = my_options + '<select name="bform[numRooms]" id="bform[numRooms]" class="select_big" onchange="setRoom(this.value, name_adults , name_children, name_childage, name_apartment);">'+"\n";
		my_options = my_options + '<option value="1">1 '+name_apartment+'</option>'+"\n";
		my_options = my_options + '<option value="2">2 '+name_apartment+'</option>'+"\n";
		my_options = my_options + '<option value="3">3 '+name_apartment+'</option>'+"\n";
		my_options = my_options + '<option value="4">4 '+name_apartment+'</option>'+"\n";
		my_options = my_options + '</select>'+"\n";
		my_block.innerHTML = my_options;
		setRoom(1, name_adults , name_children, name_childage, name_apartment);
		
		$("#bform_checkin").datepicker('option', {beforeShowDay: onlySaturday});
		$("#bform_checkout").datepicker('option', {beforeShowDay: onlySaturday});
		$("#bform_checkin").unbind("change");
		
		date1 = $("#bform_checkin").datepicker('getDate');
		var saturday = new Date(date1);
		saturday.setDate(saturday.getDate() + 6 - saturday.getDay()); 
		$("#bform_checkin").datepicker( "setDate", saturday );
		date2 = $("#bform_checkout").datepicker('getDate');
		var saturday2 = new Date(date2);
		saturday2.setDate(saturday2.getDate() + 6 - saturday2.getDay()); 
		if (saturday2 <= saturday) {
			saturday2.setDate(saturday.getDate() + 7);
		}
		$("#bform_checkout").datepicker( "setDate", saturday2 );

	} else {
		my_options = '<label>'+ name_room +"</label>\n";
		my_options = my_options + '<select name="bform[numRooms]" id="bform[numRooms]" class="select_big" onchange="setRoom(this.value, name_adults, name_children, name_childage, name_room);">'+"\n";
		my_options = my_options + '<option value="1">1 '+name_room+'</option>'+"\n";
		my_options = my_options + '<option value="2">2 '+name_room+'</option>'+"\n";
		my_options = my_options + '<option value="3">3 '+name_room+'</option>'+"\n";
		my_options = my_options + '<option value="4">4 '+name_room+'</option>'+"\n";
		my_options = my_options + '</select>'+"\n";
		my_block.innerHTML = my_options;
		setRoom(1, name_adults , name_children, name_childage, name_room);
		
		$("#bform_checkin").datepicker('option', {beforeShowDay: allDay});
		$("#bform_checkout").datepicker('option', {beforeShowDay: allDay});
		$("#bform_checkin").unbind("change");
		$("#bform_checkin").change(
			function(){
				date1 = $("#bform_checkin").datepicker('getDate');
				date2 = new Date(date1);
				date2.setDate(date1.getDate() +1);
				$("#bform_checkout").datepicker('option',
				'minDate', date2);
			}
		);
	}
}

function onlySaturday(date){
	 var day = date.getDay();
	 return [(day == 6), ''];
}

function allDay(date){
	 var day = date.getDay();
	 return [true, ''];
}

function startBlockUI(msg1, msg2, portal){
	if (portal == 2) { 
		img = "/images/ajax-loader-green.gif";
		colorborder = '#006600';
		colorbackground = '#D1DFD1';
	} else if(portal == 3) {
		img = "/images/ajax-loader-red.gif";
		colorborder = '#8f2a31';
		colorbackground = '#DFC5C3';
	} else {
		img = "/images/ajax-loader.gif";
		colorborder = '#3A79B6';
		colorbackground = '#6CA1BA';
	}
	
	$.blockUI({ 
		message: '<h1 style="font-size: 15px;">'+msg1+'<br />'+msg2+'</h1><br /><img src="'+img+'" alt="" border="0" />',
		css: { 
			border: '2px solid '+colorborder+'', 
			padding: '20px', 
			backgroundColor: '#fff', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			color: ''+colorborder+''
		},
		overlayCSS: { 
			backgroundColor: ''+colorbackground+'',
			opacity: .7
		}								 
	}); 
}

//////////////////////// FUNZIONI PER LE OFFERTE IN HOME

function newsInit() {
	if($('.text_offers_home').lenght > 2 ) {
		myInterval = setInterval ( "moveLeft(1)", 5000 );
		$('.text_offers_home:last').remove().insertBefore('#box_offerte ul li.text_offers_home:first');
		$('#pulsGalDx').click(function(){moveLeft(0)});
		$('#pulsGalSx').click(function(){moveRight()});
	}
}


function moveLeft(loop) {
	if(loop==1){
		clearInterval(myInterval);
		myInterval = setInterval ( "moveLeft(1)", 5000 );
	}		
	myFirst = $('#box_offerte ul li.text_offers_home:first');
	myWidth = $('#box_offerte ul li.text_offers_home:first').width();
	myArr = $('#box_offerte ul li.text_offers_home').filter(':animated');
	if(myArr.length == 0){
		myFirst.animate({width:0, marginRight:0},'','',
			function(){
				myFirst.remove().insertAfter('#box_offerte ul li.text_offers_home:last');
				myFirst.width(277);
				myFirst.css({marginRight:25});
			}
		);
	}
}

function moveRight() {
	clearInterval(myInterval);
	myInterval = setInterval ( "moveLeft(1)", 5000 );
	myLast = $('#box_offerte ul li.text_offers_home:last');
	myWidth = $('#box_offerte ul li.text_offers_home:last').width();
	myLast.width(0);
	myLast.css({marginRight:0});
	myLast.remove().insertBefore('#box_offerte ul li.text_offers_home:first');
	myLast.filter(':not(:animated)').animate({width:myWidth, marginRight:25});
}

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

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

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).append(this);
				$(this).fadeIn();
			})
			.error(function(){
				noimage = "/images/no_img.png";
				$(img).attr('src',noimage);
			})
			.attr({'src': imgLink, 'class':'thumb',  'width':48, 'height': 48});
		});
	}
}

var share = {
	options: {
		share: {
			FB: 'http://www.facebook.com/share.php?u=myPageUrl&t=myPageTitle',
			TW: 'http://twitter.com/share?url=myPageUrl&text=myPageTitle'
		}
	},
	init: function (optiones) {
		var myPageUrlNow = window.location.href;
		var myPageTitleNow = share.decode(escape(share.encode(document.title)));
		var myPageTextNow = "";
		var metaArray = document.getElementsByName('description');
		if (metaArray) {
			for (var i = 0; i < metaArray.length; i++) myPageTextNow = myPageTextNow + metaArray[i].content;
		}
		myPageTextNow = escape(myPageTextNow);
		for (names in optiones) {
			if (share.options.share[names] != undefined) {
				haveLink = false;
				if(typeof(window['mySocial']) != 'undefined'){
					if(mySocial[names] != undefined){
						myUrlNow = share.options.share[names].replace("myPageUrl", jbase64.decode(mySocial[names]));
						haveLink = true;
					}
				}
				if(!haveLink) myUrlNow = share.options.share[names].replace("myPageUrl", myPageUrlNow);
				myUrlNow = myUrlNow.replace("myPageTitle", myPageTitleNow);
				myUrlNow = myUrlNow.replace("myPageText", myPageTextNow);
				$('#share' + names).attr('href', 'javascript:share.modal(\'' + myUrlNow + '\');');
			}
		}
	},
	modal: function (myModalUrl) {
		if (window.showModalDialog) {
			window.showModalDialog(myModalUrl, "socials", "dialogHeight:450px;dialogWidth:880px");
		} else {
			window.open(myModalUrl, 'socials', 'height=450,width=880,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
		}
	},
	encode: function (s) {
		for (var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l; s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]);
		return s.join("");
	},
	decode: function (s) {
		for (var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
		((a = s[i][c](0)) & 0x80) && (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ? o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = ""));
		return s.join("");
	}
};
