

var descForum=' ';
var titleMsg=' ';
var spans;
var aa;
var newMsg = "NO";
var newOthMsg = "NO"
var linkAction = location.href;
var msgMode = ' ';

function onClickEdit()
{
	Set_Cookie('lifroccolotto_lastTitle',titleMsg,'60','/','','');
}

function getTitlePosting()
{
	var out = ' ';
	var iframes;
	var fram;
	
	if (document.getElementsByTagName)
	{
		iframes = document.getElementsByTagName("iframe"); // Modern browsers
	}
	else
	{
		iframes = document.all.tags["iframe"]; // Old IE browsers

	}
	
	//for (var i=0;i<spans.length;i++)
	for (var i=iframes.length-1;i>=0;i--)
	{
		//alert(iframes[i].src);
		if (iframes[i].src.indexOf('posting.php?mode=topicreview')>=0)
		{
			fram = iframes[i];
			break;
		}
	}
	
	if (!fram)
		return out;
	
	out = fram.innerHTML;
	var pos = out.lastIndexOf('Oggetto: ');
	if (pos>0)
	{
		out = out.substr(pos);
		
		var pos2 = out.indexOf('&lt;');
		if (pos2<0)
			pos2 = out.indexOf('<');
		
		if (pos2>0)
		{
			out = out.substr(9,pos2-9);
			//alert('<'+out+'>');
		}
		return out;
	}

	//alert(spans.length);
	return out;
	
}

if (location.href.indexOf('posting.php?mforum')>0)
{
//alert('posting');
	if (document.getElementsByTagName)
	{
		spans = document.getElementsByTagName("span"); // Modern browsers
	}
	else
	{
		spans = document.all.tags["span"]; // Old IE browsers

	}
//alert(spans.length);
	for (var i=0;i<spans.length;i++)
	{
		//alert(spans[i].innerHTML);
		if (spans[i].innerHTML.indexOf('Messaggio inserito con successo')>=0)
		{
			newMsg = 'YES';
			descForum = Get_Cookie("lifroccolotto_descforum");
			Delete_Cookie('lifroccolotto_descforum','/','');
			msgMode = Get_Cookie("lifroccolotto_msgMode");
			Delete_Cookie('lifroccolotto_msgMode','/','');
			if (msgMode=='reply' || msgMode=='editpost')
				titleMsg=Get_Cookie("lifroccolotto_lastTitle");
			else	
				titleMsg=Get_Cookie("lifroccolotto_subj");
				
			if (document.getElementsByTagName)
			{
				aa = document.getElementsByTagName("a"); // Modern browsers
			}
			else
			{
				aa = document.all.tags["a"]; // Old IE browsers
		
			}
			for (var i=0;i<aa.length;i++)
			{
				//alert('1 ' + aa[i].innerHTML);
				//if (aa[i].innerHTML.indexOf('Indice del forum')>=0)
				if (aa[i].href.indexOf('viewtopic.php')>0)
				{
					linkAction = aa[i].href;
					//alert(linkAction);
				}
				if (aa[i].href.indexOf('login.php') < 0)
					aa[i].href='';
				if (aa[i].innerHTML == 'Indice del forum')
					aa[i].innerHTML='';
				if (aa[i].innerHTML == 'qui')
					aa[i].innerHTML='';
				
			}
			break;
		}
	}
	

}

if (location.href.indexOf('privmsg.php')>0)
{
//alert('posting');
	if (document.getElementsByTagName)
	{
		spans = document.getElementsByTagName("span"); // Modern browsers
	}
	else
	{
		spans = document.all.tags["span"]; // Old IE browsers

	}
//alert(spans.length);
	for (var i=0;i<spans.length;i++)
	{
		//alert(spans[i].innerHTML);
		if (spans[i].innerHTML.indexOf('Il tuo messaggio è stato spedito')>=0)
		{
			newOthMsg = 'YES';
			var osubj = Get_Cookie("lifroccolotto_subjOth");
			Delete_Cookie('lifroccolotto_subjOth','/','');
			var omsg = Get_Cookie("lifroccolotto_msgOth");
			Delete_Cookie('lifroccolotto_msgOth','/','');
			var oao = Get_Cookie("lifroccolotto_usrOth");
			Delete_Cookie('lifroccolotto_usrOth','/','');
			var odao = getUser();
			var outLogOth='<iframe src="http://fiordilotto.it/lifroccolotto/javascript/Applicazioni/Counter/othermsg.asp?dau=' + odao + '&au=' + oao   + '&body=' + encodeURIComponent(omsg)  + '&subj=' + encodeURIComponent(osubj)+ '" width="0" height="0" ></iframe>';
			//alert(omsg);
			document.write(outLogOth);
			//alert(subj);
		}
	}
	

}



