// Utility functions.

browserDetected = false;

// Browser detect cribbed from:
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
function
browserDetect()
{
  // note: following variables intentionally global.
  agt=navigator.userAgent.toLowerCase();
  is_major = parseInt(navigator.appVersion);
  is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  is_nav6up = (is_nav && (is_major >= 5));
  is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
}

// Load a new page in the current window, without caching.
// window.location= loads from cache in IE, window.navigate()
// not available in Netscape, window.replace() loads from 
// cache in Netscape 4.79 and causes BACK button to skip page
function
loadPage (p)
{
  if (!browserDetected)
    browserDetect();
  if (is_ie) {
    window.navigate(p);
  } else {  // most portable, but problematic in IE
    window.location=p;
  }
}

// Reset fields of a form.
// Resets all text and textarea fields to empty, all select boxes to
// the first element, all checkboxes and radiobuttons to unchecked.
// Other types not handled.
function
doReset(f)
{
  for (var i = 0; i < f.length; i++) {
    var e = f.elements[i];
    if (e.type == "text") {
      e.value = '';
    } else if (e.type == "select-one") {
      e.selectedIndex = 0;
    } else if (e.type == "checkbox") {
      e.checked = false;
    } else if (e.type == "radio") {
      e.checked = false;
    }
  }
}
