// Global Ajax request
	var MCajaxReq = new MCAjaxRequest();

	// Add a new email address on the server using Ajax
	function getInterestGroups(){
		var iginputs = document.getElementById('mciginputs');
		if(iginputs){
			if(iginputs.getElementsByTagName('input').length){
				var inputs = iginputs.getElementsByTagName('input'); 	// radio or checkbox
			} else {
				var inputs = iginputs.getElementsByTagName('option'); 	// select list
			}
			if(inputs){
				var ig_values = "";
				for (var i=0; i < inputs.length; i++) {
 					// checked for radio or checkbox, selected for select list
					if (inputs[i].checked || inputs[i].selected) { 
					      ig_values = ig_values + inputs[i].value + ",";
	      				}
				}
			}
		}
		return(ig_values);
	}	// end of getInterestGroups

	function addEmailAddress() {

		// check email address for validity against big, nasty regular expression
		var regex = /^[\w\.-_\+]+@[\w-]+(\.\w{2,3})+$/;

		if(!regex.test(document.getElementById("email").value)){
			document.getElementById("status").innerHTML = "Invalid email address";
			return;
		}

		// Disable the Add button and set the status to busy
		document.getElementById("add").disabled = true;
		document.getElementById("status").innerHTML = "<img src='includes/mailchimp/busy.gif' width='16' height='16' border='0' /> Requesting";

		// Send the new email entry and our module id data as an Ajax request
		postvars = "ajax=true" + "&mid=22" + "&email=" + document.getElementById("email").value;
		var mergeVarInputs = document.getElementById('mcmergevars');
		mvinputs = mergeVarInputs.getElementsByTagName('input');
		maxj = mvinputs.length;
		for(j=0; j < maxj; j++){
			if(mvinputs[j].value){
				postvars = postvars + "&" + mvinputs[j].getAttribute('name') + 
					"=" + mvinputs[j].value;
			}

		}
		
		//i_groups = getInterestGroups();
		//if(i_groups.length){
		//	postvars = postvars + "&ig=" + i_groups;
		//}
		MCajaxReq.send("POST", "includes/mailchimp/send_to_mc.php", handleRequest, "application/x-www-form-urlencoded; charset=UTF-8", postvars);

	}	// end of addEmailAddress

	// Handle the Ajax request
	function handleRequest() {
		if (MCajaxReq.getReadyState() == 4 && MCajaxReq.getStatus() == 200) {
			// Confirm the addition of the email entry
			document.getElementById("status").innerHTML = MCajaxReq.getResponseText();
			document.getElementById("add").disabled = false;
			document.getElementById("email").value = "";
			/* need to clear checkboxes, etc */
		}
	}