// JavaScript Document

//--- Riconoscimento lingua ----
lingue = new Array('it','en','de','fr','es','hr')
lingua = leggiVariabile('lang');
if (lingua == 0) {
	var indirizzo = window.location.toString();
	var posizione = indirizzo.indexOf(".htm");
	var lingua=indirizzo.substring(posizione-2, posizione);}
var a=0;
for (i=0; i<lingue.length; i++) {
	if (lingua==lingue[i]) {a++}
}
if (a==0) {lingua='it'}
//------------------------------
function leggiVariabile(variabile) {
	var indirizzo = window.location.toString()+'&'; 
	var posizione_nome = indirizzo.indexOf(variabile + '='); 
	if (posizione_nome==-1) {
		variabile=0; }
	else {
		var sottostringa = indirizzo.substring(posizione_nome);
		var inizio=sottostringa.indexOf('='); 
		var fine=sottostringa.indexOf('&'); 
		var variabile=sottostringa.substring(inizio + 1, fine);}
	return variabile;
}

function calcolagiorni() {
	var datain=document.Modulo.sd.value;
	var dataout=document.Modulo.ed.value;
	anno1=datain.substring(6,10)
	mese1=datain.substring(3,5)
	giorno1=datain.substring(0,2)
	DATAIN = new Date(anno1, mese1-1, giorno1,23,59,59); // i mesi in js vanno da 0 a 11
	anno2=dataout.substring(6,10)
	mese2=dataout.substring(3,5)
	giorno2=dataout.substring(0,2)
	DATAOUT = new Date(anno2, mese2-1, giorno2);
	one_day = 1000 * 60 * 60 * 24 ;     // in millisecondi
	TODAY = new Date();
	DiffGiorni = Math.ceil((DATAOUT.getTime()-DATAIN.getTime())/(one_day));
	switch(lingua) {
		case "it": var text = new Array('Errore nella data','La data di arrivo è prima di Oggi !','La data di partenza è antecedente a quella di arrivo !'); break;
		default  : var text = new Array('Date error','Check in date is wrong, it is before today !','Check OUT date is before check IN date !'); break;}
	text[0] = '*** '+ text[0] +' !!! ***\n'
	/*if ( DATAIN < TODAY && DiffGiorni < 0 ) { DiffGiorni = 'Err'; alert(text[0]+text[1]+'\n'+text[2]); }
	else if ( DATAIN < TODAY ) { DiffGiorni = 'Err'; alert(text[0]+text[1]); }
	else if ( DiffGiorni < 0 ) { DiffGiorni = 'Err'; alert(text[0]+text[2]); }*/
	if ( DATAIN < TODAY && DiffGiorni < 0 ) { DiffGiorni = 'Err'; }
	else if ( DATAIN < TODAY ) { DiffGiorni = 'Err'; }
	else if ( DiffGiorni < 0 ) { DiffGiorni = 'Err'; }
	document.Modulo.notti.value=DiffGiorni;
}

function map() {
   var w = 780;
   var h = 600;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   finestra=window.open('mappa.htm?lang='+lingua,'','width=' + w + ',height=' + h + ',top=' + t + ',left=' + l +'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
   finestra.document.close();
}

function UnderConstruction() {
   var w = 360;
   var h = 320;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open("underconstruction.htm","","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l +'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
 }

 
function linguaflag_it() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'ITALIANO';} 
function linguaflag_en() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'ENGLISH';} 
function linguaflag_de() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'DEUTSCH';}  
function linguaflag_fr() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'FRANÇAIS';}
function linguaflag_es() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'ESPAÑOL';}
function linguaflag_hr() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = 'HRVATSKI';}

function DelValoreLingua() {
	 anchor = document.getElementById('ValoreLingua');
	 anchor.firstChild.data = '';}
	 
function Itinerari() {
   var w = 600;
   var h = 500;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open("/itinerari_it/it_castelli.htm","","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + 'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
 }
 
function gratisTel() {
   var w = 470;
   var h = 520;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open("/gratistel.htm","","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + 'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
}
 
function feedbackPopup () {
   var w = 400;
   var h = 420;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   window.open('/feedbackPopup.htm','','width=' + w + ',height=' + h + ',top=' + t + ',left=' + l + 'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
}


function facebook() {
   var w = 520;
   var h = 590;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   finestra=window.open('/facebook.htm','','width=' + w + ',height=' + h + ',top=' + t + ',left=' + l +'resizable=no, status=yes, menubar=no, location=no, toolbar=no, scrollbars=no');
   finestra.document.close();
}

/*function menu() {document.write('<iframe src="menu_'+lingua+'.htm" class="iframeClass" scrolling=no frameborder=0></iframe>');}*/
function menu() {document.write('<script src="js/menu.js"></script>');}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

