// JavaScript Document
XMLFILE = '/rssAsca.xml';
IE = (document.all) ? true : false;

count = 0;
//MY_RSS = new Array();

sx = 0;
COMMENTI_MAXCHARS = 3000;
STX = false;
VX = false;

function pagina(pagz)
	{
	var url = 'http://www.iltribuno.com' + 	pagz;
	document.location.href = url;	
	}

function getRss()
	{
	var url = 'http://www.dire.it/rss.php?canale=3';
	var Xreq = XRequest();
	alert(Xreq);
	Xreq.onreadystatechange = function()
			{
			if (Xreq.status == 200) {
			//xmlz = Xreq.responseText;
				var rtx = Xreq.responseText;
				//alert(rtx);
				} 
			}
    Xreq.open('GET', url, true);
   	Xreq.send(null);
	}
	
function getXmlNewsData()
	{
	/*
	var xmlDoc;
	if (IE) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); }
	else { xmlDoc=document.implementation.createDocument("","",null); }
	xmlDoc.async=false;
	var filez = '/rssAsca.xml?rid=' + (Math.random() * 999999999999999);
	xmlDoc.load(filez);
	
	var t = 0;

	ptx = xmlDoc.getElementsByTagName('item');
	for (var i = 0; i < ptx.length; i++)
		{
		var titolo = ptx[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;	
		var linkz = ptx[i].getElementsByTagName("link")[0].childNodes[0].nodeValue;		
		//var desk = ptx[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;		
		MY_RSS.push('<p><a href="' + linkz + '" target="_blank" title="Asca: ' + titolo + '">' + titolo + '</a></p>');
		t++;
		//if (t > 3) { break; }
		}
		*/
	pompa();	
	}

function pompa()
	{

	var htx = '';	
	var i;
	var a;
	var c =	document.getElementById('tribuno_news');
	c.style.opacity = 1;
	c.style.filter = 'alpha(opacity=100)';
	/*for (i = 0; i < 1; i++)
		{
		a = (count + i);
		if (MY_RSS[a]) { htx = MY_RSS[a]; }
		}*/
	if 	(MY_RSS[count]) { htx = MY_RSS[count]; }
		
	count = count + 1;
	//my(MY_RSS.length < 1) { return; }
	
	if (count  >= (MY_RSS.length - 1)) { count = 0; pompa(); }	
	if (htx != '')
		{
		c.innerHTML = htx;
		}
	sx = 10;
	
	STX = setTimeout( "cambiaRSS()", 4000 );
	}

function cambiaRSS()
	{
	var c =	document.getElementById('tribuno_news');
	c.style.opacity = (sx/10);
	c.style.filter = 'alpha(opacity=' + (sx * 10) + ')';
	sx--;
	if (sx > 0) { STX = setTimeout("cambiaRSS()",100); }
	else 
		{ 
		clearTimeout(STX);
		if (VX) { clearTimeout(VX) };
		c.style.opacity = 0;
		c.style.filter = 'alpha(opacity=0)';
		VX = setTimeout("pompa()",500);
		}
	}

function checkCommento()
	{
	var c = document.getElementById('commento').value;
	var tx = c.length;
	var totz = (COMMENTI_MAXCHARS - tx);
	if (totz < 0) { totz = 0; }
	document.getElementById('charz').innerHTML = 'Caratteri rimanenti: <strong>' + totz + '</strong>';
	if (tx > COMMENTI_MAXCHARS)
		{
		document.getElementById('commento').value = substr(document.getElementById('commento').value,0,COMMENTI_MAXCHARS);
		}
		
	}

function addCommento()
	{
	var nome = document.getElementById('nome').value;
	if ((nome == '') || (nome == 'undefined') || (nome == null)) { alert('Manca il nome'); return; }
	var email = document.getElementById('email').value;
	var commento = document.getElementById('commento').value;
	if ((commento == '') || (commento == 'undefined') || (commento == null)) { alert('Manca il commento'); return; }
	var securecode = document.getElementById('securecode').value;
	if ((securecode == '') || (securecode == 'undefined') || (securecode == null)) { alert('Manca il codice di sicurezza'); return; }	
	var secure_id = document.getElementById('secure_id').value;
	if ((secure_id == '') || (secure_id == 'undefined') || (secure_id == null)) { alert('Errore codice di sicurezza'); return; }	
	var url = '/commenti.php';
	atx = ''
	atx += '&idx=' + IDX;
	atx += '&nome=' + escape(encodeURI(nome));
	atx += '&email=' + escape(encodeURI(email));
	atx += '&commento=' + escape(encodeURI(commento));
	atx += '&securecode=' + escape(encodeURI(securecode));
	atx += '&secure_id=' + escape(encodeURI(secure_id));
	
	var Xreq = new XRequest();
	Xreq.onreadystatechange = function()
			{
			if (Xreq.readyState == 4) { if (Xreq.status == 200) 
				{
				var rtx = Xreq.responseText;
				//if (rtx.substr(0,1) == "1") 
				//	{ 
				//	var ptx = LINKZ + '&rid=' + Math.random() * 9999999999999 + '#commenti';
				//	document.location.href=ptx; 
				//	}
				//	else { alert('Errore: ' + rtx); }	
				parseCommento(rtx);
				} } 		
			}
	Xreq.open('POST', url, true);
  	Xreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	Xreq.setRequestHeader("Content-length", atx.length);
   	Xreq.setRequestHeader("Connection", "close");
   	Xreq.send(atx);
	
	}

