function
formatta_testo(w_text)
{
// vocals
w_text = w_text.replace(/…/g, "...");
w_text = w_text.replace(/à/g, "&agrave;");
		w_text = w_text.replace(/à/g,"&agrave;");
		w_text = w_text.replace(/è/g, "&egrave;");
		w_text = w_text.replace(/è/g,"&egrave;");
		w_text = w_text.replace(/ì/g, "&igrave;");
		w_text = w_text.replace(/ì/g,"&igrave;");
		w_text = w_text.replace(/ò/g, "&ograve;");
		w_text = w_text.replace(/ò/g,"&ograve;");
		w_text = w_text.replace(/ù/g, "&ugrave;");
		w_text = w_text.replace(/ù/g,"&ugrave;");

		w_text = w_text.replace(/€/g,"eeuro;");
		w_text = w_text.replace(/€/g,"eeuro;");

		w_text = w_text.replace(/£/g,"epound;");
		w_text = w_text.replace(/£/g,"epound;");

		return w_text;

}

function multa_fede(){
	iniData= new Date(2006,0,1); // data inizio sequenza mesi-1 es. set=8
	oggi= new Date();
	milDif=(oggi-iniData)
	giorni=parseInt(milDif/86400000);
	multa=Math.round(((giorni*350000)/1000000)*100)/100;
	anno=oggi.getFullYear().toString();
        anno=anno.substr(2,2);
        testo=oggi.getUTCDate()+'-'+(oggi.getUTCMonth()+1)+'-'+anno+'<br>totale: '+multa+' milioni &euro;';

if(document.getElementById('multa_fede'))
	document.getElementById('multa_fede').innerHTML = testo;
}

function scambia_multiple (f, g, v, i, tab, type) {
//   viscom = document.getElementById(f).style.display;
//   if(viscom == "none") 
     if(type == 0) 
      {
      document.getElementById(f).style.display = 'block';
      document.getElementById(g).style.display = 'block';
      document.getElementById(v).style.display = 'none';
      document.getElementById(i).style.display = 'none';
      document.getElementById(tab).className = 'form1_tab';
      }
   else
      {
      document.getElementById(v).style.display = 'block';
      document.getElementById(i).style.display = 'block';
      document.getElementById(f).style.display = 'none';
      document.getElementById(g).style.display = 'none';
      document.getElementById(tab).className = 'form2_tab';
      }
}

function scambia (f, g, v, i, type) {
//   viscom = document.getElementById(f).style.display;
//   if(viscom == "none") 
     if(type == 0) 
      {
      document.getElementById(f).style.display = 'block';
      document.getElementById(g).style.display = 'block';
      document.getElementById(v).style.display = 'none';
      document.getElementById(i).style.display = 'none';
      document.getElementById("the_tab").className = 'form1_tab';
      }
   else
      {
      document.getElementById(v).style.display = 'block';
      document.getElementById(i).style.display = 'block';
      document.getElementById(f).style.display = 'none';
      document.getElementById(g).style.display = 'none';
      document.getElementById("the_tab").className = 'form2_tab';
      }
}


//select all
function select_all()
{
var text_val=eval("document.modulo.textarea");
text_val.focus();
text_val.select();
}

/*------------------------------------------------------------------------------*/
/*------------ YOU tube functions for last video -------------------------------*/
/*------------------------------------------------------------------------------*/
function appendScriptTag(scriptSrc, scriptId, scriptCallback) 
	{
	// Remove any old existance of a script tag by the same name
	var oldScriptTag = document.getElementById(scriptId);
	if (oldScriptTag) 
		{
		oldScriptTag.parentNode.removeChild(oldScriptTag);
		}

	// Create new script tag
	var script = document.createElement('script');
	script.setAttribute('src', scriptSrc + '&alt=json-in-script&callback=' + scriptCallback);
	script.setAttribute('id', scriptId);
	script.setAttribute('type', 'text/javascript');
	document.getElementsByTagName('head')[0].appendChild(script);
	};

