jQuery(document).ready(function($){
	var ar_el = new Array('#news-email');
	for(i=0;i<ar_el.length;i++) {
		$(ar_el[i]).val( $(ar_el[i]).attr("title") );
	}
	$('input').focus(function(){
		if($(this).attr("title")) {
			title = $(this).attr("title");
			val = $(this).val();
			if(title==val) $(this).val("")
		}
	});

	$('input').blur(function(){
		if($(this).attr("title")) {
			title = $(this).attr("title");
			val = $(this).val();
			if(val=='') $(this).val(title)
		}
	});

	$("#news-submit").click(function(){
		$("#news-message").show();
                                           var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var email = $("#news-email").val();

		if(email == '') {
			$("#news-message").html('<span class="error" style="color:#D70D13">Please enter a valid email address</span>').show();
			hasError = true;
		} else if(!emailReg.test(email)) {
			$("#news-message").html('<span class="error" style="color:#D70D13">Please enter a valid email address</span>').show();
			hasError = true;
		}
		
		if(hasError == false) {
			$("#news-message").html('<img src="images/indicator.gif" alt="Loading" id="loading">').show();
			
			// If needed, you can replace sendmail.php with your own script which you want to submit the form details to
			$.post("/libraries/news-submit.php",
{ emailFrom: email },
   					function(data){
						//$("#loading").fadeOut("normal", function() {			   							
							$("#news-message").html("Thank you. Your name has been added to our mailing list.");											
						//});
   					}
				 );
		}


		return false;
	});
});


