﻿function validateEmailAddresses(userControlPrefix)
{
	var notificationLabelId = userControlPrefix + "_notificationLabel";
	var emailInputId = userControlPrefix + "_emailAddress";

	var emailField = document.getElementById(emailInputId);
	var notificationLabel = document.getElementById(notificationLabelId);
	
	if (!emailField.value)
	{
		if (notificationLabel)
		{
		    notificationLabel.className = "msa-Global-NotificationLabel-Error";		
			notificationLabel.innerText = document.invalidEmailAddressMessage;
		}
		else
		{
			alert(document.invalidEmailAddressMessage);
		}
		return false;
	}
	else
	{
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var addresses = emailField.value.split(";");
		
		for (var i = 0; i < addresses.length; i++)
		{
			if (!filter.test(addresses[i].replace(/^\s+|\s+$/g,"")))
			{
				if (notificationLabel)
				{
				    notificationLabel.className = "msa-Global-NotificationLabel-Error";				    
					notificationLabel.innerText = document.invalidEmailAddressMessage;
				}
				else
				{
					alert(document.invalidEmailAddressMessage);
				}
				return false;
			}
		}
	}
	
	return true;
}
