	function checkform( fields, field_descriptions ) {
		for( var i = 0; i < fields.length; i++ ) {
			if( document.getElementById(fields[i]) && document.getElementById(fields[i]).value == 0 ) {
				alert( 'Please enter a value for ' + field_descriptions[i] );
				return false;
			}
		}
		
		return true;
	}
	
	
	
	function validateForm() {
		
		// holds an array of errors to output
		var fieldErrorArray = new Array();
		
		// private accessor methods
		this.checkRadio = checkRadio;
		this.checkChecked = checkChecked;
		this.checkText = checkText;
		this.checkTextMinLength = checkTextMinLength;
		this.checkNumeric = checkNumeric;
		this.checkPrice = checkPrice;
		this.checkListBoxHasItems = checkListBoxHasItems;
		this.checkSelect = checkSelect;
		this.validateEmailAddress = validateEmailAddress;
		this.validatePostCode = validatePostCode;
		this.displayErrors = displayErrors;
		this.numberOfErrors = numberOfErrors;
		this.addCustomError = addCustomError;
		this.getErrors = getErrors;
		
		// returns the array of errors
		function getErrors() {
			return fieldErrorArray;
		}
		
		// checks that one has been checked (may need altering)
		function checkRadio( element, length, output ) {

			var hasChecked = false;
			for (i = 0; i < length; i++){
				if (document.getElementById( element + '[' + i + ']').checked) {
			      hasChecked = true;
			   }
			}
			if(!hasChecked){
				fieldErrorArray.push(output);
				return false;
			}
			return true;
		}
		
		function checkChecked( element, output ) {
			if (!document.getElementById( element ).checked) {
				fieldErrorArray.push(output);
			}
		}
		
		// ensures text has been entered
		function checkText ( element, output, defaultText ) {
			if (document.getElementById( element ).value == '') {
				fieldErrorArray.push(output);
				return false;
			} else if ( typeof defaultText != 'undefined' ) {
				if ( document.getElementById( element ).value == defaultText ) {
					fieldErrorArray.push(output);
					return false;
				}
			}
			return true;
		}
		
		// ensures text of certain length has been entered
		function checkTextMinLength ( element, output, charLength ) {
			var checkString = document.getElementById( element ).value;
			if( checkString.length < charLength ){
				fieldErrorArray.push(output);
			}
		}
		
		function checkNumeric ( element, output ){
			var data = document.getElementById( element ).value;
			var ValidChars = "0123456789.";
			var IsNumber = true;
			var Char;
			if( data.length > 0 ) {
				for (i = 0; i < data.length && IsNumber == true; i++){ 
					Char = data.charAt(i); 
					if (ValidChars.indexOf(Char) == -1){
						// ok, its not valid, if its first position is a minus
						if( i == 0 && Char == '-' ) {
							// first character can be a "-" (minus)
						} else {
							IsNumber = false;
						}
					}
				}
				if( !IsNumber ){
					fieldErrorArray.push( output + ' must be a numeric value' );
					return false;
				}
			} else {
				// no value entered
				fieldErrorArray.push( output );
				return false;
			}
			return true;
		}
		
		function checkPrice ( element, output  ){
			var data = document.getElementById( element ).value;
			var ValidChars = "0123456789.,";
			var IsNumber = true;
			var Char;
			if( data.length > 0 ) {
				for (i = 0; i < data.length && IsNumber == true; i++){ 
					Char = data.charAt(i); 
					if (ValidChars.indexOf(Char) == -1){
						IsNumber = false;
					}
				}
				if( !IsNumber ){
					fieldErrorArray.push( output + ' must be a price' );
					return false;
				}
			} else {
				// no value entered
				fieldErrorArray.push( output );
				return false;
			}
			return true;
		}
	
		
		// checks for items in the passed listbox
		function checkListBoxHasItems ( element, output ) {
			if( document.getElementById( element ).length <= 0) {
				fieldErrorArray.push(output);
				return false;
			}
			return true;
		}
		
		// checks the value chosen is not the passed default value
		function checkSelect ( element, nothingValue, output ){
			if( document.getElementById( element ).value == nothingValue ){
				fieldErrorArray.push(output);
				return false;
			}
			return true;
		}
		
		// checks the value chosen is not the passed default value
		function validateEmailAddress ( emailAddress, output ){
			if( document.getElementById( emailAddress ) )
				emailAddress = document.getElementById( emailAddress ).value;
			if( typeof( output ) == 'undefined' )
				output = 'Email address is invalid';
			var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if ( !filter.test( emailAddress )){
				fieldErrorArray.push( output );
				return false;
			}
			return true;
		}

		// checks the value chosen is not the passed default value
		function validatePostCode ( element, output ){
			var filter  = /^[A-Za-z]{1,2}[0-9]{1}[A-Za-z0-9]{0,1}[ ]?[0-9]{1}[A-Za-z]{2}$/;
			if ( !filter.test( document.getElementById( element ).value ) ){
				fieldErrorArray.push( output );
				return false;
			}
			return true;
		}
		
		
		// add a custom error to the array
		function addCustomError( errorMessage ){
			
			fieldErrorArray.push( errorMessage );
			
		}
		
		// returns the number of errors found
		function numberOfErrors(){
			
			return fieldErrorArray.length;
			
		}
		
		// alerts all current errors to the user	
		function displayErrors(){
			
			var output = '';
			
			for(i=0;i<fieldErrorArray.length;i++){
				
				output += ' - ' +fieldErrorArray[i] + '\n';
				
			}
			
			alert('The following fields have not been completed:\n\n' + output);
			
		}
		
	}
	
	// -----------------------------------------------------------------------------------
	//
	// createPagination
	//
	//  	count - the number of records returned in the result set ( so we can calculate the number of pages
	//  	currentPage - the page user is currently looking at
	//  	recordsperPage - the amount of records we show on each page
	//
	// 		output - a table row element which looks like :-
	//
	//     	|<  <<  <  1  2  3  4  5  6 >  >>  >| 
	//
	// 		as hyperlinks which in turn call a javascript function change' + functionName + 'Page()
	//
	// -----------------------------------------------------------------------------------
	function createPagination( count, currentPage, recordsPerPage, functionName ) {
	
		// if no function name was defined, use default
		if( typeof( functionName ) == 'undefined' ){
			functionName = 'changePage';
		}
		
		var newTR = document.createElement("tr");
		newTR.setAttribute("align", "center");
		var newTD = document.createElement("td");
		var intCurrentPage = parseInt( currentPage );
		var intRecordsPerPage = parseInt( recordsPerPage );
		
		if( parseInt( count ) > 0 ){
			// now add the td with all javascript links
			var numberToRound = count / recordsPerPage
			var newPageCount = Math.ceil( numberToRound );
			// work out the start and end index
			var start = 0;
			var end = 0;
			// figure out the start record
			// if current page - 5 is less than 1, set 1 to be the start page
			if( ( intCurrentPage - 5 ) < 1 ){
				start = 1;
			} else {
				// we have more than 5 records before the first page, set it to 5 before
				start = intCurrentPage - 5;
			}
			// figure the end record
			if(( intCurrentPage + 5 ) > newPageCount ){
				end = newPageCount;
			} else {
				end = intCurrentPage + 5;
			}
			
			// first record
			if( currentPage > 1 ){
				var newLink = document.createElement('a');
				newLink.setAttribute('href','javascript:' + functionName + '(1)');
		  		var linkText = document.createTextNode( "|<" );
		  		newLink.setAttribute('title', 'First Page (1)');
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
			if( currentPage > 1 ){
				// add previous x link
				var newLink = document.createElement('a');
				if( ( intCurrentPage - ( intRecordsPerPage + 1 ) ) <= 0) {
					pageIndex = 1;
				} else {
					pageIndex = intCurrentPage - ( intRecordsPerPage + 1 );
				}
		  		newLink.setAttribute('href','javascript:' + functionName + '(' + pageIndex + ')');
		  		var linkText = document.createTextNode( "<<" );
		  		newLink.setAttribute('title', ( 'Previous ' + recordsPerPage ));
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
			// previous page link
			if( currentPage > 1 ){
				var newLink = document.createElement('a');
		  		newLink.setAttribute('href','javascript:' + functionName + '(' + ( intCurrentPage - 1 ) + ')');
		  		var linkText = document.createTextNode( "<" );
		  		newLink.setAttribute('title', ( 'Previous Page' ));
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
			
			for ( l = 1; l <= newPageCount; l++ ) {
				if( ( l >= start ) && ( l <= end ) ) {
					// only add pages we want to see
					if( l != currentPage ){
						var newLink = document.createElement('a');
				  		newLink.setAttribute('href','javascript:' + functionName + '(' + l + ')');
				  		var linkText = document.createTextNode( l );
				  		newLink.setAttribute('title', ( 'Page ' + l ));
				  		newLink.appendChild( linkText );
						newTD.appendChild( newLink );
					} else {
						var noLinkText = document.createTextNode( l );
						newTD.appendChild( noLinkText );
					}
					// add a little gap
					var gapText = document.createTextNode( ' ' );
					newTD.appendChild( gapText );
				}
			}
			// next page link
			if( currentPage < newPageCount ){
				var newLink = document.createElement('a');
		  		newLink.setAttribute('href','javascript:' + functionName + '(' + ( intCurrentPage + 1 ) + ')');
		  		var linkText = document.createTextNode( ">" );
		  		newLink.setAttribute('title', ( 'Next Page' ));
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
			// add next x links
			if(  newPageCount > currentPage ){
				if( ( intCurrentPage + ( intRecordsPerPage + 1 ) ) > newPageCount) {
					pageIndex = newPageCount;
				} else {
					pageIndex = intCurrentPage + ( intRecordsPerPage + 1 );
				}
				var newLink = document.createElement('a');
		  		newLink.setAttribute('href','javascript:' + functionName + '(' + pageIndex + ')');
		  		var linkText = document.createTextNode( ">>" );
		  		newLink.setAttribute('title', ( 'Next ' + intRecordsPerPage ));
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
			// last record
			if( currentPage < newPageCount ){
				var newLink = document.createElement('a');
				newLink.setAttribute('href','javascript:' + functionName + '(' + newPageCount + ')');
		  		var linkText = document.createTextNode( ">|" );
		  		newLink.setAttribute('title', ( 'Last Page (' + newPageCount + ')'));
		  		newLink.appendChild( linkText );
				newTD.appendChild( newLink );
				var gapText = document.createTextNode( '  ' );
				newTD.appendChild( gapText );
			}
		}
	
		newTR.appendChild( newTD );
		
		return newTR;
	
	}
	
	
