<!--
// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
// ----------------------------------------------------------------------

var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var global_valfield;	// retain valfield for timer thread

// --------------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// --------------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}


// --------------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}

function validateName(x_id, x_len)
{
	validateTXT(x_id, x_len);
}

function validateEmail(x_id)
{
  var tfld = trim(x_id.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld) || !validateTXT(x_id, 6) ) {
			x_id.className = 'err';
			setfocus(x_id);
  } else {
		x_id.className = 'std';
	}
}

function validateTXT(x_id, x_len)
{
  if (!document.getElementById)
    return true;  // not available on this browser - leave validation to the server

	var data = x_id.value;
  if (data.length < x_len ) {
			x_id.className = 'err';
      setfocus(x_id);
      return false;
  }

	x_id.className = 'std';
  return true;
}

// -->


