function ViewTour(idtour,idlingua) {
	larghezza=(screen.width/2)-320;
	altezza=(screen.height/2)-240;
	windowprops="directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=500,height=500,left=" + larghezza + ",screenX=25,top=" + altezza + ",screenY=25";
	finestra=window.open("view-tour.php?idtour="+idtour+"&idlingua="+idlingua,"",windowprops);
}


function ScopriTour(blocco,scopri) {
	
	if (scopri==1){alert(document.getElementById('layout').style.display);
		blocco.style.display = 'block';
	}else{
		blocco.style.display = 'display:none';	
	}
	
}

function Left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function Right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}
function AddDay(data,giorno){
	var giorno = new Number(data.substr(0,2));
	var mese = new Number(data.substr(3,2));
	var anno = new Number(data.substr(5,4));
	var MaxDay = NumberDay(mese,anno);
	if(giorno+1<=MaxDay){
		giorno=giorno+1;
		giorno = "0" + giorno;
		mese   = "0" + mese;
		return Right(giorno,2)+"-"+Right(mese,2);
	}else{
		giorno=1;
		if(mese+1<=12){
			mese=mese+1;
		}else{
			mese=1;
		}
		giorno = "0" + giorno;
		mese   = "0" + mese;
		return Right(giorno,2)+"-"+Right(mese,2);
	}
}
function NumberDay(mese,anno){
	switch(Math.abs(mese)){
		case 1: return 30; break; 
		case 2: if(bisestile(anno)){return 29;}else{return 28;} break; 
		case 3:	return 31; break; 
		case 4: return 30; break; 
		case 5: return 31; break; 
		case 6: return 30; break; 
		case 7: return 31; break; 
		case 8: return 31; break; 
		case 9: return 30; break; 
		case 10: return 31; break; 
		case 11: return 30; break; 
		case 12: return 31; break;
	  	default:
	}
}
function bisestile(anno){
   if ((anno % 4 == 0 && anno % 100 != 0) || anno % 400 == 0){
	return true;
   }else{
      	return false;
   }
}
function ApriCondizioni(valore){
	  larghezza=(screen.width/2)-320;
	  altezza=(screen.height/2)-240;
	  windowprops="directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=500,height=500,left=" + larghezza + ",screenX=25,top=" + altezza + ",screenY=25";
	  finestra=window.open("view-condizioni.php?tipo="+valore,"",windowprops);

}
function pasqua(anno){
	var a;
	var b;
	var c;
	var Y = anno;
	var d;
	var e;
	var M;
	var N;
	var giorno;
	var mese;

	if (Y < 2099)
	{
			M = 24;
			N = 5;
	}
	else if (Y < 2199)
	{
			M = 24;
			N = 6;
	}
	else if (Y < 2299)
	{
			M = 25;
			N = 0;
	}
	else if (Y < 2399)
	{
			M = 26;
			N = 1;
	}
	else if(Y < 2499)
	{
			M = 25;
			N = 1;
	}

	a = Y % 19;
	b = Y % 4;
	c = Y % 7;
	d = ((19*a) + M) % 30
	e = ((2*b) + (4*c) + (6*d) + N) % 7;

	if (d + e < 10)
	{
			giorno = d+e+22;
			mese = 3;
	}
	else{
			giorno = d+e-9;
			mese = 4;
	}

	if (giorno==26 && mese==4)
	{
			giorno = 19;
			mese = 4;
	}

	if (giorno==25 && mese==4 && d==28 && e==6 && a>10)
	{
			giorno=18;
			mese=4;
	}
	giorno = "0" + giorno;
	mese   = "0" + mese;
	return Right(giorno,2)+"-"+Right(mese,2);
}

var oldLink = null;
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	  a.disabled = true;
	  if(a.getAttribute("title") == title) a.disabled = false;
	}
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3" || cal.sel.id == "sel4" || cal.sel.id == "sel5"))
	cal.callCloseHandler();
  if (cal.dateClicked &&  (cal.sel.id == "sel3" || cal.sel.id == "sel1")){//serce a far aggiornare il prezzo in base alla data
	calcola();
  }else if(cal.sel.id == "sel4"){
  	calcola(document.modulo1.arrivo.value);
  }
}

function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
	// we already have some calendar created
	_dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
	// first-time call, create the calendar.
	var cal = new Calendar(1, null, selected, closeHandler);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	if (typeof showsTime == "string") {
	  cal.showsTime = true;
	  cal.time24 = (showsTime == "24");
	}
	if (showsOtherMonths) {
	  cal.showsOtherMonths = true;
	}
	_dynarch_popupCalendar = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();

  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;

}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}
