
function sostTesto(strSorgente, strTestoA, strTestoB)
{
    var strDestinazione = "";
    if (strTestoA.length > 0) {
        while ((i = strSorgente.indexOf(strTestoA)) != -1) {
            strDestinazione += strSorgente.substring(0,i) + strTestoB;
            strSorgente = strSorgente.substring(i + strTestoA.length);
        }
        strDestinazione += strSorgente;
    }
    else {
        strDestinazione = strSorgente;
    }
    return(strDestinazione);
}

function txtToHTML(strTesto)
{
   strTesto = sostTesto(strTesto, "&", "&amp;");
   strTesto = sostTesto(strTesto, "\"", "&quot;");
   strTesto = sostTesto(strTesto, "<", "&lt;");
   strTesto = sostTesto(strTesto, ">", "&gt;");
   return(strTesto);
}

function leggiSegnalibro(key, skips) {
	if (skips == null)
		skips = 0;
	var cookie_string = "" + document . cookie;
	var cookie_array = cookie_string . split ("; ");
	for (var i = 0; i < cookie_array . length; ++ i)
	{
		var single_cookie = cookie_array [i] . split ("=");
		if (single_cookie . length != 2)
			continue;
		var name  = unescape (single_cookie [0]);
		var value = unescape (single_cookie [1]);
		if (key == name && skips -- == 0)
			return value;
	}
	return null;
}

function scriviSegnalibro(name, value, path) {
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getYear () + 1);
	expiration_date = expiration_date . toGMTString ();
	var cookie_string = escape (name) + "=" + escape (value) +
		"; expires=" + expiration_date;
	if (path != null)
		cookie_string += "; path=" + path;
	document . cookie = cookie_string;
}

function aggSegnalibro() {
   var strSLUrl = location.href
   var strSLTitolo = prompt("Specifica il nome della pagina da aggiungere al tuo menu:\n", document.title);
   if (strSLTitolo != null) {
      if (strSLTitolo.length > 0) {
         var intSLCorrente = -1;
         var booSLCtrl = true;
         for (var x = 0; x < 10; ++x) {
            if (leggiSegnalibro("dpf_sl_url_" + x, null) == location.href) {
               booSLCtrl = false;
            } else {
               if (leggiSegnalibro("dpf_sl_titolo_" + x, null) == null && intSLCorrente == -1) {
                  intSLCorrente = x;
               }
            }
         }
         if (intSLCorrente != -1 && booSLCtrl) {
            scriviSegnalibro("dpf_sl_titolo_" + intSLCorrente, txtToHTML(strSLTitolo), "/");
            scriviSegnalibro("dpf_sl_url_" + intSLCorrente, strSLUrl, "/");
            alert("Segnalibro registrato. Fai click sul pulsante \"Il tuo menu\" per eventuali modifiche.");
            location.reload();
         } else if (!booSLCtrl) {
            alert("Segnalibro non registrato perché già esistente.");
         } else {
            alert("Segnalibro non registrato. Hai raggiunto il numero massimo.");
         }
      }
   } 
}

function vaiSegnalibro() {
   var optionMenu = document.forms[0].segnalibro.selectedIndex;
   var urlSegnalibro = document.forms[0].segnalibro.options[optionMenu].value;
   location.href = urlSegnalibro;
}

function apriNew(URL) {
  window.open(URL,"news","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=420,height=400,top=10,left=30");
}

