/*
Utility functions

v0.1 MK 20060227	refactored
*/

// Use with pulldown menus

function redirectPulldown (menuChoice) {
  var destination = menuChoice[menuChoice.selectedIndex].value;
  if (destination == '' || destination == 'none') {
    return false;
  } else if (destination.indexOf('NEW:') == 0) {
    w = window.open (destination.substring(4));
  } else {
    window.location.href = destination;
  }
}


// fixup hover in dropdown menus for MSIE

function fixupDropdown () {
  if (document.all&&document.getElementById) {
    var menuRoot = document.getElementById("menuDropdown");
    for (i=0; i < menuRoot.childNodes.length; i++) {
      var node = menuRoot.childNodes[i];
      if (node.nodeName == "LI") {
        node.onmouseover = function() {
          this.className += " over";
        }
        node.onmouseout = function() {
          this.className = this.className.replace(" over", "");
        }
      }
    }
  }
}


// trim spaces at beginning and end of string

function trimSpaces (s) {
  var i, j;
  for (i = 0; i < s.length; i++) {
    if (s.charAt(i) != ' ') break;
  }
  for (j = s.length-1; j > 0; j--) {
    if (s.charAt(j) != ' ') break;
  }
  return s.substring(i,j+1);
}


// explode string

function explodeString (inputString, separators, includeEmpties) {
  s = new String(inputString);
  sep = new String(separators);

  if (sep == "undefined") {
    sep = " ,;";
  }

  fixedExplode = new Array();
  currentElement = "";
  count = 0;

  for (x=0; x < s.length; x++) {
    c = s.charAt(x);
    if (sep.indexOf(c) != -1) {
      currentElement = trimSpaces (currentElement);
      if (((includeEmpties > 0) && (includeEmpties != false)) || (currentElement != "")) {
        fixedExplode[count] = currentElement;
        count++;
        currentElement = "";
      }
    } else {
      currentElement += c;
    }
  }

  currentElement = trimSpaces (currentElement);
  if ((!(includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != "")) {
    fixedExplode[count] = currentElement;
  }
  return fixedExplode;
}


// sorting help

function sortCompare (a,b) {
  if (a<b) return 1;
  if (a>b) return -1;
  return 0;
}


