// JavaScript Document
if(window.location.host == 'www.termoliweb.it')
	var template = 't';
	
if(window.location.host == 'www.termolionline.it')
	var template = 'to';

if(window.location.host == 'www.campobassoweb.it')
	var template = 'c';
	
if(window.location.host == 'www.vastoweb.com')
	var template = 'v';
	
function core(pageId)
{
	
	if(pageId == 1)
	{
		//getFlashNews();
		slideCorriere();
		setInterval('updateNews()', 300000);
	}
	else
	{
		fontSizeTransform('testo');
	}
	//colsHeight();
	rollover();
	footerBanner();
}

function hideSondaggio()
{
	var sondaggio = document.getElementById('formSondaggio');
	
	sondaggio.style.display = 'none';
	//sondaggio.style.height = '33px';
	
	var votaSondaggio = document.getElementById('votaSondaggio');
	
	votaSondaggio.onclick = function ()
	{
		sondaggio.style.display = '';
		sondaggio.parentNode.style.backgroundColor = '#f5f5f5';
		//votaSondaggio.style.color = '#900';
		var votaback = document.createTextNode('VOTA IL SONDAGGIO');		
		votaSondaggio.parentNode.replaceChild(votaback, votaSondaggio);
		return false;
	}
	
	votaSondaggio.onmouseover = function ()
	{
		sondaggio.parentNode.style.background = '#ffffff';
	}
	votaSondaggio.onmouseout = function ()
	{
		sondaggio.parentNode.style.background = '';
	}
	//sondaggio.formpollForm.style.display = 'none';
}


function hideSuegiu()
{
	var suegiu2 = document.getElementById('suegiu2'),
		suegiu = document.getElementById('suegiu');
	
	suegiu2.style.display = 'none';
	suegiu.style.height = '25px';
	
	var vediSuegiu = document.getElementById('vediSuegiu');
	
	vediSuegiu.onclick = function ()
	{
		suegiu2.style.display = '';
		/*
		var suegiuback = document.createTextNode("SU & GIU'"),
			vediA = vediSuegiu.getElementsByTagName('a');
			
		vediA[0].parentNode.replaceChild(suegiuback, vediA[0]);
		*/
		vediSuegiu.style.display = 'none';
		suegiu.style.height = '108px';
		return false;
	}
	//sondaggio.formpollForm.style.display = 'none';
}

function hideFermoPosta()
{
	var fermoposta = document.getElementById('fermoPosta');
	
	fermoposta.style.display = 'none';
	//fermoposta.style.height = '33px';
	
	var vediFermoPosta = document.getElementById('vediFermoPosta');
	
	vediFermoPosta.onclick = function ()
	{
		fermoposta.style.display = '';
		vediFermoPosta.style.display = 'none';
		//fermoposta.style.height = '168px';
		return false;
	}
	//sondaggio.formpollForm.style.display = 'none';
}


function colsHeight()
{
	var leftCol = document.getElementById('rightCol2'),
		rightCol = document.getElementById('rightCol'),
		centralCol = document.getElementById('mainCol'),
		maxHeight = Math.max(leftCol.offsetHeight, rightCol.offsetHeight);
		
	//alert(leftCol.offsetHeight);
	
	if(centralCol.offsetHeight < maxHeight)
	{
		centralCol.style.height = maxHeight + 'px';
	}
}

function popup(url, name, width, height)
{
settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width="+width+",height="+height;

MyNewWindow=window.open(url,name,settings);

return false;
}

function printPreview()
{
	var htmlHead = document.getElementsByTagName('head'),
		newStyle = document.createElement('link'),
		bodyH = document.getElementById('prova');
	
	newStyle.setAttribute('rel', 'stylesheet');
	newStyle.setAttribute('type','text/css');
	newStyle.setAttribute('href', '/css/print.css');
	newStyle.setAttribute('id', 'printCss');
	
	htmlHead[0].appendChild(newStyle);
	
	window.print();

}

function cancelPrintPreview()
{
	var printCss = document.getElementById('printCss');
	
	printCss.parentNode.removeChild(printCss);
	
}


