//// HIM Ajax Lists
function disableElements(){
	var submitBtn = document.getElementById('submit'); 
	submitBtn.disabled = true;
	submitBtn.style.cursor = "auto";
	document.getElementById('sb_email').disabled = true; 		
}

function enableElements(){
	var submitBtn = document.getElementById('submit'); 
	submitBtn.disabled = false;
	submitBtn.style.cursor = "pointer";
	document.getElementById('sb_email').disabled = false; 
}

function startLoad(){
	var result = document.getElementById('result'); 
	var submitBtn = document.getElementById('submit'); 
	disableElements();
	result.style.display = "block";
	result.innerHTML='Validating Email...&nbsp;&nbsp;';
	letsRock();
}
function letsRock()
{
	var result = document.getElementById('result'); 
	var email = document.getElementById("sb_email").value;
	new Ajax.Request('_lists/mailing_list_submit.php',
	  {
		method:'post',
		postBody:'email='+email,
		onSuccess: function(transport){
		  enableElements();
		  var response = transport.responseText || "no response text";
		  result.innerHTML = response;
		},
		onFailure: function(){ alert('Could not connect...') }
	  });		  
}

function clearValue(field) {
	if (field.defaultValue == field.value)
	field.value = "";
} 
/*
this fairly common function allows us to add behavior to pages 
without cluttering up our html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
/* this adds the behaviors to our form */
function initializer() {
var theForm = document.getElementById('subscribe');
	addEvent(theForm, 'submit', startLoad);
	theForm.onsubmit = function() { return false; }
}
addEvent(window, 'load',initializer);