/****************************************************************************/
//NOME : aprichiudi()
//DESCRIZIONE : VISUALIZZA O NASCONDE UN ELEMENTO IN BASE AL SUO STATO ATTUALE
//INGRESSO : L'ELEMENTO HTML FA VISUALIZZARE O NASCONDERE
//RITORNA : OUTPUT A VIDEO
/****************************************************************************/
x=0;
w=0;
function ChiudiMenu()
{
	if (w==0)	{w=Math.floor(document.getElementById('menu').width); y=-w;}
	x=x-10;
	if (x< -w-10)	{x=0; return;}
	document.getElementById('menu').style.position='absolute';
	document.getElementById('menu').style.left=x + 'px';
	setTimeout("ChiudiMenu()", 100);		
}

function ApriMenu()
{
	if (w==0)	{w=Math.floor(document.getElementById('menu').width); y=-w;}
	y=y+10;
	if (y>10)	{y=-w; return;}
	document.getElementById('menu').style.position='absolute';
	document.getElementById('menu').style.left=y + 'px';		
	setTimeout("ApriMenu()", 100);		
}


/****************************************************************************/
//NOME : aprichiudi()
//DESCRIZIONE : VISUALIZZA O NASCONDE UN ELEMENTO IN BASE AL SUO STATO ATTUALE
//INGRESSO : L'ELEMENTO HTML FA VISUALIZZARE O NASCONDERE
//RITORNA : OUTPUT A VIDEO
/****************************************************************************/
function aprichiudi(elemento)
{
	//SE L'ELEMENTO è NASCOSTO VIENE MOSTRATO ALTRIMENTI VIENE NASCOSTO
	if (document.getElementById(elemento).className=="visible") document.getElementById(elemento).className='invisible';
	else document.getElementById(elemento).className='visible';
}

/****************************************************************************/
//NOME : scriviintag()
//DESCRIZIONE : SCRIVE IN UN DETERMINATO ELEMENTO HTML (solitamente DIV)
//				DEL TESTO RICEVUTO IN INFRESSO
//INGRESSO : L'ELEMENTO HTML SU CUI SCRIVERE ED IL TESTO DA SCRIVERE
//RITORNA : OUTPUT A VIDEO
/****************************************************************************/
function scriviintag(elemento,testo)
{
	//STAMPA DEL TESTO NEL TAG HTML PASSATO
	document.getElementById(elemento).innerHTML=testo;
}


/****************************************************************************/
//NOME : generatepass()
//DESCRIZIONE : CREA UNA PWD ALFANUMERICA DI N CARATTERI
//INGRESSO : IL NUMERO DI CARATTERI DI CUI DEVE ESSERE COMPOSTA LA PWD
//RITORNA : LA PWD GENERATA	
/****************************************************************************/
function generatepass(plength)
{
	//INIZIALIZZO LA VARIABILE PER LA PWD
	temp = '';
	
	//VARIABILE CONTENENTE IL SET DI CARATTERI DI CUI PUò ESSERE COMPOSTA LA PWD
	//var keylist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZ1234567890!?&\=()[]<>#,._/*-+";
	var keylist = "ABCDEFGHJKLMNPQRSTUVWXZ123456789";
	
	//PRENDO CASUALMENTE UN CARATTERE DALLA VARIABILE SOPRA PER IL NUMERO DI CARATTERI DI CUI DEVE ESSERE COMPOSTA LA PWD
	for (i=0; i<plength; i++)		temp += keylist.charAt(Math.floor(Math.random()*keylist.length));
	
	//RITORNO LA PWD CREATA
	return temp;
}
	
	
/****************************************************************************/
//NOME : getPasswordStrength()
//DESCRIZIONE : CALCOLA DELLA COMPLESSITA DI UNA PWD
//INGRESSO : LA PWD DA CONTROLLARE
//RITORNA : UN VALORE COMPRESO TRA 0 E 100 IN BASE AL LIVELLO DI COMPLESSITA	
/****************************************************************************/
function getPasswordStrength(pw)
{
    //RICAVO LA LUNGHEZZA DELLA PWD IN INGRESSO
    var pwlength=(pw.length);
    if (pwlength>5)	pwlength=5;
    
    //CONTROLLO IL NUMERO DI CIFRE
    var numnumeric = pw.replace (/[0-9]/g, "");
    var numeric=(pw.length - numnumeric.length);
    if (numeric>3)	numeric=3;

    //CONTROLLO IL NUMERO DI SINBOLI
    var symbols = pw.replace (/\W/g, "");
    var numsymbols=(pw.length - symbols.length);
    if (numsymbols>3)	numsymbols=3;

    //CONTROLLO IL NUMERO DI MAIUSCOLE
    var numupper = pw.replace (/[A-Z]/g, "");
    var upper=(pw.length - numupper.length);
    if (upper>3)	upper=3;

	//CALCOLO IL VALORE DA TORNARE IN BASE AI DATI RICAVATI
    var pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);

	//SE IL VALORE è NEGATIVO TORNO 0
    if (pwstrength < 0 )	pwstrength = 0;

	//SE IL VALORE è SUPERIORE A 100 TORNO 100
    if (pwstrength > 100)	pwstrength = 100;

	//RITORNO IL VALORE DI COMPLESSITA' DELLA PWD
    return pwstrength;
}

