/*
	Wuit.com
	Copyright (C) Fred Wu
*/

$(document).ready(function() {
	$(document).pngFix();
	
	$("input#email").val("Enter your email");
	$("input#email").click(function() {
		if ($(this).val() == "Enter your email") {
			$(this).val("")
		}
		$(this).css({color: "#8c8a43"});
	});
	
	$("a#btn-notify").click(function(){
		$("div.notify-msg").fadeOut();
		if (isEmail($("input#email").val())) {
			$.post($("form#frm-notify").attr("action"), {
				email: $("input#email").val()
			}, function(emailRecorded) {
				if (emailRecorded == "True") {
					$("div#notify-success").fadeIn();
				} else if (emailRecorded == "False") {
					$("div#notify-warning").fadeIn();
				} else {
					$("div#notify-error").fadeIn();
				}
			});
			return false;
		} else {
			$("div#notify-failed").fadeIn();
		}
	});
});

function isEmail(emailAddress) {
	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);
	return pattern.test(emailAddress);
}