var sepChars = "  ";		// character(s) to sepCharsarate links
var hideIndex = true;			// hide the index page name at end of links
var UToSpace = true;			// change all underscores to spaces in folder names
var DToSpace = true;			// change all dashes to spaces in folder names
var changeCaps = 0;				// 0 = no change, 1 = Initial Caps, 2 = All Upper, 3 = All Lower
var hideExt = true;				// hide extenion in file name

var i = 1;
var linkArray = new Array();
linkArray[0] = 'Home';
var linkDir = new Array();
linkDir[0] = 'index.html';

// build breadcrumb links...
function briciole() {
  var currentPage = '';

  if (linkArray.length >= 0) {

    var links = new Array(); 
    for (var n=0; n<linkArray.length; n++) {
       var onclick = '';
       if(n==0) onclick = "document.location.reload();";
       else onclick = "cancellaBriciole("+n+");caricaContenuto('"+linkDir[n]+"','"+linkArray[n]+"')";

		var thisText = bcParseText(linkArray[n], UToSpace, DToSpace, changeCaps);
		//links[links.length] = '<a href="'+baseDir+'">'+thisText+'</a>';
		links[links.length] = '<li><a href="#" onclick="'+onclick+'">'+thisText+'</a></li>';
		}

	if (currentPage != '') links[links.length] = bcParseText(currentPage, UToSpace, DToSpace, changeCaps);
	//html = '<div class="mp_backlinks">'+links.join(sepChars)+'<\/div>';
	html = links.join(sepChars);
	}
        document.getElementById('filo-arianna').innerHTML = html;

}

// parse string through text filters
function bcParseText(thisText, UToSpace, DToSpace, changeCaps) {
if (typeof thisText != "undefined" && thisText) {
	if (DToSpace) thisText = bcReplaceChar('-', ' ', thisText);
	if (UToSpace) thisText = bcReplaceChar('_', ' ', thisText);
	if (changeCaps) thisText = bcFixCaps(thisText, changeCaps);
	} else thisText = '';
return thisText;
}
// find and replace single character in string...
function bcReplaceChar(oldChar, newChar, thisString) {
var newString = '';
for (var n=0; n<thisString.length; n++) {
	newString += (thisString.charAt(n) == oldChar) ? newChar : thisString.charAt(n);
	}
return newString;
}
// determine changes in capitalization...
function bcFixCaps(thisString, changeCaps) {
if (changeCaps == 1) thisString = bcUCWords(thisString);
	else if (changeCaps == 2) thisString = thisString.toUpperCase();
	else if (changeCaps == 3) thisString = thisString.toLowerCase();
return thisString;
}

function aggiungiBriciola(valore, file) {
 if(linkArray[i-1] != valore)
 {
   linkArray[i] = valore;
   linkDir[i] = file; 
   i++;
   briciole(); 
 }
}

function cancellaBriciole(da) {
 i=da;
 var linkArrayTmp = new Array();
 var linkDirTmp = new Array();

 for (var n=0; n<da; n++) {
  linkArrayTmp[n] = linkArray[n];
  linkDirTmp[n] = linkDir[n]; 
 }

  linkArray = linkArrayTmp;
  linkDir = linkDirTmp; 
}

function azzeraBriciole() {
  linkArray = new Array();
  linkArray[0] = 'Home';
  linkDir = new Array();
  linkDir[0] = 'Home';
  i=1;
}


function getXhttp() {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
  return req;
}

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('POST', url, false);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    req.send('lingua=ciao');
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
  return req;
}

function caricaSottomenu(file) {
	clientSideInclude('sottomenu', file);
}

function caricaContenuto(file, valore) { 
alert('cosa carico?');
        aggiungiBriciola(valore, file);	
}

function caricaContenuto(file, valore) { 
	clientSideInclude('contenuto', file);
	var titolo = document.getElementById("titolo-pagina");
	titolo.innerHTML = valore;
        aggiungiBriciola(valore, file);	
}


// Selezione foto - cambio foto grande da visualizzare e classe
function sostituisciImmagine(id, file, verticale) {
 var hv = '-h';
 if(eval(verticale))
 {  
    hv = '-v';
 }
 var element = document.getElementById(id); 
 element.innerHTML = '<img class="foto-grande'+hv+'" src="img/'+file+'"/>';
}

// Selezione voce menu - cambio classe elemento
var Lst;

function chgClass(obj)
{
 if (obj==null) obj = document.getElementById('home');
 if (Lst) Lst.className='';
 obj.className='selected';
 Lst=obj;
}

/* INIZIO: FUNZIONE --BOOKMARK-- */
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar);
window.sidebar.addPanel(title, url, "");
}
/* FINE: FUNZIONE --BOOKMARK-- */

/* INIZIO: FUNZIONE --DATETIMEMSG-- */
function aggiorna() {

var mesi = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
var nomeGiorno = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');

Data = new Date()
Giorno = Data.getDate()
Mese = Data.getMonth()
Anno = Data.getFullYear()
Ore = Data.getHours()
Minuti = Data.getMinutes()
Secondi = Data.getSeconds()

if ((Ore > 6) && (Ore < 13)) Saluto = "Buon giorno"

if ((Ore > 12) && (Ore < 18)) Saluto = "Buon pomeriggio"

if ((Ore > 17) && (Ore < 7)) Saluto = "Buona sera"

// if (Ore > 21) Saluto = "Buona notte"
// 
// if (Ore < 7) Saluto = "Buona notte"

Saluto += ", benvenuti sul sito del 'Liceo Valdese di Torre Pellice'."

if (Minuti < 10) Minuti = "0" + Minuti

if (Secondi < 10) Secondi = "0" + Secondi

messaggio = Saluto + " Sono le ore " + Ore + ":" + Minuti + "." + Secondi + " di " + nomeGiorno[Data.getDay()] + ", " + Giorno + " " + mesi[Mese] + " " + Anno + "."

if(!document.layers){
  aggsec = setTimeout("aggiorna();",1000);}

if (document.getElementById){
    document.getElementById('clock').innerHTML=messaggio;}

else if (document.all){
    document.all.clock.innerHTML=messaggio;}

else if(document.layers){
    document.write(messaggio);}
}
aggiorna();
/* FINE: FUNZIONE --DATETIMEMSG-- */

