var xhr = null;
 
// Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX
function getXhr()
 {
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
  else if(window.ActiveXObject)
   {  
    try
     {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch (e)
     {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
  else 
   { 
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 
    xhr = false; 
   } 
 }

    function setInnerHTML(divContent, HTML) {
      divContent.innerHTML=HTML; 
      var All=divContent.getElementsByTagName("*");
      for (var i=0; i<All.length; i++) {
        All[i].id=All[i].getAttribute("id")
        All[i].name=All[i].getAttribute("name")
        //All[i].className=All[i].getAttribute("class")
      }
      var AllScripts=divContent.getElementsByTagName("script");
      //alert(divContent.innerHTML);
      for (var i=0; i<AllScripts.length; i++) {
         var s=AllScripts[i];

         if (s.src && s.src!="") {
         		//alert("ok 1");
            // Précédement asynchrone, mis en synchrone pour éviter des problèmes de dépendances de scripts
            //eval(getFileContent(s.src));

         }
         else {
         	
            eval(s.innerHTML);
            
         }
      }
    }

function setInnerHTML2(divContent, HTML) {
divContent.innerHTML=HTML;
try {
var All=divContent.getElementsByTagName("*");
for (var i=0; i<All.length; i++) {
All[i].id=All[i].getAttribute("id");
All[i].name=All[i].getAttribute("name");
All[i].className=All[i].getAttribute("class");
All[i].src=All[i].getAttribute("src");
}
} catch (ex) {}

try {
	var i = 0;
while (All[i].src != "") {
	//alert('Envoi2 : ' + All[i].src);
if (All[i].src && All[i].src!="") {
		//alert("ok 1 : " + All[i].src + " / " + divContent.innerHTML);
    // Précédement asynchrone, mis en synchrone pour éviter des problèmes de dépendances de scripts
    //eval(getFileContent(All[i].src));
    eval(All[i].src);
}
else {
	//alert("ok 2");
  eval(divContent.innerHTML);
}
i++;
}
} catch (ex) {}
	
try {
var AllScripts=HTML.extractTags("script");
AllScripts.forEach(function (v) {
eval(v);
})
} catch (ex) {}

try {
var AllStyles=HTML.extractTags("style");
AllStyles.forEach(function (v) {
var s=document.createStyleSheet()
s.cssText=v;
s.enabled=true;
}, true)
} catch (ex) {}
}
String.prototype.extractTags=function(tag) {
var matchAll = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'img');
var matchOne = new RegExp('(?:<'+tag+'.*?>)((\n|\r|.)*?)(?:<\/'+tag+'>)', 'im');
return (this.match(matchAll) || []).map(function(scriptTag) {
return (scriptTag.match(matchOne) || ['', ''])[1];
});
}
 // Renvoie le texte de l'objet ActiveXObject le plus récent depuis une liste
    var pickRecentProgID = function (idList){
	    // found progID flag
        var bFound = false;
        for(var i=0; i < idList.length && !bFound; i++){
            try{
                var oDoc = new ActiveXObject(idList[i]);
                o2Store = idList[i];
                bFound = true;
            }catch (objException){
                // trap; try next progID
            };
        };
        if (!bFound)
		    throw ("Aucun ActiveXObject n'est valide sur votre ordinateur, pensez à mettre à jour votre navigateur");
        idList = null;
        return o2Store;
    }
 
    // Retourne un nouvel objet XmlHttpRequest
    var GetXmlHttpRequest_AXO=null
    var GetXmlHttpRequest=function () {
	    if (window.XMLHttpRequest) {
		    return new XMLHttpRequest()
	    }
	    else if (window.ActiveXObject) {
		    if (!GetXmlHttpRequest_AXO) {
			    GetXmlHttpRequest_AXO=pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
		    }
		    return new ActiveXObject(GetXmlHttpRequest_AXO)
	    }
	    return false;
    }


    function getFileContent(url) {
       var Xhr=GetXmlHttpRequest();
       Xhr.open("GET",url,false);
       Xhr.send(null);
       return Xhr.responseText;
    }



