var global_field;

function ltrim (s)
{
    return s.replace( /^\s*/, "" );
}

function rtrim (s)
{
    return s.replace( /\s*$/, "" );
}

function trim (s)
{
    return rtrim(ltrim(s));
}


function mychrCount (str,ch)
{
    var count = 0;
    var index = -1;

    index = str.indexOf(ch);
    while (index != -1) {
        index = str.indexOf(ch,index+1);
        count++
    }
    return count;
}


function checkMail(x)
{
    var filter  = /^([a-zA-Z0-9_\'\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(x)) return true;
    else return false;
}



function validEmail(EMAIL)
{
    invalidChars = "/:,;"

    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i)
        if (EMAIL.indexOf(badChar,0) > -1) {
            return false;
        }
    }

    atPos = EMAIL.indexOf("@",1)
    if (atPos == -1){
        return false;
    }

    if (EMAIL.indexOf("@",atPos+1) != -1){
        return false;
    }

    periodPos = EMAIL.indexOf(".",atPos)
    if (periodPos == -1){
        return false;
    }

    if (periodPos+3 > EMAIL.length){
         return false;
    }

    return true;
}


function suycDateDiff( start, end, interval, rounding ) {

    var iOut = 0;

    // Create 2 error messages, 1 for each argument.
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;

    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;

    // check that the start parameter is a valid Date.
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        //alert( startMsg ) ;
        return null ;
    }

    // check that an interval parameter was not numeric.
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error.
        //alert( intervalMsg ) ;
        return null ;
    }

    var number = bufferB-bufferA ;

    // what kind of add to do?
    switch (interval.charAt(0))
    {
        case 'd': case 'D':
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error.
        //alert(intervalMsg) ;
        return null ;
    }

    return iOut ;
}