function addParameter(url, param)
{
 var xml = getXhttp( );
    if ( !xml )
       alert("Errore durante l'invio del form");
 
    xml.open('POST', url, false);
    xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   
    xml.send(param);

    var element = document.getElementById('contenuto');
   element.innerHTML = xml.responseText;
}

function addLingue()
{
 var lingua = document.getElementById('corso').value; 
 var livello = document.getElementById('livello').value;

 addParameter('html/corsilingue/modulo.php', 'lingua='+lingua+'&livello='+livello);
}

function addAnagrafica()
{
 var corso = document.getElementById('corso').value; 
 var livello = document.getElementById('livello').value; 
 var nome = document.getElementById('nome').value; 
 var cognome = document.getElementById('cognome').value;
 var data = document.getElementById('data_di_nascita').value;
 var luogo = document.getElementById('luogo_di_nascita').value;
 var via = document.getElementById('via').value;
 var cap = document.getElementById('cap').value;
 var citta = document.getElementById('citta').value;
 var stato = document.getElementById('stato').value;
 var prefix = document.getElementById('prefisso_nazionale').value;
 var tel = document.getElementById('telefono').value;
 var mail = document.getElementById('e-mail').value;
 var fax = document.getElementById('fax').value;

 if(nome=='')
 {
   alert("Il campo Nome e' obbligatorio");
   return;
}

 if(cognome=='')
 {
   alert("Il campo Cognome e' obbligatorio");
   return;
 }
 
 if(via=='')
 {
   alert("Il campo Indirizzo e' obbligatorio");
   return;
 }
 
 if(citta=='')
 {
   alert("Il campo Citta' e' obbligatorio");
   return;
 }

 if(tel=='')
 {
   alert("Il campo Telefono e' obbligatorio");
   return;
 }

 if(mail=='')
 {
   alert("Il campo e-mail e' obbligatorio");
   return;
 }

 if(isNaN(tel))
 {
    alert("il telefono deve essere numerico")
    return;
 }

 if(isNaN(cap))
 {
    alert("il cap deve essere numerico")
    return;
 }

 if(isNaN(fax))
 {
    alert("il fax deve essere numerico")
    return;
 }

 if(isNaN(prefix))
 {
    alert("il prefisso internazionale deve essere numerico")
    return;
}

 var par = 'nome='+nome+'&cognome='+cognome+'&data_di_nascita='+data+'&luogo_di_nascita='+luogo+'&via='+via+'&cap='+cap+'&citta='+citta+'&stato='+stato+'&prefisso_nazionale='+prefix+'&telefono='+tel+'&e-mail='+mail+'&fax='+fax+'&corso='+corso+'&livello='+livello;

 addParameter('html/corsilingue/conferma.php', par);
}

function addSpazi()
{
 var spazio = document.getElementById('spazio').value; 
 var data = document.getElementById('data').value;
 var dalle = document.getElementById('dalle').value;
 var alle = document.getElementById('alle').value;

 if(data=='')
 {
   alert("Il campo Data e' obbligatorio");
   return;
 }

 addParameter('html/spazisportivi/modulo.php', 'spazio='+spazio+'&data='+data+'&dalle='+dalle+'&alle='+alle);
}

function addAnagraficaSpazi()
{

 var spazio = document.getElementById('spazio').value; 
 var data = document.getElementById('data').value;
 var dalle = document.getElementById('dalle').value;
 var alle = document.getElementById('alle').value;

 var nome = document.getElementById('nome').value; 
 var cognome = document.getElementById('cognome').value;
 var via = document.getElementById('via').value;
 var cap = document.getElementById('cap').value;
 var citta = document.getElementById('citta').value;
 var telefono = document.getElementById('telefono').value;
 var mail = document.getElementById('e-mail').value;

 if(nome=='')
 {
   alert("Il campo Nome e' obbligatorio");
   return;
 }

 if(cognome=='')
 {
   alert("Il campo Cognome e' obbligatorio");
   return;
 }
 
 if(via=='')
 {
   alert("Il campo Indirizzo e' obbligatorio");
   return;
 }
 
 if(citta=='')
 {
   alert("Il campo Citta' e' obbligatorio");
   return;
 }

 if(telefono=='')
 {
   alert("Il campo Telefono e' obbligatorio");
   return;
 }

 if(mail=='')
 {
   alert("Il campo e-mail e' obbligatorio");
   return;
 }

 if(isNaN(telefono))
 {
    alert("il telefono deve essere numerico")
    return;
 }

 if(isNaN(cap))
 {
    alert("il cap deve essere numerico")
    return;
 }

 var par = 'spazio='+spazio+'&data='+data+'&dalle='+dalle+'&alle='+alle+'&nome='+nome+'&cognome='+cognome+'&data='+data+'&via='+via+'&cap='+cap+'&citta='+citta+'&telefono='+telefono+'&e-mail='+mail;

 addParameter('html/spazisportivi/conferma.php', par);
}

			function blink(delay){ 
			   var el = document.getElementById('blink');
			   el.style.visibility = el.style.visibility =='hidden' ? 'visible' : 'hidden';
			   setTimeout('blink(' + delay + ')', delay);
			}


