﻿//ograniczenie znaków w uwagach
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
// Menu

var defaultSubmenu = 'default';

function ToggleSubMenu(elem, id) {
    if (defaultSubmenu == 'default')
        defaultSubmenu = J('.submenu:visible:first').attr('id');

    J('.submenu').hide();

    J('#' + (id == '' ? defaultSubmenu : id)).show();

    //              if (el.length == 0)
    //                  J('#submenu_').show();
    //              else
    //    el.show();
}

function aktywuj(elem) {
    J(elem).children('.normal_a').removeClass('normal_a').addClass('green_span');
    J(elem).removeClass('normal_li').addClass('green_li');

}

function deaktywuj(elem) {
    J(elem).children('.green_span').removeClass('green_span').addClass('normal_a');
    J(elem).removeClass('green_li').addClass('normal_li');

}

// Buttony
function clickButton(e, buttonid) {
    var evt = e ? e : window.event;

    var bt = document.getElementById(buttonid);

    if (bt) {
        if (evt.keyCode == 13) {
            bt.focus();
            bt.click();
            return false;
        }
    }
}

function DoKoszyka(e) {
    var evt = e ? e : window.event;

    if (evt.keyCode == 13) {
        DodajDoKoszyka();
        return false;
    }
}

//Taby

function PrzelaczTab2(elem) {
    PrzelaczTab(elem, elem.getAttribute('tab_id'));
}

function PrzelaczTab(elem, id) {
    var ul = J(elem).parent().parent();
    ul.children('.h_green_r').each(function () { J(this).removeClass('h_green_r').addClass('h_gray_r'); })
    ul.children('.h_green_l').each(function () { J(this).removeClass('h_green_l').addClass('h_gray_l'); })

    J(elem).parent().removeClass('h_gray_r').addClass('h_green_r');
    J(elem).children(':first').removeClass('h_gray_l').addClass('h_green_l');

    ul.parent().children('.tab_content').hide();
    ul.parent().children('#' + id).show();
}

function PrzelaczTaby(elem) {
    var id = elem.getAttribute('tab_id');

    J(elem).parent().children('.tree_tab_active_l').attr('class', 'tree_tab_l');
    J(elem).parent().children('.tree_tab_active_r').attr('class', 'tree_tab_r');

    J(elem).prev().attr('class', 'tree_tab_active_l');
    J(elem).attr('class', 'tree_tab_active_r');

    J(elem).parent().parent().children('.tree_tab_elem').hide();
    J(elem).parent().parent().children('#' + id).show();
}

//document.body.clientHeight/Width   
//document.documentElement.­clientHeight/Width

function PozycjaOkienkaX() {
    var el = document.getElementById('right');

    return (document.documentElement.clientWidth - 755) / 2;  //el.offsetLeft + 2;
}
function PozycjaOkienkaY() {
    var el = document.getElementById('right');

    return ((document.documentElement.clientHeight - 585) / 2 + 60); //+50;  //-15;  //el.offsetTop;
}

var popupWindow = null;
function centeredPopup(url, winName, w, h, scroll) {
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0; TopPosition = 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',location=no,status=no,directories=no,resizable';
    popupWindow = window.open(url, winName, settings);
}

function pop_prom(id) {
    var h = '320';
    try { var tmp = document.getElementById('hidPopupWidth').value; if (tmp != '') h = tmp; } catch (e) { }

    centeredPopup('SaleRules.aspx?id=' + id, 'Platforma_B2B_Prom', '480', h, 'yes'); 
}

var poped = false;
var pop_id = 1;
function pop(id, t) {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var usr = '', h = '625';
    try { usr = document.getElementById('hidUserQS').value; } catch (e) { }
    usr = usr != '' && usr != undefined && usr != null ? '&u=' + usr : '';
    try { var tmp = document.getElementById('hidPopupWidth').value; if (tmp != '') h = tmp; } catch (e) { }

    if (id == undefined)
        id = J(el).parent().attr('i');
    if (id == undefined)
        id = J(el).parent().parent().attr('i');
    try {
        if (t == undefined && parent.location.href.indexOf('ProductDetails.aspx') == -1)
            t = 3;
    } catch (ex) { }
    centeredPopup('ProductDetails.aspx?id=' + id + (t == undefined ? '' : '&t=' + t) + usr
        , 'Platforma_B2B' + pop_id, '1000', h, 'no'); //return false;

    ++pop_id;

    //J.post('MainHandler.ashx', { cmd: 'popup_get', productId: id, customerId: txt_customerId }, OpenPopupCallback);
    //nd();
}

function OpenPopupCallback(data, text) {
    if (data == '0')
        return;

    nd();

    document.getElementById('container').style.opacity = '0.4';
    document.getElementById('container').style.filter = 'filter: alpha(opacity = 40)';

    poped = true;

    return overlib(data, STICKY, RELX, PozycjaOkienkaX(), RELY, PozycjaOkienkaY());
}

function ClosePopup() {
    document.getElementById('container').style.opacity = '1';
    document.getElementById('container').style.filter = 'filter: alpha(opacity = 100)';
    nd();

    poped = false;

    return nd();
}

function ChangeImage(medium, large, min) {
    J("#imgMain").attr('src', medium);
}
function checkForInt(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode; //alert(charCode);
    var b = (charCode <= 31 || (charCode >= 48 && charCode <= 57) || charCode == 46 || charCode == 44);
    //alert(b);
    return b;
}


String.format = function (text) {
    if (arguments.length <= 1)
        return text;
    var tokenCount = arguments.length - 2;

    for (var token = 0; token <= tokenCount; token++) {
        text = text.replace(new RegExp('\\{' + token + '\\}', 'gi'), arguments[token + 1]);
    }
    return text;
};

