// +----------------------------------------------------------------------+
// | CMS V5.0.0
// | Auteur: jeremy@eolas.fr - (Inspiration Harmen Christophe)
// | Action: Statistiques XiTi - Marqueur de lien externe et document
// +----------------------------------------------------------------------+

/*
* Récupération du contenu text d'un nooeud (Harmen Christophe)
*/
function xt_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 += xt_getInnerText(oNode);
			oNode = oNode.nextSibling;
		}
	} catch(e) {
		xt_afficherInfo('xt_getInnerText - ' + e.description);
	}
	return _textContent;
}

/*
* Gestion des erreurs (affichages satus bar)
*/
function xt_afficherInfo(txt) {
	xt_txt = txt;
 	var tid = setInterval(xt_statuswriter, 1000);
}
function xt_statuswriter() {
	window.status = xt_txt;
}

/*
* Initialisation - MAJ de tous les liens
*/
function xt_initialisation() {
	try {
			var oAs = document.getElementsByTagName("A");
			for (i=0;oAs[i];i++)  {
					YAHOO.util.Event.addListener(oAs[i], 'click',
					function() {
						try {
							ahref = this.href;
							aRel = this.rel;
							aText = '';
							aDocument = '';     
							if(aRel == '') {
    							if (ahref.substr(0,11)!= 'javascript:' && ahref.substr(0,7)!= 'mailto:') {
    								if (this.getAttributeNode("TITLE")) aText = this.getAttributeNode("TITLE").value;
    								if (this.getAttributeNode("TITLE")) aSrc = this.getAttributeNode("S").value;
    								if (xt_trim(aText) == '') aText = xt_getInnerText(this);
    								aText = xt_trim(aText).replace(/[^A-Za-z0-9_~\\\/\-]+/g, '_');
                    if (YAHOO.util.Dom.hasClass(this, 'document')) {
    								  aDocument =  ahref.replace(/.*(\/[^\/]*)$/,'$1');
                      pageTracker._trackPageview(aDocument);
                      xt_med('C', '', aText, 'T');
    								} else if (YAHOO.util.Dom.hasClass(this, 'external')) {
    									xt_med('C', '', ahref, 'S');
    								}
    								return true;
    							}
							}
						} catch (e) {
							xt_afficherInfo('xt_aclick - ' + e.description);
						}
					});
		}
	} catch(e) {
		xt_afficherInfo('xt_initialisation - ' + e.description);
	}
}

function xt_trim(str) {
	try {
		str = str.replace(/(^[\s:*]+)|([\s:*]+$)/g,'');
	} catch (e) {
		str = '';
		xt_afficherInfo('xt_trim - ' + e.description);
	}
	
	return str;
}

// Initialisation des scripts pour XiTi
var xt_txt = '';
YAHOO.util.Event.addListener(window, 'load', xt_initialisation);

