
//	XtraLib (php edition)
//	Copyright 2004-2009 Stra Software
//	All Rights Reserved.

//////////////////////////////////////
//									//
//	 Javascript OuputDebugString	//
//									//
//////////////////////////////////////
function DebugPrint(message)
{
	if (!DebugPrint.window_ || DebugPrint.window_.closed)
	{
		var win = window.open("", null, "width=1024,height=200,scrollbars=yes,resizable=yes,status=no,location=no,menubar=no,toolbar=no");

		if (!win) return;

		var doc = win.document;

		doc.write("<html><head><title>Debug Log</title></head><body></body></html>");
		doc.close();

		DebugPrint.window_ = win;
	}

	var logLine = DebugPrint.window_.document.createElement("div");
	logLine.appendChild(DebugPrint.window_.document.createTextNode(message));
	DebugPrint.window_.document.body.appendChild(logLine);
}
//////////////////////////////////////////////
//											//
//	 Target="_blank" compliant with XHTML	//
//											//
//////////////////////////////////////////////
function SetupExternalLinks()
{
	if(document.getElementsByTagName)
	{
		var	AnchorsList=document.getElementsByTagName("a");

		for(var AnchorIndex=0;AnchorIndex<AnchorsList.length;AnchorIndex++)
		{
			var Anchor=AnchorsList[AnchorIndex];

			if(Anchor.getAttribute("href")&&Anchor.getAttribute("rel")=="external")
			{
//				DebugPrint(Anchor.getAttribute("href"));
				Anchor.target="_blank";
			}
		}
	}
}
//////////////////////////////////////////////
//											//
// Open A Popup Wich Fit Displayed Picture	//
//											//
//////////////////////////////////////////////
function PopupPicture(File,Comment,Width,Height)
{

///	Create Popup Window ///

	var PopupWindow=window.open('','_blank','resizable=1,scrollbars=0,menubar=0,status=0');

	if(!PopupWindow)
	{
		return true;	// Popup blocked (then use failsafe code)
	}

///	Setup HTML Header ///

	PopupWindow.document.write
	(
		'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'+
		'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">\n'+
		'<head>\n'+
		'<title>\n'+
		Comment+
		'</title>\n'+
		'<script type="text/javascript">\n'+
		'function FitToContent()'+
		'{'+

'var ClientWidth=0,ClientHeight=0,de=window.document.documentElement,db=window.document.body;'+
'window.resizeTo('+(Width+64)+','+(Height+64)+');'+

'if(window.innerWidth)'+
'{'+
'	ClientWidth=window.innerWidth;'+
'	ClientHeight=window.innerHeight;'+
'}'+
'else if(de&&de.clientWidth)'+
'{'+
'	ClientWidth=de.clientWidth;'+
'	ClientHeight=de.clientHeight;'+
'}'+
'else if(db&&db.clientWidth)'+
'{'+
'	ClientWidth=db.clientWidth;'+
'	ClientHeight=db.clientHeight;'+
'}'+

'if(window.opera&&!document.childNodes)'+
'{'+
'	ClientWidth+=16;'+
'}'+

'window.resizeTo(2*'+Width+'+64-ClientWidth,2*'+Height+'+64-ClientHeight);'+

		'} FitToContent();\n'+
		'</script>\n'+
		'</head>\n'+
		'<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="overflow: hidden">\n'+
		'<a onclick="window.close()"><img src="'+
		File+
		'" alt="'+
		Comment+
		'" width="'+
		Width+
		'" height="'+
		Height+
		'" border="0" /></a>\n'+
		'</body>\n'+
		'</html>'
	);

///	Set Window HTML Footer ///

	PopupWindow.document.close();

///	Brind Popup To The Top ///

	if(PopupWindow.focus)
	{
		PopupWindow.focus();
	}

///	Success ///

	return false;
}
//////////////////////////////////////////////
//											//
//	Auto-Track Outbounds and Download Links	//	(for Google Analytics)
//											//
//////////////////////////////////////////////

// Source: http://www.epikone.com/blog/2007/04/09/tracking-clicks-with-ga-pt-3-advanced-implementation/

// By default, this script will track links to the follwoing file 
// types: .doc, .xls, .exe, .zip and .pdf

var fileTypes		= [".doc",".xls",".exe",".zip",".pdf",".jar",".xml",".lua",".rar",".7z",".jpg",".png"];

// This is a debug mode flag.  Change to '' for production.  In debug mode
// the script will display an alert box and skip sending data to Google Analytics.

//var debugTracker	= '1';

// This variable controls how outbond links will appear
// the GA reports.  By default, external links will appear as
// '/outbound/<URL>' where URL is the URL in the anchor tag.

var extIdentifier	= '/outbound/';

/// No need to change anything below this line ///

function AutoTrackLinks()
{
	if(document.getElementsByTagName)
	{
		var	AnchorsList=document.getElementsByTagName("a");

		for(var AnchorIndex=0;AnchorIndex<AnchorsList.length;AnchorIndex++)
		{
			var Anchor=AnchorsList[AnchorIndex];

			if(Anchor.hostname==location.host)
			{
				var path=Anchor.pathname.toLowerCase();
				var fnd=false;

				for(var FileTypeIndex in fileTypes)
				{
					if(path.indexOf(fileTypes[FileTypeIndex])>-1)
					{
						fnd=true;
					}
				}

				if(fnd==true)
				{
//					DebugPrint("AutoTracking.InternalLink: ["+Anchor.getAttribute("href")+"]");
					startListening(Anchor,"click",trackDocuments);
				}
			}
			else
			{
//				DebugPrint("AutoTracking.ExternalLink: ["+Anchor.getAttribute("href")+"]");
				startListening(Anchor,"click",trackExternalLinks);
			}
		}
	}
}

function startListening(obj,evnt,func)
{
	if(obj.addEventListener)
	{
		obj.addEventListener(evnt,func,false);
	}
	else
	{
		if(obj.attachEvent)
		{
			obj.attachEvent("on" + evnt,func);
		}
	}
}

function trackDocuments(evnt)
{
	var lnk;

	if(evnt.srcElement)
	{
		var elmnt = evnt.srcElement;

		while (elmnt.tagName != "A")
		{
			var newelmnt = elmnt.parentNode;
			elmnt = newelmnt;
		}

		lnk = elmnt.pathname + elmnt.search;
	}
	else
	{
		lnk = this.pathname + this.search;
	}

	if(!debugTracker)
	{
		pageTracker._trackPageview(lnk);
	}
	else
	{
//		DebugPrint("AutoTracking.InternalLink.ClickOn: "+lnk);
		return false;
	}
}

function trackExternalLinks(evnt)
{
	var lnk;

	if(evnt.srcElement)
	{ 
		var elmnt = evnt.srcElement; 

		while (elmnt.tagName != "A")
		{
			var newelmnt = elmnt.parentNode;
			elmnt = newelmnt;
		}

		lnk = extIdentifier + elmnt.hostname + elmnt.pathname + elmnt.search;
	}
	else
	{
		lnk = extIdentifier + this.hostname + this.pathname + this.search;
	}

	if(!debugTracker)
	{
		pageTracker._trackPageview(lnk);
	}
	else
	{
//		DebugPrint("Tracking.ExternalLink.ClickOn: "+lnk);
		return false;
	}
}
//////////////////////
//					//
//	Page Post Setup	//
//					//
//////////////////////
function PagePostSetup()
{
	SetupExternalLinks();
	AutoTrackLinks();
}
//////////////////
//				//
//	 Auto-run	//
//				//
//////////////////

window.onload=PagePostSetup;
