function blnValidateForms(DateFormat)
{
	/*
	'------------------------------------------------------------------------
	'Generic Validation of MULTIPLE Forms.
	'
	'Purpose
	' To perform general client side validation of ALL HTML forms in a page.
	'
	' NOTE: If you wish to only validate A SINGLE form on a page then call
	' blnvalidateform()(singular) instead of this function.
	'
	' This is common Java script function that can be to be added to any page that
	' creates a form and requires general field validation on that form
	' (ie make sure fields aren't blank, have the correct data types etc).
	'
	' To make use of this script do the following:-
	'
	' 1) Create a HTML <SCRIPT> tag in the page with the form to validate.
	'	This <SCRIPT> tag should have a file as the source for the script.
	'	This file is called 'ClientValidateForms.js' and sits in the /common directory.
	'	
	'	The <SCRIPT> tag should be included after any HTTP header information.
	'	(just before the <HTML> tag is a good spot).
	'	
	'	For example,	
	'
	'	<SCRIPT LANGUAGE=javascript src="ClientValidateForms.js">
	'	 </SCRIPT>
	'	<HTML>
	'
	' 2) No make use of the script code you will have to place a 'validation'
	'	suffix after the name of the input element you wish to validate.
	'
	'	For example if you have an input text box on your form that
	'	accepts a postcode, you would normally name it 'PostCode'.
	'	If you wanted the postcode to be only numeric you would name it
	'	'PostCode_n' where 'n' stands for 'only accept numeric input'.
	'
	'	If you wanted to make sure postcode data was always entered then
	'	name it 'PostCode_m' where 'm' stands for 'Mandatory input'.
	'
	'	You can combine validation criterias. For example if you wanted
	'	the postcode to be only numeric AND Mandatory, you would name it
	'	'PostCode_n_m'.
	'
	'	 Here is an example of the <INPUT> tag definition that uses validation,
	'
	'	<INPUT id=postcode name=postcode_n_m>
	'
	'	Note: You only need suffixes on the NAME not the ID.
	'
	'	Here is a list of currently available Validation Suffixes.
	'	_C = 'Character Data only (A-B, a-b)
	'	_N = 'Numeric Data only (0-9)
	'	_L = 'Numeric Data (long) only (0-9)
	'	_A = 'Alphanumeric Data only (A-B, a-b, 0-9)
	'	_S = 'SQL Safe Data only (All characters but @ ' * % ?)
	'	_P = 'Post Code and Phone Data only.(0-9, brackets, dashes ans spaces)
	'	 _$ = 'Currency format only. (0-9, decimal point)
	'	 _M = 'Must be entererd'
	'	 _D = 'Must be a valid date, specified by the date format passed to this function
	'
	' 3) Finally, you need to tell the form to submit the validate funtions.
	'	You do this adding
	'		ONSUBMIT="return blnValidateForms()"
	'	 to the form tag.
	'
	'	For example
	'	<FORM ACTION="ProcessForm.asp">
	'
	'	becomes
	'
	'	<FORM ONSUBMIT="return blnValidateForms()" ACTION="ProcessForm.asp">
	'
	'
	'10-Jan-2000	Cory Lee	Initial Creation.
	'19-Jan-2000	Ivone		Added support for currency type checking
	'21-Jan-2000	AJMateljan	Corrected for multiple forms in one page
	'29-Feb-2000	Rincewind	Added long numeric type
	'27/06/00		PD			Added alt255 (space for locale numbers) to strValidCurrency
	'							and strValidNumber strings  '						
	'-------------------------------------------------------------------------
	
	***********************************************************************
	*							 MAIN LINE								*
	***********************************************************************/
	
	var intFormNumber
	/* Perform Validation on ALL Forms in the document */
	for (intFormNumber=0;intFormNumber < document.forms.length;intFormNumber++) {
		if (!blnValidateForm(document.forms[intFormNumber].name)) return false
	}	
	return true
}

function keyCode() {
	var keyCode = 0;
    if (window.event)
       keyCode = window.event.keyCode;
    else // Netscape
       keyCode = arguments.callee.caller.arguments[0].which;
       
    return (keyCode == 13) ? true : false;
}

function trim(str) {
	return (str.replace(/^\s+/, '').replace(/\s+$/, ''))
}

function blnCompareDates(objToFocus, objMinDate, objMaxDate, strDateFormat) {
	
	if (blnValidDates(objToFocus, objMinDate, strDateFormat) == false)
		return false;
	else if (blnValidDates(objToFocus, objMaxDate, strDateFormat) == false)
		return false;
	else if (dateDateCheck(objToFocus, objMinDate, objMinDate.value, strDateFormat) >
			 dateDateCheck(objToFocus, objMaxDate, objMaxDate.value, strDateFormat)) {
			alert("Dates must be sequentially ordered.")
			objToFocus.focus()
			objToFocus.select()
			return false;
	}
	return true;
}

