// validate function on form submit action
function Validate(form)
{
	if (TitleValidate(form))
	{
		return EventTypesValidate (form);
	}
	else
		return false;
	
}


//regular expression validation function for phone number and ...
function RegExpCheck (obj,pattern,desc)
{
	//var pattern = /\(\d{3}\)\s\d{3}\-\d{4}/;
	//alert ('got here');
	var text = obj.value;
	//alert (text);
	if (text != '')
	{
		var result = pattern.exec(text);
		//alert (result);
		if (result == null || result == '')
		{
			alert ("Wrong format, should be " + desc);
			if(document.all) {
				obj.select();
				obj.focus();
			}
		}
     }
}

//--------------------------------------------------------------------	
/*	Explanations:
		The regular expression does the following: it wants to scan the entire value from the beginning of the line (^) to its end ($):
			/^ [stuff] $/
		The address should start with a bunch of alphanumerical (letters or numbers), underscores, dots or dashes. This is the user name.
			([a-zA-Z0-9_\.\-])+
		Then comes an @.
			\@
		After that comes the domain name, which may include several sub-domains (mail.international.company.).
		Therefore we now allow several series of alphanumerical characters and dashes, followed by a dot.
			(([a-zA-Z0-9\-])+\.)+
		Finally the top level domain, once again we check for alphanumerical characters, but now without the dash
			([a-zA-Z])+		//original version ([a-zA-Z0-9])+
*/
function checkEmailAddress(field, msg)
{
	var x = field.value;
	var z = /^\s+/;
	var y = /\s+$/;
	EmailList = new Array();
	
	if (x != '') 
	{
	
		if (x.indexOf(',') == -1)
		{
		 	EmailList[EmailList.length] = x;
		}
		else 
		{
			i = 0;
			while (x.indexOf(',',i) != -1)
			{
			str = x.substring(i,x.indexOf(',',i));
			str = str.replace(z,"");
			str = str.replace(y,"");
			EmailList[EmailList.length] = str;
			i = x.indexOf(',',i)+1;
			}
			str = x.substring(i,x.length);
			str = str.replace(z,"");
			str = str.replace(y,"");
			EmailList[EmailList.length] = str;	
		}
			
			
		for (i=0;i<EmailList.length;i++)
		{
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
		
			if (!filter.test(EmailList[i])) 
			{
				if (msg != '')
					alert(msg);
				else {
					alert('Invalid email additional address.');			
					}

				field.focus();
				field.select();
				return false;
			}
			
		}
	}
	return true;
}