/**************************************************************************************************
* Classe de gestion des requêtes XMLHttpRequest de chargement d'un lien
* Hérite de la classe XHR
* Dépend des fonctions suivantes :
*	- $
*	- addEvent
*	- remEvent
*	- positionTop
**************************************************************************************************/
spxhr.prototype=new xhr();
spxhr.prototype.constructor=spxhr;
spxhr.baseConstructor=xhr;
spxhr.superclass=xhr.prototype;

// Constructeur
function spxhr(_objname,_home,_img,_lg,_showmsg,_url,_params,_sessname,_sessid,_logged)
{
	this._initiated=false;
	this._timerpub='';
	this._pubrefresh=300000; // Intervale de rafraichissement des pubs en mode ajax
	this._msgwidth=250;	// Largeur du block d'affichage du message de chargement
	this._toolbarwidth=123;	// Largeur du block d'affichage du message de chargement
	this._msgid='ajax';	// ID du block d'affichage du message de chargement
	this._toolbarid='toolbar';	// ID du block d'affichage du message de chargement
	this._prefix='sp';	// Préfixe des balises de mise en forme des données retournées
	this._objname=_objname;
	this._home=_home;	// Chemin d'accès de la racine
	this._img=_img;	// Chemin d'accès des images
	this._lg=_lg;
	this._showmsg=_showmsg;
	this._currenturl=_url;
	this._params=_params;
	this._sessname=_sessname;
	this._sessid=_sessid;
	this._logged=_logged;
	this._adsenseurl='';
	this._nbn=null;
	this._checksitesupdinterval=null;
	this._nbn=null;
	this._siteurl=null;
	this._siteslist=null;
	this._siteschecklist=null;
	this._sitesnamelist=null;
	this._anchor=null;
	this._imgloading='loading.gif';
	this._imgtimeout='warning.png';
	this._imgfailed='warning.png';
	this._enabled=false;
	this._shift=false;
	this._ctrl=false;
	this._alt=false;
	this._f5=false;
	if (this._showmsg) this.setMsg();
}

// Initialise les messages à afficher
spxhr.prototype.setMsg=function()
{
	if (this._lg == 'en')
	{
		this._msgloading='Loading in progress...';
		this._msgtimeout='Timeout !';
		this._msgfailed='Loading failed !';
		this._msgstats1='<br />Page loaded in ';
		this._msgstats2=' secs for a size of ';
		this._msgstats3='KB (without images)';

		this._msgstart='Enable AJAX mode';
		this._msgstop='Disable AJAX mode';
		this._msgback='Previous page';
		this._msgnext='Next page';
		this._msgreload='Reload current page';
		this._msginfo='Show help';
	}
	else
	{
		this._msgloading='Chargement en cours...';
		this._msgtimeout='Délais d\'attente dépassé !';
		this._msgfailed='Le chargement a échoué !';
		this._msgstats1='<br />Page chargée en ';
		this._msgstats2=' secs pour une taille de ';
		this._msgstats3='Ko (sans les images)';

		this._msgstart='Activer le mode AJAX';
		this._msgstop='Désactiver le mode AJAX';
		this._msgback='Page précédente';
		this._msgnext='Page suivante';
		this._msgreload='Actualiser la page courante';
		this._msginfo='Afficher l\'aide';
	}
};

// Effectue des opérations lorsqu'une requête débute ou se termine
//	_state		true = requête en cours, false = aucune requête en cours
spxhr.prototype.setBusy=function(_state)
{
	if (this._showmsg)
	{
		if (_state) this.showLoading('loading');
		else if (!_state && this._busy) this.hideLoading();
	}
	spxhr.superclass.setBusy.call(this,_state);
};

// Annule une requête (appelé lors d'un timeout)
spxhr.prototype.timedOut=function()
{
	if (this._showmsg) this.showLoading('timeout');

	spxhr.superclass.timedOut.call(this);
};

/**************************************************************************************************
* Fonctions outil génériques
**************************************************************************************************/
// Positionne la fenêtre au niveau de l'ancre spécifiée
spxhr.prototype.goAnchor=function(_anchor)
{
	if (_anchor) window.scrollTo(0,(_anchor == '#top') ? 0 : positionTop(_anchor));
	return false; // Pour annuler le click sur un lien
};

