// -- Extract from File: browser.js ----------------------

function BrowserIsInternetExplorer() 
{ 
var UA = navigator.userAgent.toLowerCase(); 
return ((UA.indexOf('msie') != -1) && (UA.indexOf('spoofer') == -1) && (UA.indexOf('opera') == -1)); 
}

function BrowserIsNetscape() 
{ 
var BN = navigator.appName.toLowerCase();
var UA = navigator.userAgent.toLowerCase(); 
return ((BN == 'netscape') && (UA.indexOf('spoofer') == -1) && (UA.indexOf('compatible') == -1) && (UA.indexOf('opera') == -1)); 
}

function BrowserIsOpera() 
{ 
var UA = navigator.userAgent.toLowerCase(); 
return (UA.indexOf('opera') != -1); 
}

function BrowserIsElseAlert(Browser)
{
var Supported;
switch (Browser)
  {
  case 'IE': Supported = BrowserIsInternetExplorer(); break;
  case 'NS': Supported = BrowserIsNetscape(); break;
  case 'OP': Supported = BrowserIsOpera(); break;
  default:   Supported = false;
  }
if (!Supported) alert('Sorry, this feature is not supported by your browser.      ');
return(Supported);
}

function InternetExplorerVersion()
{
var UA          = navigator.userAgent.toLowerCase(); 
var IndexOfMSIE = UA.indexOf('msie');
var Version     = 0;
if (BrowserIsInternetExplorer() == true)
  Version = parseFloat(UA.substring(IndexOfMSIE+5));
return(Version);
}

function NetscapeVersion()
{
var Version = 0;
if (BrowserIsNetscape() == true)
  {
  Version = parseFloat(navigator.appVersion);
  if ((Version >= 5) && (typeof navigator.vendorSub != 'undefined'))
    Version = parseFloat(navigator.vendorSub);
  }
return(Version);
}

function OperaVersion()
{
var UA           = navigator.userAgent.toLowerCase(); 
var IndexOfOpera = UA.indexOf('opera');
var Version      = 0;
if (BrowserIsOpera() == true)
  Version = parseFloat(UA.substring(IndexOfOpera+6));
return(Version);
}

function AlertIfBrowserEarlierThan(MinIEVer, MinNSVer, MinOPVer)
{
var IEVer = InternetExplorerVersion();
var NSVer = NetscapeVersion();
var OPVer = OperaVersion();
var S     = '';
if ((IEVer > 0) && (IEVer < MinIEVer)) S = 'You appear to be using Internet Explorer version ' + IEVer + '    \nwhich might not operate correctly with this web site.     \n\n';
if ((NSVer > 0) && (NSVer < MinNSVer)) S = 'You appear to be using Netcape version ' + NSVer + '    \n which may not operate correctly with this web site.     \n\n';
if ((OPVer > 0) && (OPVer < MinOPVer)) S = 'You appear to be using Opera version ' + OPVer + '    \n which may not operate correctly with this web site.     \n\n';
if (S != '')
  {
  S = S + 'This site should work correctly with:\n     - Internet Explorer ' + MinIEVer + '\n     - Netscape ' + MinNSVer + '\n     - Opera ' + MinOPVer + '\n     - or compatible browsers.';
  alert(S);
  }
}



// -- Extract from File: url.js ---------------------------

function GoToURL(url, anchorName, queryString, forgetCurrentPage)
{
if (anchorName  != '') url += '#' + anchorName;
if (queryString != '') url += '?' + queryString;
if (forgetCurrentPage)
       location.replace(url);
  else location.href = url;
}















// -- Extract from File: forms.js --------------------------------

function FocusField(E, doSelect)
{
switch (E.type)
  {
  case 'text': 
  case 'textarea': E.focus(); if (doSelect) E.select(); break;
  case 'radio':
  case 'select-one':
  case 'select-multiple':
  case 'checkbox':
  case 'file':
  case 'password':
  case 'button':
  case 'reset':
  case 'submit': E.focus(); break;
  }
}
 

function FocusFormElement(formName, fieldName, doSelect)
{
var E = document.forms[formName].elements[fieldName];
FocusField(E, doSelect);
}


function IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus)
{
if (!valid)
  {
  if (alertTitle.length > 0) alert(alertTitle + '     \n\n' + alertMsg);
  if (autoFocus) FocusField(field, true);
  }
}


function fieldIsNotEmpty(field, alertTitle, autoFocus)
{
var valid    = true;
var alertMsg = '';
var s        = field.value;
s = s.toString();
if ((s != null) && (s.length < 1))
  {
  valid = false;
  alertMsg = 'Please complete this field     \n\n';
  }
IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}

