$(function() {
	
	$("#cookieClick a").click(function() {
		var $theLink = $(this);
		var agreeURL = $theLink.attr("href");
		var cookieID = $theLink.attr("id");
		var accountURL;
		if (cookieID == "fdc_agree_go_tag") { accountURL = "http://www.everywherepay.com/gotag"; }
		else if (cookieID == "fdc_agree_taxi_tag") { accountURL = "http://www.everywherepay.com/taxitag"; }
		else if (cookieID == "fdc_agree_711_tag") { accountURL = "https://www.everywherepay.com/7-elevengotag/giftCardApp.gft?orgId=7796"; }
		
		if ($.cookie(cookieID)) { window.location = accountURL; }
		else { agreePop(agreeURL); }
		
		return false;
	});
	
	$("#yesOrNo a").click(function() {
		var setCookieName = $(this).attr("id");
		if (setCookieName) {
			$.cookie(setCookieName, setCookieName, {
				expires: 30,
				path: "/"
			});
		}
		setInterval(shutAgree, 100);
	});
	
	var shutAgree = (function() {
		self.window.close();
	});
	
	var agreePop = (function(url) {
		var name = "Agree";
		var width  = "600";
		var height = "250";
		var left   = (screen.width  - width)/2;
		var top    = (screen.height - height)/2;
		var params = "width=" + width + ", height=" + height;
		params += ", top=" + top + ", left=" + left;
		params += ", directories=no";
		params += ", location=no";
		params += ", menubar=no";
		params += ", resizable=yes";
		params += ", scrollbars=no";
		params += ", status=no";
		params += ", toolbar=no";
		var newwin = window.open(url, "name", params);
		if (window.focus) { newwin.focus(); }
	});

});