// Parse les données retournés par les requêtes XMLHttpRequest
spxhr.prototype.parser=function()
{
	_txt=trim(this._response);
	var _fullreload;
	var _menuhead=null;
	var _menu=null;
	var _submenu=null;

//	alert(_txt);
	// Debug/test, on affiche le contenu s'il ne commence pas par la bonne balise
	if (_txt.substring(0,3) != '<' + this._prefix) alert(_txt);
	if (_txt && _txt != 'null' && _txt.substring(0,3) != '<br') // Netscape 6.2 retourne la chaine "null" si le script php appelé ne se termine pas
	{
//		_txt=unencodeURIComponent(_txt);
		// Infos
		var _exp=new RegExp('<' + this._prefix + 'infos>(.*)</' + this._prefix + 'infos>');
		var _infos=_exp.exec(_txt);
		if (_infos)
		{
//			alert(_infos[1]);
			var _tinfos=new Array();
			var _exp=new RegExp('<' + this._prefix + '-[a-zA-Z0-9_-]+>');
			var _tmp=_infos[1].split(_exp);
			for (var _i in _tmp)
			{
				if (_tmp[_i])
				{
					var _exp=new RegExp('^(.*)</' + this._prefix + '-([a-zA-Z0-9_-]+)>$');
					var _test=_exp.exec(_tmp[_i]);
					if (_test)
					{
						// On remplace les %OA par des \n
						var _exp=new RegExp('%0A','g');
						_tinfos[_test[2]]=_test[1].replace(_exp,"\n");
//						alert(_test[2] + ' : ' + _tinfos[_test[2]]);
						if (_test[2] == 'refresh') // Rafraichissement de la page coté navigateur
						{
							this._anchor='';
							_tinfos['notop']=1
							location.href=_test[1];
						}
						else if (_test[2] == 'redirect')
						{
//							alert(_test[1]);
							this._anchor='';
							_tinfos['notop']=1
							return this.ajax(_test[1],1); // Redirection avec rechargement complet
						}
						else if (_test[2] == 'fullreload') _fullreload=1;
						else if (_test[2] == 'logged') this._logged=_test[1];
						else if (_test[2] == 'title') document.title=_test[1];
						else if (_test[2] == 'lg')
						{
							this._lg=_test[1];
							// On réinitialise les textes lors des changements de langue
							this.setMsg();
						}
						else if (_test[2] == 'params') this._params=_test[1];
						else if (_test[2] == 'url') this._currenturl=_test[1];
						else if (_test[2] == 'urlstyle') $(_test[2]).href=_test[1];
						else if (_test[2] == 'urlfr') $(_test[2]).href=_test[1];
						else if (_test[2] == 'urlen') $(_test[2]).href=_test[1];
						else if (_test[2] == 'urllogin') $('spn_login').action=_test[1];
						else if (_test[2] == 'adsenseurl') this._adsenseurl=_test[1];
						else if (_test[2] == 'menuhead') _menuhead=_test[1];
						else if (_test[2] == 'menu') _menu=_test[1];
						else if (_test[2] == 'submenu') _submenu=_test[1];
						else if (_test[2] == 'refreshstats')
						{
//							alert($('xiti').firstChild.src);
						}
//						alert(_test[2] + ' : ' + _tinfos[_test[2]]);
					}
				}
			}
		}

//		alert('tmp1');
//alert(this._logged);
		// Items portant le nom de l'ID du block dans lequel ils doivent être insérés
		var _exp=new RegExp('<' + this._prefix + 'items>(.*)</' + this._prefix + 'items>');
		var _items=_exp.exec(_txt);
		if (_items)
		{
			var _jscode='';
			var _genstats=false;
			var _titems=new Array();
			var _exp=new RegExp('<' + this._prefix + '-[a-zA-Z0-9_-]+>');
			var _tmp=_items[1].split(_exp);
			for (var _i in _tmp)
			{
				if (_tmp[_i])
				{
					var _exp=new RegExp('^(.*)</' + this._prefix + '-([a-zA-Z0-9_-]+)>$');
					var _test=_exp.exec(_tmp[_i]);
					if (_test)
					{
//						alert(_test[2] + ' : ' + _test[1].replace(_exp,"\n"));
						// On récupère le code javascript contenu dans les éléments retournés							
						var _exp=new RegExp('<script type="text/javascript"[^>]*>');
						var _tmp2=_test[1].split(_exp);
						for (var _i in _tmp2)
						{
							if (_tmp2[_i])
							{
								var _exp=new RegExp('^(.*)</script>');
								var _tjscode=_exp.exec(_tmp2[_i]);
								var _exp=new RegExp('(<!--|// -->|%0A)','g');
								if (_tjscode) _jscode+=_tjscode[1].replace(_exp,'');
							}
						}
						// On récupère les fichiers javascript à inclure
/*						var _exp=new RegExp('<script type="text/javascript" src="');
						var _tmp2=_test[1].split(_exp);
						for (var _i in _tmp2)
						{
							if (_tmp2[_i])
							{
								var _exp=new RegExp('^([^>]*)"></script>');
								var _tjsincludes=_exp.exec(_tmp2[_i]);
								if (_tjsincludes) _jscode+='include(\'' + _tjsincludes[1] + '\');';
							}
						}*/
						var _exp=new RegExp('%0A','g');
//							alert(_test[1].replace(_exp,"\n"));
						// On remplace les %OA par des \n
						if (_test[2] == 'test') alert(_test[1].replace(_exp,"\n")); // Test
						else if ($(_test[2]))
						{
							$(_test[2]).innerHTML=_test[1].replace(_exp,"\n");
//							if (_test[2] == 'externalTools') alert(_test[1].replace(_exp,"\n"));
						}
						if (_test[2] == 'genstats') _genstats=true;
					}
				}
			}
			// S'il y a du code javascript dans les éléments retournés, on l'exécute
//			if (_jscode) alert(_jscode);
			if (_jscode) eval(_jscode);
			// S'il y avait une ancre dans l'url, on se déplace sur celle-ci, sinon, on se remet en haut de la fenêtre, sauf si _tinfos['notop'] est défini
			this.goAnchor((!this._anchor && !_tinfos['notop']) ? '#top' : this._anchor);
		}

		// Scripts javascript
		var _exp=new RegExp('<' + this._prefix + 'scripts>(.*)</' + this._prefix + 'scripts>');
		var _scripts=_exp.exec(_txt);
		if (_scripts)
		{
			var _tscripts=new Array();
			var _exp=new RegExp('<' + this._prefix + '-[a-zA-Z0-9_-]+>');
			var _tmp=_scripts[1].split(_exp);
			for (var _i in _tmp)
			{
				if (_tmp[_i])
				{
					var _exp=new RegExp('^(.*)</' + this._prefix + '-([a-zA-Z0-9_-]+)>$');
					var _test=_exp.exec(_tmp[_i]);
					if (_test)
					{
						// On remplace les %OA par des \n
						var _exp=new RegExp('%0A','g');
						_tscripts[_test[2]]=_test[1].replace(_exp,"\n");
//						alert(_test[2] + ' : ' + _tscripts[_test[2]]);
						eval(_tscripts[_test[2]]);
					}
				}
			}
		}

		// Rafraichissement du menu
		if (_fullreload) initSelectedMenu(_menuhead,_menu,_submenu);
		else refreshSelectedMenu(_menuhead,_menu,_submenu);

		this.setRequestTime();
		// Si c'est demandé, on met à jour les statistiques de chargement
		if (_genstats) $('genstats').innerHTML=$('genstats').innerHTML + this._msgstats1 + Math.round((this._time / 1000) * 100)/100 + this._msgstats2 + Math.round((this._responsesize / 1024) * 100)/100 + this._msgstats3;
		return _tinfos;
	}
	else
	{
		if (this._showmsg && $(this._msgid).className != 'msgtimeout') this.showLoading('failed');
		return false;
	}
};

