PageSourceSearch

https://medicaldeviceacademy.com/wp-content/plugins/wp-cart-for-di…/lib/eStore_read_form.js?ver=8.7.7

js medicaldeviceacademy.com collected 2026-10-02 08:06:27 UTC 17,500 bytes, 440 lines download raw bytes

1if (typeof(JS_WP_ESTORE_VARIATION_ADD_STRING) == 'undefined') {
2    JS_WP_ESTORE_VARIATION_ADD_STRING = "+";
3}
4if (typeof(JS_WP_ESTORE_CURRENCY_SYMBOL) == 'undefined') {
5    JS_WP_ESTORE_CURRENCY_SYMBOL = "$";
6}
7if (typeof(JS_WP_ESTORE_VARIATION_DECIMAL_SEPERATOR) == 'undefined') {
8    JS_WP_ESTORE_VARIATION_DECIMAL_SEPERATOR = ".";
9}
10if (typeof(JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR) == 'undefined') {
11    JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR = ",";
12}
13if (typeof(JS_WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER) == 'undefined') {
14    JS_WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER = "The minimum amount you can specify is ";
15}
16if (typeof(JS_WP_ESTORE_SELECT_OPTION_STRING) == 'undefined') {
17    JS_WP_ESTORE_SELECT_OPTION_STRING = "Select Option";
18}
19if (typeof(JS_WP_ESTORE_SELECT_OPTION_ERROR_MSG) == 'undefined') {
20    JS_WP_ESTORE_SELECT_OPTION_ERROR_MSG = "You need to slect an option before you can proceed.";
21}
22variation_add_string = JS_WP_ESTORE_VARIATION_ADD_STRING;//"+";
23currency_symbol = JS_WP_ESTORE_CURRENCY_SYMBOL;//"$";
24decimal_sep = JS_WP_ESTORE_VARIATION_DECIMAL_SEPERATOR;//".";
25thousands_sep = JS_WP_ESTORE_VARIATION_THOUSAND_SEPERATOR;//",";
26split_char = "[" + variation_add_string;
27variation_select_option = JS_WP_ESTORE_SELECT_OPTION_STRING;
28
29function CheckTok(object1)
30{
31    var var_add_amt, ary = new Array();     // where we parse
32    ary = val.split("[");          // break apart
33    variation_price_val = ary[1];
34    if (variation_price_val != null)
35    {
36        //remove the addition,currency and ] symbol then trim it
37        var_add_amt = variation_price_val.replace(variation_add_string, "");
38        var_add_amt = var_add_amt.replace(currency_symbol, "");
39        var_add_amt = var_add_amt.replace("]", "");
40        var_add_amt = var_add_amt.replace(thousands_sep, "");
41        var_add_amt = var_add_amt.replace(thousands_sep, "");//one extra for the million separator
42        if (decimal_sep != ".") {
43            var_add_amt = var_add_amt.replace(decimal_sep, ".");
44        }
45        var_add_amt = trim(var_add_amt);
46        if (eStoreIsNumeric(var_add_amt)) {
47            amt = amt + var_add_amt * 1.0;
48        }
49        else {
50            alert("Error! Variation addition amounts are not numeric. Please contact the admin and mention this error.");
51        }
52    }
53}
54function ReadForm1(object1, buttonType)
55{
56    // Read the user form
57    var i, j, pos;
58    amt = 0;
59    val_total = "";
60    val_combo = "";
61    val_1st_half = "";
62    variation_name = "";
63
64    for (i = 0; i < object1.length; i++)
65    {
66        // run entire form
67        obj = object1.elements[i];           // a form element
68
69        if (obj.type == "select-one")
70        {   // just selects
71            if (obj.name == "quantity" ||
72                    obj.name == "amount")
73                continue;
74            pos = obj.selectedIndex;// which option selected
75            val = obj.options[pos].value;// selected value		        
76            variation_name = val.split(split_char);// break apart
77            estore_product_id = object1.item_number.value;
78            if(variation_name[0].toLowerCase() == variation_select_option.toLowerCase()){
79                //The customer hasn't selected a valid variation option. Show error message.
80                eStore_error_msg_for_variation_select(estore_product_id);
81                return false;
82            } else {
83                //Clear variation error msg (if any)
84                eStore_clear_error_msg_for_variation_select(estore_product_id);
85            }
86            
87            val_combo = val_combo + " (" + trim(variation_name[0]) + ")";
88            CheckTok(object1);
89        }
90        if (obj.type == "text" || obj.type == "textarea")
91        {
92            // Read the text fields
93            //Ignore the following fields as they don't need to be captured.
94            if (obj.name == "add_qty")
95                continue;
96            if (obj.name == "custom_price")
97                continue;
98            if (obj.name == "cust_name")
99                continue;
100            if (obj.name == "cust_email")
101                continue;
102
103            val = obj.value;//custom text msg value
104            if (val.length != 0)
105            {
106                val = val.replace("(", "[");
107                val = val.replace(")", "]");
108                val_combo = val_combo + " (" + val + ")";
109            }
110        }
111    }
112
113    // Now summarize everything we have processed above
114    val_total = object1.product_name_tmp1.value + val_combo;
115    if (buttonType == 1)
116    {
117        object1.estore_product_name.value = val_total;
118        var price_after_var_change;
119        if (object1.custom_price) {
120            var custom_price = parseFloat(object1.custom_price.value);
121            if (!eStore_custom_price_validated(object1, custom_price)) {
122                return false;
123            }
124            price_after_var_change = custom_price;//custom price overrides the price
125        }
126        else {
127            price_after_var_change = parseFloat(object1.price_tmp1.value) + amt;
128        }
129        updatePriceAmtText(object1, price_after_var_change, buttonType);
130        updateOldPriceAmtText(object1, amt, buttonType);
131        object1.price.value = price_after_var_change;
132    }
133    else if (buttonType == 2)
134    {
135        object1.item_name.value = val_total;
136        if (object1.custom_price) {
137            var custom_price = parseFloat(object1.custom_price.value);
138            if (!eStore_custom_price_validated(object1, custom_price)) {
139                return false;
140            }
141            else {
142                var price_after_var_change = custom_price + amt;
143                updatePriceAmtText(object1, price_after_var_change, buttonType);
144                updateOldPriceAmtText(object1, amt, buttonType);
145                object1.amount.value = price_after_var_change.toFixed(2);
146            }
147        }
148        else {
149            var price_after_var_change = parseFloat(object1.price_tmp1.value) + amt;
150            updatePriceAmtText(object1, price_after_var_change, buttonType);
151            updateOldPriceAmtText(object1, amt, buttonType);
152            object1.amount.value = price_after_var_change.toFixed(2);
153        }
154        setCookie("cart_in_use", "true", 1);
155    }
156    else if (buttonType == 3)
157    {
158        object1.item_name.value = val_total;
159        if (object1.custom_price) {
160            var custom_price = parseFloat(object1.custom_price.value);
161            if (!eStore_custom_price_validated(object1, custom_price)) {
162                return false;
163            }
164            else {
165                updated_amt = custom_price + amt;
166                object1.a3.value = updated_amt.toFixed(2);
167            }
168        }
169        else {
170            updated_amt = parseFloat(object1.price_tmp1.value) + amt;
171            object1.a3.value = updated_amt.toFixed(2);
172        }
173        setCookie("cart_in_use", "true", 1);
174    }
175    else if (buttonType == 4)
176    {
177        object1.product.value = val_total;
178    }
179}
180function trim(stringToTrim) {
181    return stringToTrim.replace(/^\s+|\s+$/g, "");
182}
183function setCookie(c_name, value, expiredays)
184{
185    var exdate = new Date();
186    exdate.setDate(exdate.getDate() + expiredays);
187    document.cookie = c_name + "=" + escape(value) +
188            ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
189}
190function eStoreIsNumeric(input)
191{
192    return (input - 0) == input && input.length > 0;
193}
194function eStore_custom_price_validated(object1, custom_price)
195{
196    var min_amt = parseFloat(object1.price_tmp1.value);
197    if (isNaN(custom_price) || custom_price < min_amt)
198    {
199        alert(JS_WP_ESTORE_MINIMUM_PRICE_YOU_CAN_ENTER + min_amt);
200        return false;
201    }
202    return true;
203}
204function updatePriceAmtText(object1, new_price, buttonType) {
205    //update the price text amount
206    var old_price;
207    if (buttonType == 1) {
208        old_price = parseFloat(object1.price.value);
209    } else if (buttonType == 2) {
210        old_price = parseFloat(object1.amount.value);
211    }
212    new_price = parseFloat(new_price);
213    if (old_price == new_price) {//No price value changed
214        return;
215    }
216    new_price = new_price.toFixed(JS_WP_ESTORE_VARIATION_NUM_OF_DECIMALS);
217    if (decimal_sep != ".") {//Non english system
218        new_price = new_price.replace(".", decimal_sep);
219    }
220
221    var new_prod_price_text = JS_WP_ESTORE_CURRENCY_SYMBOL + new_price;
222    if (JS_WP_ESTORE_VARIATION_CURRENCY_POS == 'right') {
223        new_prod_price_text = new_price + JS_WP_ESTORE_CURRENCY_SYMBOL;
224    }
225    var jq_obj = jQuery(object1);
226    var curr_prod_div = jq_obj.closest('.eStore-fancy-wrapper');
227    curr_prod_div.find('.eStore_price_value').text(new_prod_price_text);
228}
229
230function updateOldPriceAmtText(object1, amt, buttonType) {
231    //update the price text amount
232    var jq_obj = jQuery(object1);
233    var curr_prod_div = jq_obj.closest('.eStore-fancy-wrapper');
234    var cutoff_price_display_val = curr_prod_div.find('.eStore_price_value_old').text();
235    if (cutoff_price_display_val) //cut off price is being displayed
236    {
237        var new_cuttoff_price = parseFloat(object1.price_tmp1_old.value) + amt;
238        new_cuttoff_price = new_cuttoff_price.toFixed(JS_WP_ESTORE_VARIATION_NUM_OF_DECIMALS);
239        if (decimal_sep != ".") {//Non english system
240            new_cuttoff_price = new_cuttoff_price.replace(".", decimal_sep);
241        }
242        var new_cuttoff_price_text = JS_WP_ESTORE_CURRENCY_SYMBOL + new_cuttoff_price;
243        if (JS_WP_ESTORE_VARIATION_CURRENCY_POS == 'right') {
244            new_cuttoff_price_text = new_cuttoff_price + JS_WP_ESTORE_CURRENCY_SYMBOL;
245        }
246
247        curr_prod_div.find('.eStore_price_value_old').text(new_cuttoff_price_text);
248    }
249}
250function eStore_error_msg_for_variation_select(product_id) {
251    jQuery(document).ready(function($) {
252        var jq_product_id = $(product_id);
253        //alert(JS_WP_ESTORE_SELECT_OPTION_ERROR_MSG);
254        html_error_msg = '<div class="eStore_error_variation_not_selected eStore_error_message">' + JS_WP_ESTORE_SELECT_OPTION_ERROR_MSG + '</div>';
255        $(".eStore_item_added_msg-" + product_id).html(html_error_msg);
256    });
257}
258function eStore_clear_error_msg_for_variation_select(product_id) {
259    jQuery(document).ready(function($) {
260        $(".eStore_error_variation_not_selected").html("");
261    });
262}
263
264/**
265 * Read and calculate variation price for PPCP Buy Now buttons (non-form version)
266 * This function works with DIV containers instead of forms
267 * 
268 * @param {HTMLElement} containerElement The wrapper element containing variations and hidden fields
269 * @returns {boolean} Returns true if validation passes, false otherwise
270 */
271function eStore_read_ppcp_variation(containerElement) {
272    var i, j, pos, obj, val, amt = 0;
273    var val_total = "";
274    var val_combo = "";
275    var variation_name = "";
276    var var_add_amt;
277    
278    // Get all variation select elements within the container
279    var variationSelects = containerElement.querySelectorAll('select.eStore_variation');
280    
281    // Process all variation dropdowns
282    for (i = 0; i < variationSelects.length; i++) {
283        obj = variationSelects[i];
284        if (obj.name == "quantity" || obj.name == "amount") {
285            continue;
286        }
287        
288        pos = obj.selectedIndex;
289        val = obj.options[pos].value;
290        variation_name = val.split(split_char);
291        
292        // Check if variation option is selected
293        if (variation_name[0].toLowerCase() == variation_select_option.toLowerCase()) {
294            // Customer hasn't selected a valid variation option
295            var estore_product_id = containerElement.querySelector('input[name="item_number"]');
296            if (estore_product_id) {
297                eStore_error_msg_for_variation_select(estore_product_id.value);
298            }
299            return false;
300        } else {
301            // Clear variation error msg (if any)
302            var estore_product_id = containerElement.querySelector('input[name="item_number"]');
303            if (estore_product_id) {
304                eStore_clear_error_msg_for_variation_select(estore_product_id.value);
305            }
306        }
307        
308        val_combo = val_combo + " (" + trim(variation_name[0]) + ")";
309        
310        // Calculate variation price addition
311        var variation_price_val = variation_name[1];
312        if (variation_price_val != null) {
313            var_add_amt = variation_price_val.replace(variation_add_string, "");
314            var_add_amt = var_add_amt.replace(currency_symbol, "");
315            var_add_amt = var_add_amt.replace("]", "");
316            var_add_amt = var_add_amt.replace(thousands_sep, "");
317            var_add_amt = var_add_amt.replace(thousands_sep, "");
318            if (decimal_sep != ".") {
319                var_add_amt = var_add_amt.replace(decimal_sep, ".");
320            }
321            var_add_amt = trim(var_add_amt);
322            if (eStoreIsNumeric(var_add_amt)) {
323                amt = amt + var_add_amt * 1.0;
324            } else {
325                alert("Error! Variation addition amounts are not numeric. Please contact the admin and mention this error.");
326                return false;
327            }
328        }
329    }
330    
331    // Process custom text inputs (custom_input fields)
332    var customInputs = containerElement.querySelectorAll('input.eStore_collect_input');
333    for (i = 0; i < customInputs.length; i++) {
334        obj = customInputs[i];
335        val = obj.value;
336        if (val.length != 0) {
337            val = val.replace("(", "[");
338            val = val.replace(")", "]");
339            val_combo = val_combo + " (" + val + ")";
340        }
341    }
342    
343    // Get base product name and price
344    var baseNameField = containerElement.querySelector('input[name="product_name_tmp1"]');
345    var basePriceField = containerElement.querySelector('input[name="price_tmp1"]');
346    var amountField = containerElement.querySelector('input[name="amount"]');
347    var itemNameField = containerElement.querySelector('input[name="item_name"]');
348    var customPriceField = containerElement.querySelector('input[name="custom_price"]');
349    
350    if (!baseNameField || !basePriceField || !amountField || !itemNameField) {
351        console.error('Required hidden fields not found in PPCP button wrapper');
352        return false;
353    }
354    
355    // Update item_name with variations and custom inputs
356    val_total = baseNameField.value + val_combo;
357    itemNameField.value = val_total;
358    
359    // Calculate final amount (no validation here - validation happens on button click)
360    var price_after_var_change;
361    if (customPriceField) {
362        if (customPriceField.value) {
363            var custom_price = parseFloat(customPriceField.value);
364            price_after_var_change = custom_price + amt;
365        } else {
366            price_after_var_change = parseFloat(basePriceField.value) + amt;
367        }
368    } else {
369        price_after_var_change = parseFloat(basePriceField.value) + amt;
370    }
371    
372    amountField.value = price_after_var_change.toFixed(2);
373    
374    // Update displayed price if price display element exists
375    updatePriceAmtTextForPPCP(containerElement, price_after_var_change);
376    updateOldPriceAmtTextForPPCP(containerElement, amt);
377    
378    return true;
379}
380
381/**
382 * Update the displayed price text for PPCP buttons
383 * 
384 * @param {HTMLElement} containerElement The wrapper element
385 * @param {number} new_price The new price to display
386 */
387function updatePriceAmtTextForPPCP(containerElement, new_price) {
388    var amountField = containerElement.querySelector('input[name="amount"]');
389    if (!amountField) return;
390    
391    var old_price = parseFloat(amountField.value);
392    new_price = parseFloat(new_price);
393    
394    if (old_price == new_price) {
395        return;
396    }
397    
398    new_price = new_price.toFixed(JS_WP_ESTORE_VARIATION_NUM_OF_DECIMALS);
399    if (decimal_sep != ".") {
400        new_price = new_price.replace(".", decimal_sep);
401    }
402    
403    var new_prod_price_text = JS_WP_ESTORE_CURRENCY_SYMBOL + new_price;
404    if (JS_WP_ESTORE_VARIATION_CURRENCY_POS == 'right') {
405        new_prod_price_text = new_price + JS_WP_ESTORE_CURRENCY_SYMBOL;
406    }
407    
408    var priceElement = containerElement.querySelector('.eStore_price_value');
409    if (priceElement) {
410        priceElement.textContent = new_prod_price_text;
411    }
412}
413
414/**
415 * Update the displayed old price text for PPCP buttons
416 * 
417 * @param {HTMLElement} containerElement The wrapper element
418 * @param {number} amt The variation amount to add
419 */
420function updateOldPriceAmtTextForPPCP(containerElement, amt) {
421    var oldPriceElement = containerElement.querySelector('.eStore_price_value_old');
422    if (!oldPriceElement) return;
423    
424    var cutoff_price_display_val = oldPriceElement.textContent;
425    if (cutoff_price_display_val) {
426        var oldPriceField = containerElement.querySelector('input[name="price_tmp1_old"]');
427        if (oldPriceField) {
428            var new_cuttoff_price = parseFloat(oldPriceField.value) + amt;
429            new_cuttoff_price = new_cuttoff_price.toFixed(JS_WP_ESTORE_VARIATION_NUM_OF_DECIMALS);
430            if (decimal_sep != ".") {
431                new_cuttoff_price = new_cuttoff_price.replace(".", decimal_sep);
432            }
433            var new_cuttoff_price_text = JS_WP_ESTORE_CURRENCY_SYMBOL + new_cuttoff_price;
434            if (JS_WP_ESTORE_VARIATION_CURRENCY_POS == 'right') {
435                new_cuttoff_price_text = new_cuttoff_price + JS_WP_ESTORE_CURRENCY_SYMBOL;
436            }
437            oldPriceElement.textContent = new_cuttoff_price_text;
438        }
439    }
440}

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.