function apriPostOffice() 
{
  var parametri = "width=800,height=600,top=100,left=100,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
  
  Win = window.open("","PostOffice",parametri);
  Win.document.open();

  Win.document.writeln('<','frameset rows="27%,*" frameborder=0 framespacing=0 border=0>');
  Win.document.writeln('<','frame name="Header" src="http://postoffice.finanze.it/appTopFrame.asp?appType=NuovaRubrica"  framespacing=0 frameborder=0 border=0 scrolling=no>');
  Win.document.writeln('<','frameset cols="100%,0" frameborder=1 framespacing=0 border=1>');
  Win.document.writeln('<','frame name="Data" src="http://postoffice.finanze.it/Rubrica/Dipartimenti/20009.htm" framespacing=0 frameborder=0 border=0>');
  Win.document.writeln('<','frame name="Elab" src="Blank.htm" framespacing=0 frameborder=0 border=0>');
  Win.document.writeln('<','/frameset>');
  Win.document.writeln('<','noframes>');
  Win.document.writeln('<','body>');
  Win.document.writeln('<','p>Questa pagina utilizza i frames, ma il vostro browser non li supporta.</p>');
  Win.document.writeln('<','/body>');
  Win.document.writeln('<','/noframes>');
  Win.document.writeln('<','/frameset>');
  
  Win.document.close();
  Win.focus();
}

function motorericerca()
{
   location.href = "http://search.finanze.it/cgi-bin/query?mss=search&&pg=q&i=AAMS&q="+document.homeform.q.value;
}                         

function ValidaAzione()
{
   return false;
}

function vaiMenu() {
   var optionMenu = document.forms[0].menu_servizi.selectedIndex;
   var urlMenu = document.forms[0].menu_servizi.options[optionMenu].value;
   location.href = urlMenu;
}

function invioModulo()
{
   var tasto = window.event.keyCode;
   if (tasto == 13)
   {
      location.href = "http://search.finanze.it/cgi-bin/query?mss=search&text=true&kl=it&i=AgenziaEntrate&q="+document.homeform.q.value;
   }
}

function IsVuoto(stringa)
{
   var nLen;
   var bReturn = true;

   if (stringa != null)
   {
	   nLen = stringa.length;
  	   if (nLen != 0)
      for(var i=0;i<nLen;i++)
      {
         if(stringa.charAt(i) != " ")
         {
         bReturn = false;
         break;
         }
      }
   }
   return (bReturn);
} 

function validatePrompt (Ctrl, PromptStr)
{
  alert (PromptStr)
  Ctrl.focus();
  return;
}	

function IsDate(gg, mm, aa)
{
 if (gg < "01" || gg > "31" )
   return (false);
 else if (mm < "01" || mm > "12" )
   return (false);
 else if (aa < "2000" || aa > "2030" )
   return (false);
 else if (mm == "02" && gg > "29")
   return (false);
 else if ((mm == "02" && gg == "29") && !IsBisestile(parseInt(aa, 10)))
   return (false);
 else if ((mm == "04" || mm == "06" || mm == "09" || mm == "11") && gg > "30")
   return (false);
 else {
   //Ctrl.value = gg + "/" + mm + "/" + aaaa; 
   return (true);
 }
}

function IsBisestile(anno) {
  if ( (anno%100) == 0 ) { 
    // E' un secolo
    if ( (anno%400) == 0 )
      return (true);
  } else
    if ( (anno%4) == 0 )
      return (true);

  return (false);
}

function IsNumero(Ctrl) { 
  if (isNaN(parseInt(Ctrl.value, 10))) {
    return (false);
  } else {
    if ((parseInt(Ctrl.value, 10) == 0) && (Ctrl.value != "0")) {
      return (false);
    } else {
      //Valore numerico (ma possono esserci caratteri non numerici in coda)
      //Elimina eventuali caratteri non numerici in coda
      Ctrl.value = parseInt(Ctrl.value, 10);
      return (true);
    }
  }
}

onload=function(){
	if(!document.getElementsByTagName) return;
	l=document.getElementsByTagName("a");
	for(i=0;i<l.length;i++){
		  if(l[i].className.indexOf("ext")!=-1){
			l[i].title="(link a sito esterno)";
		  }else if(l[i].className.indexOf("new_window")!=-1){
			l[i].title="(link esterno: si apre in una nuova finestra)";
			l[i].onclick=function(){window.open(this.href);return(false)};
		  }
	}
} 


