/********************************************************************************/
/* Description: Various Java Functions                                          */
/* Updates:                                                                     */
/* Date        Who                Description                                   */
/* ==========  =============      ============================================= */
/* 03/01/2009  Ian Clark          Original.                                     */
/* 03/26/2009  Ian Clark          Added functions to support animated buttons.  */
/********************************************************************************/
// Function to get the Browser type.
function getBrowserType() {
  var browser = navigator.appName;
  var browserType = "Netscape";
  if (browser == "Microsoft Internet Explorer") {
    browserType = "IE";
  }
  return browserType;
} // End of: 'function getBrowserType() {'
  
// Function to get the query parms from the URL.
function getQueryParms() {
  var QueryParms = new Array();
  var query = window.location.search.substring(1);
  var parms = query.split('&');
  for (var i=0; i<parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos+1);
      QueryParms[key] = val;
    } // End of: 'if (pos > 0) {'
  } // End of: 'for (var i=0; i<parms.length; i++) {'
  return QueryParms;
} // End of: 'function getQueryParms() {'

// This function will open an xml document
function getXMLDoc(RelativeURL, NoAlert) {
  // Get the browser type
  var BrowserType = getBrowserType();
  var XMLDocument;
  try { 
    // Create an xml document.
    if (BrowserType == "IE") {
      XMLDocument = new ActiveXObject('Microsoft.XMLDOM');
    } else {
      XMLDocument = document.implementation.createDocument("","",null);
    } // End of: 'if (BrowserType == "IE") {'  
    
    // Load the file.
    XMLDocument.async=false;
    XMLDocument.load(RelativeURL);
    
    // Return it.
    return(XMLDocument);

  } catch(e) {
  if (! NoAlert) {
    alert("Error opening " + RelativeURL + ", " + e.message);
  } // End of: 'if (!NoAlert) {'  
  return (null);
  } // End of: 'try { // Create an xml document.'
    
} // End of: 'function getXMLDoc(RelativeURL) {'

// This function is used to switch alternative sections of an input form on or off
// Based on a pair of radio buttons. 
function UISwitch(RadioButtonName) {
  var RadioButtons = document.getElementsByName(RadioButtonName);
  var NumRadioButtons = RadioButtons.length;
  // Switch on or off the elements as appropriate. 
  for (myIndex=0;myIndex<NumRadioButtons;myIndex++) {
    SwitchOnOrOff(RadioButtons[myIndex].value,RadioButtons[myIndex].checked );
  } //End of: 'for (RadioButton in RadioButtons) {'
  
} // End of: 'function UISwitch(RadioButtonName) {' 

// This is a helper function for the one above.
function SwitchOnOrOff(ElementName, SwitchOn) {

  var Index = 1;
  while (myElement = document.getElementById(ElementName + Index)) {
    if (SwitchOn) {
      myElement.style.display = '';
    } else {
      myElement.style.display = 'none';
    } //End of: 'if (SwitchOn)'
    Index++;
  } //End of: 'while (myElement = document.getElementById(ElementName + Index) {'
  
} // End of: 'function SwitchOnOrOff(Elementname) {'


// This function supports changing the button back to normal.
function buttonNormal(ButtonPath, ButtonName){
   document.images[ButtonName].src=ButtonPath + '/' + ButtonName + '_0.gif';
} // End of: 'function changeNormal(ButtonPath, ButtonName){'

// This function supports the mouse-over for a button.
function buttonOver(ButtonPath, ButtonName){
   document.images[ButtonName].src=ButtonPath + '/' + ButtonName + '_1.gif';
} // End of: 'function changeOver(ButtonPath, ButtonName){'

// This function supports the button push.
function buttonDown(ButtonPath, ButtonName){
   document.images[ButtonName].src=ButtonPath + '/' + ButtonName + '_2.gif';
} // End of: 'function changeDown(obj){'

// This function supports changing the button back to normal.
// It has a suffix for the name to support multiple uses of the same graphic.
function buttonNormal2(ButtonPath, ButtonName, Suffix){
   document.images[ButtonName + Suffix].src=ButtonPath + '/' + ButtonName + '_0.gif';
} // End of: 'function changeNormal(ButtonPath, ButtonName){'

// This function supports the mouse-over for a button.
// It has a suffix for the name to support multiple uses of the same graphic.
function buttonOver2(ButtonPath, ButtonName, Suffix){
   document.images[ButtonName + Suffix].src=ButtonPath + '/' + ButtonName + '_1.gif';
} // End of: 'function changeOver(ButtonPath, ButtonName){'

// This function supports the button push.
// It has a suffix for the name to support multiple uses of the same graphic.
function buttonDown2(ButtonPath, ButtonName, Suffix){
   document.images[ButtonName + Suffix].src=ButtonPath + '/' + ButtonName + '_2.gif';
} // End of: 'function changeDown(obj){'