 function validateentireform()
	 {
	var errorcount = 0;
	
	var errortext = 'The following errors have been found in the form.\nThey have been highlighted in red:\n\n';
	for (var i=0;i<document.forms[1].length-1;i++)
		{
		var onblursting = document.forms[1][i].onblur;
		if(onblursting)
			{
			var firstArray = onblursting.toString().split("{");
			var secondArray = firstArray[1].split("(");	
			var validatethis = trimAll(secondArray[0]);
			if (validatethis == 'validatephonenumber')
				{
				if(validatephonenumber(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatenumaricwithdecimal')
				{
				if(validatenumaricwithdecimal(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatenumaric')
				{
				if(validatenumaric(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatealpha')
				{
				if(validatealpha(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'check_date')
				{
				if(check_date(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatenotblank')
				{
				if(validatenotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatephonenumberandnotblank')
				{
				if(validatephonenumberandnotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
				
			if (validatethis == 'validatenumaricwithdecimalandnotblank')
				{
				if(validatenumaricwithdecimalandnotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatenumaricandnotblank')
				{
				if(validatenumaricandnotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'validatealphaandnotblank')
				{
				if(validatealphaandnotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			if (validatethis == 'check_dateandnotblank')
				{
				if(check_dateandnotblank(document.forms[1][i],0) == false)
					{
					var errorcount = errorcount = 1;
					var errortext = errortext + document.forms[1][i].title + '\n';
					}
				}
			}
		}
		
		if (errorcount > 0)
			{
			alert(errortext + "\nPlease correct the errors and resubmit");
			return false;
			}
		else
			{
			return true;
			}
	 }


function validatephonenumber(field,erroralert)
	{ 
	var FmtStr="";
	var index = 0;
	var LimitCheck;
	LimitCheck = field.value.length;
	while (index != LimitCheck)
		{
		if (isNaN(parseInt(field.value.charAt(index))))
			{
			}
		else
			{
			FmtStr = FmtStr + field.value.charAt(index);
			}
		index = index + 1;
		}
	if (FmtStr.length > 0)
		{
		if (FmtStr.length == 10)
			{
			FmtStr = FmtStr.substring(0,3) + "-" + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
			highlighterror(field, 1);
			field.value = FmtStr;
			return true;
			}
		else if (FmtStr.length == 11)
			{
			FmtStr =FmtStr.substring(0,1) + "-" + FmtStr.substring(1,4) + "-" + FmtStr.substring(4,7) + "-" + FmtStr.substring(7,11);
			highlighterror(field, 1);
			field.value = FmtStr;
			return true;
			}
		else
			{
			highlighterror(field, 0);
			if (erroralert == 1)
				{
				alert("Error: Please enter in the phone number in this format: 3018815120 or 12022022020.\nThe form will not submit until all error are corrected.");
				}
			//field.select();
			//field.focus();
			return false;
			}
		}
	else
		{
		highlighterror(field, 1);
		return true;
		}
	}

function validatenumaricwithdecimal(field,erroralert)
	{
	var valid = "1234567890."
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++)
		{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
	if (ok == "no")
		{
		highlighterror(field, 0);
		if (erroralert == 1)
			{
			alert("Error: Only numbers are acceptedin this field.\nThe form will not submit until all error are corrected.");
			}
		//field.select();
		//field.focus();
		return false;
		}
	else
		{
		highlighterror(field, 1);
		return true;
		}
	}
	
function validatenumaric(field,erroralert)
	{
	var valid = "1234567890"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++)
		{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (ok == "no")
		{
		highlighterror(field, 0);
		if (erroralert == 1)
			{
			alert("Error: Only numbers are accepted in this field.\nThe form will not submit until all error are corrected.");
			}
		//field.select();
		//field.focus();
		return false;
		}
	else
		{
		highlighterror(field, 1);
		return true;
		}
	}

function validatealpha(field,erroralert)
	{
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++)
		{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
		}
	if (ok == "no")
		{
		highlighterror(field, 0);
		if (erroralert == 1)
			{
			alert("Error: Only characters are accepted in this field.\nThe form will not submit until all error are corrected.")
			}
		//field.select();
		//field.focus();
		return false;
		}
	else
		{
		highlighterror(field, 1);
		return true;
		}
	}
<!-- Begin
function check_date(field,erroralert)
	{	
	highlighterror(field, 1);
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = ".";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	DateValue = DateField.value;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++)
		{
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0)
			{
			DateTemp = DateTemp + DateValue.substr(i,1);
			}
		}
	DateValue = DateTemp;
	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length != 0)
		{
		if (DateValue.length == 6)
			{
			year1 = DateValue.substr(4,2);
			if ((year1 < 50) || (year1 > 100))
				{
				DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
				}
				else
				{
				DateValue = DateValue.substr(0,4) + '19' + DateValue.substr(4,2);}
				}
			if (DateValue.length != 8)
				{
				err = 19;
				}
				/* year is wrong if year = 0000 */
			year = DateValue.substr(4,4);
			if (year == 0)
				{
				err = 20;
				}
			/* Validation of month*/
			month = DateValue.substr(0,2);
			if ((month < 1) || (month > 12))
				{
				err = 21;
				}
			/* Validation of day*/
			day = DateValue.substr(2,2);
			if (day < 1)
				{
				err = 22;
				}
			/* Validation leap-year / february / day */
			if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0))
				{
				leap = 1;
				}
			if ((month == 2) && (leap == 1) && (day > 29))
				{
				err = 23;
				}
			if ((month == 2) && (leap != 1) && (day > 28))
				{
				err = 24;
				}
			/* Validation of other months */
			if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12")))
				{
				err = 25;
				}
			if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11")))
				{
				err = 26;
				}
			/* if 00 ist entered, no error, deleting the entry */
			if ((day == 0) && (month == 0) && (year == 00))
				{
				err = 0; day = ""; month = ""; year = ""; seperator = "";
				}
			/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
			if (err == 0)
				{
				DateField.value = month + "/" + day + "/" + year;
				return true;
				}
			/* Error-message if err != 0  */
		else
			{
			highlighterror(field, 0);
			if (erroralert == 1)
				{
				alert("Error: Please enter in the date in this format: mm/dd/yyyy.\nThe form will not submit until all error are corrected.");
				}
			//field.select();
			//ield.focus();
			return false;
			}
		}
	}
//  End -->
function validatenotblank(field,erroralert)
	{
	var strTemp = field;
	strTemp = trimAll(strTemp);
	if(strTemp.value.length > 0)
		{
		highlighterror(field, 1);
		return true;
		}
	else
		{
		highlighterror(field, 0);
		if (erroralert == 1)
			{
			alert('Error: This field is required.\nThe form will not submit until all error are corrected.');
			}
		//field.select();
		//field.focus();
		return false;
		}
	}

function validatephonenumberandnotblank(field,erroralert)
	{
	if (validatenotblank(field,erroralert) == true)
		{
		if(validatephonenumber(field,erroralert) == true)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	}
	
function validatenumaricwithdecimalandnotblank(field,erroralert)
	{
	if (validatenotblank(field,erroralert) == true)
		{
		if(validatenumaricwithdecimal(field,erroralert) == true)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	}
	
function validatenumaricandnotblank(field,erroralert)
	{
	if (validatenotblank(field,erroralert) == true)
		{
		if(validatenumaric(field,erroralert) == true)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	}

function validatealphaandnotblank(field,erroralert)
	{
	if (validatenotblank(field,erroralert) == true)
		{
		if(validatealpha(field,erroralert) == true)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	}
	
function check_dateandnotblank(field,erroralert)
	{
	if (validatenotblank(field,erroralert) == true)
		{
		if(check_date(field,erroralert) == true)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	}
       

function trimAll( strValue )
	{
	var objRegExp = /^(\s*)$/;
	//check for all spaces
	if(objRegExp.test(strValue))
		{
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0)
		return strValue;
		}
	//check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue))
		{
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
		}
	return strValue;
	}

function highlighterror(field,onoff)
	{			
	if (onoff == 1)
		{
		if (field.name.indexOf('requiredfield') > 0)
			{
			field.style.backgroundColor = '#FFFFCC';
			field.style.borderColor = '#999999';
			}
		else
			{
			field.style.borderColor = '#999999';
			field.style.backgroundColor = '#FFFFFF';
			}
		}
	else
		{
		field.style.borderColor = '#990000';
		field.style.backgroundColor = '#FFE8E8';
		}
	}

function validatephonenumberblank(field,erroralert)	{
	
	var str = field.value;
	var phone2 = /^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$/; 
	var FmtStr="";
	var index = 0;
	var LimitCheck;
	LimitCheck = field.value.length;
	while (index != LimitCheck)
					{
					if (isNaN(parseInt(field.value.charAt(index))))
									{
									}
					else
									{
									FmtStr = FmtStr + field.value.charAt(index);
									}
					index = index + 1;
					}
	if (FmtStr.length > 9 && FmtStr.length != 0)
					{
					if (FmtStr.length == 10)
									{
									FmtStr = "(" + FmtStr.substring(0,3) + ") " + FmtStr.substring(3,6) + "-" + FmtStr.substring(6,10);
									highlighterror(field, 1);
									field.value = FmtStr;
									return true;
									}
					else
									{
									if (str.match(phone2))
													{
													highlighterror(field, 1);
													return true;
													}
									else
													{
													highlighterror(field, 0);
													if (erroralert == 1)
																	{
																	alert("Error: Please enter in a valid phone number.\nThe form will not submit until all errors are corrected.");
																	}
													return false;
													}
									}
					}
	else if (FmtStr.length == 0)
					{
					highlighterror(field, 1);
					return true;
					}
	else 
					{
					highlighterror(field, 0);
					if (erroralert == 1)
									{
									alert("Error: Please enter in a valid phone number.\nThe form will not submit until all errors are corrected.");
									}
					return false;
					}
	}
