
var WordCountRgx = null;                              // Static RegExp object.

if (navigator.platform)                               // Is it JavaScript 1.2?
   WordCountRgx = /\b\w/g;                            //   then safe to new RegExp().

if ( (WordCountRgx != null) && 
     ((WordCountRgx.exec('one two three') == null) || // Eliminate all browsers that can't actually
      (WordCountRgx.lastIndex != 5)) )                //   do /\b\w/g (and there's a lot of them!)
   WordCountRgx = null;

function wordCounter(fld, countfield, maxlimit) {
   var wc=0;
   var str = fld.value;
   
   if ( WordCountRgx ) // Regex will be fastest, if we can do it!
   {
      WordCountRgx.lastIndex = 0;
      while ( WordCountRgx.exec(str) != null )
      {
         wc += 1;
      }
      if ( maxlimit > 0 )
         countfield.value = maxlimit - wc;
      else
         countfield.value = wc;
         
      return;
   }

   // This helps those browsers too stupid to do simple regex's to count words (and that's a lot of them!)
   if ( str.length > 0 ) wc += 1;
   var idx = 0;
   var ch = '';
   while ( (idx = str.indexOf(' ', idx)) != -1 )
   {
      ch = str.charCodeAt(idx+1);
      if ( (ch>=64 && ch<=90) || (ch>=97 && ch<=122) || (ch>=48 && ch<=57) ) wc += 1;
      idx += 1;
   }
   
   idx = 0;
   while ( (idx = str.indexOf('\n', idx)) != -1 )
   {
      ch = str.charCodeAt(idx+1);
      if ( (ch>=64 && ch<=90) || (ch>=97 && ch<=122) || (ch>=48 && ch<=57) ) wc += 1;
      idx += 1;
   }
      if ( maxlimit > 0 )
         countfield.value = maxlimit - wc;
      else
         countfield.value = wc;
}

var VerifyArray = [
     ['name', 'Please provide your name.']
    ,['email', 'Please give us an email address by which we may contact you.']
];

function validateForm (frm) {
   if ( frm.remLen.value < 0 || frm.remLen.value > 100 )
   {
      TOP.hiLite(window, frm, 'Entry', "Please submit an entry of between 500 and 600 words.");
      return false;
   }
   return true;
}