var DYNIFS = {
    // Storage for known IFrames.
    iframes: {},
    // Here we save any previously installed onresize handler.
    oldresize: null,
    // Flag that tell us if we have already installed our onresize handler.
    ready: false,
    // The document dimensions last time onresize was executed.
    dim: [-1,-1],
    // Timer ID used to defer the actual resize action.
    timerID: 0,
    // Obtain the dimensions (width,height) of the given document.
    getDim: function(d) {
        var w=200, h=200, scr_h, off_h;
        if( d.height ) { return [d.width,d.height]; }
        with( d.body ) {
            if( scrollHeight ) { h=scr_h=scrollHeight; w=scrollWidth; }
            if( offsetHeight ) { h=off_h=offsetHeight; w=offsetWidth; }
            if( scr_h && off_h ) h=Math.max(scr_h, off_h);
        }
        return [w,h];
    },
    // This is our window.onresize handler.
    onresize: function() {
        // Invoke any previously installed onresize handler.
        if( typeof this.oldresize == 'function' ) { this.oldresize(); }
        // Check if the document dimensions really changed.
        var dim = this.getDim(document);
        if( this.dim[0] == dim[0] && this.dim[1] == dim[1] ) return;
        // Defer the resize action to prevent endless loop in quirksmode.
        if( this.timerID ) return;
        this.timerID = setTimeout('DYNIFS.deferred_resize();', 10);
    },
    // This is where the actual IFrame resize is invoked.
    deferred_resize: function() {
        // Walk the list of known IFrames to see if they need to be resized.
        for( var id in this.iframes ) this.resize(id);
        // Store resulting document dimensions.
        this.dim = this.getDim(document);
        // Clear the timer flag.
        this.timerID = 0;
    },
    // This is invoked when the IFrame is loaded or when the main window is resized.
    resize: function(id) {
        // Browser compatibility check.
        if( !window.frames || !window.frames[id] || !document.getElementById || !document.body )
            return;
        // Get references to the IFrame window and layer.
        var iframe = window.frames[id];
        var div = document.getElementById(id);
        if( !div ) return;
        // Save the IFrame id for later use in our onresize handler.
        if( !this.iframes[id] ) {
            this.iframes[id] = true;
        }
        // Should we inject our onresize event handler?
        if( !this.ready ) {
            this.ready = true;
            this.oldresize = window.onresize;
            window.onresize = new Function('DYNIFS.onresize();');
        }
        // This appears to be necessary in MSIE to compute the height
        // when the IFrame'd document is in quirksmode.
        // OTOH, it doesn't seem to break anything in standards mode, so...
        if( document.all ) div.style.height = '0px';
        // Resize the IFrame container.
        var dim = this.getDim(iframe.document);
        div.style.height = (dim[1]+30) + 'px';
    }
};

