function _0(num){
	return (num<10?"0":"") + num;
};

theFirstDate = new Date();
theSecondDate = new Date();
theSecondDate.setDate(theSecondDate.getDate()+1);

Search = {
	options:{
		from:"bform[checkin]",
		to:"bform[checkout]",
		trigger_from:"f_trigger_a",
		trigger_to:"f_trigger_b",
		override:false
	},
	calendarSetup:function(){
		var cal_from = Calendar.setup({
			inputField     :    Search.options.from,           //*
			ifFormat       :    "%d-%m-%Y",
			showsTime      :    false,
			button         :    Search.options.trigger_from,
			weekNumbers	   :	false,
			step           :    1,
			firstDay       :    1,
			dateStatusFunc :	Search.noOldDays,
			onUpdate	   :	Search.upDate,
			electric       :    false
		});
		var cal_to = Calendar.setup({
			inputField     :    Search.options.to,           //*
			ifFormat       :    "%d-%m-%Y",
			showsTime      :    false,
			button         :    Search.options.trigger_to, 
			weekNumbers	   :	false,
			step           :    1,
			firstDay       :    1,
			dateStatusFunc :	Search.noOldDaysTheSecond,
			onUpdate       :    Search.upDateTheSecond,
			electric       :    false
		});
		var cal_from2 = Calendar.setup({
			inputField     :    Search.options.from,           //*
			ifFormat       :    "%d-%m-%Y",
			showsTime      :    false,
			weekNumbers	   :	false,
			step           :    1,
			firstDay       :    1,
			dateStatusFunc :	Search.noOldDays,
			onUpdate	   :	Search.upDate,
			electric       :    false
		});
		var cal_to2 = Calendar.setup({
			inputField     :    Search.options.to,           //*
			ifFormat       :    "%d-%m-%Y",
			showsTime      :    false,
			weekNumbers	   :	false,
			step           :    1,
			firstDay       :    1,
			dateStatusFunc :	Search.noOldDaysTheSecond,
			onUpdate       :    Search.upDateTheSecond,
			electric       :    false
		});
	},
	init:function(){
		if(arguments.length == 1 && typeof(arguments[0]) == "object"){
			for(var ind in arguments[0]){
				Search.options[ind] = arguments[0][ind];
			}
		}
		if(Search.options.override){
			for(o in Overrides){
				Calendar.prototype[o] = Overrides[o];
			}
		}
		Search.calendarSetup();
	},
	noOldDays:function(date,y,m,d){
		var blockDate = new Date();
		blockDate.setDate(blockDate.getDate()-1);
		if(date<(blockDate)){
			return true;
		}else{
			return false;
		}
	},
	upDate:function(cal){
		theFirstDate = cal.date;
		if(theSecondDate.getTime()<=cal.date.getTime()){
			theSecondDate = cal.date;
			theSecondDate = new Date(theFirstDate.getFullYear(),theFirstDate.getMonth(),theFirstDate.getDate());
			theSecondDate.setDate(theSecondDate.getDate()+1);
			var theString = _0(theSecondDate.getDate())+"-"+_0(theSecondDate.getMonth()+1)+"-"+theSecondDate.getFullYear();
			document.getElementById(Search.options.to).value = theString;
		}
	},
	upDateTheSecond:function(cal){
		theSecondDate = cal.date;
	},
	noOldDaysTheSecond:function(date,y,m,d){
		var fgiorno = theFirstDate.getDate();
		var fmese = theFirstDate.getMonth();
		var fanno = theFirstDate.getFullYear();
	
		var secondBlockDate = new Date(fanno,fmese,fgiorno);
//		secondBlockDate.setDate(secondBlockDate.getDate()-1);
	
		if(date<secondBlockDate){
			
			return true;
		}else{
			return false;
		}
	}
};

