//============================================================================
// Copyright (c) 2006 Pelco. All rights reserved.
//
// This file contains trade secrets of Pelco.  No part may be reproduced or
// transmitted in any form by any means or for any purpose without the express
// written permission of Pelco.
//
// $File: cookie.js$
// $Revision: 4$
// $Date: 05/16/2008 03:27:16 PM$
// $Author: jwatson$
//============================================================================

function hasCookie(name) {
  var jar = document.cookie;
  var idx = jar.indexOf(escape(name) + "=");
  return (idx >= 0);
}

////////////////////////////////////////////////////////////////////////////////

function getCookie(name) {
  // find the cookie
  var jar = document.cookie;
  var idx = jar.indexOf(escape(name) + "=");
  if (idx < 0) { return null; }

  // find the end of the cookie value
  var end = jar.indexOf(";", idx);
  var len = (end < 0) ? jar.length : (end - idx);

  // split the cookie pair
  var cookie = jar.substr(idx, len).split("=");
  return (cookie[1]);
}

////////////////////////////////////////////////////////////////////////////////

function setCookie(name, value, expire) {
  var opts = "";
	
  // convert expires from relative to absolute time
  if (expire) {
    var exp = new Date();
    exp.setSeconds(exp.getSeconds() + expire);
    opts += ";expires=" + exp.toUTCString();
  }
	// force cookie to be valid throughout domain
	opts += "; path=/";

  // set the cookie with all completed options
  document.cookie = escape(name) + "=" + escape(value) + opts;
}

////////////////////////////////////////////////////////////////////////////////

function deleteCookie(name) {
  // just expire the cookie a month ago
  setCookie(name, "", -1*60*60*24*30);
}

