var isIEBrowser		= document.all ? 1 : 0;
var isNS6Browser 	= ( ! document.all && document.getElementById) ? 1 : 0;


/* ******************************************
   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){
	
	var popWin = window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=yes, status=yes, toolbar=yes, menubar=yes, location=yes");
	popWin.focus(); 
}  
   
function openResizablePopup( nome, file, width, height){
	
	var popWin = window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=yes, status=yes, toolbar=no, menubar=no, location=no");
	popWin.focus(); 
}
   
function openPopup( nome, file, width, height){
	
	var popWin = window.open( decodeURIComponent( file), replaceAll( nome, " ", ""), "height=" + height + ", width=" + width + ", scrollbars=yes, resizable=no, status=yes, toolbar=no, menubar=no, location=no");
	popWin.focus(); 
}

/* ******************************************
   FUNZIONE CHE CAMBIA LA VERSIONE LINGUISTICA DEL FILE DA
   <languagePrefix>/<nomeFile>.<ext> A <newLanguagePrefix>/<nomeFile>.<ext>.
   I prefissi possibili sono 
   it ---> italiano
   en ---> inglese
   ****************************************** */
   
function changeLanguage( newLanguagePrefix){
	var documentFileName = document.location.pathname
	documentFileName = documentFileName.substring( documentFileName.lastIndexOf( "/") + 1);
	documentFileName = documentFileName.substring( documentFileName.lastIndexOf( "\\") + 1);
	
	documentFileName = "../" + newLanguagePrefix.toLowerCase() + "/" + documentFileName;
	
	document.location.href = documentFileName;			
}


function changeLanguageOld( newLanguagePrefix){
	
	if(newLanguagePrefix.toLowerCase()=="en"){
		document.location.href="http://adsl.tnet.it/index_en.htm"
	}else{
		document.location.href="http://adsl.tnet.it"
		}
}


function verificaSubmit( formObject){
	
	
  //start 22 Aprile 2008
 //  alert('test');
  var pref=document.getElementById("Prefisso").value;
  var nume=document.getElementById("Numero").value;
 // alert(pref);
 // alert(nume);

  stringa="/it/DUE.aspx?target=http://adsl.tnet.it/it/NewCopertura.aspx?Prefisso="+pref+nume+"&Numero="+nume;
  formObject.action = stringa;
//end 22 Aprile 2008

  //commentato il 22 Aprile 2008  formObject.action = "/it/copertura.aspx";
	//alert('1');
    formObject.target = "PopupCopertura";
	var popCopertura = window.open( "/it/copertura.aspx", "PopupCopertura", "height=670, width=652, scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, location=no"); 
	//alert('2');

	//formObject.action = "javascript:window.open( '/it/copertura.aspx', 'PopupCopertura', 'height=320, width=520, scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, location=no'); ";
	//formObject.target = "PopupCopertura";
	formObject.submit();
//alert('3');
}

var ID_GROUP_TNET_SPA = 1;
var ID_GROUP_TNET_ITALIA_SRL = 2;

function scaricaContratto( lineaProdotti, lingua){

	var popWindow = null;
	
	if( ! ( ( lineaProdotti == "") || ( lingua == ""))){
		//alert("../pdf/Contratto_" + lineaProdotti + "_Tnet_" + lingua + ".pdf")
		switch ( document.PageForm.regioniSelect.value){
			case "" + ID_GROUP_TNET_SPA:{
				openResizablePopup( "Contratto" + lineaProdotti , "../pdf/Contratto_" + lineaProdotti + "_Tnet_" + lingua + ".pdf", 700, 400);
				break;
			}
			case "" + ID_GROUP_TNET_ITALIA_SRL:{
				openResizablePopup( "Contratto" + lineaProdotti , "../pdf/Contratto_" + lineaProdotti + "_TnetItalia_" + lingua + ".pdf", 700, 400);
				break;
			}
		}
	}	
	return false;
}
<!-- funzione PouUp Imagine Riassuntiva -->
		function popupXL2() {

			var idImg, srcImg,popImg
			idImg="Img_TabRiassuntiva"
			divImg="div_TabellaRiassuntiva"
			srcImg="images/"
			path="images/"
			popImg="<IMG id='Img_TabRiassuntiva' title='Clicca sull immagine per nasconderla' src='images/Tabella_Riassuntiva.gif' >"
			none="none"
			popImg="<A id='Img_TabRiassuntiva' href='javascript:void(0)' onclick=document.getElementById('div_TabellaRiassuntiva').style.display="+none+" >"+popImg+"</A>"
			document.getElementById('div_TabellaRiassuntiva').innerHTML=popImg
			//alert(popImg)
			var xlContStyle = document.getElementById('div_TabellaRiassuntiva').style
						
			xlContStyle.display='block';
			
				/*if (document.getElementById('Img_TabRiassuntiva').height > 500) {
				
					with (xlContStyle) {
					
					height='400px';
					
					width=(parseInt(document.getElementById('Img_TabRiassuntiva').width) + 20) + 'px';
					
					overflow='auto'
					
					}
	
				}*/
			
			}
		
		
