var isIEBrowser		= document.all ? 1 : 0;
var isNS6Browser 	= ( ! document.all && document.getElementById) ? 1 : 0;

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) {
		with (navigator) {
			if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
				document.MM_pgW=innerWidth; 
				document.MM_pgH=innerHeight; 
				onresize=MM_reloadPage; 
			}
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}
MM_reloadPage(true);


/* ******************************************
   FUNZIONE CHE SOSTITUISCE TUTTE LE OCCORRENZE DI UNA STRINGA CON UN'ALTRA.
 
   ESEMPIO: replace( "Java will be smart", "will be", "is") ------> "Java is smart"
 
   input LA STRINGA INIZIALE
   src LA STRINGA DA CERCARE
   rpl LA STRINGA DA SOSTITUIRE
   ****************************************** */
   
function replaceAll( input, src, rpl) {
	
	var toBeReturned = "";
	var pos2 = 0;
	var pos = 0;
	var lens = src.length;
	var len = input.length;

	do {
		pos2 = input.indexOf( src, pos);
		if ( pos2 == -1) {
			toBeReturned += input.substring( pos, len);
			return toBeReturned;
		}
		toBeReturned += input.substring( pos, pos2);
		toBeReturned += rpl;
		pos = pos2 + lens;
	} while ( pos < len);

	return toBeReturned;
}

/* **************************************************************************
   Funzione per la restituzione dell'insieme degli elementi di un
   dato tipo ( ed eventualmente con il nome iniziante con una data stringa)
   contenuti in un un form.
   ************************************************************************** */

function getFormElements( formControl, controlType, namePrefix){

	var elementsArray = new Array( );

	var tmpString;
    var foundElements = -1;
	for( ife = 0; ife < formControl.elements.length; ife++){

		tmpString = formControl.elements[ ife].name;
    	if( formControl.elements[ ife].type.toUpperCase( ) == controlType.toUpperCase( )){

    		if( namePrefix != null){
    			if( tmpString.substring( 0, Math.min( tmpString.length, namePrefix.length)) == namePrefix){

    				elementsArray[++foundElements] = formControl.elements[ ife];
    			}
    		}
    		else{
    			elementsArray[++foundElements] = formControl.elements[ ife];
    		}
    	}
	}

	return elementsArray;
}

/* ******************************************
   FUNZIONE CHE RESTITUISCE UNA STRINGA SENZA GLI SPAZI A DESTRA E SINISTRA.
   LA STRINGA ORIGINARIA NON VIENE MODIFICATA.
   ****************************************** */
   
   	function trim( stringa){
   	
   		var stringaMod = stringa;
		var fatto = false;
		
		var is = 0;
		
		while( ( is < stringa.length) && ( stringa.charAt( is) == " ")){
			
			stringaMod = stringa.substring( is + 1);
			is++;
		}
		
		is = stringaMod.length - 1;
		
		while( ( is >= 0) && ( stringaMod.charAt( is) == " ")){
			
			stringaMod = stringaMod.substring( 0, is);
			is--;
		}
		
		return stringaMod;
   	}

/* ******************************************
   FUNZIONE CHE ELIMINA DAL VALORE DI UN CAMPO GLI SPAZI A DESTRA E SINISTRA.
   IL CAMPO ORIGINARIO VIENE MODIFICATO.
   ****************************************** */
   
   	function trimField( campo){
   	
   		var campoValue = campo.value;
   		
   		campoValue = trim( campoValue);
   		
   		campo.value = campoValue;
   	}

/* ******************************************
   FUNZIONE CHE TESTA SE UNA STRINGA E' VUOTA O MENO.
   ****************************************** */
   
   	function isEmptyString( stringa){
   	
   		if( stringa == ""){
   			return true;
   		}
   		else{
   			return false;
   		}
   	}

/* ******************************************
   FUNZIONE CHE TESTA SE UNA CAMPO E' VUOTO O MENO.
   SE hasToBeTrimmed E' true IL VALORE DEL CAMPO VIENE
   TESTATO SENZA GLI SPAZI A DESTRA E SINISTRA.
   ****************************************** */
   
   	function isEmptyField( campo, hasToBeTrimmed){
   	
   		var campoValue = campo.value;
   		
   		if( hasToBeTrimmed){
   			campoValue = trim( campoValue);
   		}
   		
   		return isEmptyString( campoValue)
   	}


/* **************************************************************************
   Funzione di Controllo della Data ( giusti parametri + bisestile)
   ************************************************************************** */

