//*****************************************************************************
//
//  Dopple Javascript function library.
//
//  Copyright 2006-2008 - Dopple, Inc. - ALL RIGHTS RESERVED
//
//*****************************************************************************

String.prototype.right = function(count)
{
  return this.substr(this.length - count);
}

String.prototype.left = function(count)
{
  return this.substr(0, count);
}

String.prototype.ltrim = function()
{
  return this.replace(/^\s+/, '');
}

String.prototype.rtrim = function()
{
  return this.replace(/\s+$/, '');
}

String.prototype.trim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "");
}

String.prototype.fulltrim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "").replace(/\s+/g, " ");
}

String.prototype.lpad = function(new_len, pad_str)
{
  var pad_len = new_len - this.length;
  var pad     = '';

  if (pad_len > 0)
  {
    while (pad.length < pad_len) pad += pad_str;
    return pad.substr(0, pad_len) + this.substr(0);
  }
  else
    return this.substr(0);
}

String.prototype.rpad = function(new_len, pad_str)
{
  var pad_len = new_len - this.length;
  var pad     = '';

  if (pad_len > 0)
  {
    while (pad.length < pad_len) pad += pad_str;
    return this.substr(0) + pad.substr(0, pad_len);
  }
  else
    return this.substr(0);
}

if (typeof DoppleIntf == "undefined") var DoppleIntf = new Object();

DoppleIntf.getCookie = function(name)
{
  var results = document.cookie.match('(?:^|;) ?' + name + '=([^;]*)(?:;|$)');

  return results ? unescape(results[1]) : "";
}

DoppleIntf.setCookie = function(name, value, exp_y, exp_m, exp_d, path, domain, secure)
{
  var cookie_string = name + "=" + escape(value);

  if (exp_y)
  {
    var expires = new Date(exp_y, exp_m, exp_d);
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if (path) cookie_string += "; path=" + escape(path);

  if (domain) cookie_string += "; domain=" + escape(domain);
  
  if (secure) cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

DoppleIntf.deleteCookie = function(name)
{
  var cookie_date = new Date();  // current date & time

  cookie_date.setTime(cookie_date.getTime() - 1);

  document.cookie = name += "=; expires=" + cookie_date.toGMTString();
}

DoppleIntf.getTokens = function()
{
  var auth_tokens = new Array();

  auth_tokens[0] = this.getCookie("PHPSESSID");
  auth_tokens[1] = this.getCookie("DoppleAuth");
  return auth_tokens;
}


