window.addEvent('domready', function() {
    $('address').setHTML(
        '<a href="' +
        ' mai '.trim() +
        ' lto '.trim() +
        ':' +
        'aschall' +
        '@' +
        'xmission.com' +
        '">' +
        'aschall' +
        '@' +
        'xmission.com' +
        '</a>'
    );

    $('subject').value = 'Example: I love you.';
    $('subject').style.color = '#888';
    $('subject').onfocus = function() {
    	this.style.color = '#333';
    	this.value = '';
    	this.onfocus = function() {};
    };

    $('send').getParent().setHTML('<a href="javascript:send();" id="send"><span>Send note</span></a>');
});

function send() {
	if ($('name').value.length < 1 ||
        $('email').value.length < 1 ||
        $('subject').value.length < 1 ||
        $('body').value.length < 1) {
        createNotify('<p>Please complete all fields before sending.</p>');
    } else if (!$('email').value.test("[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}", "i")) {
    	createNotify('<p>Please use a bona fide email address.</p>');
    } else {
        new Ajax('http://tastic.org/contact/send/', {data: $('form')}).request();
        $('form').reset();
        createNotify('<p>Your message was sent. Thanks!</p>');
    }
}

function createNotify(html) {
    destroyNotify();
	new Element('div', {
		'id': 'notify'
    }).injectBefore($$('fieldset')[0]);
    $('notify').setHTML(html + '<a class="close" href="javascript:destroyNotify();">Close</a>');
}


function destroyNotify() {
	if($('notify')) {
        $('notify').remove();
    }
}
