var casella = new Array ("info", "segreteria", "admin", "uispici");
var dominio = new Array ( "clorolesi.it", "clorolesi.it", "clorolesi.it", "clorolesi.it");
var nomeSquadra = "clorolesi";
var codiceFIN="LOM09326";
var sponsorList = new Array ("Cassa Rurale di Treviglio", "Dimo SRL");
var sponsorUrl = new Array ("http://www.cassaruraletreviglio.it", "http://www.dimo-srl.com");
var sponsorLogo = new Array ("cassarurale.jpg", "dimo.jpg");

// rileva se l'utente naviga da smartphone

function detectMobile() {
	var mobileAgent = new RegExp("android|blackberry|dolfin|iphone|ipod|jasmine|nokia|opera mini|palm|samsung|symbian|symbianos|windows ce");


    var currUserAgent = navigator.userAgent.toLowerCase();
	if (currUserAgent.search(mobileAgent) != -1) {
			document.location="http://www.clorolesi.it/mobile/";
			}
    }

// scrive la data di oggi
function oggi() {
var today=new Date();
if (Date.parse (today)) {
	giorno=today.getDate();
	mese=today.getMonth()+1;
	anno=today.getYear();
	if (((anno - anno % 100) / 100) == 1) anno+=1900;
		document.write (giorno+"/"+mese+"/"+anno);
	}
else
  	document.write ("Data non disponibile");
}

// scrive la data dell'ultima modifica
function ultimaModifica() {
var today=new Date(document.lastModified);
if (Date.parse (today)) {
	giorno=today.getDate();
	mese=today.getMonth()+1;
	anno=today.getYear();
	if (((anno - anno % 100) / 100) == 1) anno+=1900;
		document.write (giorno+"/"+mese+"/"+anno);
	}
else
  	document.write ("Data non disponibile");
}

function trim (str)
{
     return str.replace (/^\s+|\s+$/g, '');
}

// maschera la posta dagli spammer
function contatta(index) {
	destinatario = casella[index]+'@'+dominio[index];
	document.write ('<a href="mailto:'+destinatario+'" title="Invia una email alla casella '+destinatario+'">');
	document.write (destinatario);
	document.write ("</a>");
	}
	
// maschera la posta dagli spammer, con soggetto predefinito
function richiedi(index,subject) {
	destinatario = casella[index]+'@'+dominio[index];
	document.write ('<a href="mailto:'+destinatario+'?Subject='+subject+'" title="Invia una email alla casella '+destinatario+'">');
	document.write (destinatario);
	document.write ("</a>");
	}
	
// controllo finestre di pop-up
function apriProgramma(nome_file,titolo)
{
	window.open(nome_file,titolo,'width=500,height=400,top=300,left=300');
}

function apriIscrizione(nome_file,titolo)
{
	window.open(nome_file,titolo,'width=520,height=320,top=300,left=300');
}

function apriFinestra(loc,ww,wh) {
    output=window.open(loc,"aux",'alwaysRaised=yes,toolbar=no,scrollbars=no,directories=no,status=no,menubar=no,width='+ww+',height='+wh);
   }


function apriFinestraScroll(loc,ww,wh) {
    output=window.open(loc,"aux",'alwaysRaised=yes,toolbar=no,scrollbars=yes,directories=no,status=no,menubar=no,width='+ww+',height='+wh);
   }

var delta = nomeSquadra+codiceFIN;

function getCookie(name)
{
    var cookie = document.cookie;
    var prefix = name + "=";
    var begin = cookie.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = cookie.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = cookie.length;
    }
    return unescape(cookie.substring(begin + prefix.length, end));
}

var zeta = "esiLOM";

function checkSession() {
 if (getCookie("auth")=="CLOTreviglio")
	location.href="modulo.html";

}

function validate(form) {
	this.window.location= attempt (form.user.value, form.pass.value);
}

