jQuery(function($) {
  $(".newsletter .submit").click(function(){
		$(this).attr('disabled', 'disabled');
		$(this).css('opacity', 0.5);
		$(this).css('cursor', 'auto');
		$('#status').fadeIn('normal');
		$('#status').html('Sending please wait...');
		

		if(!errors){
			$('#status').fadeOut('normal', 
								function(){$(this).html("<span class='error' style='background:none'>Email field is missing or invalid, please correct and resend.</span>")}).fadeIn();
			
			$(this).removeAttr('disabled');
			$(this).css('opacity', 1);
			$(this).css('cursor', 'pointer');
			
			return;
		}
		
		//get teh link
		queryString = '';
      queryString += 'email='+$('#email').attr('value');
		theLink = "newsletter.php?"+queryString;

		var xhr;
		
		if (window.XMLHttpRequest) {
		  xhr = new XMLHttpRequest();
		}else if (window.ActiveXObject) {
		  xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}else {
		  throw new Error("Ajax is not supported by this browser");
		}
		
		xhr.onreadystatechange = function() {
		  if (xhr.readyState == 4) { 
		    if (xhr.status >= 200 && xhr.status < 300) {
				
			  $('#status').fadeIn('normal', function(){$(this).html(xhr.responseText)});
		      
			  $(this).removeAttr('disabled');
				$(this).css('opacity', 1);
				$(this).css('cursor', 'pointer');
		    }
		  }
		}
		
		xhr.open('GET', theLink);
		xhr.send(null);
	});
});
