

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 ricercamf(){

  location.href = "http://search.finanze.it/cgi-bin/query?mss=search&kl=it&i=AgenziaEntrate&q="+document.homeform.q.value;

}



function ValidaAzione(){

       //alert("?");

       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);

    }

  }

}



function trim(str)

{

   return str.replace(/^\s*|\s*$/g,"");

}





var CT=0;

AJAX_N_CALLS=0;

function ajaxGetUrl(qryStr,url,returnFunction,httpMethod,AJAX_SHOW_TEST)
{
	CT++;

	if(!document.getElementById("ajaxStatus"))
	{

		root = document.createElement("div");

		root.id = "ajaxStatus";

		document.body.appendChild(root);

		

		//alert(_wsize);

		var _wsize = null;

		if( parseInt( navigator.appVersion ) > 3 ) 

		{

			if( navigator.appName === "Netscape" ) 

			{

				_wsize = "100%";

			}



			if( navigator.appName.indexOf( "Microsoft" ) !== -1 ) 

			{

				_wsize = document.body.offsetHeight;

			}

		}

		

		document.getElementById("ajaxStatus").style.zindex="100000";

		document.getElementById("ajaxStatus").style.position="absolute";

		document.getElementById("ajaxStatus").style.width="50%";

		document.getElementById("ajaxStatus").style.height="15px";

		document.getElementById("ajaxStatus").style.top="0";

		document.getElementById("ajaxStatus").style.left="0";

		document.getElementById("ajaxStatus").style.backgroundColor="#B8B9B8";

	}

	

	/* trasparenza */	

	var ie = (document.all) ? 1 : 0;

	var p = (ie) ? "filter" : "MozOpacity";

	v = 30;

	v = (ie) ? "alpha(opacity="+v+")" : v/100;

	document.getElementById("ajaxStatus").style[p] = v;

	/* trasparenza */

	

	document.getElementById("ajaxStatus").style.visibility ='visible';

	//window.scrollTo(0,0);



	

	var req = false;

	

    // XMLHttpRequest object

	if(window.XMLHttpRequest)

	{

		try

		{

			req = new XMLHttpRequest();

		} 

		catch(e)

		{

			req = false;

		}

	}// IE/Windows ActiveX version 

	else if(window.ActiveXObject) 

	{

		try 

		{

			req = new ActiveXObject("Msxml2.XMLHTTP");

		} 

		catch(e) 

		{

			try 

			{

				req = new ActiveXObject("Microsoft.XMLHTTP");

			} 

			catch(e) 

			{

				req = false;

			}

		}

	}

	if(req) 

	{

		req.onreadystatechange =function() 

								{

									if (req.readyState == 4) 

									{

										/*if (req.status == 200) 

										{*/

											CT--;

											AJAX_N_CALLS--;

											document.getElementById("ajaxStatus").style.visibility ='hidden'; 

											eval(""+returnFunction+"(req.responseText);");

											document.getElementById("ajaxStatus").innerHTML = "";

										/*} 

										else 

										{

											alert("There was a problem retrieving the XML data:\n"+ req.status+ "-" + req.statusText);

										}*/

									}

									else if (req.readyState == 1)

									{

										//window.scrollTo(0,0);

										document.getElementById("ajaxStatus").innerHTML = "<div style='text-align:center;position:absolute;top:25%;width:99%;border:1px dashed gray;background-color:#EDEDED;font-size:10px;'>"+AJAX_SHOW_TEST+" loading...</div>";

									}

									else if (req.readyState == 2)

									{

										//window.scrollTo(0,0);

										document.getElementById("ajaxStatus").innerHTML = "<div style='text-align:center;position:absolute;top:25%;width:99%;border:1px dashed gray;background-color:#EDEDED;font-size:10px;'>"+AJAX_SHOW_TEST+" loaded...</div>";

									}

									else if (req.readyState == 3)

									{

										//window.scrollTo(0,0);

										document.getElementById("ajaxStatus").innerHTML = "<div style='text-align:center;position:absolute;top:25%;width:99%;border:1px dashed gray;background-color:#EDEDED;font-size:10px;'>"+AJAX_SHOW_TEST+" interactive...</div>";

									}

								};

		req.open(httpMethod, url, true);



		req.setRequestHeader("Content-type","application/x-www-form-urlencoded");

		req.setRequestHeader("Content-length",qryStr.length);

		req.setRequestHeader("Connection","close");								



		req.send(qryStr);

	}

}



