window.includedHtmlFiles= new Array();
window.includedJsFiles= new Array();
window.Chargement= function (fichiersJS,fichiersHTML,listener){
this.listener= listener;
this.fichiersJS= fichiersJS;
this.fichiersHTML= fichiersHTML;
this.fileToLoad= new Array();
if(fichiersJS){
var nb= fichiersJS.length;
for(var i=0; i < nb; i++){
var o= new Object();
o.url= fichiersJS[i];
o.loaded= false;
this.fileToLoad.push(o);
}
}
if(fichiersHTML){
var nb= fichiersHTML.length;
for(var i=0; i < nb; i++){
var o= new Object();
o.url= fichiersHTML[i];
o.loaded= false;
this.fileToLoad.push(o);
}
}
}
Chargement.prototype.charge= function(){
var nb= this.fileToLoad.length
for(var i=0; i < nb; i++){
this.fileToLoad[i].loaded= false;
}
this.reload= false;
if(this.fichiersJS){
var nb= this.fichiersJS.length;
for(var i=0; i < nb; i++){
this.chargeFichier(window.includedJsFiles,this.fichiersJS[i]);
}
}
if(this.fichiersHTML){
var nb= this.fichiersHTML.length;
for(var i=0; i < nb; i++){
this.chargeFichier(window.includedHtmlFiles,this.fichiersHTML[i]);
}
}
}
Chargement.prototype.removeListener= function(){
this.listener= null;
}
Chargement.prototype.fichierCharge= function (url,reload){
this.reload= this.reload || reload;
var toutCharge= true;
var nb= this.fileToLoad.length
for(var i=0; i < nb; i++){
if(this.fileToLoad[i].url==url){
this.fileToLoad[i].loaded= true;
}
toutCharge= toutCharge && this.fileToLoad[i].loaded;
}
if(toutCharge){
if(this.fichiersJS){
var nb= this.fichiersJS.length;
for(var i=0; i < nb; i++){
eval(window.includedJsFiles[this.fichiersJS[i]]);
window.includedJsFiles[this.fichiersJS[i]]= true;
}
}
if(this.listener){
this.listener.onload(this,this.reload);
}
}
}
Chargement.getHTML= function (url){
return window.includedHtmlFiles[url];
}
Chargement.prototype.chargeFichier= function (includedFiles,url){
if(includedFiles[url]==null){
var xhr= new XMLHttpRequest();
var monChargeur= this;
xhr.onreadystatechange= function (){
if(xhr){
if(xhr.readyState==4){
if(xhr.status==200 || xhr.status==0){
includedFiles[url]= xhr.responseText;
monChargeur.fichierCharge(url,true);
}else{
redirectOnError(xhr);
}
xhr= null;
}
}else{
return;
}
}
try{
xhr.open("GET",url,true);
xhr.send(null);
}catch(e){alert(url + " : " + e.message);}
}else{
this.fichierCharge(url,false);
}
}
