 ///////////////////////////////////////////////
//check for valid dates (m/d/yy or m/d/yyyy)   //
//  2 or 4 digit year    ////////////////////////
 ///////////////////////////////////////////////
function datecheckORIG(theform,datearray)
{
var msg = "You have entered an invalid date. \n All dates must be in m/d/yy or m/d/yyyy format."
for (f = 0; f < datearray.length; f++)
     {
     var indate=theform[datearray[f]].value
     if (indate != "")
          {
          var sdate = indate.split("/")
          var chkDate=new Date(Date.parse(indate))
          if (chkDate=="NaN")
          	{
               alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
          	break;
          	}

          //check year
          if (sdate[2].length==0 || sdate[2].length==1 || sdate[2].length==3 || sdate[2].length>4)
          	{
               alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
               break;
               }

		if(sdate[2]>99)
			{
			if (sdate[2]<1900)
				{
	               alert(msg);
	               theform[datearray[f]].select();
	               theform[datearray[f]].focus();
	               submitit=false;
				break;
				}
			}

		chkDateYR = chkDate.getYear()

          //construct 2 dates using 2 different methods
          //then compare them
          //(Can't remember where I found this...it seems to do the trick)
          var cmpDate=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDateYR)
          var indate2=(Math.abs(sdate[0]))+"/"+(Math.abs(sdate[1]))+"/"+(Math.abs(sdate[2]))

          if (indate2!=cmpDate)
               {
               alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
               break;
               }
          else
               {
               if (cmpDate=="NaN/NaN/NaN")
                    {
                    alert(msg);
                    theform[datearray[f]].select();
                    theform[datearray[f]].focus();
                    submitit=false;
                    break;
                    }
               }
          }
     }
}


 ////////////////////////////////////////////////////////
// check for required fields that have been left blank //
 //////////////////////////////////////////////////////

function blankcheck(theform,blankarray,namearray)
{
x=0;
for (x=0;x<blankarray.length;x++)
	{
	var fldname = blankarray[x]
	var fieldvalue=theform[fldname].value
	if (fieldvalue.length==0 || fieldvalue=="")
		{
		alert("Please specify "+namearray[x]+".");
		theform[fldname].focus();
		submitit=false;
		return false;
		}
	}
}


 //////////////////////
//verify exact length//
 /////////////////////
function lencheck_exact(theform,fieldarray,lenarray)
{
for (x=0;x<fieldarray.length;x++)//loop thru each field
	{
	var fieldvalue=theform[fieldarray[x]].value
	if (fieldvalue)
		{
		var fieldlen=lenarray[x]
		//alert(x);
		//alert(fieldvalue.length);
		//alert(lenarray[x]);
		if (fieldvalue.length != fieldlen)
			{
			alert("This field must be exactly " + fieldlen + " characters long.");
			theform[fieldarray[x]].select();
			theform[fieldarray[x]].focus();
			submitit=false;
			return false;
			break;
			}
		}
	}
}




 ///////////////////////
//verify minimum length//
 //////////////////////
function lencheck_min(theform,fieldarray,lenarray)
{
for (x=0;x<fieldarray.length;x++)//loop thru each field
	{
	var fieldvalue=theform[fieldarray[x]].value
	if (fieldvalue)
		{
		var fieldlen=lenarray[x]
		if (fieldvalue.length < fieldlen)
			{
			alert("This field must be a minimum of " + fieldlen + " characters long.");
			theform[fieldarray[x]].select();
			theform[fieldarray[x]].focus();
			submitit=false;
			return false;
			break;
			}
		}
	}
}



 ///////////////////////
//verify minimum length//
 //////////////////////
function lencheck_max(theform,fieldarray,lenarray)
{
for (x=0;x<fieldarray.length;x++)//loop thru each field
	{
	var fieldvalue=theform[fieldarray[x]].value
	if (fieldvalue)
		{
		var fieldlen=lenarray[x]
		if (fieldvalue.length > fieldlen)
			{
			alert("This field must be a maximum of " + fieldlen + " characters long.");
			theform[fieldarray[x]].select();
			theform[fieldarray[x]].focus();
			submitit=false;
			return false;
			break;
			}
		}
	}
}



 ////////////////////////////////////////////////////////
// check fields that require a number                  //
 //////////////////////////////////////////////////////
function numbercheck(theform,fieldarray,decimal)
{
if(decimal==true)
	{
	var msg = "This field must contain a valid number. Decimals are permitted but no other non-numeric characters such as letters, commas, spaces, or dashes are."
	var checkstr="0123456789."
	}
	else
	{
	var msg = "This field must contain a valid number.  No non-numeric characters such as letters, commas, decimals, spaces, or dashes are permitted."
	var checkstr="0123456789"
	}
for (x=0;x<fieldarray.length;x++)//loop thru each field
	{
	var fieldvalue=theform[fieldarray[x]].value
	if (fieldvalue.length != 0)
		{
		for(fieldchar=0;fieldchar<fieldvalue.length;fieldchar++)
			{
			//alert(checkstr.indexOf(fieldvalue.charAt(fieldchar)));
			if (checkstr.indexOf(fieldvalue.charAt(fieldchar))==-1)
				{
				alert(msg);
				theform[fieldarray[x]].select();
				theform[fieldarray[x]].focus();
				submitit=false;
				return false;
				break;
				}
			}
		}
	}
}

