function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}


function validate_checked(field,alerttxt)
{
with (field)
  {
  if (checked==false)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid email pattern. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) and optionally,
  a valid country suffix.  Since email has many
  forms this expression only tests for near valid
  address.  Some additional validation may be
  required.
*************************************************/
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
  //check for valid email
  return objRegExp.test(strValue);
}



function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/ 
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }  
   return false;
}


function validate_form()
{
  var email = document.getElementById("eaddress");
  var txt = document.getElementById("text");

if(!validateNotEmpty(email.value))
	{alert("Email must be filled out!");email.focus();return false;}

if(!validateEmail(email.value))
	{alert("Invalid email address!");email.focus();return false;}

if(!validateNotEmpty(txt.value))
	{alert("Text is required!");txt.focus();return false;}

return true;  
}

function validate_quoteform()
{

if (validate_form()==false)
  {return false;}


  var pp = document.getElementById("pp");
  var code = document.getElementById("security_code");

if (validate_checked(pp,"You must accept the Privacy Policy")==false)
  {pp.focus();return false;}

  
if(!validateNotEmpty(code.value))
	{alert("You must input the security code");code.focus();return false;}


return true;  
}

function validate_optinform()
{
  var email = document.getElementById("eaddressoptin");

if(!validateNotEmpty(email.value))
	{alert("Email must be filled out!");email.focus();return false;}

if(!validateEmail(email.value))
	{alert("Invalid email address!");email.focus();return false;}

return true;  
}

function validate_searchform()
{
  var srch = document.getElementById("searchtext");

if(!validateNotEmpty(srch.value))
	{alert("No search text entered.");srch.focus();return false;}
return true;  
}
