var browsername = navigator.appName;
var isNS = (browsername.indexOf("Netscape")!=-1);
var isIE = (browsername.indexOf("Microsoft")!=-1);
var isMac = (navigator.appVersion.indexOf('Mac')!=-1) ? true : false;
var NS4 = (document.layers) ? true : false;
var IEmac = ((document.all)&&(isMac)) ? true : false;
var IE4plus = (document.all) ? true : false;
var IE4 = ((document.all)&&(navigator.appVersion.indexOf('MSIE 4.')!=-1)) ? true : false;
var IE5 = ((document.all)&&(navigator.appVersion.indexOf('MSIE 5.')!=-1)) ? true : false;
var IE55 = ((document.all)&&(navigator.appVersion.indexOf('MSIE 5.5')!=-1)) ? true : false;
var IE6 = ((document.all)&&(navigator.appVersion.indexOf('MSIE 6.')!=-1)) ? true : false;
var ver4 = (NS4 || IE4plus) ? true : false;
var NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1) ? true : false;

function doPrintPage() {
  window.print();
  window.close();
}

function gourl(theurl) {
  top.location.href=theurl;
}

function navigateParent(theurl) {
  opener.document.location=theurl;
  self.close();
}

function forceNoFrames() {
  if (self!=top) {
    top.location=self.location;
  }
}

function supportsForcedDownload() {
  return !(IE55 || IE6);
}

function supportsResizableFrames() {
  if (IEmac) {
    return false;
  } else if (IE4plus) {
    return true;
  } else {
    return false;
  }
}

function browserSwitch2(IEtext, NS4text) {
  browserSwitch5("", IEtext, NS4text, "");
}

function browserSwitch3(IEtext, netscapeText, otherText) {
  browserSwitch5("", IEtext, netscapeText, otherText, "");
}

function browserSwitch(prefText, IEtext, NS4text, suffText) {
  browserSwitch5(prefText, IEtext, NS4text, IEtext, suffText);
}

function browserSwitch5(prefText, IEtext, NS4text, otherText, suffText) {
  document.write(prefText+getText(IEtext, NS4text, otherText)+suffText);
}

function getText(IEtext, NS4text, otherText) {
  if (document.layers) {
    return NS4text;
  } else if (document.all) {
    return IEtext;
  } else {
    return otherText;
  }
}

function getObj(name) {
  if (document.getElementById) {
    return document.getElementById(name).style;
  } else if (document.all) {
    return document.all[name].style;
  } else if (document.layers) {
    return getObjNN4(document, name);
  }
}

function getObjNN4(obj, name) {
  var x = obj.layers;
  var ret;
  for (var i=0; i<x.length; i++) {
    if (x[i].id == name) {
      ret = x[i];
    } else if (x[i].layers.length) {
      var tmp = getObjNN4(x[i],name);
      if (tmp) {
        ret = tmp;
      }
    }
  }

  return ret;
}

function screenWidth() {
  if (IE4plus) {
    return document.body.clientWidth;
  } else {
    return window.innerWidth;
  }
}

function screenHeight() {
  if (IE4plus) {
    return document.body.clientHeight;
  } else {
    return window.innerHeight;
  }
}

function screenTop() {
  if (IE4plus) {
    return document.body.scrollTop;
  } else {
    return window.pageYOffset;
  }
  return 0;
}

function screenBottom() {
  return screenTop() + screenHeight();
}

String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");

String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");

String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");

function isEmailAddr(email) {
  var ret = false;
  var s = new String(email);
  var ix = s.indexOf("@");
  if (ix > 0) {
    var dix = s.indexOf(".", ix);
    if ((dix > ix+1) && (s.length > dix+1)) {
      ret = true;
    }
  }
  return ret;
}

function checkChoice(f, i) {
  if (i==0) {
    // "All" checkbox selected.
    if (f[0].checked == false) {
      for (i=1; i<f.length; i++) {
        f[i].checked = f[0].checked;
      }
    }
  } else {
    // A checkbox other than "Any" selected.
    if (f[i].checked == true) {
      f[0].checked = true;
    }
  }
  var total = 1;  
  for (i=1; i<f.length; i++) {
    if (!f[i].checked) {
      total += 1;
    }
  }
  if (f.length > 0) {
    if (total == f.length) {
      f[0].checked = false;
    }
  }   
}

