$(document).ready(function() {
	$(window).resize()
	$("#mailersub").click(function() {
		var email = $('#email').val();
		var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	
		if (!emailRegex.test(email))
		{
			$.modal("<span class=\"error\">Please enter a valid email address!</span>",{
				onOpen: function (dialog) {
					dialog.overlay.fadeIn('fast');
					dialog.container.fadeIn('fast');
					dialog.data.show();
				}, 
				overlayClose: true
			});
		}
		else
		{
			$.ajax({
				type: "POST",
			    url: "sub.php",
				data: "email=" + email + "&check=frozenturkey&type=s",
				success: function(response, status){
					if (status == "success" && response == "OK")
					{
						$.modal("<span class=\"OK\">You have been successfully subscribed to the mailing list.</span>",{
							onOpen: function (dialog) {
								dialog.overlay.fadeIn('fast');
								dialog.container.fadeIn('fast');
								dialog.data.show();
							}, 
							overlayClose: true
						});
					}
					else
					{
						$.modal("<span class=\"error\">Something went wrong and we were unable to setup your subscription. <br />Please try again later.</span>",{
							onOpen: function (dialog) {
								dialog.overlay.fadeIn('fast');
								dialog.container.fadeIn('fast');
								dialog.data.show();
							}, 
							overlayClose: true
						});
					}
				},
				error : function () {
					$.modal("<span class=\"error\">Something went wrong and we were unable to setup your subscription. <br />Please try again later.</span>",{
						onOpen: function (dialog) {
							dialog.overlay.fadeIn('fast');
							dialog.container.fadeIn('fast');
							dialog.data.show();
						}, 
						overlayClose: true
					});
				}
			});
		}
	});
	
	$("#mailerunsub").click(function() {
	var email = $('#email').val();
	var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

	if (!emailRegex.test(email))
	{
		$.modal("<span class=\"error\">Please enter a valid email address!</span>",{
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast');
				dialog.container.fadeIn('fast');
				dialog.data.show();
			}, 
			overlayClose: true
		});
	}
	else
	{
		$.ajax({
			type: "POST",
			url: "sub.php",
			data: "email=" + email + "&check=frozenturkey&type=u",
		success: function(response, status){
			if (status == "success" && response == "OK")
			{
				$.modal("<span class=\"OK\">Your ubsubscription request has been sent.<br/>You will stop receiving emails from us shortly.</span>",{
					onOpen: function (dialog) {
						dialog.overlay.fadeIn('fast');
						dialog.container.fadeIn('fast');
						dialog.data.show();
					}, 
					overlayClose: true
				});
			}
			else
			{
				$.modal("<span class=\"error\">Something went wrong and we were unable to setup your subscription. <br />Please try again later.</span>",{
					onOpen: function (dialog) {
						dialog.overlay.fadeIn('fast');
						dialog.container.fadeIn('fast');
						dialog.data.show();
					}, 
					overlayClose: true
				});
			}
		},
		error : function () {
				$.modal("<span class=\"error\">Something went wrong and we were unable to send your unsubscription request. <br />Please try again later.</span>",{
					onOpen: function (dialog) {
						dialog.overlay.fadeIn('fast');
						dialog.container.fadeIn('fast');
						dialog.data.show();
					}, 
					overlayClose: true
				});
		}
		});
	}
});
});

$(window).resize(function() {
	if ($(window).width() > 1030 && $(window).height() > 730) {
		$(".decolady").show();
	}
	else if ($(window).width() > 800 && $(window).height() > 920) {
		$(".decolady").show();
	}
	else {
		$(".decolady").hide(); 
	}
});
