// JavaScript Document$(document).ready(function() {

$(document).ready(function() {
	
	$("#popup").hide();	
	
	$("a.extLink").click(function() {
		window.open(this.href);
		return false;
	});	
	
	$("#nav3").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		});
	
	if(document.cookie == "") {
		$("#popup").hide()
	}
	else {
	$("#popup").hide();	
	};
	
	$("#popupClose").click(function() {
		$("#popup").hide("slow", setCookie);							 
	});
	
	$("#signUpBtn").click(function() {
		$("#popup").show("slow", clearCookie);							 
	});
	
	$("#submitform").submit( function () { 
		
		var email = $("#emailAdr").val();
											  
		$("#submitbutton").hide();
		$(".loader").show();
		$.ajaxSetup({cache: false});
		$.getJSON("/cgi-bin/show_request.cgi", {email_address: email},
			function(data){
				if (data.success == 1){
					setThanks();
				}
				else {
					setSorry(); 
				}
			});
		return false;
	});
	
	function setCookie() {
		document.cookie ='visited=true; expires=Thu, 1 Jan 2015 00:0:00 UTC; path=/'
	}
	function clearCookie() {
		document.cookie ='visited=; expires=Thu, 22 July 1985 04:20:00 UTC; path=/'	
	}
	function setThanks() {
		$("#popup").removeClass();
		$("#popup").addClass("popupThanks");
		$("#popup h3 span").html("Thank you for signing up.");
		$("#popup p span").html("You will recieve an email shortly.");
		$(".loader").hide();
		$("#popup form").remove();
	}
	function setSorry() {
		$("#popup").removeClass();
		$("#popup").addClass("popupSorry");
		$("#popup h3 span").html("Sorry, there was a problem.");
		$("#popup p span").html("Please check your email address or try again later.");
		$(".loader").hide();
		$("#submitbutton").show();	
	}
	function setNormal() {
		$("#popup").removeClass();
		$("#popup h3 span").html("Sign up to hear from Prescriptives Online");
		$("#popup p span").html("Recieve email updates with expert tips, up to the minute news, store events and special offers.");
		$(".loader").hide();
		$("#submitbutton").hide();
	}
	
	$("#nav3").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		});
	
});