function ValidateOrder(elem) {
    var res = true;

    J(elem).prevAll('table').find('.valid').each(function (i) {
        if (J(this).attr('value') == '0') {
            J(this).next().show();
            res = false;
        }
        else
            J(this).next().hide();
    });

    return res;
}

function onTreeItemClick(el) {
    J('.kategorie .active').removeClass('active');
    J(el).addClass('active');
}

function on(src) {
    if (!poped) {
        var e = window.event || arguments.callee.caller.arguments[0];
        var el = target(e);
        var imageHeight = 300;
        var of = 0;
        var fromBottom = 0;
        var windowHeight = navigator.appName.indexOf("Microsoft") != -1 ? parent.document.body.offsetHeight : parent.window.innerHeight;
        var iframeStart = J(parent.document.getElementById('frmRight')).position().top;
        var filtersHeight = 0; // J(document.getElementById('top_box_div')).height();
        var iframeScroll = 0; //  J(document.documentElement).scrollTop();     
        var iframeHeight = windowHeight - iframeStart - filtersHeight;  // J('body').height();
        src = src.replace(/ /g, '%20').replace(/\\/g, '\/');

        if (iframeHeight < 300) {
            src = src.replace('_t3', '_t2');            
            imageHeight = 150;
            of += 25;
        }

        //var fromBottom = iframeHeight - getPosition(e).y;

        var y = iframeStart + e.clientY - iframeScroll;

        fromBottom = windowHeight - y - filtersHeight;

        var pos = fromBottom < imageHeight ? -imageHeight + fromBottom - of : -10;
        //J(el).next().next().html(fromBottom + ' ' + windowHeight + ' ' + y + ' ' + e.clientY + ' ' + iframeScroll);
        return overlib('<img class=popup_image src=' + src + ' />', OFFSETY, pos);
    }
}
function off(src) {
    if (!poped) return nd();
}

function fil(n, v, url) {


    var frm = J('#frmRight');
    var s = frm.attr('src');

    if (s != undefined) {

        var qs = getQsFromUrl(s);
        if (url == undefined || url == null) {
            url = s.replace(qs, '');
        }
        qs = setUrlEncodedKey('pc', cur_page, qs);
     //   alert((url != undefined && url != null ? url : 'OfferMain.aspx') + setUrlEncodedKey(n, v, qs));
        frm.attr('src', (url != undefined && url != null ? url : 'OfferMain.aspx') + setUrlEncodedKey(n, v, qs));
    }
    else {
        var qs = getQsFromUrl(document.location.href);
        qs = setUrlEncodedKey('pc', cur_page, qs);
        document.location.href = (url != undefined && url != null ? url : 'OfferMain.aspx') + setUrlEncodedKey(n, v, qs);
    }
}
function sort(asc) {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var v = J(el);

    if (v.attr('s') == undefined) v = v.parent();
    if (v.attr('s') == undefined) v = v.parent();

    if (asc == undefined) asc = 'asc';

    var u = setUrlEncodedKey('s', v.attr('s'));
    u = setUrlEncodedKey('d', asc, u);

//    alert(u);
       parent.document.getElementById('frmRight').src = 'OfferMain.aspx'+ u;
   // alert(document.location.href);
    document.location.search = u;
}
function nv(q, add) {
    if (add == false)
        location.search = q;
    else {
        //        var qs = location.search.substring(1);
        //        location.href += (qs ? '&' : '?') + q;
    }
}


function getQsFromUrl(url) {
    return url.substring(url.indexOf('?'), url.length);
}
function target(evt) {
    var target = evt.target || evt.srcElement;

    return target;
}

// ustawianie querystringow

function getUrlEncodedKey(key, query) {
    if (!query)
        query = window.location.search;
    var re = new RegExp("[?|&]" + key + "=(.*?)&");
    var matches = re.exec(query + "&");
    if (!matches || matches.length < 2)
        return "";
    return decodeURIComponent(matches[1].replace("+", " "));
}
function setUrlEncodedKey(key, value, query) {

    query = query || window.location.search;
    var q = query + "&";
    var re = new RegExp("[?|&]" + key + "=.*?&");
    if (!re.test(q))
        q += key + "=" + encodeURI(value);
    else
        q = q.replace(re, "&" + key + "=" + encodeURIComponent(value) + "&");
    q = q.trimStart_("&").trimEnd_("&");
    var w = q[0] == "?" ? q : q = "?" + q;

    return w.replace("??", "?");
}

String.prototype.trimEnd_ = function (c) {
    if (c)
        return this.replace(new RegExp(c.escapeRegExp() + "*$"), '');
    return this.replace(/\s+$/, '');
}
String.prototype.trimStart_ = function (c) {
    if (c)
        return this.replace(new RegExp("^" + c.escapeRegExp() + "*"), '');
    return this.replace(/^\s+/, '');
}

String.prototype.escapeRegExp = function () {
    return this.replace(/[.*+?^${}()|[\]\/\\]/g, "\\$0");
};


// pozycja kursora
function getPosition(e) {
    e = e || window.event;
    var cursor = { x: 0, y: 0 };
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        cursor.x = e.clientX +
            (document.documentElement.scrollLeft ||
            document.body.scrollLeft) -
            document.documentElement.clientLeft;
        cursor.y = e.clientY +
            (document.documentElement.scrollTop ||
            document.body.scrollTop) -
            document.documentElement.clientTop;
    }
    return cursor;
}

