$(document).ready(function() { //error message already hidden by validate.js

$('#mailinglistsubmit').click(function() { 

for (var i=0; i < document.ajaxradioform.myradio.length; i++)
   {
   if (document.ajaxradioform.myradio[i].checked)
      {
      var radiovalue = document.ajaxradioform.myradio[i].value; //gets radiovalue (either 'subscribe' or 'unsubscribe')
      }
   }


var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	var mailinglistemail = $("#mailinglistemail").val();  
if ((!mailinglistemail) || (!mailinglistemail.match(emailExp))){//if no email or invalid return false
$("#mailinglist_error").fadeIn(500);  
return false;
}


document.getElementById('mailinglistsubmit').disabled=true; //disable the button
var t=setTimeout("document.getElementById('mailinglistsubmit').disabled=false", 5000);// re-enable the button after 5 seconds


var dataString = 'mailinglistemail='+ mailinglistemail + '&radiovalue=' + radiovalue;
$.ajax({
		type: "POST",
		url: "processmailinglist.php", 
		data: dataString,
		cache: false,
		success: function(html){

$("#mailinglist_error").fadeOut(500);  
$("#mailinglistmessage").fadeIn(1000);

$("#mailinglistmessage").append(html);// the placement
$("#themessage").fadeIn("slow");// comes from the php

$('#mailinglistemail').focus(function() {//if you focus on the field the message fades out, as does any errors
$("#mailinglistmessage").fadeOut(1000);
$('#mailinglistmessage').empty(); //empty the div so you dont get messages  on top of one another
});




}//html function
});//ajax
return false;
});//click function
});//doc ready






