/**
* Classe générique Activsoft : gestion d'un ou de plusieurs cache XML.
*/
Activsoft.Manager.register("activsoft.ajax.cache");

activsoft.ajax.cache.XMLCacheManager = function() {
  this.XMLcache = new Array();  
}

//Fonction d'initialisation du cache pour les données XML
activsoft.ajax.cache.XMLCacheManager.prototype.initCache = function(suffixe) {
  if (window.ActiveXObject) { 
    this.XMLcache[suffixe] = new ActiveXObject("Msxml2.DOMDocument"); 
    this.XMLcache[suffixe].async="false";
    this.XMLcache[suffixe].loadXML("<BODY></BODY>");
  } 
  if (document.implementation.createDocument) { 
    var parser = new DOMParser();
    this.XMLcache[suffixe] = parser.parseFromString("<BODY></BODY>", "text/xml"); 
  }
}

activsoft.ajax.cache.XMLCacheManager.prototype.initCacheFromXml = function(suffixe, innerXml) {
  if (window.ActiveXObject) { 
    this.XMLcache[suffixe] = new ActiveXObject("Msxml2.DOMDocument"); 
    this.XMLcache[suffixe].async="false";
    this.XMLcache[suffixe].loadXML(innerXml);
  } 
  if (document.implementation.createDocument) { 
    var parser = new DOMParser();
    this.XMLcache[suffixe] = parser.parseFromString(innerXml, "text/xml"); 
  }
}

//Suppression dans le cache
activsoft.ajax.cache.XMLCacheManager.prototype.destroyElement = function(item) {
  item.parentNode.removeChild(item);
}

//Fonctions de recherche dans le cache
activsoft.ajax.cache.XMLCacheManager.prototype.searchCache = function(expression, suffixe) {
  var testCache = xpathNodeList(expression,XMLcache[suffixe],XMLcache[suffixe]);
  return testCache.length>0;
}

//Fonctions de debug du cache
activsoft.ajax.cache.XMLCacheManager.prototype.displayCache = function(suffixe) {
  if (window.ActiveXObject) {
    alert(this.XMLcache[suffixe].xml);
  } 
  else { 
    var serializer = new XMLSerializer();
    alert(serializer.serializeToString(this.XMLcache[suffixe]));
  }
}

activsoft.ajax.cache.XMLCacheManager.prototype.getCache = function(suffixe) {
  return this.XMLcache[suffixe];
}
