// +----------------------------------------------------------------------+
// | CMS V2.0.0
// | Auteur: jeremy@eolas.fr - (Inspiration Harmen Christophe)
// | Action: Statistiques XiTi - Marqueur de lien externe et document
// +----------------------------------------------------------------------+

/*
* Gestion d'évenement (Harmen Christophe)
*/
function xt_addEventLst(EventTarget,type,listener,useCapture) {
	try {
		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;
		}
	} catch(e) {
		xt_afficherInfo('xt_addEventLst - ' + e.description);
	}
}
/*
* 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 {
		if (xt_doc_path == '' || xt_loc_path == '') {
			xt_afficherInfo('Les chemins xt ne sont pas renseignés.');
		} else {
			var oAs = document.getElementsByTagName("A");
			for (var i = 0; i < oAs.length; i++) xt_addEventLst(oAs[i], 'click', xt_aclick);
		}
	} 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;
}

/*
* Recupération du text et appel javascript JS
*/
function xt_aclick() {
	try {
		ahref = this.href;
		aText = '';
		if (ahref.substr(0,11)!= 'javascript:' && ahref.substr(0,7)!= 'mailto:') {
			if (this.getAttributeNode("TITLE")) aText = this.getAttributeNode("TITLE").value;
			if (xt_trim(aText) == '') aText = xt_getInnerText(this);
			aText = xt_trim(aText).replace(/[^A-Za-z0-9_~\\\/\-]+/g, '_');
		  if (ahref.substr(0, xt_doc_path.length) == xt_doc_path) {
		    xt_med('C', SIT_XITI_ID, aText,'T');
			} else if (ahref.substr(0, xt_loc_path.length) != xt_loc_path) {
				xt_med('C', SIT_XITI_ID, ahref,'S');
			}
			return false;
		}
	} catch (e) {
		xt_afficherInfo('xt_aclick - ' + e.description);
	}
}

// Initialisation des scripts pour XiTi
xt_addEventLst(window,'load',xt_initialisation);
var xt_txt = '';
