function getCookie(c_name) {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1) { 
		c_start = c_start + c_name.length + 1;
		c_end = document.cookie.indexOf(";", c_start);
		if (c_end==-1) {
			c_end = document.cookie.length;
		}
	}
	return unescape(document.cookie.substring(c_start, c_end));
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name +  "=" + escape(value) + ((expiredays==null) ? "" : "; expires=" + exdate.toGMTString());
}

function validateAnswers(mForm) {
	var chosen = false;
	for (i=0; i<mForm.radAnswer.length; i++) {
		if (mForm.radAnswer[i].checked) {
			setCookie("guestAnswer" + intThisPage, mForm.radAnswer[i].value, 1);
			chosen = true;
		}
	}
	if (!chosen) {
		alert("Please choose an answer to continue.");
		return false;
	}
}

function hintwindow (url) {

	// open a new window to contain FL hint page	
	var needhint;
	needhint = window.open(url,"hint","width=800,height=600,resizable=1,scrollbars=1,status=1,toolbar=0,location=0,menubar=0");
	needhint.moveTo(0,0);
	
}



/* Browser detect */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


//alert("Browser: " + BrowserDetect.browser + "\n\nVersion: " + BrowserDetect.version + "\n\nOS: " +BrowserDetect.OS);


/* ---------------- */


function getdarnCookie(name)
{ var pos
  var token = name + "=";
  var tnlen = token.length;
  var cklen = document.cookie.length;
  var i = 0;
  var j;
  while (i < cklen)
  { j = i + tnlen;
    if (document.cookie.substring(i, j) == token)
    { pos = document.cookie.indexOf (";", j);
      if (pos == -1)
        pos = document.cookie.length;
      return unescape(document.cookie.substring(j, pos));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  } //End While
  return null;
}


/* Cookie enablement check */
function LandingCheckCookie()
{
	if (BrowserDetect.browser!="Safari")
	{

		// do the cookie test/check
		 //alert("Browser is NOT Safari!");
 	
	FLQuizID = "FLIQV3";
	setCookie('FLQuizID', FLQuizID, 365);
		//alert(document.cookie);
	cookieCheck = getdarnCookie('FLQuizID'); // <-- problem here
		//alert(cookieCheck);
	if (cookieCheck!="FLIQV3") {
		alert("There was a problem with setting a cookie on your computer and this quiz requires them to function.\n\n Please enable cookies in the settings of your browser.");
		}
	}
}

/* Question page cookie check */
function checkCookie()
{
	if (BrowserDetect.browser!="Safari")
	{
	
cookieCheck = getdarnCookie('FLQuizID');
if (cookieCheck=="FLIQV3")
  {
  // there's a value in cookieCheck 
  return;
  }
else  
  {
  
    alert("It appears you've entered this quiz from a page other than the start page, or your browser is not set to accept cookies. You will be redirected to the beginning of the quiz.");
    document.location.href="http://www.fineliving.com/fine/pac_ctnt_988/text/0,,FINE_26036_61274,00.html";
    
  }
}
}