////////////////////////////////////////////////////////////////////////////////////////

function isBlank(testStr)
//	returns true if text is blank or all spaces
  {
	 
	 if (testStr.length == 0) 
	 	{        // nothing entered?
			  return true;
		}
			  
	 for (var i = 0; i <= testStr.length-1; i++)     // all spaces?
		if (testStr.charAt(i) != " ")  
			  {
			  	 return false;
			  }
		return true;
 }
  
////////////////////////////////////////////////////////////////////////////////////////

function isNumeric(testNumber)
//returns true if text is numeric
{
	for (var i = 0; i < testNumber.length; i++)
		{
		  if (!(testNumber.charAt(i) >= "0" && testNumber.charAt(i) <= "9"))
			{	
			  return false;
			} 
 		}
	
	return true;
 }

////////////////////////////////////////////////////////////////////////////////////////
//function added 8/23/2002 checks to see if a number is a decimal
//at some point will put in added functionality to test or restrict # of decimal places
function isDecimal(testNumber)
//returns true if text is decimal
{
	if (isBlank(testNumber)){							//test for blank
	  	return false;
	 }
	
	for (var i = 0; i < testNumber.length; i++)
		{
		  if (!(isNumeric(testNumber.charAt(i))))		//check to see if numeric
			{	
				if (!(testNumber.charAt(i) == "."))	//check for decimal
			    {
				  //alert(testNumber.charAt(i)+ ' not 0-9 or .');
				  return false;						//was niether number or decimal
				}
		  else										//check to see if only decimal entered
			    {
				if (testNumber.length == 1)
				  {
					//alert("testNumber.length == " + testNumber.length);
					return false;					//decimal was only thing entered 
				  }		
				}	
			} 
 		}
	
	return true;
 }
  
  
///////////////////////////////////////////////////////////////////////////////////////

function isDate(testDate)
{
//	returns false for an invalid date
	
	var strTempstr;
	var intPlaceHolder;
	var intYear;
	var intMonth;
	var intDay;
	var c;
	var e;
	var errSW = 0;
	var sErrMsg;
	
	sErrMsg = '';
	dateTestDate = new String(testDate);//  convert to string so we can use string functions
	
	intPlaceHolder = dateTestDate.indexOf('/');// find the first /
	intMonth = dateTestDate.substring(0, intPlaceHolder);// month
	c = dateTestDate.charAt(intPlaceHolder);// '/'
	strTempstr = new String(dateTestDate.substring(intPlaceHolder + 1, dateTestDate.length));// dd/yy(yy)
	
	//we need to break out the day and month, year is the leftover
	intPlaceHolder = strTempstr.indexOf('/');// find the first /
	intDay = strTempstr.substring(0, intPlaceHolder);// day
	e = strTempstr.charAt(intPlaceHolder);// '/'
	intYear = strTempstr.substring(intPlaceHolder + 1, strTempstr.length);
	
	//basic error checking
	if (isNumeric(intMonth))
	   {
	   	  if (intMonth < 1 || intMonth > 12) 
	   	  	 {  
	   	  	 	sErrMsg = 'Month must be between 1 and 12';	
				errSW = 1;
	   		 }
		}
	else
		{
		 sErrMsg = 'Month must be numeric.';
		  errSW = 1;
		}
		   
	if (c != '/')
	   {
	   	   errSW = 1;
		   sErrMsg = 'Must put a slash after month';
	   }
	
	if (isNumeric(intDay))
	   {  
	   	  if (intDay < 1 || intDay > 31) 
	   	  	 {
			  sErrMsg = 'Day must be between 1 and 31.';
	   	   	  errSW = 1;
	   		 }
	   }
	else
		{
		  sErrMsg = 'Day must be numeric';
		  errSW = 1;
		}
		
	if (e != '/') 
	   {
	   	   sErrMsg = 'Must put slash after day.';
	   	   errSW = 1;
	   }
	
	if (isNumeric(intYear))
	  {   
	   	 if (intYear.substring((intYear.length - 2), intYear.length) < 0 || intYear.substring((intYear.length - 2), intYear.length) > 99) 
	   	   	{
	   	   	   sErrMsg = 'This is not a valid date. \n Please use mm/dd/yyyy format.';
			   errSW = 1;
	   		}
			
		 if (intYear.length == 4)
			{
		   		 if (intYear.length > 4)
					{
						sErrMsg = 'Year must be 4 digits.';
				 		errSW = 1;
					}				
			}
		else
			{
				sErrMsg = 'Year must be 4 digits.';
				errSW = 1;
			}
			
	   }
	else
	   {
	   	  sErrMsg = 'Year must be numeric';
		  errSW = 1;
	   }
	   	
	//advanced error checking

	// months with 30 days
	if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11)
	   {
		    if (intDay == 31) 
			   {
			   	sErrMsg = 'This is no day 31 in this month.';
			   	 errSW = 1;
			   }
	   }

	// february, leap year
	if (intMonth == 2)
	   {
		// feb
		var g = parseInt(intYear/4);
		
		if (intDay > 29) 
		   {	
		   	sErrMsg = 'There are only 28 days in February.';
		     errSW = 1;
			 
		   }
		   
		if (intDay == 29 && ((intYear/4)!=parseInt(intYear/4))) 
		   {
		   	  sErrMsg = 'This is not a leap year.';
			  errSW = 1;
			  
		   }
		   
		}

	if (errSW == 1)
	   {
		  alert (sErrMsg);
		  return false;
	    }
	else
		{
			
		  return true;
	    }

}  
////////////////////////////////////////////////////////////////////////////////////////

function isEmail(emailTest)
//returns true if valid email
  {
	   var atsignPos = emailTest.indexOf("@", 0)     // check for @
	   if (atsignPos == -1)
		 {
		  alert("Enter a valid email address with an @.")
		  return false
		  }
	   if (emailTest.indexOf(".", atsignPos) == -1)  // check for . after @	
	     {
		   alert("Enter a valid email domain after the @.")
		   return false
		 }
	   var atsignPos2 = emailTest.indexOf(".", 0);
	   if (emailTest.length <= (atsignPos2 + 2))  
	   	{
		   alert('There must be at least two characters after the \"."');
		   return false;
	   	}
	   
	   if (emailTest.charAt((emailTest.length) - 1) == '.')  
	    {
		  alert("Email address must end with a letter");
		  return false;
	    }
	   return true
  }
  
///////////////////////////////////////////////////////////////////////////////////////

function isLogin(text)
//returns true if text contains no special characters
  {
  	if (text.indexOf('*') >= 0 || text.indexOf('%') >= 0 ||  
		text.indexOf('+') >= 0 || text.indexOf('\'') >= 0)
		{
			return false;
		}
	else
		{
			return true;
		}
  }
  
/////////////////////////////////////////////////////////////////////////////////////////