var MONTH_NAMES_SHORT = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];

function DisableSelection(AID)
{
  var LElement = document.getElementById(AID);
  LElement.onselectstart = function()
  {
    return false;
  };

  LElement.unselectable = "on";
  LElement.style.MozUserSelect = "none";
  LElement.style.cursor = "default";
}

function FormatMoney(amount, currency_sign_before,
  currency_sign_after, thousands_separator, decimal_point,
  significant_after_decimal_pt, display_after_decimal_pt)
{
    // Only display a minus if the final displayed value is going to be <= -0.01 (or equivalent)
    var str_minus = (amount * significant_multiplier <= -0.5 ? "-" : "");

    // Sanity check on the incoming amount value
    amount = parseFloat(amount);
    if( isNaN(amount) || Math.LOG10E * Math.log(Math.abs(amount)) +
            Math.max(display_after_decimal_pt, significant_after_decimal_pt) >= 21 )
    {
        return str_minus + currency_sign_before +
            (isNaN(amount)? "#" : "####################".substring(0, Math.LOG10E * Math.log(Math.abs(amount)))) +
            (display_after_decimal_pt >= 1?
                (decimal_point + "##################".substring(0, display_after_decimal_pt)) : "") +
            currency_sign_after;
    }

    var significant_multiplier = Math.pow(10, significant_after_decimal_pt);

    // Make +ve and ensure we round up/down properly later by adding half a penny now.
    amount = Math.abs(amount) + (0.5 / significant_multiplier);

    amount *= significant_multiplier;

    var str_display = parseInt(
        parseInt(amount) * Math.pow(10, display_after_decimal_pt - significant_after_decimal_pt) ).toString();

    // Prefix as many zeroes as is necessary and strip the leading 1
    if( str_display.length <= display_after_decimal_pt )
        str_display = (Math.pow(10, display_after_decimal_pt - str_display.length + 1).toString() +
            str_display).substring(1);

    var comma_sep_pounds = str_display.substring(0, str_display.length - display_after_decimal_pt);
    var str_pence = str_display.substring(str_display.length - display_after_decimal_pt);

    if( thousands_separator.length > 0 && comma_sep_pounds.length > 3 )
    {
        comma_sep_pounds += ",";

        // We need to do this twice because the first time only inserts half the commas.  The reason is
        // the part of the lookahead ([0-9]{3})+ also consumes characters; embedding one lookahead (?=...)
        // within another doesn't seem to work, so (?=[0-9](?=[0-9]{3})+,)(.)(...) fails to matchanything.
        if( comma_sep_pounds.length > 7 )
            comma_sep_pounds = comma_sep_pounds.replace(/(?=[0-9]([0-9]{3})+,)(.)(...)/g, "$2,$3");

        comma_sep_pounds = comma_sep_pounds.replace(/(?=[0-9]([0-9]{3})+,)(.)(...)/g, "$2,$3");

        // Remove the fake separator at the end, then replace all commas with the actual separator
        comma_sep_pounds = comma_sep_pounds.substring(0, comma_sep_pounds.length - 1).replace(/,/g, thousands_separator);
    }

    return str_minus + currency_sign_before +
        comma_sep_pounds + (display_after_decimal_pt >= 1? (decimal_point + str_pence) : "") +
        currency_sign_after;
}

function MM_findObj(n, d) //v4.0
{
  var p,i,x;
  if(!d)
    d = document;
  if((p = n.indexOf("?")) > 0 && parent.frames.length)
  {
    d = parent.frames[n.substring(p+1)].document;
    n = n.substring(0,p);
  }
  if(!(x = d[n]) && d.all)
    x = d.all[n];
  for (i = 0; !x && i<d.forms.length; i++)
    x = d.forms[i][n];
  for (i = 0; !x && d.layers && i < d.layers.length; i++)
    x = MM_findObj(n, d.layers[i].document);
  if (!x && document.getElementById)
    x = document.getElementById(n);
  return x;
}

function MM_preloadImages() //v3.0
{
  var d = document;
  if (d.images)
  {
    if(!d.MM_p)
      d.MM_p = new Array();
    var i,j = d.MM_p.length,
    a = MM_preloadImages.arguments;
    for (i = 0; i < a.length; i++)
      if (a[i].indexOf("#") != 0)
      {
        d.MM_p[j] = new Image;
        d.MM_p[j++].src = a[i];
      }
  }
}

function MM_swapImage() //v3.0
{
  var i,j = 0, x, a = MM_swapImage.arguments;
  document.MM_sr = new Array;
  for (i = 0; i < (a.length-2); i += 3)
    if ((x = MM_findObj(a[i])) != null)
    {
      document.MM_sr[j++] = x;
      if (!x.oSrc)
        x.oSrc = x.src;
      x.src = a[i+2];
    }
}

function MM_swapImgRestore() //v3.0
{
  var i,x,a = document.MM_sr;
  for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
    x.src=x.oSrc;
}

function OpacitySet(AElement, ALevel)
{
  AElement.style.opacity = ALevel;
  AElement.style.MozOpacity = ALevel;
  AElement.style.KhtmlOpacity = ALevel;
  AElement.style.filter = "alpha(opacity=" + (ALevel * 100) + ");";
}