/*
  PFrameworkCS API
  
  Copyright (C) 2008 by Gregor Kališnik <gregor@unimatrix-one.org>
  Copyright (C) 2008 by Unimatrix-One (www.unimatrix-one.org)
  
  This javascript is part of the PFramework CMS system. Any unauthorised
  use outside of this system is strictly prohibited.
*/

function formatUserDate(time)
{
  var date = new Date();
  date.setTime(time * 1000);

  try {
    var format = PCookieManager.value('PSettings')['timeformat'];
  } catch (e) {
    var format = false;
  }

  if (format == false || format == undefined) {
    return date.format("dd.mm.yyyy @ HH:MM:ss");
  } else {
    return date.format(format);
  }
}

function formatShortUserDate(time)
{
  var date = new Date();
  date.setTime(time * 1000);

  try {
    var format = PCookieManager.value('PSettings')['short_timeformat'];
  } catch (e) {
    var format = false;
  }

  if (format == false || format == undefined) {
    return date.format("dd.mm.yyyy");
  } else {
    return date.format(format);
  }
}

Object.extend(String.prototype, {
  ptruncate: function(length, hover)
  {
    if (hover == undefined)
      hover = false;

    var truncate = this.length > length;

    var output = '';

    if (truncate && hover == true) {
      output += '<span ';
      output += 'onmouseover="showTooltip(\'' + this.replace(/"/g, '&quot;').replace(/'/g, "\\'") + '\', \'podnapisi_release\');" onmouseout="hideTooltip();">';
    }

    output += this.truncate(length, '...');

    if (hover == true && truncate)
      output += '</span>';

    return output;
  },

  isNumeric: function()
  {
    return this.search(/^-?[0-9]+$/) == 0
  }

});