// Classe Galleria - visualizzazione gallerie di immagini
// elementi di scambio:
//  - nome: nome della galleria
//  - imagelist: nome dell'array con l'elenco delle immagini
//  - namelist: nome dell'array con i titoli delle foto
//  - infolist: nome dell'array con le didascalie
// privati:
//  - nome: nome della galleria
//  - immagine: nome dell'array con l'elenco delle immagini
//  - titoli: nome dell'array con i titoli delle foto
//  - didascalia: nome dell'array con le didascalie
//  - numFoto: numero di immagini
// metodi:
//  - mostra(i): mostra l'immagine i-esima della galleria
//

function Galleria(nome,title,imagelist,infolist) {
	this.nome=nome;
	this.numFoto=imagelist.length;
	this.immagine=imagelist;
	this.titolo=title;
	this.didascalia = infolist;
	this.curr = 0;   
	this.mostra = function(i) {
		htmlCode ="<img src=\"../foto/"+this.immagine[i]+"\" alt=\""+this.didascalia[i]+"\" style=\"-moz-box-shadow: 4px 4px 8px #888;-webkit-box-shadow: 4px 4px 8px #888;box-shadow: 4px 4px 8px #888;\" />";		
		htmlCode += ("<p>"+this.didascalia[i]+"</p>");
		return (htmlCode);
		}
		
	this.preview = function(page, target) {
	  var el=document.getElementById(target);
	  var start=4*page;
 	  if (start)
 	  	htmlCode ="<a href=\"javascript:void(0)\" onclick=\""+this.nome+".preview("+(page-1)+",'"+target+"')\" title=\"Pagina precedente\"><img src=\"../images/blueup_m.png\" alt=\"Pagina precedente\"></a><br />";
	  else
		htmlCode = "<img src=\"../images/spacer_m.png\" alt=\"Stop\" /><br />";
	  for (i=start; i< Math.min((start+4), this.numFoto); i++) {
  	  	htmlCode += "<a href=\"javascript:void(0)\" onclick=\"visualizza("+this.nome+","+i+")\" title=\"Mostra foto ingrandita\">";
  		htmlCode +="<img src=\"../fototh/"+this.immagine[i]+"\" style=\"margin-bottom: 20px;\" alt=\""+this.didascalia[i]+"\" /></a><br />";
       }
      if ((start+4)<this.numFoto) 
 	  	htmlCode+="<a href=\"javascript:void(0)\" onclick=\""+this.nome+".preview("+(page+1)+",'"+target+"')\" title=\"Pagina successiva\"><img src=\"../images/bluedown_m.png\" alt=\"Pagina successiva\"></a><br />";
	  else
		htmlCode += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" /><br />";
	  el.innerHTML=htmlCode;
	}
}

// funzione di visualizzazione di elementi di una galleria
function visualizza(gall,index) { 	
	newHTML = gall.mostra(index);
	if (index)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"prevImg("+gall.nome+","+(index-1)+")\" title=\"Foto precedente\"><img src=\"../images/blueleft_m.png\" alt=\"Foto precedente\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	if (index < gall.numFoto-1)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"nextImg("+gall.nome+","+(index+1)+")\" title=\"Foto successiva\"><img src=\"../images/blueright_m.png\" alt=\"Foto successiva\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	document.getElementById("foto").innerHTML=newHTML;
	}
    

// funzione di visualizzazione di elementi di una galleria
function nextImg(gall,index) { 	
	newHTML = gall.mostra(index);
	if (index)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"prevImg("+gall.nome+","+(index-1)+")\" title=\"Foto precedente\"><img src=\"../images/blueleft_m.png\" alt=\"Foto precedente\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	if (index < gall.numFoto-1)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"nextImg("+gall.nome+","+(index+1)+")\" title=\"Foto successiva\"><img src=\"../images/blueright_m.png\" alt=\"Foto successiva\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	if ((index%4) == 0)
		gall.preview((index/4), "preview");
	document.getElementById("foto").innerHTML=newHTML;
	}
    
