// BROWSER SNIFFER (Sniff out the good and bad browsers)

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns2 = (this.ns && (this.major == 2));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4b = (this.ns && (this.minor < 4.04));
  this.ns4 = (this.ns && (this.major >= 4));
  this.ie   = (agent.indexOf("msie") != -1);
  this.ie3  = (this.ie && (this.major == 2));
  this.ie4  = (this.ie && (this.major >= 4));
  this.op3 = (agent.indexOf("opera") != -1);
  this.win   = (agent.indexOf("win")!=-1);
  this.mac   = (agent.indexOf("mac")!=-1);
  this.unix  = (agent.indexOf("x11")!=-1);
}
var is = new Is();

// VARIABLE DECLARATIONS

var whitespace = " \t\n\r";
var iRequired =  "This is a required field.";

var defaultEmptyOK = true;

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isWordPunctuation (c)
{   return (( c == "'") || ( c == " ") || ( c == "-"))
}


function isWords (s)
{   var i;
    if (isEmpty(s)) 
       if (isWords.arguments.length == 1) return defaultEmptyOK;
       else return (isWords.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isLetter(c) && !isWordPunctuation(c))
        return false;
    }
    return true;
}

/* FUNCTIONS TO NOTIFY USER OF INPUT REQUIREMENTS OR MISTAKES. */

function warn (s)
{
  alert(s);
  return false;
};

function warnColor (theField, s)
{
  if (is.ie4) theField.style.backgroundColor = "red";
  alert(s);
  if (is.ie4) theField.style.backgroundColor = document.bgColor;
  return false;
};

/* FUNCTIONS TO CHECK FIELD VALUES */

function checkLetter (theField, s, emptyOK)
{  if (checkLetter.arguments.length == 2) emptyOK = defaultEmptyOK;
   if ((emptyOK == true) && (isEmpty(theField.value))) return true;
   if (!isLetter(theField.value)) return warnColor (theField,s);
   return true;
}

function checkEmpty (theField, s) 
{  if (isEmpty(theField.value)) return warnColor (theField,'');
   return true;
}

function checkWords (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkWords.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (isWhitespace(theField.value)) return warnColor (theField, iRequired);
    if (!isWords(theField.value)) return warnColor (theField, s);
    return true;
}

function CheckDrSearch()
{
//Headline field
  myMess = "The first name contains an invalid character"
  if (!checkWords(document.frmDrSearch.DrFirstName, myMess, true)) return false; 

//Check the event why field
  myMess = "The last name contains an invalid character"
  if (!checkWords(document.frmDrSearch.DrLastName, myMess, true)) return false;

//Check the event message field
  myMess = "The middle initial is an invalid character"
  if (!checkLetter(document.frmDrSearch.DrMiddleInitial, myMess, true)) return false;

  return true;
};

