﻿/*
Mailinglist:
Provides functionality for adding and removing e-mail addreses to the mailinglist.
*/
var MailingList = Class.extend({

	init: function() {
	},

	/*
	AddSubscriber: 
	Add a subscriber to the mailinglist.
	
	Parameters:
		email: login e-mail address.
	*/
	AddSubscriber: function(emailAddress) {
		if (emailAddress == '' || !this.ValidateEmail(emailAddress)) {
			$.modaldialog.error("A valid e-mail address is required.");
		} else {
			jQuery.ajax({
				url: "/?action=subscribe",
				data: { emailAddress: emailAddress },
				type: "POST",
				dataType: "json",
				cache: false,
				success: function(msg) {
					if (msg == "subscription_added") {
						$.modaldialog.success("Thank you for subscribing.");
					} else {
						$.modaldialog.error("Your subscription could not be processed, please try again later.");
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$.modaldialog.error("Your subscription could not be processed, please try again later.");
				}
			});
		}
	},		ValidateEmail: function(emailAddress){  
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
		return emailPattern.test(emailAddress);  
	}  	});