/**************************************************************************************************
* Gestion du mode AJAX
**************************************************************************************************/
// Active le mode AJAX
spxhr.prototype.enableAjax=function()
{
//	alert(this._home + 'ajaxmode.php?url=' + this._currenturl);
	location.href=this._home + 'ajaxmode.php?url=' + this._currenturl;
};

// Désactive le mode AJAX
spxhr.prototype.disableAjax=function()
{
//	alert(this._home + 'ajaxmode.php?disable=1&url=' + this._currenturl);
	location.href=this._home + 'ajaxmode.php?disable=1&url=' + this._currenturl;
};

// Evenement d'initialisation du mode AJAX
spxhr.prototype.initAjax=function(_url,_adsense)
{
	if (this._ok)
	{
		this._adsenseurl=_adsense;
		var _xhrtmp=this;
		// Si le navigateur le gère, onDOMContentLoaded permet de ne pas attendre un éventuel chargement trop long du logo xiti ou hit-parade (par exemple)
		addEvent(window,"DOMContentLoaded",function(_e) { this._initiated=true; _xhrtmp.__initAjax(_url); });
		// Sinon, on fait un classique onLoad
		addEvent(window,'load',function(_e) { if (!this._initiated) _xhrtmp.__initAjax(_url); });
	}
};

// Initialise le mode AJAX (appelé par this.initAjax())
spxhr.prototype.__initAjax=function(_url)
{
	this.timerPub(); // Timer de rafraichissement des pubs
	var _xhrtmp=this;
	addEvent(window.document,'keydown',function(event) {
		var _key=(event.which) ? event.which : event.keyCode;
//		window.status='down : ' + _key;
		// Annulation de F5
		if (event.keyCode == 116)
		{
			// Sous IE, on ne peut pas annuler F5, mais on peut "remplacer" par un autre touche et annuler cette autre touche
			if (_ie56 || _ie7)
			{
				_xhrtmp._f5=true;
				window.event.keyCode=8;
			}
			else
			{
				stopPropagation(event);
				preventDefault(event);
			}
			_xhrtmp.enableAjax();
		}
	    // Annulation du backspace
		if (event.keyCode == 8)
		{
			stopPropagation(event);
			preventDefault(event);
			if (_ie56 || _ie7)
			{
				if (!_xhrtmp._f5)
				{
					// Action de retour sous IE
				}
				_xhrtmp._f5=false;
			}
		}
/*		if (_key == 16) _xhrtmp._shift=true;
		if (_key == 17) _xhrtmp._ctrl=true;
		if (_key == 18) _xhrtmp._alt=true;*/
	});
	addEvent(window.document,'keyup',function(event) {
		var _key=(event.which) ? event.which : event.keyCode;
//		window.status='up : ' + _key;
/*		if (_key == 16) _xhrtmp._shift=false;
		if (_key == 17) _xhrtmp._ctrl=false;
		if (_key == 18) _xhrtmp._alt=false;*/
	});
	if (!event) var event;
	this.ajax(_url,1);
};