var Overrides = {
	showAtElement:function (el, opts) {
	var self = this;
	var p = Calendar.getAbsolutePos(el);
	if (!opts || typeof opts != "string") {
		this.showAt(p.x, p.y + el.offsetHeight);
		return true;
	}
	function fixPosition(box) {
		if (box.x < 0)
			box.x = 0;
		if (box.y < 0)
			box.y = 0;
		var cp = document.createElement("div");
		var s = cp.style;
		s.position = "absolute";
		s.right = s.width = "0px";
		document.body.appendChild(cp);
		var br = Calendar.getAbsolutePos(cp);
		document.body.removeChild(cp);
		if (Calendar.is_ie) {
			br.x += document.body.scrollLeft;
		} else {
			br.x += window.scrollX;
		}
		var tmp = box.x + box.width - br.x;
		if (tmp > 0) box.x -= tmp;
	}
	this.element.style.display = "block";
	Calendar.continuation_for_the_fucking_khtml_browser = function() {
		var w = self.element.offsetWidth;
		var h = self.element.offsetHeight;
		self.element.style.display = "none";
		var valign = opts.substr(0, 1);
		var halign = "l";
		if (opts.length > 1) {
			halign = opts.substr(1, 1);
		}
		// vertical alignment
		switch (valign) {
			case "T": p.y -= h; break;
			case "B": p.y += el.offsetHeight; break;
			case "C": p.y += (el.offsetHeight - h) / 2; break;
			case "t": p.y += el.offsetHeight - h; break;
			case "b": break; // already there
		}
		// horizontal alignment
		switch (halign) {
			case "L": p.x -= w; break;
			case "R": p.x += el.offsetWidth; break;
			case "C": p.x += (el.offsetWidth - w) / 2; break;
			case "l": p.x += el.offsetWidth - w; break;
			case "r": break; // already there
		}
		p.width = w;
		p.height = h + 40;
		self.monthsCombo.style.display = "none";
		fixPosition(p);
		self.showAt(p.x, p.y);
	};
	if (Calendar.is_khtml)
		setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10);
	else
		Calendar.continuation_for_the_fucking_khtml_browser();
	}
};
var append = function(func,callback){
	return function(){
		try{
			func();
		}catch(e){};
		try{
			callback();
		}catch(e){};
	}
};

////// newsticker mootools
	

function JSFX_FloatBottomLeft()
{
/*	var startX = 1, startY = 435; // setta l'altezza dal basso
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		// y > 435
		el.sP=function(x,y){
		if(y < 435) {y = 435;}
			this.style.left=x+"px";this.style.top=y+"px";
		};
		el.x = startX; 
		el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		el.y -= startY;
		return el;
	}
	window.stayBottomLeft=function()
	{
		var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		fblObj.y += (pY - startY - fblObj.y)/8;
		fblObj.sP(fblObj.x, fblObj.y);
		setTimeout("stayBottomLeft()", 40);
	}
	fblObj = ml("divStayTopLeft");
	stayBottomLeft();*/
};

/*	nt_duration = 26000;
	
	window.addEvent('domready',function(){
		$('ticker').addClass('js');
		rheight = $('ticker').getSize().y;
		$('ticked-wrapper').addClass('js');
		theight = $('ticked-wrapper').getSize().y;
		effect = new Fx.Tween('ticked-wrapper','top',{transition:Fx.Transitions.linear,duration:nt_duration});

		effect.addEvent('onComplete',function(){
			$('ticked-wrapper').setStyles({top:'0px'});
			this.start(-theight);
		});
		
		$('ticker').addEvent('mouseenter',function(){
			effect.pause();
		});
		$('ticker').addEvent('mouseleave',function(){
			effect.resume();
		});

		if(rheight < theight){
			$$('.ticked').each(function(elem){
				$('ticked-wrapper').adopt(elem.clone());
			});
			effect.start(0,-theight);
		}	
	});*/
/*
	posy = window.getScrollTop()+window.getHeight()-435;
	if (posy <= 432) {posy = 435;}
		$('divStayTopLeft').setStyles({'top': posy});
*/
window.addEvent('domready',function(){
	var floatindiv = (function allinea(){ 
		var id_elem = $('divStayTopLeft');
		var pos_bottom = id_elem.getSize().y+64;	// altezza div divStayTopLeft + altezza footer
		var pos_min = 446;							// offset top desiderato del div divStayTopLeft dal bordo superiore del viewport
		var posy = window.getScrollTop()+window.getHeight()-pos_bottom;
		var posa = id_elem.getPosition().y;
		if (window.getScrollTop() >= pos_min) {		// se scrollo la pagina oltre la distanza minima...
			posy = window.getScrollTop();			// ...la posizione del div è uguale alla lunghezza dello scroll (cioè il div resta ancorato al top della pagina)...
		} else {
			posy = pos_min;							// ...altrimenti resta fermo alla distanza minima dal top
		}
		//if (posy <= pos_min) {posy = pos_min;}	//spostamento vecchio
		
		var speed = (Math.abs(posy - posa))*4.5;

		efex = new Fx.Tween(id_elem,'top',{transition:Fx.Transitions.linear,duration:speed});
		efex.addEvent("onStart",function() { $clear(floatindiv); });
		efex.addEvent("onComplete",function() { allinea(); });
		efex.start(posy);
	}).periodical(50);
});
/*function bestemmie() {
	posy = window.getScrollTop()+window.getHeight()-435;
	if (posy <= 432) {posy = 435;}
	efex = new Fx.Tween('divStayTopLeft','top',{transition:Fx.Transitions.Sine.easeOut,duration:600});
	efex.start(posy);
	//$('divStayTopLeft').setStyles({'top': posy});
	setTimeout("bestemmie()",50);
}
bestemmie();*/

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+1)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-1+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-1+"px"
setTimeout(function(){scrollerinstance.animateup()}, 10)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


