// Exit Survey instigation code - Call Breakout() in Body onUnload
function Breakout()
{
	/* only invoke on a selection of unloads */
	/* If the number of minutes is modulo x launch process */			
	var Today = new Date();
	var secs = Today.getSeconds();
	var BaseURL = "http://" + document.domain;
	var surveyForm;
	
	if (secs % 10 == 0) // modulo 5 is 1:12
	{
		if (document.cookie.indexOf("survey=") < 0)
		{
			var response = confirm("Would you participate in our survey ?");
			
			if (response)
			{
				surveyForm = window.open(BaseURL + "/exitsurvey/default.aspx","Survey", "toolbar=no, status=no, menubar=no, scrollbars=yes, resizable=yes");
				if (surveyForm == null)
				{
					alert ("Popups need to be enabled for this site before the survey can start");
				}
			}
			else
			{
				RegisterSurvey();
			}
		}
	}
}

function RegisterSurvey()
{
	/* Set the survey cookie unconditionally */
	var Today = new Date();
	var expires = new Date();

	// Park a cookie to prevent from re-Asking for the next 120 minutes
	expires.setTime(Today.getTime() + 1000*60*120);
	//expires.setTime(Today.getTime() + 1000*60*1); // 1 minute TTL for testing
	setCookie("survey", Today.toString(), expires);
}

function setCookie(name, value, expire)
{
	document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + "; path=/";
}

function EatCookie()
{
	var Today = new Date();
	var expires = new Date();
	
	expires.setTime(Today.getTime());

	setCookie("survey", Today.toString(), expires);
}

function StartSurvey()
{
	var surveyForm;

	surveyForm = window.open("http://" + document.domain + "/exitsurvey/default.aspx","Survey", "toolbar=no, status=no, menubar=no, scrollbars=yes, resizable=yes");
	return (false);
}