function listVideos () 
	{
	var queryUrl = 'http://gdata.youtube.com/feeds/api/users/staffgrillo/uploads?orderby=updated&vq=+-eng+-pdt&start-index=1&max-results=1';
	if (queryUrl ) 
		{
		appendScriptTag(queryUrl, 
                         'searchResultsVideoListScript', 
                         'listVideosCallback');
		}
	else 
		{
		alert('Unknown feed type specified');
		}
	};

function listVideosCallback(data) 
	{
	//Funzione modificata da Pier Antonio per la nuova versione del blog
	// Stores the json data returned for later lookup by entry index value
//	jsonFeed_ = data.feed;
	if(document.getElementById('searchResultsVideoList'))
		{
		var resultsTableContainer = document.getElementById('searchResultsVideoList');
		if(resultsTableContainer)
			{
			content = ''; 
			if(data.feed.entry)
				{
				for (var i = 0, entry; entry = data.feed.entry[i]; i++) 
					{
					content += '<h3>I video di beppegrillo.it</h3>' + 
					'<div id="anteprima"><div id="em">' + entry.media$group.media$title.$t.replace(' beppegrillo.it', '') + '</div><a href="http://www.youtube.com/staffgrillo#baseDiv" target="_blank">' +
					'<img src="http://www2.beppegrillo.it/php/overlay_script/video_sidebar_320.php?image=' + entry.media$group.media$thumbnail[3].url + '?time=' + '" alt="' + entry.media$group.media$title.$t.replace(' beppegrillo.it', '') + '"></a></div>';
					}
				}
			resultsTableContainer.innerHTML = content;
			}
		}
	};

function popup(Site)
{
window.open(Site,'PopupName','toolbar=no,statusbar=no,location=no,scrollbars=yes,resizable=yes,width=280,height=220')
}


/* Nasconde in div */
function invisibile(div) {
var a = document.getElementById(div);        
a.style.display = 'none';
}

/*--------------------------------------------------------------------*/
/*----------------------------- AJAX ---------------------------------*/
/*--------------------------------------------------------------------*/
var myRequest = null;
var myDiv = null;
var myElement = null;

function 
CreateXmlHttpReq2(handler) 
	{
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
	} // CreateXmlHttpReq2
function 
myHandler2(the_div) 
	{
    if(myRequest.readyState == 4 && myRequest.status == 200) 
		{
        e = document.getElementById(myDiv);
//alert(myRequest.responseText);
        e.innerHTML = myRequest.responseText;
		var curdate = new Date();		
		
		//right bar banner rotation
		banner_top_third_column = new Array(2);

		banner_top_third_column[0] = "<form name='link_grillorama_catalog' action='http://grillorama.beppegrillo.it/catalog/index.php' method='post' onsubmit='this.email_address.value = getCookie(\"commenter_email\");this.email_ck.value = getCookie(\"email_ck\"); countClick(\"Grillorama\", \"\", \"barra_pdt_intestazione\");'><input type='hidden' id='email_address' name='email_address' value=''><input type='hidden' id='email_ck' name='email_ck' value=''><input type='image' src='http://www.beppegrillo.it/immagini/grillorama_210.jpg'></form>";

		banner_top_third_column[1] = "<form name='cart_quantity' action='http://grillorama.beppegrillo.it/catalog/shopping_cart.php?action=show_cart' method='post' onsubmit='this.email_address.value = getCookie(\"commenter_email\");this.email_ck.value = getCookie(\"email_ck\"); countClick(\"Grillorama\", \"\", \"barra_pdt_intestazione\");'><input type='hidden' name='products_id' value='122'><input type='hidden' name='cart_quantity' value='1'><input name='image' type='image' src='http://www.beppegrillo.it/immagini/minibanner-grilloisback.jpg'><input type='hidden' id='email_address' name='email_address' value=''> <input type='hidden' id='email_ck' name='email_ck' value=''></form>";

		index_banner_top_third_column = Math.floor(Math.random() * banner_top_third_column.length);		
		document.getElementById("banner_top_terza_colonna").innerHTML = banner_top_third_column[index_banner_top_third_column];
		//jQuery("#banner_top_terza_colonna").html(banner_top_third_column[index_banner_top_third_column]);
		
		//get tzeTze right bar
		if (jQuery && document.getElementById('tzetze_ajax_container'))
			jQuery("#tzetze_ajax_container").load('http://' + document.domain + '/sidebar_external.html?unique=' + curdate.getTime());		
		//alert(myReload);
		if (myReload)
			{
				document.location.reload(true);	
			}
		}
	}

