var openWindow;

function openwin(url, name, width, height) {
  var w = window.open(url, name, setwinparams(width, height));
  w.focus();
}

function openwinmodal(url, name, width, height) {
  openWindow = window.open(url, name, setwinparams(width, height));
}

function setwinparams(width, height) {
  var debug = false;
  var winparams = "toolbar=no,resizable=no,scrollbars=yes";
  if (debug) {
    winparams += ",status=yes";
  } else {
    winparams += ",status=no";
  }
  if (height) {
    winparams += ",height=" + height;
  } else {
    winparams += ",height=" + 525;
  }
  if (width) {
    winparams += ",width=" + width;
  } else {
    winparams += ",width=" + 700;
  }
  return winparams;
}

function checkForOpenWindow() {
  if (openWindow && !openWindow.closed) {
    openWindow.focus();
    return false;
  }
  return true;
}

function confirmurl(text, url) {
  if (confirm(text)) {
    window.location.href = url;
  }
  return false;
}

// returns an element in a cross-platform way
function getElement(id) {
    return document.getElementById ? document.getElementById(id) :
       document.all ? document.all(id) :
       document.layers ? document.layers[id] : null;
}

function hide(id) {
  var ns4 = (document.layers);
  var ie4 = (document.all);
  var ns6 = (document.getElementById);
  if (ns4) {
    if (document.layers[id]) {
      document.layers[id].visibility = "hide";
    }
  }
  else if (ie4) {
    if (document.all[id]) {
      document.all[id].style.visibility = "hidden";
    }
  }
  else if (ns6) {
    if (document.getElementById(id)) {
      document.getElementById(id).style.visibility = "hidden";
    }
  }
}

// Find the first INPUT child of this object and set .checked
function checkFirstChild(obj, event) {
  if (event.target != obj && event.srcElement != obj)
    return true;

  var children = obj.children ? obj.children : obj.childNodes;
  for (var x = 0; x < children.length; x++) {
    var node = children[x];
    if (node.tagName ==  'INPUT') {
      if (node.type == "radio") {
        node.checked = 1;
      } else {
        node.checked = !node.checked;
      }
      if (node.onchange) {
        node.onchange();
      }
      return false;
    }
  }
  return true;
}

