function FieldValidate(textboxtest)
{
  var strTest;
  var intReturn;
  
  if ( textboxtest.name == "greeting" )
  {
	intReturn = LengthCheck(textboxtest);
	if ( !intReturn )
	{
		textboxtest.focus();
	}
	return (intReturn);
  }
  
  intReturn = CapsCheck(textboxtest);
  if ( !intReturn )
  {
	textboxtest.focus();
  }
  else
  {
	intReturn = LengthCheck(textboxtest);
	if ( !intReturn )
	{
		textboxtest.focus();
	}
  }

  return (intReturn);
}
function CapsCheck(textboxtest)
{
  var strTest;
  var intReturn;
  
  // Return if field is blank - let formvalidate handle which fields must have values
  if ( trim(textboxtest.value) == "" )
  {
	return (true);
  }

  // If 1st char is numeric - skip testing
  if ( textboxtest.value.charAt(0) >= "0" && textboxtest.value.charAt(0) <= "9" )
  {
	return (true);
  }
  
  // Allow Single initial or initial followed by "."
  if ( textboxtest.value.length == 1 )
  {
	return (true);
  }
  if ( textboxtest.value.charAt(1) == "." )
  {
	return (true);
  }
  
  // Test caps lock first
  strTest = textboxtest.value.toUpperCase();
  if ( strTest == textboxtest.value )
  {
	alert("Did you have CAPS LOCK on?  Please capitilize ONLY the first letter of proper names.");
    textboxtest.focus();
    return (false);
  } 
  // Test all lower case next
  strTest = textboxtest.value.toLowerCase();
  if ( strTest == textboxtest.value )
  {
    alert("Did you forget to use capitilization?  Please capitilize the first letter of proper names.");
    textboxtest.focus();
	return (false);
  } 
  // Test first char lower case or mixed case
  strTest = textboxtest.value.charAt(0).toLowerCase();
  if ( strTest == textboxtest.value.charAt(0) )
  {
	intReturn = confirm('Did you mean to enter a lower case 1st letter?');
	if ( intReturn )
	{	return (true);
	}
	else
	{	textboxtest.focus();
		return (false);
	}
  }
  	
  return (true);
}
function LengthCheck(textboxtest)
{
  var strTest;
  var intReturn;

  // Check length of names
  var firstname = 20;
  var lastname = 25;
  var nickname = 25;
  var petname = 25;
  var restname = 55;
  var address = 30;
  var greeting = 255;
  var newstring;
  
  // FIRST NAMES
  if ( textboxtest.name == "heroinefirstname" || textboxtest.name == "herofirstname" || textboxtest.name == "friendfirstname" )
  {
	if ( textboxtest.value.length > firstname )
	{
		newstring = textboxtest.value.slice(0,firstname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  //LAST NAMES
  if ( textboxtest.name == "heroinelastname" || textboxtest.name == "herolastname" || textboxtest.name == "friendlastname" )
  {
	if ( textboxtest.value.length > lastname )
	{
		newstring = textboxtest.value.slice(0,lastname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  //NICKNAMES
  if ( textboxtest.name == "heroinenickname" || textboxtest.name == "heronickname" )
  {
	if ( textboxtest.value.length < 1 )
	{
		alert("Please enter a value for the \"Nick Name\" field.");
		textboxtest.focus();
		return (false);
	}
	if ( textboxtest.value.length > nickname )
	{
		newstring = textboxtest.value.slice(0,nickname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  // Villain first and last names
  if ( textboxtest.name == "villainfirstname" )
  {
	if ( textboxtest.value.length > firstname )
	{
		newstring = textboxtest.value.slice(0,firstname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  if ( textboxtest.name == "villainlastname" )
  {
	if ( textboxtest.value.length > lastname )
	{
		newstring = textboxtest.value.slice(0,lastname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }

  // Pet Name non-zero length
  if ( textboxtest.name == "petname" )
  {
	if ( textboxtest.value != textboxtest.defaultValue && textboxtest.value.length < 1 )
	{
		alert("Please enter a value for the \"Pet Name\" field.");
		textboxtest.focus();
		return (false);
	}
	if ( textboxtest.value.length > petname )
	{
		newstring = textboxtest.value.slice(0,firstname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  // Restaurant Name
  if ( textboxtest.name == "roadrest" )
  {
	if ( textboxtest.value != textboxtest.defaultValue && textboxtest.value.length < 1 )
	{
		alert("Please enter a value for this field.");
		textboxtest.focus();
		return (false);
	}
	if ( textboxtest.value.length > restname )
	{
		newstring = textboxtest.value.slice(0,restname);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  //Address
  if ( textboxtest.name == "heroineaddress" )
  {
	if ( textboxtest.value != textboxtest.defaultValue && textboxtest.value.length < 1 )
	{
		alert("Please enter a value for this field.");
		textboxtest.focus();
		return (false);
	}
	if ( textboxtest.value.length > address )
	{
		newstring = textboxtest.value.slice(0,address);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  //Gift Certificate personalized message
  if ( textboxtest.name == "greeting" )
  {
	if ( textboxtest.value.length > greeting )
	{
		newstring = textboxtest.value.slice(0,greeting);
		textboxtest.value = newstring;
		alert("Your entry will be truncated - please check and update your information.");
		textboxtest.focus();
		return (false);
	}
	else
	{
		return (true);
	}
  }
  return (true);
}
function FormValidate(theForm)
{
  var ii;

  if (trim(theForm.heroinefirstname.value) == "")
  {
    alert("Please enter a value for the \"Heroine's First Name\" field.");
    theForm.heroinefirstname.focus();
    return (false);
  }

  if (trim(theForm.heroinelastname.value) == "")
  {
    alert("Please enter a value for the \"Heroine's Last Name\" field.");
    theForm.heroinelastname.focus();
    return (false);
  }

  if (trim(theForm.friendfirstname.value) == "")
  {
    alert("Please enter a value for the \"Heroine's Female Friend  - First Name\" field.");
    theForm.friendfirstname.focus();
    return (false);
  }

  if (trim(theForm.herofirstname.value) == "")
  {
    alert("Please enter a value for the \"Hero First Name\" field.");
    theForm.herofirstname.focus();
    return (false);
  }
  if (trim(theForm.herolastname.value) == "")
  {
    alert("Please enter a value for the \"Hero Last Name\" field.");
    theForm.herolastname.focus();
    return (false);
  }

  // Look for villainfirstname (LND) or roadrest (TT) or nicknames
  for ( ii = 0; ii < theForm.elements.length; ii++ )
  {
	if ( theForm.elements[ii].name == "villainfirstname" )
	{
		if (trim(theForm.elements[ii].value) == "")
		{
		  alert("Please enter a value for the \"Villain First Name\" field.");
		  theForm.villainfirstname.focus();
		  return (false);
		}
	}
	if ( theForm.elements[ii].name == "roadrest" )
	{
		if (trim(theForm.elements[ii].value) == "")
		{
		  alert("Please enter a value for this field.");
		  theForm.roadrest.focus();
		  return (false);
		}
	}
	if ( theForm.elements[ii].name == "heroinenickname" )
	{
		if (trim(theForm.elements[ii].value) == "")
		{
		  alert("Please enter a value for the \"Nick Name\" field.");
		  theForm.heroinenickname.focus();
		  return (false);
		}
	}
	if ( theForm.elements[ii].name == "heronickname" )
	{
		if (trim(theForm.elements[ii].value) == "")
		{
		  alert("Please enter a value for the \"Nick Name\" field.");
		  theForm.heronickname.focus();
		  return (false);
		}
	}
  }
		
  return (true);
}
function KidsFormValidate(theForm)
{
  var ii;

  if (trim(theForm.heroinefirstname.value) == "")
  {
    alert("Please enter a value for the \"Main Character's First Name\" field.");
    theForm.heroinefirstname.focus();
    return (false);
  }

  if (trim(theForm.heroineaddress.value) == "")
  {
    alert("Please enter a value for the \"Main Character's Street Name\" field.");
    theForm.heroineaddress.focus();
    return (false);
  }
  
  if (trim(theForm.herofirstname.value) == "")
  {
    alert("Please enter a value for the \"Friend's First Name\" field.");
    theForm.herofirstname.focus();
    return (false);
  }
  
  if (trim(theForm.friendlastname.value) == "")
  {
    alert("Please enter a value for the \"Adult Character's First Name\" field.");
    theForm.friendlastname.focus();
    return (false);
  }
  return (true);
}
/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}