function WndPopup (URL, h, w, f) {

    if (f.len == 0) {
        window.open (URL, 'helppage', 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=w,height=h');
    }
    else {
        var s;
        s = "document." + id + ".submit()";
        eval (s);
    }

}

function NewWndPopup (URL, h, w, nme) {
    window.open (URL, nme, 'toolbar=1,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=' + w + ',height=' + h);
}


function ColorPopUp(URL, h, w, field)
{
    mywindow = window.open(URL, '_blank', 'toolbar=1,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=' + w + ',height=' + h);
    if (mywindow.opener == null) mywindow.opener = self;
    global_field = field;
}

function openpopup() {
    //configure "seeyou.htm and the window dimensions as desired
    window.open("seeya.asp","","width=400,height=375")
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadpopup() {
    if (get_cookie('popped')==''){
        openpopup()
        document.cookie="popped=yes"
    }
}


function preload(imgObj,imgSrc) {
    if (document.images) {
        eval(imgObj+' = new Image()')
        eval(imgObj+'.src = "'+imgSrc+'"')
    }
}

function changeImage(layer,imgName,imgObj) {
    if (document.images) {
        if (document.layers && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
        else document.images[imgName].src = eval(imgObj+".src")
    }
}




function BrowserDetector(ua) {



// Defaults
  this.browser = "Unknown";
  this.platform = "Unknown";
  this.version = "";
  this.majorver = "";
  this.minorver = "";
  this.isIE = false;

  uaLen = ua.length;

// ##### Split into stuff before parens and stuff in parens
  var preparens = "";
  var parenthesized = "";

  i = ua.indexOf("(");
  if (i >= 0) {
    preparens = trim(ua.substring(0,i));
        parenthesized = ua.substring(i+1, uaLen);
        j = parenthesized.indexOf(")");
        if (j >= 0) {
          parenthesized = parenthesized.substring(0, j);
        }
  }
  else {
    preparens = ua;
  }

// ##### First assume browser and version are in preparens
// ##### override later if we find them in the parenthesized stuff
  var browVer = preparens;

  var tokens = parenthesized.split(";");
  var token = "";
// # Now go through parenthesized tokens
  for (var i=0; i < tokens.length; i++) {
    token = trim(tokens[i]);
        //## compatible - might want to reset from Netscape
        if (token == "compatible") {
          //## One might want to reset browVer to a null string
          //## here, but instead, we'll assume that if we don't
          //## find out otherwise, then it really is Mozilla
          //## (or whatever showed up before the parens).
        //## browser - try for Opera or IE
    }
        else if (token.indexOf("MSIE") >= 0) {
      browVer = token;
    }
    else if (token.indexOf("Opera") >= 0) {
      browVer = token;
    }
        //'## platform - try for X11, SunOS, Win, Mac, PPC
    else if ((token.indexOf("X11") >= 0) || (token.indexOf("SunOS") >= 0) ||
(token.indexOf("Linux") >= 0)) {
      this.platform = "Unix";
        }
    else if (token.indexOf("Win") >= 0) {
      this.platform = token;
        }
    else if ((token.indexOf("Mac") >= 0) || (token.indexOf("PPC") >= 0)) {
      this.platform = token;
        }
  }

  var msieIndex = browVer.indexOf("MSIE");
  if (msieIndex >= 0) {
    browVer = browVer.substring(msieIndex, browVer.length);
  }

  var leftover = "";
  if (browVer.substring(0, "Mozilla".length) == "Mozilla") {
    this.browser = "Netscape";
        leftover = browVer.substring("Mozilla".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Lynx".length) == "Lynx") {
    this.browser = "Lynx";
        leftover = browVer.substring("Lynx".length+1, browVer.length);
  }
  else if (browVer.substring(0, "MSIE".length) == "MSIE") {
    this.browser = "IE";
    this.isIE = true;
    leftover = browVer.substring("MSIE".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Microsoft Internet Explorer".length) ==
"Microsoft Internet Explorer") {
    this.browser = "IE"
        leftover = browVer.substring("Microsoft Internet Explorer".length+1,
browVer.length);
  }
  else if (browVer.substring(0, "Opera".length) == "Opera") {
    this.browser = "Opera"
    leftover = browVer.substring("Opera".length+1, browVer.length);
  }

  leftover = trim(leftover);

  // # Try to get version info out of leftover stuff
  i = leftover.indexOf(" ");
  if (i >= 0) {
    this.version = leftover.substring(0, i);
  }
  else
  {
    this.version = leftover;
  }
  j = this.version.indexOf(".");
  if (j >= 0) {
    this.majorver = this.version.substring(0,j);
    this.minorver = this.version.substring(j+1, this.version.length);
  }
  else {
    this.majorver = this.version;
  }


} // function BrowserCap


function opencontactus()
{
    var w
    w = window.open('contact.asp', '_blank', 'toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1 height=630 width=690');

}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
        alert("The date format should be : mm/dd/yyyy")
        return false
    }
    if (strMonth.length<1 || month<1 || month>12){
        alert("Please enter a valid month. Dates should be formatted as mm/dd/yyyy.")
        return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter a valid day. Dates should be formatted as mm/dd/yyyy.")
        return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+ ".  Dates should be formatted as mm/dd/yyyy.")
        return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        alert("Please enter a valid date.  Dates should be formatted as mm/dd/yyyy.")
        return false
    }
return true
}

function DateDiff(date1, date2)
{
    var objDate1=new Date(date1);
    var objDate2=new Date(date2);
    return (objDate1.getTime()-objDate2.getTime())/(1000*60*60*24);
}


function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {

    // return an array of values selected in the check box group. if no boxes
    // were checked, returned array will be empty (length will be zero)
    var retArr = new Array(); // set up empty array for the return values

    if(typeof(buttonGroup) == "undefined") {
        return retArr;
    }

    var selectedItems = getSelectedCheckbox(buttonGroup);

    if (selectedItems.length != 0) { // if there was something selected
       retArr.length = selectedItems.length;
       for (var i=0; i<selectedItems.length; i++) {
          if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
             retArr[i] = buttonGroup[selectedItems[i]].value;
          } else { // It's not an array (there's just one check box and it's selected)
             retArr[i] = buttonGroup.value;// return that value
          }
       }
    }

    return retArr;

} // Ends the "getSelectedCheckBoxValue" function

function toggleblock(obj,id)
{
    if (document.getElementById(id).style.display == 'none') {
        document.getElementById(id).style.display = 'block';
        obj.src = "images/sortup.gif";
    }
    else {
        document.getElementById(id).style.display = 'none';
        obj.src = "images/sortdown.gif";
    }
}

function textCounter(field,field1,maxlimit)
{
    var f = document.getElementById(field);

    var f1 = null;

    if (field1 != null) {
        f1 = document.getElementById(field1);
    }

    if (f) {
        if (f.value.length > maxlimit) {
            f.value = f.value.substring(0, maxlimit);
        }

        if (f1) {
            f1.value = f.value.length;
        }
    }
}

function toggle (field1)
{
    var f;

    if (field1 == null) {
        return false;
    }

    f = document.getElementById(field1);
    if (f) {
        if (f.style.display == 'block') {
            f.style.display = 'none';
        }
        else {
            f.style.display = 'block';
        }
    }
}

function isCurrency(id)
{

    var nNum = 0;           // Total numbers for currency value.
    var nDollarSign = 0;    // Total times a dollar sign occurs.
    var nDecimal = 0;       // Total times a decimal point occurs.
    var nCommas = 0;        // Total times a comma occurs.
    var txtLen;             // Length of string passed.
    var xTxt;               // Assigned object passed.
    var sDollarVal;         // Assigned dollar amount with or without commas.
    var bComma;
    var decPos;             // Assigned value of numbers or positions after decimal point.
    var nNumCount = 0;      // Total number between commas.
    var i;                  // For forloop indexing.
    var x;                  // Assigned each indivual character in string.

    // Set the xTxt variable to the object passed to this function.
    // Assign the length of the string to txtLen.

    var f = document.getElementById(id);
    xTxt = f;
    txtLen = xTxt.value.length

    for(i = 0; i < txtLen; i++)
    {
        // Assign charater in substring to x.
        x = xTxt.value.substr(i, 1);

        if(x == "$")
            nDollarSign = nDollarSign + 1; // Sum total times dollar sign occurs.
        else if(x == ".")
            nDecimal = nDecimal + 1; // Sum total times decimal point occurs.
        else if(x == ",")
            nCommas = nCommas + 1; // Sum total times comma occurs.
        else if(parseInt(x) >= 0 || parseInt(x) <= 9)
            nNum = nNum + 1; // If the character is a number sum total times a number occurs.
        else
        {
            // Error occurs if any other character value is in the string
            // othere then the valid characters.

            alert("You have entered an illegal currency value!\nPlease enter only: Dollar" +
                  " Signs, Commas, Decimal Points, and numbers between 0...9!");
            return false;
        } // end else
    } // end for

    if(nDollarSign > 1)
    {
        alert("ERROR! \n\nYou have entered more then one dollar sign!\nPlease only enter one!");
        return false;

    } // end if

    if(nDecimal > 1)
    {
        alert("ERROR! \n\nYou have entered more then one decimal point!\nPlease only enter one!");
        return false;
    } // end if

    if(nDollarSign == 1)
    {
        // Make sure dollar sign in the first character in string
        // if there is a dollar sign present.
        if(xTxt.value.indexOf("$") != 0)
        {
            alert("ERROR!  \n\nThe dollar sign you entered is not in the correct position!");
            return false;
        } // end if
    }// end if

    if(nDecimal == 1)
    {
        // Get the number of numbers after the decimal point in
        // the string if there is a decimal point present
        decPos = (txtLen - 1) - xTxt.value.indexOf(".");

        // Floating point cannot be more then two.
        // Valid format after decimal point.

        /**********************************/
        /*   $#.##, $#.#, $.#, $#., $.##  */
        /**********************************/

        if(decPos > 2)
        {
            alert("ERROR! \n\nThe decimal point you entered is not in the correct position!");
            return false;
        } // end if
    } // end if

    if(nCommas == 0)
    {
        // If no commas are present value is a valid US currency.
        return true;
    }
    else
    {
        // Get total number of dollar number(s), removing
        // floating point numbers or cents.
        nNum = nNum - decPos;

        // Determine if dollar sign is in string so to be removed.
        // After determining dollar sign, assign sDollarVal
        // numbers and comma(s)
        if(xTxt.value.indexOf("$", 0) == 0)
            sDollarVal = xTxt.value.substr(1, (nNum + nCommas));
        else
            sDollarVal = xTxt.value.substr(0, (nNum + nCommas));

        // Determine if a zero is the first number or if a
        // comma is the first or last character in the string.
        if(sDollarVal.lastIndexOf("0", 0) == 0 )
        {
            alert("ERROR! \n\nYou cannot start the dollar amount out with a zero!");
            return false;
        }
        else if(sDollarVal.lastIndexOf(",", 0) == 0)
        {
            alert("ERROR! \n\nYou cannot start the dollar amount out with a comma!");
            return false;
        }
        else if(sDollarVal.indexOf(",", (sDollarVal.length - 1)) == (sDollarVal.length - 1))
        {
            alert("ERROR! \n\nYou cannot end the dollar amount with a comma!");
            return false;
        }
        else
        {
            // Initialize bComma indicating a comma has not been
            // occured yet.
            bComma = false;
            for(i = 0; i < sDollarVal.length; i++)
            {
                // Assign charater in substring to x.
                x = sDollarVal.substr(i, 1);
                if(parseInt(x) >= 0 || parseInt(x) <= 9)
                {
                    // If x is a number add one to the number counter.
                    nNumCount = nNumCount + 1;

                    // Sense comma(s) are present number counter cannot
                    // be more then three before the first or next comma.
                    if(nNumCount > 3)
                    {
                        alert("ERROR! \n\nYou have a mis-placed comma!");
                        return false;
                    } // end if
                }
                else
                {
                    // If the number counter is less then three and
                    // the comma indicator is true the comma is either
                    // mis-placed or there are not enough values.
                    if(nNumCount != 3 && bComma)
                    {
                        alert("ERROR! \n\nYou have a mis-placed comma!");
                        return false;
                    } // end if

                    // Reset the number counter back to zero.
                    nNumCount = 0;

                    // Set the comma indicator to true indicating
                    // that the first comma has been found and that
                    // there now MUST be three numbers after each
                    // comma until the loop hits the end.
                    bComma = true;
                } // end if

            } // end for

            // Determine if after the loop ended that there
            // was a total of three final numbers after the
            // last comma.
            if(nNumCount != 3 && bComma)
            {
                alert("ERROR! \n\nYou have a mis-placed comma!");
                return false;
            } // end if

        } // end if

    } // end if

    // Return true indicating that the value is a valid currency.

    return true;
}


function checkselect(id,lid)
{
    if (document.getElementById(id).checked) {
        checkAll(document.getElementsByName(lid));
    }
    else {
        uncheckAll(document.getElementsByName(lid));
    }
}

function checkAll(field)
{

    if (field.length > 0) {

        for (i = 0; i < field.length; i++) {
            field[i].checked = true ;
        }
    }
    else {
        field.checked = true;
    }

}

function uncheckAll(field)
{
    if (field.length > 0) {

        for (i = 0; i < field.length; i++) {
            field[i].checked = false;
        }
    }
    else {
        field.checked = false;
    }
}


function launchWindow(url,name,kind,w,h)
{
    var properties = kind+',width='+w+',height='+h;
    var w = window.open (url,name,properties);
    if (w) {
        w.focus();
    }
}

function newlaunchWindow(url,name,kind,w,h)
{
    location.href=url;
}

function isZip(s)
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          //alert("Zip Code Is Not Valid");
          return false;
     }

return true;
}

function my_emailCheck (emailStr)
{

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */

    var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address.
    These characters include ( ) < > @ , ; : \ " . [ ] */

    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a
    username or domainname.  It really states which chars aren't allowed.*/

    var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */

    var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */

    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */

    var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */

    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {

    /* Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address. */

    //alert("Email address seems incorrect (check @ and .'s)");
    return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
    //alert("Ths username contains invalid characters.");
    return false;
       }
    }
    for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
    //alert("Ths domain name contains invalid characters.");
    return false;
       }
    }

    // See if "user" is valid

    if (user.match(userPat)==null) {

    // user is not valid

    //alert("The username doesn't seem to be valid.");
    return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {

    // this is an IP address

    for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
    //alert("Destination IP address is invalid!");
    return false;
       }
    }
    return true;
    }

    // Domain is symbolic name.  Check if it's valid.

    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
    //alert("The domain name does not seem to be valid.");
    return false;
       }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 &&
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
    //alert("The address must end in a well-known domain or two letter " + "country.");
    return false;
    }

    // Make sure there's a host name preceding the domain.

    if (len<2) {
    //alert("This address is missing a hostname!");
    return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}


