//<script language='JavaScript'>
/*	
	NAME		:	JS_GeneralMethods.js
	DESCRIPTION :	Form containing generic methods/
	ACTION		:	
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
*/

	var mstOrderByName = new String('OrderByName');

//*****************************************************************************************
	function jfnLoadStatus() 
/*	
	NAME		:	jfnLoadStatus
	DESCRIPTION	:	Relaods the status frame
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
	CALLED BY	:	
*/
	{
		var stLocation = parent.frameStatus.location;
		parent.frameStatus.location = stLocation;
	}

//*****************************************************************************************
	function jfnNavigateHome() 
/*
	NAME		:	jfnNavigateHome
	DESCRIPTION	:	Relaods the main Menu
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
*/	
	{
		parent.frameNotHeader.location = './BigMainMenu.asp';
	}

//*****************************************************************************************
	function jfnNavigatePrevious() 
/*
	NAME		:	jfnNavigatePrevius
	DESCRIPTION	:	Reloads the last visited page
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
*/	
	{
		parent.history.back();
	}

//*****************************************************************************************
	function jfnNavigateNext() 
/*
	NAME		:	jfnNavigatenext
	DESCRIPTION	:	Relaods the next page on the history list
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
*/		
	{
		history.forward();
	}

//*****************************************************************************************
	function jfnLoadIDLocation(iButton, iBigMenu)
/*	
	DESCRIPTION	:	Loads the form whose location is stored in the button's
					ID property.
					If the iBigMenu Parameter is set to true then the sidebar menu is also
					created
					Either called by a big menu in
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000 
*/
	{
		if (iBigMenu)
			parent.parent.frameNotHeader.location = iButton.id;
		else
			parent.frameContent.location = iButton.id;
	}

//***************************************************************************
// VALIDATION FUNCTIONS
//***************************************************************************
	
	function jfnIsEmpty(istString)
/*
	DESCRIPTION	:	Checks to see if the string passed contains a value or nto
	AUTHOR		:	Ian Renshaw
	DATE		:	13 November 2000
*/		
	{
		var lString = new String(istString);
		
		if ( (lString == null) || (lString.length == 0) )
		{
			return true
		}
		else
			return false		
	}

//*****************************************************************************************
	function jfnIsControlPopulated(iElement, istErrorMsg)
/*	
	DESCRIPTION	:	Simple generic validation to determine whether the control is 
					completed or not.  If there is nothing there then the error message is
					prompted
	AUTHOR		:	Ian Renshaw
	DATE		:	16 January 2001
	CALLS		:	jfnIsEmpty
*/		
	{
		var lstElValue = new String( iElement.value )
		if (jfnIsEmpty(lstElValue))
			{
				alert(istErrorMsg);
				iElement.focus();
//				iElement.select();
				return false
			}
		else
			return true
	}

//*****************************************************************************************
	function jfnIsEitherControlPopulated(iElement1,iElement2, istErrorMsg)
/*	
	DESCRIPTION	:	Simple generic validation to determine whether the control is 
					completed or not.  If there is nothing there then the error message is
					prompted
	AUTHOR		:	Jacob Collins
	DATE		:	2nd March 2001
	CALLS		:	jfnIsEmpty
*/		
	{
		var lstElValue1 = new String( iElement1.value )
		var lstElValue2 = new String( iElement2.value )
		if (jfnIsEmpty(lstElValue1))
			{
				if (jfnIsEmpty(lstElValue2))
				{
				alert(istErrorMsg);
				iElement1.focus();
				return false
				}
			}
		else
			return true
	}

//*****************************************************************************************
	function jfnIsFormComplete(iForm)
/*	
	DESCRIPTION	:	Simple generic validation to determine if all fields are completed
	AUTHOR		:	Ian Renshaw
	DATE		:	15 November 2000
	CALLS		:	jfnIsEmpty
*/		
	{
		for (i = 0; i < iForm.length; i++)
			if (jfnIsEmpty(iForm.elements[i].value))
			{
				alert('Please complete all the fields.');
				iForm.elements[i].focus();
				iForm.elements[i].select;
				return false
			}
			return true
	}

//*****************************************************************************************
	function jfnIsOneComplete()
/*
	DESCRIPTION	:	Simple generic validation to determine if one of the controls in the array
					has been completed
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	jfnIsEmpty
*/
	{
		var liCount = jfnIsOneComplete.arguments.length;
		var lIsEmpty;
		var lOnePopulated = false;

		for ( i=0; i < liCount; i++)
		{
			var lString = new String(jfnIsOneComplete.arguments[i].value)
			lIsEmpty = jfnIsEmpty( lString );

			if ( lIsEmpty == false )
				lOnePopulated = true
		}		
		return lOnePopulated;
	}