//function Opakowanie(obj) {
//    var ilosc = parseFloat(J(obj).parent().parent().attr('o').replace(',','.'));
//    var unit = '';
//    try
//    {
//        unit = J(obj).parent().parent().children('.unit').html();
//    }
//    catch (err) {unit=''; }
//    if (ilosc > 1) {
//        var nleft = 0;
//        var ntop = 0;
//        if (obj.offsetParent) {
//            nleft = obj.offsetLeft
//            ntop = obj.offsetTop
//            while (obj = obj.offsetParent) {
//                nleft += obj.offsetLeft
//                ntop += obj.offsetTop
//            }
//        }
//        if (unit != '' && unit != 'szt.') {
//            return OpakowaniePokaz2(ilosc, nleft, ntop, unit);
//        }
//        else {
//            
//            return OpakowaniePokaz(ilosc, nleft, ntop, unit);
//        }
//    }
//    else if (unit != '' && unit != 'szt.') {
//        return OpakowaniePokaz3(ilosc, nleft, ntop, unit);
//    }
//    else
//        return nd();
//}//wrsja bioplanet

function Opakowanie(obj) {
    var ilosc = parseFloat(J(obj).parent().parent().attr('o').replace(',','.'));
    if (ilosc > 1) {
        var nleft = 0;
        var ntop = 0;
        if (obj.offsetParent) {
            nleft = obj.offsetLeft
            ntop = obj.offsetTop
            while (obj = obj.offsetParent) {
                nleft += obj.offsetLeft
                ntop += obj.offsetTop
            }
        }
        return OpakowaniePokaz(ilosc, nleft, ntop);
    }
    else
        return nd();
}
function Jednostka(obj) {

    var przelicznik = J(obj).parent().children('.qu').attr('value');
    var jednostka = J(obj).parent().children('.qu').children(':first').text(); // .attr('value');
    var zamowione = J(obj).val();
    var ilosc = roundNumber(przelicznik * zamowione, 2);
    if (ilosc % 10 > 5) {
        ilosc = Math.ceil(ilosc);
    }
    else {
        ilosc = Math.floor(ilosc);
    }
    if (przelicznik > 1 && zamowione > 0) {
        var nleft = 0;
        var ntop = 0;
        if (obj.offsetParent) {
            nleft = obj.offsetLeft
            ntop = obj.offsetTop
            while (obj = obj.offsetParent) {
                nleft += obj.offsetLeft
                ntop += obj.offsetTop
            }
        }
        return JednostkaPokaz(ilosc, nleft, ntop, jednostka);
    }
    else
        return nd();
}
function Konfekcja(obj) {
    var val = parseFloat(J(obj).attr('prc' + J(obj).attr('selectedIndex')));

    if (val != 1) {
        var nleft = 0;
        var ntop = 0;
        if (obj.offsetParent) {
            nleft = obj.offsetLeft
            ntop = obj.offsetTop
            while (obj = obj.offsetParent) {
                nleft += obj.offsetLeft
                ntop += obj.offsetTop
            }
        }
        return KonfekcjaPokaz(roundNumber(roundNumber(val - 1, 4) * 100, 2) + '%', nleft, ntop);
    }
    else {
        nd();
        return nd();
    }
}

// jednostki miary
function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
function UnitChanged(el) {
    el = J(el).attr('value') == undefined ? target(window.event || arguments.callee.caller.arguments[0]) : el;
    var v = J(el).parent();
    var ile = v.children('.Hile');
    
    // zmiana ilości
    var p_quantity = J(el).attr('value').toString().replace(',', '.');
    if (p_quantity == 0 || p_quantity == '0') {
        el.selectedIndex = 0;
        return;
    }

    var prv_quantity = 1;
    if (ile.attr('prv') != undefined)
        prv_quantity = ile.attr('prv').toString().replace(',', '.');

    ile.attr('prv', p_quantity);
    var f = roundNumber(parseFloat(ile.attr('value').replace(',', '.')) / (parseFloat(p_quantity) / parseFloat(prv_quantity)), 4);
    //    if (p_quantity == 1) {

    //        if (f % 10 > 5) {
    //            f = Math.ceil(f);
    //        }
    //        else {
    //            f = Math.floor(f);
    //        }
    //   }

    if (f == NaN || f == 'NaN' || !(f > 0)) f = '';

    ile.attr('value', f);


    // zmiana ceny
    var vv = v.parent().find('.prc');
    if (J(el).attr('prc0') != undefined && vv.size() > 0) {
        if (vv.attr('prv') == undefined)
            vv.attr('prv', J(el).attr('prc'+ J(el).attr('p_')));

        var prv_price = vv.attr('prv');
        var p_price = J(el).attr('prc' + J(el).attr('selectedIndex'));
        vv.attr('prv', p_price);

        if (vv.attr('value') == undefined) {
            vv.html(roundNumber(parseFloat(vv.html().replace(',', '.')) * (parseFloat(p_quantity) / parseFloat(prv_quantity)) * (parseFloat(p_price) / parseFloat(prv_price)), 2).toFixed(2));
            bsk_Change(3, vv, vv.html());
        }
        else {
            vv.attr('value', roundNumber(parseFloat(vv.attr('value').replace(',', '.')) * (parseFloat(p_quantity) / parseFloat(prv_quantity)), 2).toFixed(2));
            vv.attr('min', roundNumber(parseFloat(vv.attr('min').replace(',', '.')) * (parseFloat(p_quantity) / parseFloat(prv_quantity)), 2).toFixed(2));
        }
    }

    // popup z informacją o konfekcji
    Konfekcja(el);
}
function SetInbox() {
    var el = target(window.event || arguments.callee.caller.arguments[0]);

    var v = J(el).parent();
    var ile = v.children('.Hile');
    var sel = v.children('select.qu');

    sel.attr('selectedIndex', 0);
    ile.attr('value', J(el).attr('v'));
}


