var nbsp = 160;    // non-breaking space char
var node_text = 3; // DOM text node-type
var emptyString = /^\s*$/
var glb_vfld;      // retain vfld 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()
{
  glb_vfld.focus()
}

function setfocus(vfld)
{
	// save vfld in global variable so value retained when routine exits
	glb_vfld = vfld;
	setTimeout( 'setFocusDelayed()', 100 );
}

function commonCheck (vfld)   // true if required
{
if (vfld.value == 0) vfld.value = "";
if (emptyString.test(vfld.value))  {
	setfocus(vfld);
	return true;
} else {
return false;
}
}

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail  (vfld)   // true if required
{
var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
if (!email.test(tfld)) {
	setfocus(vfld);
    return true;
}

var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
if (!email2.test(tfld)) {
	setfocus(vfld);
    return true;
} else {
	return false;
}
}
