$(document).ready(function()
{
	$("#newsletter").focus(function(event)
	{	
		if ($("#newsletter").val()=="Enter Email") $("#newsletter").val("");
	});
	
	$("#newsletter").keydown(function(event)
	{
		if (event.keyCode==13)
		{
			subscribe();
			return false;
		}
	});
	
	$("#newsletter").val("Enter Email");

	$("#newsletterbutton").click(function()
	{
		subscribe();

	});
	
	function subscribe()
	{
		var s = $("#newsletter").val();
		if (s!="")
		{
			if (isEmailValid(s))
			{
				$("#newsletter").blur();
				$("#newsletter").attr("disabled",true);
				$("#newsletterbutton").attr("disabled",true);
				$.post("newslettersignup.aspx",{email:s},function()
				{
					$.notifyMe("Thank you for subscribing to the Inpress newsletter!");				
					$("#newsletter").attr("disabled",false);
					$("#newsletterbutton").attr("disabled",false);
					$("#newsletter").val("Enter Email");				
				});					

			}
			else
			{
				jAlert("Please check email validity and try again.","Error");			
			}
		}
	}
	
});

function isEmailValid(email)
{
  var pattern=new RegExp(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]+$/);
  return pattern.test(email);
}

$.notifyMe = function(msg)
{
    var id="notifyMe";
    var notifyBar = $("<div style=\"display:none;font-size:12px;width:100%;text-align:center;padding:10px;position:fixed;top:0;left:0;z-index:20000;background-color:#e0e0e0;color:#000000;border-bottom:1px solid #a0a0a0\"></div>")
    notifyBar.attr("id",id);
    notifyBar.html(msg);
    $("body").prepend(notifyBar);
    notifyBar.slideDown(300);
    setTimeout(function()
            {
                $("#"+id).fadeOut(1500,function()
                        {
                            $("#"+id).remove();
                        });                
            },2000);    
};

