/*
 * subscribe.js
 * Copyright (C) 2009
 * Author: Vanity Stuurland <vanity.stuurland@lightmaker.com>
 * Created: 2009-11-25
 */

$(document).ready(function()
{
	//hide the errormessages from the required input fields
	$('.subscribeMessage').hide();
	$(".subscribeSubmitBtn").click(function(event)
	{
				
			//for matching email and phone number
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

	
			//making variables of the id's from the input fields
			var email = $("#subscribeField").val();

			
			var hasError = false;
			
			
			//trimming the spaces from the input fields
			$('input, textarea').each(function(){
				$(this).val(jQuery.trim($(this).val()));
			});

			
			
			//checks if someone add their email the right way
			if(email == ""){	
				$("#subscribeFieldError").show();
				$("#subscribeField").focus();
				hasError = true;
			} else if (!emailReg.test(email)){
				$("#subscribeFieldError").show();
				$("#subscribeField").focus();
				hasError = true;
			} else {
				$("#subscribeFieldError").hide();
			}
			
			
			return !hasError;
	
	});
});