//Version: 1.00, 30/05/2007


function LoghiSet(strAjaxURL, arrLoghiLinkArray, strImgPrefix) {
  this.LoadImage = LoadImage;
  this.swapImageById = swapImageById;
  this.roller = roller;
  this.image = new Object();
  this.GetLoghiCallback = GetLoghiCallback;
  this.AjaxURL = strAjaxURL;
  this.ImgPrefix = strImgPrefix;
  this.LoghiLinkArray = arrLoghiLinkArray;

  this.m_Ajax = new Ajax(this.AjaxURL, this.GetLoghiCallback, "text/xml", "GET", this);

}

function LoadImage(name, src, image) {
  //alert(src);
  if (document.images[name]) {
    if (!image[name])
      image[name] = new Object();

    image[name] = new Image();
    image[name].src = src;
  }
}

function swapImageById(img, name, image) {
  if (image[name]) {
    img = document.images[img];
    img.src = image[name].src;
  }
}

function roller(objLoghiSet) {
  var d = new Date();
  var time = d.getTime();
  //recupero i valori tramite ajax
  this.m_Ajax = new Ajax(objLoghiSet.AjaxURL + "&time=" + time, this.GetLoghiCallback, "text/xml", "GET", this);

  objLoghiSet.m_Ajax.Get();
  //        for(var i = 0; i < 6; i++)
  //        {
  //         //per ogni valore carico le immagini
  //          LoadImage(objLoghiSet.ImgPrefix+i,objLoghiSet.imgArray[i],objLoghiSet.image);
  //          // e le visualizzo
  //          swapImageById(objLoghiSet.ImgPrefix+i,objLoghiSet.ImgPrefix+i,objLoghiSet.image);
  //        }

  //alert('ciao');
}

function LoadLoghi(objReq, objComboItemLoader) {
  //carico i valori via ajax
  var objDocument = objReq.responseXML;
  var objXMLNodes = objDocument.getElementsByTagName('Nodes').item(0);
  var objComboItems = new Array();

  for (var i = 0; i < objXMLNodes.childNodes.length; ++i) {
    if (i < objComboItemLoader.LoghiLinkArray.length) {
      var objXMLNode = objXMLNodes.childNodes[i];
      //recupero il valore resituito
      var strText = "is.aspx?ID=" + objXMLNode.attributes[0].nodeValue;
      var strLink = GetNodeText(objXMLNode);
      var tmp = new Array();
      tmp = strLink.split('|');
      strLink = tmp[0];
      var strRagSoc = objXMLNode.attributes[1].nodeValue;
      //creo la url delle immagini

      if (objComboItemLoader.LoghiLinkArray[i].TX != '')
        strText = strText + "&TX=" + objComboItemLoader.LoghiLinkArray[i].TX;
      if (objComboItemLoader.LoghiLinkArray[i].TY != '')
        strText = strText + "&TY=" + objComboItemLoader.LoghiLinkArray[i].TY;
      if (objComboItemLoader.LoghiLinkArray[i].th != '')
        strText = strText + "&th=" + objComboItemLoader.LoghiLinkArray[i].th;
      if (objComboItemLoader.LoghiLinkArray[i].DS != '')
        strText = strText + "&DS=" + objComboItemLoader.LoghiLinkArray[i].DS;

      objComboItemLoader.LoghiLinkArray[i].objImage.src = strText;
      objComboItemLoader.LoghiLinkArray[i].objImage.alt = strRagSoc;
      objComboItemLoader.LoghiLinkArray[i].objImage.title = strRagSoc;
      if (objComboItemLoader.LoghiLinkArray[i].PrefixUrl != '')
        objComboItemLoader.LoghiLinkArray[i].objLogoLink.href = objComboItemLoader.LoghiLinkArray[i].PrefixUrl + objXMLNode.attributes[0].nodeValue + '.htm';
    }

  }
}


function GetLoghiCallback(objReq, objLoghiLoader) {
  //Set the waiting class on the tree view
  if (objReq.readyState == 4) {
    if (objReq.status == 200) {
      // process a XML document here
      LoadLoghi(objReq, objLoghiLoader);
    }
    else {
      window.status = "Error: returned status code " + objReq.status + " " + objReq.statusText;
    }
  }
}


function LogoLink(strLogoName, strPrefixUrl, strImageName, strTX, strTY, strTH, strDS) {
  this.objLogoLink = GetElement(strLogoName);
  this.PrefixUrl = strPrefixUrl;
  this.objImage = GetElement(strImageName);
  this.TX = strTX;
  this.TY = strTY;
  this.th = strTH;
  this.DS = strDS;
}

function GetElement(strName) {
  return document.getElementById(strName);
}
