/*
    musicJS.js
    David Peet, UMass Lowell CS, dpeet@cs.uml.edu
    updated December 3, 2003 at 12:57 AM
*/


  /** This function gets the value of a named field and returns a single
   *  string value or null if the named field does not exist.
   *
   *  If there is more than one field with the same name in the location.search
   *  string, this function returns only the first one.  If one knows that
   *  there will be more than one field with the same name, s/he should use
   *  the getMultiField function instead of this one.
   *
   *  Author:  Jesse M. Heines, UMass Lowell Computer Science, heines@cs.uml.edu
   *  Revised: by JMH on January 31, 2002 at 11:56 AM
   *  Parameters:
   *     (1)  strName  the name of the field to extract
   *  Return Value:
   *     string  value of specified field or null if the field does not exist
   */
  function getField( strName )
  {
    // extract the address part starting at the "?"
    var strSearch = "" + location.search ;

    // find the location of the field name you're looking for
    var intStart = strSearch.indexOf( strName + "=" ) ;

    // make sure that field name is not part of a larger field name,
    // that is, a substring of a larger field name
    var boolOK = ( intStart > 0 ) &&
                 ( strSearch.charAt( intStart-1 ) == "?" ||
                   strSearch.charAt( intStart-1 ) == "&" )

    // if the field is not found or is part of a larger field name,
    // return null
    if ( ! boolOK )
      return null ;

    // else extract the field's value and return it
    else
    {
      // extract from the start of the value to the end of the entire
      // search string and append an ampersand to the end of the
      // extract value string
      var strValue =
        strSearch.substr( intStart + strName.length + 1 ) + "&" ;

      // find the position of the first ampersand in the value string
      // and return the substring ending at the first ampersand
      return strValue.substr( 0, strValue.indexOf( "&" ) ) ;
    }
  }

  // ----------------------------------- //

  function userBrowser()
  {
     var strReturn = "";

     var strNavPlat = navigator.platform ;    // determine user's platform
     if ( strNavPlat == "Win32" )
       strNavPlat = "Windows" ;

     var strNavName = navigator.appName ;     // determine user's browser name
     if ( strNavName == "Microsoft Internet Explorer" )
       strNavName = "Internet Explorer" ;

     var strNavVer = navigator.userAgent ;   // determine user's browser version
     if ( strNavName == "Internet Explorer" )
     {
       strNavVer = strNavVer.substring( strNavVer.indexOf( "MSIE" ) + 5 ) ;
       strNavVer = strNavVer.substring( 0, strNavVer.indexOf( ";" ) ) ;
     }
     else if ( strNavName == "Netscape" )
     {
       strNavVer = strNavVer.substring( strNavVer.indexOf( "Netscape/" ) + 9 ) ;
       if ( strNavVer.indexOf( " " ) != -1 )
         strNavVer = strNavVer.substring( 0, strNavVer.indexOf( " " ) ) ;
     }

     // tell user what s/he's running
     strReturn += "<p> You appear to be running under: <b>" + strNavPlat + " using " +
                     strNavName + " Version " + strNavVer + "</b>.&nbsp;" ;
     

     // say whether the user's system is OK
     if ( ( strNavPlat == "Windows" && strNavName == "Internet Explorer" && strNavVer >= "6.0" ) ||
          ( strNavPlat == "MacPPC" && strNavName == "Netscape" && strNavVer >= "7.1" ) )
     {
       strReturn += "&nbsp;Your system appears to be compatible with this program." ;
     }
     else
     {
       strReturn += "</p><p style='color: red'>Your system does <b>NOT</b> appear to be compatible with this program. " +
                       "Please switch to a compatible system. Compatible systems are Windows Internet Explorer 6.0. " +
                       " or Mac Netscape 7.1."
                       " This Web site will not work properly on the system you are using. Thank you.</p>" ;
     }
     
     return strReturn;
  }

  // ----------------------------------- //

  function noop() { }   // empty function (no operation) to prevent page from reloading on form processing
  // ----------------------------------- //


  function incCounter() {

    var node;
    node = document.getElementById( "direction" ) ;
    node.setAttribute( "value", "forward" ) ;

  }

  // ----------------------------------- //

  function decCounter() {

    var node;
    node = document.getElementById( "direction" ) ;
    node.setAttribute( "value", "back" ) ;

  }

  // ----------------------------------- //

  // max. number of plays
  var counter = 0 ;

  var newNode = null ;
  var oldNode = null ;

  function play2( file )
  {

    // user may only play music clip 4 times
    if ( ++counter > 4 )
    {
      alert( "You've already heard four sound clips. That's all you get!\n" ) ;
      return ;
    }

    // sets attributes embed tag (which plays music)
    var nodeTT = document.getElementById("tt") ;
    newNode = document.createElement( "embed" ) ;
    newNode.setAttribute( "src", file ) ;
    newNode.setAttribute( "loop", false ) ;
    newNode.setAttribute( "hidden" , true ) ;
    //alert( newNode.height ) ;

    // replace original attributes with above settings
    if ( oldNode == null )
      nodeTT.appendChild( newNode ) ;
    else
      nodeTT.replaceChild( newNode, oldNode ) ;
    oldNode = newNode ;

    // used to limit the length of playing music
    //  setInterval( "document.getElementById(\"tt\").removeChild( node )", 3000 ) ;   // milliseconds

  }
  
  // ----------------------------------- //  
/*
  function clearPlayer()
  {
    var text = '' ;
    if ( document.layers )      // for Netscape
    {
       with ( document.layers['tt1'].document )
       {
          write( text ) ;
          close() ;
       }
    }
    else if ( document.all ) {  // for Internet Explorer
      document.all.tt.innerHTML = text ;
    }
  }
*/