function NUMBER_floorToDecimals(inValue, decimals)
{
    if (decimals == 0) {
        return Math.floor(inValue);
    } else {
        var p = Math.pow(10, decimals);
        return Math.floor(p * inValue)/p;
    }
}

function NUMBER_roundToDecimals(inValue, decimals)
{
    if (decimals == 0) {
        return Math.round(inValue);
    } else {
        var p = Math.pow(10, decimals);
        return Math.round(p * inValue)/p;
    }
}

function NUMBER_roundForPresentation(inValue, inExp, inWholes, inDecimals, inThousandSep, inThousandDec, inPreferNoExponent)
{
    outValue = inValue * Math.pow(10, inExp);
    outValueRounded = NUMBER_roundToDecimals(outValue, inDecimals);

    if (inValue==0)
    {
        out=0;
    }
    else
    {
        var isMinus = (outValue < 0) ? 1 : 0;
        var valAbs = Math.abs(outValue);
        var exp = 0;

        while (valAbs >= 10) {valAbs = 0.1 * valAbs; exp++;}
        while (valAbs <  1)  {valAbs = 10  * valAbs; exp-=1;}

        if (NUMBER_roundToDecimals(valAbs, inDecimals) >= 10)
        {
            valAbs = 0.1 * valAbs;
            exp++;
        }

        if (exp > -inDecimals)
        {
            var dec = 11 - exp;
            if (dec<0) dec=0;
            if (dec>inDecimals) dec=inDecimals;
            outValueRounded = NUMBER_roundToDecimals(outValue, dec);
        }
        else
        {
            outValueRounded = 'e';
        }

        var outStr = '' + outValueRounded;
        var isDot = (outStr.indexOf('.') >= 0) ? 1 : 0;
        if ((inPreferNoExponent)
            && (outStr.indexOf('e') == -1)
            && (outStr.length < (13 + isDot + isMinus))
            )
        {
            out = outValueRounded;
        }
        else
        {
            out = (isMinus)?'-':'';
            out = out + NUMBER_roundToDecimals(valAbs, inDecimals) +'\u00D7'+'10<sup>'+exp+'</sup>';
        }
    }
    return out;
}

function MONEY_floorToGroszy(inValue)
{
    return Math.floor(inValue * 100)*0.01;
}

function MONEY_roundTo10Groszy(inValue)
{
    return Math.floor((inValue * 10) + 0.5)*0.1;
}

function MONEY_roundToGroszy(inValue)
{
    return Math.floor((inValue * 100) + 0.5)*0.01;
}

function MONEY_roundToZloty(inValue)
{
    return Math.floor(inValue + 0.5);
}

function MONEY_ceilToZloty(inValue)
{
    return Math.ceil(inValue);
}

function MONEY_toString100Groszy(inValue)
{
    return inValue.toFixed(2);
}

function CENTS_numberToCents(inValue)
{
    return Math.floor(inValue*100);
}

function CENTS_centsToString(inValue)
{
    return (Math.floor(inValue)/100).toFixed(2);
}

function NUMBER_isDecimalFloat(txt)
{
    var validChars = '0123456789';
    var isNumber = 1;
    var onlyOneDot = 1;
    var len = txt.length;

    if (len == 0)
    {
        isNumber = 0;
    }

    for (var i = 0; (i < len) && (isNumber); i++)
    {
        var c = txt.charAt(i);
        if (c == '.')
        {
            if (onlyOneDot)
            {
                onlyOneDot = 0;
            }
            else
            {
                isNumber = 0;
            }
        }
        else if (c == '-')
        {
            if (i > 0)
            {
                isNumber = 0;
            }
        }
        else if (validChars.indexOf(c) == -1)
        {
            isNumber = 0;
        }
        else
        {
            onlyOneMinus = 0;
        }
    }
    return isNumber;
}

function NUMBER_parseInput(inValue)
{
    if (typeof inValue == "string")
    {
        var rv = inValue.replace(',', '.');
        rv = rv.replace(/ /g, '');
        if (NUMBER_isDecimalFloat(rv))
        {
            rv = parseFloat(rv);
        }
        else
        {
            rv = '';
        }
    }
    else if (typeof inValue == "number")
    {
        rv = inValue;
    }
    return rv;
}

function NUMBER_isParsedInputValid(parsedInValue)
{
    if (typeof parsedInValue == "string")
    {
        return 0;
    }
    return 1;
}

function DAYS_inMonth(y, m)
{
    if (m == 1)
        return ((y & 3) == 0) ? 29 : 28;

    if ((m == 3) || (m == 5) || (m == 8) || (m == 10))
        return 30;

    return 31;
}

function DAYS_YMD_Create()
{
}

function INPUT_getRadioValue(elementIdPrefix, defaultValue)
{
    var i = 0;
    var rv = defaultValue;
    while (document.getElementById(elementIdPrefix + i))
    {
        if (document.getElementById(elementIdPrefix + i).checked == 1)
        {
            rv = document.getElementById(elementIdPrefix + i).value;
            break;
        }
        i++;
    }
    return rv;
}

function PL_DopelniaczMiesiecy(months)
{
    var rv;

    if (months == 0)
    {
        rv = 'miesięcy';
    }
    else if (months == 1)
    {
        rv = 'miesiąc';
    }
    else if (months <= 4)
    {
        rv = 'miesiące';
    }
    else if (
        (((months % 100) >= 22) || ((months % 100) < 4))
        && ((months % 10) >= 2) && ((months % 10) <= 4))
    {
        rv = 'miesiące';
    }
    else
    {
        rv = 'miesięcy';
    }

    return rv;
}

var monthTxt = new Array('Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień');
