/* FORM Object 
 * depends on x.js
 *
 *
 */
function Form() {
  
  this.sFormName;
  this.aFormElements = new Array();
  
  // This function sets the form object
  this.setForm = function(sFormName)
  {
  	this.sFormName = sFormName;
  	switch(typeof(this.sFormName))
  	{
  		case "string":
  			if (document.forms[this.sFormName]) 
  				this.oForm = document.forms[this.sFormName];
  			else 
  			{
  				if (xGetElementById(this.sFormName))
  				this.oForm = xGetElementById(this.sFormName);
  				else
  				{
  					alert('Given form name could not be found');
  					return false;
  				}
  			}
  			break;
  		case "object":
  			this.oForm = this.sFormName;
  			break;  		
  		default:
  			alert('Please initiate the form object with a form name or form object');
  			return false;
  	}
  	
		this.FormElements = this.oForm.elements;
		
		for(i=0; i<this.aFormElements.length; i++)
		{
				this.aFormElements[i] = this.trim(this.aFormElements[i].value);
		}
	}
  
  this.checkEmail = function(sEmail)
	{
		// Trim values
		sEmail = this.trim(sEmail);
		
		var oRegExp	= /^([A-z0-9!#%&'\*+-./=?^_`{|}~])+@(([A-z0-9-])+.)+([A-z0-9]{2,})+$/gi;
		aMatch = oRegExp.exec(sEmail);
		
		
		
		if (aMatch)		
		return (aMatch[0] == sEmail)
		else return false;
	}
	
	this.CheckMaxChars = function(iCharCount, iCharMax)
	{		
		if (iCharCount > iCharMax)
		{
			alert('U mag maximaal ' + iCharMax + ' tekens invoeren.');			
			return false;
		}
	}
	
	this.checkEmpty = function(sVal)
	{
		sVal = this.trim(sVal);
		return (sVal == "");
	}

		
	this.trim = function(s) 
	{
		return s.replace(/^\s+|\s+$/g, "");
	}
	
	
}



