

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(data) {
	data= data.replace(/^\s+/, '');
	return data.replace(/\s+$/, '');
}



var CT=0;

var AJAX_N_CALLS=0;

function ajaxGetUrl(qryStr,url,returnFunction,httpMethod,AJAX_SHOW_TEST)
{
	CT++;

	if(!document.getElementById("ajaxStatus"))
	{

		var 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="50px";

		document.getElementById("ajaxStatus").style.height="50px";

		document.getElementById("ajaxStatus").style.top="90%";

		document.getElementById("ajaxStatus").style.left="0";
		
		//document.getElementById("ajaxStatus").style.right="50px";

		//document.getElementById("ajaxStatus").style.top=_wsize+"px";
		
		
	}

	

	/* trasparenza */	

	var ie = (document.all) ? 1 : 0;

	var p = (ie) ? "filter" : "MozOpacity";

	var v = 40;

	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:right;position:absolute;width:99%;'><img src='/themes/__admin_images/loading4.gif'/></div>";

									}

									else if (req.readyState == 2)

									{

										//window.scrollTo(0,0);

										document.getElementById("ajaxStatus").innerHTML = "<div style='text-align:right;position:absolute;width:99%;'><img src='/themes/__admin_images/loading4.gif'/></div>";

									}

									else if (req.readyState == 3)

									{

										//window.scrollTo(0,0);

										document.getElementById("ajaxStatus").innerHTML = "<div style='text-align:right;position:absolute;width:99%;'><img src='/themes/__admin_images/loading4.gif'/></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>0)

	{

		setTimeout("ajaxAddUrl('"+qryStr+"','"+url+"','"+returnFunction+"','"+httpMethod+"','"+AJAX_SHOW_TEST+"')",100);

	}

	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+'">'+trim(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 saveMap()
{
//extractData();

	var rep = /http:\/\/s-agenziaterritorio.agenziaterritorio.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(/&nbsp;/gi,"");
	
	//alert(data_map_HTML);
	
	/*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.

function saveCss(id)
{
	var strQry = '';
	
	for(var i=0;i<document.datacss.elements.length;i++)
	{
		if(document.datacss.elements[i].type!='button')
		{
			strQry = strQry + '&' + document.datacss.elements[i].name + '=' + document.datacss.elements[i].value;
		}
	}
	ajaxAddUrl(strQry,"site.php?id=admin&mode=popup&namefile=ajax&fx=createCss&aj_id="+id,"resSaveCss","POST");
}

function resSaveCss(data)
{
	data = trim(data);
	if(data == "TRUE")
	{
		alert("Salvato correttamente.");
		document.getElementById("editcss").innerHTML = "";
	}
	else
	{
		prompt(data);
	}
}

function editCss(id,mode)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax&fx=editCss&aj_id="+id+"&aj_mode="+mode,"resEditCss","GET");
}

function resEditCss(data)
{
	document.getElementById("editcss").style.visibility = "visible";
	document.getElementById("editcss").style.marginTop = "10px";
	document.getElementById("editcss").innerHTML = data;
}

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 id=\"admin_menu_cont\">"
									+"<h1 onclick=\"adminShowMenu();\" style=\"cursor: hand; cursor:pointer;\">Menu di amministrazione</h1>"
									+"<div style=\"display:none;\" id=\"admin_menu\">"
									+"</div>"
								+"</div>";
		
		var admin_menu = "<ol>";
									
		if(idpage=="home")
		{
			admin_menu += "<li id=\"gestione_news\"><a href=\"?id=admin&mode=news\">Gestione news</a></li>"
							+"<li id=\"cache\"><a href=\"?id=admin&mode=cache&action=1&idp[]="+idpage+"\">Rimuovi dalla cache</a></li>"
							+"<li id=\"amministrazione\"><a href=\"?id=admin\">Amministrazione</a></li>"
							+"<li id=\"logout\"><a href=\"?id=admin&mode=logout\">Log out</a></li>";
							
		}
		else if(idpage=="mappa")
		{
			admin_menu += "<li id=\"modifica_pagina\"><a href=\"?id=admin&mode=mkmap\">Modifica mappa</a></li>"
							+"<li id=\"cache\"><a href=\"?id=admin&mode=cache&action=1&idp[]="+idpage+"\">Rimuovi dalla cache</a></li>"
							+"<li id=\"amministrazione\"><a href=\"?id=admin\">Amministrazione</a></li>"
							+"<li id=\"logout\"><a href=\"?id=admin&mode=logout\">Log out</a></li>";
		}
		else
		{
			admin_menu += "<li id=\"modifica_pagina\"><a href=\"?id=admin&mode=pages&action=mod&idpage="+idpage+"\">Modifica pagina</a></li>"
							+"<li id=\"cache\"><a href=\"?id=admin&mode=cache&action=1&idp[]="+idpage+"\">Rimuovi dalla cache</a></li>"
							+"<li id=\"amministrazione\"><a href=\"?id=admin\">Amministrazione</a></li>"
							+"<li id=\"logout\"><a href=\"?id=admin&mode=logout\">Log out</a></li>";
		}
		admin_menu += "</ol>";
		
		document.getElementById("admin_menu").innerHTML = admin_menu;	
	}
	else
	{
	 //alert("nada");
	}
	
}





function reOrder(type)
{
	var container_id = document.getElementById("table_main_"+type);
	var all_tr = container_id.getElementsByTagName("TR");
	//alert(all_tr.length);
	
	var e = 0;
	for(var i=0;i<all_tr.length;i++)
	{
		if(all_tr[i].id)
		{
			all_tr[i].id = "id_" + type + "_" + e;
			e++;
		}
	}
// KzM - Commentato perchè ogni volta che clicco su una freccetta, mi esegue saveAllPosition
	//saveAllPositions(type);
}




function moveUp(item,type)
{
	document.getElementById("news_button_save").disabled=false;
	document.getElementById("news_button_save").style.background="url(/themes/__admin_images/save.gif) no-repeat top center";
	document.getElementById("news_button_save").style.opacity=1;
	document.getElementById("news_button_save").style.filter=100;

	var element = item.parentNode.parentNode.parentNode;
	var element_tagid = element.id;
	var element_id_n = element_tagid.split("_");
	var element_id = element_id_n[2];
	var element_new_id = "id_" + type + "_" + (parseInt(element_id)-1);
	
	if(document.getElementById(element_new_id))
	{
		var element_new_position = document.getElementById(element_new_id);
		
		element_new_position.parentNode.insertBefore(element,element_new_position);
		element.style.backgroundColor = "#F4E4AD";
		reOrder(type);
	}
}

function moveDown(item,type)
{
	document.getElementById("news_button_save").disabled=false;
	document.getElementById("news_button_save").style.background="url(/themes/__admin_images/save.gif) no-repeat top center";
	document.getElementById("news_button_save").style.opacity=1;
	document.getElementById("news_button_save").style.filter=100;

	var element = item.parentNode.parentNode.parentNode;
	var element_tagid = element.id;
	var element_id_n = element_tagid.split("_");
	var element_id = element_id_n[2];
	var element_new_id = "id_" + type + "_" + (parseInt(element_id)+1);
	
	if(document.getElementById(element_new_id))
	{
		var element_new_position = document.getElementById(element_new_id);
		
		element_new_position.parentNode.insertBefore(element_new_position,element);
		element.style.backgroundColor = "#F4E4AD";
		reOrder(type);
	}

	
}

function saveAllPositions(type)
{
	//var container_id = document.getElementById("table_main_" + type);
	
	var container_id = document.getElementById("admin_news");
	var subTableId = "table_main_";
	
	var query = "";
	
	for(var i=0; i<container_id.getElementsByTagName("table").length; i++) {
		if(container_id.getElementsByTagName("table")[i].id.match("table_main_")) {
			var all_tr = container_id.getElementsByTagName("tr");
			
			for(var i=0;i<all_tr.length;i++) {
				if(all_tr[i].id) {
					var div_id = all_tr[i].getElementsByTagName("div");
					var id_record = div_id[0].id;
					
					var element_id_n = all_tr[i].id.split("_");
					var element_id = element_id_n[2];
					
					query += "eid["+id_record+"]=" + element_id + "&";
				}
			}
		}
	}
	ajaxAddUrl("&"+query,"site.php?id=admin&mode=popup&namefile=ordnews","resSaveAllPosition","POST","");
	//alert(query);
	return query;
}

function resSaveAllPosition(data) {
	var container_id = document.getElementById("admin_news");
	var subTableId = "table_main_";
	for(var i=0; i<container_id.getElementsByTagName("table").length; i++) {
		if(container_id.getElementsByTagName("table")[i].id.match("table_main_")) {
			var all_tr = container_id.getElementsByTagName("tr");
			
			for(var i=0;i<all_tr.length;i++) {
				if(all_tr[i].id.match("id_")){
					all_tr[i].style.backgroundColor = "#EEEEEE";
				}
			}
		}
	}
	document.getElementById("news_button_save").disabled=true;
	document.getElementById("news_button_save").style.background="url(/themes/__admin_images/save.gif) no-repeat top center";
	
	document.getElementById("news_button_save").style.opacity="0.22";
	document.getElementById("news_button_save").style.filter="alpha(opacity='22')";
	//alert(data);
}






function errorFound(e)
{
	prompt("",e);	
}

function getAssBlock(id,mode)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&vismode="+mode+"&namefile=ajax&fx=getAssBlock&aj_id="+id,"resAssBlock","GET")
}

function resAssBlock(data)
{
				if(document.getElementById("propertyblocks"))
				{
								document.getElementById("propertyblocks").innerHTML = data;
				}
}


function insertBlock(id,idcontent,position)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax&fx=insertBlock&aj_id="+id+"&aj_idcontent="+idcontent+"&aj_position="+position,"resInsertBlock","GET")
}

function resInsertBlock(data)
{
	data = trim(data);
	if(data=="true")
	{
		location.href = location.href;
		if(document.getElementById('propertyblocksdone').style.visibility=="hidden")
		{
			document.getElementById('propertyblocksdone').style.height="100%";
			document.getElementById('propertyblocksdone').style.visibility="visible";
		}
		//document.getElementById('propertyblocksdone').innerHTML=document.getElementById('propertyblocksdone').innerHTML + document.getElementById('selectBlock').options[document.getElementById('selectBlock').selectedIndex].text+'&nbsp;<input style=\"margin-left:20px;\" type=\"text\" name=\"block[]\" value=\"'+document.getElementById('selectBlock').value+'\" DISABLED /><br />';
		document.getElementById('propertyblocksdone').innerHTML=document.getElementById('propertyblocksdone').innerHTML + "<strong>ID contenuto:</strong> "+document.getElementById('selectBlock').value+" --> <strong>Posizione:</strong> "+document.getElementById('position').value+" <a href=\"#\" onclick=\"modBlock("+document.getElementById('selectBlock').value+");return false;\">Modifica</a><br />";
		document.getElementById('propertyblocks').innerHTML="";
	}
	else
	{
		prompt('',"'"+data+"'");
	}
}

function getMenu(id)
{
	var xid = (mod==1 ? now_idparent_menu:trim(id));

//	if (xid == '0')
//		now_id_menu = '0';

	modDivIsVisible = false;
	
	if(document.getElementById("menu_view_"+xid).style.visibility == "hidden")
	{
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=viewMenu&aid="+xid,"resMenu","GET")
	}
	else
	{
		document.getElementById("menu_view_"+now_id_menu).innerHTML = "";
		document.getElementById("menu_view_"+now_id_menu).style.visibility = "hidden";
	}
//	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax&fx=viewMenu&aid="+id,"resMenu","GET")
}

function resMenu(data)
{
	lcont = 1;
	
	var xid = (mod==1 ? now_idparent_menu:now_id_menu);
	
	document.getElementById("menu_view_"+xid).style.paddingLeft = lcont+"px";
	document.getElementById("menu_view_"+xid).style.visibility = "visible";
	document.getElementById("menu_view_"+xid).innerHTML = data;
	lcont++;
	
	mod = 0;
}


function insMenu(id)
{
	clearAllinsmod();

	idLocal = (mod == 1 ? now_mid : now_parent_id);

	if(!divIsVisible)
	{
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=viewFormInsertMenu&mxid="+idLocal+"&mod="+mod,"resInsModMenu","GET");
	}
	else
		divIsVisible = false;
}

function modMenu(id)
{
	clearAllinsmod();

	if(!modDivIsVisible)
	{
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=viewFormInsertMenu&mxid="+id+"&mod="+mod+"&aid="+now_mid,"resInsModMenu","GET");
	}
	else
		modDivIsVisible = false;
}


function resInsModMenu(data)
{
	lcont = 1;

	idLocal = (mod == 1 ? now_mid : now_parent_id);

	document.getElementById("menu_insmod_"+idLocal+(mod==1 ? "_mod" : "")).style.position = "relative";
	document.getElementById("menu_insmod_"+idLocal+(mod==1 ? "_mod" : "")).style.visibility = "visible";
	document.getElementById("menu_insmod_"+idLocal+(mod==1 ? "_mod" : "")).style.border.color = "#000";
	document.getElementById("menu_insmod_"+idLocal+(mod==1 ? "_mod" : "")).innerHTML = data;

	if(mod == 1)
	{
		modDivIsVisible = true;
		divIsVisible = false;
		
	}
	else
	{
		divIsVisible = true;
		modDivIsVisible = false;
	}

	lcont++;
}


function clearAllinsmod()
{
	div = document.getElementsByTagName("div");

	for(i=0; i<div.length; i++)
	{
		sub = div[i].getAttribute("id");
		sub_ele = div[i];

		if(sub)
		{
			if("menu_insmod" == sub.substring(0,11) && sub_ele.style.visibility == "visible")
			{
				sub_ele.innerHTML = "";
				sub_ele.style.visibility = "hidden";
			}
		}			
	}

	return false;
}


function addMenu(id)
{
	var titolo 	= document.frmInsMenu.amenu_tit.value;
	var posizione 	= document.frmInsMenu.amenu_pos.value;


	var descr 	= document.frmInsMenu.amenu_descr.value;
	var icon 	= document.frmInsMenu.amenu_icon.value;
	
	if(now_parent_id != '0')
	{
		var pagina 	= document.frmInsMenu.amenu_idpage.value;
		//var sinottico 	= document.frmInsMenu.amenu_sin.checked;
	}
//	id = (mod == 0 ? "" : document.frmInsMenu.amenu_id.value);

//	sin = (sinottico ? true : false);

	mod_or_ins = (mod == 0 ? "insertMenu" : "updateMenu");

	idLocal = (mod == 1 ? now_idparent_menu : now_parent_id);
	clearAllinsmod();

//	if(document.getElementById("menu_insmod_"+idLocal+(mod==1 ? "_mod" : "")).style.visibility == "visible")
//	{
		// xmdData
		document.getElementById("menu_view_"+idLocal).style.visibility = "hidden";
		document.getElementById("menu_view_"+idLocal).innerHTML = "";
		

		ajaxAddUrl("&amenu_tit="+titolo+"&amenu_pos="+posizione+"&amenu_idpage="+pagina+"&amenu_descr="+descr+"&amenu_icon="+icon,"site.php?id=admin&mode=popup&namefile=ajax_menu&fx="+mod_or_ins+"&aid="+idLocal+"&mxid="+id,"getMenu","POST");
//		ajaxAddUrl("&amenu_tit="+titolo+"&amenu_pos="+posizione+"&amenu_idpage="+pagina+"&amenu_descr="+descr+"&amenu_icon="+icon+"&amenu_sin="+sin,"site.php?id=admin&mode=popup&namefile=ajax_menu&fx="+mod_or_ins+"&aid="+idLocal+"&mxid="+id,"getMenu","POST");



//	}
//	else
//	{
//		document.getElementById("menu_view_"+idLocal).innerHTML = "";
//		document.getElementById("menu_view_"+idLocal).style.visibility = "hidden";
//	}
	
}

function deleteMenu(id)
{
	if(confirm("Continuare con la cancellazione?"))
	{
		document.getElementById("menu_view_"+now_did).style.visibility = "hidden";
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=deleteMenu&aid="+now_did+"&mxid="+id,"getMenu","GET");
	}
	clearAllinsmod();
}


function getSinottico(id)
{
	if(document.getElementById("menu_sin"+amenu_sin_mid).style.display == "none")
	{
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=selectMenu&sin_id="+id,"resGetSinottico","GET");
		document.getElementById("amenu_assoc_pagina").style.display = "none";
	}
	else
	{
		document.getElementById("menu_sin"+amenu_sin_mid).style.innerHTML = "";
		document.getElementById("menu_sin"+amenu_sin_mid).style.display = "none";
		
		document.getElementById("amenu_assoc_pagina").style.display = "block";
	}

//	clearAllinsmod();

	return false;
}


function resGetSinottico(data)
{
	document.getElementById("menu_sin"+amenu_sin_mid).style.display = "block";
	document.getElementById("menu_sin"+amenu_sin_mid).innerHTML = data;

	document.getElementById("amenu_assoc_pagina").style.display = "none";

}


/*
function modMenu(id)
{
	if(document.getElementById("menu_mod_"+now_mid).style.visibility == "hidden")
	{
		ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax_menu&fx=viewFormEditMenu&mid="+id,"resModMenu","POST");
	}
	else
	{
		document.getElementById("menu_mod_"+now_mid).innerHTML = "";
		document.getElementById("menu_mod_"+now_mid).style.visibility = "hidden";
	}
}


function resModMenu(data)
{
	lcont = 1;

	document.getElementById("menu_mod_"+now_mid).style.position = "relative";
	document.getElementById("menu_mod_"+now_mid).style.visibility = "visible";
	document.getElementById("menu_mod_"+now_mid).innerHTML = data;
	
	lcont++;	
}

*/
function modBlock(id)
{
	
}

function delBlock(id,id2)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=ajax&fx=deleteBlock&aj_id[]="+id+"&aj_id[]="+id2,"resDelBlock","GET");
}

function resDelBlock(data)
{
	data = trim(data);
	if(data == "true")
	{
		location.href = location.href;
	}
	else
	{
		alert(data);
	}
}


var last_ele = null;
var last_ele_val = null;
var all_select = new Array();
all_select[0]="id_0";
function getXSelect(id,ele)
{
	
	last_ele = ele;
	
	document.getElementById(last_ele).disabled = true;
	
	//if(xf=0 && !document.getElementById("id_"+id))	
	all_select[all_select.length]="id_"+id;
	
	if(!document.getElementById("id_"+id))
	{
		
		var flag=0;
		var temp_ar = new Array();
		
		for(var i=0;i<all_select.length;i++)
		{
			if(all_select[i]==ele)
			{
				temp_ar[i]=all_select[i];
				flag=1;
			}
			else
			{
				temp_ar[i]=all_select[i];
				if(flag==1 && document.getElementById(all_select[i]))
				{
					try
					{
						eval("fadeOut('"+document.getElementById(all_select[i]).id+"',100);");
						setTimeout('removeEle(document.getElementById(all_select['+i+']))',200);
					}
					catch(e)
					{
						alert(e.message + document.getElementById(all_select[i]).id);
					}
				}
			}
		}
		
		all_select = temp_ar;
		if(id!="")
		{
			if(ele=="id_0")
			{
				ajaxAddUrl("","/site.php?id=admin&mode=popup&namefile=pages&idpadre="+id+"&isroot=1","addSelect","GET","Getting data...");
			}
			else
			{
				ajaxAddUrl("","/site.php?id=admin&mode=popup&namefile=pages&idpadre="+id,"addSelect","GET","Getting data...");
			}
		}
		else
		{
			document.getElementById(last_ele).disabled = false;
		}
	}
	
	
}

function removeEle(ele)
{
	try
	{
		document.getElementById('treeroot').removeChild(ele);
	}
	catch(e)
	{
		//alert(e.message + ele);
	}
	
}

function addSelect(data)
{
	document.getElementById("element_sel").innerHTML = "Pagina non selezionata"
	last_ele_val = null;
	data = trim(data);
	
	if(data!="")
	{
		var e = document.createElement("select");
		eval(data);
		e.style.visibility = "hidden";
		var ele = document.getElementById("treeroot").appendChild(e);
		myOnClick = new Function('e', 'setEleName("'+e.id+'");');e.onclick=myOnClick;
		
		eval("fadeIt('"+e.id+"',0);");
		e.style.visibility = "visible";	
		eval("fadeIn('"+e.id+"',0);");
	}
	document.getElementById(last_ele).disabled = false;
	
}

function setEleName(ele)
{
	try
	{
		for(var i=0;i<document.getElementById("treeroot").childNodes.length;i++)
		{
			var e = document.getElementById("treeroot").childNodes[i];
			if(e.id==ele)
			{
				last_ele_val = e.options[e.selectedIndex].value;
				document.getElementById("element_sel").innerHTML = "Selezionato: " + e.options[e.selectedIndex].value
				
			}
		}
	}
	catch(e)
	{
		alert(e.message);
	}
}


function fadeIt(obj,valFade)
{
	if(document.getElementById(obj))
	{
	/* trasparenza */	
		var ie = (document.all) ? 1 : 0;
		var p = (ie) ? "filter" : "MozOpacity";
		var v = valFade;
		v = (ie) ? "alpha(opacity="+v+")" : v/100;
		document.getElementById(obj).style[p] = v;
	/* trasparenza */
	}
}

function fadeIn(obj,valFade)
{
	if(document.getElementById(obj))
	{
		/* trasparenza */	
			var ie = (document.all) ? 1 : 0;
			var p = (ie) ? "filter" : "MozOpacity";
			
			if(valFade>=100) var v = 100;
			else var v = valFade;
			
			v = (ie) ? "alpha(opacity="+v+")" : v/100;
			document.getElementById(obj).style[p] = v;
			
			if(valFade<=100) setTimeout("fadeIn('"+obj+"',"+(valFade+10)+")",40);
			
		/* trasparenza */
	}
}

function fadeOut(obj,valFade)
{
	if(document.getElementById(obj))
	{
	/* trasparenza */	
		var ie = (document.all) ? 1 : 0;
		var p = (ie) ? "filter" : "MozOpacity";
		
		if(valFade<=0) var v = 0;
		else var v = valFade;
	
		v = (ie) ? "alpha(opacity="+v+")" : v/100;
		document.getElementById(obj).style[p] = v;
		
		if(!valFade<=0) setTimeout("fadeOut('"+obj+"',"+(valFade-10)+")",40);
		
	/* trasparenza */
	}
}



function getMenuHide(main)
{
				var div = document.getElementById("c_"+main);
				
				if(div.style.display=='block')
				{
								div.style.display='none';
				}
				else if(!div.style.display || div.style.display=='')
				{
								div.style.display='none';
				}
				else if(div.style.display=='none')
				{
								div.style.display='block';
				}
}

function checkTab()
{
				var cookieTab = getCookie("selectedTab");
				var cookieXTab = getCookie("selectedXTab");
				
				var tab1 = document.getElementById('block_utenti');
				var tab2 = document.getElementById('block_operatori');
				
				var tab3 = document.getElementById('portaboxInternaSx');
				var tab4 = document.getElementById('portaboxInternaDx1');
				
				if(tab1.id==cookieTab)
				{
								tab1.style.display = 'block';
								tab2.style.display = 'none';
								document.getElementById('utenti').className = 'current'; 
								document.getElementById('operatori').className = ''; 
								document.getElementById('indicaTab').className = 'tabcurrentLeft'
				}
				else if(tab2.id==cookieTab)
				{
								tab2.style.display = 'block';
								tab1.style.display = 'none';
								document.getElementById('operatori').className = 'current'; 
								document.getElementById('utenti').className = ''; 
								document.getElementById('indicaTab').className = 'tabcurrentRight'
				}
				else
				{
								tab1.style.display = 'block';
								tab2.style.display = 'none';
								document.getElementById('utenti').className = 'current'; 
								document.getElementById('operatori').className = ''; 
								document.getElementById('indicaTab').className = 'tabcurrentLeft'
				}
				
				
				if(tab3.id==cookieXTab)
				{
								tab3.style.display = 'block';
								tab4.style.display = 'none';
								document.getElementById('tabSin').className='tabSinistra portaboxInternaSx current';
								document.getElementById('tabDes1').className='tabDestra portaboxInternaDx1';
				}
				else if(tab4.id==cookieXTab)
				{
					
								tab3.style.display = 'none';
								tab4.style.display = 'block';
								//alert("in");
								document.getElementById('tabSin').className='tabSinistra portaboxInternaSx';
								document.getElementById('tabDes1').className='tabDestra portaboxInternaDx1 current';
				}
				else
				{
								tab3.style.display = 'block';
								tab4.style.display = 'none';
								document.getElementById('tabSin').className='tabSinistra portaboxInternaSx current';
								document.getElementById('tabDes1').className='tabDestra portaboxInternaDx1';
				}
				
				
}

function checkTabClick(idtab)
{
				setCookie("selectedTab",idtab);
}

function checkXTabClick(idtab)
{
				setCookie("selectedXTab",idtab);
}

function switchTab(idtab)
{
				//var cookieTab = getCookie("selectedTab");
				
				var tab1 = document.getElementById('block_utenti');
				var tab2 = document.getElementById('block_operatori');
				
				if(tab1.id==idtab)
				{
								tab1.style.display = 'block';
								tab2.style.display = 'none';
								document.getElementById('utenti').className = 'current'; 
								document.getElementById('operatori').className = ''; 
								document.getElementById('indicaTab').className = 'tabcurrentLeft'
				}
				
				if(tab2.id==idtab)
				{
								tab2.style.display = 'block';
								tab1.style.display = 'none';
								document.getElementById('operatori').className = 'current'; 
								document.getElementById('utenti').className = ''; 
								document.getElementById('indicaTab').className = 'tabcurrentRight'
				}
}

function switchAnyTab(idtab,allTabs)
{

				for(var i=0;i<allTabs.length;i++)
				{
								if(allTabs[i][0]==idtab)
								{
												document.getElementById(allTabs[i][0]).style.display = 'block';
												var all_classes = document.getElementById(allTabs[i][1]).className.split(" ");
												document.getElementById(allTabs[i][1]).className = all_classes[0] + " current";
								}
								else
								{
												if(document.getElementById(allTabs[i][0])) document.getElementById(allTabs[i][0]).style.display = 'none';
												if(document.getElementById(allTabs[i][1])) var all_classes = document.getElementById(allTabs[i][1]).className.split(" ");
												if(document.getElementById(allTabs[i][1])) document.getElementById(allTabs[i][1]).className = all_classes[0];
								}
				}
				
				checkXTabClick(idtab);
				
}

function setCookie( name, value) 
{
				document.cookie = name + "=" +escape( value );
}


function getCookie(name) 
{
	
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	
	return null;
}

function getMenuData(id)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=mmenu&menuid="+id,"resGetMenuData","GET");
	mmenuid = "admin_"+id;
	fadeIt(document.getElementById(mmenuid).id,0);
}

function resGetMenuData(data)
{
	fadeIn(document.getElementById(mmenuid).id,0);
	document.getElementById(mmenuid).innerHTML=data;
}

function getMenuSearchData(string)
{
	ajaxAddUrl("","site.php?id=admin&mode=popup&namefile=mmenu&sqry="+string,"resGetMenuData","GET");
	mmenuid = "admin_search_box";
	fadeIt(document.getElementById(mmenuid).id,0);
}

function resgetMenuSearchData(data)
{
	fadeIn(document.getElementById(mmenuid).id,0);
	document.getElementById(mmenuid).innerHTML=data;
}

function checkAllcheckbox(nameform, namecheck)
{
		var all_checkbox = nameform.getElementsByTagName("INPUT");
		
		for(var i=0;i<all_checkbox.length;i++)
		{
						if(all_checkbox[i].type=="checkbox" && all_checkbox[i].name==namecheck)
						{
										if(all_checkbox[i].checked==true)
										{
														all_checkbox[i].checked=false;
										}
										else
										{
														all_checkbox[i].checked=true;
										}
						}
		}
}
