// utilsHTML.js   V 1.0

function addOnLoad(new_function) {
  var old_onload = (window.onload) ? window.onload : function(){};
  window.onload = function() {
    old_onload();
    new_function();
  }
}

function focusControl(control) {
  if (isDefined(control.length)) control = control[0];
  if (isDefined(control.focus)) control.focus();
}

function selectControl(control) {
  focusControl(control);
  if (isDefined(control.select)) control.select();
}

function setSelectAll(f, state) {
  for (var r = 0; r < f.length; r++) {
    f.options[r].selected = state;
  }
}

function swapSelectOptions(fFrom, fTo, isMulti) {
  if (fFrom.selectedIndex != -1) {
    for (var r = 0; r < fFrom.length; r++) {
      opt = fFrom.options[r];
      if (opt.selected) {
        fTo.options[fTo.length] = new Option(opt.text, opt.value);
        fFrom.remove(r--);
        if (!isMulti) break;
      }
    }
  }
}

function openWindow(theURL, winName, myWidth, myHeight, isCenter, features) {
  features += ((features != "") ? "," : "") + "width=" + myWidth + ",height=" + myHeight;
  if (isCenter && window.screen) {
    var myLeft = (screen.width - myWidth) / 2;
    var myTop = (screen.height - myHeight) / 2;
    features += ",left=" + myLeft + ",top=" + myTop;
  }
  return window.open(theURL, winName, features);
}

function openSimpleWindow(theURL, winName, myWidth, myHeight, isCenter) {
  return openWindow(theURL, winName, myWidth, myHeight, isCenter, "toolbar=0,resizable=0,scrollbars=0,menubar=0,status=0");
}