//CALCOLO DELLA PASQUA
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;
 }
 if (mese<10) mese="0"+mese;
 if (giorno<10) giorno="0"+giorno;
  return(Y+"-"+mese+"-"+giorno);
}

function pasquetta(anno)
{
  var giornopasqua=pasqua(anno);
  
  var appo=giornopasqua.split("-");
  var pasquetta= new Date(appo[0],eval(appo[1])-1,eval(appo[2])+1);
  appo=pasquetta.getFullYear()+"-";
  if (eval(pasquetta.getMonth()+1)<10) appo+="0";
  appo+=eval(pasquetta.getMonth())+1+"-";
  if (eval(pasquetta.getDate())<10) appo+="0";
  appo+=pasquetta.getDate();
  return (appo)

}

function setCookie(sNome, sValore, iGiorni) {
  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
    (dtOggi.getTime() + 24 * iGiorni * 3600000)
  document.cookie = sNome + "=" + escape(sValore) +
    ";path=/; expires=" + dtExpires.toGMTString();
}

// restituisce il valore del cookie sNome
function getCookie(sNome) {
  // genera un array di coppie "Nome = Valore"
  // NOTA: i cookies sono separati da ';'
  var asCookies = document.cookie.split("; ");
  // ciclo su tutti i cookies
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
  {
    // leggo singolo cookie "Nome = Valore"
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    }
  }

  // SE non esiste il cookie richiesto
  return("");
}

// rimuove un cookie
function delCookie(sNome) {
  setCookie(sNome, "");
}

function mostrasoluzioni(idstruttura,maxsoluzioni)
{
	for (var x=1;x<maxsoluzioni;x++)
	{
		if (document.getElementById("sol-"+idstruttura+"-"+x).style.display!='')
		document.getElementById("sol-"+idstruttura+"-"+x).style.display='';
		else document.getElementById("sol-"+idstruttura+"-"+x).style.display='none';
	}
}


function settacookiecarrello(idcamera,datainizio,datafine,checkid)
{

	var i=getCookie("numprenotazioni");
	if (i=="")	i=0;
	for (x=0;x<i;x++)
	{
		setCookie("dati["+x+"].idcamera","",-1);
	        setCookie("dati["+x+"].datainizio","",-1);
	        setCookie("dati["+x+"].datafine","",-1);
	        setCookie("dati["+x+"].checkid","",-1);
	}
	
	var appo=datainizio.split(" ");
	datainizio=appo[0];
	var appo=datafine.split(" ");
	datafine=appo[0];

	var appodatainizio=datainizio.split("-");

	var appodatainizio1 = new Date(appodatainizio[0],appodatainizio[1]-1,appodatainizio[2]);

	var appodatafine=datafine.split("-");
	var appodatafine1 = new Date(appodatafine[0],appodatafine[1]-1,appodatafine[2]);
	
	setCookie("dati[0].idcamera", idcamera, 1);
	setCookie("dati[0].datainizio", appodatainizio1, 1);
	setCookie("dati[0].datafine", appodatafine1, 1);
	setCookie("dati[0].checkid", checkid, 1);
	
	setCookie("numprenotazioni", "1", 1);
}

function svuotacookiecarrello()
{
	var i=getCookie("numprenotazioni");
	if (i=="")	i=0;
	for (x=0;x<i;x++)
	{
		setCookie("dati["+x+"].idcamera","",-1);
	        setCookie("dati["+x+"].datainizio","",-1);
	        setCookie("dati["+x+"].datafine","",-1);
	        setCookie("dati["+x+"].checkid","",-1);
	}
	
	setCookie("numprenotazioni","",-1);
}

