// Cookie Functions
// ----------------
//
// Form entry is required to access the brochures.html page.  This 
// code will redirect to said page if the user has already filled
// out the form.  
//
// Based on code found at  http://www.quirksmode.org/js/cookies.html
//
// Tweaked by Dallas Vogels, 2007-01-19
// Tweaked by Jeff Jacob, 2007-06-15

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// redirects to destination page
function redirect2page(url){
    window.location = url;
}

// checks for cookie
function checkCookie(name, url) {
	if (readCookie(name)) {
		redirect2page(url);
	} 
}

function popupOnce(name,url,height,width,days)
{
	
	if (readCookie(name)) {
		return null;
	}
		if (days)
		{
			createCookie(name,'true',days);
		}
		else
		{
			createCookie(name,'true');
		}
		var options = 'width='+width+',height='+height;
		window.open(url,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,'+options);
	
}

function redirectOnce(name,url,days)
{
	
	if (readCookie(name)) {
		return null;
	}
		if (days)
		{
			createCookie(name,'true',days);
		}
		else
		{
			createCookie(name,'true');
		}
		window.location = url;
}
