jQuery(document).ready(function(){
	
	// campaign monitor form
	//jQuery('#mc-cafe').focus(function(){
	//	jQuery(this).val('');
	// });
	//jQuery('#mc-cafe').blur(function(){
	 	//jQuery(this).val('your email. our newsletter.');
	 //});
	 jQuery('#mc-cafe').focus(function(){
	 	jQuery(this).val('');
	  });
	  jQuery('#mc-cafe').blur(function(){
	  	jQuery(this).val('your email. our newsletter. (type and hit "enter")');
	   });
	jQuery('#enews').hover(function(){
	  	jQuery('#newsletter').css('display', 'block');
	  	},
	  	function(){
	  	jQuery('#newsletter').css('display', 'none');
	 });
	
	function checkEmail(email) { 
	  var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  var emailVal = jQuery("#" + email).val();
	  return pattern.test(emailVal);
	}
	
	jQuery(function() {
	  jQuery("#subForm input").keypress(function(e) { 
	    if(e.which == 13){ 
	    
	    // First, disable the form from submitting
	    jQuery('form#subForm').submit(function() { return false; });
	    
	    // Grab form action
	    var formAction = jQuery("form#subForm").attr("action");
	    
	    // Hacking together id for email field
	    // Replace the xxxxx below:
	    // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
	    var id = "mc-cafe";
	    var emailId = id;
	    
	    // Validate email address with regex
	    if (!checkEmail(emailId)) {
	      alert("Please enter a valid email address");
	      return;
	    }
	    
	    // Serialize form values to be submitted with POST
	    var str = jQuery("form#subForm").serialize();
	    
	    // Add form action to end of serialized data
	    // CDATA is used to avoid validation errors
	    //<![CDATA[
	    var serialized = str + "&action=" + formAction;
	    // ]]>
	    
	    // Submit the form via ajax
	    jQuery.ajax({
	      url: "http://cafeyouth.org/wp/wp-content/themes/cafe/j/proxy.php",
	      type: "POST",
	      data: serialized,
	      success: function(data){
	        // Server-side validation
	        if (data.search(/invalid/i) != -1) {
	          alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
	        }
	        else
	        {
	          jQuery("#theForm").hide(); // If successfully submitted hides the form
	          jQuery("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
	          jQuery("#confirmation").tabIndex = -1;
	          jQuery("#confirmation").focus(); // For screen reader accessibility
	          // Fire off Google Analytics fake pageview
	          //var pageTracker = _gat._getTracker("UA-XXXXX-X");
	          //pageTracker._trackPageview("/newsletter_signup");
	        }
	      }
	    });
	    }
	  });
	});
		
	
});

