var expireTomorrow = new Date()
var expireYear = new Date()
expireTomorrow.setTime(expireTomorrow.getTime() + 1000 * 60 * 60 * 24);
expireYear.setTime(expireYear.getTime() + 1000 * 60 * 60 * 24 * 365);

setCookie("testVal", "ok", expireTomorrow);
var cookiesOK = null;
var testVal = getCookie("testVal");
if(testVal != null) {
	cookiesOK = true;
}

function popWin(url,wd,ht,scroll) {
	useScroll = 0;
	if (scroll == 1)	{
		useScroll = 1;
	}
	height = ht;
	width = wd;
	thisURL = url;
	popupWin=window.open(thisURL,"","width=" + width + ",height=" + height + ", scrollbars=" + useScroll + ", resizable")
}

function bakeCookie(response) {
	intDeclined = 0;
	switch(response) {
		case 'no':
			var td = getCookie('timesDeclined');
			if(td == null) {
					intDeclined = 0;
			} else {
					intDeclined = parseInt(td);
			}
			if(intDeclined == 2) {
				setCookie('march07Survey', 'never', expireYear);
			} else {
				setCookie('march07Survey', 'no', expireTomorrow);
				intDeclined = (intDeclined + 1);
				setCookie('timesDeclined', intDeclined, expireYear)
			}
			window.close();
			break;
		case 'never':
			setCookie('march07Survey', 'never', expireYear);
			window.close();
			break;
		case 'complete':
			setCookie('march07Survey', 'complete', expireYear);
			break;
	}
}	

function setCookie(name, value, expireDate) {
	document.cookie = name + "=" + value + "; expires=" + expireDate + "; path=/;";
}

function getCookie(name) {
	var key = name + "=";
	var aCookieParts = document.cookie.split(';');
	for(var i=0;i < aCookieParts.length;i++)
	{
		var cookiePiece = aCookieParts[i];
		while (cookiePiece.charAt(0)==' ') cookiePiece = cookiePiece.substring(1,cookiePiece.length);
		if (cookiePiece.indexOf(key) == 0) return cookiePiece.substring(key.length,cookiePiece.length);
	}
	return null;
}

function eatCookie(name) {
	alert(getCookie(name));
}

function burnCookie(name) {
	setCookie(name, null, -1);
}

function offerSurvey() {
	if(cookiesOK) {
		surveyResponse = getCookie('march07Survey');
		if((surveyResponse != "no") && (surveyResponse != "never") && (surveyResponse != "complete")) {
			
			// Date Management Script 1.2
			// by: Joseph Neil Reiter

			// Get current system time and date
			var d = new Date()

			// Set the event date
			var Web_Survey_Invitation_Start_Month = "3"
			var Web_Survey_Invitation_Start_Day = "13"
			var Web_Survey_Invitation_Start_Year = "2007"

			var Web_Survey_Invitation_End_Month = "12"
			var Web_Survey_Invitation_End_Day = "31"
			var Web_Survey_Invitation_End_Year = "2007"

				if ((((d.getMonth() + 1) == Web_Survey_Invitation_Start_Month) && (d.getDate() >= Web_Survey_Invitation_Start_Day) && (d.getFullYear() == Web_Survey_Invitation_Start_Year)) || (((d.getMonth() + 1) > Web_Survey_Invitation_Start_Month) && (d.getFullYear() == Web_Survey_Invitation_Start_Year)) || (d.getFullYear() > Web_Survey_Invitation_Start_Year)) {

					if ((((d.getMonth() + 1) == Web_Survey_Invitation_End_Month) && (d.getDate() <= Web_Survey_Invitation_End_Day) && (d.getFullYear() == Web_Survey_Invitation_End_Year)) || (((d.getMonth() + 1) < Web_Survey_Invitation_End_Month) && (d.getFullYear() == Web_Survey_Invitation_End_Year)) || (d.getFullYear() < Web_Survey_Invitation_End_Year)) {

						// It is less than or equal to the last day of the survey, display the survey invitation.
						//popWin('/Web_Site_Survey/surveyInvite.html',459,500,0);

					}  


				}

			// End Date Management Script

		}
	}
}

function openSurvey() {
	window.open("http://www.surveymonkey.com/s.asp?u=712883484502");
	window.close();
}
