
var floatOpacity = 0;
var floatOpacityRequired = 90;
var intervalFade = 0;

function initializeSurvey()
{
	var dateNow = new Date();
//	var strDateStart = "2010-01-11 17:08";
	var strDateStart = "2010-01-15 08:30";
	var strDateEnd = "2010-01-25 08:00";
	var strDateNow = LPad(dateNow.getFullYear(), '0', 4) + "-" + LPad((dateNow.getMonth() + 1), '0', 2) + "-" + LPad(dateNow.getDate(), '0', 2) + " " + LPad(dateNow.getHours(), '0', 2) + ":" + LPad(dateNow.getMinutes(), '0', 2);
	var intWeight = 10;

	var flagDo = true;

	if (document.cookie.length > 0)
	{
		if (document.cookie.indexOf('survey=') != -1)
		{
			flagDo = false;
		}
	}

	if (flagDo == true)
	{

		if (Math.floor(Math.random()*intWeight) == 0)
		{

			if ((strDateNow >= strDateStart) && (strDateNow < strDateEnd))
			{

				document.write("<div id=\"idUnderlay\" style=\"position: fixed; display: none; z-index: 10000; width: 100%; height: 100%; top: 0px; left: 0px; background-color: #cccccc; opacity: 0.0; filter:alpha(opacity=0);\"></div>\n");
				document.write("<div id=\"idOverlay\" style=\"position: absolute; z-index: 10001; left: 50%; top: 50%;\">\n");
				document.write("	<div id=\"idMessage\" style=\"position: absolute; display: none; left: -320px; top: -100px; width: 640px; height: 200px; background-color: #ffffff; margin: 0px; border: 2px solid #000000; padding: 5px 10px 5px 10px; opacity: 0.0; filter:alpha(opacity=0);\">\n");
				document.write("		<p>Please help us to improve the Lancashire County Council website.\n");
				document.write("		</p>\n");
				document.write("		<p>Complete our survey and you could <strong>win a trip to Edinburgh</strong>.\n");
				document.write("		</p>\n");
				document.write("		<p>First TransPennine Express are offering two 1st class rail tickets to Edinburgh.\n");
				document.write("		</p>\n");
				document.write("		<p style=\"text-align: center;\"><a href=\"/home/survey/redirect.asp\">Yes – count me in</a> || <a href=\"#\" onClick=\"fadeOut(); return false;\">No – not at this time</a>\n");
				document.write("		</p>\n");
				document.write("	</div>\n");
				document.write("</div>");

				fadeIn();

			}

		}

	}

}

function fadeIn()
{
	floatOpacity = 0;
	floatOpacityRequired = 90;
	document.getElementById('idMessage').style.display = 'block';
	document.getElementById('idUnderlay').style.display = 'block';
	intervalFade = setInterval('fader()',1);
}

function fadeOut()
{
	floatOpacity = 90;
	floatOpacityRequired = 0;
	intervalFade = setInterval('fader()',1);
	var exdate = new Date();
	exdate.setDate (exdate.getDate() + 1);
	document.cookie="survey=no;expires=" + exdate.toGMTString() + ";path=/";
}

function fader()
{
	if (floatOpacity < floatOpacityRequired)
	{
		floatOpacity = floatOpacity + 2;
	}
	else if (floatOpacity > floatOpacityRequired)
	{
		floatOpacity = floatOpacity - 2;
	}
	else
	{
		intervalFade = window.clearInterval(intervalFade);
		floatOpacity = floatOpacityRequired;
	}

	document.getElementById('idUnderlay').style.opacity = (floatOpacity / 100);
	document.getElementById('idMessage').style.opacity = (floatOpacity / 100);
	document.getElementById('idUnderlay').style.filter = 'alpha(opacity=' + floatOpacity + ')';
	document.getElementById('idMessage').style.filter = 'alpha(opacity=' + floatOpacity + ')';

	if (floatOpacity == 0)
	{
		document.getElementById('idMessage').style.display = 'none';
		document.getElementById('idUnderlay').style.display = 'none';
	}
}

initializeSurvey(); /* the much celebrated addLoadEvent function causes errors in certain browsers so we'll use the rubbish way. */