<!-- funzione PouUp Imagine Riassuntiva per pagine interne-->
		function popupXL2i() {

			var idImg, srcImg,popImg
			idImg="Img_TabRiassuntiva"
			divImg="div_TabellaRiassuntiva"
			srcImg="../images/"
			path="../images/"
			popImg="<IMG id='Img_TabRiassuntiva' title='Clicca sull immagine per nasconderla' src='../images/Tabella_Riassuntiva.gif' >"
			none="none"
			popImg="<A id='Img_TabRiassuntiva' href='javascript:void(0)' onclick=document.getElementById('div_TabellaRiassuntiva').style.display="+none+" >"+popImg+"</A>"
			document.getElementById('div_TabellaRiassuntiva').innerHTML=popImg
			//alert(popImg)
			var xlContStyle = document.getElementById('div_TabellaRiassuntiva').style
						
			xlContStyle.display='block';
			
				/*if (document.getElementById('Img_TabRiassuntiva').height > 500) {
				
					with (xlContStyle) {
					
					height='400px';
					
					width=(parseInt(document.getElementById('Img_TabRiassuntiva').width) + 20) + 'px';
					
					overflow='auto'
					
					}
	
				}*/
			
			}
function richiestachi(){
	
	formObject.action = "/it/coperturachi.aspx";
	
    formObject.target = "PopupCoperturachi";
	var popCopertura = window.open( "", "PopupCoperturachi", "height=670, width=652, scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, location=no"); 
	
	//formObject.action = "javascript:window.open( '/it/copertura.aspx', 'PopupCopertura', 'height=320, width=520, scrollbars=auto, resizable=no, status=yes, toolbar=no, menubar=no, location=no'); ";
	//formObject.target = "PopupCopertura";
	formObject.submit();
}
function verificaSubmitPilota( formObject){
	
	//start 29 Aprile 2008
   //pref=document.getElementById("Prefisso").value;
   //nume=document.getElementById("Numero").value;
  pref=document.getElementById("Prefisso").value;
  nume=document.getElementById("Numero").value;
  

   //alert("prova2");   
  //alert(pref);
   //alert(nume);
   stringa="/it/DUE.aspx?target=http://adsl.tnet.it/it/NewcoperturaPilota.aspx?Prefisso="+pref+nume+"&Numero="+nume;
   
   formObject.action = stringa;
   formObject.target = "PopupCopertura";
   var popCopertura = window.open( "/it/NewcoperturaPilota.aspx", "PopupCopertura", "height=670, width=652, scrollbars=yes, resizable=yes, status=yes,  location=no"); 
    
   formObject.submit();
   //end 29 Aprile 2008



//start codice di partenza

//    formObject.action = "/it/coperturaPilota.aspx";
//    formObject.target = "PopupCoperturaPilota";
//	var popCopertura = window.open( "", "PopupCoperturaPilota", "height=760, width=652, scrollbars=yes, resizable=no, status=no, toolbar=no, menubar=no, location=no"); 
//	formObject.submit();
//end 29 codice di partenza
}