// $Id$

var enter_address_msg = 'Enter your email address, so we can contact you!';
var redirect_sig = '436f62e10d6ce52d5d9961551845fda08e8ffb61';
var redirect = 'http://glenparkfestival.com/contact-sent.shtml';

var recipients = {
    'entertainment': {
        'description': 'the entertainment coordinator',
        'email': [
          {'address':'music' + '@glenparkfestival.com', 'propername': 'Angela Bennett'}
        ],
        'subject': 'Glen Park Festival Entertainment',
    },
    'raffle': {
        'description': 'the raffle donorship coordinator',
        'email': [
          {'address':'raffle' + '@glenparkfestival.com', 'propername': 'Kara Romanko'}
        ],
        'subject': 'Glen Park Festival donations',
    },
    'food': {
        'description': 'Food &amp; Beverage Coordinators',
        'email': [
          {'address':'food' + '@glenparkfestival.com',
           'propername': 'Carlos Longa and Barry Hooper'}
        ],
        'subject': 'Glen Park Festival vendor',
    },
    'grants': {
        'description': 'Grants Committee',
        'email': [
          {'address':'grants' + '@glenparkfestival.com',
           'propername': 'Grants Committee'}
        ],
        'subject': 'Glen Park Festival grants',
    },
    'vendors': {
        'description': 'Vendor relations',
        'email': [
          {'address':'vendors' + '@glenparkfestival.com',
           'propername': 'Kate Zimman'}
        ],
        'subject': 'Glen Park Festival vendor',
    },
    'shirts': {
        'description': 'T-Shirt sales',
        'email': [
          {'address':'shirts' + '@glenparkfestival.com',
           'propername': 'Kimberlee Dickerson and Carrie Lee'}
        ],
        'subject': 'Glen Park Festival t-shirt sales',
    },
    'sponsorship': {
        'description': 'our sponsorship coordinators',
        'email': [
          {'address':'sponsorship' + '@glenparkfestival.com',
           'propername': 'Petra Dekins'}
        ],
        'subject': 'Glen Park Festival sponsorship',
    },
    'advertising': {
        'description': 'our advertising coordinator',
        'email': [
          {'address':'advertising' + '@glenparkfestival.com',
           'propername': 'Rebecca MurrayMetzger'}
        ],
        'subject': 'Glen Park Festival program advertising',
    },
    'volunteer': {
        'description': 'our volunteer coordinator',
        'email': [
          {'address':'volunteer' + '@glenparkfestival.com',
           'propername': 'Kimberlee Dickerson'},
        ],
        'subject': 'Glen Park Festival volunteering',
    },
    'web': {
        'description': 'website issues',
        'email': [
          {'address':'web' + '@glenparkfestival.com',
           'propername': 'Devin Carraway'}
        ],
        'subject': 'Glen Park Festival website questions',
    },
    'general': {
        'description': 'for Questions and Answers',
        'email': [
          {'address':'inquiries' + '@glenparkfestival.com',
           'propername': 'General Inquiries'}
        ],
        'subject': 'Glen Park Festival questions',
    },
};

function showmail(to) {
    if (! (to in recipients)) {
        alert("Unknown recipient " + to);
        return false;
    }
    maildiv = document.getElementById('maildiv_' + to);
    h = '<div class="mailbox"><h1 class="mailbox">Email ' +
        recipients[to]['description'] + '</h1>' +
        '<form name="mailform_' + to + '"' +
        ' action="http://appengine.glenparkfestival.com/mail/send"' +
               ' method="post" onSubmit="return' +
               ' submit_mailform(this,\'' + to + '\')">' +
        '<input type="hidden" name="whom" value="' + to + '" />' +
        '<input type="hidden" name="redirect"' +
        ' value="' + redirect + '" />' +
        '<input type="hidden" name="redirect_sig"' +
        ' value="' + redirect_sig + '" />' +
        '<p class="mailbox"><label class="mailbox" for="name">To:</label> ';
    for (var i = 0; i < recipients[to]['email'].length; i++) {
        if (i != 0) {
            h += ', ';
        }
        h += '<a name="mailto" href="mailto:' +
             escape(recipients[to]['email'][i]['address']) + '"' +
             ' title="Click to email directly with your usual mailer"' +
             '>' + recipients[to]['email'][i]['propername'] +
             ' &lt;' + recipients[to]['email'][i]['address'] + '&gt;' +
             '</a>';
    }
    h += '</p><p class="mailbox"><label class="mailbox" for="from">From:</label>' +
         '<input type="text" name="from" class="mailbox_from"' +
         ' value="' + enter_address_msg + '"' +
         ' size="40" onFocus="start_address_entry(this)"' +
         ' onBlur="restore_address_entry(this)"' +
         ' /><input type="hidden" name="to" value="' + to + '" />';
    h += '</p><p class="mailbox"><label class="mailbox" for="subject">Subject:</label>' +
         '<input class="mailbox" type="text" size="40" name="subject"' +
         ' value="' + recipients[to]['subject'] + '" /></p>' +
         '<textarea class="mailbox" name="body" rows="20" cols="50">' +
         '</textarea><br clear="all" />' +
         '<input type="submit" value="Send" />' +
         '<input type="button" value="Cancel"' +
           'onClick="hidemail(\'' + to + '\')" />' +
         '</form>' +
         '<p class="mailbox-small">Please feel free to email us directly at the email address' +
         ' shown above if you prefer; this form is just for convenience.' +
         ' We\'ll happily read it either way.' +
         '</p>' +
         '</div>' +
         '';
    recipients[to]['normalhtml'] = maildiv.innerHTML;
    maildiv.innerHTML = h;
    return false;
}

function hidemail(to) {
    if (! (to in recipients))
        return false;
    maildiv = document.getElementById('maildiv_' + to);
    if ('normalhtml' in recipients[to]) {
        maildiv.innerHTML = recipients[to]['normalhtml'];
        delete recipients[to]['normalhtml'];
    }
}

function expose_mailto(loc) {
    var hashre = /^#(\w+)$/;
    if (loc && loc.hash) {
        var match = loc.hash.match(hashre);
        if (match[1] in recipients) {
            showmail(match[1]);
        }
    }
}

function start_address_entry(input) {
    if (input.value == enter_address_msg) {
        input.value = "";
        input.style.color = "black";
    }
}

function restore_address_entry(input) {
    if (input.value == "") {
        input.value = enter_address_msg;
        input.style.color = "#a2a2a2";
    }
}

function submit_mailform(form, to) {
    if (! form.from.value || form.from.value == enter_address_msg) {
        alert("Please enter your own email address, or we won't" +
              " be able to reply.");
        form.from.focus();
        return false;
    }
    // simple & permissive (real validation happens server-side)
    var email_re = /^.+@.+\./;
    var match = form.from.value.match(email_re);
    if (! match) {
        alert("That doesn't look like a valid email address.");
        form.from.focus();
        return false;
    }
	return true;
    var request = new XMLHttpRequest();
    var url = 'http://appengine.glenparkfestival.com/mail/send' +
              '?sender=' + escape(form.from.value) +
              '&to=' + escape(to) +
              '&subject=' + escape(form.subject.value) +
              '&body=' + escape(form.body.value)
    request.open("POST", url, true);
    request.setRequestHeader('Content-Type',
                             'application/x-www-form-urlencoded');
    request.onreadystatechange = function() {
      if (request.readyState == 4 && request.status == 200) {
        json = request.responseText;
        response_obj = eval(json);
        if (response_obj['ok']) {
            alert('sent');
        } else {
            alert('error: ' + json);
        }
      }
    }
    return false;
}
// vi: set ts=4 sw=4 et:

