
/* addRemoveEvent
********************/
function addRemoveEvent(add, el, evt, func){
	if(add){
		if(el.addEventListener) el.addEventListener(evt, func, false);
		else if (el.attachEvent) el.attachEvent("on" + evt, func);
	}else{
		if(el.removeEventListener) el.removeEventListener(evt, func, false);
		else if (el.detachEvent) el.detachEvent("on" + evt, func);
	}
}

/* anchors
********************/
function initAnchors(){
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; ++i){
		if (!anchors[i].getAttribute("href") || !anchors[i].getAttribute("rel")) continue;
		var relation = String(anchors[i].getAttribute("rel"));
		if (relation.match("popup")) anchors[i].onclick=popup;
		if (relation == "external") anchors[i].onclick=externalLink;
	}
}
function popup(){
	var relation = String(this.getAttribute("rel"));
	if(relation == "popup"){
		window.open(this, "pop", "scrollbars=no");
	}else{
		var arguments = relation.substring(6,relation.length-1).split(";");
		window.open(this,arguments[0],'toolbar=0,location=0,directories=0,status=0,menubar=0,' + arguments[1] + ',resizable=no,width=' + arguments[2] + ',height=' + arguments[3] + ',top=' + arguments[4] + ',left=' + arguments[5]);
	}
	return false;
}
function externalLink(){
	window.open(this);
	return false;
}

/* swf object
********************/
function injectSO(){
	try{
		var so_head = new SWFObject("swf-xml/header.swf", "soinj_header", "930", "162", "8", "#ffffff");
		so_head.addParam("wmode", "transparent");
		so_head.addParam("menu", "false");
		so_head.write("header");
	} catch(err) {}
}

/* xhrObject
********************/
var xhrs = [
	function(){ return new XMLHttpRequest(); },
	function(){ return new ActiveXObject("Msxml2.XMLHTTP"); },
	function(){ return new ActiveXObject("Msxml3.XMLHTTP"); },
	function(){ return new ActiveXObject("Microsoft.XMLHTTP"); },
];

function createXhr(){
	var xhr = false;
	for (var i=0; i<xhrs.length; i++){
		try{ xhr = xhrs[i](); }
		catch(e){ continue; }
		break;
	}
	return xhr;
}

/* xhrRequest
********************/
function xhrReq(url, callback, params){
	var req = createXhr();
	var method = (params)?"POST":"GET";
	req.open(method, url, true);
	req.setRequestHeader("User-Agent", "XHR");
	if(method == "POST") req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.onreadystatechange = function(){
		if(req.readyState != 4) return;
		if(req.status != 200 && req.status != 304){
			alert("erreur " + req.status);
			return;
		}
		if(callback) callback(req);
	}
	if(req.readyState == 4) return;
	req.send(params);
}

/* initStats
********************/
function initStats(){
	var xhrCheck = createXhr();
	if(!xhrCheck) return;
	xhrReq("JSstatsRedirect.php?siteid=3395&ref="+document.referrer);
}

/* init
********************/
addRemoveEvent(true, window, "load", injectSO);
addRemoveEvent(true, window, "load", initAnchors);
initStats();
