//alert('moofer')
	String.prototype.padRight = function(length) {
		if (this.length < length) {
			return this + '                                                       '.substring(0, (length - this.length));
		} else {
			return this;
		}
	}
		
	function SortedValidator (formName) {
		this.init(formName);
	}
			
	SortedValidator.prototype = {
		init: function (formName) {
			this.defaultErrorStyle = 'border: 1px solid #000; background-color: #fff;';
			this.defaultValidStyle = 'border: 1px solid #000; background-color: #fff;';
			this.isValid = false;
			if (formName) {
				this.formName = formName;
			}
			this._form = document.forms[this.formName];
			if (this._form) {
				this.readForm();
			}
		},
						
		getForm: function () {
			return this._form;
		},
				
		readForm: function () {
			this.inputs = {};
			for (var i = 0; i < this.getForm().elements.length; i++) {
				var el = this.getForm().elements[i];
				if (el.tagName != 'BUTTON' && el.getAttribute('type') != 'submit') {
					var value = el.value;
					var parameter = el.getAttribute('parameter');
					var validation = el.getAttribute('validation');
					var errorMessage = el.getAttribute('error-message');
					var errorStyle = el.getAttribute('error-style');
					var validStyle = el.getAttribute('valid-style');
					var errorMessage = (errorMessage) ? errorMessage : this.defaultMessages[validation];
					if (validation) {
						this.inputs[el.getAttribute('name')] = {
							element: el,
							value: value,
							parameter: parameter,
							validation: validation,
							validationMethod: this.validators[validation],
							isValid: false,
							errorMessage: errorMessage,
							errorStyle: (errorStyle) ? errorStyle : this.defaultErrorStyle,
							validStyle: (validStyle) ? validStyle : this.defaultValidStyle
						};
					}
				}
			}
		},
				
		validate: function () {
			this.isValid = true;
			for (var inputName in this.inputs) {
				var input = this.inputs[inputName];
				input.isValid = input.validationMethod(input.value, input.parameter);
				if (!input.isValid) {
					this.isValid = false;
				}
			}
			return this.isValid;
		},
		
		getErrorMessages: function () {
			if (!this.isValid) {
				var message = '';
				for (var inputName in this.inputs) {
					var input = this.inputs[inputName];
					if (!input.isValid) {
						//message += inputName.replace('_', ' ').padRight(14);
						//message += ': ';
						message += input.errorMessage.replace('{parm}', input.parameter).replace('{text}', input.value);
						message += '\n';
					}
				}
				return message;
			} else {
				return null;
			}
		},
		
		colourise: function () {
			for (var inputName in this.inputs) {
				var input = this.inputs[inputName];
				var styleSpec = (input.isValid) ? input.validStyle : input.errorStyle;
				if (document.all) { // switch for IE
					input.element.style.cssText = styleSpec;
				} else {
					input.element.setAttribute('style', styleSpec);
				}
			}
		},
				
		inputs: {},
				
		validators: {
					
			regex: function (text, parm) {
				return text.match(parm);
			},
					
			hasValue: function (text) {
				return (text) ? true : false;
			},
					
			contains: function (text, parm) {
				return (text.indexOf(parm) != -1) ? true : false;
			},
					
			equals: function (text, parm) {
				return (text == parm);
			},
					
			not: function (text, parm) {
				return (text != parm);
			},
					
			email: function (text) {
				return text.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
			}
					
		},
				
		defaultMessages: {
			regex: 'The input provided does not match the necessary pattern,',
			hasValue: 'The input must have a value provided.',
			contains: 'The input provided does not contain \'{parm}\'.',
			equals: 'The input privoded must equal \'{parm}\'.',
			not: 'The input provided must not equal \'{parm}\'.',
			email: 'The address \'{text}\' is not a valid e-mail address.'
		}				
				
	}
			
	/*window.onload = function () {
		var v = new SortedValidator('testForm');
		v.validate();
		v.colourise();
		if (!v.isValid) {
			alert(v.getErrorMessages());
		}
	}
		
		<form name="testForm" action="SuperValidator.asp">
			<input type="text" name="first_name" value="" 
				validation="hasValue" 
				error-message="OOPS!" 
			/>
			<br />
			<input type="text" name="surname"
				validation="hasValue" 
			/>
			<br />
			<input type="text" name="middle_name" value="Max" 
				validation="contains" 
				parameter="Jo" 
				error-style="border-color: blue; border-width: 1px; border-style: solid" 
			/>
			<br />
			<input type="text" name="email" value="guy_sortedsites.com" 
				validation="email" 
			/>
			<br />
			<select name="status"
				validation="equals"
				parameter="unset"
				error-message="You must select a status"
				error-style="background-color: red; color: white"
			>
				<option value="unset">unset</option>
				<option value="one">one</option>
				<option value="two">two</option>
				<option value="three">three</option>
			</select>
			<br />
			<button type="submit">submit</button>
		</form>
		
		
		
		
		<script src="scripts/validator.js" language="javascript" type="text/javascript"></script>
		<!-- InstanceEndEditable -->
		<!-- InstanceBeginEditable name="head" -->
		<script language="javascript" type="text/javascript">
			function validateForm (form) {
				var v = new SortedValidator(form.getAttribute('name'));
				v.validate();
				v.colourise();
				if (!v.isValid) {
					alert(v.getErrorMessages());
				}
				return v.isValid;
			}
		</script>
		
<form action="property-finder-process.asp" method="post" name="propertyfinder" enctype="multipart/form-data" onSubmit="return validateForm(this)">


						<select name="bedrooms" 
							class="formfield"
							error-message="You must select a minimum value for Bedrooms"
							error-style="background-color: red; color: white;"
							validation="hasValue">

*/