package com.guru.form 
{
	import com.guru.utils.StringUtil;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class FormGroupElement
	{
		private var mElement_array:Array;
		
		public function FormGroupElement()
		{
			mElement_array = new Array();
		}
		
		public function reset():void
		{
			for (var i:Number = 0; i < mElement_array.length; i++ )
			{
				FormTextElement(mElement_array[i][0]).setText("");
				FormTextElement(mElement_array[i][0]).hideError();
			}
		}
		
		public function dispose():void
		{
			while (mElement_array.length > 0)
			{
				mElement_array.shift();
			}
			mElement_array = null;
		}
		
		public function addElement(pFormTextElement:FormTextElement, pIsEmail_bol:Boolean = false):void
		{
			mElement_array.push([pFormTextElement, pIsEmail_bol]);
		}
		
		public function checkFormValidity():Boolean
		{
			var valid_bol:Boolean = true;
			
			for (var i:Number = 0; i < mElement_array.length; i++ )
			{
				if (!mElement_array[i][1])
				{
					//Not Email
					if (FormTextElement(mElement_array[i][0]).checkError())
						valid_bol = false;
				}
				else
				{
					//Is Email
					if (!FormTextElement(mElement_array[i][0]).checkError() && StringUtil.checkEmail(FormTextElement(mElement_array[i][0]).getData()))
					{
						FormTextElement(mElement_array[i][0]).hideError();
					}
					else
					{
						FormTextElement(mElement_array[i][0]).showError();
						valid_bol = false;
					}
				}
			}
			
			return valid_bol;
		}
		
	}

}