var timeoutAjax = 5000; // Nombre de ms avant timeout d'une requete Ajax

// Methode de redirection vers une page du site PS avec verification d'etat d'authentification prealable
function verifLoginPSandRedirect(urlTest, urlRedirect) {
	document.location.href = urlRedirect;
}

// Methode d'affichage d'un iframe du site PS avec verification d'etat d'authentification prealable
function verifLoginPSandShowIframe(urlTest, urlIframe, idIframe) {
	new Ajax.Request(urlTest,{
		method : "post",
		onComplete: function(request) {
			if (request.status == "200") {
				document.getElementById(idIframe).src = urlIframe;
				document.getElementById(idIframe+"Loading").style.display = "none";
				document.getElementById(idIframe).style.display = "block";
			} else {
				document.getElementById(idIframe+"Loading").style.display = "none";
				document.getElementById(idIframe+"Error").style.display = "block";
			}
		}
	});
}

// Methode d'affichage d'un contenu Ajax avec traitement d'erreur
function showAjax(urlOpenBet, idDiv, idBackup, position) {
	jQuery.ajax({
		type: "GET",
		url: urlOpenBet,
		success: function(data){
			document.getElementById(idDiv).innerHTML = data;
			document.getElementById(idDiv+"Loading").style.display = "none";
			document.getElementById(idDiv).style.display = "block";
			jQuery(data).find("script").each(function() {eval(this.innerHTML);});
		},
		timeout: timeoutAjax,
		error: function(XMLHttpRequest, textStatus){
			if (idBackup != null && document.getElementById(idBackup) != null) {
				var defaultArticle = document.getElementById(idBackup).cloneNode(true);
				if (position != null) defaultArticle.className = (position == "gauche") ? "unit size1on2 relative" : "lastunit relative";
				defaultArticle.style.display = "block";
				document.getElementById(idDiv+"Error").innerHTML = "";
				document.getElementById(idDiv+"Error").appendChild(defaultArticle);
			}
			document.getElementById(idDiv+"Loading").style.display = "none";
			document.getElementById(idDiv+"Error").style.display = "block";
		}
	});
}
