var msOkIsVisible = 3000;		// miliseconds that OK icon will be visible, before setting the signup button back


$(document).ready(function()
{

	// perform button click when pressing enter key
	$("#mailaddress").keypress(function(e)
	{
		if(e.which == 13)
		{
			$("#btn_signup").click();
		}
	});
	
	
	// setup button click handler
	$("#btn_signup").click(function()
	{
		if($("#mailaddress").val() == '') return;
		
		
		$(this).attr('src','images/buttons/loading16x16.gif');
		$(this).addClass("disabled");
		
		$.post('ajax/signup.php', { mailaddress: $("#mailaddress").val() },
			function(data)
			{	
				if(data.res == "ok")
				{
					$("#mailaddress").val('');
					
					$("#btn_signup").attr('src','images/buttons/icn-ok16c.png');
					$("#btn_signup").animate({opacity: 0.40}, 500, function()
					{
						$(this).animate({opacity: 1}, 500);
					});
				}
				else
				{
					$("#btn_signup").attr('src','images/buttons/icn-err16.png');
					$("#btn_signup").animate({opacity: 0.40}, 500, function()
					{
						$(this).animate({opacity: 1}, 500);
					});
				}
				
				setTimeout(function()
				{
					$("#btn_signup").fadeOut('fast',
						function()
						{
							$(this).attr('src', 'images/buttons/btn-go.png');
							$(this).fadeIn('fast');
						});					
					$("#btn_signup").removeClass("disabled");
					
				}, msOkIsVisible);
			}, "json");
	});
});
