<!--
  function validateField(field,strAlertTxt)
  {
    with (field)
    {
      if (value == null || value == "")
      {
        alert(strAlertTxt);
        return false;
      }
      else
      {
        return true;
      }
    }
  }

  function validateForm(thisForm)
  {
    try
    {
      with (thisForm)
      {

        if (validateField(user,"Please enter your name.") == false)
        {
          user.focus();
          return false;
        }  

 
        if ((validateField(email,"Please enter your email") == false) || (validateEmail(email) == false))
        {
          email.focus();
          return false;
        }  

 
      }
    }
    catch (exception)
    {
      alert("There has been an error on this page.");
      return false;
    }

    return true; //Needed but not in example?
  }

  function validateGetForm(thisForm)
  {
    try
    {
      with (thisForm)
      {

        if (validateEmail(email,"Invalid email address entered. Please try again") == false)
        {
          email.focus();
          return false;
        }

      }
    }
    catch (exception)
    {
      alert("There has been an error on this page.");
      return false;
    }

    return true; //Needed but not in example?
  }

  function validateTesterForm(thisForm)
  {
    try
    {
      with (thisForm)
      {
        if (validateField(name,"Please enter your name.") == false)
        {
          name.focus();
          return false;
        }  


        if (validateEmail(email,"Invalid email address entered. Please try again") == false)
        {
          email.focus();
          return false;
        }

      }
    }
    catch (exception)
    {
      alert("There has been an error on this page.");
      return false;
    }

    return true; //Needed but not in example?
  }



  function validateCommentForm(thisForm)
  {
    try
    {
      with (thisForm)
      {

        if (validateField(name,"Please enter your name.") == false)
        {
          name.focus();
          return false;
        }  

        if (validateField(comment,"Please enter a comment.") == false)
        {
          comment.focus();
          return false;
        }  

        if (validateCommentEmail(email) == false)
        {
          email.focus();
          return false;
        }

      }
    }
    catch (exception)
    {
      alert("There has been an error on this page.");
      return false;
    }

    return true; //Needed but not in example?
  }

  function validateCommentEmail(emailField)
  {
    with (emailField)
    {
      if (value == null || value == "")
      {
        return true; //Nothing to do as no email offered
      }

      if (validateEmailValue(value) == false)
      {
        var bConfirm = confirm("You have entered an email address but it does not appear to be valid.\nPress 'OK' if you want to correct the address.");
        if (bConfirm == true)
        {
          return false; //Force re-entry of email
        }
        else
        {
          value = ""; //Blank out email value
        }
      }
    }
 

    return true;
  }

  function validateEmail(field,strAlertTxt)
  {
    with (field)
    {
      if (validateEmailValue(value) == false)
      {

        alert(strAlertTxt);
        return false;

      } 
    }
    return true;
  }

  //--- Simpler version - use one below...
  //
  
  function validateEmailValueShort(emailValue) 
  {
    //--- Taken from http://www.white-hat-web-design.co.uk/articles/js-validation.php

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(emailValue) == false)
    {
      return false;
    }
    return true;
  }
  



  /**
  Validate an email address.
  Provide email address (raw input)
  Returns true if the email address has the email 
  address format and the domain exists.
  */
  //--- Taken from http://www.linuxjournal.com/article/9585
  //    Original in PHP - porting to javascript
  //    Using library functions to help with this as below.
  //
  function validateEmailValue(email)
  {
    //alert(email);

    var iAtIndex = strrpos(email, "@");
    if ((is_bool(iAtIndex) == true) && (iAtIndex == false))
    {
      //alert("No @ found"); 
      return false;
    }

    var strDomain = substr(email, iAtIndex + 1);
    var strLocal = substr(email, 0, iAtIndex);
    var iLocalLen = strlen(strLocal);
    var iDomainLen = strlen(strDomain);
    
    if (iLocalLen < 1 || iLocalLen > 64)
    {
      //alert("local part length zero or too big");
      return false;
    }
    
    if (iDomainLen < 1 || iDomainLen > 255)
    {
      //alert("domain part length zero or too big");
      return false;
    }

    if (strLocal.charAt(0) == '.' || strLocal.charAt(iLocalLen - 1) == '.')
    {
      //alert("local part starts or ends with '.'");
      return false;
    }

    //--- Added by Terry Clark - this is to help meet conditions 6 & 7 at http://www.linuxjournal.com/article/9585
    if (strDomain.charAt(0) == '.' || strDomain.charAt(iDomainLen - 1) == '.')
    {
      //alert("domain part starts or ends with '.'");
      return false;
    }


    var reg = /\.\./; 
    if (reg.test(strLocal) == true)
    {
      //alert("local part has two consecutive dots");
      return false;
    }

    reg = /^[A-Za-z0-9\-\.]+$/;
    if (reg.test(strDomain) == false)
    {
      //alert("character not valid in domain part");
      return false;
    }

    reg =  /\.\./;  
    if (reg.test(strDomain) == true)
    {
      //alert("domain part has two consecutive dots");
      return false;
    }
   
    reg = /^(\\.|[A-Za-z0-9!#%&`_=\/$'*+?^{}|~.-])+$/;  //Matches "\anything" or the group of characters
    var strDeSlashed = str_replace("\\\\","",strLocal); //Removes pairs of backslahes (four needed to show this in string)
    if (reg.test(strDeSlashed) == false)
    {
      reg = /^"(\\"|[^"])+"$/; //Matches \" (Quoted ") or not "
      if (reg.test(strDeSlashed) == false)
      {
        //alert("character not valid in local part unless local part is quoted");
        return false;
      }
    }

    //--- Can't do the equivalent of checkdnsrr as is available to PHP

    return true;
  }

  //--- PHP to Javascript methods from http://phpjs.org/
  //    Just picking up the ones needed here.
  //
  function strrpos( haystack, needle, offset)
  {
    // Finds position of last occurrence of a string within another string  
    // 
    // version: 810.1317
    // discuss at: http://phpjs.org/functions/strrpos
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: strrpos('Kevin van Zonneveld', 'e');
    // *     returns 1: 16

    var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
    return i >= 0 ? i : false;
  }

  function is_bool(mixed_var)
  {
    // Returns true if variable is a boolean  
    // 
    // version: 810.1317
    // discuss at: http://phpjs.org/functions/is_bool
    // +   original by: Onno Marsman
    // *     example 1: is_bool(false);
    // *     returns 1: true
    // *     example 2: is_bool(0);
    // *     returns 2: false
    return (typeof mixed_var == 'boolean');
  }

  function substr( f_string, f_start, f_length ) 
  {
    // Returns part of a string  
    // 
    // version: 810.1317
    // discuss at: http://phpjs.org/functions/substr
    // +     original by: Martijn Wieringa
    // +     bugfixed by: T.Wild
    // +      tweaked by: Onno Marsman
    // *       example 1: substr('abcdef', 0, -1);
    // *       returns 1: 'abcde'
    // *       example 2: substr(2, 0, -6);
    // *       returns 2: ''
    f_string += '';

    if(f_start < 0) {
        f_start += f_string.length;
    }

    if(f_length == undefined) {
        f_length = f_string.length;
    } else if(f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if(f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
  }

  function strlen (string)
  {
    // Get string length  
    // 
    // version: 905.3122
    // discuss at: http://phpjs.org/functions/strlen
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Sakimori
    // +      input by: Kirk Strobeck
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +    revised by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: May look like overkill, but in order to be truly faithful to handling all Unicode
    // %        note 1: characters and to this function in PHP which does not count the number of bytes
    // %        note 1: but counts the number of characters, something like this is really necessary.
    // *     example 1: strlen('Kevin van Zonneveld');
    // *     returns 1: 19
    // *     example 2: strlen('A\ud87e\udc04Z');
    // *     returns 2: 3
    var str = string+'';
    var i = 0, chr = '', lgth = 0;

    var getWholeChar = function (str, i) 
    {
        var code = str.charCodeAt(i);
        var next = '', prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { // High surrogate(could change last hex to 0xDB7F to treat high private surrogates as single characters)
            if (str.length <= (i+1))  {
                throw 'High surrogate without following low surrogate';
            }
            next = str.charCodeAt(i+1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i)+str.charAt(i+1);
        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i-1);
            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }
        return str.charAt(i);
    };

    for (i=0, lgth=0; i < str.length; i++) 
    {
        if ((chr = getWholeChar(str, i)) === false) 
        {
            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to
          // representthe individual character; purpose is to treat the first part of a surrogate pair as the whole character and then 
          // ignore the second part
        lgth++;
    }
    return lgth;
  }

  function str_replace(search, replace, subject, count) 
  {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 905.3122
    // discuss at: http://phpjs.org/functions/str_replace
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}




//-->