function DeleteCookies() {
    Delete_Cookie('b2b_user', '/', '');
    Delete_Cookie('b2b_pass', '/', '');
}

function Get_Cookie(check_name) {
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for (i = 0; i < a_all_cookies.length; i++) {
        a_temp_cookie = a_all_cookies[i].split('=');

        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        if (cookie_name == check_name) {
            b_cookie_found = true;

            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }

            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}


function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
            ((path) ? ";path=" + path : "") +
            ((domain) ? ";domain=" + domain : "") +
            ";expires=Thu, 01-Jan-2020 00:00:01 GMT";
}

function SaveWebSetting(key, value) {
    J.post('MainHandler.ashx', { cmd: 'web_setting', key: key, value: value, customerId: txt_customerId });
}


function frmLeftIE() {
    var v = document.getElementById('frmLeft'); //alert(v.height);alert('src' + v.src);
    if (v.src.indexOf('LeftFrame.aspx') == -1 || v.height < 30) { v.height = 1; v.height = 0; }
}
function setTitle(txt) {
    var v = parent.document.getElementById('content_title');
    if (v != null)
        v.innerHTML = txt;
}
function Hide(hide, id) {
    if (hide)
        J(id).hide();
    else
        J(id).show();
}

function Search2() {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var query = J(el).parent().find('.search_txt').attr('value');
    J(el).parent().find('.search_txt').attr('value', '');
    if (query.length < 2) return;
    var id = J('#searchCategory').attr('catId');
    var qId = J('#chbSearchCategory').attr('checked') ? '&id=' + id : '';

    nav('frmRight', 'OfferMain.aspx?url=Search.aspx&q=' + query + qId);
}
function Search2_(link) {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var query = J(el).parent().find('.search_txt').attr('value');
    if (query.length < 2) return;
    //var id = J('#searchCategory').attr('catId');
    //var qId = J('#chbSearchCategory').attr('checked') ? '&id=' + id : '';

    location.href = link + query;
}
function tgl() {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var v = J(el);
    if (!v.hasClass('title_l') && !v.hasClass('title_r') && !v.hasClass('title_text') && !v.hasClass('title_m'))
        return;

    while (true) {
        if (v.hasClass('title_l'))
            break;
        v = v.parent();
    }

    var n = v.next();
    if (n.is(':visible')) {
        v.removeClass('m').addClass('m');
        n.hide();
    }
    else {
        v.removeClass('m');
        n.show();
    }

    //parent.resizeIframe('frmMain');
}
function upleft(id) {
    var v = J('.tree_box.kategorie');
    var a = v.find(id);

    var s = a.attr('t').split(';');

    for (var i = 0; i < s.length; ++i) {
        if (s[i] == '') continue;

        var b = v.find('#' + s[i]);
        b = b.children();
        if (!b.hasClass('ex')) b.click();
    }

    v.find('.active').removeClass('active');
    a = a.children();
    if (!a.hasClass('ex')) a.click();
}
function addEvt(f) {
    if (window.addEventListener) // W3C standard
    {
        window.addEventListener('load', f, false); // NB **not** 'onload'
    }
    else if (window.attachEvent) // Microsoft
    {
        window.attachEvent('onload', f);
    }
}
// zatrzymuje wykonywanie eventu
function stp(e) { if (typeof e.stopPropagation != 'undefined') e.stopPropagation(); if (typeof e.cancelBubble != 'undefined') e.cancelBubble = true; }
function changeUrl(url) {
    document.location = url;
}

function srccat(catId, el) {
    try {
        J('#searchCategory').html(J(el).find('.cn').html()).attr('catId', catId);
        J('#search_category').css('visibility', 'visible');
    } catch (ex) { }
}
var cur_page = 1;
function UpdatePages(pn, pc) {
    //alert('UpdatePages');
    var s = '';
    var v = J("#cmbPageCurrent");

    if (pn < 2) {
        v.hide();
        return;
    }

    v.show();

    for (var i = 1; i <= pn; ++i) {
        s += '<option value="' + i + '">' + i + '</option>';
    }

    v.html(s);
    v.val(pc);
}
function ToggleTitleParams(show) {
    if (show == 1)
        J('.content_title_r').css('visibility', 'visible');
    else
        J('.content_title_r').css('visibility', 'hidden');
}


