/* ********************************************************************
* Evertz.com main javascript file
*
* All Javascript which affects all, or a large proportion of all, pages
* at the site should be placed here.
*
* Onload, this file triggers an empty evertzOnload() function, which
* you can fill in the Javascript file of whatever sub page which
* requires commands to be executed onload.
*
******************************************************************** */

var HOSTCODE = window.location.hostname.replace(/webdev/, "").replace(/evertz\.com/, "").replace(/\./, "") || "www";
var ROOTPATH = window.location.pathname.replace(/\/(products|tools|frame|contact|careers|downloads|resources)\/.*$/, "/");

var isIE = /*@cc_on!@*/false;
var isIE5 = (navigator.userAgent && navigator.userAgent.indexOf('MSIE 5.') > -1);
var isIE6 = /*@if(@_jscript_version == 5.6)!@end@*/false;
var isIElt8 = /*@if(@_jscript_version < 5.8)!@end@*/false;


String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
};



function attachOnload(func) {
  if (window.addEventListener) {
    window.addEventListener('load', func, false);
  } else if (window.attachEvent)
    window.attachEvent('onload', func);
}


attachOnload(function() {
  if (isIE) {
    var menu = document.getElementById('menu');
    for (var x = 0, smenu, smenu2; x < menu.childNodes.length; x++) {
      if (menu.childNodes[x].nodeName == "LI") {
        if (isIE6) {
          menu.childNodes[x].timeout = 0;
          menu.childNodes[x].onmouseover = function() {
            clearTimeout(this.timeout);
            if (this.className.indexOf("hover") == -1)
              this.className += " hover";
          };
          menu.childNodes[x].onmouseout = function() {
            var self = this;
            this.timeout = setTimeout(function() {
              self.className = self.className.replace(/ ?hover ?/g, "");
            }, 5);
          };
          var subm = menu.childNodes[x].getElementsByTagName('li');
          for (var y = 0; y < subm.length; y++) {
            subm[y].timeout = 0;
            subm[y].onmouseover = function() {
              clearTimeout(this.timeout);
              if (this.className.indexOf("hover") == -1)
                this.className += " hover";
            };
            subm[y].onmouseout = function() {
              var self = this;
              this.timeout = setTimeout(function() {
                self.className = self.className.replace(/ ?hover ?/g, "");
              }, 5);
            };
          }
        }
        if (smenu = menu.childNodes[x].getElementsByTagName('ul')[0]) {
          smenu.style.display = "block";
          for (var y = 0, a; y < smenu.childNodes.length; y++) {
            if (smenu.childNodes[y].nodeName == "LI") {
              if (a = smenu.childNodes[y].getElementsByTagName('a')[0])
                a.style.width = (smenu.childNodes[y].offsetWidth - 38) + "px";
              if (a = smenu.childNodes[y].getElementsByTagName('span')[0])
                a.style.width = (smenu.childNodes[y].offsetWidth - 38) + "px";

              if (smenu2 = smenu.childNodes[y].getElementsByTagName('ul')[0]) {
                smenu2.style.display = "block";
                for (var z = 0, a; z < smenu2.childNodes.length; z++)
                  if (smenu2.childNodes[z].nodeName == "LI")
                    if (a = smenu2.childNodes[z].getElementsByTagName('a')[0])
                      a.style.width = (smenu2.childNodes[z].offsetWidth - 38) + "px";
                smenu2.style.display = "";
              }

            }
          }
          smenu.style.display = "";
        }
      }
    }
    if (isIE6) {
      var fadd = document.getElementsByTagName('address');
      if (fadd.length) {
        fadd[fadd.length - 1].style.display = "none";
        fadd[fadd.length - 1].style.display = "block";
      }
    }
  }

  // Modify links which have certain magic classNames
  var replinks = document.body.getElementsByTagName('a');
  for (var x = 0, lnk; lnk = replinks[x++];) {
    if (lnk.className.indexOf("tblank") > -1) lnk.target = "_blank";
  }
});
