﻿// JavaScript Document
var langvis = false;

function ApriPopup(URL,nome,proprieta) {
  finestra = window.open(URL,nome,proprieta);
  finestra.focus();
  return false;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function lightit (obj, layr) {
	obj.style.borderBottom='1px solid #f7d6b5'; 
	obj.style.backgroundColor='#f7d6b5';
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="block";
}
function darkenit (obj, layr) {
	obj.style.borderBottom='1px solid #de2219'; 
	obj.style.backgroundColor='#f79b52';
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="none";
}
function light (obj, layr) {
	mytd = MM_findObj(obj);
	mytd.style.backgroundColor='#f7d6b5';
	mytd.style.borderBottom='1px solid #f7d6b5'; 
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="block";
}

function dark (obj, layr) {
	mytd = MM_findObj(obj);
	mytd.style.backgroundColor='#f79b52';
	mytd.style.borderBottom='1px solid #de2219'; 
	mylayer = MM_findObj("expl"+layr);
	mylayer.style.display="none";
}


function show_facility (hostel, facility, total){
	for(i=0; i<total; i++) {
		layername  = "h"+hostel+"f"+i;
		mylayer = MM_findObj(layername);
		if(i== facility) {
			mylayer.style.display="block";
		} else {
			mylayer.style.display="none";
		}
	}
	return false;
}
function hide_facility (hostel, facility, total){
	mylayer = MM_findObj("h"+hostel+"f"+facility);
	mylayer.style.display="none";
	mylayer = MM_findObj("h"+hostel+"f0");
	mylayer.style.display="block";
	return false;
}

function showLayer(layer) {
	mylayer = MM_findObj(layer);
	mylayer.style.display="block";
}
function hideLayer(layer) {
	mylayer = MM_findObj(layer);
	mylayer.style.display="none";
}




function validateSearch(f, lingua) {
	if(f.country.value == "0" || f.city.value == "0") {
		switch (lingua) {
			case "fr":
			alert ("Vous n'avez pas sélectionné le pays et la ville");
			break;
			case "it":
			alert ("Non hai selezionato un paese e una città");
			break;
			case "de":
			alert ("Sie muessen vorher Land und Stadt waehlen");
			break;
			default:
			alert ("You must select a country and a city before searching");
			break;
		}
		
		return false;
	} else {
		return validateDate(f, lingua);
	}
}
function validateDate (f, lingua) {
	miogiorno = f.giorno.selectedIndex;
	miomese = f.mese.selectedIndex;
	mioanno = f.anno.selectedIndex;
	mienotti = f.notti.selectedIndex;
	miecurr = f.currency.selectedIndex;
	giornocheck = parseInt(f.giorno.options[f.giorno.selectedIndex].value) ;
	mesecheck =    parseInt(f.mese.options[f.mese.selectedIndex].value) - 1;
	annocheck = parseInt( f.anno.options[f.anno.selectedIndex].value) ;
	giornimesi = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	leapyear = 2008;
	error = false;
	if(mesecheck == 2 && annocheck == leapyear) {
		if(giornocheck>29) {error =true;}
	} else {
		if(giornocheck>giornimesi[mesecheck]) {error = true;}
	}
	if(error == false) {
		date = new Date(); 
		annoadesso = date.getFullYear();
		if(annoadesso > annocheck) {
			error = true;
		} else if (annoadesso == annocheck) {
			meseadesso = date.getMonth();
			giornoadesso = date.getDate();
			if (mesecheck < meseadesso) {
				error = true;
			} else if((mesecheck == meseadesso) && (giornocheck< (giornoadesso + 1))) {
				error = true;
			}
		}
		
	}
	
	
	if(error == true) {
		switch (lingua) {
			case "fr":
			alert ("Vous avez choisi une date incorrecte");
			break;
			case "it":
			alert ("La data che hai scelto non e' valida");
			break;
			case "de":
			alert ("Das Datum ist nicht gultig");
			break;
			default:
			alert ("You have selected an invalid date");
			break;
		}
		
		return false;
	} else {
		setCalCookie(miogiorno, miomese, mioanno, mienotti, miecurr);
		return true;
	}
}
function setDataCookie(f, lingua) {
	miogiorno = f.giorno.selectedIndex;
	miomese = f.mese.selectedIndex;
	mioanno = f.anno.selectedIndex;
	mienotti = f.notti.selectedIndex;
	miecurr = f.currency.selectedIndex;
	setCalCookie(miogiorno, miomese, mioanno, mienotti, miecurr);
	return true;
}
function showhide(id) {
	var a = MM_findObj(id) ;
	if(a.style.display == "none") {
		a.style.display = "block";
	} else {
		a.style.display = "none";
	}
	return false;
}




 function addToFavorites()
 {
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName);
  }
  else
  { 
   alert("Sorry! Your browser doesn't support this function. You have to bookmark the page using the Bookmarks command in your browser's menu.");
  }
 }
