/*
 * Copyright (C) 2007 TriActive, Inc.  All rights reserved.
 * Cookie functions taken from quirksmode.org.
 */
var triactive = window.triactive || {};
triactive.bulletin = 
{

  // configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  // When there is no cookie, forward here
  defaultUrl: 'https://manager.systemsmanagementondemand.com/',
  daysToLive: 1,

  skipName: 'mgr.bulletin.skip',   // do not change this
  startPage: 'mgr.host.startPage', // do not change this
  

  // functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
  /**
   * Creates a cookie for each domain that is listed above, but only the one
   * whose domain matches the destination domain will actually bind.
   */
  createSkipCookie: function() 
  {
    if (triactive.bulletin.daysToLive == null)
    {
      triactive.bulletin.daysToLive = 1;
    }
    
    triactive.bulletin.createCookie(triactive.bulletin.skipName, 'true', triactive.bulletin.daysToLive)
  },
  
  gotoStartPage: function(formName) 
  {
    var url = triactive.bulletin.readCookie(triactive.bulletin.startPage);

    if (url == null) 
    {
      url = triactive.bulletin.defaultUrl;
    }
    
    // if skip is checked drop some cookies
    var skip0 = document.getElementById('skip0');
    var skip1 = document.getElementById('skip1');

    if (((skip0 != null) && (skip0.checked == true)) 
       || ((skip1 != null) && (skip1.checked == true))) 
    {
      triactive.bulletin.createSkipCookie();
    }
    
    window.location = url;
  },

  update: function(checkbox) 
  {
    if (checkbox.checked == true) 
    {
      document.getElementById('skip0').checked = true;
      document.getElementById('skip1').checked = true;
    } 
    else 
    {
      document.getElementById('skip0').checked = false;
      document.getElementById('skip1').checked = false;
    }
  },

  createCookie: function(name,value,days) 
  {
    if (days) 
    {
      var date = new Date();
      var midnight = new Date(date.getFullYear(),date.getMonth(),date.getDate(),0,0,0);
      date.setTime(date.getTime() + (days*24*60*60*1000)-(date-midnight));
      var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  },

  readCookie: function(name) 
  {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) 
    {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  },

  eraseCookie: function(name) 
  {
    triactive.bulletin.createCookie(name,"",-1);
  }

};