//*****************************************************************************************
	function jfnIsInteger(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	jfnIsEmpty
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var liCount = 0;
		for (liCount=0; liCount < lstValue.length; liCount++)
			if ( lstValue.charAt(liCount) < '0' || lstValue.charAt(liCount) > '9')
			{
				jfnWarnInvalid(iElement, 'Please enter only numeric values.');
				return false;
			}
		return true
	}
			
//*****************************************************************************************
// VALIDATION FUNCTIONS TO LIMIT TEXT ENTRY TO FIELDS
//*****************************************************************************************

	function jfnLimitToNumeric(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsDigit(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}
//*****************************************************************************************
	function jfnLimitToDecimal(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsDecimal(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToMoney(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsMoney(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToDate(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsDateChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToPhone(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numeric values are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsPhoneChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToPostCode(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numbers, letters and spaces are added
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	Use in OnKeyUp event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsPostCodeChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}
//*****************************************************************************************
	function jfnLimitToTime(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numbers or colons are added
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	Use in OnKeyUp event and OnKeyDown event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsTimeChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToAddress(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only numbers,letters, commas or spacess are added
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	Use in OnKeyUp event and OnKeyDown event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsAddressChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToText(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only letters or spaces are added
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	Use in OnKeyUp event and OnKeyDown event
*/
	{
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsTextChar(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}

//*****************************************************************************************
	function jfnLimitToTextNoSpace(iElement)
/*
	DESCRIPTION	:	Generic Validation Code to check only letters are added
	AUTHOR		:	Alex Knott
	DATE		:	08 July 2003
	CALLS		:	Use in OnKeyUp event and OnKeyDown event
*/
	{
		
		
		var lstValue = new String(iElement.value)
		
		// if nothing there, then it is ok
		if (jfnIsEmpty(lstValue)) return true
		
		var lstLastChar = new String( lstValue.charAt(lstValue.length-1) );
		if ( !jfnIsTextCharNoSpace(lstLastChar) )
		{
			// Remove it
			iElement.value = lstValue.substring(0, lstValue.length-1)
			iElement.focus();
		}
		return true
	}


//*****************************************************************************************
// End of validation functions to limit text entry to fields
//*****************************************************************************************

//*****************************************************************************************
// 
//*****************************************************************************************

	function jfnCheckLimit( iRequestedElement, iMax, iItem )
/*	
	DESCRIPTION	:	Generic Validation Code...
					Checks that the value entered into a control is not in excess of the 
					max value, also passed into the function.  If it is then displays an error
					and returns false.
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	
*/	
	{
		var lstValue = new String(iRequestedElement.value);
		var lstMax = new String(iMax);

		if (lstValue > lstMax)
		{
			alert('The maximum number of ' + iItem + ' that can be ordered is ' + lstMax);
			return false
		}
		else
			return true
	}

//*****************************************************************************************
	function jfnIsNumberWithinLimit( iRequestedNumber, iMax, iItem )
/*		
	DESCRIPTION	:	Generic Validation Code...
					Checks that the number passed in is not in excess of the 
					max value, also passed into the function.  If it is then displays an error
					and returns false.
	AUTHOR		:	Ian Renshaw
	DATE		:	16 November 2000
	CALLS		:	
*/	
	{
		var lstValue = new String(iRequestedNumber);
		var lstMax = new String(iMax);

		if (lstValue > lstMax)
		{
			alert('The maximum number of ' + iItem + ' that can be ordered is ' + lstMax);
			return false
		}
		else
			return true
	}
//*****************************************************************************************
	function jfnLimitText(field, maxlimit)
/*
	DESCRIPTION	:	Checks to see if a text area or simmilar is not passed the max length.  If it is 
					then it fails to enter anymore text.
					fieldObj = this
					maxChars = number of max chars ie 255
				On key up
	AUTHOR		:	Sian Mace
	DATE		:	28 October 2003
	CALLED		:		
	CALLS		:	
*/	
		{

		if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);

		}

//*****************************************************************************************
	function jfnAllPopulatedOrEmpty( iArray )
/*
	DESCRIPTION	:	Returns true if all the values of objects passed in through the array
					parameter are either all populated or all empty
	AUTHOR		:	Ian Renshaw
	DATE		:	December 2000
	CALLED		:		
	CALLS		:	None
*/	
	{
		var ltfOneFilled = false
		var ltfOneEmpty = false
		var lstValue = new String()

		// iterate through the array
		for ( liArrayItem=0; liArrayItem<iArray.length; liArrayItem++ )
		{
			lstValue = null;
			lstValue = iArray[liArrayItem].value;
			
			// Is the value of the value attribute empty?
			if ((lstValue == null) || (lstValue.length == 0))
			{
				if ( ltfOneFilled )
				{
					return false;
					break;
				}
				else
					ltfOneEmpty=true;
			}
			else
			// if the string is populated
			{
				if (ltfOneEmpty)
				{
					return false;
					break;
				}
				else
					ltfOneFilled=true;
			}
		}
		return true
	} // end of function

//*****************************************************************************************
	function jfnAreAllDetailsForGroupComplete( iArray, iGroupName )
/*
	DESCRIPTION	:	Returns true if all the values of objects passed in through the array
					parameter are either all populated or all empty... Allows it to be accessed
					with a message
	PARAMETERS	:	A user defined array of controls
*/
	{
		// Remove any underscores if there are any
		var lstGroupName = new String ( jfnRemoveUnderscores(iGroupName) )
		var lRetVal;
		lRetVal = jfnAllPopulatedOrEmpty(iArray);
		if ( lRetVal==false )
		{
			alert('The details for ' + lstGroupName + ' are not complete.');
			return false;
		}
		else
			return true;
	}

//*****************************************************************************************
/*	function jfnMakeArrayOfValues()

	DESCRIPTION	:	Reads the parameters passed in, which are values that have a "value"
					and adds these to an array
	PARAMETERS	:	A user defined array 'values'

	{
		var lRetVal = new Array();

		var liCount = jfnMakeArrayOfValues.arguments.length;
		for ( i=0; i < liCount; i++)
			lRetVal[i] = jfnMakeArrayOfValues.arguments[i].value;

		return lRetVal;
	}
*/
//*****************************************************************************************
	function JavascriptTest(iText)
	{
		alert(iText);
	}

//*****************************************************************************************
	function jfnGetBrowserDetails()
	{
		var bName = navigator.appName;
		var bVer = parseFloat(navigator.appVersion);
		if (bName == 'Netscape')
			{
			var browser = 'Netscape Navigator';
			alert('Sorry, this site is designed to work in Internet Explorer only.');
			}
	
		
	}

//*****************************************************************************************
	function jfnCompareString( iString1, iString2)
/*
	DESCRIPTION	:	Compares two strings to determine whether they are identical.  
					This is also case sensetive
					Does not work with Chars
	AUTHOR		:	Ian Renshaw
	DATE		:	December 2000
	CALLED		:		
	CALLS		:	
*/	
	{
		var liString1 = new String(iString1);
		var liString2 = new String(iString2);

		var lDifferent
		if ( liString1.length != liString2.length )
			lDifferent = true;
		else
		{
			for (i=0; i<iString1.length; i++)
			{
				if ( iString1.charAt(i) != iString2.charAt(i) )
					lDifferent = true;
			}
		}
		if ( lDifferent == true )
			return false
		else
			return true
	}

//*****************************************************************************************
	function jfnIsOneFormElementComplete(iForm)
/*
	DESCRIPTION	:	Simple generic validation to determine if one of the controls in the array
					has been completed... 
					Where elements have common ID values, these are validated to ensure
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	jfnIsEmpty
*/	
	{
		var lRetVal = false

		// Iterate thro all the elements
		for ( liElementID=0; liElementID < iForm.elements.length; liElementID++)
		{
			// Store the value type and id of the element
			var lstValue = new String(iForm.elements[liElementID].value)
			var lstType = new String(iForm.elements[liElementID].type);
			var lstID = new String(iForm.elements[liElementID].id);
			
			// if there is a value to the element...
			if ( !jfnIsEmpty( lstValue ) ) 
			{
				// But if the completed element has an id value of OrderByName then ignore
				if ( !jfnCompareString( lstID, mstOrderByName ) )
				{
					// Only valid if the populated element is a select or a text box
					if ( (jfnCompareString(lstType,'text')) || (jfnCompareString(lstType,'select-one')) )
						lRetVal = true
				}
			}
		}	
		if (!lRetVal)
			alert('Please enter a value into at least one box.');
		return lRetVal
	}

//*****************************************************************************************
	function jfnIsGroupPartFilled(iForm)
/*	
	DESCRIPTION	:	Primary Uniform Order Validation Function
					Return true if the group is part filled... ie when several elements with the 
					same ID attribute are neither all empty nor all populated.
	AUTHOR		:	Ian Renshaw
	DATE		:	30 November 2000
	CALLS		:	jfnCompareString, jfnAreAllDetailsForGroupComplete, jfnGetArrayOfTextOrCombo 
*/
	{
		// Iterate through the form elements that are text or combo controls.
		var laTextComboArray = new Array();
		laTextComboArray = jfnGetArrayOfTextOrComboElements(iForm)
		for ( liGroup=0; liGroup<laTextComboArray.length; liGroup++ )
		{
			//Get the ID value
			var lstID = new String( laTextComboArray[liGroup].id );
			
			// make sure there is a value attribute...
			if ( !jfnIsEmpty( lstID) )
			{
				var laElementGroup = new Array();
			
				//Iterate through the elements in the form to get an array of elements with same id
				for ( liSubGroup=0; liSubGroup<laTextComboArray.length; liSubGroup++ )
				{
					// Get the id of each element and if it is the same, add the element to the array
					var lstSubID = new String( laTextComboArray[liSubGroup].id );
					if ( jfnCompareString( lstSubID, lstID ))
						laElementGroup[laElementGroup.length] = laTextComboArray[liSubGroup];
				}

				// Call jfnAreAllDetailsForGroupComplete method to see if all the members
				// of the array are populated
				var lAllCompleteRetVal = jfnAreAllDetailsForGroupComplete( laElementGroup, lstID )
				if (!lAllCompleteRetVal)
				{
					//laTextComboArray(liGroup).focus();
					return false
				}
			}	// if there is a value attribute
		}
		return true
	}

//*****************************************************************************************

	function jfnIsGroupPartCompletelyFilled(iForm)
/*	
	DESCRIPTION	:	Primary Uniform Order Validation Function
					Return true if the group is part filled... ie when several elements with the 
					same ID attribute are neither all empty nor all populated.
	AUTHOR		:	Ian Renshaw
	DATE		:	30 November 2000
	CALLS		:	jfnCompareString, jfnAreAllDetailsForGroupComplete, jfnGetArrayOfTextOrCombo 
*/
	{
		
	// Iterate through the form elements that are text or combo controls.
		var laTextComboArray = new Array();
		laTextComboArray = jfnGetArrayOfTextOrComboElements(iForm)
		for(liGroup=0; liGroup < laTextComboArray.length; liGroup++)
		{
			alert(laTextComboArray[liGroup].value);
		}
		alert("done");
		
		
		
		for ( liGroup=0; liGroup<laTextComboArray.length; liGroup++ )
		{
			//Get the ID value
			//liGroup++;
			var lstID = new String( laTextComboArray[liGroup].id );
			//alert(lstID);
			// make sure there is a value attribute...
			if ( !jfnIsEmpty( lstID) )
			{
				//alert("Details for" + lstID + "are not complete");
				var laElementGroup = new Array();
			
				//Iterate through the elements in the form to get an array of elements with same id
				for ( liSubGroup=0; liSubGroup<laTextComboArray.length; liSubGroup++ )
				{
					// Get the id of each element and if it is the same, add the element to the array
					var lstSubID = new String( laTextComboArray[liSubGroup].id );
					if ( jfnCompareString( lstSubID, lstID ))
						laElementGroup[laElementGroup.length] = laTextComboArray[liSubGroup];
				}

				// Call jfnAreAllDetailsForGroupComplete method to see if all the members
				// of the array are populated
				var lAllCompleteRetVal = jfnAreAllDetailsForGroupComplete( laElementGroup, lstID )
				if (!lAllCompleteRetVal)
				{
					//laTextComboArray(liGroup).focus();
					return false
				}
			}	// if there is a value attribute
		}
		return true
	}

//*****************************************************************************************
	function jfnGetArrayOfTextOrComboElements(iForm)
	
/*	DESCRIPTION	:	Returns an array of elements which are text or combo input controls
	AUTHOR		:	Ian Renshaw
	DATE		:	30 November 2000
	PARAMETER	:	Form
	REURNS		:	An array of elements
	CALLS		:	jfnIsTextOrCombo	
*/
	{
		var laElements = new Array();

		for ( liFormElement=0; liFormElement<iForm.elements.length; liFormElement++ )
		{
			// is each item a text or combo?
			var lRetVal = jfnIsTextArea(iForm.elements[liFormElement])
			
			// If it is a combo box or a text box...
			if ( lRetVal == true )
			{
				// Add it to the array
				var liCount = laElements.length;

				laElements[liCount] = iForm.elements[liFormElement];

			}
		}
		return laElements
	}

//-----------------------------------------------------------------------------
	function jfnIsTextOrCombo(iElement)

/*	DESCRIPTION	:	Returns an boolean to indicate whether the element passed in was a text 
					or combo control
	AUTHOR		:	Ian Renshaw
	DATE		:	30 November 2000
	PARAMETER	:	Element
	REURNS		:	Boolean
	CALLS		:	jfnCompareString	
*/
	{
		var lstType = new String(iElement.type);
	
		if ( (jfnCompareString(lstType,'textarea')) || (jfnCompareString(lstType,'text')) || (jfnCompareString(lstType,'select-one')))
			return true
		else
			return false
	}


//-----------------------------------------------------------------------------
	function jfnIsTextArea(iElement)

/*	DESCRIPTION	:	Returns an boolean to indicate whether the element passed in was a text 
					or combo control
	AUTHOR		:	Ian Renshaw
	DATE		:	30 November 2000
	PARAMETER	:	Element
	REURNS		:	Boolean
	CALLS		:	jfnCompareString	
*/
	{
		var lstType = new String(iElement.type);
	
		if ( (jfnCompareString(lstType,'textarea')))
			return true
		else
			return false
	}
//*****************************************************************************************
// VALIDATION FUNCTIONS TO DETERMINE THE TYPE OF SINGLE CHARS
//*****************************************************************************************

	function jfnIsLetter (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		return ( ((iChar.charAt(0) >= "a") && (iChar.charAt(0) <= "z")) || ((iChar.charAt(0) >= "A") && (iChar.charAt(0) <= "Z")) )
	}

//*****************************************************************************************
	function jfnIsDigit (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		return ((iChar >= "0") && (iChar <= "9"))
	}

//-------------------------------------------------------------------------------------
	function jfnIsSpace (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		var lstSpace = new String(' ');
		return ( jfnCompareString(iChar, lstSpace ) )
	}


//*****************************************************************************************
	function jfnIsSlash (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		var lstSpace = new String('/');
		return ( jfnCompareString(iChar, lstSpace ) )
	}
//*****************************************************************************************
	function jfnIsPeriod (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		var lstSpace = new String('.');
		return ( jfnCompareString(iChar, lstSpace ) )
	}

//*****************************************************************************************
	function jfnIsPound (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		var lstSpace = new String('£');
		return ( jfnCompareString(iChar, lstSpace ) )
	}


//*****************************************************************************************
	function jfnIsColon (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins	
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		var lstSpace = new String(':');
		return ( jfnCompareString(iChar, lstSpace ) )
	}

//*****************************************************************************************
	function jfnIsComma (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins	
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		var lstSpace = new String(',');
		return ( jfnCompareString(iChar, lstSpace ) )
	}


//*****************************************************************************************
	function jfnIsPostCodeChar (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Ian Renshaw
	DATE		:	21 November 2000
	CALLS		:	
*/		
	{   
		return (jfnIsLetter(iChar) || jfnIsDigit(iChar) || jfnIsSpace(iChar))
	}

//*****************************************************************************************
	function jfnIsTimeChar (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins	
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsDigit(iChar) || jfnIsColon(iChar) )
	}
//*****************************************************************************************
	function jfnIsDecimal (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins	
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsDigit(iChar) || jfnIsPeriod(iChar) )
	}
//*****************************************************************************************
	function jfnIsMoney (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins	
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsDigit(iChar) || jfnIsPeriod(iChar) || jfnIsPound(iChar) )
	}
//*****************************************************************************************
	function jfnIsTextChar (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsLetter(iChar) || jfnIsSpace(iChar))
	}
	
//*****************************************************************************************
	function jfnIsTextCharNoSpace (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsLetter(iChar))
	}

//*****************************************************************************************
	function jfnIsAddressChar (iChar)
/*
	DESCRIPTION	:	
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLS		:	
*/		
	{   
		return (jfnIsLetter(iChar) || jfnIsSpace(iChar) || jfnIsDigit(iChar) || jfnIsComma(iChar))
	}

//*****************************************************************************************
	function jfnIsPhoneChar (iChar)
/*
	DESCRIPTION	:	Returns a boolean to show if the passed character is valid in a phone number
	USED		:	ChangeOtherDetails.asp
*/
	{   
		var lRetVal = ( jfnIsDigit(iChar) || jfnIsSpace(iChar) )
		return lRetVal
	}

//*****************************************************************************************
	function jfnIsDateChar (iChar)
/*
	DESCRIPTION	:	Returns a boolean to show if the passed character is valid in a phone number
	USED		:	ChangeOtherDetails.asp
*/
	{   
		var lRetVal = ( jfnIsDigit(iChar) || jfnIsSlash(iChar) )
		return lRetVal
	}

//******************************************************************************************
// End of determining whether single chars are what type
//******************************************************************************************

	function jfnWarnInvalid (iElement, iMessage)
/*
	DESCRIPTION	:	Shows a message and sets the focus to an element
	AUTHOR		:	Ian Renshaw
	DATE		:	December 2000
	CALLED		:		
	CALLS		:	
*/	
	{
		iElement.focus()
		iElement.select()
		alert(iMessage)
		return false
	}

//******************************************************************************************
// FUNCTIONS TO VALIDATE THAT STRINGS CONFORM TO CERTAIN TYPES
//******************************************************************************************
	function jfnContainsValidPostCode(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is a valid post code
					i.e. Maximum of 8 characters, which are either numbers, letters or a space 
					Shows an error message if not valid
	AUTHOR		:	Ian Renshaw
	DATE		:	December 2000
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsPostcodeChar
*/	
	{
		var lString = new String(iElement.value);
		var liSpaceCount = 0;

		// Check length
		if ( lString.length > 8 )
		{
			jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid post code.');
			return false;
		}
		// Iterate through each item
		for ( liIndex=0; liIndex<lString.length; liIndex++ )
		{
			// How many spaces?
			if ( jfnIsSpace(lString.charAt(liIndex) ) )
			{
				liSpaceCount++;
				if ( liSpaceCount > 1 )
				{ 
					jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid post code.');
					return false;
				}
			}

			// Check Characters
			if ( !jfnIsPostCodeChar( lString.charAt(liIndex) ) )
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid post code.');
				return false;
			}
		}
	}

//*****************************************************************************************
	function jfnContainsValidDate(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is a valid date
					i.e. Contains only numbers and two "/"'s 
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsDateChar
*/	
	{
		// Iterate through each item
		var lString = new String(iElement.value);
		var lName = new String(iElement.Name);
		
		// Check the number of / characters
		if ( jfnCharCount(lString, '/') != 2 )
		{
			//jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid date.');
			//alert("Not a Valid Date");
			return false;
		}

		// Check all chars are valid
		for ( liIndex=0; liIndex<lString.length; liIndex++ )
		{
			if ( !jfnIsDateChar( lString.charAt(liIndex) ) )
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid date.');
				return false;
			}
		}

		return true
	}
//*****************************************************************************************
	function jfnContainsValidSunday(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is a valid sunday. 
					To do this it first checks it has two slashes in, the uses a formula to 
					see if it is a sunday
	AUTHOR		:	Jacob Collins
	DATE		:	2 March 2001
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsDateChar
*/
	{	
		var lString = new String(iElement.value);
	//this is to see that it contains two slashes
		if ( jfnCharCount(lString, '/') != 2 )
		{
			jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid date.');
			return false;
		}
		else
		{
		//this is processed iff it has two slashes in	
			var lStringArray=lString.split("/");
			//this makes sure that no part of the date is blank
			if (!(lStringArray[0].length==0 || lStringArray[1].length==0 || lStringArray[2].length==0))
			{
			
				var dd = (lStringArray[0]);
				var mm = (lStringArray[1]);
				var yyyy = (lStringArray[2]);
			//the math.floor is used to convert the variables from strings to n umeric
				var y = Math.floor(yyyy); 
				var d = Math.floor(dd);
				var m = Math.floor (mm);
				var ly=0;
				//this determines whether it is a leapyear
				if (y/4==Math.floor(y/4))
				{	
					ly=1;
				}
				var mc;
				//this determines the effect of the month
				if (m==1) 
					{
						mc=6;
						if (ly == 1)
						{mc=5}
					}
				else if (m==2)
					{
						mc=2;
						if (ly == 1)
						{mc=1}
					}
				else if (m==3)
					{mc=2}
				else if (m==4)
					{mc=5}
				else if (m==5)
					{mc=0}
				else if (m==6)
					{mc=3}
				else if (m==7)
					{mc=5}
				else if (m==8)
					{mc=1}
				else if (m==9)
					{mc=4}
				else if (m==10)
					{mc=6}
				else if (m==11)
					{mc=2}
				else if (m==12)
					{mc=4}
				//this  combines all the variables and calculates whether it is a Sunday
				var a = d + y + mc + Math.floor (y/4);
				var r =a/7;
				var p =Math.floor(a/7)
				var q =Math.round(7*(r-p))
				// it turns out that it returmns a q of 1 if the date is a Sunday
				if (q==1) 
				{
					return true
				}
				else
				{
					jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Sunday.');
					return false
				}
			}
			else
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Sunday.');
				return false
			}
		}
	}
	
function jfnContainsValidFirst(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is the first of the month. 
					To do this it first checks it has two slashes in, the uses a formula to 
					see if it is a 1.
	AUTHOR		:	Jacob Collins
	DATE		:	2 March 2001
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsDateChar
*/
	{	
		var lString = new String(iElement.value);
	//this is to see that it contains two slashes
		if ( jfnCharCount(lString, '/') != 2 )
		{
			jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid date.');
			return false;
		}
		else
		{
		//this is processed iff it has two slashes in	
			var lStringArray=lString.split("/");
			//this makes sure that no part of the date is blank
			if (!(lStringArray[0].length==0 || lStringArray[1].length==0 || lStringArray[2].length==0))
			{
			
				var dd = (lStringArray[0]);
				var mm = (lStringArray[1]);
				var yyyy = (lStringArray[2]);
			//the math.floor is used to convert the variables from strings to n umeric
				var y = Math.floor(yyyy); 
				var d = Math.floor(dd);
				var m = Math.floor (mm);
				
				if (d==1) 
				{
					return true
				}
				else
				{
					jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Date.');
					return false
				}
			}
			else
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Date.');
				return false
			}
		}
	}
	
//*****************************************************************************************
	function jfnContainsValidTime(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is a valid time
					i.e. Contains only numbers and one :
	AUTHOR		:	Jacob Collins
	DATE		:	22 February 2001
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsTimeChar
*/	
	{
		// Iterate through each item
		var lString = new String(iElement.value);
		
		// Check the number of : characters
		if ( jfnCharCount(lString, ':') != 1 )
		{
			jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Time.');
			return false;
		}

		// Check all chars are valid
		for ( liIndex=0; liIndex<lString.length; liIndex++ )
		{
			if ( !jfnIsTimeChar( lString.charAt(liIndex) ) )
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid Time.');
				return false;
			}
		}
		return true
	}

//*****************************************************************************************
	function jfnContainsValidPhoneNumber(iElement)
/*
	DESCRIPTION	:	Takes a form element and checks that the content of it is a valid phone
					number...
					i.e. Maximum of 14 characters, which are either numbers or a space 
					Shows an error message if not valid
	AUTHOR		:	Ian Renshaw
	DATE		:	December 2000
	CALLED		:		
	CALLS		:	jfnWarnInvalid, jfnIsPhoneChar
*/	
	{
		var lString = new String(iElement.value);
		// Iterate through each item
		
		// Max length is 14
		if ( lString.length > 14 )
		{
			jfnWarnInvalid(iElement, '"' + iElement.value + '" is too long for a phone number.');
			return false;
		}

		for ( liIndex=0; liIndex<lString.length; liIndex++ )
		{
			if ( !jfnIsPhoneChar(lString.charAt(liIndex) ) )
			{
				jfnWarnInvalid(iElement, '"' + iElement.value + '" is not a valid phone number.');
				return false;
			}
		}
	}
	
//*****************************************************************************************
	function jfnCharCount(iString, iChar)
	{
		var liCharCount = 0;
		for ( liIndex=0; liIndex<iString.length; liIndex++ )
		{
			if ( iString.charAt(liIndex) == iChar )
				liCharCount++
		}
		return liCharCount;
	}
//*****************************************************************************************
	function jfnLinkTo( iLinkName )
/*
	DESCRIPTION	:	Used in the onClick element event to link to a hyperlink which has a name...
					ie. one in the same document

*/	
	{
		document.location = iLinkName
	}

//*****************************************************************************************
	function jfnOrderNameEntered(iForm)
/*
	DESCRIPTION	:	Checks to make sure that the form's txtOrder_Placed_By <input> tag has a value
					assigned to it
					Depends on the form having an element whose name is "txtOrder_Placed_By"
	DATE		:	Decemeber 2000
	AUTHOR		:	IanRenhaw
	CALLED BY	:	Order Forms
	CALLS		:	jfnIsEmpty, jfnWarnInvalid
*/
	{
		if ( jfnIsEmpty(iForm.txtOrder_Placed_By.value) )
		{
			jfnWarnInvalid (iForm.txtOrder_Placed_By, 'Please enter your name.')
			return false
		}
		else
			return true
	}

//*****************************************************************************************
	function jfnAreAllIDsEntered( iForm, iID )
/*
	DESCRIPTION	:	Checks to make sure that the form's txtOrder_Placed_By <input> tag has a value
					assigned to it
	DATE		:	Decemeber 2000
	AUTHOR		:	Ian Renshaw
	CALLED BY	:
	CALLS		:	jfnIsEmpty, jfnCompareString
*/
	{
	// iterate through all the form elements looking for those whose ID value is the same as the
	// input parameter
	for ( liElCount=0; liElCount<iForm.elements.length; liElCount++ )
		{
			if ( jfnCompareString( iForm.elements[liElCount].id, iID ) )
			{
				if ( jfnIsEmpty(iForm.elements[liElCount].value) )
					return false
			}
		}
		return true;
	}
//*****************************************************************************************
		function jfnRemoveUnderscores( iString )
/*
	DESCRIPTION	:	Removes underscores from the string passed in and replaces them with 
					spaces
	DATE		:	25 January 2001
	AUTHOR		:	Ian Renshaw
	CALLED BY	:
	CALLS		:	
*/
	{
		var lstOutString = new String;
		for ( var liChar=0; liChar<iString.length; liChar++ )
		{
			if ( iString.charAt(liChar) == '_' )
				lstOutString = lstOutString + ' '
			else
				lstOutString = lstOutString + iString.charAt(liChar)
		}
		return lstOutString



	}
//*****************************************************************************************	
	function jfnFormatCurrency( iString )
/*
	DESCRIPTION	:	Returns the string passed in the format #.00
	DATE		:	17 December 2002
	AUTHOR		:	Susie Gardner
*/
	{	iString+="";
		if(iString.indexOf('.')<0)	
			iString+=".00";
		while(iString.indexOf('.')>iString.length-3)	
			iString+="0";
		if(iString.indexOf('.')<iString.length-3){	
			var i = iString.indexOf('.');
			iString = iString.substr(0,i+3);
			}
		if (!isNaN(iString))
			return iString;
		else
			return "0.00";
	}

//*****************************************************************************************

	function jfnValidDate( lstDateD, lstDateM, lstDateY, istErrorMsg ) 
	/*
	DESCRIPTION	:	Checks Date is valid, returns True if date is valid
	DATE		:	13 March 2003
	AUTHOR		:	Alexander Knott
	*/
	{
		var lstValueD = new String( lstDateD.value );
		var lstValueM = new String( lstDateM.value );
		var lstValueY = new String( lstDateY.value );
		
		var dt = new Date();
		var day = dt.getDate();
		var month = dt.getMonth()+1;
		var year = dt.getFullYear();	
		
		if (jfnIsEmpty(lstValueD))
		{
			alert("Enter Day part of Date");
			lstDateD.focus();
			//lstDateD.select();
			return false;
		}
		else if (jfnIsEmpty(lstValueM))
		{
			alert("Enter Month part of date");
			lstDateM.focus();
			//lstDateM.select();
			return false
		}
		
		else if (jfnIsEmpty(lstValueY))
		{
			alert("Enter Year part of Date");
			lstDateY.focus();
			//lstDateY.select();
			return false
		}
		else 
		{
			switch (lstDateM.value) 
			{
				case '02':
					if (lstValueD > 29) 
					{
						alert("Date out of range");
						lstDateD.focus();
//						lstDateM.select();
						return false;
					}
					break;
				case '04':
					if (lstValueD > 30) 
					{
						alert("Date out of range");
						lstDateD.focus();
//						lstDateM.select();
						return false;
					}
					break;
				case '06':
					if (lstValueD > 30) 
					{
						alert("Date out of range");
						lstDateD.focus();
//						lstDateM.select();
						return false;
					}
					break;
				case '09':
					if (lstValueD > 30) {
						alert("Date out of range");
						lstDateD.focus();
//						lstDateM.select();
						return false;
					}
					break;
				case '11':
					if (lstValueD > 30) {
						alert("Date out of range");
						lstDateD.focus();
//						lstDateM.select();
						return false;
					}
					break;
			}//end switch
		}// end else
		if (lstValueY == year)
		{
			if (lstValueM > month) 
			{
				lstDateM.focus();
				alert("You can not select future dates");
				return false;
			}//end if
			if (lstValueM == month)
			{
				if (lstValueD > day)
				{
					lstDateD.focus();
					alert("You can not select future Dates");
					return false;
				}//end if 	
			}//end if
		}//end if	
				
		
				
		return true;	
	} //end jfnValidDate

//*****************************************************************************************

	function jfnValidTime2(lstTime)
	/*
	DESCRIPTION	:	Checks Time is in valid 24hr format, returns True if format is valid
	DATE		:	13 March 2003
	AUTHOR		:	Alexander Knott
	*/
	{
		
		var lstValueT = new String(lstTime.value);
		var lstTimeH = lstValueT.substring(0,2);
		var lstTimeM = lstValueT.substring(3);
		
		if (jfnIsEmpty(lstValueT))
		{
			alert("Please enter the Time of the incident");
			lstTime.focus();
			//lstTime.select();
			return false
		}
		else if ((lstTimeH > 24) || (lstTimeM > 59))
		{
			alert("Time out of range");
			lstTime.focus();
			//lstTime.select();
			return false
		}
		else if (lstValueT.charAt(2) != ":")
		{
			alert("Time must be in 00:00 format");
			lstTime.focus();
			//lstTime.select();
			return false
		}
		else
			return true; 
	}// end jfnValidTime

  

//</script>