// ############################## Nowy KOSZYK ##############################
var bsk_block = false;
function bsk_Uwagi(id) {
    J(id).show();
    J(id).css('height', J('#tb1').css('height'));
}
function bsk_Start() {
    bsk_block = true;

    // skopiowanie promocji polecanych na dół koszyka
    if (J('.prom_basket').html() != null)
        J('.bsk_inf').html('<div class="prom_basket">' + J('.prom_basket').html() + '</div>' + J('.bsk_inf').html());

    // kontrolka plus - minus
    J.spin.imageBasePath = '/Scripts/spin/img/spin2/'; J('.Hile').spin({ interval: 1, min: 0 });

    // ukrycie linków: wróć do oferty
    if ((parent.url_2 && parent.url_2.indexOf('OfferMain.aspx') == -1) || (!parent.url_2 && parent.document.location.search.indexOf('OfferMain.aspx') == -1))
        J('.bsk_back').hide();

    // ustawianie przekroczonych stanów (red row)
    var states_over = J('#bsk_states_over');
    J('#axc1 .Hile, #axc2 .Hile').each(function () { bsk_CheckState(this, states_over, 0); });
    if (J('#axc1 tr.red').size() > 0) { states_over.show(); if (v_basket_states_over_hide_btn == '1') J('#btnOrder').hide(); }
    else { states_over.hide(); if (v_basket_states_over_hide_btn == '1') J('#btnOrder').show(); }

    // ustawianie aktywnego koszyka
    if (Get_Cookie('b2b_basket_1_' + txt_customerId))
        J('#bsk_list').attr('value', Get_Cookie('b2b_basket_1_'+ txt_customerId));
    if (Get_Cookie('b2b_basket_2_' + txt_customerId))
        J('#bsk_list2').attr('value', Get_Cookie('b2b_basket_2_'+ txt_customerId));    
    J('#hidNewId2').attr('value', J('#bsk_list2').attr('value'));

    // ustawianie parametrów
    var pars = unescape(getUrlEncodedKey('pars'));
    if (pars == '')
        pars = unescape(J('#hidParameters').attr('value'));
    if (pars != '') {
        var p = pars.split('||');
        for (var i = 0; i < p.length; ++i) {
            if (p[i] == '') continue;
            var pp = p[i].split('^');
            J('#b' + pp[0]).attr('value', pp[1]);
        }
    }

    bsk_block = false;
    J('.Hile').bind('focus', function(){this.select();});
    var vv = J('#axc1 .Hile');
    vv.bind('change', function(){bsk_CheckState(this);});
    J('.p_td input').bind('change', function(){bsk_CheckAgentPrice(this);});
    J('#axc2 .Hile, .p_td input').bind('keypress', function(){if(!checkForInt(window.event || arguments.callee.caller.arguments[0])) {return false;}});
    vv.bind('change', function () { Jednostka(this); });
    vv.bind('keyup', function () { Jednostka(this); });
    vv.bind('focus', function () { Opakowanie(this); });
    vv.bind('blur', function () { return nd(); });
    var vvv = J('#axc1 .q_td select'); vvv.bind('change', bsk_UnitChanged); vvv.bind('blur', function () { nd(); return nd(); });

}
// action: 1 = sortuj, 2 = zapisz, 3 = wyślij, 4 = usuń, 5 = zmien koszyk, 6 = aktywuj koszyk, 7 = dodaj koszyk, 8 = usuń koszyk
// , 9 = zmien przechowalnie, 10 = usuń z przechowalni, 11 = usun przechowalnie, 12 = anuluj zamowienie do akceptacji
function bsk_Zapisz(action) {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var query_string = document.location.search;
    if (action == 1)
        query_string = bsk_Sort(el, query_string);
    query_string = bsk_Pars(el, query_string);
    query_string = bsk_Action(el, query_string, action);
    query_string = bsk_Products(el, query_string, action);
    query_string = bsk_ParsBaskets(el, query_string, action);

    //alert(unescape(query_string));
    // parent.document.getElementById('frmMain').src = 'Offer.aspx'+ u;
    //  document.location.search = query_string; // escape(query_string);
    J('#hidItm').attr('value', query_string);
    //alert(J('#hidItm').attr('value'));
    document.forms['aspnetForm'].submit();
}

var bsk_tab = 1;
function bsk_Action(el, query_string, action) {
    query_string = setUrlEncodedKey('act', action, query_string);
    query_string = setUrlEncodedKey('con', J('#hidConfirm').attr('value'), query_string);
    query_string = setUrlEncodedKey('tab', bsk_tab, query_string);

    return query_string;
}
function bsk_Pars(el, query_string) {
    var bsk_pars = '';

    J('.bsk_par').each(function () {
        var v = J(this).attr('type') == 'checkbox' ? (J(this).attr('checked') == true ? '1' : '0') : J(this).attr('value');
        bsk_pars += J(this).attr('p') + '^' + v.toString().replace(/\^/g,'') + '||';
    });

    query_string = setUrlEncodedKey('pars', escape(bsk_pars), query_string);

    return query_string;
}
function bsk_Sort(el, query_string) {
    var v = J(el);

    if (v.attr('s') == undefined) v = v.parent();
    if (v.attr('s') == undefined) v = v.parent();

    query_string = setUrlEncodedKey('s', v.attr('s'), query_string);
    query_string = setUrlEncodedKey('d', v.attr('d'), query_string);

    return query_string;
}
function bsk_Products(el, query_string, action) {
    if (action == 5 || action == 7 || action == 8 || action == 9 || action == 11)
        return query_string;
    
    if (action == 4)
        J('#axc1 .chbS:checked').each(function () { bsk_Change(4, this); })
    if (action == 10)
        J('#axc2 .chbS:checked').each(function () { bsk_Change(4, this); })

    query_string = setUrlEncodedKey('cha', changes.serialize('||'), query_string);

    return query_string;
}
function bsk_ParsBaskets(el, query_string, action) {
    var bsk_pars = '';

    var newId = J('#hidNewId1').attr('value');
    if(newId != undefined && newId != '' && newId != 0)
        query_string = setUrlEncodedKey('id', newId, query_string);
    newId = J('#hidNewId2').attr('value');
    if (newId != undefined && newId != '' && newId != 0)
        query_string = setUrlEncodedKey('id2', newId, query_string);

    if (action == 7) {
        var n = prompt(txt_AddBasket);
        query_string = setUrlEncodedKey('new', escape(n == null ? '' : n), query_string);
    }
    else if (action == 5) {
        var id = J('#bsk_list').attr('value');
        query_string = setUrlEncodedKey('id', id, query_string);
        query_string = setUrlEncodedKey('pars', '', query_string);
        query_string = setUrlEncodedKey('cha', '', query_string);
        Set_Cookie('b2b_basket_1_' + txt_customerId, id, '', '/', '', '');
    }
    else if (action == 9) {
        var id2 = J('#bsk_list2').attr('value');
        query_string = setUrlEncodedKey('id2', id2, query_string);
        query_string = setUrlEncodedKey('pars', '', query_string);
        query_string = setUrlEncodedKey('cha', '', query_string);
        Set_Cookie('b2b_basket_2_' + txt_customerId, id2, '', '/', '', '');
    }
    else if (action == 11) {
        Delete_Cookie('b2b_basket_2_' + txt_customerId);
    }

    return query_string;
}

