// JavaScript Document //

/*++++++++++++++++++++++                        popup completo                       +++++++++++++++++++++++++++++++++++++++++++*/
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));
}

/*++++++++++++++++++++++                         url  encode                     +++++++++++++++++++++++++++++++++++++++++++*/

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;
};

/*++++++++++++++++++++++                        url decode                       +++++++++++++++++++++++++++++++++++++++++++*/

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();


/*++++++++++++++++++++++                        cambiamento dimensioni testo                      +++++++++++++++++++++++++++++++++++++++++++*/

function writeIcoText(){
  if(aumentoDimensioneTesto!="BIG"){
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/testo_grande.gif" width="25" height="25" border="0" alt="Ingrandisci il testo" name="icoTextResize"></a>');
  }
  else{
		document.write('<a href="javascript:manualTextResize()"><img src="/immagini/testo_piccolo.gif" width="25" height="25" border="0" alt="Riduci il testo" name="icoTextResize"></a>');
  }
}

function manualTextResize(){
	  if(document.all){	  
				if(aumentoDimensioneTesto!="BIG"){
					  aumentoDimensioneTesto = 'BIG';	  
					  styleFile.href="/css/governareper_grande.css";
					  document.images['icoTextResize'].src = "/immagini/testo_piccolo.gif"
					  document.images['icoTextResize'].alt = "Riduci il testo";
				}
				else{
					  aumentoDimensioneTesto = '';
					  styleFile.href="/css/governareper_normal.css";
					  document.images['icoTextResize'].src = "/immagini/testo_grande.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/governareper_grande.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/governareper_grande.css">');
		}
  }
  else{
		if(document.all){
		  document.write('<link id="styleFile" rel="stylesheet" href="/css/governareper_normal.css">');
		}
		else{
		  document.write('<link rel="stylesheet" href="/css/governareper_normal.css">');
		}
  }
}

/*++++++++++++++++++++++                        controllo form registrazione                       +++++++++++++++++++++++++++++++++++++++++++*/

function controllo_registrazione(theForm) {
	if (theForm.nome.value == "") {
    	alert("Inserire il proprio nome,grazie.");
    	theForm.nome.focus();
    	return (false);
		}
	if (theForm.cognome.value == "") {
    	alert("Inserire il proprio cognome, grazie.");
    	theForm.cognome.focus();
    	return (false);
		}
	if (theForm.indirizzo.value == "") {
    	alert("Inserire  il proprio indirizzo di residenza, grazie.");
    	theForm.indirizzo.focus();
    	return (false);
		}		
	if (theForm.citta.value == "") {
    	alert("Inserire la citta in cui vive, grazie.");
    	theForm.citta.focus();
    	return (false);
		}		
	if (theForm.cap.value == "") {
    	alert("Inserire il cap di residenza, grazie.");
    	theForm.cap.focus();
    	return (false);
		}	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo.\nGrazie.");
		theForm.email.focus();
		return (false);
		}
			if (theForm.privacy.type == 'checkbox') {
 	 	if (!theForm.privacy.checked) {
    	alert("Non è possibile proseguire senza acconsentire al trattamento dei dati personali, grazie.");
    	return (false);
		}	
  	}
 }





/*++++++++++++++++++++++                        controllo form scrivici                       +++++++++++++++++++++++++++++++++++++++++++*/

function controllo_scrivici(theForm) {
	if (theForm.nome.value == "") {
    	alert("Inserire il proprio nome,grazie.");
    	theForm.nome.focus();
    	return (false);
		}
	if (theForm.cognome.value == "") {
    	alert("Inserire il proprio cognome,grazie.");
    	theForm.cognome.focus();
    	return (false);
		}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo.\nGrazie.");
		theForm.email.focus();
		return (false);
		}	
	if (theForm.testo.value == "") {
    	alert("Inserire il contenuto del messaggio,grazie.");
    	theForm.testo.focus();
    	return (false);
		}	
		if (theForm.privacy.type == 'checkbox') {
 	 	if (!theForm.privacy.checked) {
    	alert("Non è possibile proseguire senza acconsentire al trattamento dei dati personali, grazie.");
    	return (false);
		}	
  	}
 }
/*++++++++++++++++++++++                        controllo form newsletter home page                       +++++++++++++++++++++++++++++++++++++++++++*/

function controllo_newsletter(theForm) {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo.\nGrazie.");
		theForm.email.focus();
		return (false);
		}
	}

/*++++++++++++++++++++++                        controllo form commento                       +++++++++++++++++++++++++++++++++++++++++++*/

function controllo_commento(theForm){
	
if (theForm.autore.value == "") {
    	alert("Inserire il proprio nome,grazie.");
    	theForm.autore.focus();
    	return (false);
		}
	if (theForm.autore_1.value == "") {
    	alert("Inserire il proprio cognome,grazie.");
    	theForm.autore_1.focus();
    	return (false);
		}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.titolo_3.value))) {
		alert("Indirizzo E-Mail non valido, si prega di verificarlo.\nGrazie.");
		theForm.titolo_3.focus();
		return (false);
		}		
	
	if (theForm.testo_rtf.value == "") {
    	alert("Inserire il contenuto del messaggio,grazie.");
    	theForm.testo_rtf.focus();
    	return (false);
		}
	if (theForm.privacy.type == 'checkbox') {
 	 	if (!theForm.privacy.checked) {
    	alert("Non è possibile proseguire senza acconsentire al trattamento dei dati personali, grazie.");
    	return (false);
		}	
  	}	
 }

/*++++++++++++++++++++++                        controllo form voto gradimento                       +++++++++++++++++++++++++++++++++++++++++++*/
function controllo_vota(theForm){
    var i = 0;
    var ret = false;
    while ((i <= 9) && (!ret)) {
      ret = document.form1.gradimento[i].checked;
      ++i;
    }
    if (!ret) {
  	  alert('Impossibile votare senza esprimere il gradimento');
      return (false);
	}				
 }

/*++++++++++++++++++++++++++++   popup mx ++++++++++++++++++++++++++*/

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



