//// Copyright © 2003 Abacus Arts, Inc. All rights reserved.

// Distribution list subscription routines. Requires modified version for FormMail.

// 2/25/06 - Modifed to use MailEnable, which requires sending listserv commands to each list address, not a central address.

function setAction (form) {
	var domain = "@theatreknoxville.com"

for (var i=0; i<form.action.length; i++) {
		if (form.action[i].checked) {
			break
		}
	}
	var chosenAction = form.action[i].value

	for (var i=0; i<form.listname.length; i++) {
		if (form.listname[i].checked) {
			break
		}
	}

	var chosenList = form.listname[i].value

	var user = form.fullname.value
	
    switch (chosenAction) {
        case "sub":
            form.subject.value = "subscribe";
            form.msgbody.value = "subscribe " + chosenList + " " + user;
            form.recipient.value = chosenList + domain;
            break

        case "unsub":
            form.subject.value = "unsubscribe";
            form.msgbody.value = "unsubscribe " + chosenList;
            form.recipient.value = chosenList + domain;
            break      
    }
		// Check to be sure the address being added to the list does not match the listname, which causes an infinite loop of confirmation messages.

	if (form.email.value == form.recipient.value) {
		alert('Error: The email address you entered matches the name of the list you are trying to join.\n\nYour subscription attempt has been blocked and the webmaster has been notified.');
            form.subject.value = "subscribe";
            form.msgbody.value = "Subscription attempt blocked for list: " + chosenList + ". Attempted by: " + user;
            form.recipient.value = "webmaster" + domain;
		}
}

