/*
  exported from tool.wrap for use as a client-side included library
  from that doc...
  _tb source is based on code by Duncan Crombie: dcrombie@chirp.com.au
  Please acknowledge use of this code by including this header.
  created to function in MWS WRAP environment 
*/

window.getCookie = function(name) {                   // usage: getCookie("name");
  var oRE = new RegExp(name + "=("+String.fromCharCode(91)+"^;"+String.fromCharCode(93)+"+)")      // note: using CharCodes for brackets to avoid wrap problems
  var sValue = oRE.exec(document.cookie);
  return (sValue != null) ? unescape(sValue[1]) : null;
}

window.setCookie = function(name, value, ttl, path, domain) {       // usage: setCookie("name", value, (ttl=int number of days));
  var lDomain = domain || window.location.host || '[community.domain]'; if(lDomain.match(/community\.domain/)) lDomain = ''
  var sDomain = ';domain=' + lDomain;
  var lPath = path || '/';
  var sPath = ';path=' + lPath;
  var oToday = new Date();
  var sTTL = '';
  if(ttl){
    var expiry = new Date(oToday.getTime() + ttl * 24 * 60 * 60 * 1000); // set expiration of cookie based on ttl
    sTTL=';expires=' + expiry.toGMTString();
  }
  var lCookie = name + "=" + escape(value) + sPath + sDomain + sTTL;
  document.cookie=lCookie;
}