/*
function fieldVerifyNumChars(field, minChars, maxChars, alertTitle, autoFocus)
{
var valid    = true;
var alertMsg = '';
var s        = field.value;

s = s.toString();
if ((valid) && (s != null) && (s.length < minChars))
  {
  valid = false;
  alertMsg = 'Please enter at least '+minChars+' character(s)     \n\n';
  }
if ((valid) && (s != null) && (s.length > maxChars))
  {
  valid = false;
  alertMsg = 'Please enter no more than '+maxChars+' character(s)     \n\n';
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}




function fieldIsInteger(field, minValue, maxValue, alertTitle, autoFocus)
// Verifies field string represents a valid integer within a specified range.
{
var valid      = true;
var alertMsg   = '';
var digitFound = false;
var v          = 0;
var c          = 0;
var s          = field.value;

s = s.toString();
if (s != null)
  {
  for (var i=0; i < s.length; i++)
    {
    if (valid)
      { 
      c = s.charCodeAt(i);
      if ((c >= 48) && (c <= 57))
             digitFound = true;
        else {
             if (c == 45)
                    {
                    // Character is minus sign
                    if (i != 0)
                      {
                      valid = false;
                      alertMsg = 'Only the first character can be a minus sign     \n\n';
                      }
                    }
               else {
                    // Character is not a digit or minus sign
                    valid = false;
                    alertMsg = 'Please enter a valid integer     \n\n';
                    }
             }
      }
    } // End for loop

  // Check for at least one digit
  if ((valid) && (!digitFound))
    {
    valid = false;
    alertMsg = 'Please enter a valid integer     \n\n';
    }

  // Check numeric range of integer
  if (valid)
    {
    // Here, s must be a valid integer
    v = parseInt(s);
    if (v < minValue)
      {
      valid = false;
      alertMsg = 'The value must be at least '+minValue+'    \n\n';
      }
    if (v > maxValue)
      {
      valid = false;
      alertMsg = 'The value should be no more than '+maxValue+'     \n\n';
      }
    }
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}




function fieldIsNumber(field, minValue, maxValue, alertTitle, autoFocus)
// Verifies field string represents a valid number (integer or floating point, but 
// not exponential) within a specified range.
{
var valid             = true;
var alertMsg          = '';
var digitFound        = false;
var decimalPointFound = false;
var v                 = 0;
var c                 = 0;
var s                 = field.value;

s = s.toString();
if (s != null)
  {
  for (var i=0; i < s.length; i++)
    {
    if (valid)
      { 
      c = s.charCodeAt(i);
      if ((c >= 48) && (c <= 57))
             digitFound = true;
        else {
             // Character is not a digit
             if (c == 45)
                    {
                    // Character is minus sign
                    if (i != 0)
                      {
                      valid = false;
                      alertMsg = 'Only the first character can be a minus sign     \n\n';
                      }
                    }
               else {
                    // Character is not a digit or minus sign
                    if (c == 46)
                           {
                           // Character is a decimal point
                           if (decimalPointFound)
                                  {
                                  valid = false;
                                  alertMsg = 'Too many decimal points     \n\n';
                                  }
                             else decimalPointFound = true;
                           }
                      else {
                           // Character is not a digit, a minus sign or a decimal point
                           valid = false;
                           alertMsg = 'Please enter a valid number     \n\n';
                           }
                    }
             }
      }
    } // End for loop

  // Check for at least one digit
  if ((valid) && (!digitFound))
    {
    valid = false;
    alertMsg = 'Please enter a valid number     \n\n';
    }

  if (valid)
    {
    // Here, s must be a valid number
    v = parseFloat(s);
    if (v < minValue)
      {
      valid = false;
      alertMsg = 'The value must be at least '+minValue+'    \n\n';
      }
    if (v > maxValue)
      {
      valid = false;
      alertMsg = 'The value should be no more than '+maxValue+'     \n\n';
      }
    }
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}




function fieldIsAlphanumeric(field, allowedSymbols, alertTitle, autoFocus)
// Verifies fields string contains letters and digits only.
// The string allowedSymbols lists any non-alphanumeric characters that
// are also allowed.
{
var valid       = true;
var alertMsg    = '';
var notAlphaNum = false;
var c           = 0;
var s           = field.value;

s = s.toString();
if (s != null)
  {
  for (var i=0; i < s.length; i++)
    {
    if (valid)
      { 
      c = s.charCodeAt(i);
      if ((((c < 48) || (c > 57)) && ((c < 65) || (c > 90)) && ((c < 97) || (c > 122))) &&
          (allowedSymbols.indexOf(s.charAt(i)) == -1))
        {
        valid = false;
        alertMsg = 'Invalid character(s) in this field     \n\n';
        }
      }
    }
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}




function fieldHasNoLowerCase(field, alertTitle, autoFocus)
// Verifies field string contains no lower case letters.
{
var valid    = true;
var alertMsg = '';
var s        = field.value;

s = s.toString();
if (s != null)
  {
  if (s != s.toUpperCase())
    {
    valid = false;
    alertMsg = 'Lower case letters are not allowed     \n\n';
    }
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}



function fieldHasNoUpperCase(field, alertTitle, autoFocus)
// Verifies field string contains no upper case letters.
{
var valid    = true;
var alertMsg = '';
var s        = field.value;

s = s.toString();
if (s != null)
  {
  if (s != s.toLowerCase())
    {
    valid = false;
    alertMsg = 'Upper case letters are not allowed     \n\n';
    }
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}
*/


function fieldIsEMail(field, alertTitle, autoFocus)
// Verifies field string has a format consistent with being an E-Mail address
{
var valid    = true;
var alertMsg = '';
var reEMail  = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
var s        = field.value;

s = s.toString();
if ((s != null) && (!s.match(reEMail)))
  {
  valid = false;
  alertMsg = 'Please enter a valid E-mail address    \n\n';
  }

IndicateIfNotValid(field, valid, alertTitle, alertMsg, autoFocus);
return(valid);
}






