function ControlData( campoDaControllare, nomeCampo){

	var dataInserita = campoDaControllare.value;
	
	var ggmmaaaaArray = null;
	var gg, mm, aaaa;
	
	var formatoCorretto = true;
	
	if( dataInserita != "")
	{
		ggmmaaaaArray = dataInserita.split( "/");
			
		if( ( dataInserita.length > "gg/mm/aaaa".length)  ||
			( ggmmaaaaArray.length != 3) 	 ||
			( ggmmaaaaArray[0].length < 1) 	 ||
			( ggmmaaaaArray[0].length > 2) 	 ||
			( isNaN( ggmmaaaaArray[0])) 	 ||
			( ggmmaaaaArray[1].length < 1) 	 ||
			( ggmmaaaaArray[1].length > 2) 	 ||
			( isNaN( ggmmaaaaArray[1])) 	 ||
			( ggmmaaaaArray[2].length != 4)  ||
			( isNaN( ggmmaaaaArray[2])))
		{
			//messaggioErrore += "Utilizzare il formato gg/mm/aaaa.";
			formatoCorretto = false;
		}
		else
		{
			gg = parseInt( ggmmaaaaArray[0], 10);
			mm = parseInt( ggmmaaaaArray[1], 10);
			aaaa = parseInt( ggmmaaaaArray[2], 10);
						
			if( ( gg > 31) || ( gg < 1))
			{
				//messaggioErrore += "Il giorno deve essere compreso tra 1 e 31.";
				formatoCorretto = false;
			}
			else if( ( mm > 12) || ( mm < 1))
			{
				//messaggioErrore += "Il mese deve essere compreso tra 1 e 12.";
				formatoCorretto = false;
			}
			else if( mm == 2)
			{ 
				if( gg > 29)
				{ 
					//messaggioErrore += "Il mese di febbraio non può avere più di 29 giorni.";
					formatoCorretto = false;
				}
				else if( ( ( aaaa % 4) != 0) || ( ( ( aaaa % 100) == 0) && ( ( aaaa % 400) != 0)))
				{ 
					if( gg > 28)
				 	{ 
				 		//messaggioErrore += "L'anno " + aaaa + " non è bisestile.";
				 		formatoCorretto = false;
				 	}
				}   
			}
		 	else if( ( mm == 4) || ( mm == 6) || ( mm == 9) || ( mm == 11))
			{ 
				if( gg > 30)
			   	{
			   		//messaggioErrore += "Il mese selezionato non può avere più di 30 giorni.";
			   		formatoCorretto = false; 
			   	}
			}
		}	
		
		if( ! formatoCorretto){

			alert( "Formato della data nel campo '" + nomeCampo + "' non corretto!");

			//campoDaControllare.value = "";
			campoDaControllare.focus( );
		}
	}	
	
	return formatoCorretto
}


/* **************************************************************************
   Funzione di Controllo dei campi di testo contenenti indirizzi email
   ************************************************************************** */

