/**
 * Validator class
 * @id Validator
 * @classDescription Contains varius validation rutines and helpers
 * @version 0.1
 * @author Jon Ege Ronnenberg
 */ 
function Validator(){
	/**
	 * Returns true if the data was an email address
	 * @method [EmailAddress]
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.EmailAddress = function(data){
		// convert data to string
		var test = this.Trim(String(data));
		// Find an email address
		var reg = new RegExp("[\\w\\-]+(\\.[\\w\\-]+)*@[\\w\\-]+(\\.[\\w\\-]+)*\\.[A-Za-z]+");
		// returns true if the data was an email address
		return reg.test(test.toLowerCase()) ? true : false; 
	};
	/**
	 * Returns true if only letters was found 
	 * (including space, accent and acute accent + some other chars)
	 * @method [OnlyChars]
	 * @param {String} data
	 * @return {Bool}
	 */	
	this.OnlyChars = function(data){
		// convert data to string
		var test = this.Trim(String(data));
		// don't find chars
		var reg = new RegExp("[^a-zæøåA-ZÆØÅ 'áíñëâôà]");
		// Returns true if only letters was found (including space, accent and acute accent + some other chars)
		return reg.test(test) ? false : true;
	};
	/**
	 * Returns true if only numbers was found
	 * @method OnlyNumbers
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.OnlyNumbers = function(data){
		// convert data to string
		var test = this.Trim(String(data));
		// don't find numbers
		var reg = new RegExp("[^0-9]");
		// returns true if only numbers was found
		return reg.test(test) ? false : true;
	};
	/**
	 * Returns true if data is only numbers and its length is equal to 4
	 * @method DanishZipCode
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.DanishZipCode = function(data){
		// convert data to string
		var test = this.Trim(String(data));
		if(this.OnlyNumbers(test) && test.length == 4){
			return true;
		} else {
			return false;
		}
	};
	/**
	 * Removes whitespace from the left of a string
	 * @method LeftTrim
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.LeftTrim = function(data){
		// convert data to string
		var string = String(data);
		while (string.substring(0,1) == ' ')
		{
			string = string.substring(1, string.length);
		}
		return string;
	};
	/**
	 * Removes whitespace from the right of a string
	 * @method RightTrim
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.RightTrim = function(data){
		// convert data to string
		var string = String(data);
		while (string.substring(string.length-1, string.length) == ' ')
		{
			string = string.substring(0,string.length-1);
		}
		return string;
	};
	/**
	 * Removes whitespace from both sides of a string
	 * @method Trim
	 * @param {Object} data
	 * @return {Bool}
	 */
	this.Trim = function(string){
		string = this.LeftTrim(string);
		string = this.RightTrim(string);
		return string;
	};
}