function SetCookie(sName, sValue,nDays)
{
	var today = new Date();
	var expireDate = new Date();
	
	//If the cookie life time is not given then don't set expire value.
	// This means that the cookie will expire when the browser is closed.
	// Otherwise, set the expire value.
	if (nDays==null || nDays==0) 
	{
		document.cookie = sName + "=" + escape(sValue);
	}
	else
	{
		expireDate.setTime(today.getTime() + 3600000*24*nDays);
		document.cookie = sName + "=" + escape(sValue) + "; expires=" + expireDate.toGMTString();
	}
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function ShowSurvey()
{
	testValue=Math.floor(1000*Math.random());	
	SetCookie('AreCookiesEnabled',testValue);
	
	// If the cookies are enabled then show the survey dialog based on the previously
	// selected option. Otherwise, no action.
	if (testValue==GetCookie('AreCookiesEnabled')) 	
	{
		var surveyStatus = GetCookie('SurveyStatus');
		
		// If the user has selected "never" then cookie will get expired after 100 years
		// so GetCookie will not return null within 100 years.
		
		// If the user had selected "Take me to the survey" then the cookie 
		// will get expired after 100 years so GetCookie will not return null with in 100 years.
		
		// If the user had selected "Later"  option then the cookie will not expired with in the 
		// same browser session but it will get expire when browser window is closed 
		// so the survey window will be shown during next visit.
		
		// Also, when user has deleted the cookie then survey window will be shown.
		
		if (surveyStatus == null) 
			window.open("http://www.opsi.gov.uk/Survey.Htm","mywindow","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=455,height=330,left = 490,top = 362");
	}
}			

function btnNever_Click()
{
	SetCookie('SurveyStatus','never',100 * 365);
	window.close();
}

function btnToSurvey_Click()
{
	var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
	SetCookie('SurveyStatus','visited',100 * 365);	
	window.open("http://www.surveymonkey.com/s.aspx?sm=FLkgGaZ7Os1hydKkPG13XA_3d_3d","Survey_Form_Window",strWindowFeatures);
	window.close();
}		

function btnLater_Click()
{
	SetCookie('SurveyStatus','later',null);
	window.close();
}	