// Javascript per il form iscrizione corsi newslot
function nasconditipologia(campo,camponascosto){
	if(campo.value!=10){
		camponascosto.disabled= true;
		camponascosto.value="";
	}else{
		camponascosto.disabled= false;	
	}

}
function nascondiconcessionari(campo,camponascosto1,camponascosto2){
	if(campo.value<=0){
		camponascosto1.disabled= true;
		camponascosto1.value="";
		camponascosto2.disabled= true;
		camponascosto2.checked=false;
	}else{
		camponascosto1.disabled= false;	
		camponascosto2.disabled= false;	
	}

}

function nascondicomuni(campo,camponascosto){
	if(campo.value=='00'){
		camponascosto.disabled= true;
		camponascosto.value="";
	}else{
		camponascosto.disabled= false;	
	}

}

var dataApplication = new Array();

function GetDati(id)
{
 	return dataApplication[id];
}

function createSelectByRegione(selectori,selectdest)
{  
	if(selectdest.selectedIndex!=-1){
		temp=selectdest.options[selectdest.selectedIndex].value ;
	}else{
		temp="00"
	}
	var values = GetDati(selectori.options[selectori.selectedIndex].value);
	var n = document.getElementById('COMUNE');
	if(n!=null)	document.getElementById('nascondi').removeChild(n);
	var selectcomuni=document.createElement('select');
	selectcomuni.setAttribute("id","COMUNE");
	selectcomuni.setAttribute("name","B27");
	if(values)
	{   
		for(i=0;i<values.length;i++)
		{  
			theOption=document.createElement("OPTION");
			theOption.value=values[i][1];
			theOption.innerHTML=values[i][0];
			if(temp==values[i][1]) theOption.setAttribute("selected","selected");;
			selectcomuni.appendChild(theOption);
		}
		
	}
	document.getElementById('nascondi').appendChild(selectcomuni);
}


function init(mode){
	if(document.getElementById('TIPOLOGIA')==null || document.getElementById('ALTTIP')==null || document.getElementById('NANS')==null || document.getElementById('CONC')==null || document.getElementById('NET')==null || document.getElementById('PROV')==null || document.getElementById('COMUNE')==null)
	{
		setTimeout('init()', 500) ;
	}
	else
	{
		createSelectByRegione(document.getElementById('PROV'),document.getElementById('COMUNE'));
		nascondicomuni(document.getElementById('PROV'),document.getElementById('COMUNE'));
		nasconditipologia(document.getElementById('TIPOLOGIA'),document.getElementById('ALTTIP'));
		nascondiconcessionari(document.getElementById('NANS'),document.getElementById('CONC'),document.getElementById('NET'));
		if(mode=="aggiungi"){
			self.location.hash= '#ACOGNOME';
			setTimeout('document.getElementById(\'COGNOME\').focus()', 200) ;
		}
	}
	return false;
}

function CaptureKey(e){
	/*var key;
	if (!e) var e = window.event;
	if (e.keyCode) key=e.keyCode;
	else if (e.which) key=e.which;
*/
	//
	if (typeof e == 'undefined'){
		var e = window.event;
	}
	var source;
	if (typeof e.target != 'undefined'){
		source = e.target;
	} else if (typeof e.srcElement != 'undefined'){
		source = e.srcElement;
	}
	else{
		return;
	}		
	if(e.keyCode==38 || e.keyCode==40){ 
		
		if(source.id=="PROV"){
			//alert(e.keyCode);
			if(source.value!="00"){
				document.getElementById('COMUNE').disabled=false; 
			}else{
				document.getElementById('COMUNE').disabled=true;
			}
		}
		if(source.id=="TIPOLOGIA"){
			if(source.value!="10"){
				document.getElementById('ALTTIP').disabled=true; 
			}else{
				document.getElementById('ALTTIP').disabled=false;
			}
		}

 	}else{
		if(source.id=="NANS"){
			//alert(source.value);
			if(source.value>0){
				
				document.getElementById('CONC').disabled=false;
				document.getElementById('NET').disabled=false;
				document.getElementById('NET').checked=false;
			}else{
				document.getElementById('CONC').disabled=true;	
				document.getElementById('NET').disabled=true;
			}
		}
	}
	
}


// fine