var titoloArticoloStyle = 'font-size:22px; line-height:26px; margin-top:4px; color:#0085C2; margin-bottom:9px;'

function onContent(f){ //(C)webreflection.blogspot.com
var a,b=navigator.userAgent,d=document,w=window,
c="__onContent__",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(w[c]);
if(d[e])d[e]("DOMContentLoaded",w[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
(function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};

function replaceString(string,search,replace) {
var string = string.split(search);
result = string[0];
if (string.length > 1) {
for (var i=1; i<string.length; i++) {
var result = result + replace + string[i];
}
}
return result;
}

// Check form e-mail in home page

function CheckForm8(f) {
var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
if (!email_re.test(f.email.value)) {
alert("Inserisci un indirizzo email valido.");
f.email.focus();
return false;
}
return true;
}

/////

function aggiungiBoxNewsletter() {
var formNewsletter = document.createElement("div");
formNewsletter.innerHTML = '<table width="348" cellspacing="0" cellpadding="0" border="0">\
<tbody>\
<tr>\
<td style="background-color: #0085C2;"><p style="margin: 4px; font-size: 12px; font-family: Georgia,Times,serif; color: white; font-weight: bold;">NEWSLETTER</p></td>\
</tr>\
<tr>\
<td valign="top"><p style="margin: 6px 3px 5px; font-size: 16px; font-weight: bold; line-height: 19px; font-family: Georgia,Times,serif; color: rgb(0, 133, 194);">Iscriviti alla nostra newsletter</p></td>\
</tr>\
<tr>\
<td valign="top"><p style="margin: 3px 3px 8px; padding: 0pt; font-size: 12px; font-family: Arial,Helvetica,sans-serif; line-height: 15px;">Iscrivendoti riceverai tempestivamente tutte le ultime notizie <br />\
sul mondo della stampa digitale: hardware, software, <br />\
consumabili, ricerche di mercato, fiere, eventi e molto altro.</p>\
<form id="form1" name="form1" method="get" action="http://italiapublishers.sunnycompublishing.it/newsletter/index.php" onsubmit="return CheckForm8(this);" style="margin:12px 3px 10px; font-family:Arial, Helvetica, sans-serif; font-size:12px">\
<input name="email" type="text" style="width:220px;" onblur="if (this.value==\'\'){ this.value=\'Tuo indirizzo e-mail\'}" onclick="if(this.value==\'Tuo indirizzo e-mail\'){this.value=\'\'}" title="Inserici il tuo indirizzo e-mail" value="Tuo indirizzo e-mail" />&nbsp;&nbsp;\
<input type="submit" id="submit" value="OK" style="width:60px;" />\
</form>\
</td>\
</tr>\
<tr>\
<td style="background-color: #0085C2; height: 4px;"></td>\
</tr>\
</tbody>\
</table>';
var formNewsletterStyle = 'margin:0 0 10px; padding:0; width:348px; background-color:white;';
//document.getElementById('col_3_large').appendChild(banner348x120);
document.getElementById('col_3_large').insertBefore(formNewsletter,document.getElementById('eventi'));
formNewsletter.setAttribute('style',formNewsletterStyle);
formNewsletter.style.cssText = formNewsletterStyle;
}

/////

function aggiungiBoxIssuu() {
var BoxIssuu = document.createElement("div");
BoxIssuu.innerHTML = '<table width="348" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="background-color:#0085C2;"><p style="margin: 4px; font-size: 12px; font-family:Arial, Helvetica, sans-serif; color: white; font-weight: bold;">L\'ultimo uscito...</p></td></tr><tr><td valign="top"><object style="width:100%;height:242px;margin-top:4px;"><param name="movie" value="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf?mode=embed&amp;folderId=465bbb03-d72b-431c-825f-57ba53d05ca6&amp;layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml" /><param name="allowFullScreen" value="true" /><embed src="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf" type="application/x-shockwave-flash" allowFullScreen="true" style="width:100%;height:242px;margin-top:4px;" flashvars="mode=embed&amp;folderId=465bbb03-d72b-431c-825f-57ba53d05ca6&amp;layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Flight%2Flayout.xml" /></object></td></tr><tr><td style="background-color:#0085C2; height: 4px;"><p style="margin: 4px 5px 4px 4px; font-size: 9px; font-family:Arial, Helvetica, sans-serif; color: white; font-weight: bold; text-align:right; text-transform:uppercase;"><a href="http://www.italiapublishers.com/page.do?id=24" style="text-decoration:none; color:white;">ARCHIVIO NUMERI PRECEDENTI</a></p></td></tr></tbody></table>';
var BoxIssuuStyle = 'margin:0 0 10px; padding:0; width:348px; height:290px; background-color:white;';
//document.getElementById('col_3_large').appendChild(banner348x120);
document.getElementById('col_3_large').insertBefore(BoxIssuu,document.getElementById('eventi'));
BoxIssuu.setAttribute('style',BoxIssuuStyle);
BoxIssuu.style.cssText = BoxIssuuStyle;
}

/////

function aggiungiBoxHighlight() {
//spostaInBasso('content_focus','276px');
//spostaInBasso('content_right','276px');
// preparazione elemento content
//var contenuto = document.getElementById('content');
//var contenutoStyle = 'position:relative;'
//contenuto.setAttribute('style',contenutoStyle);
//contenuto.style.cssText = contenutoStyle;
// aggiunta nuovo banner con if relativo alla tipologia di pagina in cui ci si trova
var banner348x120 = document.createElement("div");
banner348x120.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="348">\
<tbody>\
<tr>\
<td colspan="2" style="background-color: #0085c2;">\
<p class="box_titolo" style="font-size: 12px; margin: 4px 4px; font-family: Georgia, Times, serif; color: white; font-weight: bold;">HIGHLIGHT</p>\
</td>\
</tr>\
<tr>\
<td colspan="2" valign="top">\
<p style="font-size: 16px; font-weight: bold; margin: 6px 3px 5px 3px; line-height: 19px; font-family: Georgia, Times, serif;"><a href="http://italiapublishers.com/italiapub/article.do?id=140" target="_self" style="color: #0085c2; text-decoration: none;">Report Viscom Italia 2009</a></p>\
</td>\
</tr>\
<tr>\
<td valign="top" width="112">\
<div style="margin: 6px 12px 8px 3px; overflow: hidden; width: 96px; height: 55px; display: block;"><a href="http://italiapublishers.com/italiapub/article.do?id=140" target="_self"><img src="http://www.italiapublishers.com/italiapub/files/articles/i/logoviscom2009.gif" style="margin: -4px 0 0 0;" border="0" width="96" /></a></div>\
</td>\
<td valign="top" width="auto">\
<p style="font-size: 12px; margin: 3px 3px 8px 0; font-family: Arial, Helvetica, sans-serif; line-height: 15px; padding: 0;">In un anno difficile, segnali positivi arrivano da Viscom 2009. La fiera della comunicazione visiva ha dimostrato quest\'anno quanto il comparto del wide format sia in costante fermento.</p>\
</td>\
</tr>\
<tr>\
<td colspan="2" style="background-color: #0085c2; height: 4px;"></td>\
</tr>\
</tbody>\
</table>';
/*if (window.location.toString().indexOf('/index.do') != -1) {
var banner300x250Style = 'margin:0; padding:6px 0 0 0; position:absolute; width:353px; height:256px; right:0; text-align:center; top:4px; background-color:#EEEEEE;';
document.getElementById('content').appendChild(banner300x250);
} else if (window.location.toString().indexOf('/article.do') != -1 || window.location.toString().indexOf('/news.do') != -1 || window.location.toString().indexOf('/area.do') != -1 || window.location.toString().indexOf('/issue.do') != -1) {
eliminaElemento('eventi');
var banner300x250Style = 'margin:0; padding:6px 0 0 0; position:absolute; width:353px; height:256px; top:12px; right:0; text-align:center; background-color:#EEEEEE;';
document.getElementById('ie6_right').appendChild(banner300x250);
}*/
var banner348x120Style = 'margin:0 0 10px; padding:0; width:348px; background-color:white;';
//document.getElementById('col_3_large').appendChild(banner348x120);
document.getElementById('col_3_large').insertBefore(banner348x120,document.getElementById('eventi'));
banner348x120.setAttribute('style',banner348x120Style);
banner348x120.style.cssText = banner348x120Style;
}


/////

function eliminajsessionid(){
	var homelink = document.getElementById('home_link').getElementsByTagName('a')[0].getAttribute('href');
	//console.log(homelink);
	if (homelink.indexOf('jsessionid') != -1 && navigator.cookieEnabled) {
		//console.log("hi");
		window.location.reload();
	}
}

/////


function currentSite(){
var currentSite = window.location.toString().slice(7).split('/')[0];
if (currentSite.indexOf('www') != -1) {
var currentSite = currentSite.slice(4);
}
if (currentSite.toString() == 'italiapublishers.com') {
var currentSite = 'Italia Publishers';
} else if (currentSite == 'comunicandoweb.com') {
var currentSite = 'Comunicando';
} else if (currentSite == 'largeformat.it') {
var currentSite = 'LARGEformat';
}
return currentSite;
}

function addCopyright() {
var riproduzioneRiservata = document.createElement("div");
riproduzioneRiservata.innerHTML = '© RIPRODUZIONE RISERVATA';
var riproduzioneRiservataStyle = 'float:left; clear:both; font-size:10px; font-family:Arial; margin:6px 0 6px 0;';
riproduzioneRiservata.setAttribute('style',riproduzioneRiservataStyle);
riproduzioneRiservata.style.cssText = riproduzioneRiservataStyle;
document.getElementById('content_main').getElementsByTagName('div')[0].appendChild(riproduzioneRiservata);
}

function checkTitle() {
var articleTitle = document.getElementsByTagName('h1')[0].firstChild.nodeValue.replace('<br>',' ');
document.title = articleTitle + ' - ' + currentSite();
}

function changeSectTitle() {
var sezioni = document.getElementById('menu_sezioni_body').getElementsByTagName('a');
for (var i = 0; i <= sezioni.length; i++) {
if (sezioni[i].className != undefined){
if (sezioni[i].className == 'selected') {
var sezioneAttiva = sezioni[i].innerHTML;
document.title = sezioneAttiva + ' - ' + currentSite();
return;
}
}
}
}

function changeEdTitle () {
var campoAutore = document.getElementById('content_main').getElementsByTagName('div')[1].getElementsByTagName('div')[0];
var campoTitolo = document.getElementById('content_main').getElementsByTagName('h1')[0];
var titolo = campoAutore.innerHTML.replace(/\s{2}/g,'<br>');
//var autore = 'Lorenzo Villa'
campoAutore.innerHTML = '';
//campoAutore.setAttribute('style','margin-bottom:18px;');
campoTitolo.innerHTML = titolo;
checkTitle();
}

function checkTitoliArticoliHome () {
if (document.getElementById('content_main') != null) {
var titoliArticoliHome = document.getElementById('content_main').getElementsByTagName('h1');
for (var k = 0; k < titoliArticoliHome.length; k++) {
var titoloArticolo = titoliArticoliHome[k].getElementsByTagName('a')[0];
titoloArticolo.innerHTML = titoloArticolo.innerHTML.replace('  ','<br>');
}
} else {
setTimeout("checkTitoliArticoliHome ()",200);
}
}

function checkTitoloArticolo () {
var titoloArticolo = document.getElementsByTagName('h1')[0];
titoloArticolo.innerHTML = titoloArticolo.innerHTML.replace('  ','<br>');
}

function checkTitoliNewsHome () {
if(document.getElementById('news_scroller')) {
var titoliNewsHome = document.getElementById('news_scroller').getElementsByTagName('h1');
for (var k = 0; k < titoliNewsHome.length; k++) {
titoliNewsHome[k].getElementsByTagName('a')[0].innerHTML = titoliNewsHome[k].getElementsByTagName('a')[0].innerHTML.replace(/\s{2}/g,'<br>');
}
} else {
setTimeout("checkTitoliArticoliHome ()",200);
}
}

// RINOMINA PAGINA START

onContent(function() {
setTimeout('eliminajsessionid()','1200');
setTimeout('sistemaTutto()','1600');
setTimeout('aggiungiBoxNewsletter();','1600'); // CREAZIONE HIGHLIGHT
setTimeout('aggiungiBoxIssuu();','1600'); // CREAZIONE HIGHLIGHT
});

// RINOMINA PAGINA END

// SISTEMA TUTTO

function sistemaTutto() {
if (window.location.toString().indexOf('/article.do') != -1 || window.location.toString().indexOf('/news.do') != -1) {
checkTitoloArticolo();
addCopyright();
checkTitle();
}
if (window.location.toString().indexOf('/index.do') != -1 || window.location.toString() == 'http://www.italiapublishers.com/' || window.location.toString() == 'http://italiapublishers.com/') {
document.title = 'Italia Publishers - Increasing Knowledge in Printed Communication';
checkTitoliArticoliHome();
checkTitoliNewsHome();
}
if (window.location.toString().indexOf('/area.do') != -1) {
changeSectTitle();
checkTitoliArticoliHome();
}

if (window.location.toString().indexOf('/issue.do') != -1) {
changeEdTitle();
}
}