function CopyFormFieldsFromURL ( formName ) {
//
// Copy URL parameters into form field values of the form with the given name.
//

var    _l = document.location.toString ( );
var    PS = new Array ( );
var    _i = _l.indexOf ( "?" );

if ( _i != -1 ) {
    // then there is a "?" in the url
    _l = _l.substr ( _i + 1, _l.length );  // lets only deal with the parameters

    while ( _l.indexOf ( "&" ) != -1 ) {
        // pull each param/value pair out until there is only 1 left.
        var    _a = _l.substr ( 0, _l.indexOf ( "&" ) );
        var    _m = _l.substr ( 1, _l.length ).indexOf ( "&" );

        PS [ PS.length ? PS.length : 0 ] = _a;
        _m++;             // move 1 past the &

        // if there are no more & - get the rest of the url string.
        if ( _m == 0 )
           _m = _l.length;

        _l = _l.substr( _m + 1, _l.length );
    }

    // pull off the last param/value pair.
    PS [ PS.length ? PS.length : 0 ] = _l;
    }

for ( var _I = 0; _I < PS.length; _I++ ) {
    var    _a = PS [ _I ].indexOf ( "=" );
    var    _b = PS [ _I ].substr ( 0, _a );
    var    _c = PS [ _I ].substr ( _a + 1, PS [ _I ].length );
    var    i;

    _c = unescape ( Replace1 ( _c, "+", " " ) );

    if ( eval ( "document." + formName ) ) {
        if ( eval ( "document." + formName + "." + _b ) ) {
            eval ( "document." + formName + "." + _b ) . value = _c;
            }
        }
    }
}

//=================================================================================

function DateStringToday ( ) {
//
// Return today's date as a string: DD MonName YYYY
//   months = new Array();   months[1] = "January";  months[7] = "July";   months[2] = "February"; months[8] = "August";   months[3] = "March";    months[9] = "September";   months[4] = "April";    months[10] = "October";   months[5] = "May";      months[11] = "November";   months[6] = "June";     months[12] = "December";   todaysdate = new Date();   date  = todaysdate.getDate();   month = todaysdate.getMonth() + 1;   year = todaysdate.getFullYear();
   return ( date + " " + months[month] + " " + year );   }

//=================================================================================

function FormatAmount ( v ) {
//
// Add leading spaces to right justify the argument (number) to fit in a field 8 spaces wide.
//   var value = Math.abs ( v );   result = + Math.floor ( value ) + ".";   var cents = 100 * ( value - Math.floor ( value ) ) + 0.5;   result += Math.floor ( cents / 10 );   result += Math.floor ( cents % 10 );   if ( v < 0 )               result = '-' + result;   while ( result.length < 8 )      result = ' ' + result;   return ( result );   }

//=================================================================================

function GetListValue ( list ) {
//
// Return the value associated with the selected element in the given list (form field).
//   return ( list.options[list.selectedIndex].value );   }
//=================================================================================

function GetListText ( list ) {
//
// Return the value associated with the selected element in the given list (form field).
//   return ( list.options[list.selectedIndex].text );   }
//=================================================================================

function GetRadioButtonValue ( radioButton ) {
//
// Return the value associated with the selected element in the given list (form field).
//
   for ( i = 0; i < radioButton.length; ++i ) {
      if ( radioButton[i].checked )
         return ( radioButton[i].value );
      }   return ( null );   }
//=================================================================================

function FormatWithBR ( s ) {
//
// Return a new string with the CRs mapped into <BR>
//
   if ( "\n".length == 1 )
      return ( Replace1 ( s, "\n", "<br>" ) );
   else      return ( Replace2 ( s, "\n", "<br>" ) );
   }
//=================================================================================

function Replace1 ( string, old1, new1 ) {
//
// Replace all occurrences of the old single character with the new characters.
//
   var s = "";
   var i = 0;

   while ( i < string.length ) {
      if ( string.charAt ( i ) == old1.charAt ( 0 ) ) {
         s = s + new1;
         }
      else {
         s = s + string.charAt ( i );
         }

      ++i;
      }

   return ( s );
   }

//=================================================================================


function Replace2 ( string, old1, new1 ) {
//
// Replace all occurrences of the old pair of characters with the new characters.
//
   var s = "";
   var i = 0;

   while ( i < string.length ) {
      if ( i + 1 < string.length
      && string.charAt ( i ) == old1.charAt ( 0 )
      && string.charAt ( i + 1 ) == old1.charAt ( 1 ) ) {
         s = s + new1;
         ++i;
         }
      else {
         s = s + string.charAt ( i );
         }

      ++i;
      }

   return ( s );
   }

//=================================================================================


