document.observe("dom:loaded", function()	{
	var email_text = $('notification_email');
	if (email_text)	{
		email_text.observe('focus', clear_text);
		email_text.observe('keypress', function(e)	{
			var key = e.which || e.keyCode;
			if (key == Event.KEY_RETURN)
				save_email(e);
		});
	}
	if ($('cmd_save_email'))
		$('cmd_save_email').observe('click', save_email);
});

function clear_text(e)	{
	var element = Event.element(e);
	element.stopObserving('focus');
	element.value = "";
}

function save_email(e)	{
	Event.stop(e);
	var node = $('cmd_save_email');
	var email = $('notification_email');
	if (email)
		email = email.value;
	new Ajax.Request(node.href, {
		method: "post",
		postBody: "email=" + email,
		onComplete: function(response)	{
			var r = response.responseText.evalJSON(true);
			var h = $('notification_response');
			h.update(r.message);
			h.show();
			if (r.success) $('notification_email').value = "";
		}
	});
}