function prevImg(gall,index) { 	
	newHTML = gall.mostra(index);
	if (index)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"prevImg("+gall.nome+","+(index-1)+")\" title=\"Foto precedente\"><img src=\"../images/blueleft_m.png\" alt=\"Foto precedente\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	if (index < gall.numFoto-1)
		newHTML += "<a href=\"javascript:void(0)\" onclick=\"nextImg("+gall.nome+","+(index+1)+")\" title=\"Foto successiva\"><img src=\"../images/blueright_m.png\" alt=\"Foto successiva\" /></a>";
	else
		newHTML += "<img src=\"../images/spacer_m.png\" alt=\"Stop\" />";
	if ((index%4) == 3)
		gall.preview(Math.floor(index/4), "preview");
	document.getElementById("foto").innerHTML=newHTML;
	}
    

// gestione del layer semiopaco sovrapposto
function toggle(obj) {	
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		}
	else {
		el.style.display = 'inline';
		}
	}

function formIndCheck(obj) {
	var cognome=document.getElementById('cognome');
	var nome=document.getElementById('nome');
	var el=document.getElementById(obj);
	if ((trim(cognome.value)=='') || (trim(nome.value)=='')) {
		alert('Inserire sia il cognome che il nome');
		}
	else if ( el.style.display == 'none' ) {
		el.style.display = 'inline';
		}
	cancelOp();
	}

function formArchSqCheck(obj) {
	var ricerca=document.getElementById('tipoRicerca');
	var el=document.getElementById(obj);
	if (ricerca.value=="NaN") {
		alert('Nessuna ricerca selezionata');
		}
	else if (ricerca.value=="CSN") {
		sendPostRequest('showsq.php', 'indname');
		}
	else if (el.style.display == 'none') {
		el.style.display = 'inline';
		}
	cancelOp();
	}

function formHistCheck(obj) {
	var stagione=document.getElementById('stagione');
	var ricerca=document.getElementById('tipoRicerca');
	var el=document.getElementById(obj);
	if (stagione.value=="0") {
		alert('Nessuna stagione selezionata');
		exit;
		}		
	if (ricerca.value=="NaN") {
		alert('Nessuna ricerca selezionata');
		exit;
		}
	sendPostRequest('showsqstag.php', 'indname');
	}

function clearIndivReq() {
	document.indname.reset();
	if (document.getElementById('datasel')) document.getElementById('datasel').style.display='none';
	cancelOp();
	}
	
function clearAllIndivReq() {
	document.forms[0].reset();
	document.forms[1].reset();
	document.getElementById('datasel').style.display='none';
	cancelOp();
	}

function clearDetails() {
	if (document.getElementById('datasel')) document.getElementById('datasel').style.display='none';
	cancelOp();
	}

function clearAllReq() {
	document.forms[0].reset();
	if (document.forms[1]) document.forms[1].reset();
	if (document.getElementById('datasel')) document.getElementById('datasel').style.display='none';
	cancelOp();
	}

function clearSqReq(obj) {
	document.indname.reset();
	var secondForm=document.getElementById(obj);
	if (secondForm) secondForm.reset();
	if (document.getElementById('datasel')) document.getElementById('datasel').style.display='none';
	cancelOp();
	}
	
function openclose(controlid, objid) {
	var comm = document.getElementById(controlid);	
	var el = document.getElementById(objid);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		comm.innerHTML ='<img src="./images/blueright.png" alt="Right" />';
		}
	else {
		el.style.display = 'inline';
		comm.innerHTML = '<img src="./images/bluedown.png" alt="Down" />';
		}
	}

function showSponsors() {
	for (i=0; i<sponsorList.length; i++) {
		document.write("<p><a href=\""+sponsorUrl[i]+"\" title=\""+sponsorList[i]+" - Visita il sito\" target=\"_blank\">");
		document.write("<img src=\"./images/"+sponsorLogo[i]+"\" alt=\"Logo "+sponsorList[i]+"\" /></a></p>");
		}
	}