Array.prototype.search = function (o) {
    for (var i = 0; i < this.length; i++) {
        //alert(this[i]);
        if (this[i].toString().indexOf(o) != -1)
            return i;
    }
    return -1;
}
Array.prototype.serialize = function (o) {
    var result = '';
    for (var i = 0; i < this.length; i++) {
        result += this[i] + o;
    }
    return result;
}
var changes = new Array();
// type: 1 = ilosc, 2 = jednostki miary, 3 = cena, 4 = usuwanie, 5 cena zbiorczo
function bsk_Change(type, el, value) {
    if (bsk_block)
        return;
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);
    var basketId = 0;

    if (type == 5) {
        basketId = J('#bsk_price_change select').val();
    }
    else {
        var v = J(el).parent();
        if (v.attr('b') == undefined) v = v.parent();
        if (v.attr('b') == undefined) v = v.parent();
        if (v.attr('b') == undefined) v = v.parent();
        if (v.attr('b') == undefined) throw 'Brak parametru: koszyk_id.';
        basketId = v.attr('b');
    }

    if (value == undefined) {
        value = J(el).attr(type == 2 ? 'selectedIndex' : 'value');        
        if (type == 1) value = (parseFloat(value.toString().replace(',','.')) * parseFloat(J(el).attr('prv')));
    }

    value = value.toString();
    value = parseFloat(value.replace(',', '.'));

    if (value == NaN || value.toString() == 'NaN')
        value = 0;
    
    var ii = changes.search(basketId + '^' + type);
    if (ii != -1)
        changes[ii] = basketId + '^' + type + '^' + value;
    else
        changes.push(basketId + '^' + type + '^' + value);
}

function bsk_UnitChanged() {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    UnitChanged(el);
    bsk_Change(2, el);

}

function bsk_CheckState(el, comment, recur) {
    try {
        if (v_basket_states_over != '0') {
            var txt = J(el);
            var prv = 1;
            var b = false;
            if (!comment) { b = true; comment = J('#bsk_states_over'); };

            if (txt.attr('prv') != undefined)
                prv = txt.attr('prv');

            var val = parseFloat(txt.attr('value')) * parseFloat(prv);
            var stan = parseFloat(txt.attr('p2'));
            if (val > stan) {
                txt.parent().parent().removeClass('red').addClass('red');

                if (b && J('#axc1 tr.red').size() > 0) {
                    comment.show();
                    if (v_basket_states_over_hide_btn == '1') J('#btnOrder').hide();
                }

                // zamienianie stanu produktu na liczbe
                if (stan >= 0) {
                    if (txt_basekt_states_over_no != '0') {
                        var il = txt.parent().parent().find('.Hilosc');
                        il.hide();
                        il.parent().html('<div class="' + il.attr('class') + ' 2_">' + stan + '</div>' + il.parent().html());
                    }
                }
            }
            else {
                txt.parent().parent().removeClass('red');

                // przywracanie stanu produktu
                if (txt_basekt_states_over_no != '0') {
                    var il = txt.parent().parent().find('.Hilosc');
                    il.show();
                    il = txt.parent().parent().find('.Hilosc.2_');
                    il.hide();
                }
                if (b && J('#axc1 tr.red').size() == 0) {
                    comment.hide();
                    if (v_basket_states_over_hide_btn == '1') J('#btnOrder').show();
                }
                //            b = true;
                //            var bb = true;
                //            if ( recur == 1)
                //                J('#axc1 .Hile').each(function () { var bbb = bsk_CheckState(this, comment, 0); if (!bbb) { alert('ta'); bb = false; } });
                //            else
                //                bb = false;
                //            if(bb)
                //                comment.hide();
            }
        }
    } catch (ex) { }

    bsk_Change(1, el);

    return b;
}
function bsk_CheckAgentPrice(el) {
    // sprawdz czy cena wpisana jest mniejsza niż minimalna cena
    var min = 0;
    try { min = parseFloat(J(el).attr('min')); } catch (ex) { }
    var val = parseFloat(J(el).attr('value'));
    if (val < min) {
        //alert('Minimalna cena dla tego produktu to: '+ min);
        J(el).attr('value', min.toFixed(2));
    }

    bsk_Change(3, el);
}
function bsk_CheckAll(el, parent, d) {
    J(parent +' .chbS').each(function () {
        if (el.checked) {
            if (!this.checked)
                this.checked = true; ;
        }
        else {
            if (this.checked)
                this.checked = false;
        }
    })
    if (el.checked)
        J(d).removeClass('dis');        
    else
        J(d).removeClass('dis').addClass('dis');
}
function bsk_Check(el, parent, d) {
    var unchecked = true;
    J(parent + ' .chbS').each(function () {
        if (this.checked)
            unchecked = false;
    });
    if(unchecked)
        J(d).removeClass('dis').addClass('dis');
    else
        J(d).removeClass('dis');
}

