var mooValidate = new Class({
	
	initialize: function () {
		
		this.ecount = 0;
		
	},
	
	vLength: function (id, len, message, operator) {
		
		if ($(id).getValue().length > len && operator == "gt") {
			
			this.removeError(id);
			
		} else if ($(id).getValue().length < len && operator == "lt") {
			
			this.removeError(id);
			
		} else if($(id).getValue().length >= len && operator == "gte") {
			
			this.removeError(id);
				
		} else if($(id).getValue().length <= len && operator == "lte") {
			
			this.removeError(id);
			
		} else if($(id).getValue().length == len && operator == "eq") {
			
			this.removeError(id);
			
		} else {
			
			this.printError(id, message);
			
		}
		
	},
	
	vState: function(message) {
		
		if ($('state').getValue().length == 2)
		{
			
			this.removeError('state');
			
		} else {
			
			this.printError('state', message);
			
		}
		
	},
	
	vEmail: function(message) {
		
		if ($('email').getValue().match(/(.)+@(.)+\.(.)+$/))
		{
			
			this.removeError('email');
			
		} else {
			
			this.printError('email', message);

		}
		
	},
	
	vNumah: function(message) {
		
		if ($('numah').getValue().match(/(.)+@(.)+\.(.)+$/))
		{
			
			this.removeError('numah');
			
		} else {
			
			this.printError('numah', message);

		}
		
	},
	
	vPhone: function(message) {
		
		if ($("phone").getValue().match(/^1?[0-9]{10}$/))
		{
			
			this.removeError('phone');
			
		} else {
			
			this.printError('phone', message);
		
		}
		
	},
	
	vFax: function(message) {
		
		if ($('fax').value.length > 0)
		{
			if (!$("fax").getValue().match(/^1?[0-9]{10}$/))
			{
				
				this.removeError('fax');
			
			} else {
			
				this.printError('fax', message);
				
			}
		}
		
	},
	
	vZip: function(message) {
		
		if ($('zip').getValue().match(/^[1-9][0-9]{4}$/))
		{
			
			this.removeError('zip');
			
		} else {
			
			this.printError('zip', message);
			
		}
		
	},
	
	formSubmit: function(e) {
			
		if (this.ecount > 0) {
				
			alert("All errors must be corrected before the form can be submitted.");
			
			new Event(e).stop();
			
		}
		
	},
	
	printError: function(ele_id, message) {
		
		if ($(ele_id+"_error").hasClass("error") == false) {
			
			$(ele_id+"_error").addClass('error');
			$(ele_id+"_error").setText(message);
			this.ecount += 1;
			
		}
		
	},
	
	removeError: function(ele_id) {
		
		if ($(ele_id+"_error").hasClass("error") == true) {
			
			$(ele_id+"_error").removeClass('error');
			$(ele_id+"_error").setText("");
			this.ecount -= 1;
			
		}
		
	}
	
});