/*****************************************************************
Large portions of this file are based on code graciously provided
to the public by by Danny Goodman (www.dannyg.com)
******************************************************************/

    //test function
    function bling(msg) {
        var astr = "===>> *" + msg + "* <<===";
        alert(astr);
    }

var isNav = ((navigator.appName == "Netscape") &&
             (parseInt(navigator.appVersion) >= 4))
var isIEMac = (!isNav && navigator.userAgent.indexOf("Mac") != -1)

//********BEGIN 'THE EVALUATOR'************************************
// Evaluate an expression (including executing a statement)
// and display returned values in 'output' textarea. Provide
// switch for Navigator codebase principal security.
function evaluateIt(form) {
  if (isNav && form.security.checked) {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite")
  }
  form.output.value = eval(form.input.value)
  if (isNav && form.security.checked) {
    netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserRead")
    netscape.security.PrivilegeManager.disablePrivilege(
        "UniversalBrowserWrite")
  }
}

// List all properties of an object (except for document.domain) 
// in the 'output' textarea.
function showProps(form) {
  objName = form.inspector.value
  obj = eval(objName)
  var msg = ""
  var count = 0
  var cr = (isIEMac) ? "\r\n" : "\n"

  for (var i in obj) {
    if (i != "domain") {
      msg += objName + "." + i + "=" + obj[i] + cr
    }
  }
  form.output.value = msg
}

// Event handler looks for Enter key to trigger evaluateIt()
function evalIfReady(form, evt) {
  if (isNav) {
    if (evt.which == 13) {
      evaluateIt(form)
      return false
    }
  } else {
    if (window.event.keyCode == 13) {
      evaluateIt(form)
      return false
    }
  }
  return true
}

// Event handler looks for Enter key to trigger showProps()
function showPropsIfReady(form, evt) {
  if (isNav) {
    if (evt.which == 13) {
      showProps(form)
      return false
    }
  } else {
    if (window.event.keyCode == 13) {
      showProps(form)
      return false
    }
  }
  return true
}

var a, b, c, d, e, f
// Writes The Evaluator fields to your document wherever you want.
function printEvaluator() {
  document.writeln("<hr size='4'><FORM onSubmit='return false'>")
  document.writeln("<p>Enter an expression to evaluate:<br />")
  document.writeln("<input type='text' name='input' size=80 ")
  if (!isIEMac) {
    document.writeln("onKeyPress='return evalIfReady(this.form, event)'")
  }
  document.writeln("><input type='button' value='Evaluate' " +
                   "onClick='evaluateIt(this.form)'>&nbsp;")
  if (isNav) {
    document.writeln("<input type='checkbox' name='security'>Use " +
                     "Codebase Security")
  }
  document.writeln("</p><p>Results:<br />")
  document.writeln("<textarea name='output' cols='80' rows='6' " +
                   "wrap='virtual'>")
  document.writeln("</textarea></p>")
  document.writeln("<p>Enter a reference to an object:<br>")
  document.writeln("<input><input><br>")
  document.writeln("</form>")
}
//********END 'THE EVALUATOR'************************************


//********BEGIN PROPERTY DUMPER**********************************
// output list of properties for the object
function dumpProps(objName) {
  var obj = eval(objName)
  var msg = ""
  var count = 0
  var maxProps = 10

  // loop through properties of the object
  for (var i in obj) {
    if (i != "outerHTML" && i != "outerText" && i != "innerHTML" &&
        i != "innerText" && i != "domain") {
      msg += objName + "." + i + "=" + obj[i] + "\n"
      if (count > maxProps) {
        // output a batch
        if (isNav) {
          java.lang.System.out.println(msg)
        } else {
          alert(msg)
        }
        msg = ""
        count = 0
        continue
      }
      count++
    }
  }
  // output any leftovers
  if (isNav) {
    java.lang.System.out.println(msg)
  } else {
    alert(msg)
  }
}
//********END PROPERTY DUMPER************************************


//********BEGIN TRACER*******************************************
// trace debugger (see
//  http://developer.netscape.com/viewsource/goodman_jsdebug.html)
// var IETraceWind
function trace(flag, label, value) {
  if (flag) {
    var funcName = trace.caller.toString()
    funcName = funcName.substring(10, funcName.indexOf(")") + 1)
    var msg = "In " + funcName + ": " + label + "=" + value
    if (isNav) {
      java.lang.System.out.println(msg)
    } else {
      if (!IETraceWind || IETraceWind.closed) {
        IETraceWind = window.open()
      }
      IETraceWind.document.writeln(msg)
    }
  }
}
//********END TRACER*********************************************


//********BEGIN AUTOFOCUS****************************************
//  <input type="text" name="cc3" size="5" maxlength="4" 
//      onkeypress="return numeralsOnly(event)" 
//      onkeyup="autofocus(this, 4, 'cc4', event)">&nbsp;&nbsp;
//  <input type="text" name="cc4" size="5" maxlength="4" 
//      onkeypress="return numeralsOnly(event)">
//  
//  The onkeypress event handler for each field restricts entry to
//  numerals, while the onkeyup event handlers invoke the following
//  function, which advances focus to a named form field after a set
//  number of characters:
function autofocus(field, limit, next, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
                                    ((evt.keyCode) ? evt.keyCode : 
                                                     ((evt.which) ? evt.which :
                                                                    0));
    if (charCode > 31 && field.value.length == limit) {
        field.form.elements[next].focus( );
    }
}
//********END AUTOFOCUS******************************************


//********BEGIN NO_OP********************************************
function no_op(name) {
    var str = name;
}
//********END NO_OP**********************************************

//  Easily handle parameters in the search part of a URL
//  
//  <HTML><HEAD></HEAD><BODY>
//  <SCRIPT>
//  TheParameters  = document.location.search.substring(1,255)
//  alert(TheParameters)
//  TheParametersArray = TheParameters.split("&")
//  k = TheParametersArray.length
//  for (i= 0 ; i < k; i++) {
//   alert(unescape(TheParametersArray[i]))
//    }
//  </SCRIPT></BODY></HTML>


//******** BEGIN WPOP ********************************************
// utility shortcut to open a popup window with a given name and source
function wpop(wname, fname)
{
    window.open(fname, wname, "resizable,scrollbars,height=400,width=600");
}
//******** END WPOP **********************************************


//******** BEGIN SWAP IMAGES ******************************
function swapImages(ImageName, NewImage)
{

  /* test to see if the browser understands
   * rollovers
   * If it does swap one image for the other
   */

  if (document.images)
  {
    document[ImageName].src = NewImage;
  }
}

//******** END SWAP IMAGES ********************************


//******** BEGIN OPEN CLOSE ******************************
//preload images for OpenClose
if (document.images) {
    btnPlus = new Image;
    btnMinus = new Image;
    btnPlus.src = "/images/DRSC-btn-plus.gif";
    btnMinus.src = "/images/DRSC-btn-minus.gif";
} else {
    btnPlus = "";
    brnMinus = "";
}
function openClose(ThisID, ImageName)
{
    if (document.getElementById(ThisID).style.display == 'none')
    {
        document.getElementById(ThisID).style.display = '';
        document[ImageName].src = btnMinus.src;
    } else {
        document.getElementById(ThisID).style.display = 'none';
        document[ImageName].src = btnPlus.src;
    }
}
//******** END OPEN CLOSE ********************************