function bsk_Pop(id) {
    var el = target(window.event || arguments.callee.caller.arguments[0]);
    var h = '670';
    try { var tmp = document.getElementById('hidPopupHeight').value; if (tmp != '') h = tmp; } catch (e) { }

    if (id == undefined)
        id = J(el).parent().attr('i');
    if (id == undefined)
        id = J(el).parent().parent().attr('i');

    centeredPopup('RetailOffer.aspx?id=' + id, 'Platforma_B2B', '1000', h, 'yes'); //return false;
}

// NOWA TABELKA
// konta
var acc_p0, acc_p1, acc_p2, acc_p3, acc_p4, acc_p5, acc_p6, acc_p7, acc_p8, acc_p9; 
function acc_Dodaj(el) {
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);
    var el = J(el).parent().parent();
    var invalid = false;

    acc_p0 = J('#hidCustomerId').attr('value');
    if (!tbl_PobierzParametry(el.find('.1'))) invalid = true;
    acc_p1 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.2'))) invalid = true;
    acc_p2 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.3'))) invalid = true;
    acc_p3 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.4'))) invalid = true;
    acc_p4 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.5'))) invalid = true;
    acc_p5 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.6'))) invalid = true;
    acc_p6 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.7'))) invalid = true;
    acc_p7 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.8'))) invalid = true;
    acc_p8 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.9'))) invalid = true;
    acc_p9 = tbl_val;

    if (invalid) return false;

    J.post('Post.aspx', { sql: 'select count(*) from klienci where email = ' + acc_p2, typ: '2'
    }, acc_SprawdzUnikalnoscEmailCallback);

    return true;
}
function acc_DodajCallback(data, text) { document.location.search = setUrlEncodedKey('tab', '1', document.location.search); }
function acc_SprawdzUnikalnoscEmailCallback(data, text) {
    if (data == '0')
        J.post('Post.aspx', { sql: 'insert into klienci(klient_nadrzedny_id, nazwa, symbol, email, telefon, haslo, haslo_odkryte, subkonto_grupa_id, konto_potwierdzajace_id, adres_wysylki_id, adres_wysylki_blokada, promocje)'
            + ' values(' + acc_p0 + ', ' + acc_p1 + ', \'\', ' + acc_p2 + ', ' + acc_p3 + ', ' + acc_p4 + ', ' + acc_p4 + ', ' + acc_p5 + ', ' + acc_p6 + ', ' + acc_p7 + ', ' + acc_p8 + ', ' + acc_p9 + ');update klienci set zrodlo_id=-klient_id '
            + ' where klient_id=IDENT_CURRENT(\'klienci\')', typ: '1'
        }, acc_DodajCallback);
    else
        alert((txt_EmailNotUnique == undefined ? 'Podany adres email jest już zajęty: ' : txt_EmailNotUnique ) + acc_p2.replace(/'/g,""));
}

// adresy
function adr_Dodaj(el) {
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);
    var el = J(el).parent().parent();
    var invalid = false;

    var p0 = J('#hidCustomerId').attr('value');
    if (!tbl_PobierzParametry(el.find('.1'))) invalid = true;
    var p1 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.2'))) invalid = true;
    var p2 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.3'))) invalid = true;
    var p3 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.4'))) invalid = true;
    var p4 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.5'))) invalid = true;
    var p5 = tbl_val;

    if (invalid) return false;

    J.post('Post.aspx', { sql: 'insert into adresy(klient_id, nazwa, ulica_nr, miasto, kod_pocztowy, kraj)'
        + ' values(' + p0 + ', ' + p1 + ', ' + p2 + ', ' + p3 + ', ' + p4 + ', ' + p5 + ')', typ: '1'}, adr_DodajCallback);

    return true;
}
function adr_DodajCallback(data, text) { document.location.search = setUrlEncodedKey('tab', '3', document.location.search); }

// grupy subkont
function acg_Dodaj(el) {
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);
    var el = J(el).parent().parent();
    var invalid = false;

    acc_p0 = J('#hidCustomerId').attr('value');
    if (!tbl_PobierzParametry(el.find('.1'))) invalid = true;
    acc_p1 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.2'))) invalid = true;
    acc_p2 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.3'))) invalid = true;
    acc_p3 = tbl_val;
    if (!tbl_PobierzParametry(el.find('.4'))) invalid = true;
    acc_p4 = tbl_val;

    if (invalid) return false;

    J.post('Post.aspx', { sql: 'insert into subkonta_grupy(klient_id, nazwa, limit_ilosci_zamowien, limit_wartosci_zamowien, limit_okres)'
            + ' values(' + acc_p0 + ', ' + acc_p1 + ', ' + acc_p2 + ', ' + acc_p3 + ', ' + acc_p4 + ');', typ: '1'
    }, acg_DodajCallback);

    return true;
}
function acg_DodajCallback(data, text) { document.location.search = setUrlEncodedKey('tab', '4', document.location.search); }