function setRoom2(nrooms,label_adults,label_children,label_children_age,label_room){
	//cancello le righe e le ricreo
	for (cc=2;cc<=10;cc=cc+1) 
	{
		jQuery('.r'+cc).remove();
		jQuery('#childlabel'+cc).remove();
	}
	
	var roomsHtml = '';
	
	if(nrooms > 1)
	{
		for (cc=2;cc<=nrooms;cc=cc+1) 
		{
			var roomsHtml =  roomsHtml +
			'<tr class="r'+cc+'" >' +
			'<td colspan="2"><div class="roomlabel">'+label_room+' '+cc+'</div></td>' +
			'</tr>' +
			'<tr class="r'+cc+'" >' +
			'<td scope="row">'+label_adults+'</td>' +
			'<td><select name="bform[reqRooms]['+cc+'][adults]" >' +
			'<option value="1">1</option>' +
			'<option value="2" selected="selected" >2</option>' +
			'<option value="3">3</option>' +
			'<option value="4">4</option>' +
			'</select>' +
			'</td>' +
			' </tr>' +
			'<tr class="r'+cc+'" >' +
			'<td scope="row">'+label_children+'' +
			'</td>' +
			'<td><select name="bform[reqRooms]['+cc+'][child]" onchange="setChildAge2(this.value,'+cc+')" >' +
			' <option value="0">0</option>' +
			' <option value="1">1</option>' +
			' <option value="2">2</option>' +
			' <option value="3">3</option>' +
			'</select>' +
			'</td>' +
			' </tr>' +
			'<tr id="childlabel'+cc+'">' +
			'<td scope="row">'+label_children_age+'</td>' +
			'<td><div id="childage'+cc+'"></div></td>'
			'</tr>';
		}
		
		jQuery('#lastroom').after( roomsHtml ).show();
		
		for (cx=2;cx<=nrooms;cx=cx+1) 
		{
			jQuery('#childlabel'+cx).css( 'display', 'none' );
			jQuery('#childage'+cx).html( '' );
		}
		
		jQuery('div.roomlabel').css( 'display', 'block' );
		jQuery('.spazio').css( 'height', '2px' );
	}
	else
	{
		jQuery('div.roomlabel').css( 'display', 'none' );
		jQuery('.spazio').css( 'height', '13px' );
	}
	
}


function setChildAge2(nchild,roomn){
	if(nchild > 0)
	{
		var selectHtml = '';
		var cc = 1;
		
		for (cc=1;cc<=nchild;cc=cc+1) 
		{
			var selectHtml =  selectHtml + '<select name="bform[reqRooms]['+roomn+'][childAge][' + cc + ']"  class="childage {validate:{required:true, messages:{required:\'\'}}}" >' +
			'<option value="">-</option>' +
			'<option value="0">&lt;1</option>' +
			'<option value="1">1</option>' +
			'<option value="2">2</option>' +
			'<option value="3">3</option>' +
			'<option value="4">4</option>' +
			'<option value="5">5</option>' +
			'<option value="6">6</option>' +
			'<option value="7">7</option>' +
			'<option value="8">8</option>' +
			'<option value="9">9</option>' +
			'<option value="10">10</option>' +
			'<option value="11">11</option>' +
			'<option value="12">12</option>' +
			'<option value="13">13</option>' +
			'<option value="14">14</option>' +
			'<option value="15">15</option>' +
			'<option value="16">16</option>' +
			'<option value="17">17</option>' +
			'<option value="18">18</option>' +
			'</select>';
		}
		
		jQuery('#childage'+roomn).html( selectHtml ).show();
		jQuery('#childlabel'+roomn).removeAttr( 'style' );
		//jQuery('#search').validate();
	}
	else
	{
		jQuery('#childage'+roomn).html( '' );
		jQuery('#childlabel'+roomn).css( 'display', 'none' );
		//jQuery('#search').validate();
	}
}