function validateTelephone( strValue ) {

  // non-digit characters which are allowed in phone numbers
  var phoneNumberDelimiters = "+()- ";
  // Minimum no of digits in an international phone no.
  var minDigitsInIPhoneNumber = 10;
  s=stripTelDelim(strValue,phoneNumberDelimiters);
  return (validateInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function stripTelDelim(s, delims) {   
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not a telephone delimiter, append to returnString.
  for (i = 0; i < s.length; i++)
  {   
      // Check that current character isn't whitespace.
      var c = s.charAt(i);
      if (delims.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}


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 = trimAll(strValue);
   if(strTemp.length > 0)
     return true;
   return false;
}


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*)([\W\w]*)(\b\s*$)/;

	//check for leading &amp; trailing spaces
	if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
	return strValue;
}


function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

*************************************************/
  var objRegExp = /^[a-zA-Z0-9&._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return objRegExp.test(strValue);

  //check for valid email
  return objRegExp.test(strValue);
}


function  validateNumeric( strValue ) {
/******************************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}


// check to see if input is alphanumeric
function isAlphaNumeric(val)
{
	return val.match(/^[a-zA-Z0-9]+$/);	
}


function  validatePassword( strValue ) 
{
  return isAlphaNumeric(strValue);
}


function validateInteger( s ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  //var objRegExp = /^\d+$/;
  //return objRegExp.test(strValue);
  
  if(s.length == 0) return false;
  
  var i;
  var digits = "0123456789";

  for (i = 0; i < s.length; i++)
  {   
      // Check that current character is number.
      var c = s.charAt(i);
      if (digits.indexOf(c) == -1) return false;
  }
  // All characters are numbers.
  return true;
  
}


function  validateDate( strDay, strMonth, strYear ) {
/******************************************************************************
DESCRIPTION: Validates that a number combinations provide a valid date

PARAMETERS:
   strDay - Date day
   strMonth - Date month   
   strYear - Date year
	
RETURNS:
   True if valid, otherwise false.
******************************************************************************/

	var isValid = true;
	
	if(!validateInteger(strDay)) isValid=false;
	if(validateInteger(strMonth)) {
		if(strMonth<1 || strMonth>12) isValid=false;
	}
	else
		isValid=false;
	if(!validateInteger(strYear)) isValid=false;
	
	var today = new Date();
	if(strYear < 1900 || strYear > today.getFullYear()) isValid=false;

	if(isValid)
	{
		switch(strMonth)
		{
			case 1:
				if(strDay<1 || strDay>31) isValid=false;
				break;
			case 2:
				if(strDay<1 || strDay>29) isValid=false;
				break;
			case 3:
				if(strDay<1 || strDay>31) isValid=false;
				break;
			case 4:
				if(strDay<1 || strDay>30) isValid=false;
				break;				
			case 5:
				if(strDay<1 || strDay>31) isValid=false;
				break;				
			case 6:
				if(strDay<1 || strDay>30) isValid=false;
				break;
			case 7:
				if(strDay<1 || strDay>31) isValid=false;
				break;
			case 8:
				if(strDay<1 || strDay>31) isValid=false;
				break;
			case 9:
				if(strDay<1 || strDay>30) isValid=false;
				break;
			case 10:
				if(strDay<1 || strDay>31) isValid=false;
				break;				
			case 11:
				if(strDay<1 || strDay>30) isValid=false;
				break;				
			case 12:
				if(strDay<1 || strDay>31) isValid=false;
				break;							
		}
	}

	return isValid;
}

	function verifyValidDate(objDay, objMonth, objYear, sDescription)
	{
		var selDay = objDay.value;
		if(selDay == "")
		{
			alert("The " + sDescription + " date is not valid."); 
			return false;
		}
		
		var selMonth = objMonth.options[objMonth.selectedIndex].innerHTML;
		if ( (selMonth == '' || selMonth == 'Apr' || selMonth == 'Jun' || selMonth == 'Sep' || selMonth == 'Nov') && selDay > 30  )
		{
			alert("The " + sDescription + " date is not valid."); 
			return false; 
		}

		if ( selMonth == 'Feb' && selDay > 28 )
		{
			alert("The " + sDescription + " date is not valid."); 
			return false; 
		}
		
		if ( objYear.value == '' )
		{
			alert("The " + sDescription + " date is not valid."); 
			return false; 
		}
		
		return true;
		
	}
	
	function verifyFutureDate(objDay, objMonth, objYear, sDescription)
	{
		var today = new Date();
		today.setDate(today.getDate());

		var aDate = new Date();
		aDate.setFullYear(objYear.options[objYear.selectedIndex].value,objMonth.options[objMonth.selectedIndex].value-1,objDay.value)
		
		if(today > aDate){
			alert("The " + sDescription + " date must be a date in the future."); 
			return false;
		}
		
		return true;
	}


/*
//onkeypress = "return numbersOnly(event);"
function numbersOnly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
	if (unicode<48||unicode>57) //if not a number
	return false; //disable key press
	}
	return true;
}
*/


