/* ********************************************************************
 * Place the contents of block #{val} into the results area
 *
 */
function showModules(val) {
  var resH4 = document.getElementById("results").getElementsByTagName('h4')[0];
  var resDL = document.getElementById("results").getElementsByTagName('dl')[0];
  while (resDL.firstChild) resDL.removeChild(resDL.firstChild);

  if (!blocks[val]) {
    resH4.firstChild.nodeValue = "Contact Factory";

        var dd = document.createElement('dd');
            dd.appendChild(document.createTextNode("Please contact Evertz factory for more information regarding this product"));
      resDL.appendChild(dd);

        var dt = document.createElement('dt');
            dt.appendChild(document.createTextNode("Phone"));
      resDL.appendChild(dt);
        var dd = document.createElement('dd');
            dd.appendChild(document.createTextNode("(905) 335-3700"));
      resDL.appendChild(dd);

        var dt = document.createElement('dt');
            dt.appendChild(document.createTextNode("Fax"));
      resDL.appendChild(dt);
        var dd = document.createElement('dd');
            dd.appendChild(document.createTextNode("(905) 335-0909"));
      resDL.appendChild(dd);

        var dt = document.createElement('dt');
            dt.appendChild(document.createTextNode("E-Mail"));
      resDL.appendChild(dt);
        var dd = document.createElement('dd');
          var a = document.createElement('a');
              a.href = "mailto:sales@evertz.com";
              a.appendChild(document.createTextNode("sales@evertz.com"));
            dd.appendChild(a);
      resDL.appendChild(dd);

  } else blocks[val].putBlock();

  resDL.scrollTop = 0;
}


attachOnload(function() {
  var res = document.getElementById("results");
      res.removeChild(res.getElementsByTagName('noscript')[0]);

    var dl = document.createElement('dl');
      var dd = document.createElement('dd');
          dd.appendChild(document.createTextNode("Click a category button in the diagram to the left to view available Evertz modules for that application"));
        dl.appendChild(dd);
      res.appendChild(dl);
});


/* ********************************************************************
 ***** Classes ***************************************************** */
function Product(link, name, description, vistalink) {
  this.link = (typeof link == "string") ? [link] : link;
  this.name = (typeof name == "string") ? [name] : name;
  this.description = description;
  this.vistalink = vistalink;

  this.getDT = function() {
    var dt = document.createElement('dt');
      if (this.vistalink) {
        var img = document.createElement('img');
            img.src = "img/product.vistalink.png";
            img.alt = "VistaLINK Enabled";
          dt.appendChild(img);
      }

      if (this.link[0].match(/\.pdf$/i)) {
        var img = document.createElement('img');
            img.src = "img/icon.pdf.png";
            img.alt = "PDF Document";
          dt.appendChild(img);
      }

      for (var x = 0; x < this.name.length; x++) {
        if (x) dt.appendChild(document.createTextNode(" / "));
        if (this.link[x]) {
          var a = document.createElement('a');
              a.href = "products/" + this.link[x];
              a.appendChild(document.createTextNode(this.name[x]));
            dt.appendChild(a);
        } else dt.appendChild(document.createTextNode(this.name[x]));
      }

    return dt;
  }

  this.getDD = function() {
    var dd = document.createElement('dd');
        dd.appendChild(document.createTextNode(this.description));
    return dd;
  }
}


function PGroup(name, nodes) {
  this.name = name;
  this.nodes = (nodes) ? nodes : [];

  this.putGroup = function() {
    var resDL = document.getElementById("results").getElementsByTagName('dl')[0];

    if (this.name) {
      var dt = document.createElement('dt');
          dt.appendChild(document.createTextNode(this.name));
          dt.className = "heading";
        resDL.appendChild(dt);
    }

    for (var x = 0; x < this.nodes.length; x++) {
      resDL.appendChild(this.nodes[x].getDT());
      resDL.appendChild(this.nodes[x].getDD());
    }
  }
}


function PBlock(name, groups) {
  this.name = name;
  this.groups = (groups) ? groups : [];

  this.putBlock = function() {
    document.getElementById("results").getElementsByTagName('h4')[0].firstChild.nodeValue = this.name;
    for (var x = 0; x < this.groups.length; x++) this.groups[x].putGroup();
  }
}
