$(function(){
	$('#nl_email').click(function(){
		$(this).val('');
		
	});
	$('#nl_send').click(function(){
		var email = $('#nl_email').val();
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			if(pattern.test(email)){
				$('#nl_msg').hide().html('Please wait...').slideDown(500);

				$.post('/nl.php',{email : email},function(data){
					if(data == 'ERROR') {
						$('#nl_msg').html('You e-mail is already in our database');
													
					}
					else {
						$('#nl_email').slideUp(500,function(){ $(this).remove() });
						$('#nl_send').remove();
						$('#nl_msg').html('Your e-mail has been successfully added to our database. Thank you!');
						
						
					}
				});
			}
			else{
						$('#nl_msg').hide()
													.html('Please enter a valid e-mail address!')
													.slideDown(500);
			}
	});
	
	
});
