$(document).ready(function(){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	
	$('input[name=inputmail-small]').focus(function(){
		if($(this).val()=='Enter your email'){
			$(this).val('');
		}
	});
	
	$('input[name=inputmail-small]').blur(function(){
		if($(this).val().length<=0){
			$(this).val('Enter your email');	
		}							   
	});
	
	$('input[name=button-mail]').click(function(){
		if($('input[name=inputmail-small]').val().length<=0){
			$('input[name=inputmail-small]').focus();
		}else if(!emailPattern.test($('input[name=inputmail-small]').val())){
			$('input[name=inputmail-small]').focus();
		}else{
			$.ajax({
				url: "/subscribe/add/",
				type: "POST",
				cache: false,
				dataType: "html",
				data: {
					Email: $('input[name=inputmail-small]').val()
				},
				error: function(){
					alert('Cannot Send Email !');
				},
				success: function(text){
					if(text.indexOf('false')!=-1){
						alert('The email has existed !, please try again');
					}else if(text.indexOf('true')!=-1){
						alert('Success');
					}
				}
			});	
		}
	});
});
