		function checkIfEmpty( fieldValue, span )
		{
			var span = document.getElementById(span);
			
			if( fieldValue != "" ) /* If there is a value, show the tick image .... */
			{
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"Field filled in correctly!\">";
				return true;
			}
			else /* If there is no value, show a warning message ... */
			{
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"Field MUST be filled in!\">";
				return false;
			}	
		}	
		
		
		function warnIfEmpty( fieldValue, span )
		{
			var span = document.getElementById(span);
			
			if( fieldValue == "" ) /* If there is a value, show the tick image .... */
			{
				span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"Are you sure you wanted to leave this field blank?\">";
			}
			else /* If there is no value, show a warning message ... */
			{
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"Field filled in correctly!\">";		
			}	
		}	

		
		function checkIfSelectNull( fieldValue, span )
		{
			//alert("This is being called!");
			var span = document.getElementById(span);
			
			if( fieldValue != "" ) /* If there is a value, show the tick image .... */
			{
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"Option selected successfully!\">";
			}
			else /* If there is no value, show a warning message ... */
			{
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"You MUST choose an option!\">";		
			}	
		}	
		
		
		function checkIsPostcode ( fieldValue, span, notBlankFlag )
		{
			//alert("This has been called!"); 
				
			var span = document.getElementById(span);
			var regExpUKPostcode = /^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1}(\s){0,1}[0-9][A-Za-z]{2}$/;
			
			// the notBlankFlag is used to specify whether or not you want the function to stop the user from entering nothing
			// This may sound like a case you would not expect to come accross but your application may require this option
			// If notBlankFlag is set to 1 it will not allow the user to leave the password fields blank
			
			if ( (notBlankFlag == 1) && (regExpUKPostcode.test(fieldValue) == false) ) 
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid UK postcode!\">";
			}
			else if ( (notBlankFlag == 0) && (!(fieldValue == "")) && (regExpUKPostcode.test(fieldValue) == false) ) 
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid UK postcode!\">";
			}
			else if ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
					span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"It is recommended that you insert a postcode for contact purposes.\">";
			}
			else
			{
				   span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct postcode format, please continue!\">";
			}
		}
		
		function checkIsTelephone ( fieldValue, span, notBlankFlag )
		{
				//alert("This has been called!"); 
				
				var span = document.getElementById(span);
				//var regExpUKTel = /^(\()?[0-9]{2}(\))?(\s)?[0-9]{9}$/;
				var regExpUKTel = /^(\()?[0-9]{2}(\))?(\s)?[0-9]{9}$|^(\()?[0-9]{3}(\))?(\s)?[0-9]{4}(\s)?[0-9]{4}$|^(\()?[0-9]{4}(\))?(\s)?[0-9]{3}(\s)?[0-9]{4}$|^(\()?[0-9]{5}(\))?(\s)?[0-9]{6}$/;
				//var regExpUKTel = /^[0-9]{4}(\s)?[0-9]{7}$|^\([0-9]{2,5}\)(\s)?[0-9]{6,9}$/;
				
				// the notBlankFlag is used to specify whether or not you want the function to stop the user from entering nothing
				// This may sound like a case you would not expect to come accross but your application may require this option
				// If notBlankFlag is set to 1 it will not allow the user to leave telephone fields blank
				
				if ( (notBlankFlag == 1) && (regExpUKTel.test(fieldValue) == false) ) 
				{
						span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid UK telephone number!\">";
				}
				else if ( (notBlankFlag == 0) && (!(fieldValue == "")) && (regExpUKTel.test(fieldValue) == false) ) 
				{
						span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid UK telephone number!\">";
				}
				else if ( (notBlankFlag == 0) && (fieldValue == "") ) 
				{
						span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"It is recommended that you insert a telephone number for contact purposes.\">";
				}
				else
				{
					   span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct telephone number format, please continue!\">";
				}

		}			 
				
		function checkIsEmail ( fieldValue, span, notBlankFlag )
		{
			//alert("This has been called!"); 
		
			var span = document.getElementById(span);
		  	//this variable is the reg expression used for an e-mail address = a@b.c
			var regExpEmail = /^.+\@.+\..+$/ ;
			
			
			if ( (notBlankFlag == 1) && (regExpEmail.test(fieldValue) == false) )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a valid e-mail address\">";
			}
			else if ( (notBlankFlag == 0) && (!(fieldValue == "")) && (regExpEmail.test(fieldValue) == false) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a valid e-mail address\">";
			}
			else if  ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
				   span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"It is recommended that you insert an e-mail address for contact purposes.\">";
			}
			else 
			{
					span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct e-mail address format, please continue!\">";
			}
		}
		
		function checkIsUrl ( fieldValue, span, notBlankFlag )
		{
			//alert("This has been called!"); 
		
			var span = document.getElementById(span);
		  	//this variable is the reg expression used for a URL
			var regExpUrl = /^([0-9a-zA-Z-\_]{2,63})+(\.)+([0-9a-zA-Z-\_]{2,63})+(\.)+([0-9a-zA-Z\.]{2,5})+$|^([0-9a-zA-Z]{2,63})+(\.)+([0-9a-zA-Z\.]{2,5})+$/;
			
			
			if ( (notBlankFlag == 1) && (regExpUrl.test(fieldValue) == false) )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a valid website address\">";
			}
			else if ( (notBlankFlag == 0) && (!(fieldValue == "")) && (regExpUrl.test(fieldValue) == false) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a valid website address\">";
			}
			else if  ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
				   span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"It is recommended that you insert a website address for contact purposes.\">";
			}
			else 
			{
					span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct website address format, please continue!\">";
			}
		}
		
		function checkIsMoney (fieldValue, span, poundsPence, notBlankFlag) {
			//alert("This has been called!"); 
		
			var span = document.getElementById(span);
		  	//the variables below are reg expressions for pounds and pence
			var regExpPounds = /^[0-9]{1,9}$/;
			var regExpPence = /^[0-9]{1,2}$/;
			
			
			if ( (notBlankFlag == 1) && (poundsPence == 'pounds') && (regExpPounds.test(fieldValue) == false) )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a monetary value.\">";
			}
			else if ( (notBlankFlag == 0) && (poundsPence == 'pounds') && (!(fieldValue == "")) && (regExpPounds.test(fieldValue) == false) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a monetary value.\">";
			}
			else if ( (notBlankFlag == 1) && (poundsPence == 'pence') && (regExpPence.test(fieldValue) == false) )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a monetary value.\">";
			}
			else if ( (notBlankFlag == 0) && (poundsPence == 'pence') && (!(fieldValue == "")) && (regExpPence.test(fieldValue) == false) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"Not a monetary value.\">";
			}
			else if  ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
				   span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"This field is blank - please make sure you have intentionally left this field blank.\">";
			}
			else 
			{
					span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct monetary format, please continue!\">";
			}
		
		}
		
		function checkIsNumber (fieldValue, span, notBlankFlag) {
					
			var span = document.getElementById(span);
						
			if ( (notBlankFlag == 1) && ( (isNaN(fieldValue)) || fieldValue == "" ) )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a number.\">";
			}
			else if ( (notBlankFlag == 0) && (!(fieldValue == "")) && (isNaN(fieldValue)) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a number.\">";
			}
			else if ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
				   span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"This field is blank - please make sure you have intentionally left this field blank..\">";
			}
			else 
			{
					span.innerHTML = "<img src=\"images/tick.gif\" title=\"Valid number, please continue!\">";
			}
		
		}
		
		
		function checkIsDate (fieldValue, span, notBlankFlag) {
					
			var span = document.getElementById(span);
			var regExpDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/ ;
						
			if ( (notBlankFlag == 1) && (!(fieldValue == "")) && (regExpDate.test(fieldValue) == false)  )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid date (in the format mm/dd/yyyy).\">";
					return 0;
			}
			else if ( (notBlankFlag == 1) && ( fieldValue == "" )  )
			{
					span.innerHTML = "<img src=\"images/cross.gif\" title=\"You MUST enter a date.\">";
					return 0;
			}
			else if ( (notBlankFlag == 0) && (fieldValue != "") && (regExpDate.test(fieldValue) == true) ) 
			{
				   span.innerHTML = "<img src=\"images/tick.gif\" title=\"Correct Date Format.\">";
				   return 0;
			}
			else if ( (notBlankFlag == 0) && (fieldValue != "") && (regExpDate.test(fieldValue) == false) ) 
			{
				   span.innerHTML = "<img src=\"images/cross.gif\" title=\"You have not entered a valid date (in the format mm/dd/yyyy).\">";
				   return 0;
			}
			else if ( (notBlankFlag == 0) && (fieldValue == "") ) 
			{
				   span.innerHTML = "<img src=\"images/exclamation.gif\" alt=\"!\" title=\"This field is blank - please make sure you have intentionally left this field blank..\">";
				   return 2;
			}
			else 
			{
					return 1;
			}
		
		}
		
		
		
		
		
		function checkIfPasswordMatch ( password1, password2, span, minChar, maxChar, notBlankFlag ) {
		
			//alert("This is being called!");
			var span = document.getElementById(span);
			
			// the notBlankFlag is used to specify whether or not you want the function to stop the user from entering nothing
			// This may sound like a case you would not expect to come accross but your application may require this option
			// If notBlankFlag is set to 1 it will not allow the user to leave the password fields blank
			
			//minChar is the minimum amount of chars the password can have
			//maxChar is the maximum amount of chars the password can have
			
			if( (password1 == password2) && (password1 == "") && (password2 == "") && (notBlankFlag == 1)  ) 
			/* If there is a match but no value and the notBlankFlag is 1 then we must tell them they must enter a password .... */
			{
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"You must enter a password!\">";
			}
			else if( (password1 == password2) && (password1 == "") && (password2 == "") && (notBlankFlag == 0) ) 
			/* If there is a match but no value and the notBlankFlag is 0 then we must warn them that the password won't be reset .... */
			{
				span.innerHTML = "<img src=\"images/exclamation.gif\" title=\"Password will NOT be reset if fields are left blank!\">";
			}
			else if(  (password1 == password2) && ( (!(password1.length >= minChar)) || (!(password1.length <= maxChar)) )  ) 
			/* If there is a password match but the password doesn't meet the min and max char requirements so we must tell them! */
			{
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"Passwords must contain at least 6 characters and no more than 12 characters.\">";
			}
			else if ( !(password1 == password2) )
			/* If there is not a password match, show a warning message ... */
			{
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"Passwords entered DO NOT match!\">";		
			}
			else
			/* If there is a match and the password meets the min and max char requirements then we can tell them all is ok!*/
			{
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"Passwords match, please continue.\">";
			}	
		
		}
		
		function memberCheck (fieldValue, fieldsetId, correspondingSpan ) {
			//just a test to check function was called
			//alert("This function is being called");
			
			var fieldset = document.getElementById(fieldsetId);
			var correspondingSpan = document.getElementById(correspondingSpan);
			
			 if ( fieldValue == 0 ) {
					correspondingSpan.innerHTML = "<img src=\"images/tick.gif\" title=\"No subscription date needs to be set because the company is not selected as a member.\">";
					//fieldset.style.display = "none";
					return false;
			}
		
			else {
				correspondingSpan.innerHTML = "";
				fieldset.style.display = "block";
				return true;
			}
			
		}
		
		function checkSubDate( fieldValue, span ) {
		
			//alert("checkSubDate()");
		
			var span = document.getElementById(span);
			var membershipStatusFieldValue = document.forms['newcompany'].membership_status.value;
			//alert("membershipStatusFieldValue = " + membershipStatusFieldValue);
			var memberFlag = "";
			if (membershipStatusFieldValue == 1) { memberFlag = true; } else { memberFlag = false; }
			//alert("memberFlag = " + memberFlag);
			var dayFieldValue = document.forms['newcompany'].subscription_expiry_day.value;
			var monthFieldValue = document.forms['newcompany'].subscription_expiry_month.value;
			var yearFieldValue = document.forms['newcompany'].subscription_expiry_year.value;
						
			if ( memberFlag == false ) {
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"No subscription date needs to be set because the company is not  selected as a member.\">";
			}
			else if (  (memberFlag == true) && (dayFieldValue != "") && (monthFieldValue != "") && (yearFieldValue != "")  ) {
				span.innerHTML = "<img src=\"images/tick.gif\" title=\"Subscription date set correctly.\">";
			}
			else {
				span.innerHTML = "<img src=\"images/cross.gif\" title=\"Subscription date needs to be set correctly because the company is selected as a member.\">";
			}
		
		}
		
			
		
		
		function checkBeforeSubmit ( form ) {	
				//alert("This has been called!");
								
				// Iterate through all the form elements
				for( i = 0 ; i < form.length ; i++ )
				{
					// Don't perform any actions on the submit button 
					if( form.elements[i].type != "submit" ) 
					{
						var input = form.elements[i]; // Get a handle on the input field
						var spanID = input.name + "_msg"; // Create span ID string
										
						// check that this element has a corresponding span tag
						if( document.getElementById(spanID) )
						{
							var span = document.getElementById(spanID) // Get a handle on the span tag
							var matchTxt = span.innerHTML.match( "tick.gif" ); // match "tick.gif"
							var matchTxt2 = span.innerHTML.match( "exclamation.gif" ); // match "exclamation.gif"
							var matchTxt3 = span.innerHTML.match( "cross.gif" ); // match "cross.gif"
							
							// check for a tick or exclamation, if there is no tick or exclamation then show the error and return false
							if( (matchTxt != "tick.gif") && (matchTxt2 != "exclamation.gif") )
							{
								// Alert the user that there's an error on the form
								alert( " There are errors on the form, please check your input and re-submit!" );
								// Set the focus on the input field responsible
								input.focus();
								// return false to stop the form submitting
								return false;
							}		
						}				
					}
				}
			} // close: function checkBeforeSubmit ( form ) 
			
			
			
			function checkBeforeSubmit2 ( form ) {	
				//alert("This has been called!");
								
				// Set the variable which will hold with true / false flag for validation
				var validationFlag = false;				
								
				// Iterate through all the form elements
				for( i = 0 ; i < form.length ; i++ )
				{					
					// Don't perform any actions on the submit button 
					if( form.elements[i].type != "submit" ) 
					{
						var input = form.elements[i]; // Get a handle on the input field
						var spanID = input.getAttribute('name') + "_msg"; // Create span ID string
										
						// check that this element has a corresponding span tag
						if( document.getElementById(spanID) )
						{
							var inputName = input.getAttribute('name');
							var inputValue = input.value;
							//alert(inputName);
							if ( inputValue == null )
							{
								var inputValue = "";
							}

							//alert(inputValue);
												
							
							//alert("Start");
							inputValidationMethodCall = new String( input.getAttribute('onBlur') );
							//alert(inputValidationMethodCall);
							inputValidationMethodCall = inputValidationMethodCall.replace("this.value", "'" + inputValue + "'");
							//alert(inputValidationMethodCall);
							inputValidationMethodCall = inputValidationMethodCall.replace("this.name + '_msg'", '"' + inputName + '_msg"');
							//alert(inputValidationMethodCall);
							//alert("End");
							
							eval(inputValidationMethodCall);
							
							var span = document.getElementById(spanID);
							var matchTxt = span.innerHTML.match( "tick.gif" ); // match "tick.gif"
							var matchTxt2 = span.innerHTML.match( "exclamation.gif" ); // match "exclamation.gif"
							
							// check for a tick or exclamation, if there is no tick or exclamation then show the error and return false
							if( (matchTxt != "tick.gif") && (matchTxt2 != "exclamation.gif") )
							{
								// Alert the user that there's an error on the form
								alert( " There are errors on the form, please check your input and re-submit!" );
								// Set the focus on the input field responsible
								input.focus();
								// return false to stop the form submitting
								return false;
							}		
							
						} // if( document.getElementById(spanID) )
						

					} // if( form.elements[i].type != "submit" ) 
					
				} // for( i = 0 ; i < form.length ; i++ )
								
			} // close: function checkBeforeSubmit2 ( form ) 
