function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// backwardly compatible with those pages that need it.
function onloadfunc_doer() {
  if (window.onloadfunc != null) {onloadfunc()}
}
addLoadEvent(onloadfunc_doer);

// JS functions to present mouse-over popups.
function hidelayer(lay) {
    if (document.getElementById) {document.getElementById([lay]).style.display = "none";}
    if (document.all) {document.all[lay].style.visibility = "hidden";}
    if (document.layers) {document.layers[lay].visibility = "hide";}
}

function showlayer(lay) {
    if (document.getElementById) {document.getElementById([lay]).style.display = "inline";}
    if (document.all) {document.all[lay].style.visibility = "visible";}
    if (document.layers) {document.layers[lay].visibility = "show";}
}
  

// JS goodness to load states and cities.
function xmlGet(url, changeFunc) {
  var req;
  function changeHandler() {
    if(req.readyState == 4) {
      if(req.status == 200) {
	changeFunc(req.responseXML);
      } else {
	alert("There was a problem retrieving the data: \n" +
	      req.statusText);
      }
    }
  }

  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = changeHandler;
    req.open("GET", url, true);
    req.send(null);
    // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    isIE = true;
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = changeHandler;
      req.open("GET", url, true);
      req.send();
    }
  }
}	 

function clearSelectList(selectId) {
  var select = document.getElementById(selectId);
  while(select.length > 0) { select.remove(0); }
}

function appendToSelect(select, value, content) {
  var opt;

  opt = document.createElement("option");
  opt.value = value;
  opt.appendChild(content);
  select.appendChild(opt);
}
