$(document).ready(function(){
	$('form#enewsForm .submit-enews').click(function(){
		
		$("#processing").show();
		$('#enewsForm .error').hide();	//if error visibile, hide on new click		
		
		var email_test = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		var email = $('input#email').val();
		if (email == "" || email == " ") {
			$("#processing").hide();
			$('div.enews-form-container').removeClass('errorBlack')
			$("#errorMsg-enews").fadeIn('slow', function() {
				$('div.error').html('<p><em>Please enter in an email address.</em></p>');
				$('#email-label-enews').addClass('errorBlack');
			});
		   return false;
		} else if (!email_test.test(email)) {
		   $("#processing").hide();
			$('div.enews-form-container').removeClass('errorBlack')
			$("#errorMsg-enews").fadeIn('slow', function() {
				$('div.error').html('<p><em>Please double check the email address you entered...</em></p>');
				$('#email-label-enews').addClass('errorBlack');
			});
		   return false;
		}
		
		var data_string = $('form#enewsForm').serialize();

		$.ajax({
		    type: "POST",
		    url: "enews-process.php",
		    data: data_string,
		    success: function() {
				$('#errorMsg-enews').hide('slow');
				$('div.enews-form-container').removeClass('errorBlack')
				$("#processing").hide();
		   		$('#successMsg-enews').slideDown('slow', function(){
					// then clear out the form fields
					$('#enewsForm').get(0).reset(); 				
				});
		    }//end success function

		}) //end ajax call

		return false;

	}) //end click function
		
	var current_data = new Array();

	$('.clear-form').each(function(i){
		$(this).removeClass('clear-form').addClass('clear-form'+i);
		current_data.push($(this).val());

		$(this).focus(function(){
			if($(this).val() == current_data[i]) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			var stored_data = current_data[i];
			if($(this).val()==''){
				$(this).val(stored_data);
			}
		})
	});
})
