/*
	Validation object
	Written by David Abdul 
	26/04/07
*/
function ConfirmAction() {
	decision = confirm("Are you sure you want to delete this record?");
	if (decision) return true;
	else return false;
}
function validator() {
	// Properties
	this.error = "";
	this.Regex = //;
	this.Result = true;
	this.Error = ""
	
	//Methods
	this.init = init;
	this.loadRegex = loadRegex;
	this.testPattern = testPattern;
	
	function init() {
		//Name fields
		this.loadRegex(/^[a-zA-Z0-9_\s-,]+$/);
		msg = "Name field is invalid.\nOnly letters and spaces are allowed.\n\n";
		this.testPattern(document.getElementById("data[FullName]").value,msg);
		//Date fields
		//this.loadRegex(/^\d{1,2}\/\d{1,2}\/\d{4}$/);
		//msg = "Date field is invalid.\nThe date must be typed in dd/mm/yyyy format.\n\n";
		//this.testPattern(document.getElementById("form[Date]").value,msg);
		//Email fields
		this.loadRegex(/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/);
		msg = "Email field is invalid.\n\n";
		this.testPattern(document.getElementById("data[email]").value,msg);
		//Number fields
		//Check result
		if (this.Result == false) { 
			alert(this.Error);
			this.Error = "";
			this.Result = true;
			return false;
		}
		else return true;
	}
	function loadRegex(pattern) {
		this.Regex = pattern;
	}
	
	function testPattern(string,msg) {
		if (!this.Regex.test(string)) {
			this.Result = false;
			this.Error = this.Error + msg;
		}
	}
}
var validator = new validator();