function blnValidDates(objToFocus, objDateBox, strDateFormat) {
	if (dateDateCheck(objToFocus, objDateBox, objDateBox.value, strDateFormat) == false ){
		objToFocus.focus()
		objToFocus.select()
		return false;
	}
	return true;
}

function dateDateCheck(objToFocus, objTextBox, strToCheck, strDateFormat) {
	if (trim(strToCheck) == "" || strToCheck == null)
		return;
		
	if (strDateFormat == null )
		strDateFormat = "DMY"
		
	var idxYear = strDateFormat.indexOf("Y")
	var idxMonth = strDateFormat.indexOf("M")
	var idxDay = strDateFormat.indexOf("D")
		
	if (strToCheck.indexOf("/")!=-1)
		var sdate = strToCheck.split("/")
	else 	{
		if (strToCheck.indexOf("-")!=-1)
			var sdate = strToCheck.split("-")
		else
			var sdate = strToCheck.split(".")
		}
	if (sdate[idxYear] <= 50)
		sdate[idxYear] = 2000 + parseInt(sdate[idxYear])
	else
		if ((sdate[idxYear] > 50) && (sdate[idxYear]<= 99))
			 sdate[idxYear] = 1900 + parseInt(sdate[idxYear])

	var chkDate = new Date(Math.abs(sdate[idxMonth])+"/"+Math.abs(sdate[idxDay])+"/"+Math.abs(sdate[idxYear]))
	var indate2=(Math.abs(sdate[idxMonth]))+"/"+(Math.abs(sdate[idxDay]))+"/"+(Math.abs(sdate[idxYear]))
	var cmpDate=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+((chkDate.getYear()< 1900?chkDate.getYear()+1900:chkDate.getYear()))
	if (indate2!=cmpDate){
		alert("Input date is invalid or not in an acceptable format.")
		objToFocus.focus()
		objToFocus.select()
		return false;
	}
	else {
		if (cmpDate=="NaN/NaN/NaN"){
			alert("Input date is not valid or in an unacceptable format.")
			objToFocus.focus()
			objToFocus.select()
			return false;
			}
		else {
			return chkDate; 
		}
	}
 }