// Timer qui rafraichi les pubs tuotes les X secondes en mode ajax
spxhr.prototype.timerPub=function()
{
//	alert(typeof _timerpub);
//	if (typeof _timerpub != 'undefined')
	if (this._timerpub)
	{
		if ($('ifadsense1'))
		{
			$('ifadsense1').src='iframes/adsense.if.php'
			$('ifadsense2').src='iframes/adsense.if.php'
		}
//		alert('test');
	}
	_xhrtmp=this;
	this._timerpub=setTimeout(function() { _xhrtmp.timerPub(); },this._pubrefresh);
//	this._timerpub=setTimeout('timerPub()',_pubrefresh);
//	alert(typeof _timerpub);
};

// Fonction appelée dans le onclick des liens et boutons pour se substituer à eux en mode AJAX
spxhr.prototype.link=function(event,_this,_forcereload)
{
	// On laisse passer l'action normale (en retournant true) si shift, ctrl ou alt est pressé
	if (!this._ok || event.shiftKey || event.ctrlKey || event.altKey) return true;
//	if (!this._ok || this._shift || this._ctrl) return true;

	return this.ajax(_this,_forcereload);
}
// Fonction appelée dans le onclick des liens et boutons pour se substituer à eux en mode AJAX
spxhr.prototype.ajax=function(_this,_forcereload)
{
//	if (!this._ok || this._shift || this._ctrl) return true;
	if (!this._ok) return true;
	var _method='get';
	var _data='';
	// On récupère d'abord l'url en fonction de ce qui est passé en paramètre
	var _url='';
	if (typeof _this != 'object') _url=_this; // Si _this n'est pas un objet, on concidère que c'est l'url
	else if (_this.href) _url=_this.href; // Si c'est un lien
	else if (_this.action) // Si c'est un formulaire
	{
		_method=_this.method;
		_url=_this.action;
	}

	// On récupère l'ancre et la retire de l'url
	this._anchor='';
	if (_url.lastIndexOf('#') != -1)
	{
		this._anchor=_url.substring(_url.lastIndexOf('#')+1);
		_url=_url.replace(_url.substring(_url.lastIndexOf('#')),'');
	}
	// On retire le domaine de l'url
	_url=_url.replace('http://' + location.host,'');

	// Si c'est un formulaire, on en récupère toutes les valeurs pour les passer en paramètre
	if (_this.action)
	{
		for (var _i=0; _i<_this.length; _i++)
		{
			var _e=_this.elements[_i];
			var _val='';
			if (_e.type == 'select-one' && !_e.value) var _val='-';
			if (_e.name && (_e.value || _val) && !_e.disabled && ((_e.type != 'checkbox' && _e.type != 'radio') || _e.checked))
			{
//				_data+=((_data) ? '&' : '') + _e.name + '=' + (_e.value ? _e.value : _val);
//				if (_method == 'post') _e.value=encodeURIComponent(_e.value);
//				_data+=((_data) ? '&' : '') + _e.name + '=' + (_e.value ? _e.value : _val);
//				_data+=((_data) ? '&' : '') + _e.name + '=' + (_e.value ? encodeURIComponent(_e.value,1) : _val);
				// On converti les caractères non ISO-9958-1 en référence numérique HTML puis urlencode le tout
				_data+=((_data) ? '&' : '') + _e.name + '=' + (_e.value ? encodeURIComponent(convertToEntities(_e.value,1)) : _val);
//				alert(_e.value + ' - ' + encodeURIComponent(_e.value));
			}
		}
//		alert(encodeURIComponent(_data));
//		alert(_data);
	}
	// Sinon on récupère les paramètres de l'url
	else
	{
		// Si le lien pointe vers une ancre de la page, on va directement sur cette ancre sans rechargement
		if (encodeURIComponent(_url.replace(this._home,'')) == this._currenturl && this._anchor)
		{
			this.goAnchor(this._anchor);
			return false;
		}

		var _turl=_url.split('?');
		_url=_turl[0];
		if (typeof _turl[1] != 'undefined') _data=_turl[1];
//		alert(_data);
	}

//	alert(_data);
	// On ajoute l'url courante et l'id de session dans la liste des paramètres
	_data+=((_data) ? '&' : '') + 'params=' + this._params + '&' + this._sessname + '=' + this._sessid + '&logged=' + this._logged;
	// On fait suivre le paramètre forcant le rechargement complet s'il est fourni
	if (typeof _forcereload != 'undefined') _data+='&xhrreload=' + _forcereload;
	// Si l'url commence par le chemin vers la racine du site, on retire ce chemin de l'url
	if (this._home && _url.substring(0,this._home.length) == this._home) _url=_url.substring(this._home.length);
	// Sans url-rewriting
	if (_url.substring(0,9) == 'index.php')
	{
		_url=this._home + _url.replace('index.php','xhr.php');
		_data+=((_data) ? '&' : '?') + 'xhrfile=link';
	}
	// Avec url-rewriting, on ajoute juste /xhr devant le chemin de lapage, l'.htaccess redirigeant alors vers l'xhr.php en ajoutant le paramètre xhrfile=link
	else _url=this._home + 'xhr/' + _url;
//	alert(_url + ' - ' + _data);
//	alert(_data);
	return (_method == 'post') ? !this.post(_url,_data,'this.parser') : !this.get(_url,_data,'this.parser');
};