function ajaxAddUrl(qryStr,url,returnFunction,httpMethod,AJAX_SHOW_TEST)

{

	if(CT>15)

	{

		setTimeout("ajaxAddUrl('"+qryStr+"','"+url+"','"+returnFunction+"','"+httpMethod+"','"+AJAX_SHOW_TEST+"')",2000);

	}

	else

	{

		ajaxGetUrl(qryStr,url,returnFunction,httpMethod,AJAX_SHOW_TEST);

	}

}



function getTemplate(url)

{

	ajaxAddUrl("",url,"resTemplate","GET")

}



function resTemplate(data)

{

	document.getElementById("mainIframe").innerHTML=data;

}





function convertCharAscii(source)

{

	var ss = "";

	var i = 0;

	for(i=0;i<source.length;i++)

	{

		//alert(source);

		if(source.charCodeAt(i) >= 128)

		{

			var chr = "/"+source.substring(0,1)+"/g";



			source = source.replace(chr,"&#"+source.charCodeAt(i));

		}

	}

	return source;

}



var all_pages_oj = new Object;
var xnx =0;
function resContentPage(data)

{

	data = trim(data);

//prompt(data);



	if(trim(data)!="")

	{

		var xtData = data.split("^");

		var idPadre = xtData[1];

		var allId = xtData[2];
		
		var mainidPadre = xtData[0]

		

		var xtData = allId.split("|");

		

		var liData = "";

		

		for(var e=0;e<xtData.length;e++)

		{

			if(trim(xtData[e])!="")

			{

				var nowValue = xtData[e];

				

				var tData = nowValue.split("$");

				

				var idData = tData[0];

				var idDataT = tData[1];

				

				// .oO - KzM - Oo.

				var rep = /'/g;

				idDataT = idDataT.replace(rep,"&#39;");

				

				var rep = /\n/g;

				idDataT = idDataT.replace(rep,"");

				

				var rep = /\r/g;

				idDataT = idDataT.replace(rep,"");

//alert(idDataT);

//				var rep2 = /"/g;

//				idDataT = idDataT.replace(rep2,"&#34;");



				idDataT = convertCharAscii(idDataT);

				// .oO - KzM fine - Oo.
				/*if(document.getElementById("map_"+idData))
				{
					alert(idData+" - pagina già presente nell'alberatura...");
				}*/
				
				liData += '<li class="map_li" id="map_'+idData+'"><a href="/site.php?id='+idData+'">'+idDataT+'</a></li>\n';
				
				
				if(all_pages_oj[mainidPadre])
				{
					all_pages_oj[mainidPadre] = parseInt(all_pages_oj[mainidPadre])+1;
					//alert(all_pages_oj[mainidPadre]);
				}
				else
				{
					all_pages_oj[mainidPadre] = 1;
				}
				/*for(var e=0;e<all_pages_oj.lenght;e++)
				{
					alert(all_pages_oj[e][0]);
				}*/
				
				xnx++;

				if(parseInt(all_pages_oj[mainidPadre])<document.getElementById("level").value)
				{
				
				AJAX_N_CALLS++;

				ajaxAddUrl("","site.php?id=admin&mode=mkmap&AJ=1&aj_mainidpage="+mainidPadre+"&aj_idpage="+idData+"&aj_idpage="+idData+"&aj_idpadre="+idPadre,"resContentPage","GET",idDataT);
				}

			}

			

		}

		if(trim(liData)!="" && document.getElementById("map_"+idPadre))
		{

			//alert(document.getElementById("map_"+idPadre).lenght);
			/*if(document.getElementById("map_"+idPadre)!=document.getElementById("map_"+idPadre))
			{
				alert(idPadre+" - pagina già esistente nell'alberatura...");
			}
			else
			{*/
				var all_li_found = document.getElementsByTagName("LI");
				
				//alert(document.getElementById("map_"+idPadre).length);
				if(document.all)
				{
					for(var i=0;i<all_li_found.length;i++)
					{
						if(all_li_found[i].id=="map_"+idPadre)
						{
							all_li_found[i].innerHTML +='<ul class="map_ul">'+liData+'</ul> \n';
							//alert(all_li_found[i].innerHTML);
							//setTimeout("all_li_found[i].innerHTML +='<ul class=\"map_ul\">'+liData+'</ul> \n';",100*i);
						}
					}
				}
				else
				{
					document.getElementById("map_"+idPadre).innerHTML +='<ul class="map_ul">'+liData+'</ul> \n';
				}
			//}

			//window.scrollTo(0,document.getElementById(idPadre).offsetTop);

			//document.getElementById("ajaxStatus").style.top=document.getElementById(idPadre).offsetTop;

			//alert(document.getElementById(idPadre).offsetTop);

		}

	}

	if(AJAX_N_CALLS<=0)
	{
		alert("Creazione della mappa conclusa. Se la mappa è stata creata correttamente \npotete proseguire con il salvataggio della mappa.");
		document.getElementById('save_map').disabled=false;
	}

}

