/*////////////////// FORM VALIDATION JS /////////////////
*
* Last Update: 2006 04 16
* 
* A collection of javascript functions usefull for validating forms
*
* Available functions:
*
* trimAll( strValue ) - Removes leading and trailing spaces.
* validateNotEmpty( strValue ) - Validates that a string is not all blank (whitespace) characters.
* validateEmail( strValue) - Validates that a string contains a  valid email pattern.
* 
*/////////////////   //////////////////   ////////////////*/

/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.

   reference http://www.faqts.com/knowledge_base/view.phtml/aid/1678/fid/1
*************************************************/
function trimAll (str) {
  str = this != window ? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

/************************************************
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.

   reference http://www.rgagnon.com/jsdetails/js-0063.html
*************************************************/
 function validateNotEmpty( strValue ) {
  var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}

/**
* 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.) or valid country suffix.
**/
function validateEmail( strValue) {
	var objRegExp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/i;
	//check for valid email
	return objRegExp.test(strValue);
}

/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
function validateUSZip( strValue ) {
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
function validateInteger( strValue ) {
  var objRegExp  = /(^-?\d\d*$)/;

  //check for integer characters
  return objRegExp.test(strValue);
}

/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************/
 function  validateNumeric( strValue ) {
	 var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
	 //check for numeric characters
	 return objRegExp.test(strValue);
}