function 
get_cont(url, the_div, doLocationReload) 
	{
//alert(url);
	myDiv = the_div;
	myReload = doLocationReload;
	myRequest = CreateXmlHttpReq2(myHandler2);
	myRequest.open("GET", url);
	myRequest.send(null);
	}
/*------------------------ AJAX MULTIPLE -----------------------------*/
var myRequestMultiple = null;

function 
CreateXmlHttpReqMultiple(handler, local_div, doLocationReload) 
	{
	CreateXmlHttpReqMultiple.local_div = local_div;
	CreateXmlHttpReqMultiple.doLocationReload = doLocationReload;
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
	} // CreateXmlHttpReqMultiple

function 
myHandlerMultiple() 
	{
	if(myRequestMultiple.readyState == 4) 
		{
		e = document.getElementById(CreateXmlHttpReqMultiple.local_div);
		e.innerHTML = myRequestMultiple.responseText;
		
		//get latest post from MoVimento
		var curdate = new Date();		
		if (jQuery)
			{
				jQuery("#lastPostFromMovimento").load('http://' + document.domain + '/last_post_for_blog.html?unique=' + curdate.getTime());
			}
		if(CreateXmlHttpReqMultiple.doLocationReload)
			{
			document.location.reload(true);	
			}
		}
	} // myHandlerMultiple

function 
get_cont_multiple(url, the_div, doLocationReload) 
	{
	myRequestMultiple = CreateXmlHttpReqMultiple(myHandlerMultiple, the_div, doLocationReload);
	myRequestMultiple.open("GET", url);
	myRequestMultiple.send(null);
	} // get_cont_multiple

var myRequestMultipleHeader = null;
function 
CreateXmlHttpReqMultipleHeader(handler, local_div, doLocationReload) 
	{
	CreateXmlHttpReqMultipleHeader.local_div = local_div;
	CreateXmlHttpReqMultipleHeader.doLocationReload = doLocationReload;
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
	} // CreateXmlHttpReqMultipleHeader
function 
myHandlerMultipleHeader() 
	{
	if(myRequestMultipleHeader.readyState == 4) 
		{
		e = document.getElementById(CreateXmlHttpReqMultipleHeader.local_div);
		e.innerHTML = myRequestMultipleHeader.responseText;

var x = e.getElementsByTagName("script");   
   for(var i=0;i<x.length;i++)  
   {  
       eval(x[i].text);  
   }  
		if(CreateXmlHttpReqMultipleHeader.doLocationReload)
			{
			document.location.reload(true);	
			}
		}
	} // myHandlerMultipleHeader
function 
get_cont_multiple_header(url, the_div, doLocationReload) 
	{
/*	myRequestMultipleHeader = CreateXmlHttpReqMultipleHeader(myHandlerMultipleHeader, the_div, doLocationReload);
	myRequestMultipleHeader .open("GET", url);
	myRequestMultipleHeader .send(null);
*/
banners = new Array();

banners[0] = "<a onclick=\"countClick('Kindle', 'http://www.amazon.it/gp/product/B0051QVF7A/ref=as_li_qf_sp_asin_tl?ie=UTF8&tag=blodibepgri-21&linkCode=as2&camp=3370&creative=23322&creativeASIN=B0051QVF7A', 'banner_home_top');\" href=\"http://www.amazon.it/gp/product/B0051QVF7A/ref=as_li_qf_sp_asin_tl?ie=UTF8&tag=blodibepgri-21&linkCode=as2&camp=3370&creative=23322&creativeASIN=B0051QVF7A\" target=\"_blank\"><img alt=\"Kindle\" src=\"http://www.beppegrillo.it/immagini/banner-kindle-giornali.jpg\" /></a>";



index = Math.floor(Math.random() * banners.length);
document.getElementById(the_div).innerHTML=banners[index];

	} // get_cont_multiple_header

