﻿var expDays = 30; // number of days the cookie should last

function GetThisCookie (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
  return null;
}

function SetThisCookie (name, value) {
  var argv = SetThisCookie.arguments;
  var argc = SetThisCookie.arguments.length;
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + 30);
  //var expires = exdate; //(argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) + ((exdate == null) ? "" : ("; expires=" + exdate.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));


function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
    var count = GetThisCookie('count');
    if (count == null) {
        alert("Spread betting offers many benefits, but it’s important to note that it carries \na high level of risk to your capital, so you should only bet with money you \ncan afford to lose. It is possible for you to lose more than your initial deposit \nand stake so please ensure spread betting meets your investment objectives \nand seek independent advice if necessary.");
        SetThisCookie('count', 'fsa');
    }
}

window.onload=checkCount;