var healthline = window.healthline || {};
healthline.utils = healthline.utils || {};
healthline.utils.cookies = {
  get: function(cookieName){
    var cookieNameStart,valueStart,valueEnd,value;
    cookieNameStart = document.cookie.indexOf(cookieName+'=');
    if (cookieNameStart < 0){
      return null;
    }
    valueStart = document.cookie.indexOf(cookieName+'=') + cookieName.length + 1;
    valueEnd = document.cookie.indexOf(";",valueStart);
    if (valueEnd == -1){
      valueEnd = document.cookie.length;
    }
    value = document.cookie.substring(valueStart,valueEnd);
    value = unescape(value);
    if (value == ""){
      return null;
    }
    return value;
  },
  set: function(cookieName, value, hoursToLive, path, domain, secure){
    var expireString,timerObj,expireAt,pathString,domainString,secureString,setCookieString;
    if (!hoursToLive || typeof hoursToLive != 'number' || parseInt(hoursToLive) == 'NaN'){
      expireString = "";
    }
    else {
      timerObj = new Date();
      timerObj.setTime(timerObj.getTime() + (parseInt(hoursToLive) * 60 * 60 * 1000));
      expireAt = timerObj.toGMTString();
      expireString = "; expires=" + expireAt;
    }
    pathString = "; path=";
    (!path || path == "") ? pathString += "/" : pathString += path;
    domainString = "; domain=";
    (!domain || domain == "") ? domainString += window.location.hostname : domainString += domain;
    (secure === true) ? secureString = "; secure" : secureString = "";
    value = escape(value);
    //setCookieString = cookieName + "=" + value + expireString + pathString + domainString;
    //TODO - make use of passing in the rest of these variables without breaking code
    setCookieString = cookieName + "=" + value + expireString;
    document.cookie = setCookieString;
  },
  del: function(cookieName, path, domain){
    (!path || !path.length) ? path = "" : path = path;
    (!domain || !domain.length) ? domain = "" : domain = domain;
    healthline.utils.cookies.set(cookieName, "", -8760, path, domain);
  },
  tourPanel: function() {
    var tp_cookie = healthline.utils.cookies.get('hl_tp');
    if(tp_cookie == 'inprogress'){
      healthline.utils.cookies.set('hl_tp','inprogress',24*365);
      tourStatus = true;
    }else if(tp_cookie == 'completed') {
      healthline.utils.cookies.set('hl_tp','completed',24*365);
      tourStatus = false;
    }else{
      healthline.utils.cookies.set('hl_tp','inprogress',24*365);
      tourStatus = true;
    }
    return tourStatus;
  }
};