// tabelka
function tbl_Usun(el, table_name, table_id) {
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);
    var el = J(el).parent().parent();
    var invalid = false;

    var p0 = J('#hidCustomerId').attr('value');
    if (!tbl_PobierzParametry(el.find('.1'))) invalid = true;
    var p1 = tbl_val;
    
    J.post('Post.aspx', { sql: 'delete from '+ table_name +' where '+ table_id +' = '+ tbl_id, typ: '1'}, tbl_UsunCallback);

    return true;
}
function tbl_UsunCallback(data, text) { document.location.search = setUrlEncodedKey('tab', '3', document.location.search); }
function tbl_Zapisz(el, table_name, table_id) {
    if (el == undefined) el = target(window.event || arguments.callee.caller.arguments[0]);

    if (!tbl_PobierzParametry(el))
        return false;

    if (tbl_id == 0)
        return true;

    table_name_ = table_name;
    table_id_ = table_id;

    if (table_name == 'klienci' && tbl_col == 'email')
        J.post('Post.aspx', { sql: 'select count(*) from klienci where email = ' + tbl_val, typ: '2' }, tbl_SprawdzUnikalnoscEmailCallback);
    else 
        J.post('Post.aspx', { sql: 'update ' + table_name + ' set ' + tbl_col + ' = ' + tbl_val + ' where ' + table_id + ' = ' + tbl_id + tbl_sql, typ: '1' }, tbl_ZapiszCallback);
    
    return true;
}
function tbl_ZapiszCallback(data, text) { if (tbl_tab != undefined) document.location.search = setUrlEncodedKey('tab', tbl_tab, document.location.search); }
function tbl_SprawdzUnikalnoscEmailCallback(data, text) {
    if (data == '0')
        J.post('Post.aspx', { sql: 'update ' + table_name_ + ' set ' + tbl_col + ' = ' + tbl_val + ' where ' + table_id_ + ' = ' + tbl_id + tbl_sql, typ: '1' }, tbl_ZapiszCallback);
    else
        alert((txt_EmailNotUnique == undefined ? 'Podany adres email jest już zajęty: ' : txt_EmailNotUnique) + tbl_val.replace(/'/g, ""));
}
var table_name_, table_id_;

function tbl_Waliduj(el) {
    var ret = true;
    var req = J(el).attr('req');
    if (req != undefined) {
        var r = parseInt(req);
        if (J(el).attr('value').length < r)
            ret = false;
    }

    if (ret) J(el).removeClass('inv');
    else J(el).addClass('inv');

    return ret;
}
function tbl_Tick(el) {
    var s = J(el).attr('value').indexOf('true') != -1 ? 'false' : 'true';
    J(el).attr('value', s);
    J(el).addClass(s).removeClass(s == 'true' ? 'false' : 'true');
}

var tbl_typ, tbl_nul, tbl_id, tbl_val, tbl_col, tbl_tab, tbl_sql;
function tbl_PobierzParametry(el) {
    try{
    if (!tbl_Waliduj(el))
        return false;

    tbl_sql = J(el).attr('sql');if (tbl_sql == undefined) tbl_sql = '';  // dodatkowy sql po zapisaniu
    tbl_tab = J(el).attr('tab'); // indeks aktualnej zakładki (taba)
    tbl_typ = J(el).attr('t'); // typ danych: int, varchar
    tbl_nul = J(el).attr('nul'); // czy zero oznacza null
    tbl_val = J(el).attr('value'); // wartosc
    tbl_col = J(el).attr('c'); // kolumna zapisywana
    var v = J(el).parent();
    if (v.attr('i') == undefined) v = v.parent();
    if (v.attr('i') == undefined) v = v.parent();
    if (v.attr('i') == undefined) throw 'Brak parametru: i.';
    tbl_id = v.attr('i');

    if (tbl_typ == '2') // wartosc tekstowa
        tbl_val = '\'' + tbl_val + '\'';
    if (tbl_nul == '0' && tbl_val == '0') // wartosc int?
        tbl_val = 'null';
    if (tbl_typ != '2')
        tbl_val = tbl_val.replace(',', '.');

    // ukrywanie wartości: 0 (np. brak limitu)
    if (parseFloat(tbl_val) == 0) J(el).addClass('zero');
    else J(el).removeClass('zero');
    }
    catch (ex) {return true; }

    return true;
}
// ########################################################################


function input_decimal(e) {
    var key;
    var keychar;
    var dec = true;
    
    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);
    
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        return true;
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;
    else if (dec && (keychar == ".") && e.target.value.indexOf('.') == -1)
        return true;
    else
        return false;
}
function input_int(e) {
    var key;
    var keychar;
    var dec = true;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    keychar = String.fromCharCode(key);

    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
        return true;
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;
    else
        return false;
}

function PokazUkryjDrzewko(url) {
    if ((url.indexOf('OfferMain.aspx') == -1 && url.indexOf('Article.aspx') == -1 && url.indexOf('Basket.aspx') == -1)
        || url.indexOf('gc=0') != -1) {
        $('.tree_box_kategorie').hide();
        // $('#left').hide(); 
        $('#left').css('width','0px');
        $('#right').css('padding-left', '0px');
    }
    else {
        if (url.indexOf('Article.aspx') == -1) 
            $('.tree_box_kategorie').show();
        else
            $('.tree_box_kategorie').hide();
        // $('#left').show(); 
        $('#left').css('width', '233px');
        $('#right').css('padding-left', '10px');
    }
}
function PokazUkryjDrzewko_() {
    var url = null;
    try { url = document.getElementById('frmRight').src; } catch (exc) { return; }

    if ((url.indexOf('OfferMain.aspx') == -1 && url.indexOf('Article.aspx') == -1 && url.indexOf('Basket.aspx') == -1)
        || url.indexOf('gc=0') != -1) {
        J('.tree_box_kategorie').hide();
        // $('#left').hide(); 
        $('#left').css('width', '0px');
        J('#right').css('padding-left', '0px');
    }
    else {
        if (url.indexOf('Article.aspx') == -1)
            $('.tree_box_kategorie').show();
        else
            $('.tree_box_kategorie').hide();
        // $('#left').show(); 
        $('#left').css('width', '233px');
        $('#right').css('padding-left', '10px');
    }
}

function number_format(number, decimals, dec_point, thousands_sep) {   
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

