function setClass (e,c) {
  e.setAttribute ('class', c); e.setAttribute ('className', c);
}

// Args: classname[, start node, tag filter]
function getElementsByClass (searchClass,node,tag) {
  var classElements = [];
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
  for (i = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) )
      classElements.push(els[i]);
  }
  return classElements;
}

// Fade: from full opacity to none
//
function fade (e, msg, delay) {
  e.innerHTML = msg;
  if (delay > 0)
    setTimeout (function() { fadeStep(e, 10) }, delay*1000);
}
function fadeStep(e, s) {
  if (s > 0) {
    setOpacity (e, s-1);
    setTimeout (function() { fadeStep(e,s-1) }, 90);
  } else {
    e.innerHTML = '';
    setOpacity (e, 10);
  }
}
function setOpacity(e, value) {  // value=0-10
  e.style.opacity = value/10;  /* moz/saf */
  e.style.filter = 'alpha(opacity=' + value*10 + ')'; //ie
}

// Highlight: from highlighted to white background
// Args: element, colorMap, [startDelay]
//
function highlight (e, hmap, delay) {
  var num = hmap.length - 1;
  e.style.backgroundColor = hmap[num];
  var fn = function() { highlightStep(e, num-1, hmap) };
  if (delay != null && delay > 0)
    setTimeout (fn, delay);
  else
    fn();
}
function highlightStep (e, num, hmap) {
  e.style.backgroundColor = hmap[num];
  if (num > 0)
    setTimeout (function() { highlightStep(e, num-1, hmap) }, 1000/hmap.length);
}

function stretch (e, n, cl, wmap) {
  e.style.width = wmap[n];
  if (++n < wmap.length)
    setTimeout (function() { stretch(e,n,cl,wmap) }, 900/wmap.length);
  else
    setClass(e,cl);
}

function popHelp(url) {
  var w = window.open (url, "helpWin", 'dependent=1,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400');
  if (w) w.focus();
  return w;
}

function log (message) {
  if (!log.window_ || log.window_.closed) {
    var win = window.open("", null, "width=400,height=200," +
        "scrollbars=yes,resizable=yes,status=no," +
        "location=no,menubar=no,toolbar=no");
    if (!win) return;
    var doc = win.document;
    doc.write("<html><head><title>Debug Log</title></head>" +
        "<body></body></html>");
    doc.close();
    log.window_ = win;
  }
  var logLine = log.window_.document.createElement("div");
  logLine.appendChild(log.window_.document.createTextNode(message));
  log.window_.document.body.appendChild(logLine);
}


