// JavaScript Document //
function PopUp(page,w,h,t,s,m) 
	{
	popwidth = w;
	popheight = h;
    if (!t) {t = 'no'};
	if (!s) {s = 'no'};
	if (!m) {m = 'no'};
	OpenWin = this.open(page, "prn", "toolbar=" + t + ", menubar=" + m +", location=no, scrollbars=" + s + ", resizable=no, width="+popwidth+", height="+popheight+", left=" + Math.floor((screen.width - popwidth) / 2) + ", top=" + Math.floor((screen.height - popheight) / 2));
}

function URLEncode(s)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = s;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
		} // for

	
	return encoded;
};

function URLDecode(s)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = s;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};

var aumentoDimensioneTesto = location.search.substring(location.search.indexOf("STB=")+4, (location.search.substr(location.search.indexOf("STB=")+4).indexOf(";"))+(location.search.indexOf("STB=")+4));

dimensionamentoTesto();

function writeIcoText(){
  if(aumentoDimensioneTesto!="BIG"){
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/dimensione_carattere.gif" width="20" height="15" border="0" alt="Enlarge text" name="icoTextResize"></a>');
  }
  else{
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/dimensione_carattere_2.gif" width="20" height="15" border="0" alt="Reduce text" name="icoTextResize"></a>');
  }
}

function manualTextResize(){
	  if(document.all){	  
				if(aumentoDimensioneTesto!="BIG"){
					  aumentoDimensioneTesto = 'BIG';	  
					  styleFile.href="/css/stile_franceschini_grande.css";
					  document.images['icoTextResize'].src = "/immagini/dimensione_carattere_2.gif"
					  document.images['icoTextResize'].alt = "Riduci il testo";
				}
				else{
					  aumentoDimensioneTesto = '';
					  styleFile.href="/css/stile_franceschini.css";
					  document.images['icoTextResize'].src = "/immagini/dimensione_carattere.gif";
					  document.images['icoTextResize'].alt = "Ingrandisci il testo";	  
				}	
	  } else {
					 if(aumentoDimensioneTesto!="BIG"){
						  if (location.href.indexOf("?") <= 0) {
								location.href = location.href + "?STB=BIG;";
						  } else {
								location.href = location.href + "&STB=BIG;";
						  }
					}else{
							location.href = location.href.substr(0, location.href.indexOf("STB=") - 1);
					}
	  }	
};

function dimensionamentoTesto(){
  if(aumentoDimensioneTesto=="BIG"){
		if(document.all){
		  document.write('<link id="styleFile" rel="stylesheet" href="/css/stile_franceschini_grande.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/stile_franceschini_grande.css">');
		}
  }
  else{
		if(document.all){
		  document.write('<link id="styleFile" rel="stylesheet" href="/css/stile_franceschini.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/stile_franceschini.css">');
		}
  }
};

