

function FloatToPL(val, scale){
    val = Round2(new Number(val),scale);
    if (scale == null) scale = 2;
    var rb = new String(val);
    rb = rb.replace('.', ',');
    if (rb.indexOf(',') == -1 && scale > 0){
        rb += ',';
    } else {
        rb = rb.substr(0,rb.indexOf(',')+scale+1);
    }
    var i = rb.length;
    while (rb.lastIndexOf(',') >= rb.length - scale)
        rb += '0';
    return rb;
}

function PlToFloat(val){
    return new Number((new String(val)).replace(',', '.'));
}
function parseFloat2(val, scale){
    if (scale == null) scale = 2;
    var val2 = new String(val);
    var temp = new Number(val2.replace(',', '.'));
    scale = Math.pow(10, scale);
    return Math.round(temp * scale) / scale;
}
function Round2(val,scale){
    scale = Math.pow(10, scale)
    return (Math.round(val*scale)/scale);

}




function Debugger(tekst,nazwa){
    var win = window.open('','','height=300,width=400,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
    win.document.open();
    if (tekst != null)
        win.document.writeln((new String).varToString(tekst,nazwa));
    return win.document;
}
String.prototype.varToString = function(val,name){
    this._varToStrLevel++;
    var r = '&nbsp;';
    var temp = r.repeat((this._varToStrLevel-1)*3) + (name != '' ? name : '') + ' [' + typeof val + ']: ';

    if (typeof val == 'string')
        temp += val.toHtmlEntities();

    if (typeof val == 'number')
        temp += val;

    if (typeof val == 'boolean')
        temp += (val == true ? 'true' : 'false');

    if (typeof val == 'array' || typeof val == 'object')
        for (i in val)
            temp += this.varToString(val[i],i);

    if (typeof val != 'string' && typeof val != 'number' && typeof val != 'boolean' && typeof val != 'array' && typeof val != 'object' && val.toString != null)
        temp += val.toString();

    this._varToStrLevel--;
    return  ' <br>\r\n' + temp;
}
String.prototype._varToStrLevel = 0;

String.prototype.repeat = function(times){
    var temp = '';
    var i = 0
    for (i = 0 ; i < times ; i++)
        temp += this.toString();
    return temp;
}

String.prototype.toHtmlEntities = function(){
    var temp = this.toString();
    temp = temp.replace(/\</gi,'&#60;');
    temp = temp.replace(/\>/gi,'&#62;');
    temp = temp.replace(/\r\n/gi,'<br>');
    temp = temp.replace(/\n/gi,'<br>');
    temp = temp.replace(/\r/gi,'<br>');
    return temp;
}
