/* isInternetExplorer()
***********************
Determines if this browser is internet explorer
or otherwise. Unfortunately IE presents some
serious DOM problems...
*/
function isInternetExplorer() {
   if (navigator.appVersion.indexOf('MSIE') != -1) return true;
   else return false;
}

/* getParams()
**************
Gets paramets from a specific form.
*/
function getParams(formName) {
   var params = '';
   var i;

   for (i=0; i<document.forms[formName].elements.length; i++) {
      params += document.forms[formName].elements[i].name;
      params += '=';
      params += encodeURIComponent(document.forms[formName].elements[i].value);
      params += '&';
   }

   params = params.substring(0,params.length-1);

   return params;
}

/* replaceNodeX()
*****************
Replaces an existing node with a new one according
to id.
*/
function replaceNodeX(intruder, home) {
   // var originalNode = home.id;

   var originalNode =  home.getAttribute('id');
   document.getElementById(originalNode).parentNode.replaceChild(intruder,home);
}

/* setAttributeById()
*********************
IE/Firefox framework that takes an element id, the attribute to be set (e.g. 
onmouseover, onmouseout) and the function as a string. Results in a 
browser-safe correct setting of the attribute. Add more events here.
*/
function setAttributeById(id, attrib, val) {
   if (attrib == 'onmouseover') {
      document.getElementById(id).onmouseover = new Function(val);
      document.getElementById(id).setAttribute('onMouseOver',val);
   }
   else if (attrib == 'onmouseout') {
      document.getElementById(id).onmouseout = new Function(val);
      document.getElementById(id).setAttribute('onMouseOut',val);
   }
   else if (attrib == 'onload') {
      document.getElementById(id).onload = new Function(val);
      document.getElementById(id).setAttribute('onLoad',val);
   }
}

/* toggleDisplay()
******************
Alters the display attribute of the selected element.
*/
function toggleDisplay(id, type){
   if ((!this.document.getElementById(id).style.display) || (this.document.getElementById(id).style.display == 'none')) {
      this.document.getElementById(id).style.display = type;
   }
   else {
      this.document.getElementById(id).style.display='none';
   }
}

/* setSelectedIndex()
*********************
For a given select box id, preselect its value.
*/
function setSelectedIndex(element,preselected) {
   var i;

   for (i=0; i<element.options.length; i++) {
      if (element.options[i].value == preselected) {
         element.options[i].selected = true;
      }
      else {
         element.options[i].selected = false;
      }
   }
}