// Affiche la fenêtre de loading
spxhr.prototype.showLoading=function(_type)
{
	this.hideLoading();
	$(this._msgid).className=(_type) ? 'msg' + _type : '';

	switch (_type)
	{
		case 'loading' : var _msg=this._msgloading; break;
		case 'timeout' : var _msg=this._msgtimeout; break;
		case 'failed' : var _msg=this._msgfailed;
		default : break;
	}

	// Gestion du repositionnement vertical de la fenêtre de loading sur les navigateurs ne supportant pas l'attribut CSS position:fixed
	if (document.all)
	{
		$(this._msgid).style.position='absolute';
		var _xhrtmp=this;
		addEvent(window, 'scroll', function(event) { _xhrtmp.repositionLoading(event); });
	}

//	if (_type == 'timeout') alert('$(' + this._msgid + ').firstChild.innerHTML=' + _msg);
	$(this._msgid).firstChild.innerHTML=_msg;
	$(this._msgid).style.display='block';
	this.repositionLoading();
};

// Repositionne la fenêtre de loading
spxhr.prototype.repositionLoading=function(_e)
{
	if ($(this._msgid).style.display != 'block') window.onscroll='';
	if (self.innerWidth) var _w=self.innerWidth; // Netscape 6
	else if (document.documentElement && document.documentElement.clientWidth) var _w=document.documentElement.clientWidth; // Le reste
	else if (document.body) var _w=document.body.clientWidth; // IE sans Doctype
	$(this._msgid).style.left=(_w - this._msgwidth) / 2 + 'px';
	if (document.all)
	{
		var _tmp=(document.body.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;
		$(this._msgid).style.top=(5 + _tmp) + 'px';
	}
	else $(this._msgid).style.top='5px';
};

// Masque la fenêtre de loading
spxhr.prototype.hideLoading=function()
{
	$(this._msgid).style.display='none';
};

// Ajoute le block contenant le message de loading dans la source de la page
spxhr.prototype.loadingBlock=function()
{
	document.write('<div id="' + this._msgid + '"><div style="width:' + this._msgwidth + 'px"></div></div>');
};

spxhr.prototype.addFavorite=function(_url)
{
//alert(window.sidebar);
//alert(window.external);
	if (window.sidebar && window.sidebar.addPanel) window.sidebar.addPanel(document.title,_url,false);
	else if (window.external && window.external.AddFavorite) window.external.AddFavorite(_url,document.title);
	else if (window.opera && window.print) return true; 
	else alert('Fonction non supportée par votre navigateur.');
};
/*if( window.sidebar && window.sidebar.addPanel ) {
    //Gecko (Netscape 6 etc.) - add to Sidebar
    window.sidebar.addPanel( this.title, this.href, '' );
} else if( window.external && ( navigator.platform == 'Win32' ||
      ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
    //IE Win32 or iCab - checking for AddFavorite produces errors in
    //IE for no good reason, so I use a platform and browser detect.
    //adds the current page page as a favourite; if this is unwanted,
    //simply write the desired page in here instead of 'location.href'
    window.external.AddFavorite( location.href, document.title );
} else if( window.opera && window.print ) {
    //Opera 6+ - add as sidebar panel to Hotlist
    return true;
} else if( document.layers ) {
    //NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
    //not target page)
    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
} else {
    //other browsers - tell them to add a bookmark (adds current page, not target page)
    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
}
return false;
*/

/**************************************************************************************************
* Gestion de la toolbar
**************************************************************************************************/
// Ajoute la toolbar dans la source de la page
spxhr.prototype.initToolbar=function()
{
//	var _bar='<div id="' + this._toolbarid + '"><div style="width:' + this._toolbarwidth + 'px">';
	var _bar='<div id="' + this._toolbarid + '" style="width:' + this._toolbarwidth + 'px">';
	_bar+='</div>';
//	_bar+='</div></div>';
	document.write(_bar);
	this.toolbar();
	this.showToolbar();
};

// Ajoute la toolbar dans la source de la page
spxhr.prototype.toolbar=function()
{
	this._buttons=new Array();
	this._buttons['start']='<a href="javascript:' + this._objname + '.enableAjax()"><img src="' + this._img + 'toolbar/start.gif" alt="" title="' + this._msgstart + '" /></a>';
//	this._buttons['start']='<a href="javascript:void()" onclick="' + this._objname + '.enableAjax()"><img src="' + this._img + 'toolbar/start.gif" alt="" title="' + this._msgstart + '" /></a>';
	this._buttons['stop']='<a href="javascript:' + this._objname + '.disableAjax()"><img src="' + this._img + 'toolbar/stop.gif" alt="" title="' + this._msgstop + '" /></a>';
//	this._buttons['stop']='<a href="javascript:void(0)" onclick="' + this._objname + '.disableAjax()"><img src="' + this._img + 'toolbar/stop.gif" alt="" title="' + this._msgstop + '" /></a>';
//	this._buttons['stop']='<a href="ajaxmode.php?disable=1&url=' + this._currenturl + '"><img src="' + this._img + 'toolbar/stop.gif" alt="" title="' + this._msgstop + '" /></a>';
	this._buttons['back']='<a href="javascript:void(0)"><img src="' + this._img + 'toolbar/back.gif" alt="" title="' + this._msgback + '" /></a>';
	this._buttons['backd']='<img src="' + this._img + 'toolbar/backd.gif" />';
	this._buttons['next']='<a href="javascript:void(0)"><img src="' + this._img + 'toolbar/next.gif" alt="" title="' + this._msgnext + '" /></a>';
	this._buttons['nextd']='<img src="' + this._img + 'toolbar/nextd.gif" />';
	this._buttons['reload']='<a href="javascript:void(0)"><img src="' + this._img + 'toolbar/reload.gif" alt="" title="' + this._msgreload + '" /></a>';
	this._buttons['reloadd']='<img src="' + this._img + 'toolbar/reloadd.gif" />';
//	this._buttons['info']='<a href="#" onclick="_spxhr.addFavorite(\'http://www.test.com\')"><img src="' + this._img + 'toolbar/info.gif" alt="" title="' + this._msginfo + '" /></a>';
	this._buttons['info']='<a href="javascript:void(0)" onclick="alert(\'En construction.\')"><img src="' + this._img + 'toolbar/info.gif" alt="" title="' + this._msginfo + '" /></a>';

//	var _bar='<div id="' + this._toolbarid + '"><div style="width:' + this._toolbarwidth + 'px">';
///	var _bar='<div id="' + this._toolbarid + '" style="width:' + this._toolbarwidth + 'px">';

	var _bar='';
	if (this._ok)
	{
		_bar+='<div id="t_stop">' + this._buttons['stop'] + '</div>';
		_bar+='<div>' + this._buttons['back'] + '</div>';
		_bar+='<div>' + this._buttons['next'] + '</div>';
		_bar+='<div>' + this._buttons['reload'] + '</div>';
	}
	else
	{
		_bar+='<div id="t_start">' + this._buttons['start'] + '</div>';
		_bar+='<div>' + this._buttons['backd'] + '</div>';
		_bar+='<div>' + this._buttons['nextd'] + '</div>';
		_bar+='<div>' + this._buttons['reloadd'] + '</div>';
	}
	
	_bar+='<div>' + this._buttons['info'] + '</div>';
	$(this._toolbarid).innerHTML=_bar;
///	_bar+='</div>';
//	_bar+='</div></div>';
//	document.write('<div id="' + this._msgid + '" style="width:' + this._msgwidth + '"></div>');

///	document.write(_bar);
///	this.showToolbar();
};

// Affiche la toolbar
spxhr.prototype.showToolbar=function()
{
	var _xhrtmp=this;
	if (document.all)
	{
		$(this._toolbarid).style.position='absolute';
		addEvent(window, 'scroll', function(event) { _xhrtmp.repositionToolbar(event); });
	}
	addEvent(window, 'resize', function(event) { _xhrtmp.repositionToolbar(event); });

//	$(this._msgid).firstChild.innerHTML=_msg;
	$(this._toolbarid).style.display='block';
	this.repositionToolbar();
};

// Repositionne correctement la toolbar
spxhr.prototype.repositionToolbar=function(_e)
{
	if ($(this._toolbarid).style.display != 'block')
	{
		var _xhrtmp=this;
		remEvent(window, 'scroll', function(event) { _xhrtmp.repositionToolbar(event); });
		remEvent(window, 'resize', function(event) { _xhrtmp.repositionToolbar(event); });
	}
	else
	{
		if (self.innerWidth) var _w=self.innerWidth; // Netscape 6
		else if (document.documentElement && document.documentElement.clientWidth) var _w=document.documentElement.clientWidth; // Le reste
		else if (document.body) var _w=document.body.clientWidth; // IE sans Doctype
		$(this._toolbarid).style.left=(_w - this._toolbarwidth - 15) / 1 + 'px';
		if (document.all)
		{
			var _tmp=(document.body.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;
			$(this._toolbarid).style.top=(5 + _tmp) + 'px';
		}
		else $(this._toolbarid).style.top='5px';
	}
};

/**************************************************************************************************
* Rechargement d'un site
**************************************************************************************************/
spxhr.prototype.initReload=function(_checksitesupdinterval,_nbn,_siteurl,_siteslist,_siteschecklist,_sitesnamelist,_sitesdesclist,_mainobj)
{
	this._checksitesupdinterval=_checksitesupdinterval;
	this._nbn=_nbn;
	this._siteurl=_siteurl;
	this._siteslist=_siteslist;
	this._siteschecklist=_siteschecklist;
	this._sitesnamelist=_sitesnamelist;
	this._sitesdesclist=_sitesdesclist;
	if (typeof this._timerchecksitesupd != 'undefined') clearTimeout(this._timerchecksitesupd);
	this._timerchecksitesupd=null;
	// Nom de l'objet global créé pour le rechargement des sites, utile pour savoir quelle liste de dates de derniere maj mettre à jour lors du reloadSite qui crée un objet distinct pour chaque rechargement
	// Initialiser au nom de l'objet lui même pour l'objet principal, qui le fera passer aux objets créés pour le rechargement de chaque site
	this._mainobj=_mainobj;
};

// Affiche le lien pour recharger un site lorsque le navigateur supporte XMLHttpRequest
spxhr.prototype.showReload=function(_id,_nbn,_desc)
{
	if (this._ok)
	{
		if (this._lg == 'en')
		{
			var _txt1='Reload this site';
			var _txt2='Don\'t show news description';
			var _txt3='Show news description';
			var _txt4='Show news description on mouse over';
/*			var _txt1='Reload this site';
			var _txt2='desc:';
			var _txt3='no';
			var _txt4='yes';
			var _txt5='on mouse over';*/
		}
		else
		{
			var _txt1='Recharger ce site';
			var _txt2='Ne pas afficher la description des news';
			var _txt3='Afficher la description des news';
			var _txt4='Affiche la description des news au passage de la souris';
/*			var _txt1='Recharger ce site';
			var _txt2='desc :';
			var _txt3='sans';
			var _txt4='avec';
			var _txt5='passage souris';
*/		}
		
		var _t='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'' + _desc + '\'); return false"><img src="' + this._img + 'icons/reload.gif" alt="' + _txt1 + '" title="' + _txt1 + '" /></span> ';
		_t+='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'no\'); return false"><img src="' + this._img + 'icons/desc1.gif" alt="' + _txt2 + '" title="' + _txt2 + '" /></span> ';
		_t+='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'yes\'); return false"><img src="' + this._img + 'icons/desc2.gif" alt="' + _txt3 + '" title="' + _txt3 + '" /></span> ';
		_t+='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'mouse\'); return false"><img src="' + this._img + 'icons/desc3.gif" alt="' + _txt4 + '" title="' + _txt4 + '" /></span>';
/*		var _t='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'' + _desc + '\'); return false">' + _txt1 + '</span>';
		_t+=' (' + _txt2 + ' <span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'no\'); return false">' + _txt3 + '</span>, ';
		_t+='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'yes\'); return false">' + _txt4 + '</span>, ';
		_t+='<span class="reload" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'mouse\'); return false">' + _txt5 + '</span>)';
*/

/*		var _t='<a href="#" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'' + _desc + '\'); return false">' + _txt1 + '</a>';
		_t+=' (' + _txt2 + ' <a href="#" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'no\'); return false">' + _txt3 + '</a>, ';
		_t+='<a href="#" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'yes\'); return false">' + _txt4 + '</a>, ';
		_t+='<a href="#" onclick="_spxhr.reloadSite(' + _id + ',' + _nbn + ',\'mouse\'); return false">' + _txt5 + '</a>)';
*/
		$('toolbar_' + _id).innerHTML=_t;
	}
};

// Fonction appelée par le lien de rechargement d'un site
spxhr.prototype.reloadSite=function(_id,_nbn,_desc,_noconnection)
{
	var _nocon=(typeof _noconnection != 'undefined') ? '&noconnection=1' : '';
	var _url=this._siteurl.replace('[:id:]',_id);

	// Mise à jour de l'état d'affichage de la description
	var _tids=this._siteslist.split(',');
	var _tdescs=this._sitesdesclist.split(',');
	for (var _i in _tdescs) { if (_tids[_i] == _id) _tdescs[_i]=_desc; }
	this._sitesdesclist=_tdescs.join(',');

	// On crée un objet pour chaque site à charger, pour éviter les conflits sur les chargements simultanés
	// On passe le nom de l'objet principal dans la fonction d'initialisation pour que ce soit la liste de dernières maj de l'objet principal qui soit mise à jour
	eval('_spxhr' + _id + '=new spxhr(this._home,this._lg)');
	if (eval('_spxhr' + _id + '._ok'))
	{
		eval('_spxhr' + _id + '.initReload(this._checksitesupdinterval,this._nbn,this._siteurl,this._siteslist,this._siteschecklist,this._sitesnamelist,this._sitesdesclist,this._mainobj)');
		eval('_spxhr' + _id + '.get(this._home + \'xhr.php\',\'xhrfile=reloadsite&id=' + _id + '&nbn=' + _nbn + '&lg=' + _lg + '&desc=' + _desc + '&url=' + encodeURIComponent(_url) + _nocon + '\',\'this.affReloadedSite(' + _id + ')\',\'this.affSiteReloading(' + _id + ')\')');
	}
};

// Fonction appelée lors du début du rechargement d'un site pour afficher les messages de chargement en cours
spxhr.prototype.affSiteReloading=function(_id)
{
	if (this._lg == 'en')
	{
		var _txt1='News of ';
		var _txt2=' are loading...';
		var _upd='Loading in progress...';
	}
	else
	{
		var _txt1='Chargement des news de ';
		var _txt2=' en cours...';
		var _upd='Chargement en cours...';
	}
	var _txt=_txt1 + '<span class="b">' + this.siteName(_id) + '</span>' + _txt2;
	$('siteupd_' + _id).innerHTML=_upd;
	$('site_' + _id).innerHTML=_txt;
	var _descs=$('sitend_' + _id)
	if (_descs) _descs.innerHTML='';
};

// Fonction appelée à la fin du rechargement d'un site pour afficher le résultat
spxhr.prototype.affReloadedSite=function(_id)
{
	_txt=this._response;
	if (_txt)
	{
		var _items=this.parser(_txt);

		// Mise à jour de la date de dernière vérification pour l'objet principal
		var _tids=eval(this._mainobj + '._siteslist.split(\',\')');
		var _tchecks=eval(this._mainobj + '._siteschecklist.split(\',\')');
		for (var _i in _tchecks) { if (_tids[_i] == _id) _tchecks[_i]=_items['lastcheck']; }
		eval(this._mainobj + '._siteschecklist=_tchecks.join(\',\')');
	}
	// En cas d'échec, on le signale
	else
	{
		if (this._lg == 'en') { var _txt='The reloading of this site has failed, try again or reload the entire page.'; var _upd='The reloading has failed'; }
		else { var _txt='Le rechargement du site a échoué, essayez à nouveau ou rechargez toute la page.'; var _upd='Le rechargement a échoué'; }
				
		$('siteupd_' + _id).innerHTML=_upd;
		$('site_' + _id).innerHTML=_txt;
	}
};

// Timer de check de la mise à jour des sites
spxhr.prototype.timerCheckSitesUpd=function()
{
	// Si un timer tourne et si la liste des sites à checker n'est pas vide, on les check
	if (this._siteslist && this._timerchecksitesupd && $('checkupdsites').checked) this.checkSitesUpd();
	// On arrête le timer, utile sur les nouvelles pages ou il n'y a aucun site à checker
	if (this._timerchecksitesupd) clearTimeout(this._timerchecksitesupd);
	// On relance un nouveau timer
	var _xhrtmp=this;
	if (this._siteslist) this._timerchecksitesupd=setTimeout(function() { _xhrtmp.timerCheckSitesUpd(); },this._checksitesupdinterval);
};

// Vérification de la mise à jour des sites
spxhr.prototype.checkSitesUpd=function()
{
	if (this._siteslist) this.get(this._home + 'xhr.php','xhrfile=checkupdsites&ids=' + this._siteslist + '&checks=' + this._siteschecklist,'this.reloadUpdSites');
};

// Recharge les sites mis à jour
spxhr.prototype.reloadUpdSites=function()
{
	_updsiteslist=this._response;
	if (_updsiteslist)
	{
		// Rechargement des sites le necessitant
		var _tids=_updsiteslist.split(',');
		for (var _i in _tids)
		{
			var _id=_tids[_i];
//			var _url=this._siteurl.replace('[:id:]',_id);

			// Récupération de l'état d'affichage de la description pour le site courant
			var _tmp=this._siteslist.split(',');
			var _tdescs=this._sitesdesclist.split(',');
			for (var _i in _tdescs) { if (_tmp[_i] == _id) var _desc=_tdescs[_i]; }

//			this.reloadSite(_id,this._nbn,_desc,_url,1);
			this.reloadSite(_id,this._nbn,_desc,1);
		}
	}
};

// Retourne le nom du site à partir de son id
spxhr.prototype.siteName=function(_id)
{
	if (_id)
	{
		var _tids=this._siteslist.split(',');
		var _tnames=this._sitesnamelist.split(',');
		for (var _i in _tids) if (_tids[_i] == _id) return decodeURIComponent(_tnames[_i].replace('%E9','é'));
//		for (var _i in _tids) if (_tids[_i] == _id) return decodeURIComponent(_tnames[_i]);
	}
	else return false;
};
