// Common field validators

//IsNotEmpty - Validates that the field value string has one or more characters in it.

function IsNotEmpty(elem)
{
	var str=elem.value;
	
	if(str==null || str.length==0)
		{
			return false;
		}
	else
		{
			return true;
		}
		
}


function IsTenDigitPhoneNumber(elem)
{
	var str=elem.value;
	
	if(str==null || str.length<10)
	{
			return false;
	}
	else
	{
		return true;
	}
		
}

function IsFourDigitYear(elem)
{
	var str=elem.value;
	
	if(str==null || str.length<4)
	{
			return false;
	}
	else
	{
		return true;
	}
		
}


function IsFiveDigitZipCode(elem)
{
	var str=elem.value;
	
	if(str==null || str.length<5)
	{
			return false;
	}
	else
	{
		return true;
	}
		
}

//IsPositiveNumber - Validates that the entry is a positive number.

function IsPositiveWholeNumber(elem)
{
	var str = elem.value;
	var oneDecimal = false;
	var oneChar = 0;
	//make sure value hasn't been cast to a number data type
	str = str.toString();
	for(var i=0; i < str.length; i++)
	{
		oneChar=str.charAt(i).charCodeAt(0);
		//characters outside of 0 through 9 not O.K.
		if(oneChar < 48 || oneChar > 57)
		{
			return false;
			
		}
		
	}
	
	return true;
	
}

/*-------------------------------------------------------------------------------------
 -IsValidEmail - Validates that the entry is formatted as an email address
 --------------------------------------------------------------------------------------
  Looks for a match that begins (^) with one or more letters, numerals, underscores,
  or hyphens([\w-]), followed by zero or more combinations of a period, letter, numeral
  underscore, or hyphen ((\.[\w-]+)*), followed by the @ symbol, followed by one or more
  computer or domains (([\w-]+\.)+), followed by two to seven upper or lowercase letters 
  for the top-level domain name([a-zA-Z]{2,7}) on the tail end($).
 ---------------------------------------------------------------------------------------
 */


function IsValidEmail(elem)
{
	var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if(!str.match(re))
	{
		return false;
	}
	
	else
	{
		return true;
		
	
	}
	
}

/*---------------------------------------------------------------------------------------
 -IsValidPolicyNumber - Validates that the entry is in an acceptable policy number format.
 ----------------------------------------------------------------------------------------
 Valid formats are (optional) ca or CA, followed by an optional space, nine digits with a 
 hypen and two digits or just nine digits.
 -----------------------------------------------------------------------------------------
 */
function IsValidPolicyNumber(elem)
{
var str = elem.value;


	var re = /([cC][aA][\s]|[cC][aA])?([0-9]{9}[-][0-9]{2}|[0-9]{2})/;
	if(!str.match(re))
	{
		return false;
	}
	
	else
	{
		return true;
		
	
	}
	
}

/*---------------------------------------------------------------------------------------
 -IsValidDate - Validates that the entry is in an actual date.
 -monthString must be month abbreviation - e.g. "Mar" (see direct_policy_addvehicle.aspx)
 ----------------------------------------------------------------------------------------

 -----------------------------------------------------------------------------------------
 */
function IsValidDate(dayString,monthString,yearString)

{
var myDateStr = yearString + '/' + monthString + '/' + dayString;

/* Using form values, create a new date object
which ends up looking like "Wed Jan 1 00:00:00 EST 1975". */
var myDate = new Date(myDateStr);
//alert(myDate);
// Convert the date to a string so we can parse it.
var myDate_string = myDate.toDateString();


/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */
var myDate_array = myDate_string.split( ' ' );

/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
converts the value to "Mar 3, 1975". Therefore, we compare the month
in the array with the month we entered into the form. If they match,
then the date is valid, otherwise, the date is NOT valid. */

if (myDate_array[1] != monthString) 
{
  return false;
} 

else 
{
  return true;
}

}
/*-------------------------------------------------------------------------------------------
 -numeralsOnly - Key Press event for text box entry.  
				 To use, add attribute to text boxes: onkeypress="return numeralsOnly(event)"
 --------------------------------------------------------------------------------------------

 --------------------------------------------------------------------------------------------
 */
function numeralsOnly(evt)
						{
							
							//Equalize event models.
							evt = (evt)? evt:event;
							var charCode=(evt.charCode)?evt.charCode:((evt.keyCode)? evt.keyCode:((evt.which)? evt.which:0));
							
							//For characters out of "numeric" range, cancel bubble.
							if(charCode > 31 && (charCode < 48 || charCode > 57))
							{
							 return false;
							}
							
							return true;
						
					 }
	