var m_loadMethod = "" ;
var m_loopAnswerHandle ;
var m_method ;
var m_parameters ;
var m_requestId ;
var m_intervalLoop = 100 ;
var m_nbrTentativesMax = 100 ;
var m_nbrTentativesFaites = 0 ;

testJSAJAXCompatibility();

function testJSAJAXCompatibility() {
	if(!document.getElementById) {
		return ;
	}
	loadDirect(root+"js/test1.js");
	loadCreateInnerHTML(root+"js/test2.js")
	loadCreateEl(root+"js/test3.js") ;
	m_loopAnswerHandle = setInterval("validationLoop()", m_intervalLoop) ;
}

function validationLoop() {
	if(typeof(_1) != "undefined" || typeof(_2) != "undefined" || typeof(_3) != "undefined") {
		clearInterval(m_loopAnswerHandle);
		if(typeof(_1) != "undefined") {
			m_loadMethod = "loadDirect" ;
		}
		else if(typeof(_3) != "undefined") {
			m_loadMethod = "loadCreateEl" ;
		}
		else {
			m_loadMethod = "loadCreateInnerHTML" ;
		}   
	}
	else if(m_nbrTentativesFaites < m_nbrTentativesMax) {
		m_nbrTentativesFaites++;
		return ;
	}
	else {
		clearInterval(m_loopAnswerHandle);
		alert("Your browser doesn't seem to support any of the techniques or the connexion with the server failed.");
	}
}

var jsFile='null.js';
function lanceRequete() {
	if(m_loadMethod=='') setTimeout('lanceRequete()', 100);
	else {
		m_answer = "" ;
		m_nbrTentativesFaites = 0 ;
		date = new Date() ;
		m_requestId = date.getTime() ;
		jsFile+='/'+Math.random();
		loadjs(jsFile) ;
		m_loopAnswerHandle = setInterval("loopAnswer()", m_intervalLoop) ;
	}
}

function loopAnswer() {
	typeofResponse = eval('typeof(_' + m_requestId + ')') ;
	if(typeofResponse == "undefined" && m_nbrTentativesFaites < m_nbrTentativesMax) {
		m_nbrTentativesFaites++ ;
		return ;
	}
	else if(typeofResponse == "undefined") {
		m_answer = "No answer received. Maybe m_nbrTentativesMax should be greater. Please try again." ;
	}
	else {
	}
	clearInterval(m_loopAnswerHandle) ;
}

function loadjs(jssrc) {
	if(m_loadMethod == "") {
		return ;
	}
	eval(m_loadMethod + "('" + jssrc + "') ;") ; 
}

function loadDirect(jssrc) {
	js = document.getElementById("jsajax") ;
	js.src = jssrc ;
}

function loadCreateInnerHTML(jssrc) {
	div = document.getElementById("divajax") ;
	div.innerHTML = '<scr' + 'ipt type="text/javascript" id="jsajax2"></sc' + 'ript>' ;
	js = document.getElementById("jsajax2") ;
	if(js) {
		js.src = jssrc ;
	}
}
		
function loadCreateEl(jssrc) {
	divj = document.getElementById('divajax2');
	var newEl = document.createElement('script');
	//textEl.setAttribute("type","text/javascript");
	//textEl.setAttribute("id","jsajax2");
	newEl.setAttribute("src", jssrc);
	divj.appendChild(newEl);
}