var myRequestMultipleHeaderDown = null;
function 
CreateXmlHttpReqMultipleHeaderDown(handler, local_div, doLocationReload) 
	{
	CreateXmlHttpReqMultipleHeaderDown.local_div = local_div;
	CreateXmlHttpReqMultipleHeaderDown.doLocationReload = doLocationReload;
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
	} // CreateXmlHttpReqMultipleHeaderDown
function 
myHandlerMultipleHeaderDown() 
	{
	if(myRequestMultipleHeaderDown.readyState == 4) 
		{
		e = document.getElementById(CreateXmlHttpReqMultipleHeaderDown.local_div);
		e.innerHTML = myRequestMultipleHeaderDown.responseText;
		if(CreateXmlHttpReqMultipleHeaderDown.doLocationReload)
			{
			document.location.reload(true);	
			}
		}
	} // myHandlerMultipleHeaderDown
function 
get_cont_multiple_header_down(url, the_div, doLocationReload) 
	{
	myRequestMultipleHeaderDown = CreateXmlHttpReqMultipleHeaderDown(myHandlerMultipleHeaderDown, the_div, doLocationReload);
	myRequestMultipleHeaderDown .open("GET", url);
	myRequestMultipleHeaderDown .send(null);
	} // get_cont_multiple_header_down

/*------------------------- FINE AJAX --------------------------------*/

function creadata() {
function crea() 
{
  for (i = 0; i<crea.arguments.length; i++)
    this[i + 1] = crea.arguments[i];
}

var mesi = new crea('Gennaio','Febbraio','Marzo',
    'Aprile','Maggio','Giugno','Luglio','Agosto','Settembre',
    'Ottobre','Novembre','Dicembre');
var date = new Date();
var gg  = date.getDate();
var mese = date.getMonth()+1;
var yy = date.getYear();
var yyyy = (yy < 1000) ? yy + 1900 : yy;

document.write(gg + " " + mesi[mese] + " " + yyyy);
}

function
countClick(company, company_url, from) 
        {
        var elImage = document.createElement('img');
        elImage.setAttribute('id', 'count_' + parseInt(Math.random()*99999999));
        elImage.setAttribute('alt', '');
        elImage.setAttribute('src', 'http://www.beppegrillo.it//count_click.php?company=' + company + '&company_url=' + company_url + '&from=' + from + '&cb=' + parseInt(Math.random()*99999999));
        elImage.style.display = 'none';
        document.body.appendChild(elImage);
        return true;
        } // countClick

/****
* Banner Ad Rotater v3.02
* Anarchos > anarchos3@hotmail.com
* http://anarchos.xs.mw/bannerad.phtml
**/

