PageSourceSearch

https://www.compteur-energie.com/mag/scripts/lib_ajax_v2.js?v=1.88.2

js compteur-energie.com collected 2026-10-09 00:31:09 UTC 20,121 bytes, 527 lines download raw bytes

1function getHTTPObject()
2{
3    if (window.XMLHttpRequest)
4    { return new XMLHttpRequest(); }
5    else if (window.ActiveXObject)
6    { return new ActiveXObject("Microsoft.XMLHTTP"); }
7    else
8    { return false; }
9}
10
11function loadCategory(listbox, asc_id, asv_parentid, selected_value)
12{
13    if (listbox) {
14        var xhr_object = null;
15        xhr_object = getHTTPObject();
16
17        xhr_object.open("GET", "/mag/getCategory.php?asc_id=" + asc_id + "&asv_parentid=" + asv_parentid, true);
18
19        reinitList(listbox);
20
21        xhr_object.onreadystatechange = function () {
22            if (xhr_object.readyState == 4) {
23                var reponse = xhr_object.responseText;
24                var ligne = reponse.split("<br/>");
25
26                for (var i = 0; i < ligne.length; i++) {
27                    if (ligne[i] != '') {
28                        var champ = ligne[i].split("|||");
29                        var idx = listbox.options.length;
30
31                        listbox.options[idx] = new Option(champ[1], champ[0]);
32
33                        if (selected_value == champ[0]) {
34                            listbox.options[idx].selected = true;
35                        }
36                    }
37                }
38
39            }
40        };
41
42        xhr_object.send(null);
43    }
44}
45
46function getBasket(lang)
47{
48    var xhr_object = null;
49    xhr_object = getHTTPObject();
50
51    xhr_object.open("GET", "/mag/getBasket.php?lang=" + lang + "&rnd=" + Math.random(), true);
52
53    xhr_object.onreadystatechange = function () {
54        if (xhr_object.readyState == 4) {
55            var reponse = xhr_object.responseText;
56
57            if (document.getElementById('d_basket_detail'))
58            { var basketRightActive = 1; }
59
60            if (document.getElementById('totalit_basket'))
61            { var basketSupActive = 1; }
62
63            var ligne = reponse.split("<br/>");
64            var numit = 0;
65            var totalit = 0;
66            var basket_html = "";
67
68            for (var i = 0; i < ligne.length; i++) {
69                if (ligne[i] != '') {
70                    var champ = ligne[i].split("|||");
71
72                    if (basketSupActive == 1 || basketRightActive == 1) {
73                        var champ12 = parseInt(champ[1]) * parseFloat(champ[2]);
74                        totalit += champ12;
75
76                        if (basketSupActive == 1) {
77                            numit += parseInt(champ[1]);
78                        }
79
80                        if (basketRightActive == 1) {
81                            var champ1 = parseInt(champ[1]) - 1;
82                            var tp;
83
84                            if (champ[1] == 1) { tp = 'del'; } else { tp = 'rem'; }
85
86                            var champ2 = parseInt(champ[1]) + 1;
87
88                            var vl_champ2 = champ12.toFixed(2);
89
90                            var currency = champ[6];
91
92                            basket_html = basket_html + "\r\n<span class=\"primary\">" + champ[3] + "</span><div class=\"quantity\"><input class='btn_quantity' type=button value='-' onclick=\"quantity('moins',document.getElementById('input_" + i + "'));updateBasket('" + champ[0] + "', '" + tp + "', '&bskit_id=" + champ[4] + "&ctx_qty_" + champ[4] + "=" + champ1 + "&lang=" + lang + champ[5] + "')\"><input id='input_" + i + "' type='hidden' disabled value='" + champ[1] + "'/><span class=\"quantity_value\">" + champ[1] + "</span><input class='btn_quantity' type='button' value='+' onclick=\"quantity('plus',document.getElementById('input_" + i + "'));updateBasket('" + champ[0] + "', 'add', '&bskit_id=" + champ[4] + "&ctx_qty_" + champ[4] + "=" + champ2 + "&lang=" + lang + champ[5] + "')\"></div><span class=\"price\">" + vl_champ2 + currency + "</span>";
93                        }
94                    }
95                }
96            }
97            if (totalit > 0) {
98                totalit = totalit.toFixed(2);
99            }
100            setHtmlBasetSupRight(numit, totalit, basket_html);
101        }
102    };
103
104    xhr_object.send(null);
105    return '1';
106}
107
108function callGetBasket(lang, basketRightActive, Cart_numit, Cart_totalit)
109{
110    if (basketRightActive == '1' || Cart_numit == '' || Cart_totalit == '') {
111        getBasket(lang);
112    } else {
113        setHtmlBasetSupRight(Cart_numit, Cart_totalit, '');
114    }
115}
116
117function setHtmlBasetSupRight(numit, totalit, basket_html)
118{
119    Cart_numit = numit;
120    Cart_totalit = totalit;
121
122    if (document.getElementById('d_basket_detail'))
123    { var basketRightActive = 1; }
124
125    if (document.getElementById('totalit_basket'))
126    { var basketSupActive = 1; }
127
128    if (basketSupActive == 1) {
129        showChar(Cart_numit);
130        if (Cart_numit > 0) {
131            document.getElementById('numit_basket').innerHTML = Cart_numit;
132        }
133        if (document.getElementById("top_basket_numits")) {
134            document.getElementById('top_basket_numits').innerHTML = Cart_numit;
135        }
136        if (Cart_totalit > 0) {
137            document.getElementById('totalit_basket').innerHTML = Cart_totalit;
138            showChar(Cart_numit, 1);
139        } else {
140            document.getElementById('totalit_basket').innerHTML = '';
141        }
142    }
143
144    if (basketRightActive == 1) {
145        if (basket_html != '') {
146            //Cart_basketRightHtml = basket_html;
147            if (document.getElementById('d_basket_detail')) {
148                document.getElementById('d_basket_detail').innerHTML = basket_html;
149            }
150        }
151        if (document.getElementById('total_dbasket')) {
152            showChar_dbasket(Cart_totalit);
153            document.getElementById('total_dbasket').innerHTML = Cart_totalit;
154        }
155
156    }
157}
158
159function reinitList(listbox)
160{
161    if (listbox) {
162        listbox.options.length = 0;
163        var valueListName = '';
164        if (document.getElementById('msg_traduct_select')) {
165            valueListName = document.getElementById('msg_traduct_select').value;
166        }
167        listbox.options[listbox.options.length] = new Option(valueListName, 0);
168    }
169}
170
171function loadSentensPopupGroupeDefaut(valueCPID, typeCP, store_id, GPdefaut)
172{
173    var xhr_object = null;
174    xhr_object = getHTTPObject();
175    xhr_object.open("GET", "/mag/groupSelect.php?valueCPID=" + valueCPID + "&typeCP=" + typeCP + "&store_id=" + store_id + "&GPdefaut=" + GPdefaut, true);
176
177    xhr_object.onreadystatechange = function () {
178        if (xhr_object.readyState == 4) {
179            var reponse = xhr_object.responseText;
180            if (reponse == "ok") {
181                document.location.reload();
182            } else {
183                document.getElementById('divSelectionGroup').style.visibility = 'hidden';
184                document.getElementById('divGroupDefaut').style.visibility = 'visible';
185            }
186        }
187    };
188
189    xhr_object.send(null);
190}
191
192function getPrice(product_id)
193{
194    var nb = 1;
195
196    if (document.getElementById('nb'))
197    { nb = document.getElementById('nb').value; }
198
199    var optid_array = new Array();
200    var i = 1;
201
202    while (document.getElementById('hidden_choice_opt_' + i)) {
203        optid_array.push(document.getElementById('hidden_choice_opt_' + (i)).value);
204        i++;
205    }
206
207    //calcul prix
208    var xhr_object = null;
209    xhr_object = getHTTPObject();
210    xhr_object.open("GET", "/mag/getPrice.php?product_id=" + product_id + "&nb=" + nb + "&optid_array=" + optid_array, true);
211
212    xhr_object.onreadystatechange = function () {
213        if (xhr_object.readyState == 4) {
214            var getPrice = xhr_object.responseText;
215            var champ = getPrice.split("|");
216            var priceTTC = champ[2];
217            if (document.getElementById('ajaxPriceTTC'))
218            { document.getElementById('ajaxPriceTTC').innerHTML = champ[0]; }
219
220            if (document.getElementById('pdt_pweight')) {
221                var pdtQuantity = new Number(document.getElementById('pdt_quantity').value);
222                if (pdtQuantity > 0) {
223                    var priceUnit = priceTTC / pdtQuantity;
224                    priceUnit = priceUnit.toFixed(2);
225                    document.getElementById('pdt_pweight').innerHTML = priceUnit;
226                }
227            }
228
229            if (document.getElementById('ajaxPriceHT')) {
230                document.getElementById('ajaxPriceHT').innerHTML = champ[1];
231            }
232
233            if (document.getElementById('ajaxPriceOld') && champ[3] != '') {
234                document.getElementById('ajaxPriceOld').innerHTML = champ[3];
235            }
236        }
237    };
238
239    xhr_object.send(null);
240}
241
242function checkStockAndAdd(pdtId, action, param)
243{
244    var optid_array = [];
245    var listoptid_array = [];
246    var opt_param = "";
247    var nb = getValueFromParams(param, 'nb');
248
249    if (action.substring(0, 4) != "list") {
250        if (action == "addAndRefresh") {
251            var i = 1;
252            while (getValueFromParams(param, 'hidden_choice_opt_' + i) != null) {
253                optid_array.push(getValueFromParams(param, 'hidden_choice_opt_' + i));
254                listoptid_array.push(getValueFromParams(param, 'hidden_choice_listopt_' + i));
255                i++;
256            }
257        } else {
258            var i = 1;
259            while (document.getElementById('hidden_choice_opt_' + i)) {
260                optid_array.push(document.getElementById('hidden_choice_opt_' + i).value);
261                listoptid_array.push(document.getElementById('hidden_choice_listopt_' + i).value);
262                opt_param = opt_param + "&input_choice_opt_" + i + "=" + document.getElementById('input_choice_opt_' + i).value;
263                opt_param = opt_param + "&hidden_choice_opt_" + i + "=" + document.getElementById('hidden_choice_opt_' + i).value;
264                opt_param = opt_param + "&hidden_choice_listopt_" + i + "=" + document.getElementById('hidden_choice_listopt_' + i).value;
265
266                i++;
267            }
268
269        }
270    } else if (action == "listPopup") {
271        action = "popup";
272    }
273
274    var xhr_object = null;
275    xhr_object = getHTTPObject();
276
277    xhr_object.open("GET", "/mag/getStock.php?pdtId=" + pdtId + "&nb=" + nb + "&listoptid_array=" + listoptid_array + "&optid_array=" + optid_array + "&rnd=" + Math.random(), true);
278
279    var lang = getValueFromParams(param, "lang");
280
281    xhr_object.onreadystatechange = function () {
282        if (xhr_object.readyState == 4) {
283            var reponse = xhr_object.responseText;
284
285            if (reponse == "0") {
286                document.getElementById('alertStock').style.display = "inline";
287            } else if (reponse == "notSelected1") {
288                document.getElementById('alertOpt').style.display = "inline";
289            } else if (reponse == "notSelected2") {
290                document.getElementById('alertOpt').style.display = "inline";
291            } else if (reponse == "-1") {
292                document.getElementById('alertMiniQuantityPurchase').style.display = "inline";
293            } else {
294                document.getElementById('alertStock').style.display = "none";
295
296                if (action == "pdtToBasket") {
297                    document.getElementById('formulaire').action = "/mag/" + lang + "/shoppingcart.php?action=insert&" + param + opt_param;
298                    document.getElementById('formulaire').submit();
299                } else if (action == "formToBasket") {
300                    document.getElementById('formPost').action = "/mag/" + lang + "/form_post.php?action=valid&" + param + opt_param;
301                    document.getElementById('formPost').submit();
302                } else if (action == "popup") {
303                    param += '&checkStockAndAdd=' + reponse + '&instock=' + reponse;
304                    setBasket(pdtId, "set", param + opt_param);
305                } else if (action == "addAndRefresh") {
306                    param += '&instock=' + reponse;
307                    setBasket(pdtId, "add", param + opt_param);
308                } else if (action == "listPdtAssociatedToBasket") {
309                    document.getElementById('formAssociated').action = "/mag/" + lang + "/shoppingcart.php?action=insert&" + param + opt_param;
310                    document.getElementById('formAssociated').submit();
311                } else if (action == "listPdtListToBasket" || action == "listPdtHomeToBasket") {
312                    document.getElementById('formulaire').action = "/mag/" + lang + "/shoppingcart.php?action=insert&" + param + opt_param;
313                    document.getElementById('formulaire').submit();
314                } else if (action == "listPdtSearchToBasket") {
315                    document.getElementById('formulaire_search').action = "/mag/" + lang + "/shoppingcart.php?action=insert&" + param + opt_param;
316                    document.getElementById('formulaire_search').submit();
317                }
318            }
319        }
320    };
321
322    xhr_object.send(null);
323}
324
325function updateBasket(pdtId, action, param)
326{
327    param = param + '&isBasketSup=1';
328    if (action == "rem") // On retire une unite
329    {
330        setBasket(pdtId, "rem", param);
331    } else if (action == "del") // On supprime le produit
332    {
333        setBasket(pdtId, "del", param);
334    } else if (action == "add") // On ajoute une unite
335    {
336        checkStockAndAdd(pdtId, "addAndRefresh", param + '&popup_inactive=1');
337    }
338}
339
340function setBasket(pdtId, action, param)
341{
342    var xhr_object = null;
343    xhr_object = getHTTPObject();
344    xhr_object.open("GET", "/mag/setBasket.php?id=" + pdtId + "&t
344ype=" + action + "&rnd=" + Math.random() + param, true);
345
346    xhr_object.onreadystatechange = function () {
347        if (xhr_object.readyState == 4) {
348            var response = JSON.parse(xhr_object.responseText);
349
350            if (document.getElementById('item_basket') || document.getElementById('d_basket')) {
351                getBasket(getValueFromParams(param, "lang"));
352            }
353
354            if (action != "del" && action != "rem") {
355                var instock = getValueFromParams(param, "instock");
356                var stockorder = getValueFromParams(param, "nb");
357                instock = parseInt(instock);
358                stockorder = parseInt(stockorder);
359
360                var popup_inactive = getValueFromParams(param, "popup_inactive");
361
362                var numItemAdded = 0;
363
364                if (!popup_inactive) {
365                    if (stockorder > instock) {
366                        document.getElementById('popupbkjs_stockinsufficient').style.display = 'block';
367                        document.getElementById('popupbkjs_stockinsufficient_number').innerHTML = instock;
368
369                        numItemAdded = instock;
370                    } else {
371                        document.getElementById('popupbkjs_stockinsufficient').style.display = 'none';
372                        numItemAdded = stockorder;
373                    }
374
375                    document.getElementById('popupbkjs_quantity').innerHTML = 'x ' + numItemAdded;
376
377                    var basketOnglet = '';
378
379                    if (document.getElementById('product')) {
380                        if (document.getElementById('briefcase_popup_basket')) {
381                            basketOnglet = document.getElementById('briefcase_popup_basket').innerHTML;
382                        } else if (document.getElementById('list_contener') && document.getElementById('pdt_popup_basket')) {
383                            basketOnglet = document.getElementById('title_associed').outerHTML;
384                            for (var i = 1; i <= 3; i++) {
385                                if (document.getElementById('item' + i))
386                                { basketOnglet += document.getElementById('item' + i).outerHTML; }
387                            }
388                        }
389                        basketOnglet = '<div class="content_popup_bsk_onglet">' + basketOnglet + '</div>';
390                        sf_innerHTML('content_popup_bsk_onglet', basketOnglet);
391                    }
392
393                    sf_innerHTML('content_popup_div_bkjs', response.contentHtml);
394
395                    /* price total*/
396                    if (document.getElementById('popupbkjs_price_hidden')) {
397                        var price = parseFloat(document.getElementById('popupbkjs_price_hidden').innerHTML);
398                        document.getElementById('popupbkjs_pricetotal').innerHTML = precisionRound(price * numItemAdded, 2);
399                    }
400
401                    if (document.getElementById('popupbkjs_currency_hidden') && document.getElementById('popupbkjs_currency')) {
402                        document.getElementById('popupbkjs_currency').innerHTML = document.getElementById('popupbkjs_currency_hidden').innerHTML;
403                    }
404                    document.getElementById('popup_div_bkjs').style.display = 'inline';
405                }
406
407                if (typeof (addCartCallBack) === "function") {
408                    addCartCallBack(pdtId, response.bskitId, numItemAdded);
409                }
410            }
411        }
412    };
413
414    xhr_object.send(null);
415}
416
417function getValueFromParams(params, param)
418{
419    var tbParam = params.split("&");
420    for (var i = 0; i < tbParam.length; i++) {
421        if (tbParam[i].substring(0, param.length) == param) {
422            var val = tbParam[i].split("=");
423            return val[1];
424        }
425    }
426    return null;
427}
428
429function getReversoForm(number, idco, host)
430{
431    var xhr_object = getHTTPObject();
432
433    xhr_object.open("GET", "/mag/getReversoForm.php?number=" + number + "&idco=" + idco + "&host=" + host 
433+ "&rnd=" + Math.random(), true);
434
435    xhr_object.onreadystatechange = function () {
436        if (xhr_object.readyState == 4) {
437            var reponse = xhr_object.responseText;
438
439            eval(reponse);
440
441        }
442    };
443    xhr_object.send(null);
444}
445
446function deleteEventCookie(evtId)
447{
448    var xhr_object = getHTTPObject();
449    xhr_object.open("GET", "/mag/eventCookie.php?evtId=" + evtId + "&rnd=" + Math.random(), true);
450    xhr_object.send(null);
451}
452
453function addWishList()
454{
455    var id = this.getAttribute('data-id');
456    var action = this.getAttribute('data-action');
457    var target = this.getAttribute('data-target');
458
459    var add = 0;
460
461    if (this.className === 'wishlist') {
462        this.className += ' wishlist_added';
463        add = 1;
464    } else {
465        this.className = 'wishlist';
466        add = 0;
467    }
468
469    if (action === 'delete') {
470        document.getElementById(target).style.display = "none";
471    }
472
473    var xhr_object = getHTTPObject();
474
475    xhr_object.open("GET", "/mag/addWishList.php?id=" + id + "&add=" + add, true);
476    xhr_object.send(null);
477}
478
479function replicateOrder(id)
480{
481    var xhr_object = null;
482    xhr_object = getHTTPObject();
483
484    xhr_object.open("GET", "/mag/replicateOrder.php?id=" + id + "&rnd=" + Math.random(), true);
485
486    xhr_object.onreadystatechange = function () {
487        if (xhr_object.readyState == 4) {
488            if (xhr_object.responseText == "0") {
489                replicateOrderConfirm(false);
490            } else {
491                replicateOrderConfirm(true);
492            }
493        }
494    };
495
496    xhr_object.send(null);
497}
498
499function replicateOrderConfirm(isOk)
500{
501    if (document.getElementById('popup_ok_replicateorder')) {
502        if (isOk === true) {
503            document.getElementById('popup_ok_replicateorder').style.display = 'inline';
504            setTimeout("document.getElementById('popup_ok_replicateorder').style.display = 'none';", 5000);
505        } else {
506            document.getElementById('popup_nok_replicateorder').style.display = 'inline';
507            setTimeout("document.getElementById('popup_nok_replicateorder').style.display = 'none';", 5000);
508        }
509    }
510}
511
512function grecaptchaV3Verify(token, lang, action)
513{
514    var xhr_object = null;
515    xhr_object = getHTTPObject();
516    var params = 'action=recaptchav3&token='+token+'&grecaptchaaction='+action
517    xhr_object.open("POST", "mag/scripts/ajaxHandler.php", true);
518
519    xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
520
521    xhr_object.onreadystatechange = function() {
522        if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
523            console.log(xhr_object.responseText)
524        }
525    }
526    xhr_object.send(params);
527}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.