function blnValidateForm(strFormName,DateFormat)
{
	/*
	'------------------------------------------------------------------------
	'Generic Validation of a SINGLE Form
	'
	'Purpose
	' To perform general client side validation of a SINGLE HTML form.
	'
	' NOTE: If you wish to validate ALL forms on a page then do not call this
	' function. Instead, call blnvalidateformS().
	'
	' This is common Java script function that can be to be added to any page that
	' creates a form and requires general field validation on that form
	' (ie make sure fields aren't blank, have the correct data types etc).
	'
	' To make use of this script do the following:-
	'
	' 1) Create a HTML <SCRIPT> tag in the page with the form to validate.
	'	This <SCRIPT> tag should have a file as the source for the script.
	'	This file is called 'ClientValidateForm.js' and sits in the /common directory.
	'	
	'	The <SCRIPT> tag should be included after any HTTP header information.
	'	(just before the <HTML> tag is a good spot).
	'	
	'	For example,	
	'
	'	<SCRIPT LANGUAGE=javascript src="ClientValidateForm.js">
	'	 </SCRIPT>
	'	<HTML>
	'
	' 2) No make use of the script code you will have to place a 'validation'
	'	suffix after the name of the input element you wish to validate.
	'
	'	For example if you have an input text box on your form that
	'	accepts a postcode, you would normally name it 'PostCode'.
	'	If you wanted the postcode to be only numeric you would name it
	'	'PostCode_n' where 'n' stands for 'only accept numeric input'.
	'
	'	If you wanted to make sure postcode data was always entered then
	'	name it 'PostCode_m' where 'm' stands for 'Mandatory input'.
	'
	'	You can combine validation criterias. For example if you wanted
	'	the postcode to be only numeric AND Mandatory, you would name it
	'	'PostCode_n_m'.
	'
	'	Here is an example of the <INPUT> tag definition that uses validation,
	'
	'	<INPUT id=postcode name=postcode_n_m>
	'
	'	Note: You only need suffixes on the NAME not the ID.
	'
	'	Here is a list of currently available Validation Suffixes.
	'	_C = 'Character Data only (A-B, a-b)
	'	_N = 'Numeric Data only (0-9)
	'	_L = 'Numeric Data (long) only (0-9)
	'	_A = 'Alphanumeric Data only (A-B, a-b, 0-9)
	'	_S = 'SQL Safe Data only (All characters but @ ' * % ?)
	'	_P = 'Post Code and Phone Data only.(0-9, brackets, dashes ans spaces)
	'	_$ = 'Currency format only. (0-9, decimal point)
	'	_D = 'Dates with valid date seperators only (0-9, /-:. )
	'	_M = 'Must be entered'
	'
	' 3) Finally, you need to tell the form to submit the validate funtions.
	'	You do this adding
	'		ONSUBMIT="return blnValidateForm()"
	'	to the form tag.
	'
	'	For example
	'	<FORM ACTION="ProcessForm.asp">
	'
	'	becomes
	'
	'	<FORM ONSUBMIT="return blnValidateForm()" ACTION="ProcessForm.asp">
	'
	'
	'10-Jan-2000	Cory Lee	Initial Creation.
	'19-Jan-2000	Ivone		Added support for currency type checking
	'21-Jan-2000	AJMateljan	Corrected for multiple forms in one page
	'29-Feb-2000	Rincewind	Added long numeric type
	'28-Sep-2001	PD			Added objElementToCheck.value!=null constrain in MAIN form checking
	'-------------------------------------------------------------------------

	*/

	/* This receives the suffix part of the elements name ie '_n_m'
		and splits this string by '_' into an array of parameters. */
	function aryGetValidationParms(strElementName)
	{
		var strParmArray = new Array();
		strParmArray = strElementName.split('_');
		return strParmArray
	}

	/* Display a message box with a validation error for an element
		depending on what type of error has occured */
	function strNotValidAlert(strElementName , strFailedCheckType)
	{
		strElementName = strElementName.substring(0,strElementName.indexOf('_') )
		
		if (strElementName.substring(0,3)=='inp' && strElementName.substring(0,5)!='input')
			strElementName = strElementName.substring(3)
		switch (strFailedCheckType)
		{
			case 'C' :
				alert('The ' + strElementName + ' can only consist of letters.');break
			case 'N' :
				alert('The ' + strElementName + ' can only consist of digits.');break
			case 'L' :
				alert('The ' + strElementName + ' can only consist of digits.');break
			case 'A' :		
				alert('The ' + strElementName + ' can only consist of letters and digits.');break
			case 'M' :		
				alert('The ' + strElementName + ' must be entered.');break
			case 'S' :
				alert("The " + strElementName + " can not have any of the following characters  @  '  *  %  or  ?");break		
			case 'D' :
				alert("The " + strElementName + " can only consist of digits and date seperators.");break
			case 'P' :
				alert("The " + strElementName + " can only consist of digits, spaces, dashes, pluses and brackets.");break		
			case '$' :
				alert("The " + strElementName + " can only consist of digits and currency seperators.");break		
			case 'X' :
				alert("The " + strElementName + " must be less than 100000000.");break		
		}
	}

	function blnDateCheck(strToCheck, strElementName)
	{
		if (DateFormat == null )
			DateFormat = "DMY"

		var idxYear = DateFormat.indexOf("Y")
		var idxDay = DateFormat.indexOf("D")
		var idxMonth = DateFormat.indexOf("M")
		
		if (strToCheck.indexOf("/")!=-1)
				 var sdate = strToCheck.split("/")
		else
			{
			if (strToCheck.indexOf("-")!=-1)
				var sdate = strToCheck.split("-")
			else
				var sdate = strToCheck.split(".")
			}
		if (sdate[idxYear] <= 50)
			sdate[idxYear] = 2000 + parseInt(sdate[idxYear])
		else
			if ((sdate[idxYear] > 50) && (sdate[idxYear]<= 99))
				sdate[idxYear] = 1900 + parseInt(sdate[idxYear])

		var chkDate = new Date(Math.abs(sdate[idxMonth])+"/"+Math.abs(sdate[idxDay])+"/"+Math.abs(sdate[idxYear]))
		var indate2=(Math.abs(sdate[idxMonth]))+"/"+(Math.abs(sdate[idxDay]))+"/"+(Math.abs(sdate[idxYear]))
		var cmpDate=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+((chkDate.getYear()< 1900?chkDate.getYear()+1900:chkDate.getYear()))
		if (indate2!=cmpDate){
			alert("Input date is invalid or not correctly formatted.")
			return false;
		}
		else {
				if (cmpDate=="NaN/NaN/NaN"){
					alert("Input date is invalid or incorrectly formatted.")
					return false;
				}
				else {
					return true;
				}
		}
	}

	function blnCurrencyCheck(strToCheck, strElementName)
	{
		var blnPointFound = false
		
		strElementName = strElementName.substring(0,strElementName.indexOf('_') )

		if (strElementName.substring(0,3)=='inp' && strElementName.substring(0,5)!='input')
			strElementName = strElementName.substring(3)

		for (var i=0; i < strToCheck.length;i++)
			if (".".indexOf(strToCheck.substring(i, i+1)) != -1)
			{ 	
				if (blnPointFound)
				{
					for (var j=i; j < strToCheck.length;j++)	
						if (".".indexOf(strToCheck.substring(j, j+1)) > -1)
						{
							alert("The " + strElementName + " can only have one decimal point.")		
							return false
						}
				}
				blnPointFound = true
				if ( strToCheck.length > i+3 )
				{
					alert("The " + strElementName + " cannot have more than two digits after the decimal point.")		
					return false
				}
				if ( strToCheck.length == i+1 )
				{
					alert("The " + strElementName + " must have a digit after the decimal point.")	
					return false
				}
			}
	 return true
	}

	/* Make sure the 'strToCheck' string only contains
		characters within the selected datatype. */
	function blnDataTypeCheck(strToCheck , strDatatype)
	{
		var strValidAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		var strValidNumeric = '0123456789., '
		/*var strSQLSafe = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 @\\`~#$^&()-_+="{[}]:;<,>./|'*/
		var strSQLUnSafe = "@'*%?"
		var strPhone_PostCode = '0123456789 -()+'
		var strValidCurrency = '012345678 9.,'
		var strValidDate = '0123456789/-:. '
		var strValidChars

		/* Select the list of characters allowed in the string to check */
		switch(strDatatype.toUpperCase( ))
		{
			case 'C' : strValidChars = strValidAlpha;break
			case 'N' : strValidChars = strValidNumeric;break
			case 'L' : strValidChars = strValidNumeric;break
			case 'A' : strValidChars = strValidAlpha + strValidNumeric;break
			case 'S' : strValidChars = strSQLUnSafe;break
			case 'P' : strValidChars = strPhone_PostCode;break
			case '$' : strValidChars = strValidCurrency;break
			case 'D' : strValidChars = strValidDate;break
		}

		/* Check that characters in 'strToCheck' are OK. */
		if (strDatatype.toUpperCase() != 'S')
		{
			for(var i=0; i < strToCheck.length;i++)
				if (strValidChars.indexOf(strToCheck.substring(i, i+1))== -1)
				 	return false
		}
		else
		{
			for(var i=0; i < strToCheck.length;i++)
				if (strValidChars.indexOf(strToCheck.substring(i, i+1))!= -1)
					return false
		}
		return true
	}
	

	/***********************************************************************
	*							 MAIN LINE								*
	***********************************************************************/

	var intFormNumber, intElementNumber,intValidationNumber;
	var strValidationParms = new Array();
	var objElementToCheck
	var strCheckType
	var frmToValidate

		frmToValidate = document.forms[strFormName]
		
		/* Traverse ALL elements within the current Form.*/
		for (intElementNumber=0;intElementNumber < frmToValidate.elements.length;intElementNumber++)
		{
			/* See if the current element has 'Validation' suffixes in the name
				ie 'NAME_n_m' has two validation suffixes '_n' and '_m'. */

			objElementToCheck = frmToValidate.elements[intElementNumber]
			strValidationParms  = aryGetValidationParms( frmToValidate.elements[intElementNumber].name )

			/* For each suffix if the element name perform the requested validation. */
			for (intValidationNumber=0;intValidationNumber < strValidationParms.length;intValidationNumber++)
			{
				strCheckType = strValidationParms[intValidationNumber].toUpperCase( )
			
				/* If requested, do a data type check */
				if (objElementToCheck.value!=null && objElementToCheck.value != "" && ( strCheckType == 'C' || strCheckType == 'N' || strCheckType == 'L' || strCheckType == 'A' || strCheckType == 'S'  || strCheckType == 'P' || strCheckType == '$'|| strCheckType == 'D' ) )
				{
					if ( !blnDataTypeCheck(objElementToCheck.value , strCheckType ))
					{
						strNotValidAlert(objElementToCheck.name , strCheckType)
						objElementToCheck.select()
						objElementToCheck.focus()
						return false
					}
					
					if ( strCheckType == '$' )
					{
						if (! blnCurrencyCheck(objElementToCheck.value, objElementToCheck.name)) {
							objElementToCheck.select()
							objElementToCheck.focus()
							return false
						}
					}
					
					if ( strCheckType == 'D' )
					{
						if (! blnDateCheck(objElementToCheck.value, objElementToCheck.name)) {
							objElementToCheck.select()
							objElementToCheck.focus()
							return false
						}
					}
					if (strCheckType == 'N' )
					{
						if (objElementToCheck.value > 100000000) {
							strNotValidAlert(objElementToCheck.name , 'X')
							objElementToCheck.select()
							objElementToCheck.focus()
							return false
						}
					}
				}
				/* If requested, do a mandatory entry check */
				if (objElementToCheck.value == "" && strCheckType == 'M')
				{
					strNotValidAlert(objElementToCheck.name , strCheckType)
					objElementToCheck.select()
					objElementToCheck.focus()
					return false
				}
			}
		}
	return true
}