function sendEmail() {
    $.post("/ajax/email.php",$("#mailinglistform :input").serialize(), function(data) {
        if (data == "success") {
            $("#mailinglistform").hide();
            $("#mailinglistthanks").show();
        }
    });
}

function checkForEnter (event) {
    if (event.keyCode == 13) {
        sendEmail();
    }
}

$(document).ready(function() {
	$.getJSON("/ajax/fetch-courses.php",
		function(data){
    		html = '<ul>';
			$.each(data.courses, function(i,course){
				var d = new Date(course.course_date1 * 1000);
	          	html += '<li>';
	            html += '<div class="course_title"><a href="/education/course_details.php?course='+course.course_slug+'">' + course.course_title + '</a></div>';
	            html += '<div class="course_date">' + dateFormat(d,"fullDate") + ' ' + dateFormat(d,"h:MM tt") +'</div>';
	            //html += '<div class="course_desc">' + course.course_source +'</div>';
	            html += '</li>';
            	if ( i == 5 ) return false;
			});
			html += '</ul>';
			$("#upcoming_courses").html(html);
        });

		
	$("#mailinglistthanks").hide();
	
	$("#mailinglistsubmit").click(function() {
        sendEmail();
	});
	
	if ($.browser.mozilla) { 
        $("#emailaddress").keypress (checkForEnter); 
    } else {
        $("#emailaddress").keydown (checkForEnter);
    }
});