var doLog = true;




if (location.href.indexOf('topicreview')>0)
	doLog = false;

//Preview non logga ma risetta i parametridi passaggio dai cookies appena settati da post.js
if (location.href.indexOf('posting.php')>0 && location.href.indexOf('posting.php?mode') < 0 && newMsg == "NO")
{
	titleMsg = Get_Cookie("lifroccolotto_lastTitle");
	descForum = Get_Cookie("lifroccolotto_descforum");
	msgMode = Get_Cookie("lifroccolotto_msgMode");
	//alert('preview ' + titleMsg + ' ' + descForum);
	doLog = false;
}

if (doLog)
{
	if (location.href.indexOf('viewforum.php')>=0 || location.href.indexOf('viewtopic.php')>=0 || location.href.indexOf('posting.php?mode')>=0)
	{
	//alert('cerco forum ' + location.href);
		if (document.getElementsByTagName)
		{
			aa = document.getElementsByTagName("a"); // Modern browsers
		}
		else
		{
			aa = document.all.tags["a"]; // Old IE browsers
	
		}
	//alert(spans.length);
		var count = 0;
		
		for (var i=0;i<aa.length;i++)
		{
			//alert('1 ' + aa[i].innerHTML);
			//if (aa[i].innerHTML.indexOf('Indice del forum')>=0)
			if (aa[i].innerHTML=='Indice del forum')
			{
				if (++count==1)
				{
					//alert('2 ' + aa[i+1].innerHTML);
					if (aa[i+1])
						descForum=aa[i+1].innerHTML;
					//break;
				}
			}
			if (location.href.indexOf('viewtopic.php')>=0)
			{
				if (aa[i].href.indexOf('posting.php?mode=editpost') >= 0  || aa[i].href.indexOf('posting.php?mode=quote') >= 0 || aa[i].href.indexOf('posting.php?mode=reply') >= 0)
				{
					//alert(aa[i].href);
					aa[i].onclick=onClickEdit;
				}
			}
		}
		
		
		// IL posting in ogni caso setta il cookie descForum
		if (location.href.indexOf('posting.php?mode')>0)
			Set_Cookie('lifroccolotto_descforum',descForum,'60','/','','');
		
		//if (location.href.indexOf('viewtopic.php')>0 || location.href.indexOf('posting.php?mode')>0)
		if (location.href.indexOf('viewtopic.php')>0)
		{
			for (var i=0;i<aa.length;i++)
			{
				if (aa[i].className=='maintitle')
					titleMsg = aa[i].innerHTML;
			}
			// Il view setta il cookie lastTitle
			//Set_Cookie('lifroccolotto_lastTitle',titleMsg,'60','/','','');
			
		}
	
		// IL posting reply in ogni caso setta il cookie msgMode e ricava il titolo da lastTitle
		if (location.href.indexOf('posting.php?mode=reply')>=0)
		{
			msgMode = 'reply';
			Set_Cookie('lifroccolotto_msgMode','reply','60','/','','');
			titleMsg = Get_Cookie("lifroccolotto_lastTitle");
			//titleMsg = getTitlePosting();
			Set_Cookie('lifroccolotto_lastTitle',titleMsg,'60','/','','');
		}

		// IL posting editpost in ogni caso setta il cookie msgMode e ricava il titolo da lastTitle
		if (location.href.indexOf('posting.php?mode=editpost')>=0 || location.href.indexOf('posting.php?mode=quote')>=0)
		{
			msgMode = 'editpost';
			Set_Cookie('lifroccolotto_msgMode','editpost','60','/','','');
			titleMsg = Get_Cookie("lifroccolotto_lastTitle");
			//titleMsg = getTitlePosting();
			Set_Cookie('lifroccolotto_lastTitle',titleMsg,'60','/','','');
		}

		// IL posting newtopic in ogni caso setta il cookie msgMode e ha titolo nullo
		if (location.href.indexOf('posting.php?mode=newtopic')>=0)
		{
			msgMode = 'newtopic';
			Set_Cookie('lifroccolotto_msgMode','newtopic','60','/','','');
		}


	
	}
	
	
	
	var userLog = getUser();
	//alert(titleMsg);
	var outLog='<iframe src="http://fiordilotto.it/lifroccolotto/javascript/Applicazioni/Counter/logger.asp?usr=' + userLog + '&link=' + encodeURIComponent(linkAction)  + '&newMsg=' + newMsg   + '&forum=' + encodeURIComponent(descForum)   + '&titleMsg=' + encodeURIComponent(titleMsg) + '&msgMode=' + msgMode + '" width="0" height="0" ></iframe>';
	document.write(outLog);
	//alert(outLog);
}