/**
* Includes
*/
includeJS.Path = './js/';
includeJS('prelude/onAlmostLoad.js');
//includeJS('prelude.cookie.js');
includeJS('prelude/quickDOM.js');
includeJS('prelude/HtmlToEmail.js');


/**
* Script maestro
*/

window.onload = function () {
  if ( window.includeJS.IsLoading ) { window.includeJS.OnEmpty = main; }
  else main();
}


function main () {
  if (window.loadImages) window.loadImages();
  HtmlToEmail( document.getElementsByTagName('BODY')[0] );
  
  activarMenu();
  
  //agregarNedstat("ACPc3w+KLAyZrcdADVZZQEnhwmXA", 'nedstat', true);

}



/**
* Agrega la clase "active" a cada LI y enlace cuyo href sea esta página
*/
function activarMenu(node, newClass) {
  if (!node) node = document.getElementsByTagName('BODY')[0];
  if (!newClass) newClass = 'active';

  var thisPage = document.location.href.before('#');
  var ifNode = function (n) { return n.nodeName == 'A' ; }
  var perform = function (n) { 
    var addClass = function (n,c) { n.className = (n.className?n.className+' ':'') + c; };
    if (thisPage == n.href ) {
      addClass(n, newClass);
      if (n.parentNode.nodeName == 'LI') addClass(n.parentNode, newClass);
    }
  }
  
  DOMIterator(ifNode, perform, node);
}


// Agrega Nedstat
function agregarNedstat(nedstatCode, nodeId, visible) {
  includeJS.OnEmpty = function () {
    var dw = document.write;
    document.write = function (e) { document.globalNedtstat = e; }
    nedstatbasic(nedstatCode, 0);
    document.write = dw;
    var span = document.createElement('span');
    span.innerHTML = document.globalNedtstat;
    if (!visible) {
      span.style.position = 'absolute';
      span.style.height = '1px';
      span.style.textIndent = '-1000px';
      span.style.overflow = 'hidden';
    }
    document.getElementById(nodeId).appendChild(span); 
  };
  includeJS( "http://m1.nedstatbasic.net/basic.js");
}