// EmailFormatCondition.class.js (Fertile Form JS Framework) || Version: 0.02 || Last Updated: 2011-01-20 10:00 || Updated by: Hidde-Finne Peters || Created: 2010-08-23 by Hidde-Finne Peters
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

var EmailFormatCondition = FormCondition.extend({
	
	init: function (feedbackString, fieldObject) {
		this._super(feedbackString, fieldObject);
	},
	
	//	------------------------------------------------------------------------------------------------------------
	//	--- update -------------------------------------------------------------------------------------------------	0.00
	//	------------------------------------------------------------------------------------------------------------
	//	Methods called to change properties dynamically
	
	//	Reanalyze situation and set property "this.valid" accordingly
	updateValid: function () {
		if (this.isEmailFormat(this.getValue())) {
			this.setValid(true);
			return;
		}
		this._super();
	},
	
	//	------------------------------------------------------------------------------------------------------------
	//	------------------------------------------------------------------------------------------------- update ---
	//	------------------------------------------------------------------------------------------------------------
	
	//	------------------------------------------------------------------------------------------------------------
	//	--- isEmailFormat ------------------------------------------------------------------------------------------	0.00
	//	------------------------------------------------------------------------------------------------------------
	
	isEmailFormat : function (str) {
		//	Empty string is valid (ensures this condition can be applied to fields that do not require values)
		if (str.length < 1) {
			return true;
		}
		//	Check email format with regular expression
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		return reg.test(str);
	}

	//	------------------------------------------------------------------------------------------------------------
	//	------------------------------------------------------------------------------------------ isEmailFormat ---
	//	------------------------------------------------------------------------------------------------------------
	
});