function extractData()
{
	var text ="<ul><li>sdfsd<ul><li>dsas</li></ul></li></ul>";
	
	if (window.ActiveXObject)
	  {
	  var doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(text);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  var doc=parser.parseFromString(text,"text/xml");
	  }
	  
	  alert(doc.innerHTML);
}

function saveMap()
{
//extractData();
	
	var rep = /http:\/\/s-.*xcmtest.it/gi;
	var rep2 = /'/g;

	var data_map = document.getElementById('resMap');
	var data_map_HTML = data_map.innerHTML;

	data_map_HTML = data_map_HTML.replace(rep,"");
	
	data_map_HTML = data_map_HTML.replace(/[^\?]id=([^>| ]+)/gi,"");
	
	data_map_HTML = data_map_HTML.replace(/class=([^>| |\"]+)/gi,"class=\"$1\"");
	
	
	if(document.all)
	{
		data_map_HTML = data_map_HTML.replace(/<\/H4>/gi,"</h4></li>");
			
		data_map_HTML = data_map_HTML.replace(/<\/h4><\/li>\s*<UL/gi,"</h4><ul");
		
		data_map_HTML = data_map_HTML.replace(/<\/UL>\s*<li/gi,"</ul></li><li");
		
		data_map_HTML = data_map_HTML.replace(/<UL/gi,"<ul");
		data_map_HTML = data_map_HTML.replace(/<\/UL/gi,"</ul");
		
		data_map_HTML = data_map_HTML.replace(/<LI/gi,"<li");
		data_map_HTML = data_map_HTML.replace(/<\/LI/gi,"</li");
		
		data_map_HTML = data_map_HTML.replace(/<\/h4>\s*<\/li>\s*<\/li>\s*<\/ul>/gi,"</h4></li></ul>");
	}
	/*data_map_HTML = data_map_HTML.replace(/<CHILD/gi,"<li");
	data_map_HTML = data_map_HTML.replace(/<\/CHILD/gi,"</li");*/
	
	//alert(data_map_HTML);
	
	
	//data_map_HTML = data_map_HTML.replace(/class=([^ ]+)/i,"class=\"$1\"");
	//stext = stext.replace(/<strong>(.*)<\/strong>/i,'$1');
	
	

	ajaxAddUrl("&data_map="+data_map_HTML,"site.php?id=admin&mode=mkmap&AJ=2","resSaveMap","POST","");

}



function resSaveMap(data)

{

	if(trim(data)=='TRUE')

	{

		alert("Mappa salvata correttamente.");

	}

	else

	{

		alert("Si sono provocati errori in fase di salvataggio."+data);

	}

}


// .oO - kz.M - ARCHIVIAZIONE - Oo.

function checkAll(namecheck) {
	var check = document.getElementsByTagName("input");

	for(i=0; i< check.length; i++) {
		if(check[i].getAttribute("name") == namecheck) {
			check[i].checked = !check[i].checked;
		}
	}
}


function evidenziaCheck(element, titolo) {
	document.getElementById(titolo).style.background = (element.checked == true ? "#BEBEBE" : "#EEEEEE");
}


function archiviaNovita(namecheck) {
	var check = document.getElementsByTagName("input");
	var tmp = new Array();
	var j = 0;
	
	if(namecheck == "check_archiviaprimopiano") {
		alert("Le notizie di primo piano prima non le archiviavamo, non so cosa devo fare adesso visto che non c'è nessuno a cui posso chiedere me ne vado a casa :DDDDDDDDDDD\n cmq l'archiviazione delle novità funziona!!!");
	}
	
	for(i=0; i< check.length; i++) {
		if(check[i].getAttribute("name") == namecheck) {
			if(check[i].checked === true) {
				tmp[j] = check[i].value;
				j++;
			}
		}
	}

	ajaxAddUrl("&archivia=true&ch="+tmp,"site.php?id=admin&mode=news","resArchivio","POST","");
}


function resArchivio(data) {
	document.location.reload(true);
}

function espandiArch(anno) {
	//var divArch = document.getElementById("arch_"+anno);
	ajaxAddUrl("&espandi=true&anno="+anno,"site.php?id=admin&mode=popup&namefile=archivia","resEspandi","POST","");
}

function resEspandi(data){
	//alert(data);
	document.getElementById("arch_2006").style.display = "block";
	document.getElementById("arch_2006").innerHTML = data;
}

function valida(path,passwd,type) {
	
	var old_passwd = document.getElementById(type+"_passwd");
	var img_valida = document.getElementById(type+"_img_valida");


	img_valida.style.display = (old_passwd.value.length != 0 ? "inline" : "none");
	img_valida.setAttribute("src",path+(old_passwd.value == unescape(passwd) ? "valida_passwd.gif" : "novalida_passwd.gif"));
}

function conf() {
	/*
	var inp1 = document.getElementById("old_passwd");
	var inp2 = document.getElementById("new_passwd");
	var inp3 = document.getElementById("renew_passwd");
	
	if(inp1.value.length == 0 && inp2.value.length == 0 )
	alert('Password modificata!')
	*/
}
// .oO - kz.M - ============= - Oo.



/*MENU AMMINISTRAZIONE*/
function adminShowMenu()
{
	if(document.getElementById("ADMIN_MENU").style.display == "none")
	{
		document.getElementById("ADMIN_MENU").style.display = "block";
	}
	else
	{
		document.getElementById("ADMIN_MENU").style.display = "none";
	}
}

function resAdminMenu(data)
{
	var data_idpage = window.location.href.split("?");
	var idpage = window.location.href.split("=");
	
	
	var idpage=idpage[1];
	
	
	if(trim(data)!="")
	{
		
		document.body.innerHTML += "<div style=\"position:absolute;font-size:80%;border:1px dashed;top:40px;z-index:3000;right:6px;width:200px;background-color:#fff;\">"
									+"<div id=\"ADMIN_MENU\" style=\"width:100%;display:none;\">"
									+"</div>"
									+"<div onclick=\"adminShowMenu();\" style=\"text-align:center;\">"
									+"Menu di amministrazione"
									+"</div>"
								+"</div>";
		
		var admin_menu = "<ol>";
									
		if(idpage=="home")
		{
			admin_menu += "<li><a href=\"?id=admin&mode=news\">Gestione news</a></li>"
							+"<li><a href=\"?id=admin&mode=cache&action=1&idp[]="+idpage+"\">Rimuovi dalla cache</a></li>"
							+"<li><a href=\"?id=admin\">Amministrazione</a></li>"
							+"<li><a href=\"?id=admin&mode=logout\">Log out</a></li>";
							
		}
		else
		{
			admin_menu += "<li><a href=\"?id=admin&mode=pages&action=mod&idpage="+idpage+"\">Modifica pagina</a></li>"
							+"<li><a href=\"?id=admin&mode=cache&action=1&idp[]="+idpage+"\">Rimuovi dalla cache</a></li>"
							+"<li><a href=\"?id=admin\">Amministrazione</a></li>"
							+"<li><a href=\"?id=admin&mode=logout\">Log out</a></li>";
		}
		admin_menu += "</ol>";
		
		document.getElementById("ADMIN_MENU").innerHTML = admin_menu;	
	}
	else
	{
	 //alert("nada");
	}
	
}