function parseCommento(rtx)
	{
	var tx = '';
	var ptx = rtx.substr(0,1);
	if (ptx == '1')
		{
		alert('Errore compilazione campi');	
		return;	
		}
	else 
		{
		if (ptx == '2')
			{
			alert('Codice conferma non valido.');	
			return;	
			}
		else
			{
			if (ptx == '3')
				{
				alert('Errore dati.');	
				return;	
				}
			else
				{
				 tx += ' <table width="100%" border="0" cellspacing="0" cellpadding="0" class="editoriale_tab">';
				 tx += ' <tr>  <td class="editoriale_bar"><img src="/img/commenti_2.png" alt="Commenti" width="150" height="20" /></td>';
				 tx += ' </tr>   <tr> <td valign="top" style="padding:4px;">\n';
				 tx += rtx;
				 tx += '\n</td></tr></table>\n';
				 document.getElementById('commenti').innerHTML = tx;
 				 document.getElementById('securecode').value = '';	
				 document.getElementById('commento').value = '';	
				 var o = document.getElementById('commenti');
				 if (o) 
				 	{
					var p = findPosY(o);
					window.scrollTo(0,p);
					}
				 else 
				 	{ 
				 	alert('Commento inserito con successo');
				 	}
				}
			}
		}
	}




function addCommentoBlog()
	{
	if (!document.getElementById('idArticolo')) { alert('Errore dati'); return; }
		
	var nome = document.getElementById('nome').value;
	if ((nome == '') || (nome == 'undefined') || (nome == null)) { alert('Manca il nome'); return; }
	var email = document.getElementById('email').value;
	var commento = document.getElementById('commento').value;
	if ((commento == '') || (commento == 'undefined') || (commento == null)) { alert('Manca il commento'); return; }
	var securecode = document.getElementById('securecode').value;
	if ((securecode == '') || (securecode == 'undefined') || (securecode == null)) { alert('Manca il codice di sicurezza'); return; }	
	var secure_id = document.getElementById('secure_id').value;
	if ((secure_id == '') || (secure_id == 'undefined') || (secure_id == null)) { alert('Errore codice di sicurezza'); return; }	
	var url = '/commentiBlog.php';
	atx = ''
	atx += '&idx=' + document.getElementById('idArticolo').value;
	atx += '&nome=' + escape(encodeURI(nome));
	atx += '&email=' + escape(encodeURI(email));
	atx += '&commento=' + escape(encodeURI(commento));
	atx += '&securecode=' + escape(encodeURI(securecode));
	atx += '&secure_id=' + escape(encodeURI(secure_id));
	
	var Xreq = new XRequest();
	Xreq.onreadystatechange = function()
			{
			if (Xreq.readyState == 4) { if (Xreq.status == 200) 
				{
				var rtx = Xreq.responseText;
				parseCommentoBlog(rtx);

				} } 		
			}
	Xreq.open('POST', url, true);
  	Xreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   	Xreq.setRequestHeader("Content-length", atx.length);
   	Xreq.setRequestHeader("Connection", "close");
   	Xreq.send(atx);
	
	}

function parseCommentoBlog(rtx)
	{
	var tx = '';
	var ptx = rtx.substr(0,1);
	if (ptx == '1')
		{
		alert('Errore compilazione campi');	
		return;	
		}
	else 
		{
		if (ptx == '2')
			{
			alert('Codice conferma non valido.');	
			return;	
			}
		else
			{
			if (ptx == '3')
				{
				alert('Errore dati.');	
				return;	
				}
			else
				{
				 tx += ' <table width="100%" border="0" cellspacing="0" cellpadding="0" class="editoriale_tab">';
				 tx += ' <tr>  <td class="editoriale_bar"><img src="/img/commenti_2.png" alt="Commenti" width="150" height="20" /></td>';
				 tx += ' </tr>   <tr> <td valign="top" style="padding:4px;">\n';
				 tx += rtx;
				 tx += '\n</td></tr></table>\n';
				 document.getElementById('commenti').innerHTML = tx;
 				 document.getElementById('securecode').value = '';	
				 document.getElementById('commento').value = '';	
				}
			}
		}
	}

function findPosX(obj)
{
	if (!obj) { return false; }
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	if (!obj) { return false; }
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function XRequest()
 	{
	 	var http_request = false;
     	if (window.XMLHttpRequest) 
			{ // Mozilla, Safari,...
	        http_request = new XMLHttpRequest();
        	if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
    		} 
		else if (window.ActiveXObject) 
			 { // IE
	         try 
			 	{
    	        http_request = new ActiveXObject("Msxml2.XMLHTTP");
         		} catch (e) 
				{
		            try {
        		       http_request = new ActiveXObject("Microsoft.XMLHTTP");
            		} catch (e) {}
         		}
      		}
      	if (!http_request) 
			{
        	alert('No XMLHTTP instance!');
         	return false;
      		}
	 	return http_request;
  	}