//////////////////////////////
//CHECK FOR MAXIMUM DECIMALS//
//////////////////////////////
function decimalcheck(theform,fieldarray,namearray,num)
{
	for(x=0;x<fieldarray.length;x++)
	{
		var fieldvalue=theform[fieldarray[x]].value
		if (fieldvalue.length != 0)
			{
			var split_field = fieldvalue.split(".")
			if(split_field.length==2)
				{
				if(split_field[1].length > num)
					{
					alert("This field cannot have more than " + num + " decimal places.")
					theform[fieldarray[x]].select();
					theform[fieldarray[x]].focus();
					submitit=false;
					return false;
					break;
					}
				}
			}
	}
}





 //////////////////////////
//find invalid characters//
//////////////////////////
function charcheck(theform, fieldarray, checkstr)
{
msg = "This field contains one or more invalid characters."
for (f = 0; f < fieldarray.length; f++)//loop thru fields (fieldarray)
     {
     var str=theform[fieldarray[f]].value
     if (str != "")
          {
          cnt = 0
          while (cnt <= str.length)//loop thru characters of the string being examined (str)
               {
               ch=str.charAt(cnt)//get char from str
               for (c = 0; c <= checkstr.length; c++)//loop thru characters in the check string (checkstr)
                    {
                    if (ch == checkstr.charAt(c))
                         {
                         break;
                         }
                    else
                         {
                         if (c == checkstr.length)
                              {
                              alert(msg);
                              theform[fieldarray[f]].select();
                              theform[fieldarray[f]].focus();
                              submitit=false;
                              return false;
                              }
                         }
                    }
               cnt++
               }
          }
     }
}

 ///////////////////////////////////////
//Check for valid email address format//
 //////////////////////////////////////
function emailcheck(theform,fieldarray)
{
msg = "The Email address you entered is not a valid format."
for (x=0;x<fieldarray.length; x++)//loop thru the fields
	{
	var fieldvalue=theform[fieldarray[x]].value
	var exclude=/[^@\-\.\w]|^[@\.\-]|[\.\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	//var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((fieldvalue.search(exclude) != -1)||(fieldvalue.search(check)) == -1)||(fieldvalue.search(checkend) == -1))
		{
			alert(msg);
			theform[fieldarray[x]].select();
			theform[fieldarray[x]].focus();
			submitit=false;
			return false;
			break;
		}
	}
}


 ////////////////////////
//2 fields must be equal//
 ////////////////////////
function samevalue(theform,field1,field2)
{
if (theform[field1].value != theform[field2].value)
	{
		alert("The " + field1 + " fields must match to ensure correctness.");
		theform[field1].select();
		theform[field1].focus();
		submitit=false;
		return false;
	}
}





 ///////////////////////////////////////////////
//check for valid dates (m/d/yy or m/d/yyyy)   //
//  2 or 4 digit year    ////////////////////////
 ///////////////////////////////////////////////
function datecheck(theform,datearray)
{
//alert("date check function");
//alert(theform.name);
//alert(datearray[0]);
var msg = "You have entered an invalid date. All dates must be in m/d/yyyy format."
//alert("date array length:" + datearray.length);
for (f = 0; f < datearray.length; f++)
     {
     var indate=theform[datearray[f]].value
     
     if (indate != "")
          {
          var sdate = indate.split("/")
          //alert("split date length:" + sdate.length)
          if(sdate.length<3)
          	{
			alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
         		break;
          	}
          if(sdate[0]==0 || sdate[1]==0 || sdate[2]==0)
          	{
			alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
          	break;          		          		
          	}
          
          
          if(sdate[0].length==0 || sdate[1].length==0 || sdate[2].length==0)
          	{
			alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
          	break;          		          		
          	}
          
		if(datenumbercheck(sdate[0])==false || datenumbercheck(sdate[1])==false || datenumbercheck(sdate[2])==false)
			{
			alert(msg + "\n \n Month, Day, and Year must all be numeric and separated by '/'.");
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
          	break;				
			}


          
          var chkDate=new Date(Date.parse(indate))
          if (chkDate=="NaN")
          	{
               alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
          	break;
          	}

          //check year (REQUIRE 4 DIGIT YEAR)
          if (sdate[2].length!=4)
          	{
               alert(msg+"\n \n You must use 4-digit year.");
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
               break;
               }

		if (sdate[2]<1900)
			{
               alert(msg+"\n \n Year appears to be invalid.");
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
			break;
			}

		chkDateYR = chkDate.getFullYear()
		//alert("chkdateyr" + chkDateYR);
          //construct 2 dates using 2 different methods
          //then compare them
          //(Can't remember where I found this...it seems to do the trick)
          var cmpDate=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDateYR)
          var indate2=(Math.abs(sdate[0]))+"/"+(Math.abs(sdate[1]))+"/"+(Math.abs(sdate[2]))
		//alert(cmpDate);
		//alert(indate2);
          if (indate2!=cmpDate)
               {
               alert(msg);
               theform[datearray[f]].select();
               theform[datearray[f]].focus();
               submitit=false;
               break;
               }
          else
               {
               if (cmpDate=="NaN/NaN/NaN")
                    {
                    alert(msg);
                    theform[datearray[f]].select();
                    theform[datearray[f]].focus();
                    submitit=false;
                    break;
                    }
               }
          }
     }
}



function datenumbercheck(fieldvalue)
{
var checkstr="/0123456789"

if (fieldvalue.length != 0)
	{
	for(fieldchar=0;fieldchar<fieldvalue.length;fieldchar++)
		{
		if (checkstr.indexOf(fieldvalue.charAt(fieldchar))==-1)
			{
			return false;
			break;
			}
		}
	}
}