function  Verifica_checkbox_selezionati(theForm) {
var i=0;
var vero=false;

while (i <=7){
	if (theForm.elements[i].checked == true) {
	vero=true;
	}
++i;
}

if (vero == false) {
	alert("Attenzione!\nE' necessario selezionare almeno un criterio di ricerca");
	return false;

} else if (theForm.testo_ricerca.value == "") {
	alert("Attenzione!\nE' necessario digitare almeno una parola da cercare");
	return false;

} else {

var pat = /^[0-9|\s]*$/;

var da_giorno = theForm.da_giorno.value ;
var da_mese = theForm.da_mese.value ;
var da_anno = theForm.da_anno.value ;
var data = true;

if (da_giorno > 28) {
    if (da_giorno > 30 && da_mese != 2) {
 	  if (da_mese == 4 || da_mese == 6 || da_mese == 9 || da_mese == 11) {
	   	alert("Attenzione: il mese selezionato ha 30 giorni.");
   		theForm.da_giorno.focus();
		return(false);
	  }
	} else {
	    if (da_mese == 2) {
		  if (((da_anno % 4 != 0 || da_anno == 1900) && da_giorno == 29) || (da_giorno >= 30)) {
		   	alert("Attenzione: Il mese di febbraio dell'anno selezionato ha 28 giorni.");
		   	theForm.da_giorno.focus();
			return(false);
		  }
		}
	}
}

if ((da_giorno > 31) || (da_giorno == 0)) {
   	alert("Attenzione: il giorno da cui far partire la ricerca non e' corretto.");
   	theForm.da_giorno.focus();
	return(false);
}

if ((da_mese > 12) || (da_mese == 0)) {
   	alert("Attenzione: il mese da cui far partire la ricerca non e' corretto.");
   	theForm.da_mese.focus();
	return(false);
}

 if(!pat.test(da_giorno) || da_giorno =="") {
	alert("Il giorno da cui far partire la ricerca non e' valido o non e' stato inserito.\rIl formato deve essere gg.\nAd esempio 09");
	theForm.da_giorno.focus();
	return false;
}	  

 if(!pat.test(da_mese) || da_mese =="") {
	alert("Il mese da cui far partire la ricerca non e' valido o non e' stato inserito.\rIl formato deve essere mm.\nAd esempio 01");
	theForm.da_mese.focus();
	return false;
}	

 if(!pat.test(da_anno) || da_anno =="") {
	alert("L'anno da cui far partire la ricerca non e' valido o non e' stato inserito.\rIl formato deve essere aaaa.\nAd esempio 1970");
	theForm.da_anno.focus();
	return false;
}	

var a_giorno = theForm.a_giorno.value ;
var a_mese = theForm.a_mese.value ;
var a_anno = theForm.a_anno.value ;
var data = true;

if (a_giorno > 28) {
    if (a_giorno > 30 && a_mese != 2) {
 	  if (a_mese == 4 || a_mese == 6 || a_mese == 9 || a_mese == 11) {
	   	alert("Attenzione: il mese selezionato ha 30 giorni.");
   		theForm.a_giorno.focus();
		return(false);
	  }
	} else {
	    if (a_mese == 2) {
		  if (((a_anno % 4 != 0 || a_anno == 1900) && a_giorno == 29) || (a_giorno >= 30)) {
		   	alert("Attenzione: Il mese di febbraio dell'anno selezionato ha 28 giorni.");
		   	theForm.a_giorno.focus();
			return(false);
		  }
		}
	}
}

if ((a_giorno > 31) || (a_giorno == 0)) {
   	alert("Attenzione: il giorno di nascita inserito non e' corretto.");
   	theForm.a_giorno.focus();
	return(false);
}

if ((a_mese > 12) || (a_mese == 0)) {
   	alert("Attenzione: il mese di nascita inserito non e' corretto.");
   	theForm.a_mese.focus();
	return(false);
}

 if(!pat.test(a_giorno) || a_giorno =="") {
	alert("Giorno di nascita non valido o non inserito.\rIl formato deve essere gg.\nAd esempio 09");
	theForm.a_giorno.focus();
	return false;
}	  

 if(!pat.test(a_mese) || a_mese =="") {
	alert("Mese di nascita non valido o non inserito.\rIl formato deve essere mm.\nAd esempio 01");
	theForm.a_mese.focus();
	return false;
}	

 if(!pat.test(a_anno) || a_anno =="") {
	alert("Anno di nascita non valido o non inserito.\rIl formato deve essere aaaa.\nAd esempio 1970");
	theForm.a_anno.focus();
	return false;
}	

}
};

function controllo_ricerca(theForm){
	if (theForm.testo_ricerca.value == "") {
    	alert("E' necessario inserire il testo da ricercare.\nGrazie.");
    	theForm.testo_ricerca.focus();
    	return (false);
		}
}

function controllo_blog(theForm){
	if (theForm.titolo.value == "") {
    	alert("E' necessario inserire il titolo del commento.\nGrazie.");
    	theForm.titolo.focus();
    	return (false);
		}
	if (theForm.argomento_soggetto.value == "") {
    	alert("E' necessario inserire il nome dell'autore del commento.\nGrazie.");
    	theForm.argomento_soggetto.focus();
    	return (false);
		}
	if (theForm.commento.value == "") {
    	alert("E' necessario inserire il testo del commento.\nGrazie.");
    	theForm.commento.focus();
    	return (false);
		}
	if (theForm.code.value == "") {
    	alert("Per favore inserire il codice di sicurezza.\nGrazie.");
    	theForm.code.focus();
    	return (false);
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ControlloInvio(theForm) {
	if (theForm.nome.value == "") {
    	alert("Per favore inserire il proprio nome, grazie.");
    	theForm.nome.focus();
    	return (false);
	}
	if (theForm.cognome.value == "") {
    	alert("Per favore inserire il proprio cognome, grazie.");
    	theForm.cognome.focus();
    	return (false);
	}
	if (theForm.email.value == "") {
    	alert("Per favore inserire il proprio indirizzo Email, grazie.");
    	theForm.email.focus();
    	return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo.\nGrazie.");
		theForm.email.focus();
		return (false);
	}
	if (theForm.cap.value == "") {
    	alert("Per favore inserire il proprio cap, grazie.");
    	theForm.cap.focus();
    	return (false);
	}
	if (theForm.testo.value == "") {
    	alert("Per favore inserire il testo del messaggio, grazie.");
    	theForm.testo.focus();
    	return (false);
	}
}