function Banner(refreshTime, width, height, altText, start, random){
	this.objName = "bannerAd" + (Banner.count++);
	eval(this.objName + "=this");
	if (!refreshTime) this.refreshTime = 5000; else this.refreshTime = refreshTime*1000;
	if (!width) this.width = 776; else this.width = width;
	if (!height) this.height = 44; else this.height = height;
	if (random == null) this.random = 1; else this.random = random;
	this.altText = altText;
	this.ads = [];
	if (start) this.currentAd = start-1; else start = null;
	this.mySize = 0;

	this.Ad = function(src, href, target, mouseover) {
		var tempImage = new Image();
		tempImage.src = src;
		this.ads[this.mySize] = new Object();
		var ad = this.ads[this.mySize];
		ad.src = src;
		if (typeof(target) == "undefined" || target == null) ad.target = "_self"; else ad.target = target;
		ad.href = href;
		ad.mouseover = mouseover;
		this.mySize++;
	}

	this.link = function(){
		var	ad = this.ads[this.currentAd];
		if (ad.target == "_self"){
			location.href = ad.href;
		}
		else if (ad.target == "_blank" || ad.target == "_new"){
			open(ad.href,this.objName + "Win");
		}
		else top.frames[ad.target].location.href = ad.href;
	}

	this.showStatus = function(){
		var ad = this.ads[this.currentAd];
		if (ad.mouseover) status = ad.mouseover;
		else status = ad.href;
	}

	this.randomAd = function(){
		var n;
		do { n = Math.floor(Math.random() * (this.mySize)); } 
		while(n == this.currentAd);
		this.currentAd = n;
	}

	this.output = function(){
		var tempCode = "";
		if (this.mySize > 1){
			if (this.currentAd == null) this.randomAd();
			if (this.currentAd >= this.mySize) this.currentAd = this.mySize - 1;
			tempCode = '<a href="javascript:'+this.objName+'.link();"';
			tempCode += ' onMouseOver="' + this.objName + '.showStatus(); return true"';
			tempCode += ' onMouseOut="status=\'\';return true">';
			tempCode += '<img src="' + this.ads[this.currentAd].src + '" width="' + this.width;
			tempCode += '" name="' + this.objName + 'Img" height="' + this.height + '" ';
			if (this.altText) tempCode += 'alt="'+this.altText + '" ';
			tempCode += 'border="0" /></a>';
			document.write(tempCode);
			this.nextAd();
		} else document.write("Error: two banners must be defined for the script to work.");
	}

	this.newAd = function(){
		if (!this.random){	
			this.currentAd++;
			if (this.currentAd >= this.mySize)
			   this.currentAd = 0;
		}
		else {
			this.randomAd();
		}
		this.nextAd();
	}

	this.nextAd = function(){
		document.images[this.objName+ 'Img'].src = this.ads[this.currentAd].src;
		setTimeout(this.objName+'.newAd()',this.refreshTime)
	}
}
Banner.count = 0;

/* Funzioni per TzeTze contatore */
function tzetzeScore(scoreButton, URL) {
	window.buttonToUpdate = scoreButton;
	scoreButton.style.backgroundImage = "url('http://www.beppegrillo.it/immagini/immagini/scoring-pending.gif')";
	var elscript = document.createElement('script');
	elscript.type = 'text/javascript';
	elscript.setAttribute('alt', '');
	elscript.setAttribute('src', 'http://www.tzetze.it/php/insert_vote_tzetze.php?url=' + URL + '&callback=leggi_voto&cb=' + parseInt(Math.random()*99999999));
	document.body.appendChild(elscript);
	scoreButton.onclick = "function () { return false }";
	}

function
leggi_voto(data, URL)
	{
	scoreButton = window.buttonToUpdate;
	scoreButton.style.backgroundImage = "url('http://www.beppegrillo.it/immagini/immagini/scoring-scored.gif')";
	// alert("numero voti " + data.scores);
	var sp1 = document.createElement("span");
	sp1.setAttribute("id", "newSpan");
	var sp1_content = document.createTextNode("voti: " + data.scores);
	/*sp1.style.backgroundColor = "#EFEFEF";
	sp1.style.border = "1px solid #c1c1c1";
	sp1.style.fontFamily = "Arial";
	sp1.style.fontSize = "10px";
	sp1.style.padding = "3px 2px 0px 2px";
	sp1.style.marginRight = "3px";*/
	sp1.appendChild(sp1_content);
	var sp2 = scoreButton;
	var parentDiv = sp2.parentNode;
	parentDiv.insertBefore(sp1, sp2.nextSibling );
	}
	


/* Contatore Follower Social Media */
function writeSocialCounter(data)
	{
		var counter = "";
		
		//Facebook
		if(data.likes)
			counter = data.likes;
		//Twitter
		if(data.followers_count)
			counter = data.followers_count;
		//Youtube
		if(data.entry)
			if(data.entry.yt$statistics.subscriberCount)
				counter = data.entry.yt$statistics.subscriberCount;
		
		//Write results
		if(counter != "")
			document.write("<strong>" + counter + "</strong>");
	}
