/** A.  this script file handles browser differences in one place.  The following functions will be useful to most situations
	    that need to support multiple browser versions:
		   getObjectById(sId) - pass in the id of the object, returns the id.  How the id is found is based on capabilities of the browser
		   getObjectsByTagName(sTagName) - pass in the name of the tag, returns a collection of objects of that type.  How they are found is
					based on the capabilities of the browser
		   Please take note of the following info:
			  1.  if user is using an incompatible browser (doesn't support layers/all collections or W3C DOM getElementById method,
				an alert message box will appear
			  2.  the name property doesn't work in Netscape, so unfortunately we can't just group things together using the same name
	B.  this script file will also contain methods that are not browser-specific, but are useful common utilities.  It has
		the following methods:
			doObjectVisibilityById(sId, bDisplay) -this will hide/display the object represented by the input id.  If
					bDisplay is true, it will display the object.  Else it will hide the object.
			doObjectVisibilityByName(sTagName, sFieldName, bDisplay) -this will display the object represented by the input name and tag name.  If
					bDisplay is true, it will display the object.  Else it will hide the object.  Please note that this
					does not work as expected in Netscape since it does not support the name property
			hideObject(obj) -this will hide the input object
			showObject(obj) -this will display the input object
**/
var usesId = (document.getElementById) ? true : false;  //this uses the getElemById method, ie IE5, NS6 and above (hopefully!)
var isLayersOnly = (document.layers) ? true : false;  //this uses layers collections only, ie NS4
var isAllOnly = (document.all && !document.getElementById) ? true : false; //this uses all collections only, ie IE4
var sWrongBrowserMsg = "I am sorry, but you are using an incompatible browser.  Please get IE4 or above or Netscape 4 or above.  If you continue to use this browser, things may not work as expected.";

//this will get a document object, doing so based on browser capabilities
function getObjectById(sId) {
  var elm;

  if (isLayersOnly){
   elm = document.layers[sId];
  }
  else if (isAllOnly) {
   elm = document.all(sId);
  }
  else if (usesId) {
   elm = document.getElementById(sId);
  }
  else {
    alert(sWrongBrowserMsg);
  }
  return elm;
}

//this will get a document object based on the input id and the input tag type
function getObjectByIdAndTagName(sId, sTagName) {

  //this will get me all the objects with the specified tag type
  var tmpObjs =	getObjectsByTagName(sTagName);
  //loop thru the objects and check the id of each
  for (i = 0; i < tmpObjs.length; ++i) {
    if (tmpObjs[i].id==sId) { //once we get the one with that id, return it
      return tmpObjs[i];
    }
  }
  return null;  //if we get here, it wasn't found
}

//this will get a collection of objects with the input tag name, doing so based on browser capabilities
function getObjectsByTagName(sName) {
  var elm;

  if (isLayersOnly){
   elm = document.layers[sName];
  }
  else if (isAllOnly) {
   elm = document.all.tags(sName);
  }
  else if (usesId) {
   elm = document.getElementsByTagName(sName);
  }
  else {
    alert(sWrongBrowserMsg);
  }
  return elm;
}

//this will hide the input object
function hideObject(o) {
	o.style.visibility = "hidden";
	o.style.display = "none";
}
//this will display the input object
function showObject(o) {
	o.style.visibility = "visible";
	o.style.display = "inline";
}

//this will hide/display the object represented by the input id based on the input display mode
function doObjectVisibilityById(sId, bDisplay) {
  if (bDisplay) {
    showObject(getObjectById(sId));
  }
  else {
    hideObject(getObjectById(sId));
  }
}

//this will hide/display all the objects with the specified name of the specified tag type
//Please note that this does not work as expected in Netscape since the name property
//is undefined.
function doObjectVisibilityByTagName(sTagName, sFieldName, bDisplay) {
  var tmpObjs =	getObjectsByTagName(sTagName); //this will get me all the objects with the specified tag type
  for (i = 0; i < tmpObjs.length; ++i) { //loop thru them
    if (tmpObjs[i].name==sFieldName) { //if of the same name
      if (bDisplay) {
          showObject(tmpObjs[i]); //show them
      } else {
          hideObject(tmpObjs[i]); //hide them
      }
    }
  }
}

//this will return a blank string if the input is null
function echoBlankIfNull(str) {
	if (str == null)
		return "";
	return str;
}

//This checks for browser type
function bw_check(){
    var is_major = parseInt(navigator.appVersion);
    this.ver=navigator.appVersion;
    this.agent=navigator.userAgent;
    this.dom=document.getElementById?1:0;
    this.opera=this.agent.indexOf("Opera")>-1;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera)?1:0;
    this.ie4=(document.all && !this.dom && !this.opera)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6;
    this.mac=this.agent.indexOf("Mac")>-1;
    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ie3 = (this.ver.indexOf("MSIE") && (is_major < 4));
    this.hotjava = (this.agent.toLowerCase().indexOf('hotjava') != -1)? 1:0;
    this.ns4=(document.layers && !this.dom && !this.hotjava)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera);
    this.ver3 = (this.hotjava || this.ie3);return this;
}

function echoBlankIfNull(str) {
	if (str == null)
		return "";
	return str;
}