function fontSizeTransform(id)
{
	var testo = document.getElementById(id),
		aumenta = document.getElementById('aFont'),
		diminuisci = document.getElementById('dFont');
	
	//testo.style.fontSize = '14px';
	
	aumenta.onclick = function()
	{
		if(testo.style.fontSize == '') testo.style.fontSize = '13px';
		if(testo.style.fontSize.split('px')[0] < 18)
			testo.style.fontSize = Number(testo.style.fontSize.split('px')[0]) + Number(2) + 'px';
			
		return false;
	}
	
	diminuisci.onclick = function()
	{
		if(testo.style.fontSize == '') testo.style.fontSize = '13px';
		if(testo.style.fontSize.split('px')[0] > 13)
			testo.style.fontSize = Number(testo.style.fontSize.split('px')[0]) - Number(2) + 'px';
			
		return false;
	}

}


function rollover()
{
	var allLinks = document.links;
		rolloverImage = Array();
	
	for(a=0; a<allLinks.length; a++)
	{
		if(allLinks[a].getAttribute('class') == 'rollover')
		{
			rolloverImage[a] = allLinks[a].firstChild;
			
			allLinks[a].onmouseover = function()
			{
				if(this.childNodes[0].src)
					var image = this.childNodes[0];
				else if(this.childNodes[1].src)
					var image = this.childNodes[1];
					
				//alert(image.indexOf('stampa'));
				
				if(image.src.indexOf('stampa') > 0)
					image.src = '/template/'+template+'/images/stampa.png';
				else if(image.src.indexOf('mail') > 0)
					image.src = '/template/'+template+'/images/mail.png';
				
			}
			
			allLinks[a].onmouseout = function()
			{
				if(this.childNodes[0].src)
					var image = this.childNodes[0];
				else if(this.childNodes[1].src)
					var image = this.childNodes[1];
					
				//alert(image.indexOf('stampa'));
				
				if(image.src.indexOf('stampa') > 0)
					image.src = '/images/stampa.png';
				else if(image.src.indexOf('mail') > 0)
					image.src = '/images/mail.png';
			}
		}
	}
}

function countClick(id_banner)
{
	var xmlhttp;
	
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
/*
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  alert(xmlhttp.responseText);
  }
}*/
xmlhttp.open("GET",'/library/countbanner.php?id='+id_banner,true);
xmlhttp.send(null);

return true;
}

function aggiornamentoHome()
{
	var xmlhttp;
	
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4)
	  {
	  if(xmlhttp.responseText == 1) window.location = window.location;
	  }
	}
	xmlhttp.open("GET",'/newversion/library/lastupdate.php',true);
	xmlhttp.send(null);
	
	return true;
}

function banneraTempo(type, idBanner)
{
	var xmlhttp,
		response;
	
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			response = xmlhttp.responseText;
			//alert(response);
			//return;
			
			var vPairs = new Array();
			
			vPairs = response.split('&');
			var value = new Array();
			
			
			for(var a = 0; a < vPairs.length; a++)
			{
				value[a] = vPairs[a].split('=');
			}
			
			var secondi = value[1][1] * 1000;
				
			bannerType(type,idBanner);
			setTimeout('banneraTempo('+type+','+idBanner+')', secondi);
			
		}
	}
	xmlhttp.open("GET",'/newversion/library/bannertempo.php?id='+idBanner+'&type='+type,true);
	xmlhttp.send(null);
	
	return true;
}

function bannerType(type, idBanner)
{
	var xmlhttp,
		response = document.getElementById('bannerTempo-'+idBanner);
	
		
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			response.innerHTML = xmlhttp.responseText;			
		}
	}
	xmlhttp.open("GET",'/newversion/library/bannertype.php?id='+type,true);
	xmlhttp.send(null);
	
	return true;
}

function footerBanner()
{
	var footB = document.getElementById('footerBanner'),
		incr,
		decr,
		a = -270;
	
	if(!footB)
		return;
	
	footB.onmouseover = function()
	{
		clearInterval(decr);
		incr = setInterval(increment, 10);
		//footB.style.bottom = '0';
	}
	
	footB.onmouseout = function()
	{
		clearInterval(incr);
		decr = setInterval(decrease, 10);
		//footB.style.bottom = '-270px';
	}
	
	function increment()
	{
		if(a < 0)
		{
			a += 10;
			footB.style.bottom = a + 'px';
		}
		else
		{
			clearInterval(incr);
		}
	}
	
	
	function decrease()
	{
		if(a > -270)
		{
			a -= 10;
			footB.style.bottom = a + 'px';
		}
		else
		{
			clearInterval(decr);
		}
	}

}

function updateNews()
{
	var xmlhttp,
		news = document.getElementById('news');
	
		
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			news.innerHTML = xmlhttp.responseText;			
		}
	}
	xmlhttp.open("GET",'/newversion/library/update.php',true);
	xmlhttp.send(null);
	
	return true;
}