PageSourceSearch

https://www.unraveledsa.com/1723204580/products-28.js

js unraveledsa.com collected 2026-09-29 11:55:27 UTC 88,457 bytes, 1,981 lines download raw bytes

1/* products-28.js
2* Includes Shopping Cart (pre-2017 version)
3* Below are function I have determined are needed by the new cart
4* */
5
6/*Code developed by Posin Begin*/
7
8//Function used to store value in cookie
9function setDesignWallCookie(name, value, expires, path, domain, secure) {
10    var today = new Date();
11    today.setTime(today.getTime());
12
13    if (expires) {
14        expires = expires * 1000 * 60 * 60 * 24;
15    }
16    var expires_date = new Date(today.getTime() + (expires));
17
18    if (domain == '') {
19        domain = document.domain.split('.');
20        if (domain[domain.length - 1].toLowerCase() == 'au' || domain[domain.length - 1].toLowerCase() == 'uk' || domain[domain.length - 1].toLowerCase() == 'nz' || domain[domain.length - 1].toLowerCase() == 'za') {
21            domain = domain[domain.length - 3] + '.' + domain[domain.length - 2] + '.' + domain[domain.length - 1];
22        } else {
23            domain = domain[domain.length - 2] + '.' + domain[domain.length - 1];
24        }
25    }
26
27    document.cookie = name + "=" + escape(value) +
28        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
29        ( ( path ) ? ";path=" + path : "" ) +
30        ( ( domain ) ? ";domain=" + domain : "" ) +
31        ( ( secure ) ? ";secure" : "" );
32}
33//Function used to get product id from cookie
34function getDesignWallCookie(check_name) {
35    var a_all_cookies = document.cookie.split(';');
36    var a_temp_cookie = '';
37    var cookie_name = '';
38    var cookie_value = '';
39    var b_cookie_found = false;
40
41    for (i = 0; i < a_all_cookies.length; i++) {
42        a_temp_cookie = a_all_cookies[i].split('=');
43
44        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
45
46        if (cookie_name == check_name) {
47            b_cookie_found = true;
48
49            if (a_temp_cookie.length > 1) {
50                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
51            }
52
53            return cookie_value;
54            break;
55        }
56        a_temp_cookie = null;
57        cookie_name = '';
58    }
59    if (!b_cookie_found) {
60        return null;
61    }
62}
63
64//Function used to open a design wall popup
65function o(href, height, width) {
66    var w = window.open(href, "popup", "height=" + height + ",width=" + width + ",resizable,scrollbars=yes");
67    w.focus();
68}
69
70//Function used to store  product id in cookie
71function AddProductToDesignWall(store_url, productId) {
72    var designWall = '';
73    if (getDesignWallCookie('designWallCookie')) {
74        designWall = getDesignWallCookie('designWallCookie');
75    }
76    var designWallArray = new Array();
77    designWallArray = designWall.split('|');
78    var itemFlag = 0;
79    for (var i = 0; i < designWallArray.length; i++) {
80        if (designWallArray[i] != '') {
81            if (designWallArray[i] == productId) {
82                itemFlag = 1;
83                break;
84            }
85        }
86    }
87
88    if (itemFlag == 0) {
89        if (designWall == "") {
90            setDesignWallCookie('designWallCookie', productId, '', '/', '', '');
91        }
92        else {
93            setDesignWallCookie('designWallCookie', designWall + '|' + productId, '', '/', '', '');
94        }
95    }
96    o(store_url, 630, 800)
97
98}
99
100/*Code developed by Posin End*/
101
102function checkLength(o, n, min, max) {
103    if (o.val().length > max || o.val().length < min) {
104        o.addClass("ui-state-error");
105        alert("Length of " + n + " must be between " +
106            min + " and " + max + ".");
107        return false;
108    } else {
109        return true;
110    }
111}
112
113function alertAndRemoveCoupon(i, message) {
114    alert(message);
115    $('#code').val('');
116    window.cartArray.remove(i);
117    Set_Cart_Cookie('cart', BuildCookieFromArray(), '', '/', '', '');
118}
119
120function getCouponExpiredString(data) {
121    var date_str = 'Coupon "' + data.code + '"';
122    if (data.status === 'expired') {
123        date_str += ' has expired.';
124        if (data.date !== undefined) {
125            date_str += '  Exp date: ' + data.date;
126        }
127    }
128    else if (data.status === 'invalid') {
129        date_str += ' is not valid yet.';
130        if (data.date !== undefined) {
131            date_str += '  Start date: ' + data.date;
132        }
133    }
134    return date_str;
135}
136
137var productParams = [];
138
139function GetAttendees(in_businessEmail, in_paymentAction, productId, productTitle, productPrice, productWeight, productCountType, productSku, requiresDownloadEmailAddress, minQuantity, maxQuantity, isTimed, in_notes, in_shipping, in_taxes, inlineAddToCartBtn, in_productType, in_hasAttendees, isDiscountEligible, productImagePath, productImageStyle, requireClassAttendees, pslrId, packageData, holdingId, deptId, categoryIdList, displayPrice, unitType, soldInIncrements) {
140    productParams[productId] = [];
141    productParams[productId]['in_businessEmail'] = in_businessEmail;
142    productParams[productId]['in_paymentAction'] = in_paymentAction;
143    productParams[productId]['productId'] = productId;
144    productParams[productId]['productTitle'] = productTitle;
145    productParams[productId]['productPrice'] = productPrice;
146    productParams[productId]['displayPrice'] = productPrice;
147    productParams[productId]['productWeight'] = productWeight;
148    productParams[productId]['productCountType'] = productCountType;
149    productParams[productId]['productSku'] = productSku;
150    productParams[productId]['requiresDownloadEmailAddress'] = requiresDownloadEmailAddress;
151    productParams[productId]['minQuantity'] = minQuantity;
152    productParams[productId]['maxQuantity'] = maxQuantity;
153    productParams[productId]['isTimed'] = isTimed;
154    productParams[productId]['in_notes'] = in_notes;
155    productParams[productId]['in_shipping'] = in_shipping;
156    productParams[productId]['in_taxes'] = in_taxes;
157    productParams[productId]['inlineAddToCartBtn'] = inlineAddToCartBtn;
158    productParams[productId]['in_productType'] = in_productType;
159    productParams[productId]['in_hasAttendees'] = in_hasAttendees;
160    productParams[productId]['isDiscountEligible'] = isDiscountEligible;
161    productParams[productId]['productImagePath'] = productImagePath;
162    productParams[productId]['productImageStyle'] = productImageStyle;
163    productParams[productId]['requireClassAttendees'] = requireClassAttendees;
164
165    productParams[productId]['pslrId'] = pslrId;
166    productParams[productId]['packageData'] = packageData;
167    productParams[productId]['holdingId'] = holdingId;
168
169    productParams[productId]['deptId'] = deptId;
170    productParams[productId]['categoryIdList'] = categoryIdList;
171    productParams[productId]['unitType'] = unitType;
172    productParams[productId]['soldInIncrements'] = soldInIncrements;
173
174    // Make a dialog box if needed
175    if ($('#attendees-form').length == 0) {
176        $('body').append(
177            '<div id="attendees-form" title="Attendees">' +
178            '<form>' +
179            '<span id="attendeeInputs"></span>' +
180            '</form>' +
181            '</div>'
182        );
183
184        $("#attendees-form").dialog({
185            autoOpen: false,
186            height: 330,
187            width: 570,
188            modal: true,
189            buttons: {
190                "Add to Cart": function() {
191                    var bValid = true;
192                    var attendeeCount;
193                    var productId = $('#attendeeProductId').val();
194                    if (inlineAddToCartBtn) {
195                        attendeeCount = parseInt(document.getElementById('inlineInteger' + productId).value) + parseFloat(document.getElementById('inlineFraction' + productId).value);
196                    } else {
197                        attendeeCount = parseInt(document.getElementById('integer' + productId).value) + parseFloat(document.getElementById('fraction' + productId).value);
198                    }
199                    $('.attendeeField').removeClass("ui-state-error");
200
201                    for (var i = 0; i < attendeeCount; i++) {
202                        if (!($('#attendeeName' + i).val().replace(/^\s+|\s+$/g, '').indexOf(' ') > 0)) {
203                            alert('Both first and last names must be entered.');
204                            $('#attendeeName' + i).addClass("ui-state-error");
205                            bValid = false;
206                            break;
207                        }
208                        bValid = bValid && checkLength($('#attendeePhone' + i), "phone", 10, 16);
209                        if (bValid == false) {
210                            break;
211                        }
212                        bValid = bValid && checkLength($('#attendeeEmail' + i), "email", 6, 100);
213                        if (bValid == false) {
214                            break;
215                        }
216                    }
217
218                    if (bValid) {
219                        var attendeeVal = '';
220                        for (var i = 0; i < attendeeCount; i++) {
221                            attendeeVal += $('#attendeeName' + i).val() + '::' + $('#attendeePhone' + i).val() + '::' + $('#attendeeEmail' + i).val() + ';;';
222                        }
223
224                        AddProductToCart(
225                            productParams[productId]['in_businessEmail'],
226                            productParams[productId]['in_paymentAction'],
227                            productParams[productId]['productId'],
228                            productParams[productId]['productTitle'],
229                            productParams[productId]['productPrice'],
230                            productParams[productId]['productWeight'],
231                            productParams[productId]['productCountType'],
232                            productParams[productId]['productSku'],
233                            productParams[productId]['requiresDownloadEmailAddress'],
234                            productParams[productId]['minQuantity'],
235                            productParams[productId]['maxQuantity'],
236                            productParams[productId]['isTimed'],
237                            productParams[productId]['in_notes'],
238                            productParams[productId]['in_shipping'],
239                            productParams[productId]['in_taxes'],
240                            productParams[productId]['inlineAddToCartBtn'],
241                            productParams[productId]['in_productType'],
242                            attendeeVal,
243                            productParams[productId]['isDiscountEligible'],
244                            productParams[productId]['productImagePath'],
245                            productParams[productId]['productImageStyle'],
246                            productParams[productId]['requireClassAttendees'],
247
248                            productParams[productId]['pslrId'],
249                            productParams[productId]['packageData'],
250                            productParams[productId]['holdingId'],
251
252                            productParams[productId]['deptId'] = deptId,
253                            productParams[productId]['categoryIdList'],
254                            productParams[productId]['productPrice'],
255                            productParams[productId]['unitType'],
256                            productParams[productId]['soldInIncrements']
257                        );
258
259                        $(this).dialog("close");
260                    }
261                },
262                Cancel: function() {
263                    $(this).dialog("close");
264                }
265            },
266            close: function() {
267            }
268        });
269    }
270
271    var str = '';
272    str += '' +
273        '<input type=hidden id="attendeeProductId" value="' + productId + '" />' +
274        '<table cellpadding=10 cellspacing=0 border=0>' +
275        '	<tr>' +
276        '		<td>&nbsp;</td>' +
277        '		<td><b>Full Name</b></td>' +
278        '		<td><b>Phone</b></td>' +
279        '		<td><b>Email</b></td>' +
280        '	</tr>';
281
282    var attendeeCount;
283    if (inlineAddToCartBtn) {
284        attendeeCount = parseInt(document.getElementById('inlineInteger' + productId).value) + parseFloat(document.getElementById('inlineFraction' + productId).value);
285    } else {
286        attendeeCount = parseInt(document.getElementById('integer' + productId).value) + parseFloat(document.getElementById('fraction' + productId).value);
287    }
288
289    for (var i = 0; i < attendeeCount; i++) {
290        str += '' +
291            '<tr>' +
292            '	<td>#' + (i + 1) + '</td>' +
293            '	<td><input id="attendeeName' + i + '" type=text class="attendeeField" style="width:150px;" /></td>' +
294            '	<td><input id="attendeePhone' + i + '" type=text class="attendeeField" style="width:110px;" /></td>' +
295            '	<td><input id="attendeeEmail' + i + '" type=text class="attendeeField" style="width:150px;" /></td>' +
296            '</tr>';
297    }
298
299    str += '</table>';
300
301    $("#attendeeInputs").html(str);
302    $("#attendees-form").dialog("open");
303
304}
305
306// Below this point are function need by the old cart but not the new cart
307
308function CollapseCart() {
309    var cartDiv = $("#cartDiv");
310    var cartDivMobile = $("#cartDivMobile");
311    var totalItems = window.cartArray.length;
312
313    UpdateCouponsInCartArrayAndCookie();
314
315    cartDivMobile.html(
316        '<div style="padding:10px;"><table width="100%"><tr>
316' +
317        '<td style="text-align: left; color: #fff;"><a href="' + editcartUrl + '" style="">Cart - ' + totalItems + ' items</a></td>' +
318        '</tr></table></div>'
319    );
320
321    cartDiv.html(
322        '<div style="display:table; height:28px; text-align:right; width:100%;">' +
323        '  <span style="vertical-align:middle; display:table-cell; color: #ccc; font-family: Arial; font-size: 12px !important;">' +
324        '    <a href="javascript:ProceedToCheckout(\'no\');" style="' + linkStyles + '">Check Out</a>' +
325        '    &nbsp; | &nbsp; ' +
326        '    <a href="' + editcartUrl + '" style="' + linkStyles + '">View Cart</a>' +
327        '    &nbsp;&nbsp;&nbsp; ' +
328        '  </span>' +
329        '  <span style="vertical-align:middle; display:table-cell; color: #ccc; font-family: Arial; font-size: 12px !important;">' +
330        '    <a href="#" onclick="ExpandCart();"><img border=0 width=16 height=11 src="https://siteimages.s3.amazonaws.com/btn-expand.png"></a>' +
331        '  </span>' +
332        '</div>' +
333        MakeCartForm() +
334        '');
335
336    var cart = Get_Cart_Cookie('cart');
337    cart = 'mode##collapsed' + cart.substring(cart.indexOf(';'));
338    Set_Cart_Cookie('cart', cart, '', '/', '', '');
339}
340
341// Test to see if in_email is a valid email address--as far as we can tell with Javascript
342function IsValidEmail(in_email) {
343    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
344    if (reg.test(in_email) == false) {
345        return false;
346    } else {
347        return true;
348    }
349}
350
351function ProceedToCheckout(skip) {
352
353    // do normal checkout
354    if (window.paymentProcessor === undefined || window.paymentProcessor == false) {
355        window.paymentProcessor = 'paypal';
356    }
357
358    // see if we need to get their email address for digital downloads
359    var needEmail = false;
360    var cart = '';
361    if (Get_Cart_Cookie('cart')) {
362        cart = Get_Cart_Cookie('cart');
363    }
364
365    for (var i = 0; i < window.cartArray.length; i++) {
366        if (window.cartArray[i][0] == 'product' && window.cartArray[i][8] == 'yes') {
367            needEmail = true;
368            break;
369        }
370    }
371
372    // if needed, get email address for digital download
373    if (needEmail && cart.indexOf("downloadEmail") == -1 && (window.checkoutVersion == '' || window.checkoutVersion == '2014')) {
374        var email = prompt("At least 1 item in your shopping cart will be emailed to you.  Please enter your email address:");
375        if (IsValidEmail(email)) {
376            Set_Cart_Cookie('cart', cart + ';;downloadEmail##' + email, '', '/', '', '');
377        } else {
378            alert('The email address you entered was not a valid email address.');
379            return;
380        }
381    }
382
383    // Get shipping method id (if possible)
384    var shippingMethod = $('input[name=shipRadio]:checked');
385    var shippingId = '';
386    if (shippingMethod.attr('id') != undefined) {
387        shippingId = parseInt(shippingMethod.attr('id').substring(10));
388    }
389
390    if (window.paymentProcessor == 'NMI3S') {
391        if (window.checkoutVersion == '' || window.checkoutVersion == '2014') {
392            location = window.CheckoutUrl;
393        }
394        else {
395            location = window.EditCartUrl;
396        }
397    }
398    else if (window.paymentProcessor == 'wholesaleCheckoutNoCC') {
399        if (window.checkoutVersion == '' || window.checkoutVersion == '2014') {
400            $.post(document.location.protocol + "//" + document.domain + "/module/product.htm?save_shopping_cart_contents=1&shippingCalcId=" + shippingId + "&shopping_cart_contents_id=" + window.shopping_cart_contents_id, $("#cartform").serialize(),
401                function(data) {
402                    location = "/module/product.htm?wholesaleCheckoutNoCC=1&shoppingCartContentsId=" + parseInt(data);
403                });
404        } else {
405            location = window.EditCartUrl;
406        }
407    }
408    else {
409        // paypal
410        if (window.checkoutVersion == '' || window.checkoutVersion == '2014') {
411            if (skip !== 'yes' && useShipping == 'yes') {
412                // See if we have anything that needs to be shipped
413                var needsShipping = false;
414                for (var i = 0; i < window.cartArray.length; i++) {
415                    if (window.cartArray[i][0] == 'product' && window.cartArray[i].length > 16 && window.cartArray[i][16] != 'GC' && window.cartArray[i][16] != 'class' && window.cartArray[i][8] != 'yes') {
416                        needsShipping = true;
417                        break;
418                    }
419                }
420
421                if (needsShipping == true) {
422                    showShippingOptions('yes', 0, 0, 0);
423                }
424                else {
425                    $("#cartform").append(' <input type=hidden name=shipping_1 id=shipping_1 value=0>');
426                    ProceedToCheckout('yes');
427                }
428            }
429            else {
430                $.post(document.location.protocol + "//" + document.domain + "/module/product.htm?save_shopping_cart_contents=1&shippingCalcId=" + shippingId + "&shopping_cart_contents_id=" + window.shopping_cart_contents_id, $("#cartform").serialize(),
431                    function(data) {
432                        $("#cartform #notify_url").val(document.location.protocol + '//' + document.domain + '/module/product.htm?ipn=1&shopping_cart_contents_id=' + parseInt(data));
433                        document.cartform.submit();
434                    });
435            }
436        }
437        else {
438            location = window.EditCartUrl;
439        }
440    }
441}
442
443function showShippingOptions(dialogvar, weight, subtotal, quantity) {
444    var appendString = '';
445    if (dialogvar == 'yes') {
446        $("#overlayShipping").replaceWith('');
447        appendString += '<div id="overlayShipping" style="display:none;" title="Shipping Options"><br>Estimate shipping and tax<br><br>';
448    }
449
450    if (window.domesticCountry == 'United States') {
451        appendString += '<select id="selectState">' +
452            '<option selected="selected">Select State</option>' +
453            '<option disabled="disabled">----------</option>' +
454            '<option value="AL">Alabama</option>' +
455            '<option value="AK">Alaska</option>' +
456            '<option value="AS">American Samoa</option>' +
457            '<option value="AZ">Arizona</option>' +
458            '<option value="AR">Arkansas</option>' +
459            '<option value="CA">California</option>' +
460            '<option value="CO">Colorado</option>' +
461            '<option value="CT">Connecticut</option>' +
462            '<option value="DE">Delaware</option>' +
463            '<option value="DC">District of Columbia</option>' +
464            '<option value="FM">Federated States of Micronesia</option>' +
465            '<option value="FL">Florida</option>' +
466            '<option value="GA">Georgia</option>' +
467            '<option value="GU">Guam</option>' +
468            '<option value="HI">Hawaii</option>' +
469            '<option value="ID">Idaho</option>' +
470            '<option value="IL">Illinois</option>' +
471            '<option value="IN">Indiana</option>' +
472            '<option value="IA">Iowa</option>' +
473            '<option value="KS">Kansas</option>' +
474            '<option value="KY">Kentucky</option>' +
475            '<option value="LA">Louisiana</option>' +
476            '<option value="ME">Maine</option>' +
477            '<option value="MH">Marshall Islands</option>' +
478            '<option value="MD">Maryland</option>' +
479            '<option value="MA">Massachusetts</option>' +
480            '<option value="MI">Michigan</option>' +
481            '<option value="MN">Minnesota</option>' +
482            '<option value="MS">Mississippi</option>' +
483            '<option value="MO">Missouri</option>' +
484            '<option value="MT">Montana</option>' +
485            '<option value="NE">Nebraska</option>' +
486            '<option value="NV">Nevada</option>' +
487            '<option value="NH">New Hampshire</option>' +
488            '<option value="NJ">New Jersey</option>' +
489            '<option value="NM">New Mexico</option>' +
490            '<option value="NY">New York</option>' +
491            '<option value="NC">North Carolina</option>' +
492            '<option value="ND">North Dakota</option>' +
493            '<option value="MP">Northern Mariana Islands</option>' +
494            '<option value="OH">Ohio</option>' +
495            '<option value="OK">Oklahoma</option>' +
496            '<option value="OR">Oregon</option>' +
497            '<option value="PW">Palau</option>' +
498            '<option value="PA">Pennsylvania</option>' +
499            '<option value="PR">Puerto Rico</option>' +
500            '<option value="RI">Rhode Island</option>' +
501            '<option value="SC">South Carolina</option>' +
502            '<option value="SD">South Dakota</option>' +
503            '<option value="TN">Tennessee</option>' +
504            '<option value="TX">Texas</option>' +
505            '<option value="UT">Utah</option>' +
506            '<option value="VT">Vermont</option>' +
507            '<option value="VI">Virgin Islands</option>' +
508            '<option value="VA">Virginia</option>' +
509            '<option value="WA">Washington</option>' +
510            '<option value="WV">West Virginia</option>' +
511            '<option value="WI">Wisconsin</option>' +
512            '<option value="WY">Wyoming</option>' +
513            '<option value="AA">Armed Forces AA</option>' +
514            '<option value="AE">Armed Forces AE</option>' +
515            '<option value="AP">Armed Forces AP</option>' +
516            '</select>';
517    } else if (window.domesticCountry == 'Canada') {
518        appendString += '<select id="selectState">' +
519            '<option selected="selected">Select Province</option>' +
520            '<option disabled="disabled">----------</option>' +
521            '<option>Alberta</option>' +
522            '<option>British Columbia</option>' +
523            '<option>Manitoba</option>' +
524            '<option>New Brunswick</option>' +
525            '<option>Newfoundland</option>' +
526            '<option>Northwest Territories</option>' +
527            '<option>Nova Scotia</option>' +
528            '<option>Nunavut</option>' +
529            '<option>Ontario</option>' +
530            '<option>Prince Edward Island</option>' +
531            '<option>Quebec</option>' +
532            '<option>Saskatchewan</option>' +
533            '<option>Yukon</option>' +
534            '</select>';
535    } else if (window.domesticCountry == 'Australia') {
536        appendString += '<select id="selectState">' +
537            '<option selected="selected">Select State</option>' +
538            '<option disabled="disabled">----------</option>' +
539            '<option>Australian Capital Territory</option>' +
540            '<option>New South Wales</option>' +
541            '<option>Northern Territory</option>' +
542            '<option>Queensland</option>' +
543            '<option>South Australia</option>' +
544            '<option>Tasmania</option>' +
545            '<option>Victoria</option>' +
546            '<option>Western Australia</option>' +
547            '</select>';
548    }
549
550    appendString += '<select id="selectIntState" style="display:none">
550' +
551        '<option selected="selected">Select Country</option>' +
552        '<option disabled="disabled">----------</option>' +
553        '<option>Afghanistan</option>' +
554        '<option>Aland Islands</option>' +
555        '<option>Albania</option>' +
556        '<option>Algeria</option>' +
557        '<option>American Samoa</option>' +
558        '<option>Andorra</option>' +
559        '<option>Angola</option>' +
560        '<option>Anguilla</option>' +
561        '<option>Antarctica</option>' +
562        '<option>Antigua and Barbuda</option>' +
563        '<option>Argentina</option>' +
564        '<option>Armenia</option>' +
565        '<option>Aruba</option>' +
566        '<option>Australia</option>' +
567        '<option>Austria</option>' +
568        '<option>Azerbaijan Republic</option>' +
569        '<option>Bahamas</option>' +
570        '<option>Bahrain</option>' +
571        '<option>Bangladesh</option>' +
572        '<option>Barbados</option>' +
573        '<option>Belarus</option>' +
574        '<option>Belgium</option>' +
575        '<option>Belize</option>' +
576        '<option>Benin</option>' +
577        '<option>Bermuda</option>' +
578        '<option>Bhutan</option>' +
579        '<option>Bolivia</option>' +
580        '<option>Bosnia and Herzegonvina</option>' +
581        '<option>Botswana</option>' +
582        '<option>Bouvet Island</option>' +
583        '<option>Brazil</option>' +
584        '<option>British Indian Ocean Territory</option>' +
585        '<option>British Virgin Islands</option>' +
586        '<option>Brunei</option>' +
587        '<option>Bulgaria</option>' +
588        '<option>Burkina Faso</option>' +
589        '<option>Burundi</option>' +
590        '<option>Cambodia</option>' +
591        '<option>Cameroon</option>' +
592        '<option>Canada</option>' +
593        '<option>&nbsp;&nbsp; Alberta</option>' +
594        '<option>&nbsp;&nbsp; British Columbia</option>' +
595        '<option>&nbsp;&nbsp; Manitoba</option>' +
596        '<option>&nbsp;&nbsp; New Brunswick</option>' +
597        '<option>&nbsp;&nbsp; Newfoundland</option>' +
598        '<option>&nbsp;&nbsp; Northwest Territories</option>' +
599        '<option>&nbsp;&nbsp; Nova Scotia</option>' +
600        '<option>&nbsp;&nbsp; Nunavut</option>' +
601        '<option>&nbsp;&nbsp; Ontario</option>' +
602        '<option>&nbsp;&nbsp; Prince Edward Island</option>' +
603        '<option>&nbsp;&nbsp; Quebec</option>' +
604        '<option>&nbsp;&nbsp; Saskatchewan</option>' +
605        '<option>&nbsp;&nbsp; Yukon</option>' +
606        '<option>Cape Verde</option>' +
607        '<option>Cayman Islands</option>' +
608        '<option>Central African Republic</option>' +
609        '<option>Chad</option>' +
610        '<option>Chile</option>' +
611        '<option>China</option>' +
612        '<option>Christmas Island</option>' +
613        '<option>Cocos Island</option>' +
614        '<option>Colombia</option>' +
615        '<option>Comoros</option>' +
616        '<option>Cook Islands</option>' +
617        '<option>Costa Rica</option>' +
618        '<option>Cote DIvoire</option>' +
619        '<option>Croatia</option>' +
620        '<option>Cuba</option>' +
621        '<option>Cyprus</option>' +
622        '<option>Czech Republic</option>' +
623        '<option>Democratic Republic of the Congo</option>' +
624        '<option>Denmark</option>' +
625        '<option>Djibouti</option>' +
626        '<option>Dominica</option>' +
627        '<option>Dominican Republic</option>' +
628        '<option>East Timor</option>' +
629        '<option>Ecuador</option>' +
630        '<option>Egypt</option>' +
631        '<option>El Salvador</option>' +
632        '<option>Equatorial Guinea</option>' +
633        '<option>Eritrea</option>' +
634        '<option>Estonia</option>' +
635        '<option>Ethiopia</option>' +
636        '<option>Falkland Islands</option>' +
637        '<option>Faroe Islands</option>' +
638        '<option>Federated States of Micronesia</option>' +
639        '<option>Fiji</option>' +
640        '<option>Finland</option>' +
641        '<option>France</option>' +
642        '<option>French Guiana</option>' +
643        '<option>French Polynesia</option>' +
644        '<option>French Southern Territories</option>' +
645        '<option>Gabon Republic</option>' +
646        '<option>Gambia</option>' +
647        '<option>Georgia</option>' +
648        '<option>Germany</option>' +
649        '<option>Ghana</option>' +
650        '<option>Gibraltar</option>' +
651        '<option>Greece</option>' +
652        '<option>Greenland</option>' +
653        '<option>Grenada</option>' +
654        '<option>Guadeloupe</option>' +
655        '<option>Guam</option>' +
656        '<option>Guatemala</option>' +
657        '<option>Guernsey</option>' +
658        '<option>Guinea</option>' +
659        '<option>Guinea Bissau</option>' +
660        '<option>Guyana</option>' +
661        '<option>Haiti</option>' +
662        '<option>Heard and McDonald Islands</option>' +
663        '<option>Honduras</option>' +
664        '<option>Hong Kong</option>' +
665        '<option>Hungary</option>' +
666        '<option>Iceland</option>' +
667        '<option>India</option>' +
668        '<option>Indonesia</option>' +
669        '<option>Iran</option>' +
670        '<option>Iraq</option>' +
671        '<option>Ireland</option>' +
672        '<option>Isle of Man</option>' +
673        '<option>Israel</option>' +
674        '<option>Italy</option>' +
675        '<option>Jamaica</option>' +
676        '<option>Japan</option>' +
677        '<option>Jersey</option>' +
678        '<option>Jordan</option>' +
679        '<option>Kazakhstan</option>' +
680        '<option>Kenya</option>' +
681        '<option>Kiribati</option>' +
682        '<option>Kuwait</option>' +
683        '<option>Kyrgyzstan</option>' +
684        '<option>Laos</option>' +
685        '<option>Latvia</option>' +
686        '<option>Lebanon</option>' +
687        '<option>Lesotho</option>' +
688        '<option>Liberia</option>' +
689        '<option>Libya</option>' +
690        '<option>Liechtenstein</option>' +
691        '<option>Lithuania</option>' +
692        '<option>Luxembourg</option>' +
693        '<option>Macau</option>' +
694        '<option>Macedonia</option>' +
695        '<option>Madagascar</option>' +
696        '<option>Malawi</option>' +
697        '<option>Malaysia</option>' +
698        '<option>Maldives</option>' +
699        '<option>Mali</option>' +
700        '<option>Malta</option>' +
701        '<option>Marshall Islands</option>' +
702        '<option>Martinique</option>' +
703        '<option>Mauritania</option>' +
704        '<option>Mauritius</option>' +
705        '<option>Mayotte</option>' +
706        '<option>Mexico</option>' +
707        '<option>Moldova</option>' +
708        '<option>Monaca</option>' +
709        '<option>Mongolia</option>' +
710        '<option>Montenegro</option>' +
711        '<option>Montserrat</option>' +
712        '<option>Morocco</option>' +
713        '<option>Mozambique</option>' +
714        '<option>Myanmar</option>' +
715        '<option>Namibia</option>' +
716        '<option>Nauru</option>' +
717        '<option>Nepal</option>' +
718        '<option>Netherlands</option>' +
719        '<option>Netherlands Antilles</option>' +
720        '<option>New Caledonia</option>' +
721        '<option>New Zealand</option>' +
722        '<option>Nicaragua</option>' +
723        '<option>Niger</option>' +
724        '<option>Nigeria</option>' +
725        '<option>iue</option>' +
726        '<option>Norfolk Island</option>' +
727        '<option>North Korea</option>' +
728        '<option>Northern Mariana Islands</option>' +
729        '<option>Norway</option>' +
730        '<option>Oman</option>' +
731        '<option>Pakistan</option>' +
732        '<option>Palau</option>' +
733        '<option>Palestine</option>' +
734        '<option>Panama</option>' +
735        '<option>Papua New uinea</option>' +
736        '<option>Paraguay</option>' +
737        '<option>Peru</option>' +
738        '<option>Philippines</option>' +
739        '<option>Pitcairn Islands</option>' +
740        '<option>Poland</option>' +
741        '<option>Portugal</option>' +
742        '<option>Puerto Rico</option>' +
743        '<option>Qatar</option>' +
744        '<option>Republic of the Congo</option>' +
745        '<option>Reunion</option>' +
746        '<option>Romania</option>' +
747        '<option>Russia</option>' +
748        '<option>Rwanda</option>' +
749        '<option>Saint Vincent and the Grenadin</option>' +
750        '<option>Samoa</option>' +
751        '<option>San Marino</option>' +
752        '<option>Sao Tome and Principe</option>' +
753        '<option>Saudi Arabia</option>' +
754        '<option>Senegal</option>' +
755        '<option>Serbia</option>' +
756        '<option>Serbia and Montenegro</option>' +
757        '<option>Seychelles</option>' +
758        '<option>Sierra Leone</option>' +
759        '<option>Singapore</option>' +
760        '<option>Slovakia</option>' +
761        '<option>Slovenia</option>' +
762        '<option>Soloman Islands</option>' +
763        '<option>Somalia</option>' +
764        '<option>South Africa</option>' +
765        '<option>South Georgia</option>' +
766        '<option>South Korea</option>' +
767        '<option>Spain</option>' +
768        '<option>Sri Lanka</option>' +
769        '<option>St. Helena</option>' +
770        '<option>St. Kitts and Nevis</option>' +
771        '<option>St. Lucia</option>' +
772        '<option>St. Pierre and Miquelon</option>' +
773        '<option>Sudan</option>' +
774        '<option>Suriname</option>' +
775        '<option>Svalbard and Jan Mayen Island</option>' +
776        '<option>Swaziland</option>' +
777        '<option>Sweden</option>' +
778        '<option>Switzerland</option>' +
779        '<option>Syria</option>' +
780        '<option>Taiwan</option>' +
781        '<option>Tajikistan</option>' +
782        '<option>Tanzania</option>' +
783        '<option>Thailand</option>' +
784        '<option>Timor-Leste</option>' +
785        '<option>Togo</option>' +
786        '<option>Tokelau</option>' +
787        '<option>Tonga</option>' +
788        '<option>Trinidad and Tobago</option>' +
789        '<option>Tunisia</option>' +
790        '<option>Turkey</option>' +
791        '<option>Turkmenistan</option>' +
792        '<option>Turks and Caicos Islands</option>' +
793        '<option>Tuvalu</option>' +
794        '<option>Uganda</option>' +
795        '<option>Ukraine</option>' +
796        '<option>United Arab Emirates</option>' +
797        '<option>United Kingdom</option>' +
798        '<option>United States</option>' +
799        '<option>Uruguay</option>' +
800        '<option>US Minor Outlying Islands</option>' +
801        '<option>Uzbekistan</option>' +
802        '<option>Vanuatu</option>' +
803        '<option>Vatican City State</option>' +
804        '<option>Venezuela</option>' +
805        '<option>Vietnam</option>' +
806        '<option>Virgin Islands (USA)</option>' +
807        '<option>Wallis and Futuna Islands</option>' +
808        '<option>Western Sahara</option>' +
809        '<option>Yemen</option>' +
810        '<option>Yugoslavia</option>' +
811        '<option>Zambia</option>' +
812        '<option>Zimbabwe</option>' +
813        '</select>';
814
815    appendString += '&nbsp&nbsp&nbsp';
816    appendString += '<a href="#" id="selectUs" style="display:none">Ship to ' + window.domesticCountry + '</a>';
817    appendString += '<a href="#" id="selectOutside">Ship outside ' + window.domesticCountry + '</a>';
818    appendString += '<br><br><table width="100%" id="shippingOptionsTable"><tbody id="shippingOptionsTableBody"></tbody><tfoot id="shippingOptionsTableFoot"></tfoot></table>';
819
820    if (dialogvar == 'yes') {
821        appendString += '</div>';
822        $(document.body).append(appendString);
823        $("#overlayShipping").dialog({width: 500, height: 400});
824    } else {
825        $("#shippingDiv").append(appendString);
826    }
827
828    $("#selectUs").bind("click", function(event) {
829        $("#selectOutside").show();
830        $("#selectState").show();
831        if (window.domesticCountry == 'United States' || window.domesticCountry == 'Australia') {
832            $("#selectState").val('Select State');
833        } else if (window.domesticCountry == 'United Kingdom') {
834            StateSelect('N/A');
835        } else {
836            $("#selectState").val('Select Province');
837        }
838        $("#selectIntState").hide();
839        $("#selectUs").hide();
840
841        $("#shippingOptionsTableBody").html('');
842        $("#shippingOptionsTableFoot").html('');
843
844        if (dialogvar !== 'yes') {
845            $("#shipCountry").val('1');
846            $("#x_ship_to_state").val('');
847            $("#x_ship_to_state").attr('disabled', 'disabled');
848            $("#x_ship_to_country").val('');
849            $("#x_ship_to_country").attr('disabled', 'disabled');
850            if (typeof(calculateTotal) == 'function') {
851                calculateTotal(0);
852            }
853        }
854    });
855
856    $("#selectOutside").bind("click", function(event) {
857        $("#selectState").hide();
858        $("#selectIntState").val('Select Country');
859        $("#selectIntState").show();
860        $("#selectOutside").hide();
861        $("#selectUs").show();
862
863        $("#shippingOptionsTableBody").html('');
864        $("#shippingOptionsTableFoot").html('');
865
866        if (dialogvar !== 'yes') {
867            $("#shipCountry").val('2');
868            $("#x_ship_to_state").val('');
869            $("#x_ship_to_state").removeAttr('disabled');
870            $("#x_ship_to_country").val('');
871            $("#x_ship_to_country").attr('disabled', 'disabled');
872            if (typeof(calculateTotal) == 'function') {
873                calculateTotal(0);
874            }
875        }
876    });
877
878    var cartUrlBase = '';
879    if (isAdminUrl(location.host)) {
880        cartUrlBase = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrlBase;
881    }
882
883    function StateSelect(selectedState) {
884        $("#shippingOptionsTableBody").html('');
885        $("#shippingOptionsTableFoot").html('');
886        if (typeof showShippingAddress != "undefined") {
887            showShippingAddress();
888        }
889
890        if (selectedState !== 'Select State' && selectedState !== 'Select Province') {
891            cartUrl = cartUrlBase + '/module/product.htm?shipping=1&nation=' + window.domesticCountry + '&location=' + selectedState;
892
893            GetShippingOptions(cartUrl, dialogvar, weight, subtotal, quantity);
894            $("#x_ship_to_state").val(selectedState);
895            $("#x_ship_to_country").val('U.S.');
896        }
897        else {
898            $("#x_ship_to_state").val('');
899            $("#x_ship_to_country").val('');
900        }
901    }
902
903    $("#selectState").bind("change", function(event) {
904        var selectedState = $('select#selectState option:selected').val();
905        if (selectedState !== 'Select State' && selectedState !== 'Select Province') {
906            StateSelect(selectedState);
907        }
908    });
909
910    $("#selectIntState").bind("change", function(event) {
911        $("#shippingOptionsTableBody").html('');
912        $("#shippingOptionsTableFoot").html('');
913        if (typeof showShippingAddress != "undefined") {
914            showShippingAddress();
915        }
916        var selectedCountry = $.trim($('select#selectIntState option:selected').val());
917        if (selectedCountry !== 'Select Country') {
918            cartUrl = cartUrlBase + '/module/product.htm?shipping=1&nation=International&location=' + selectedCountry;
919
920            GetShippingOptions(cartUrl, dialogvar, weight, subtotal, quantity);
921            //if (typeof(calculateTotal) == 'function') calculateTotal(0);
922            $("#x_ship_to_country").val(selectedCountry);
923            if (selectedCountry == 'Alberta' || selectedCountry == 'British Columbia' || selectedCountry == 'Manitoba' || selectedCountry == 'New Brunswick' || selectedCountry == 'Newfoundland' || selectedCountry == 'Northwest Territories' || selectedCountry == 'Nova Scotia' || selectedCountry == 'Nunavut' || selectedCountry == 'Ontario' || selectedCountry == 'Prince Edward Island' || selectedCountry == 'Quebec' || selectedCountry == 'Saskatchewan' || selectedCountry == 'Yukon') {
924                $("#x_ship_to_state").val(selectedCountry);
925                $("#x_ship_to_country").val('Canada');
926            } else {
927                $("#x_ship_to_state").val('');
928            }
929        } else {
930            $("#x_ship_to_country").val('');
931        }
932    });
933
934    if (window.domesticCountry == 'United Kingdom') {
935        StateSelect('N/A');
936    }
937}
938
939function GetShippingOptions(cartUrl, dialogvar, weight, subtotal, quantity) {
940    var totalWeight = 0;
941    var totalQuantity = 0;
942
943    if (dialogvar == 'yes') {  // paypal
944        var paypalsubtotal = 0;
945        for (var i = window.cartArray.length - 1; i >= 0; i--) {
946            if (window.cartArray[i][0] == 'product') {
947                totalWeight += (window.cartArray[i][4] * window.cartArray[i][5]);
948      
948          paypalsubtotal += Math.round(parseFloat(parseFloat(window.cartArray[i][3]) * parseFloat(window.cartArray[i][4])) * 100) / 100;
949                totalQuantity += parseFloat(window.cartArray[i][4]);
950            }
951        }
952        for (var i = window.cartArray.length - 1; i >= 0; i--) {
953            if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
954                var discount = CalculateDiscount(paypalsubtotal, i);
955                if (discount > 0) {
956                    discount = Math.round(discount * 100) / 100;
957                    paypalsubtotal -= discount;
958                }
959            }
960        }
961        subtotal = paypalsubtotal;
962    } else {
963        totalWeight = weight;
964        totalQuantity = quantity;
965    }
966    subtotal = Math.round(subtotal * 100) / 100;
967    //totalWeight = Math.ceil(totalWeight);
968    totalQuantity = Math.ceil(totalQuantity);
969    if (totalQuantity < 1) {
970        totalQuantity = 1;
971    }
972
973    cartUrl += '&weight=' + totalWeight + '&qty=' + totalQuantity + '&subtotal=' + subtotal;
974
975    $("#shippingOptionsTableBody").html('<img src="https://s3.amazonaws.com/siteimages/loading.gif">');
976
977    $.getJSON(cartUrl, function(data) {
978        $("#shippingOptionsTableBody").html('');
979        if (data) {
980            if (data.shipOptions) {
981                if(data.shipOptions.length > 0) {
982                    var checked = 'checked="checked"';
983
984                    // All "Store Pickup" options are removed below - The separate "Pickup" option will be used instead
985
986                    for (var i = 0; i < data.shipOptions.length; i++) {
987                        var optionName = data.shipOptions[i].name;
988                        if (isStorePickupOption(optionName) || isCurbsidePickupOption(optionName)) {
989                            continue;
990                        }
991
992                        if (i > 0) {
993                            checked = '';
994                        }
995
996                        var selectedString = '';
997                        if (i == 0) {
998                            selectedString = '<span class="selectedMethodClass">$ ' + parseFloat(data.shipOptions[i].price).toFixed(2) + '</span>';
999                        }
1000
1001                        $("#shippingOptionsTableBody").append(
1002                            '<tr><td nowrap><input type="radio" name="shipRadio" id="shipRadio_' +
1003                            data.shipOptions[i].id + '" value="' + parseFloat(data.shipOptions[i].price).toFixed(2) +
1004                            '" ' + checked + '/>&nbsp&nbsp' + optionName +
1005                            '</td><td  width="120px" align=right>' + parseFloat(data.shipOptions[i].price).toFixed(2) +
1006                            '</td><td align=right id="selectedMethodTd_' + i + '" style="font-weight:bold; ' +
1007                            (dialogvar == 'yes' ? 'display:none;' : '') + '">' + selectedString + '</td></tr>'
1008                        );
1009                    }
1010
1011                    for (var i = 0; i < data.shipOptions.length; i++) {
1012                        var optionName = data.shipOptions[i].name;
1013                        if (isStorePickupOption(optionName) || isCurbsidePickupOption(optionName)) {
1014                            continue;
1015                        }
1016
1017                        $('#shipRadio_'+ data.shipOptions[i].id).bind("change", {i:i}, function(event) {
1018                            $('.selectedMethodClass').remove();
1019                            $('#selectedMethodTd_' + event.data.i).html('<span class="selectedMethodClass">$ ' + parseFloat(data.shipOptions[event.data.i].price).toFixed(2) + '</span>');
1020                        });
1021                    }
1022
1023                    $('input[name=shipRadio]').bind("change", function() {
1024                        var newShippingAmount = parseFloat($('input[name=shipRadio]:checked').val());
1025                        if (typeof(calculateTotal) == 'function') {
1026                            calculateTotal(newShippingAmount);
1027                        }
1028                    });
1029
1030                    if (dialogvar == 'yes') {  // here do a save button, if Paypal
1031                        $("#shippingOptionsTableFoot").append('<tr><td>&nbsp</td></tr><tr><td><input type="submit" value="Next >" name="submit" id="shippingOptionsSubmit"></td></tr>');
1032
1033                        $("#shippingOptionsSubmit").bind("click", function(event) {
1034                            var shippingAmount = $('input[name=shipRadio]:checked').val();
1035                            $("#cartform").append(' <input type=hidden name=shipping_1 id=shipping_1 value=' + shippingAmount + '>');
1036                            ProceedToCheckout('yes');
1037                            return false;
1038                        });
1039                    }
1040
1041                } else {
1042                    $("#shippingOptionsTableBody").append('<tr><td>Contact store for shipping information</td></tr>');
1043                }
1044                var newShippingAmount = parseFloat($('input[name=shipRadio]:checked').val());
1045                if (typeof(calculateTotal) == 'function') {
1046                    calculateTotal(newShippingAmount);
1047                }
1048            }
1049        }
1050    });
1051}
1052
1053function isStorePickupOption(optionName) {
1054    "use strict";
1055
1056    var index = optionName.search('Store Pickup');
1057    return (index >= 0);
1058}
1059
1060function isCurbsidePickupOption(optionName) {
1061    "use strict";
1062
1063    var index = optionName.search('Curbside Pickup');
1064    return (index >= 0);
1065}
1066
1067function MobileCart(forceExpand) {
1068    var mobileCartDiv = $("#mobileCartDiv");
1069    if (forceExpand) {
1070        mobileCartDiv.show();
1071    }
1072    else {
1073        mobileCartDiv.hide();
1074    }
1075
1076    var products = '';
1077    var subtotal = 0;
1078    var subtotal_to_discount = 0;
1079    var giftCardSubtotal = 0;
1080    var itemTotal = 0;
1081    var integer = 0;
1082    var remainder = 0;
1083
1084    UpdateCouponsInCartArrayAndCookie();
1085
1086    for (var i = 0; i < window.cartArray.length; i++) {
1087        if (window.cartArray[i][0] == 'product') {
1088            var idExt = window.cartArray[i][1];
1089            if (window.cartArray[i].length >= 18) {
1090                idExt += '-' + window.cartArray[i][17];
1091            }
1092
1093            var amount = Math.round((parseFloat(window.cartArray[i][3]) * window.cartArray[i][4]) * 100) / 100;
1094            if (window.cartArray[i].length > 16 && window.cartArray[i][16] == 'GC') {
1095                giftCardSubtotal += amount;
1096            }
1097            else {
1098                subtotal += amount;
1099                if (window.cartArray[i][19] === "true") // 19 - discount_eligible
1100                {
1101                    subtotal_to_discount += amount;
1102                }
1103            }
1104
1105            itemTotal = parseFloat(window.cartArray[i][3]) * parseFloat(window.cartArray[i][4]);
1106            itemTotal = Math.round(itemTotal * 100) / 100;
1107            integer = Math.floor(window.cartArray[i][4]);
1108            products +=
1109                '	<tr>' +
1110                '		<td colspan=3 style="color: #556b2f;">' + window.cartArray[i][2].replace(/\+/g, ' ') + '</td>' +
1111                '   </tr>' +
1112                '   <tr>' +
1113                '		<td align=right nowrap><b>' + formatCurrency(window.cartArray[i][3]) + '</b></td>' +
1114                '		<td align=left nowrap>' +
1115                '			<select onchange="checkFabricMinimum(\'' + idExt + '\', ' + window.cartArray[i][10] + ')" name=integer' + idExt + ' id=integer' + idExt + '>';
1116            for (var j = 0; j <= window.cartArray[i][10]; j++) {
1117                products +=
1118                    '				<option value=' + j + (j == integer ? ' selected' : '') + '>' + j + '</option>';
1119            }
1120            products += '</select>';
1121            products += '<script>checkFabricMinimum(\'' + idExt + '\', ' + window.cartArray[i][10] + ');</script>';
1122
1123            if (window.cartArray[i][6] == 'fraction') {
1124
1125                remainder = Math.round(parseFloat(window.cartArray[i][4]) * 100) % 100;
1126
1127                var maxVal = parseFloat(window.cartArray[i][10]);
1128                var maxIntegerVal = Math.floor(maxVal);
1129                var maxFractionVal = Math.floor((maxVal * 100) % 100) / 100;
1130
1131                if (window.measurementUnit == 'Meter') {
1132                    products += '<select name=fraction' + idExt + ' id=fraction' + idExt + '>';
1133                    products += '	<option value="0"' + (remainder == 0 ? ' selected' : '') + '>.0</option>';
1134                    if (integer == 0 && window.cartArray[i][9] == 'fat quarter') {
1135                        if (maxIntegerVal > 0 || maxFractionVal >= 0.25) {
1136                            products += '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>fat quarter</option>';
1137                        }
1138                        if (maxIntegerVal > 0 || maxFractionVal >= 0.3) {
1139                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1140                        }
1141                        if (maxIntegerVal > 0 || maxFractionVal >= 0.4) {
1142                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1143                        }
1144                    }
1145                    else if (integer == 0 && (window.cartArray[i][9] == '0.25' || window.cartArray[i][9] == 'fat quarter')) {
1146                        if (maxIntegerVal > 0 || maxFractionVal >= 0.3) {
1147                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1148                        }
1149                        if (maxIntegerVal > 0 || maxFractionVal >= 0.4) {
1150                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1151                        }
1152                    }
1153                    else if (integer > 0) {
1154                        if (integer < maxIntegerVal || maxFractionVal >= 0.1) {
1155                            products += '	<option value="0.1"' + (remainder == 10 ? ' selected' : '') + '>.1</option>';
1156                        }
1157                        if (integer < maxIntegerVal || maxFractionVal >= 0.2) {
1158                            products += '	<option value="0.2"' + (remainder == 20 ? ' selected' : '') + '>.2</option>';
1159                        }
1160                        if (integer < maxIntegerVal || maxFractionVal >= 0.3) {
1161                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1162                        }
1163                        if (integer < maxIntegerVal || maxFractionVal >= 0.4) {
1164                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1165                        }
1166                    }
1167                    if (integer < maxIntegerVal || maxFractionVal >= 0.5) {
1168                        products += '	<option value="0.5"' + (remainder == 50 ? ' selected' : '') + '>.5</option>';
1169                    }
1170                    if (integer < maxIntegerVal || maxFractionVal >= 0.6) {
1171                        products += '	<option value="0.6"' + (remainder == 60 ? ' selected' : '') + '>.6</option>';
1172                    }
1173                    if (integer < maxIntegerVal || maxFractionVal >= 0.7) {
1174                        products += '	<option value="0.7"' + (remainder == 70 ? ' selected' : '') + '>.7</option>';
1175                    }
1176                    if (integer < maxIntegerVal || maxFractionVal >= 0.8) {
1177                        products += '	<option value="0.8"' + (remainder == 80 ? ' selected' : '') + '>.8</option>';
1178                    }
1179                    if (integer < maxIntegerVal || maxFractionVal >= 0.9) {
1180                        products += '	<option value="0.9"' + (remainder == 90 ? ' selected' : '') + '>.9</option>';
1181                    }
1182                    products += '</select>';
1183                }
1184                else { // Yards
1185                    products +=
1186                        '<select name=fraction' + idExt + ' id=fraction' + idExt + '>' +
1187                        '	<option value="0"' + (remainder == 0 ? ' selected' : '') + '>0</option>';
1188                    if (integer == 0 && (window.cartArray[i][9] == '0.25' || window.cartArray[i][9] == 'fat quarter')) {
1189                        products +=
1190                            '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>' + (window.cartArray[i][9] == 'fat quarter' ? 'fat quarter' : '1/4') + '</option>';
1191                    } else if (integer > 0) {
1192                        products +=
1193                            '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>1/4</option>';
1194                    }
1195                    products +=
1196                        '	<option value="0.5"' + (remainder == 50 ? ' selected' : '') + '>1/2</option>' +
1197                        '	<option value="0.75"' + (remainder == 75 ? ' selected' : '') + '>3/4</option>' +
1198                        '</select>';
1199                }
1200
1201            }
1202            products +=
1203                '		</td>' +
1204                '		<td align=right nowrap><b>' + formatCurrency(itemTotal) + '</b></td>' +
1205                '	</tr>';
1206        }
1207    }
1208
1209    for (var i = 0; i < window.cartArray.length; i++) {
1210        if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
1211            var couponInfo = GetCouponInfo(window.cartArray[i]);
1212            var discount = Math.round(CalculateDiscount(subtotal_to_discount, i) * 100) / 100;
1213            if (discount > 0) {
1214                subtotal -= discount;
1215                products +=
1216                    '	<tr>' +
1217                    '		<td><b>' + couponInfo.title.replace(/\+/g, ' ') + '</b></td>' +
1218                    '		<td>&nbsp;</td>' +
1219                    '		<td align=right nowrap><b>- ' + formatCurrency(discount) + '</b></td>' +
1220                    '	</tr>' +
1221                    '';
1222            }
1223        }
1224    }
1225
1226    subtotal += giftCardSubtotal;
1227
1228    // Gift Card Payments
1229    var giftCardPayments = 0;
1230    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1231        if (window.cartArray[i][0] == 'giftcard') {
1232            giftCardPayments += Math.round(window.cartArray[i][3] * 100) / 100;
1233        }
1234    }
1235
1236    var giftCardRows = '';
1237    if (giftCardPayments > 0) {
1238
1239        if (subtotal < giftCardPayments) {
1240            giftCardPayments = subtotal;
1241        }
1242
1243        giftCardRows = '' +
1244            '	<tr>' +
1245            '		<td colspan=3 align=right valign=top nowrap>' +
1246            '			<b>Payments Made With Gift Cards</b>' +
1247            '		</td>' +
1248            '		<td align=right valign=top nowrap><b>' + formatCurrency(giftCardPayments) + '</b></td>' +
1249            '	</tr>' +
1250            '	<tr>' +
1251            '		<td colspan=3 align=right valign=top nowrap>' +
1252            '			<b>Amount Remaining</b>' +
1253            '		</td>' +
1254            '		<td align=right valign=top nowrap><b>' + formatCurrency(subtotal - giftCardPayments) + '</b></td>' +
1255            '	</tr>'
1256        ;
1257
1258    }
1259
1260    subtotal = Math.round(subtotal * 100) / 100;
1261
1262    mobileCartDiv.html('<table width=100% cellpadding=5 cellspacing=0 border=0>' +
1263        '	<tr><td colspan=3><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1264        '	<tr>' +
1265        '		<td colspan=3 style="font-size: 10px;">Description</td>' +
1266        '   </tr>' +
1267        '   <tr>' +
1268        '		<td style="font-size: 10px;" align=right>Price</td>' +
1269        '		<td style="font-size: 10px;" align=left>Quantity</td>' +
1270        '		<td style="font-size: 10px;" align=right>Amount</td>' +
1271        '	</tr>' +
1272        '	<tr><td colspan=3><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1273        products +
1274        '	<tr>' +
1275        '		<td>&nbsp;</td>' +
1276        '		<td align=left colspan=2 nowrap>' +
1277        '			<a href="javascript:UpdateMobileCart()"><img width=70 height=26 border=0 src="https://siteimages.s3.amazonaws.com/btn-update-1.png" alt="Update"></a>' +
1278        '		</td>' +
1279        '	</tr>' +
1280        '	<tr><td colspan=3><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1281        '	<tr>' +
1282        '		<td colspan=3 align=right valign=top><br>' +
1283        '                   <a href="#"><img border=0 width=160 height=26 src="https://siteimages.s3.amazonaws.com/btn-enter-coupon-1.png" alt="Enter Coupon" id="mobile-enter-coupon-btn"></a>' +
1284        '		</td>' +
1285        '	</tr>' +
1286        '	<tr>' +
1287        '		<td colspan=2 align=right valign=top>' +
1288        '			<h2>Item Total</h2>' +
1289        '		</td>' +
1290        '		<td align=right valign=top nowrap><h2>' + formatCurrency(subtotal) + '</h2></td>' +
1291        '	</tr>' +
1292
1293        giftCardRows +
1294
1295        '	<tr>' +
1296        '		<td colspan=3 align=right>' +
1297        '			<span style="font-size: 10px;">(shipping will be calculated at checkout)</span>' +
1298        '		</td>' +
1299        '	</tr>' +
1300        '	<tr>' +
1301        '		<td colspan=3 align=right>' +
1302        '			<br>' +
1303        '			<a href="javascript:ProceedToCheckout(\'no\');"><img border=0 width=160 height=26 src="https://siteimages.s3.amazonaws.com/btn-proceed-to-checkout-1.png" alt="Proceed to Checkout"></a>' +
1304        '		</td>' +
1305        '	</tr>' +
1306        '</table>' +
1307        '' +
1308        MakeCartForm() +
1309        '');
1310}
1311
1312function WideCart() {
1313    var wideCartDiv = $("#wideCartDiv");
1314
1315    var products = '';
1316    var subtotal = 0;
1317    var subtotal_to_discount = 0;
1318    var giftCardSubtotal = 0;
1319    var itemTotal = 0;
1320    var integer = 0;
1321    var remainder = 0;
1322
1323    UpdateCouponsInCartArrayAndCookie();
1324
1325    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1326        var row = window.cartArray[i];
1327        if (row[0] == 'product') {
1328            var idExt = row[1];
1329
1330            if (row.length >= 18) {
1331                idExt += '-' + row[17];
1332            }
1333
1334            var amount = Math.round((parseFloat(row[3]) * row[4]) * 100) / 100;
1335            if (row.length > 16 && row[16] == 'GC') {
1336                giftCardSubtotal += amount;
1337            }
1338            else {
1339                subtotal += amount;
1340                if (row[19] === "true")  // 19 - discount_eligible
1341                {
1342                    subtotal_to_discount += amount;
1343                }
1344            }
1345
1346            itemTotal = parseFloat(row[3]) * parseFloat(row[4]);
1347            itemTotal = Math.round(itemTotal * 100) / 100;
1348            integer = Math.floor(row[4]);
1349            products +=
1350                '	<tr>' +
1351                '		<td>' + renderImage(row) + row[2].replace(/\+/g, ' ') + '</td>' +
1352                '		<td align=right nowrap>' + formatCurrency(row[3]) + '</td>' +
1353                '		<td align=left nowrap>' +
1354                '			<select onchange="checkFabricMinimum(\'' + idExt + '\', ' + row[10] + '); UpdateWideCart(true);" name=integer' + idExt + ' id=integer' + idExt + '>';
1355            for (var j = 0; j <= row[10]; j++) {
1356                products +=
1357                    '				<option value=' + j + (j == integer ? ' selected' : '') + '>' + j + '</option>';
1358            }
1359            products += '</select>';
1360            products += '<script>checkFabricMinimum(\'' + idExt + '\', ' + row[10] + ');</script>';
1361
1362            if (row[6] == 'fraction') {
1363
1364                remainder = Math.round(parseFloat(row[4]) * 100) % 100;
1365
1366                var maxVal = parseFloat(row[10]);
1367                var maxIntegerVal = Math.floor(maxVal);
1368                var maxFractionVal = Math.floor((maxVal * 100) % 100) / 100;
1369
1370                if (window.measurementUnit == 'Meter') {
1371                    products += '<select onchange="UpdateWideCart(true);" name=fraction' + idExt + ' id=fraction' + idExt + '>';
1372                    products += '	<option value="0"' + (remainder == 0 ? ' selected' : '') + '>.0</option>';
1373                    if (integer == 0 && row[9] == 'fat quarter') {
1374                        if (maxIntegerVal > 0 || maxFractionVal >= 0.25) {
1375                            products += '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>fat quarter</option>';
1376                        }
1377                        if (maxIntegerVal > 0 || maxFractionVal >= 0.3) {
1378                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1379                        }
1380                        if (maxIntegerVal > 0 || maxFractionVal >= 0.4) {
1381                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1382                        }
1383                    }
1384                    else if (integer == 0 && (row[9] == '0.25' || row[9] == 'fat quarter')) {
1385                        if (maxIntegerVal > 0 || maxFractionVal >= 0.3) {
1386                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1387                        }
1388                        if (maxIntegerVal > 0 || maxFractionVal >= 0.4) {
1389                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1390                        }
1391                    }
1392                    else if (integer > 0) {
1393                        if (integer < maxIntegerVal || maxFractionVal >= 0.1) {
1394                            products += '	<option value="0.1"' + (remainder == 10 ? ' selected' : '') + '>.1</option>';
1395                        }
1396                        if (integer < maxIntegerVal || maxFractionVal >= 0.2) {
1397                            products += '	<option value="0.2"' + (remainder == 20 ? ' selected' : '') + '>.2</option>';
1398                        }
1399                        if (integer < maxIntegerVal || maxFractionVal >= 0.3) {
1400                            products += '	<option value="0.3"' + (remainder == 30 ? ' selected' : '') + '>.3</option>';
1401                        }
1402                        if (integer < maxIntegerVal || maxFractionVal >= 0.4) {
1403                            products += '	<option value="0.4"' + (remainder == 40 ? ' selected' : '') + '>.4</option>';
1404                        }
1405                    }
1406                    if (integer < maxIntegerVal || maxFractionVal >= 0.5) {
1407                        products += '	<option value="0.5"' + (remainder == 50 ? ' selected' : '') + '>.5</option>';
1408                    }
1409                    if (integer < maxIntegerVal || maxFractionVal >= 0.6) {
1410                        products += '	<option value="0.6"' + (remainder == 60 ? ' selected' : '') + '>.6</option>';
1411                    }
1412                    if (integer < maxIntegerVal || maxFractionVal >= 0.7) {
1413                        products += '	<option value="0.7"' + (remainder == 70 ? ' selected' : '') + '>.7</option>';
1414                    }
1415                    if (integer < maxIntegerVal || maxFractionVal >= 0.8) {
1416                        products += '	<option value="0.8"' + (remainder == 80 ? ' selected' : '') + '>.8</option>';
1417                    }
1418                    if (integer < maxIntegerVal || maxFractionVal >= 0.9) {
1419                        products += '	<option value="0.9"' + (remainder == 90 ? ' selected' : '') + '>.9</option>';
1420                    }
1421                    products += '</select>';
1422                }
1423                else { // Yards
1424                    products +=
1425                        '<select onchange="UpdateWideCart(true);" name=fraction' + idExt + ' id=fraction' + idExt + '>' +
1426                        '	<option value="0"' + (remainder == 0 ? ' selected' : '') + '>0</option>';
1427                    if (integer == 0 && (row[9] == '0.25' || row[9] == 'fat quarter')) {
1428                        products +=
1429                            '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>' + (row[9] == 'fat quarter' ? 'fat quarter' : '1/4') + '</option>';
1430                    } else if (integer > 0) {
1431                        products +=
1432                            '	<option value="0.25"' + (remainder == 25 ? ' selected' : '') + '>1/4</option>';
1433                    }
1434                    products +=
1435                        '	<option value="0.5"' + (remainder == 50 ? ' selected' : '') + '>1/2</option>' +
1436                        '	<option value="0.75"' + (remainder == 75 ? ' selected' : '') + '>3/4</option>' +
1437                        '</select>';
1438                }
1439
1440            }
1441            products +=
1442                '		</td>' +
1443                '		<td align=right nowrap>' + formatCurrency(itemTotal) + '</td>' +
1444                '		<td align=right nowrap><span onclick="$(\'#integer' + idExt + '\').val(0); $(\'#fraction' + idExt + '\').val(0); UpdateWideCart(false);" onmouseover="$(this).css(\'color\',\'#c00\');" onmouseout="$(this).css(\'color\',\'#ccc\');" style="color:#ccc;cursor:pointer;"><b>&nbsp;&times;&nbsp;</b></span></td>' +
1445                '	</tr>';
1446        }
1447    }
1448
1449    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1450        if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
1451            var couponInfo = GetCouponInfo(window.cartArray[i]);
1452            var discount = Math.round(CalculateDiscount(subtotal_to_discount, i) * 100) / 100;
1453            if (discount > 0) {
1454                subtotal -= discount;
1455                products +=
1456                    '	<tr>' +
1457                    '		<td>' + couponInfo.title.replace(/\+/g, ' ') + '</td>' +
1458                    '		<td>&nbsp;</td>' +
1459                    '		<td>&nbsp;</td>' +
1460                    '		<td align=right nowrap>- ' + formatCurrency(discount) + '</td>' +
1461                    '		<td>&nbsp;</td>' +
1462                    '	</tr>' +
1463                    '';
1464            }
1465        }
1466    }
1467
1468    subtotal += giftCardSubtotal;
1469    subtotal = Math.round(subtotal * 100) / 100;
1470
1471    // Gift Card Payments
1472    var giftCardPayments = 0;
1473    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1474        if (window.cartArray[i][0] == 'giftcard') {
1475            giftCardPayments += Math.round(window.cartArray[i][3] * 100) / 100;
1476        }
1477    }
1478
1479    var giftCardRows = '';
1480    if (giftCardPayments > 0) {
1481
1482        if (subtotal < giftCardPayments) {
1483            giftCardPayments = subtotal;
1484        }
1485
1486        giftCardRows = '' +
1487            '	<tr>' +
1488            '		<td colspan=3 align=right valign=top nowrap>' +
1489            '			<b>Payments Made With Gift Cards</b>' +
1490            '		</td>' +
1491            '		<td colspan=2 align=right nowrap><b>' + formatCurrency(giftCardPayments) + '</b></td>' +
1492            '	</tr>' +
1493            '	<tr>' +
1494            '		<td colspan=3 align=right nowrap>' +
1495            '			<b>Amount Remaining</b>' +
1496            '		</td>' +
1497            '		<td colspan=2 align=right nowrap><b>' + formatCurrency(subtotal - giftCardPayments) + '</b></td>' +
1498            '	</tr>'
1499        ;
1500
1501    }
1502
1503    if (typeof updateSubtotal != "undefined") {
1504        updateSubtotal(subtotal);
1505    }
1506
1507    var wideCartHtml =
1508        '<div class="table-responsive">' +
1509        '<table width=100% cellpadding=5 cellspacing=0 border=0 class="table-condensed">' +
1510        '	<tr><td colspan=5><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1511        '	<tr>' +
1512        '		<td style="font-size: 10px;">Description</td>' +
1513        '		<td style="font-size: 10px;" align=right>Price</td>' +
1514        '		<td style="font-size: 10px;" align=left>Quantity</td>' +
1515        '		<td style="font-size: 10px;" align=right>Amount</td>' +
1516        '		<td>&nbsp;</td>' +
1517        '	</tr>' +
1518        '	<tr><td colspan=5><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1519        products +
1520        '	<tr><td colspan=5><div style="height: 1px; border-top: 1px solid #fff; border-bottom: 1px solid #bbb;"><spacer></div></td></tr>' +
1521        '	<tr>' +
1522        '		<td colspan=5 align=left valign=top nowrap>' +
1523        '			<a href="' + editcartUrl + '&enterCoupon=true" style="font-size:14px !important;">Enter Coupon</a>' + (window.paymentProcessor === undefined || window.paymentProcessor == false || window.paymentProcessor == 'paypal' ? '' : '&nbsp; | &nbsp; <a href="' + editcartUrl + '&enterGiftcard=true">Enter Gift Card</a>') +
1524        '		</td>' +
1525        '	</tr>' +
1526
1527        '	<tr>' +
1528        '		<td colspan=4 align=right valign=top nowrap><h2 style="font-size: 20px !important; margin:0px !important;">Subtotal: &nbsp; ' +
1529        '		' + formatCurrency(subtotal) + '</h2></td>' +
1530        '		<td>&nbsp;</td>' +
1531        '	</tr>' +
1532        giftCardRows
1533    ;
1534
1535    if (window.cartModeProceed !== false) {
1536        wideCartHtml +=
1537            '	<tr>' +
1538            '		<td colspan=4 align=right>' +
1539            '			<span style="font-size: 10px;">(shipping will be calculated at checkout)</span>' +
1540            '		</td>' +
1541            '		<td>&nbsp;</td>' +
1542            '	</tr>' +
1543            '	<tr>' +
1544            '		<td valign=middle nowrap><a href="javascript:history.go(-1);" style="font-size:14px !important;">< Continue Shopping</a></td>' +
1545            '		<td colspan=3 align=right>' +
1546            '			<a href="javascript:ProceedToCheckout(\'no\');" class="proceedToCheckout" style="display:inline-block; padding: 5px 25px; border: 1px solid #999; background: #000; font-size: 16px !important; text-decoration:none !important; color: #fff !important;">Proceed to Checkout &raquo;</a>' +
1547            '		</td>' +
1548            '		<td>&nbsp;</td>' +
1549            '	</tr>' +
1550            '</table><br><br>' +
1551            '</div>' +
1552            MakeCartForm() +
1553            ''
1554        ;
1555    } else {
1556        wideCartHtml +=
1557            '</table><br><br>' +
1558            '</div>' +
1559            ''
1560        ;
1561    }
1562
1563    wideCartDiv.html(wideCartHtml);
1564
1565}
1566
1567function renderImage(row) {
1568    var path = row[20];
1569    if (path !== undefined && path !== "" && row[21] !== undefined) {
1570        return '<img border=0 style="width:40px; height:40px;' + row[21] + ' margin-top: 4px; margin-bottom: 4px;" src="' + row[20] + '">&nbsp;&nbsp;';
1571    }
1572    return "";
1573}
1574
1575function handleWaitlistProductOptionChanged(in_productId, in_attributeIndex) {
1576    var key = '';
1577
1578    // Get the key
1579    for (var i = 0; i < window['numAttributes' + in_productId]; i++) {
1580        key += (key.length > 0 ? '-' : '') + $('#attribute_' + in_productId + '_' + i).val();
1581    }
1582    if (window['prices' + in_productId][key] == undefined) {
1583        // We didn't find the key, so we need to choose a key that exists
1584        var attributeVal = $("#attribute_" + in_productId + "_" + in_attributeIndex).val();
1585        for (var priceKey in window['prices' + in_productId]) {
1586            var parts = priceKey.split('-');
1587            if (parts[in_attributeIndex] == attributeVal) {
1588                for (var k = 0; k < parts.length; k++) {
1589                    $("#attribute_" + in_productId + "_" + k).val(parts[k]);
1590                }
1591                key = priceKey;
1592                break;
1593            }
1594        }
1595    }
1596}
1597
1598function UpdateCartArrayAndCookie(in_promptForDelete) {
1599    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1600        var row = window.cartArray[i];
1601        if (row[0] == 'product') {
1602            var idExt = row[1];
1603
1604            if (row.length >= 18) {
1605                idExt += '-' + row[17];
1606            }
1607
1608            if (row[6] == 'integer') {
1609                productCount = parseInt(document.getElementById('integer' + idExt).value);
1610            }
1611            else {
1612                productCount = parseInt(document.getElementById('integer' + idExt).value) + parseFloat(document.getElementById('fraction' + idExt).value);
1613            }
1614            if (row[12] == 1) {
1615                var cartUrl = '/module/product.htm?timed=1';
1616                if (isAdminUrl(location.host)) {
1617                    cartUrl = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrl;
1618                }
1619                $.ajax({
1620                    url: cartUrl,
1621                    type: 'POST',
1622                    data: 'timed=1' + '&which=1' + '&productId=' + row[1] + '&pslrId=' + row[17] + '&prevcount=' + row[4] + '&newcount=' + productCount + '&prevholdingid=' + row[13] + '&i=' + i,
1623                    async: false,
1624                    success: function(result) {
1625                        if (result.substring(0, 12) == 'insufficient') {
1626                            alert('There is no longer sufficient inventory to add the number of items you requested to your cart.');
1627                            window.cartArray.remove(parseInt(result.substring(13)));
1628                            return;
1629                        } else {
1630                            result = result.split('-');
1631                            if (parseInt(result[0]) == 0) {
1632                                window.cartArray.remove(parseInt(result[1]));
1633                            }
1634                            else {
1635                                window.cartArray[parseInt(result[1])][4] = parseInt(result[0]);
1636                                window.cartArray[parseInt(result[1])][13] = result[2];
1637                            }
1638                        }
1639                    }
1640                });
1641            } else {
1642                if (productCount == 0) {
1643                    if (in_promptForDelete) {
1644                        if (confirm('Do you want to remove this product from your shopping cart?')) {
1645                            window.cartArray.remove(i);
1646                        }
1647                    } else {
1648                        window.cartArray.remove(i);
1649                    }
1650                } else {
1651                    row[4] = productCount;
1652                }
1653            }
1654        }
1655    }
1656
1657    var productCount = 0;
1658    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1659        if (window.cartArray[i][0] == 'product') {
1660            productCount++;
1661        }
1662    }
1663
1664    if (productCount == 0) {
1665        Delete_Cart_Cookie('cart', '/', '');
1666    } else {
1667        Set_Cart_Cookie('cart', BuildCookieFromArray(), '', '/', '', '');
1668    }
1669}
1670
1671function UpdateCouponsInCartArrayAndCookie() {
1672    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1673        if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
1674            var couponInfo = GetCouponInfo(window.cartArray[i]);
1675            checkCouponExpiration(i, couponInfo.number);
1676        }
1677    }
1678}
1679
1680function checkCouponExpiration(i, coupon_id) {
1681    if(typeof coupon_id == 'undefined' || coupon_id == 0 || coupon_id == '0') {
1682        return;
1683    }
1684    var cartUrl = '/module/product.htm?editCart=1';
1685    if (isAdminUrl(location.host)) {
1686        cartUrl = location.pathname.substring(0, location.pathname.indexOf('/', 2)) + cartUrl;
1687    }
1688
1689    $.ajax({
1690        url: cartUrl, type: 'GET', data: 'couponid=' + coupon_id,
1691        async: false,
1692        success: function(result) {
1693            var data = JSON.parse(result);
1694            if (data.status !== "ok") {
1695                alertAndRemoveCoupon(i, getCouponExpiredString(data));
1696                return;
1697            }
1698        }
1699    });
1700}
1701
1702function UpdateMobileCart() {
1703    UpdateCartArrayAndCookie(false);
1704    MobileCart(true);
1705}
1706
1707function UpdateWideCart(in_promptForDelete) {
1708    UpdateCartArrayAndCookie(in_promptForDelete);
1709    WideCart();
1710}
1711
1712function CalculateDiscountData() {
1713    var subtotal = 0;
1714    var subtotal_to_discount = 0;
1715    var newGiftCardSubtotal = 0;
1716    var appliedGiftCardSubtotal = 0;
1717    var discount = 0;
1718    var retPercent = 0;
1719
1720    var hasDollarOff = false;
1721    var hasPercentOff = false;
1722    var percentOrAmount = 'percent';
1723
1724    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1725        var row = window.cartArray[i];
1726        if (row[0] == 'product') {
1727            if (parseInt(row[4]) == row[4]) {
1728                var amount = Math.round((parseFloat(row[3]) * row[4]) * 100) / 100;
1729                if (row.length > 16 && row[16] == 'GC') {
1730                    newGiftCardSubtotal += amount;
1731                } else {
1732                    subtotal += amount;
1733                    if (row[19] === "true") // 19 - discount_eligible
1734                    {
1735                        subtotal_to_discount += amount;
1736                    }
1737                }
1738            } else {
1739                var amount = (parseFloat(row[3]) * parseFloat(row[4]));
1740                amount = Math.round(parseFloat(amount) * 100) / 100;
1741                if (row.length > 16 && row[16] == 'GC') {
1742                    newGiftCardSubtotal += amount;
1743                } else {
1744                    subtotal += amount;
1745                    if (row[19] === "true") // 19 - discount_eligible
1746                    {
1747                        subtotal_to_discount += amount;
1748                    }
1749                }
1750            }
1751        }
1752    }
1753
1754    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1755        if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
1756            var couponInfo = GetCouponInfo(window.cartArray[i]);
1757
1758            if (couponInfo.couponType == 'dollar_off') {
1759                hasDollarOff = true;
1760            }
1761            if (couponInfo.couponType == 'percent_off') {
1762                hasPercentOff = true;
1763            }
1764
1765            discount = CalculateDiscount(subtotal_to_discount, i);
1766            if (discount > 0) {
1767                // Only one coupon should be applied.  The last one is the one that will be applied.
1768                discount = Math.round(discount * 100) / 100;
1769            }
1770        }
1771    }
1772
1773    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1774        if (window.cartArray[i][0] == 'giftcard') {
1775            var giftCardAmount = Math.round(parseFloat(window.cartArray[i][3]) * 100) / 100;
1776            if (giftCardAmount > (subtotal - appliedGiftCardSubtotal)) {
1777                giftCardAmount = subtotal - appliedGiftCardSubtotal - 0.01;
1778            } // Paypal doesn't allow $0 carts
1779            appliedGiftCardSubtotal += giftCardAmount
1780        }
1781    }
1782
1783    if (discount > 0 || appliedGiftCardSubtotal > 0) {
1784        retPercent = Math.round(((discount + appliedGiftCardSubtotal) / subtotal) * 10000) / 100;
1785    }
1786
1787    if (hasDollarOff == true && hasPercentOff == false) {
1788        percentOrAmount = 'amount';
1789    }
1790
1791    return {
1792        hasDiscount: (retPercent > 0),
1793        percent: retPercent,
1794        discount: discount,
1795        percentOrAmount: percentOrAmount
1796    };
1797
1798}
1799
1800function MakeCartForm() {
1801    var productsStr = '';
1802    var totalWeight = 0;
1803    var count = 0;
1804    var subtotal = 0;
1805    var giftCardSubtotal = 0;
1806
1807    var discountData = CalculateDiscountData();
1808    var accumulatedDiscount = 0;
1809    var discountAmount = 0;
1810
1811    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1812        if (window.cartArray[i][0] == 'product') {
1813            count++;
1814            totalWeight += (window.cartArray[i][4] * window.cartArray[i][5]);
1815            var amount = window.cartArray[i][3];
1816            var weight = window.cartArray[i][5];
1817            var quantity = window.cartArray[i][4];
1818            var units = '';
1819            var isClass = window.cartArray[i][1].indexOf('CLASS') > -1;
1820
1821            if (parseInt(window.cartArray[i][4]) == window.cartArray[i][4]) {
1822                if (window.cartArray[i].length > 16 && window.cartArray[i][16] == 'GC') {
1823                    giftCardSubtotal += Math.round((parseFloat(window.cartArray[i][3]) * window.cartArray[i][4]) * 100) / 100;
1824                } else {
1825                    subtotal += Math.round((parseFloat(window.cartArray[i][3]) * window.cartArray[i][4]) * 100) / 100;
1826                }
1827            } else {
1828                amount = (parseFloat(window.cartArray[i][3]) * parseFloat(window.cartArray[i][4]));
1829                if (window.cartArray[i].length > 16 && window.cartArray[i][16] == 'GC') {
1830                    giftCardSubtotal += Math.round(parseFloat(amount) * 100) / 100;
1831                } else {
1832                    subtotal += Math.round(parseFloat(amount) * 100) / 100;
1833                }
1834                amount = Math.round(amount * 100) / 100;
1835                weight = (parseFloat(window.cartArray[i][5]) * parseFloat(window.cartArray[i][4]));
1836                weight = Math.round(weight * 100) / 100;
1837                quantity = 1;
1838                units = ' (' + window.cartArray[i][4] + ' ' + window.measurementText.toLowerCase() + 's)';
1839            }
1840
1841            productsStr += '<input type=hidden name=amount_' + count + ' id=amount_' + count + ' value="' + amount + '">';
1842            productsStr += '<input type=hidden name=item_name_' + count + ' id=item_name_' + count + ' value="' + window.cartArray[i][2].replace(/["']/g, "") + units + (window.cartArray[i].length >= 8 && window.cartArray[i][7] != '' ? " [" + window.cartArray[i][7] + "]" : '') + '">';
1843            productsStr += '<input type=hidden name=item_number_' + count + ' id=item_number_' + count + ' value="' + window.cartArray[i][1] + '">';
1844            productsStr += '<input type=hidden name=weight_' + count + ' id=weight_' + count + ' value="' + weight + '">';
1845            productsStr += '<input type=hidden name=quantity_' + count + ' id=quantity_' + count + ' value="' + quantity + '">';
1846            if (window.cartArray[i].length > 14 && window.cartArray[i][14].length > 0) {
1847                productsStr += '<input type=hidden name=shipping_' + count + ' value="' + window.cartArray[i][14] + '">';
1848            }
1849            if (window.cartArray[i].length > 16 && window.cartArray[i][16] == 'GC') {
1850                productsStr += '<input type=hidden name=tax_' + count + ' value="
18500">';
1851            } else if (window.cartArray[i].length > 15 && window.cartArray[i][15].length > 0) {
1852                if (isClass) {
1853                    // We always want classes to not be taxed on old cart
1854                    productsStr += '<input type=hidden name=tax_' + count + ' value="0">';
1855                } else {
1856                    // Let PayPal decide whether to add taxes for products
1857                    productsStr += '<input type=hidden name=tax_' + count + ' value="">';
1858                }
1859            }
1860
1861            if (discountData.hasDiscount) {
1862                if (discountData.percentOrAmount == 'percent') {
1863                    productsStr += '<input type=hidden name=discount_rate_' + count + ' id=discount_rate_' + count + ' value="' + discountData.percent + '">';
1864                } else {
1865                    if (IsLastProduct(i)) {
1866                        discountAmount = Math.round((discountData.discount - accumulatedDiscount) * 100) / 100;
1867                        accumulatedDiscount = discountData.discount;
1868                    } else {
1869                        discountAmount = Math.round(parseFloat(amount) * (Math.round(parseFloat(quantity) * 1000) / 1000) * (parseFloat(discountData.percent) / 100) * 100) / 100;
1870                        accumulatedDiscount += discountAmount;
1871                    }
1872                    productsStr += '<input type=hidden name=discount_amount_' + count + ' id=discount_amount_' + count + ' value="' + discountAmount + '">';
1873                }
1874            }
1875
1876        }
1877    }
1878
1879    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1880        if (window.cartArray[i][0] == 'coupon' || window.cartArray[i][0] == 'couponV2') {
1881            var couponInfo = GetCouponInfo(window.cartArray[i]);
1882            if (discountData.hasDiscount) {
1883                count++;
1884
1885                productsStr += '<input type=hidden name=amount_' + count + ' id=amount_' + count + ' value="0">';
1886                productsStr += '<input type=hidden name=item_name_' + count + ' id=item_name_' + count + ' value="' + couponInfo.title.replace(/["']/g, "") + '">';
1887                productsStr += '<input type=hidden name=item_number_' + count + ' id=item_number_' + count + ' value="0">';
1888                productsStr += '<input type=hidden name=weight_' + count + ' id=weight_' + count + ' value="0">';
1889                productsStr += '<input type=hidden name=quantity_' + count + ' id=quantity_' + count + ' value="1">';
1890            }
1891        }
1892    }
1893
1894    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1895        if (window.cartArray[i][0] == 'giftcard') {
1896            //var giftCardAmount = window.cartArray[i][3];
1897            count++;
1898
1899            productsStr += '<input type=hidden name=amount_' + count + ' id=amount_' + count + ' value="0">';
1900            productsStr += '<input type=hidden name=item_name_' + count + ' id=item_name_' + count + ' value="' + window.cartArray[i][2].replace(/["']/g, "") + '">';
1901            productsStr += '<input type=hidden name=item_number_' + count + ' id=item_number_' + count + ' value="' + window.cartArray[i][1] + '">';
1902            productsStr += '<input type=hidden name=weight_' + count + ' id=weight_' + count + ' value="0">';
1903            productsStr += '<input type=hidden name=quantity_' + count + ' id=quantity_' + count + ' value="1">';
1904
1905        }
1906    }
1907
1908    if (productsStr == '') {
1909        return '';
1910    } // Return nothing if we have no products
1911
1912    totalWeight = Math.ceil(totalWeight);
1913
1914    var paymentAction = 'sale';
1915    if (GetCartArrayValueByKey('businessEmail', 'paymentAction') == 'authorization') {
1916        paymentAction = 'authorization';
1917    }
1918
1919    window.shopping_cart_contents_id = escape(document.domain).replace(/@/g, '').replace(/\./g, '') + Math.floor(Math.random() * 100000000) + Math.floor(Math.random() * 100000000);
1920    if (!window.PayPalUrl) {
1921        window.PayPalUrl = 'https://www.paypal.com/cgi-bin/webscr';
1922    }
1923
1924    var str =
1925        '<form id=cartform name=cartform method=post action="' + window.PayPalUrl + '">' +
1926        '<input type="hidden" name="cmd" value="_cart">' +
1927        '<input type="hidden" id="notify_url" name="notify_url" value="http://' + document.domain + '/module/product.htm?ipn=1&shopping_cart_contents_id=' + window.shopping_cart_contents_id + '">' +
1928        '<input type=hidden name=upload id=upload value="1">' +
1929        '<input type=hidden name=weight_unit id=weight_unit value="' + window.weightUnit + '">' +
1930        '<input type=hidden name=currency_code id=currency_code value="' + window.currency + '">' +
1931        '<input type="hidden" name="return" value="' + location.href + (location.href.indexOf('?') > 0 ? '&' : '?') + 'emptycart=1">' +
1932        '<input type="hidden" name="shopping_url" value="' + location.href + '">' +
1933        '<input type=hidden name=business id=business value="' + GetCartArrayValueByKey('businessEmail') + '">' +
1934        '<input type=hidden name=paymentaction id=paymentaction value="' + paymentAction + '">' +
1935        '<input type="hidden" name="bn" value="Rain_SP">' +
1936        productsStr +
1937        '</form>' +
1938        '';
1939
1940    return str;
1941}
1942
1943function IsLastProduct(in_i) {
1944    var lastI = false;
1945    for (var i = window.cartArray.length - 1; i >= 0; i--) {
1946        if (window.cartArray[i][0] == 'product') {
1947            lastI = i;
1948        }
1949    }
1950    return (lastI === in_i ? true : false);
1951}
1952
1953function GetCartArrayValueByKey(in_key, in_subKey) {
1954    if (window.cartArray === undefined || window.cartArray.length == 0) {
1955        return '';
1956    }
1957
1958    var retVal = '';
1959    for (var i = 0; i < window.cartArray.length; i++) {
1960        if (window.cartArray[i][0] == in_key) {
1961            if (in_subKey != undefined) {
1962                for (var j = 0; j < window.cartArray[i].length; j++) {
1963                    if (window.cartArray[i][j] == in_subKey) {
1964                        if (window.cartArray[i].length >= j + 1) {
1965                            retVal = window.cartArray[i][j + 1];
1966                        }
1967                        break;
1968                    }
1969                }
1970                break;
1971            } else {
1972                if (window.cartArray[i].length >= 2) {
1973                    retVal = window.cartArray[i][1];
1974                }
1975            }
1976            break;
1977        }
1978    }
1979
1980    return retVal;
1981}

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.