// All scripting necessary to invoke a newletter notification on page load. 
// Notifier HTML is in the footer include.

// This sets the cookie
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// This deletes the cookie
function delCookie(c_name) 
	{
	document.cookie = c_name +
	'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	}

// This gets the cookie
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Check if cookie is set, if not prompt user to sign up. 
$(document).ready(function()
	{
	if (getCookie('submitted') != 'true')
	  	{
		newsNotice = $.pnotify({
				pnotify_text: $('#form_notice').html(),
				pnotify_notice_icon: '',
				pnotify_width: 'auto',
				pnotify_hide: true,
				pnotify_closer: true,
				pnotify_insert_brs: false,
				pnotify_opacity: .95,
				pnotify_notice_icon: 'ui-icon ui-icon-mail-closed'
				});
  		}
	}
); 

// When the user clicks "Don't show again, set the cookie"
function dontShowAgain() {
	setCookie('submitted','true','365');
	var sorryText = '<i>Okay, we won\'t bug you again!</i>';
	$('div#dontShowText').html(sorryText);
	newsNotice.pnotify_remove();
}