function clear(id){
	var mio_div = document.getElementById(id);
	var selettori_mio_div = mio_div.getElementsByTagName('strong');
	for(k = 0; k < selettori_mio_div.length; k++) {
		selettori_mio_div[k].style.visibility = "hidden";
	}
}

function dinamic_panel(id){
	blocco = "box_home_service";
	if (document.getElementById(blocco)){
		var mio_blocco = document.getElementById(blocco);
		var mio_nodo = mio_blocco.getElementsByTagName('li');
		for(i=0; i < mio_nodo.length; i++){
			if (mio_nodo[i].id){
				var current_div = mio_nodo[i].id;
				var mio_div_content = document.getElementById(current_div);
				mio_div_content.style.overflow = "hidden";
				if (current_div != id){
					mio_div_content.style.height="15px";
				} else {
					mio_div_content.style.height="130px";
				}
			}
		}
	}
}

function open_panel(id){
	var blocco = "box_home_service";
	var panel_open_now = "undefined";
	var height_panel_open = 141;
	if (document.getElementById(blocco)){
		var mio_blocco = document.getElementById(blocco);
		var mio_nodo = mio_blocco.getElementsByTagName('li');
		for(i=0; i < mio_nodo.length; i++){
			if (mio_nodo[i].id){
				var current_div = mio_nodo[i].id;
				var mio_div_content = document.getElementById(current_div);
				if (mio_div_content.offsetHeight != "26" && (mio_div_content.offsetHeight*1 == height_panel_open*1)){
					panel_open_now = mio_nodo[i].id;
					height_panel_open = mio_div_content.offsetHeight;
				} else if (mio_div_content.offsetHeight != "26" && mio_div_content.offsetHeight != height_panel_open){
					return false;
				}
			}

		}
	}
	if (panel_open_now != id && panel_open_now != "undefined"){
		open_dinamic_panel(panel_open_now, id, 145, 15);
	}
}

function open_dinamic_panel(panel_open_now, id, height, height_now){
	
	p1 = panel_open_now + "";
	p2 = id + "";
	
	var blocco = "box_home_service";
	
	new_height = Math.round((height-height_now)/8)*1;
	my_height = height;

	var mio_blocco_figlio = document.getElementById(id);

	var mio_blocco_figlio_2 = document.getElementById(panel_open_now);
	
	my_height_result = new_height+height_now;
	
	if ((height-height_now)>15){
		mio_blocco_figlio.style.height = (my_height_result)+"px";
		mio_blocco_figlio_2.style.height = (height-my_height_result)+"px";
		
		setTimeout("open_dinamic_panel(p1, p2, my_height, my_height_result)", 10);
		
	} else {
		mio_blocco_figlio.style.height="130px";
		mio_blocco_figlio_2.style.height="15px";
		return false;
	}
}

function moveto(my_photo, my_container){
	if (document.getElementById(my_container)){
		var mio_blocco = document.getElementById(my_container);
		var mio_blocco_foto = mio_blocco.getElementsByTagName("img");
		/*if(mio_blocco_foto[0].style.top==""){
			mio_blocco_foto[0].style.top = "0";
		} else {
			mio_blocco_foto[0].style.top = -((my_photo*1)-1)*105+"px";
		}*/
		mio_blocco_foto[0].style.top = -((my_photo*1)-1)*105+"px";
	} else {
		alert("Elemento " + my_container + " inesistente.");
	}
}

function show(mydiv){
	if (document.getElementById){
		document.getElementById(mydiv).style.height="auto";
		//document.getElementById(mydiv).style.overflow="visible";
		document.getElementById(mydiv).style.backgroundPosition = "left bottom";
	}
}
function hide(mydiv){
	if (document.getElementById){
		document.getElementById(mydiv).style.height="20px";
		//document.getElementById(mydiv).style.overflow="hidden";
		document.getElementById(mydiv).style.backgroundPosition = "left -160px";
	}
}
function init(mydiv){
	if (document.getElementById(mydiv)){
		document.getElementById(mydiv).style.height="20px";
		document.getElementById(mydiv).style.overflow="hidden";
		document.getElementById(mydiv).style.backgroundPosition = "left -160px";
	}
}

function reset_type(id){
	if (document.getElementById(id)){
		var obj = document.getElementById(id);
		if (id == "call_name"){
			if(obj.value == varNome) {
				obj.value="";
			} else if(obj.value=="") {
				obj.value=varNome;
			}
		} else if (id == "call_phone") {
			if(obj.value == varTelefono) {
				obj.value="";
			} else if(obj.value=="") {
				obj.value=varTelefono;
			}
		}
	}
}

function checkCallback(){
	var testo_err = varRequest+'\n\n';
	var mancato_ins = false;	

	if (document.forms['call']['name'].value == varNome) {
		testo_err = testo_err + '- '+ varNome +'\n';
		mancato_ins = true; 
	}
	if (document.forms['call']['phone'].value == varTelefono) {
		testo_err = testo_err + '- '+ varTelefono +'\n';
		mancato_ins = true; 
	}
	if (mancato_ins == true) {
		alert (''+testo_err+'');
		return false;
	} else {
		return true;
	}
}

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]",
		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){};
	}
};

function addQuerystring(myId, myVal){
	if (document.getElementById(myId)){
		myIdQuery = myVal.split(",");
		mioBlocco = document.getElementById(myId);
		var myLi = mioBlocco.getElementsByTagName("li");
		for (i=0; i<myLi.length; i++){
			//alert(i);
			myAnchor = myLi[i].getElementsByTagName("a");
			if (myIdQuery[i]!="0"){
				myHref = myAnchor[0].getAttribute("href")+ "?p=" + myIdQuery[i];
				myAnchor[0].setAttribute("href",myHref);
			}
		}
	} else {
		alert("non esiste");
	}
}
