// setInnerHTML Sécurisé
function setInnerHTML(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")
      }
    }
	
	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];
    });
  }
 
Object.prototype.forEach=function(delegate, ownpropertiesonly) {
        if (typeof(delegate)=="function") {
            if (this instanceof Array && typeof(ownpropertiesonly)=="undefined") {
                ownpropertiesonly=true;
            }
            for (key in this) {
                var ok = (!ownpropertiesonly);
                if (!ok) {
                    try {
                        ok=this.hasOwnProperty(key)
                    } catch (ex) {}
                }
                if (ok) {
                    try { delegate(this[key], key, this) } catch(e) {
                        // ...
                    }
                }
            }
        }
        return false;
    }
 
Object.prototype.map=function(iterator) {
    var results = [];
    this.forEach(function(value, index) {
      results.push(iterator(value, index));
    });
    return results;
  }


// 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 requeteXHR(url, cadre) {
   var Xhr = GetXmlHttpRequest();
   Xhr.open("GET",url,false);
   Xhr.send(null);
   
   // ecriture de la réponse
	setInnerHTML(document.getElementById(cadre).innerHTML = Xhr.responseText, document.getElementById(cadre).innerHTML = Xhr.responseText);
}
