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 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 ValidateContact(frm)
{
	var mailExp  = /^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
	var errMsg  = "Please correct the following item(s):\n\n";
	var errNum  = 0;

	if(!validateNotEmpty(frm.first_name.value))
	{
        frm.first_name.value == '';
        frm.first_name.focus();
		errMsg += ++errNum + ". First Name cannot be blank.\n";
	}
	if(!validateNotEmpty(frm.last_name.value))
	{
        frm.last_name.value == '';
		frm.last_name.focus();
		errMsg += ++errNum + ". Last Name cannot be blank.\n";
	}
	if(!validateNotEmpty(frm.company.value))
	{
        frm.company.value == '';
		frm.company.focus();
		errMsg += ++errNum + ". Company Name cannot be blank.\n";
	}
	if(!validateNotEmpty(frm.address.value))
	{
        frm.address.value == '';
		frm.address.focus();
		errMsg += ++errNum + ". Address cannot be blank.\n";
	}
	if(!validateNotEmpty(frm.phone.value))
	{
        frm.phone.value == '';
		frm.phone.focus();
		errMsg += ++errNum + ". Phone cannot be blank.\n";
	}
	if(!validateNotEmpty(frm.email.value))
	{
        frm.email.value == '';
		frm.email.focus();
		errMsg += ++errNum + ". Email Address cannot be blank.\n";
	}
	if(!validateEmail(frm.email.value))
	{
		errMsg += ++errNum + ". Email Address Invalid.\n";
		frm.email.focus();
	}	
	if(!validateNotEmpty(frm.description.value))
	{
        frm.description.value == '';
		frm.description.focus();
		errMsg += ++errNum + ". Comments cannot be blank.\n";
	}
	if(errNum != 0 )
	{
		alert(errMsg);
	}
	else
		frm.submit();
}
