// +----------------------------------------------------------------------+
// | CMS V5.0.0
// | Auteur: jeremy@eolas.fr - (Inspiration Harmen Christophe) - utilisé par matthieu@eolas.fr pour Google Analytics 
// | Action: Statistiques Google Analytics - Marqueur de lien externe et document
// +----------------------------------------------------------------------+

function ga_addEventLst(EventTarget,type,listener,useCapture) {
	useCapture = typeof(useCapture)=="boolean"?useCapture:false;
	if (EventTarget.addEventListener) {
		EventTarget.addEventListener(type, listener, useCapture);
	} else if ((EventTarget==window) && document.addEventListener) {
		document.addEventListener(type, listener, useCapture);
	} else if (EventTarget.attachEvent) {
		EventTarget["e"+type+listener] = listener;
		EventTarget[type+listener] = function() {EventTarget["e"+type+listener]( window.event );}
		EventTarget.attachEvent("on"+type, EventTarget[type+listener]);
	} else {
		EventTarget["on"+type] = listener;
	}
}

function ga_hasClassName(oNode, className) {
	return (oNode.nodeType==1)?
		((" "+oNode.className+" ").indexOf(" "+className+" ")!=-1):false;
}

function ga_getInnerText(oNode) {
	try {
		if (oNode.tagName == 'IMG') return oNode.getAttributeNode("ALT").value;
		if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;}
		switch (oNode.nodeType) {
			case 3: // TEXT_NODE
			case 4: // CDATA_SECTION_NODE
				return oNode.nodeValue;
				break;
			case 7: // PROCESSING_INSTRUCTION_NODE
			case 8: // COMMENT_NODE
				if (getTextContent.caller!=getTextContent) {
					return oNode.nodeValue;
				}
				break;
			case 9: // DOCUMENT_NODE
			case 10: // DOCUMENT_TYPE_NODE
			case 12: // NOTATION_NODE
				return null;
				break;
		}
		
		var _textContent = "";
		oNode = oNode.firstChild;
		while (oNode) {
			_textContent += ga_getInnerText(oNode);
			oNode = oNode.nextSibling;
		}
	} catch(e) {
		ga_afficherInfo('ga_getInnerText - ' + e.description);
	}
	return _textContent;
}

function ga_afficherInfo(txt) {
	ga_txt = txt;
 	var tid = setInterval(ga_statuswriter, 1000);
}
function ga_statuswriter() {
	window.status = ga_txt;
}

function ga_initialisation() {
	try {
		var oAs = document.getElementsByTagName("A");
		for (i=0;oAs[i];i++)  {
			ga_addEventLst(oAs[i], 'click',
				function() {
					try {
						ahref = this.href;
						aRel = this.rel;
						aText = '';
						if(aRel == '') {
   						if (ahref.substr(0,11)!= 'javascript:' && ahref.substr(0,7)!= 'mailto:') {
   							if (this.getAttributeNode("TITLE")) aText = this.getAttributeNode("TITLE").value;
   							if (ga_trim(aText) == '') aText = ga_getInnerText(this);
   							aText = ga_trim(aText).replace(/[^A-Za-z0-9_~\\\/\-]+/g, '_');
   							if (ga_hasClassName(this, 'document')) {
                                pageTracker._trackPageview('/telechargement/'+aText);
   							} else if (ga_hasClassName(this, 'external')) {
   								pageTracker._trackPageview('/lien_externe/'+aText);
   							}
   							return true;
   						}
						}
					} catch (e) {
						ga_afficherInfo('ga_aclick - ' + e.description);
					}
				});
		}
	} catch(e) {
		ga_afficherInfo('ga_initialisation - ' + e.description);
	}
}

function ga_trim(str) {
	try {
		str = str.replace(/(^[\s:*]+)|([\s:*]+$)/g,'');
	} catch (e) {
		str = '';
		ga_afficherInfo('ga_trim - ' + e.description);
	}
	return str;
}

var ga_txt = '';
ga_addEventLst(window,'load',ga_initialisation);
