$(document).ready(function(){
  $("#subscribe").bind("click", add_Email);
  $("#main_image").mouseover(function(){
      $("#info").css("display", "").fadeIn(1);
    }).mouseout(function(){
		$("#info").css("display", "none");
    });

});

function add_Email(event)
{
	event.preventDefault();
	if($("#email").val()=='')
  	{
	  alert('You must enter email!');
	  return false;
  	}

	if(!validateEmail($("#email").val()))
	{
		alert('Invalid email!');
		return false;
	}
	
	var email = $("#email").val();
	$("#maillist").fadeOut("slow",function(){
    $(this).empty()
	$(this).show()
	$(this).html('<h3>Loading ... <img src="images/ajax_load.gif"></h3>');
	$.post("ajax.php",{action:'maillist',email:email},function(data){
	var result_html = "<b>"+data+"</b>";
    $("#maillist").html(result_html).fadeIn("slow"); 
    });
	});
	
}

function validateEmail(elementValue){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})+$/;
   if(filter.test(elementValue)) return true;
   else return false; 
}