function isValidEmail( who) {
	function isEmpty( who) {
		var testArr=who.split( "");
		if( testArr.length==0)
			return true;
		var toggle=0;
		for( var i=0; i<testArr.length; i++) {
			if( testArr[i]==" ") {
				toggle=1;
				break;
			}
		}
		if( toggle)
			return true;
		return false;
	}

	function isValid( who) {
		var invalidChars=new Array( "~","!","@","#","$","%","^","&","*","( ",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<"," > ","?");
		var testArr=who.split( "");
		for( var i=0; i<testArr.length; i++) {
			for( var j=0; j<invalidChars.length; j++) {
				if( testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}

	function isfl( who) {
		var invalidChars=new Array( "-","_",".");
		var testArr=who.split( "");
		which=0;
		for( var i=0; i<2; i++) {
			for( var j=0; j<invalidChars.length; j++) {
				if( testArr[which]==invalidChars[j]) {
					return false;
				}
			}
			which=testArr.length-1;
		}
		return true;
	}

	function isDomain( who) {
		var invalidChars=new Array( "-","_",".");
		var testArr=who.split( "");
		if( testArr.length<2 || testArr.length > 4) {
			return false;
		}
		for( var i=0; i<testArr.length; i++) {
			for( var j=0; j<invalidChars.length; j++) {
				if( testArr[i]==invalidChars[j]) {
					return false;
				}
			}
		}
		return true;
	}

	if( who == "")
		return true;
	else{
		var addressesArr = who.split( ";");
		var testArr = "";
		
		var toBeReturned = false;
		
		if( addressesArr.length < 1) {
			toBeReturned = false;
		}
		else{			
			for( iar = 0; iar < addressesArr.length; iar++){
				
				testArr = trim( addressesArr[iar]).split( "@");
				
				if( testArr.length <= 1 || testArr.length > 2) {
					toBeReturned = false;
				}
				else {
					if( isValid( testArr[0]) && isfl( testArr[0]) && isValid( testArr[1])) {
						
						if( ! isEmpty( testArr[testArr.length-1]) && !isEmpty( testArr[0])) {
							
							var testArr2 = testArr[testArr.length - 1].split( ".");
							if( testArr2.length >= 2) {
								
								var toggle = 1;
								
								for( var i = 0; i < testArr2.length; i++) {
									if( isEmpty( testArr2[i]) || !isfl( testArr2[i])) {
										toggle = 0;
										break;
									}
								}
								if( toggle && isDomain( testArr2[testArr2.length - 1])){
									toBeReturned = true;
								}
								else{
									toBeReturned = false;
								}
							}
							else{
								toBeReturned = false;
							}
						}
					}
				}
			}
		}	
		
		return toBeReturned;
	}
}

function ControlEmailField( campoDaControllare, nomeCampo){
	var campoInserito = campoDaControllare.value;
	var validSubset;
	var charCode = 0, lowerLimit = 0; upperLimit = 0;

	var formatoCorretto = isValidEmail( campoInserito);

	if( ! formatoCorretto){

		alert( "Indirizzo non valido nel campo" + ( ( nomeCampo != "") ? ( " '" + nomeCampo + "'") : "") + ".");

		//campoDaControllare.value = "";
		campoDaControllare.focus( );
	}

	return formatoCorretto
}

/* ******************************************
   FUNZIONE CHE APRE UNA POPUP CON BARRE DI SCORRIMENTO.
   nome E' IL NOME DELLA FINESTRA
   file E' IL PATH DEL FILE DA APRIRE
   width E' LA LARGHEZZA DELLA FINESTRA
   height E' L'ALTEZZA DELLA FINESTRA
   ****************************************** */
   
function openFullPopup( nome, file, width, height){
	
	window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=yes, status=yes, toolbar=yes, menubar=yes, location=yes");
}  
   
function openResizablePopup( nome, file, width, height){
	
	window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=yes, status=yes, toolbar=no, menubar=no, location=no");
}
   
function openPopup( nome, file, width, height){
	
	window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=no, status=yes, toolbar=no, menubar=no, location=no");
}
   
/* ******************************************
   FUNZIONE CHE CAMBIA L'IMAGINE DEL PRIMO RADIO CHECK NEL MOTORE DI RICERCA CON QUELLA DEL SECONDO.
   control1 E' IL PRIMO CONTROLLO IMG CUI CAMBIARE L'IMMAGINE
   control2 E' IL SECONDO CONTROLLO IMG CUI CAMBIARE L'IMMAGINE
   ****************************************** */   
function swapSearchRadio( control1, control2){
	
	var tempString = control1.src.toUpperCase();
	if( tempString.indexOf( "EMPTY.") != -1){
		control1.src = control2.src;
		control2.src = tempString;
	}
}

function clickMenuPrincipale( idMenu){
	var divMenuPrincipale;			
	
	for( ic = 0; ic < 3; ic++){
	
		if( isNS6Browser){
			divMenuPrincipale = document.getElementById( 'divMenuPrincipale' + ic);
		
        }
		else if( isIEBrowser){
			divMenuPrincipale = document.all[ 'divMenuPrincipale' + ic];
		//   alert(divMenuPrincipale.outerHTML)
       }
		
//alert("1 :"+divMenuPrincipale.style.visibility+"idMenu :"+idMenu+" ic: "+ic)
		if( ( divMenuPrincipale.style.visibility == "hidden") && ( idMenu == ic)){
			divMenuPrincipale.style.visibility = "visible";
		}
		else if( divMenuPrincipale.style.visibility == "visible"){
			
         divMenuPrincipale.style.visibility = "hidden";
		} 
	}	
			
//alert("2 :"+divMenuPrincipale.style.visibility)

	if( divMenuPrincipale.style.visibility == "visible"){
		var filmato = isIEBrowser ? window.document.all['flashMenuPrincipale' + idMenu] : window.document.getElementById( 'flashMenuPrincipale' + idMenu);
		
      filmato.Play();
	  
  }
}
// La funzione che non veniva letta da dotnetnuke.
function posizionaDiv( ){
	
	if( isNS6Browser){
		for( ic = 0; ic < 3; ic++){
			document.getElementById( 'divMenuPrincipale' + ic).style.left = ( ( window.innerWidth - 780) / 2) + 170 + ( 124 * ic) + "px";
			document.getElementById( 'divMenuPrincipale' + ic).style.visibility = "hidden";
		}
	}
	else if( isIEBrowser){
		for( ic = 0; ic < 3; ic++){
			document.all[ 'divMenuPrincipale' + ic].style.left = ( ( document.body.scrollWidth - 780) / 2) + 178 + ( 124 * ic) + "px";
			document.all[ 'divMenuPrincipale' + ic].style.visibility = "hidden";
		}
	}
}
//posizione menu home page
function posizionaDiv20( ){
	
  if( isNS6Browser){
		for( ic = 0; ic < 3; ic++){
			document.getElementById( 'divMenuPrincipale' + ic).style.left = ( ( window.innerWidth - 780) / 2) + 177 + ( 124 * ic) + "px";
			//document.getElementById( 'divMenuPrincipale' + ic).style.visibility = "hidden";
		}
	}
	else if( isIEBrowser){
		for( ic = 0; ic < 3; ic++){
			document.all[ 'divMenuPrincipale' + ic].style.left = ( ( document.body.scrollWidth - 780) / 2) + 178 +( 124 * ic)+ "px";
			//document.all[ 'divMenuPrincipale' + ic].style.visibility = "hidden";
            		 document.all[ 'divMenuPrincipale' + ic].style.top=document.all[ 'tablepulsante'].style.top+92;
     }
	}
	
}
//posizione menu internal page
function posizionaDiv30( ){
	if( isNS6Browser){
		for( ic = 0; ic < 3; ic++){
			document.getElementById( 'divMenuPrincipale' + ic).style.left = ( ( window.innerWidth - 780) / 2) + 177 + ( 124 * ic) + "px";
			document.getElementById( 'divMenuPrincipale' + ic).style.visibility = "hidden";
		}
	}
	else if( isIEBrowser){
		for( ic = 0; ic < 3; ic++){
			document.all[ 'divMenuPrincipale' + ic].style.left = ( ( document.body.scrollWidth - 780) / 2) + 178 +( 124 * ic)+ "px";
			document.all[ 'divMenuPrincipale' + ic].style.visibility = "hidden";
            		 document.all[ 'divMenuPrincipale' + ic].style.top=document.all[ 'tablepulsante'].style.top+76;
     }
	}
	
}

function posizionaDivInt( ){
	if( isNS6Browser){
		for( ic = 0; ic < 3; ic++){
			document.getElementById( 'divMenuPrincipale' + ic).style.left = ( ( window.innerWidth - 780) / 2) + 180 + ( 124 * ic) + "px";
			//document.getElementById( 'divMenuPrincipale' + ic).style.visibility = "hidden";
		}
	}
	else if( isIEBrowser){
		for( ic = 0; ic < 3; ic++){
			document.all[ 'divMenuPrincipale' + ic].style.left = ( ( document.body.scrollWidth - 780) / 2) + 180 +( 124 * ic)+ "px";
			//document.all[ 'divMenuPrincipale' + ic].style.visibility = "hidden";
            		 document.all[ 'divMenuPrincipale' + ic].style.top=document.all[ 'tablepulsante'].style.top+90;
     }
	}
	
}

// La funzione seguente verifica la presenza di un plugin Flash attivo sul browser.
	     
function testFlashPlugin(){

	var ShockwaveFlashInstalled = false;
	
	if( isIEBrowser) {
		try{
			var pluginObj = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash");
		
			ShockwaveFlashInstalled = ( pluginObj != null);
		}
		catch( exc){
		}
	}
	
	if( ( navigator.plugins && navigator.plugins["Shockwave Flash"]) || ( ShockwaveFlashInstalled)){ 
		
		ShockwaveFlashInstalled = true; 
	} 

	if( ! ShockwaveFlashInstalled){
		alert( "Attenzione: il browser non supporta l'esecuzione di filmati Macromedia Flash.\r\nI menu' delle pagine potrebbero non funzionare."); 
	}
}

function nascondiMenu( idMenu){
	var divMenuPrincipale;			
	
	
		if( isNS6Browser){
			divMenuPrincipale = document.getElementById( 'divMenuPrincipale' + idMenu);
		
        }
		else if( isIEBrowser){
			divMenuPrincipale = document.all[ 'divMenuPrincipale' + idMenu];
		//   alert(divMenuPrincipale.outerHTML)
       }
		 divMenuPrincipale.style.visibility = "hidden";
	

}

function clickMenuPrincipaleInt( idMenu){
	var divMenuPrincipale;			
	
	for( ic = 0; ic < 3; ic++){
	
		if( isNS6Browser){
			divMenuPrincipale = document.getElementById( 'divMenuPrincipale' + ic);
		
        }
		else if( isIEBrowser){
			divMenuPrincipale = document.all[ 'divMenuPrincipale' + ic];
		//   alert(divMenuPrincipale.outerHTML)
       }
		
//alert("1 :"+divMenuPrincipale.style.visibility+"idMenu :"+idMenu+" ic: "+ic)
		if( ( divMenuPrincipale.style.visibility == "hidden") && ( idMenu == ic)){
			divMenuPrincipale.style.visibility = "visible";
		
         }
		else if( divMenuPrincipale.style.visibility == "visible"){
			
         divMenuPrincipale.style.visibility = "hidden";
		} 
	}	
			
//alert("2 :"+divMenuPrincipale.style.visibility)
}
