PageSourceSearch

https://www.scientology.de/theme/store/js/jquery.scnstore.js?_=142cd6f51

js scientology.de collected 2026-10-02 12:55:28 UTC 66,462 bytes, 2,334 lines download raw bytes

1$('[name="ShippingCountryCode"], [name="BillingCountryCode"]').change(function(){
2    var countrycode = $(this).val();
3
4    if(countrycode == "RU" || countrycode == "KZ" || countrycode == "KG" || countrycode == "BY" || countrycode == "MD") {
5        $('[name="ShippingCountryCode"]').val('');
6        $('[name="BillingCountryCode"]').val('');
7        showRUMessage(countrycode);
8    }
9});
10
11function showRUMessage(countryCode) {
12    var country = countryCode || globalGeolocationData.estimated_location.country_code;
13    $('[data-countrycode]').addClass('hidden');
14    $('#russia_store_message [data-countrycode="'+country+'"]').removeClass('hidden');
15    $('#russia_store_message').modal();
16    window.ga && ga('send', 'event', "CIS Message", "Shown", countryCode);
17}
18
19
20
21
22;(function(factory){
23  
24    if (typeof define === 'function' && define.amd) {
25        define(['jquery'], factory);
26    } else if (typeof exports !== 'undefined') {
27        module.exports = factory(require('jquery'));
28    } else {
29        factory(jQuery);
30    }
31
32})(function($){
33
34    
35    if ( ! window.console ) console = { log: function(){} };
36
37    
38
39    function ScnStore(element, settings) {
40        this.defaults = {
41            logLevel:    'error',
42            locale:      "de_DE",
43            prodLang:    'en',
44            currency:    'EUR',
45            miniCart: {
46                Container: '',
47                AjaxUrl:   '',
48                Enabled:   false
49            },
50            checkoutUrl: 'checkout.action',
51            successUrl: 'thank-you.action',
52            orderForm: {}, 
53            cardTypes: {
54                visa:       '^4',
55                amex:       '^3[47]',
56                mastercard: '^5[1-5]\d{2}|^2(?:2(?:2[1-9]|[3-9]\d)|[3-6]\d\d|7(?:[01]\d|20))',
57                discover:   '^6(?:011|5)',
58                jcb:        '^(?:2131|1800)',
59                dinersclub: '^3(?:0[0-5]|[68])'
60            }
61        };
62
63        
64        
65        this.settings = $.extend({},this,this.defaults,settings);
66
67        
68        this.initials = {
69            lastCart:    {},
70            orderForm:   {},
71            isPageLoad:  true,
72            countryList: {},
73            currency:    this.settings.currency     
74        };
75
76        
77        $.extend(this,this.initials);
78
79        
80        this.$el = $('html');
81
82        
83        this.init();
84    }
85
86    
87
88    ScnStore.prototype.init = function(){
89        
90        this.$el.addClass('scnstore');
91
92        
93        
94        this.log = window.log.noConflict();
95        this.log.setLevel(this.settings.logLevel);
96
97        
98        this.activate();
99
100        
101        this.events();
102
103        
104        if (this.settings.miniCart.Enabled) {
105            this.MiniCart.init();
106        };
107
108        
109        this._pageLoaded();
110    };
111    
112    
113    
114 
115    ScnStore.prototype.activate = function(){
116        
117        
118        this.CartContents();
119
120        
121        this._loadOrderForm();
122
123        
124        this._initPaymentForm();
125
126    };
127    
128    
129
130    ScnStore.prototype.events = function(){
131
132        
133        var that = this;
134
135        
136        $('.scnstore-atc').on('click', function(){
137
138            var $el = $(this);
139            var prodId = $el.data('store-product-id');
140            var qty = ($el.data('store-qty'))? $(this).data('store-qty'): 1;
141
142            that._failIfUndefined(prodId,
143                'data-store-product-id not set on the element!');
144
145            that._logger('Add To Cart click detected', 'info');
146            that._logger('Data on click: '+prodId+' with qty:'+qty);
147
148            
149            
150            $el.addClass('loading');
151
152            that.AddToCart(prodId, qty, $el);
153        });
154
155
156        
157        $('.scnstore-remove').on('click', function(e){
158            e.preventDefault();
159            var uniqueId = $(this).data('store-unique-id');
160            
161            that._failIfUndefined(uniqueId,
162                'data-store-unique-id not set on the element!');
163
164            that._logger('Remove line item click detected', 'info');
165            that._logger('Data on click: ' + uniqueId);
166            that.RemoveLineItem(uniqueId);        
167        });
168
169
170        
171
172        
173
174        if (! $.isEmptyObject(this.orderForm)) {
175
176            var that = this;
177            var form = this.orderForm;
178
179            
180            $('#'+form.BillingAddressData.CountryCode.Id).change(function() {
181                that.UpdateStateList(
182                    form.BillingAddressData.StateProvince.Id,
183                    form.BillingAddressData.CountryCode.Id
184                );
185            });
186
187            
188            
189            $('#'+form.ShippingAddressData.CountryCode.Id).change(function() {
190                that.UpdateStateList(
191                    form.ShippingAddressData.StateProvince.Id,
192                    form.ShippingAddressData.CountryCode.Id
193                );
194            });
195
196
197            
198            
199            $('#'+form.BillingAddressData.StateProvince.Id).change(function() {
200                that._checkForOtherStateValAndHandle(
201                    that.orderForm.BillingAddressData.StateProvince.Id
202                );
203            });
204
205            
206            $('#'+form.ShippingAddressData.StateProvince.Id).change(function() {
207                that._checkForOtherStateValAndHandle(
208                    that.orderForm.ShippingAddressData.StateProvince.Id
209                );
210            });
211
212
213
214            
215
216
217            
218            var onblur = {
219                ShippingAddressData: [
220                    'Email', 'FirstName', 'LastName', 'Address1', 'Address2', 'City',
221                    'PostalCode', 'Phone'
222                ],
223                BillingAddressData: [
224                    'FirstName', 'LastName', 'Address1', 'Address2', 'City',
225                    'PostalCode', 'Phone'
226                ],
227            };
228            var onchange = {
229                ShippingAddressData: ['StateProvince', 'CountryCode'],
230                BillingAddressData:  ['StateProvince', 'CountryCode']
231            };
232
233            
234            var oninput = {
235                ShippingAddressData: ['PostalCode'],
236                BillingAddressData:  ['PostalCode']
237            };
238
239            
240            $.each(onblur, function(section, fields) {
241                for (var i = fields.length - 1; i >= 0; i--) {
242                    var shipElemId = form[section][fields[i]].Id;
243                    $(document).on('blur', '#'+shipElemId, function() {
244                        that.UpdateOrderForm();
245                    });
246                };
247            });
248
249            
250            $.each(onchange, function(section, fields) {
251                for (var i = fields.length - 1; i >= 0; i--) {
252                    var shipElemId = form[section][fields[i]].Id;
253                    $('#'+shipElemId).change(function() {
254                        that.UpdateOrderForm();
255                    });
256                };
257            });
258
259
260            
261            $.each(oninput, function(section, fields) {
262                for (var i = fields.length - 1; i >= 0; i--) {
263                    var field = fields[i];
264                    var shipElemId = form[section][field].Id;
265                    $('#'+shipElemId).on('input', function() {
266
267                        
268                        
269                        if (field == 'PostalCode') {
270                            var countryCode = $('#'+form[section]['CountryCode'].Id).val();
271                            if ($.inArray(countryCode, that._shipQuoteValidationList.PostCodeRequired) !== -1) {
272                                that.UpdateOrderForm();
273                            }
274                        };
275                    });
276                };
277            });
278
279
280
281            
282            
283            
284            if (form.hasOwnProperty('PaymentMethods')) {
285                if (form.PaymentMethods.hasOwnProperty('creditcard')) {
286                    var cardId = form.PaymentMethods.creditcard.AccountNumber.Id;
287                    
288                    
289                    $(document).on('input', '#'+cardId, function() {
290
291                        
292                        
293                        var initVal = $(this).val();
294                        $(this).val(that._cardFormat(initVal));
295
296                        
297                        
298                        var cardType = that._getCardType($(this).val());
299                        if (cardType) {
300                            that._setCardType(cardType);
301                        } else {
302                            that._unsetAllCardTypes();
303                        }
304                    });
305                };
306            };
307
308            $(document).on('click', '.payment-card', function() {
309                var types = that.settings.cardTypes;
310                var $el = $(this);
311
312                $.each(types, function(card, regex) {
313                    if ($el.hasClass(card)) {
314                        that._unsetAllCardTypes();
315                        $el.addClass('active');
316                    };
317                });
318            });
319
320
321            
322            $('.cart-item .language').change(function() {
323                var itemCode = $(this).val();
324                var uniqueId = $(this).closest('.cart-item')
325                    .data('scnstore-uniqueid');
326
327                that._logger('Updating language', 'info')
328                that._logger('Unique ID: ' + uniqueId);
329                that._logger('New item code: ' + itemCode);
330
331                $(this).attr('disabled', true);
332                that.ChangeLanguage(uniqueId, itemCode);
333            });
334
335
336            
337            $('.cart-item .item-qty').change(function() {
338                var qty = $(this).val();
339                var uniqueId = $(this).closest('.cart-item')
340                    .data('scnstore-uniqueid');
341
342                that._logger('Updating quantity', 'info')
343                that._logger('Unique ID: ' + uniqueId);
344                that._logger('New qunatity: ' + qty);
345
346                $(this).attr('disabled', true);
347                that.ChangeQuantity(uniqueId, qty);
348            });
349
350        };
351    };
352
353    
354    
355
356    ScnStore.prototype.AddToCart = function(productId, qty, $el, callback){
357        
358        
359        if ( ! this._isset(qty) || qty == 0) {
360            qty = 1;
361        };    
362
363        this._logger('Called AddToCart with: ', 'info');
364        this._logger({ProductID:productId,Quantity:qty});
365
366        var req = this._jsonRpcRequest("CartApi.AddToCart", [{
367            LineItem: {
368                ProductId: productId,
369                Quantity: qty,
370            },
371        }]);
372
373        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
374            context: this,
375            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
376            success: function(data){
377
378                
379                this._displayError(data);
380                if (data.hasOwnProperty('result')) {
381                    this._updateCart(data.result);
382                };
383
384                
385                if($(window).width() < 768 && window.location.pathname != '/store/checkout.action') {
386                    window.location.pathname = '/store/checkout.action';
387                }
388
389                
390                
391                if (this._isset($el)) {
392                    $el.removeClass('loading');
393
394                    if (this._isset('callback') && callback == 'inline') {
395                        this._atcInline($el);
396                        return;
397                    } else if(callback) {
398                        callback();
399                    }
400
401                    
402                    this._atcPopover($el);
403                };
404            },
405            failure: function(errMsg) {
406                this._logger('AddToCart wasn\'t successful', 'warn');
407                this._throwError(errMsg);
408                $el.removeClass('loading');
409            },
410        }));
411    };
412
413
414    
415
416    ScnStore.prototype.CartContents = function(){
417        var that = this;
418
419        this._logger('Called CartContents', 'info');
420
421        var req = this._jsonRpcRequest("CartApi.CartContents");
422
423        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
424            context: this,
425            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
426            success: function(data){
427
428                
429                if (data.hasOwnProperty('result')) {
430                    this._updateCart(data.result);
431
432                    if(data.result.LineItem) {
433                        $.each(data.result.LineItems, function(i, item) {
434                            that._updateProductAttrs(item);
435                        });
436                    }
437
438                    if(window.location.search.indexOf("?item0") == 0) {
439                        this.setLineItems(window.location.search);
440                    }
441                };
442
443                this._displayError(data);
444            },
445            failure: function(errMsg) {
446                this._logger('CartContents wasn\'t successful', 'warn');
447                this._throwError(errMsg);
448            },
449        }));
450    };
451
452
453    ScnStore.prototype.setLineItems = function(query){
454        var parts = query.substr(1, query.length).split('&');
455        if(this.lastCart && this.lastCart.LineItems) {
456            for (var index = 0; index < this.lastCart.LineItems.length; index++) {
457                var item = this.lastCart.LineItems[index];
458                this.RemoveLineItem(item.UniqueId);
459            }
460        }
461
462        var counter = parts.length / 2;
463
464        for (index = 0; index < parts.length; index += 2 ) {
465            var part = parts[index];
466            var activePart = part.split("=");
467            var productId = activePart[1];
468            
469            activePart = parts[index+1].split("=");
470            var quantity = activePart[1];
471            
472            this.AddToCart(productId, quantity, $(document.createElement("div")), function(){
473                counter --;
474                console.log('counter',counter);
475                if(counter == 0) {
476                    window.location = window.location.pathname;
477                }
478            });
479        }
480    }
481
482
483    
484
485    ScnStore.prototype.LineItemCount = function(){
486
487        if (this.hasOwnProperty('lastCart')) {
488            if ($.isEmptyObject(this.lastCart)
489                || this.lastCart == false
490                || this.lastCart.LineItems == null) {
491                return 0;
492            };
493        } else {
494            return 0;
495        };
496
497        return this.lastCart.LineItems.length;
498    };
499
500
501    
502
503    ScnStore.prototype.ChangeLanguage = function(uniqueId, newItemCode) {
504
505        var that = this;
506
507        
508        if ( ! this._isset(uniqueId)) {
509            this._logger('The item\'s unique ID is required.', 'error');
510            return;
511        };
512        if ( ! this._isset(newItemCode)) {
513            this._logger('The new item code with proper language is required.', 'error');
514            return;
515        };
516
517        var newItem = {
518            UniqueId: uniqueId,
519            ProductId: newItemCode
520        }
521
522        
523        this.UpdateLineItem(newItem);
524    };
525
526
527
528    
529
530    ScnStore.prototype.ChangeQuantity = function(uniqueId, qty) {
531
532        if ( ! this._isset(uniqueId)) {
533            this._logger('The item\'s unique ID is required.', 'error');
534            return;
535        };
536        if ( ! this._isset(qty) && /^\d+$/.test(qty)) {
537            this._logger('The new item quantity is required and must be a number.', 'error');
538            return;
539        };
540
541        
542        if (qty == 0) {
543            if ($('li[data-scnstore-uniqueid='+uniqueId+']').find('.delete').length) {
544
545                
546                $('li[data-scnstore-uniqueid='+uniqueId+']').find('.delete').click();
547                return;
548            }
549
550            this.RemoveLineItem(uniqueId);
551        };
552
553        var newItem = {
554            UniqueId: uniqueId,
555            Quantity: qty
556        }
557
558        
559        this.UpdateLineItem(newItem);
560    };
561
562
563    
564
565    ScnStore.prototype.UpdateLineItem = function(newItem){
566        this._logger('Called UpdateLineItem...', 'info');
567        var that = this;
568
569        var li = {};
570        $.each(this.lastCart.LineItems, function(item, attrs) {
571            if (attrs.UniqueId == newItem.UniqueId) {
572                li = that.lastCart.LineItems[item];
573            };
574        });
575
576        if (li.length == 0) {
577            this._logger('Item not found by unique id', 'error');
578            return;
579        };
580
581
582        
583        li = $.extend({}, li, newItem);
584        var req = this._jsonRpcRequest("CartApi.UpdateLineItem", [{
585            LineItem: li,
586        }]);
587
588        this._logger('New item updating to:');
589        this._logger(li);
590
591        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
592            context: this,
593            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
594            success: function(data){
595                this._logger('UpdateLineItem successful:', 'info');
596
597                if (data.hasOwnProperty('result')) {
598                    this._updateCart(data.result);
599                    
600                    $.each(data.result.LineItems, function(i, item) {
601                        if (item.UniqueId == newItem.UniqueId) {
602                            that._updateProductAttrs(item);
603                        };
604                    });
605                };
606
607                this._displayError(data);
608            },
609            failure: function(errMsg) {
610                this._logger('CartContents wasn\'t successful', 'warn');
611                this._throwError(errMsg);
612            },
613        }));
614
615        this.UpdateOrderForm();
616
617        return true;
618    };
619
620
621    
622
623    ScnStore.prototype.RemoveLineItem = function(uniqueId){
624
625        this._logger('Called RemoveLineItem with: ', 'info');
626        this._logger({uniqueId:uniqueId});
627
628        var req = this._jsonRpcRequest("CartApi.RemoveLineItem", [{
629            LineItem: {
630                UniqueId: uniqueId
631            },
632        }]);
633
634        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
635            context: this,
636            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
637            success: function(data){
638
639                
640                this._displayError(data);
641                if (data.hasOwnProperty('result')) {
642                    this._updateCart(data.result);
643                };
644            },
645            failure: function(errMsg) {
646                this._logger('RemoveLineItem call failed', 'warn');
647                this._throwError(errMsg);
648            },
649        }));
650
651        if ($.isEmptyObject(this.orderForm)) {
652            this.UpdateOrderForm();
653        };
654    };
655
656
657    
658
659    ScnStore.prototype.UpdateUI = function() {
660
661        this._logger('Updating the UI...', 'info');
662        this._logger('The last cart is');
663        this._logger(this.lastCart);
664
665        var $counter = $('.store-cart-items-count');
666
667        
668        if ($counter.length) {
669            if (this.LineItemCount() != 0) {
670                $counter.text(this.LineItemCount()).removeClass('invisible');
671            } else {
672                $counter.text('').addClass('invisible');
673            };
674
675            if ($('#banner_shopping_cart_outer').hasClass('glowable')) {
676                this._logger('items count is glowable.');
677
678                var element = document.getElementById('banner_shopping_cart_outer');
679                
680                element.classList.remove("run-blue-pulse");
681                
682                element.offsetWidth = element.offsetWidth;
683                
684                element.classList.add("run-blue-pulse");
685            };
686
687        };
688        
689        if (this.settings.miniCart.Enabled) {
690            
691            this.UpdateMiniCart();
692        };
693
694        
695        
696        this._setShippingOptions();
697
698        this.UpdateCartTotals();
699    };
700
701
702    
703
704    ScnStore.prototype.UpdateCartTotals = function() {
705        this._logger('Updating Cart Totals...', 'info');
706
707        
708        var cart     = this.lastCart,
709            shipping = cart.Shipping,
710            subtotal = cart.Subtotal,
711            tax      = cart.Tax,
712            discount = cart.Discount,
713            customs  = cart.Customs,
714            total    = cart.Total,
715            locale   = this.settings.locale.split('_'),
716            currency = this.settings.currency,
717            lang     = locale[0],
718            fmtc     = window.FormatCurrency, 
719            that     = this
720
721        
722        $totals = $('#totals_box');
723        $totals.find('.subtotal .totals-data').html(fmtc(lang, currency, subtotal, false));
724        $totals.find('.shipping .totals-data').html(fmtc(lang, currency, shipping, false));
725        $totals.find('.discount .totals-data').html("-"+fmtc(lang, currency, discount, false));
726        $totals.find('.customs .totals-data').html(fmtc(lang, currency, customs, false));
727        $totals.find('.tax .totals-data').html(fmtc(lang, currency, tax, false));
728        $totals.find('.grand-total .totals-data').html(fmtc(lang, currency, total, false));
729        
730        
731        var cond = ['tax', 'discount', 'customs'];
732        $('#totals_box .discount').attr('data-amount', discount);
733        $('#totals_box .customs').attr('data-amount', customs);
734        $('#totals_box .tax').attr('data-amount', tax);
735
736        for (var i = cond.length - 1; i >= 0; i--) {
737            if ($totals.find('.'+cond[i]).attr('data-amount') > 0 || cart[cond[i]] > 0) {
738                $totals.find('.'+cond[i]).removeClass('hidden');
739            } else {
740                $totals.find('.'+cond[i]).addClass('hidden');
741            };
742        };
743    };
744
745    
746
747    ScnStore.prototype.UpdateMiniCart = function() {
748
749        this._logger('Updating Mini Cart...', 'info');
750
751        
752        var that = this;
753        
754        var rand = Math.floor(Math.random() * 1000000);
755        var url = this.settings.miniCart.AjaxUrl + (this.settings.miniCart.AjaxUrl.indexOf('?') > -1 ? '&' : '?') + '_=' + rand;
756        
757        $.get(url, function(data) {
758            $(that.settings.miniCart.Container).html(data);
759
760            
761            
762            if (that.MiniCart.skipMiniCart == false) {
763                that.MiniCart.showMiniCart(3000);
764            };
765
766            
767            that.MiniCart.skipMiniCart = false;
768
769            
770            that._logger('Updated the Mini Cart', 'info');
771
772            return true;
773        });
774    }; 
775
776    ScnStore.prototype.MiniCart = {
777
778        timeoutId: 0,
779        skipMiniCart: true,
780
781        init: function() {
782            
783            this.events();
784        },
785
786        
787        hideMiniCart: function() {
788            $('#mini_cart').removeClass('active');
789            setTimeout(function(){$('#mini_cart').addClass('hidden')}, 250);
790        },
791
792        showMiniCart: function(duration) {
793            var that = this;
794
795            
796            $('#mini_cart').delay(200).removeClass('hidden').addClass('active');
797
798            if (typeof that.timeoutId !== "undefined") {
799                clearTimeout(that.timeoutId);
800            }
801
802            
803            
804            if (typeof duration !== "undefined") {
805                that.timeoutId = setTimeout(function(){
806                    that.hideMiniCart()
807                }, duration);
808            };
809        },
810
811        
812        removeItem: function($el) {
813            var obj = window.ScnStore;
814
815            
816            $el.addClass('deleted');
817
818            
819            setTimeout(function(){
820                $el.remove();
821                obj.RemoveLineItem($el.data('scnstore-uniqueid'));
822            }, 300);
823        },
824
825        events: function() {
826
827            
828            var that = this;
829
830            
831            
832            $('#banner_shopping_cart_outer').on('mouseenter', function() {
833                if (window.ScnStore.LineItemCount() > 0) {
834                    that.showMiniCart();
835                }
836            });
837
838            
839            
840            $('#banner_shopping_cart_outer').on('mouseleave', function() {
841                that.timeoutId = setTimeout(function(){that.hideMiniCart()}, 250);
842            });
843
844            
845            
846            $( "#mini_cart_outer" ).on('mouseenter', '#mini_cart', function() {
847                if (typeof that.timeoutId !== "undefined") {
848                    clearTimeout(that.timeoutId);
849                };
850            });
851
852            
853            $("#mini_cart_outer").on('mouseleave', '#mini_cart', function() {
854                that.timeoutId = setTimeout(function(){that.hideMiniCart()}, 200);
855            });
856
857
858            
859            $('#mini_cart_outer').on('click','.minicart-item .delete',function() {
860                that.removeItem($(this).closest('.minicart-item'));
861            });
862
863        }
864    };
865
866
867    
868
869     ScnStore.prototype.UpdateOrderForm = function() {
870
871
872        this._logger('Updating order form...', 'info');
873
874        if ( ! this._isset(this.orderForm)) {
875            this._logger('The order form is not set. Readme tells how to set it.', 'warn');
876            return;
877        };
878
879        
880        var OrderFormData = {
881            FullRecalculate: false,
882            ShippingAddressData: {},
883            BillingAddressData:  {},
884            ShippingOptionData:  {}
885        };
886
887        
888        var that = this;
889
890        
891        $.each(that.orderForm, function(section, fields) {
892
893            
894            if (section == "ShippingAddressData") {
895
896                
897                $.each(fields, function(field, attr) {
898                    var val = $('#' + attr.Id).val();
899
900                    
901
902                    if (field == 'StateProvince' && val == "other") {
903                        val = $('#ShippingStatePorvince_other').val();
904                    };
905                    OrderFormData.ShippingAddressData[field] = val;
906                });
907
908                that._logger("Captured shipping address as:", 'info');
909                that._logger(OrderFormData.ShippingAddressData);
910
911                
912            };
913
914            
915            if (section == "BillingAddressData") {
916
917                
918                $.each(fields, function(field, attr) {
919                    var val = $('#' + attr.Id).val();
920                    if (field == 'StateProvince' && val == "other") {
921                        val = $('#BillingStatePorvince_other').val();
922                    };
923                    OrderFormData.BillingAddressData[field] = val;
924                });
925
926                that._logger("Captured billing address as:", 'info');
927                that._logger(OrderFormData.BillingAddressData);
928
929            };
930
931
932            
933            if (section == "ShippingOptions") {
934
935                var val = $('input[name=ShipOption]').val();
936                OrderFormData.ShippingOptionData.ShipOption = val;
937
938                that._logger("Captured shipping option as:", 'info');
939                that._logger(OrderFormData.ShippingOptionData);
940            };
941
942        });
943
944
945        
946
947        if ( ! OrderFormData.BillingAddressData.Address1) {
948
949            this._logger('No bill addr set, copy from ship addr...', 'info');
950
951            
952            var sad = JSON.parse(JSON.stringify(OrderFormData.ShippingAddressData));
953            OrderFormData.BillingAddressData = sad;
954
955            this._logger('Merged ship addr into bill addr:', 'info');
956            this._logger(OrderFormData.BillingAddressData);
957
958        };
959
960
961        
962
963        if (OrderFormData.ShippingOptionData.ShipOption) {
964            var shipOption = OrderFormData.ShippingOptionData.ShipOption;
965            this.SelectShippingOption(shipOption);
966        };
967
968
969        
970
971        var ship = OrderFormData.ShippingAddressData;
972        var pcr  = this._shipQuoteValidationList.PostCodeRequired;
973        var rr   = this._shipQuoteValidationList.RegionRequired;
974
975        
976        
977        if ($.inArray(ship.CountryCode, pcr) !== -1) {
978
979            this._logger('The post code is required', 'warn');
980            if (ship.PostalCode.length > 0) {
981                this._logger('And it\'s set to '+ship.PostalCode+' so set flag to "true"');
982                OrderFormData.FullRecalculate = true;
983            };
984
985        
986        } else if ($.inArray(ship.CountryCode, rr) !== -1) {
987
988            this._logger('The region is required', 'warn');
989            if (ship.StateProvince.length > 0) {
990                this._logger('And it\'s set to '+ship.StateProvince+' so set flag to "true"');
991                OrderFormData.FullRecalculate = true;
992            };
993
994        
995        } else {
996            this._logger('The city is required', 'warn');
997            if (ship.City.length > 0 && ship.CountryCode) {
998                this._logger('And it\'s set to '+ship.City+' so set flag to "true"');
999                OrderFormData.FullRecalculate = true;
1000            };          
1001        };
1002
1003
1004        
1005        if (this.lastCart.Tax || this.lastCart.Customs) {
1006            OrderFormData.FullRecalculate = true;
1007        };
1008
1009
1010        
1011        if ( ! this.isPageLoad) {
1012            var fr = OrderFormData.FullRecalculate;
1013            this._logger('Calling bill and ship update. FullRecalc: '+fr);
1014            this.SetBillingShippingAndRecalculate(OrderFormData, fr);
1015        };
1016        
1017    };
1018
1019
1020    
1021    ScnStore.prototype.SetBillingShippingAndRecalculate = function(address, fullRecalc) {
1022        this._logger('Called SetBillingShippingAndRecalculate with: ', 'info');
1023        this._logger(address);
1024
1025        var req = this._jsonRpcRequest("CartApi.SetBillingShippingAndRecalculate", [{
1026            BillingAddressData: address.BillingAddressData,
1027            ShippingAddressData: address.ShippingAddressData,
1028            FullRecalculate: fullRecalc
1029        }]);
1030
1031        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
1032            context: this,
1033            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
1034            success: function(data){
1035
1036                
1037                this._displayError(data);
1038                if (data.hasOwnProperty('result')) {
1039                    this._updateCart(data.result);
1040                };
1041            },
1042            failure: function(errMsg) {
1043                this._logger('SetBillingShippingAndRecalculate call failed', 'error');
1044                this._throwError(errMsg);
1045            },
1046        }));
1047    };
1048
1049
1050    
1051    ScnStore.prototype.SelectShippingOption = function(shipOption) {
1052        this._logger('Called SelectShippingOption with: ', 'info');
1053        this._logger(shipOption);
1054
1055        var req = this._jsonRpcRequest("CartApi.SelectShippingOption", [{
1056            ShippingOptionUniqueId: shipOption,
1057        }]);
1058
1059        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
1060            context: this,
1061            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
1062            success: function(data){
1063
1064                
1065                this._displayError(data);
1066            },
1067            failure: function(errMsg) {
1068                this._logger('SelectShippingOption call failed', 'warn');
1069                this._throwError(errMsg);
1070            },
1071        }));
1072    };
1073
1074
1075    
1076
1077    ScnStore.prototype.UpdateStateList = function(listId, cntyId) {
1078        this._logger('Updating the state list for #' + listId, 'info');
1079
1080        $('#'+listId).addClass('disabled').attr('disabled', 'disabled');
1081        $('#'+listId).parent().addClass('updating');
1082        $('#'+listId+' option').remove();
1083
1084        this._setStateSelect(listId, $('#'+cntyId).val());
1085    };
1086
1087
1088
1089    ScnStore.prototype.ApplyMemberDiscount = function() {
1090        this._logger('Applying member discount.');
1091
1092        var fields = this.orderForm.IasMembership;
1093        var member_info = {
1094            number:    $('#'+fields.IasNumber.Id).val(),
1095            lifetime:  $('#'+fields.IasLifetime.Id).is(':checked'),
1096            exp_date:  null
1097        }
1098
1099        
1100        if ( ! member_info.lifetime) {
1101            member_info.exp_year = $('#'+fields.IasExpYear.Id).val();
1102            member_info.exp_month = $('#'+fields.IasExpMonth.Id).val();
1103            member_info.exp_date = member_info.exp_year+"-"+member_info.exp_month;
1104        }
1105
1106        this._logger(member_info);
1107
1108        var this_year = new Date().getFullYear();
1109        var this_month = new Date().getMonth();
1110
1111
1112        
1113        if (member_info.number.length > 19
1114            || member_info.number.length < 16) {
1115            $('#ias_error_number_length').removeClass('hidden');
1116            return;
1117        }
1118
1119        $('#ias_error_number_length').addClass('hidden');
1120
1121        
1122        if ( ! member_info.lifetime) {
1123            var valid = false;
1124
1125            if (member_info.exp_year == this_year) {
1126                if (member_info.exp_month >= this_month) {
1127                    valid = true;
1128                }
1129            }
1130            else if(member_info.exp_year > this_year) {
1131                valid = true;
1132            }
1133
1134            
1135            if ( ! valid) {
1136                $('#ias_error_expired').removeClass('hidden');
1137                return;
1138            } else {
1139                $('#ias_error_expired').addClass('hidden');
1140            }
1141        }
1142
1143        
1144        $('.ias-error').addClass('hidden');
1145
1146        
1147        var attrs = {};
1148        attrs['public_ias_number'] = (member_info.number) ? member_info.number : null;
1149
1150        var req = this._jsonRpcRequest("CartApi.SetPublicAttrs", [{
1151            OrderAttrs: attrs,
1152            FullRecalculate: true
1153        }]);
1154
1155        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
1156            context: this,
1157            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
1158            success: function(data){
1159
1160                
1161                this._displayError(data);
1162                if (data.hasOwnProperty('result')) {
1163                    $('.ias-error').addClass('hidden');
1164                    $('#ias_success').removeClass('hidden');
1165                    this._updateCart(data.result);
1166                };
1167            },
1168            failure: function(errMsg) {
1169                this._logger('SetBillingShippingAndRecalculate call failed', 'error');
1170                this._throwError(errMsg);
1171            },
1172        }));
1173
1174    };
1175
1176
1177    
1178
1179
1180    ScnStore.prototype.Checkout = function(method) {
1181        this._logger('Doing Checkout...', 'info');
1182
1183        
1184        payMethods = this.orderForm.PaymentMethods;
1185
1186        if ( ! payMethods.hasOwnProperty(method)) {
1187            this._logger(
1188                'Payment method "'+method+'" is not defined in the settings. Aborting.', 'warn'
1189            );
1190            return;
1191        };
1192
1193        
1194        switch (method) {
1195            case 'creditcard' :
1196                var PaymentData = this._captureCreditCardForm();
1197                break;
1198            case 'paypal' :
1199                
1200                break;
1201            default :
1202                this._logger('Payment method is not supported. Aborting', 'warn');
1203                return;
1204        };
1205
1206        this._logger("Captured payment data as: ", 'info');
1207        this._logger(PaymentData);
1208
1209        
1210        this.ExecuteOrder(PaymentData);
1211
1212    };
1213
1214
1215
1216    
1217
1218    ScnStore.prototype.ExecuteOrder = function(payment) {
1219        
1220        if (payment == 'test') {
1221            payment = {
1222                Method:            "creditcard",
1223                AccountType:       "visa",
1224                AccountNumber:     "4111111111111111",
1225                AccountName:       "Joe Test",
1226                AccountExpiration: "2020-10",
1227                AccountVerifCode:  "123"
1228            }
1229        };
1230
1231        this._logger('Called ExecuteOrder with: ', 'info');
1232        this._logger(payment);
1233
1234        var req = this._jsonRpcRequest("CartApi.ExecuteOrder", [{
1235            PaymentAttrs: {
1236                Method:            payment.Method,
1237                AccountType:       payment.AccountType,
1238                AccountNumber:     payment.AccountNumber,
1239                AccountName:       payment.AccountName,
1240                AccountExpiration: payment.AccountExpiration,
1241                AccountVerifCode:  payment.AccountVerifCode
1242            },
1243            Currency: this.currency,
1244            Total: this.lastCart.Total
1245        }]);
1246
1247        this._logger(req);
1248
1249        $.ajaxq('scnstoreq', $.extend(this._jsonBp, {
1250            context: this,
1251            data: {r:JSON.stringify(req),_stsid:window.store_session_id},
1252            success: function(data){
1253                this._logger('ExecuteOrder call succeeded', 'info');
1254                this._logger(data.result);
1255                if (data.result) {
1256                    this._redirect(this.settings.successUrl);
1257                    return;
1258                };
1259
1260                
1261                this._displayError(data);
1262                $('#checkout_btn').prop('disabled', false)
1263                    .html('Bestellung aufgeben »');
1264            },
1265            failure: function(errMsg) {
1266                this._logger('ExecuteOrder call failed', 'warn');
1267                this._throwError(errMsg);
1268            },
1269        }));
1270    };
1271
1272
1273
1274    ScnStore.prototype._captureCreditCardForm = function() {
1275        
1276        fields = this.orderForm.PaymentMethods.creditcard;
1277
1278        var PaymentData = {
1279            Method: 'creditcard',
1280            AccountType:       $('input[name='+fields.AccountType.Id+']:checked').val(),
1281            AccountNumber:     $('#'+fields.AccountNumber.Id).val().replace(/\D/g,''),
1282            AccountName:       $('#'+fields.AccountName.Id).val(),
1283            AccountExpiration: $('#'+fields.AccountExpiration.Year).val()+'-'+$('#'+fields.AccountExpiration.Month).val(),
1284            AccountVerifCode:  $('#'+fields.AccountVerifCode.Id).val()
1285        };
1286
1287        return PaymentData;
1288    };
1289
1290
1291    
1292
1293    ScnStore.prototype._cardFormat = function(str) {
1294        var delimeter    = ' ';
1295        var numbers      = str.substr(0,19).replace(/[^\d]/gi,'');
1296        var full_segment = numbers.match(/(\d){4}/g);
1297
1298        if (full_segment) { 
1299            var block = '';
1300            for (i = 0; i < full_segment.length; i++) {
1301                block += (i != full_segment.length - 1
1302                    ? full_segment[i] + ((i < 3) ? delimeter : '')
1303                    : full_segment[i]);
1304            }
1305            return (numbers.length % 4 != 0 
1306                ? block + ' ' + numbers.substr((full_segment.length * 4),numbers.length)
1307                : block);
1308        } else {
1309            return numbers;
1310        }
1311    }
1312
1313
1314    
1315    
1316    ScnStore.prototype._updateCart = function(newCart) {
1317
1318        if (newCart !== null) {
1319
1320            this._logger('Updating lastCart with newCart: ', 'info');
1321            this._logger(newCart);
1322
1323            
1324            this.lastCart = newCart;
1325
1326            
1327            if (newCart.Currency) {
1328                this.settings.currency = newCart.Currency;
1329            };
1330
1331            this.UpdateUI();
1332        };
1333    };
1334
1335
1336    
1337
1338    ScnStore.prototype._loadOrderForm = function() {
1339
1340        
1341        if ( ! $.isEmptyObject(this.settings.orderForm)) {
1342
1343            
1344            this.orderForm = this.settings.orderForm;
1345
1346            
1347            this._setFulfilledByNotice();
1348
1349            
1350            
1351            
1352            if (this.orderForm.ShippingAddressData.CountryCode.Id
1353                || this.orderForm.BillingAddressData.CountryCode.Id) {
1354
1355                this._loadCountries();
1356            };
1357        };
1358    };
1359
1360
1361    
1362
1363    ScnStore.prototype._loadCountries = function(countries) {
1364
1365        var that = this;
1366
1367        if ( ! this._isset(countries)) {
1368            this._logger('Loading countries...', 'info');
1369            var url = "/_alias/sd.edgesuite.net/lookups/country_list.html";
1370            var locale = that.settings.locale.split('_');
1371            var lang = locale[0];
1372
1373            $.ajaxq('scnstoreq', {
1374                context: this,
1375                url: url+"?locale="+lang+"&callback=ScnStore._loadCountries",
1376                dataType: "script",
1377                failure: function(errMsg) { this._throwError(errMsg) }
1378            });
1379
1380        
1381        
1382        
1383        } else {
1384            this.countryList = countries;
1385            this._logger('Countries loaded successfully:', 'info');
1386            this._logger(countries);
1387
1388            var form = this.orderForm;
1389
1390            
1391            if (shipCntyId = form.ShippingAddressData.CountryCode.Id) {
1392                this._logger('Setting ShippingCountryCode...');
1393                
1394                var shipStateId = form.ShippingAddressData.StateProvince.Id
1395                this._setGeoSelectElementPair(shipCntyId, shipStateId);
1396                $('[name="ShippingCountryCode"]').change();
1397            };
1398
1399            
1400            if (billCntyId = form.BillingAddressData.CountryCode.Id) {
1401                this._logger('Setting BillingCountryCode...');
1402                $('[name="BillingCountryCode"]').change();
1403                
1404                var billStateId = form.BillingAddressData.StateProvince.Id
1405                this._setGeoSelectElementPair(billCntyId, billStateId);
1406            };
1407        };
1408    };
1409
1410
1411
1412    
1413
1414    ScnStore.prototype._setGeoSelectElementPair = function(cntyId, stateId) {
1415        country = this._setCountrySelect(cntyId);
1416
1417        
1418        if (this._isset(stateId) && stateId != false) {
1419            this._setStateSelect(stateId, country);
1420        };
1421    };
1422
1423
1424
1425    
1426
1427    ScnStore.prototype._setCountrySelect = function(cntyId) {
1428
1429        var cntySet = this._createOptionSet(this.countryList, true);
1430        var $list = $('#' + cntyId);
1431
1432        
1433        $list.append(cntySet);
1434
1435        
1436        var country = $list.data('last-country-code');
1437        if (country) {
1438            this._logger('Last country was '+country+', setting it.');
1439            $list.val(country.toUpperCase());
1440        } else {
1441            this._logger('No last country set, falling back to locale...');
1442            var ll = "de_DE".split("_");
1443
1444            if (ll.length > 1) {
1445                country = ll[1].toUpperCase();
1446                this._logger('Locale found: ' + ll[1]);
1447                $list.val(ll[1].toUpperCase());
1448            } else {
1449                country = "US";
1450                this._logger('Locale not found, defaulting to "US".');
1451                $list.val("US");
1452            };
1453        };
1454
1455        
1456        
1457        $list.attr('data-last-country-code', country);
1458        $list.removeAttr('disabled');
1459
1460        return country;
1461    };
1462
1463
1464
1465    
1466    ScnStore.prototype._setStateSelect = function(listId, country) {
1467
1468        var that = this;
1469
1470        var rand = parseInt(Math.random()*(99999999-10000000)+10000000);
1471        var callback = '_stateList_' + rand;
1472        this._logger('Name of the callback is: '+callback);
1473
1474        
1475        
1476        window[callback] = function(stateList) {
1477            that._logger('Got the states for #'+listId);
1478
1479            
1480            
1481            var o = {};
1482            $.each(stateList, function(code, name) {
1483                var parts = code.split('-');
1484                var abbr = parts[1];
1485                o[abbr] = name;
1486            });
1487            stateList = o;
1488
1489            var stateSet = that._createOptionSet(stateList, true);
1490            var $list = $('#' + listId);
1491
1492            
1493            $list.append(stateSet);
1494
1495            
1496            
1497            var state = $list.data('last-state');
1498            if (state) {
1499                that._logger('Last state was '+state+', checking if it\'s here.');
1500
1501                $.each(stateList, function(code, name) {
1502                    if (code == state.toUpperCase()) {
1503                        $list.val(state.toUpperCase());
1504                        return;
1505                    };
1506                });
1507            };
1508
1509
1510            
1511
1512            
1513            
1514            
1515            var c = country;
1516            if (c == "US" || c == "MX" || c == "BR" || c == "DE") {
1517                var label = 'Land ...';
1518            } else if (c == "AU") {
1519                var label = 'Territorium\/Staat ...';
1520            } else if (c == "ZA" || c == "IT" || c == "TW" || c == "NZ") {
1521                var label = 'Provinz ...';
1522            } else if (c == "CA") {
1523                var label = 'Provinz\/Territorium ...';
1524            } else if (c == "GB") {
1525                var label = 'Bezirk';
1526            } else {
1527                var label = 'Region ...';
1528            };
1529
1530            $list.prepend('<option value="">'+label+'</option>');
1531            $list.append('<option value="other">Andere Angabe ...</option>');
1532
1533
1534            
1535            
1536            $list.attr('data-last-state', state);
1537            $list.removeClass('disabled').removeAttr("disabled");
1538            $list.parent().removeClass('updating');
1539        };
1540
1541        
1542        
1543        this._loadStateProvinces(country, callback);
1544
1545    };
1546
1547
1548
1549    
1550
1551    ScnStore.prototype._loadStateProvinces = function(data, callback) {
1552
1553        if(!data) {
1554            console.log("Country is not selected, skipping state list");
1555            return;
1556        }
1557
1558        this._logger('Getting states for '+ data +'...', 'info');
1559        var url = "/_alias/sd.edgesuite.net/lookups/state_list.html";
1560
1561        this._logger("URL: "+url+"?countryCode=" + data + "&callback=" + callback);
1562
1563        $.ajaxq('scnstoreq', {
1564            context: this,
1565            url: url+"?countryCode=" + data + "&callback=" + callback,
1566            dataType: "script",
1567            failure: function(errMsg) { this._throwError(errMsg) }
1568        });
1569    };
1570
1571
1572
1573    
1574
1575    ScnStore.prototype._createOptionSet = function(map, sort) {
1576        
1577        this._logger(map);
1578
1579        
1580        if (sort) {
1581            map = this._sortProperties(map);
1582        };
1583
1584        
1585        
1586        
1587        var optSet = document.createDocumentFragment();
1588
1589        $.each(map, function(code, name) {
1590            var option = document.createElement("option");
1591            option.textContent = name;
1592            option.value = code;
1593            optSet.appendChild(option);
1594        });
1595
1596        return optSet;
1597    };
1598
1599
1600    
1601    
1602    
1603    ScnStore.prototype._checkForOtherStateValAndHandle = function(listId) {
1604        this._logger('Calling _checkForOtherStateValAndHandle', 'info');
1605
1606        var $list = $('#'+listId);
1607        var listVal = $list.val();
1608        
1609        if (listVal == "other") {
1610
1611            
1612            if ( ! $('#'+listId+'_other').length) {
1613
1614                this._logger('There\'s no "other" input and it is selected. Making one...');
1615
1616                var $listParent = $list.parent();
1617
1618                
1619                var input = document.createElement("input");
1620                input.type = "text";
1621                input.setAttribute("id", listId + "_other");
1622                input.setAttribute("style",
1623                    "display: inline-block; width: 68%; float: left; margin-left: 2.5%"
1624                );
1625                input.setAttribute("class", "form-control");
1626
1627                
1628                $list.css({
1629                    width: '29.5%',
1630                    float: 'left'
1631                }).addClass('otherState'); 
1632
1633                
1634                $listParent.append(input);
1635                $('#'+listId + "_other").focus();
1636
1637                this._logger('done.');
1638            };
1639
1640        } else {
1641            this._logger('The selected state is not "other"');
1642
1643            
1644            
1645            if ($list.hasClass('otherState')) {
1646                this._logger('Removing "other" text input');
1647                $list.removeClass('otherState pull-left').css({width:'',float:''});
1648                $('#'+listId+'_other').remove();
1649            };
1650        };
1651    };
1652
1653
1654
1655    
1656
1657    ScnStore.prototype._setShippingOptions = function() {
1658
1659        if ( ! this.hasOwnProperty('orderForm')) {
1660            return;
1661        };
1662        if ( ! this.orderForm.hasOwnProperty('ShippingOptions')) {
1663            return;
1664        };
1665
1666        this._logger('Setting shipping options...', 'info');
1667        var cart = this.lastCart;
1668        var shipOptWrapperId = this.orderForm.ShippingOptions.Id;
1669
1670        
1671        if ( ! cart.ShippingOptions) {
1672            this._logger('No ShippingOptions available yet.', 'warn');
1673
1674            
1675            $('#' + shipOptWrapperId + ' li').each(function(index, val) {
1676                if ($(this).attr('id') == 'ship_option_notice') {
1677                    $(this).removeClass('hidden');
1678                } else {
1679                    $(this).remove();
1680                };
1681            });
1682            return;
1683        }
1684        
1685        var that = this;
1686        var options = cart.ShippingOptions;
1687        var $optionContainer = $('#'+that.orderForm.ShippingOptions.Id);
1688
1689        this._logger('Found some shipping options, here they are:');
1690        this._logger(options);
1691
1692        
1693        $('#' + shipOptWrapperId + ' li').each(function(index, val) {
1694            if ($(this).attr('id') == 'ship_option_notice') {
1695                $(this).addClass('hidden');
1696            } else {
1697                $(this).remove();
1698            };
1699        });
1700
1701        delete this.orderForm.ShippingOptions.Options;
1702        this.orderForm.ShippingOptions.Options = {};
1703
1704        for (var i = options.length - 1; i >= 0; i--) {
1705            $optionContainer.append(that._buildShippingOption(options[i]));
1706        };
1707        
1708        $('#' + shipOptWrapperId + ' input[type=radio]:first-child').attr('checked', 'checked');
1709    };
1710
1711
1712    ScnStore.prototype._buildShippingOption = function(option) {
1713        this._logger('Building option for ' + option.Name);
1714
1715        
1716        var rand = parseInt(Math.random()*(99999-10000)+10000);
1717        var elId = 'ship_option_' + rand;
1718        var currency = this.settings.currency;
1719        var locale = this.settings.locale.split('_');
1720        var lang = locale[0];
1721        var form = this.orderForm;
1722
1723        
1724        var wrapper = document.createElement('li');
1725        wrapper.setAttribute('class', 'shipping-option col-xs-24');
1726
1727            
1728            var input = document.createElement('input');
1729            input.setAttribute('type', 'radio');
1730            input.setAttribute('name', 'ShipOption');
1731            input.setAttribute('value', option.UniqueId);
1732            input.setAttribute('id', elId);
1733            wrapper.appendChild(input);
1734
1735            
1736            var label = document.createElement('label');
1737            label.setAttribute('for', elId);
1738            label.setAttribute('class', 'popout');
1739
1740                
1741                var fauxRdoBtn = document.createElement('div');
1742                fauxRdoBtn.setAttribute('class', 'faux-radio-btn');
1743                label.appendChild(fauxRdoBtn);
1744
1745                
1746                var title = document.createElement('span');
1747                title.setAttribute('class', 'title');
1748                title.appendChild(document.createTextNode(option.Name));
1749                label.appendChild(title);
1750
1751                
1752                var body = document.createElement('span');
1753                body.setAttribute('class', 'body');
1754                body.appendChild(document.createTextNode(
1755                    'Der Versand erfolgt innerhalb eines Arbeitstags.')
1756                );
1757                label.appendChild(body);
1758
1759                
1760                var rate = document.createElement('span');
1761                rate.setAttribute('class', 'rate');
1762                rate.appendChild(document.createTextNode(
1763                    window.FormatCurrency(lang, currency, option.Amount, true)
1764                ));
1765                label.appendChild(rate);
1766
1767        
1768        wrapper.appendChild(label);
1769
1770        
1771        form.ShippingOptions.Options[option.UniqueId] = {id: elId};
1772        this._logger('Done. Element ID is ' + elId);
1773
1774        return wrapper;
1775    };
1776
1777
1778    ScnStore.prototype._setFulfilledByNotice = function() {
1779        var org = this.orderForm.ShippingOptions.FulfilledBy;
1780
1781        if (org !== "undefined") {
1782            switch(org) {
1783                case "bpi": $('#fulfill_notice_' + org).removeClass('hidden');
1784                case "nep": $('#fulfill_notice_' + org).removeClass('hidden');
1785            };
1786            return true;
1787        };
1788        return false;
1789    };
1790
1791
1792    
1793
1794    ScnStore.prototype._initPaymentForm = function() {
1795        
1796        if ( ! this.orderForm) {
1797            return false;
1798        };
1799        var form = this.orderForm;
1800
1801        
1802        if (form.hasOwnProperty('PaymentMethods')) {
1803            
1804            
1805            if (form.PaymentMethods.hasOwnProperty('creditcard')) {
1806                
1807                var mid = form.PaymentMethods.creditcard.AccountExpiration.Month;
1808                var yid = form.PaymentMethods.creditcard.AccountExpiration.Year;
1809                var date = new Date();
1810                $('#'+mid).val(date.getMonth() + 1);
1811                $('#'+yid).val(date.getFullYear());
1812            };
1813        };
1814
1815        return true;
1816    };
1817
1818    ScnStore.prototype._getCardType = function(val) {
1819        
1820        
1821        var types = this.settings.cardTypes;
1822        var ret = false;
1823        $.each(types, function(card, expr) {
1824            var re = new RegExp(expr, 'g');
1825            if (val.match(re)) {
1826                ret = card;
1827            };
1828        });
1829
1830        return ret;
1831    };
1832
1833    ScnStore.prototype._setCardType = function(type) {
1834        
1835        $('.payment-card').each(function(i,el) {
1836            if ($(el).hasClass(type)) {
1837                $(el).addClass('active');
1838                $(el).siblings().prop('checked', true);
1839            };
1840        });
1841        
1842    };
1843
1844    ScnStore.prototype._unsetAllCardTypes = function() {
1845        
1846        $('.payment-card').removeClass('active')
1847        $('input[name=CardType]').prop('checked', false);
1848        
1849    };
1850
1851
1852    
1853    
1854    
1855    ScnStore.prototype._atcPopover = function($el) {
1856
1857        if ($el.hasClass('no-popover')) {
1858            return;
1859        };
1860
1861        var rand = Math.floor(Math.random()*90000) + 10000;
1862        var rmid = 'rm_' + rand;
1863
1864        var txt = document.createElement('p');
1865        txt.setAttribute('class', 'text-success');
1866        txt.setAttribute('style', 'margin: 0; font-weight: bold; text-transform: capitalize');
1867        txt.appendChild(document.createTextNode('Zum Einkaufswagen hinzugef\u0026uuml;gt'));
1868
1869        var btn1 = document.createElement('a');
1870        btn1.setAttribute('class', 'fancy-button1');
1871        btn1.setAttribute('href', 'https:\/\/www.scientology.de\/store\/checkout.action?_=142cd6f51');
1872        btn1.setAttribute('style', 'display: inline-block; margin-right: .5em; text-decoration: none !important');
1873        btn1.appendChild(document.createTextNode('Zur Kasse weitergehen'));
1874
1875        var btn2 = document.createElement('button');
1876        btn2.setAttribute('class', 'btn btn-sm btn-default');
1877        btn2.setAttribute('id', rmid);
1878        btn2.setAttribute('style', 'display: inline-block');
1879        btn2.appendChild(document.createTextNode('×'));
1880
1881        var buttons = document.createElement('div');
1882        buttons.setAttribute('style', 'white-space: nowrap');
1883        buttons.appendChild(btn1);
1884        buttons.appendChild(btn2);
1885
1886        var content = document.createElement('div');
1887        content.appendChild(txt);
1888        content.appendChild(buttons);
1889
1890        var options = {
1891            placement: 'top',
1892            trigger: 'focus',
1893            html: true,
1894            template: '<div class="popover" role="tooltip"><div class="arrow"></div><div class="popover-content"></div></div>',
1895            content: content,
1896        }
1897
1898        $el.popover(options).popover('show');
1899
1900        $('body').on('click', '#' + rmid, function(event) {
1901            event.preventDefault();
1902            $el.popover('hide');
1903        });
1904
1905        setTimeout(function(){
1906           $el.popover('hide'); 
1907        },5000)
1908
1909
1910
1911    };
1912
1913    
1914    
1915    
1916    ScnStore.prototype._atcInline = function($el) {
1917
1918        
1919        var cache = $el.html();
1920        
1921        
1922        $el.addClass('proceed-to-checkout');
1923        $el.html('Zum Einkaufswagen hinzugef\u0026uuml;gt');
1924
1925        
1926        setTimeout(function(){
1927            $el.html(cache);
1928            $el.removeClass('proceed-to-checkout');
1929        }, 3000);
1930    }
1931
1932
1933    
1934
1935
1936    
1937    ScnStore.prototype._jsonRpcRequest = function(methodName, params) {
1938        if ( ! this._isset(params)) { params = [{}] };
1939
1940        return {
1941            "jsonrpc": "2.0",
1942            "method": methodName,
1943            "id": parseInt(Math.random() * 1000000000000),
1944            "params": params
1945        }
1946    };
1947
1948    
1949    ScnStore.prototype._jsonBp = {
1950        type: "POST",
1951        url: "https://www.scientology.de/store/api.action?_=142cd6f51",
1952        
1953        dataType: "json"
1954    };
1955
1956    
1957
1958     ScnStore.prototype._logger = function(data, level) {
1959
1960        
1961            return;
1962        
1963
1964        switch (level) {
1965            case 'info':  this.log.info(data);  break;
1966            case 'warn':  this.log.warn(data);  break;
1967            case 'trace': this.log.info(trace); break;
1968            case 'error': this.log.error(data); break;
1969            default: this.log.debug(data);
1970        }
1971    };
1972
1973
1974    
1975    ScnStore.prototype._failIfUndefined = function(v, msg) {
1976        if ( ! this._isset(v)) {
1977            throw new this._throwError(msg);
1978        };
1979    };
1980
1981
1982    
1983    ScnStore.prototype._throwError = function(msg) {
1984        var err = Error.call(this, msg);
1985        err.name = "ScnStoreError";
1986        return err;
1987    };
1988
1989
1990    ScnStore.prototype._displayError = function(data) {
1991        if (data.error) {
1992
1993            var err = data.error;
1994            var alertElement;
1995
1996            
1997            if (err.code == 1000) {
1998                for (var i = err.data.length - 1; i >= 0; i--) {
1999                    this._buildErrorMessage(
2000                        err.data[i].Code,
2001                        err.data[i].Message
2002                    );
2003
2004                    
2005                    this._logger('ScnStore Error '+
2006                        err.data[i].Code +': '+
2007                        err.data[i].Message, 'error');
2008                };
2009            } else {
2010                
2011                
2012                
2013
2014                
2015                this._logger('ScnStore Error: '+
2016                    err, 'error');
2017
2018                this._buildErrorMessage(
2019                    'generic_err',
2020                    
2021                    'Fehlermeldung'
2022                );
2023            };
2024        };
2025    };
2026
2027    ScnStore.prototype._buildErrorMessage = function(code, message) {
2028        var alert = document.createElement('li');
2029        alert.setAttribute('class', 'alert alert-danger alert-dismissible');
2030        alert.setAttribute('id', code);
2031        alert.setAttribute('role', 'alert');
2032        alert.appendChild(document.createTextNode(message));
2033            var btn = document.createElement('button');
2034            btn.setAttribute('type', 'button');
2035            btn.setAttribute('class', 'close');
2036            btn.setAttribute('data-dismiss', 'alert');
2037            btn.setAttribute('aria-label', 'Close');
2038                var x = document.createElement('span');
2039                x.setAttribute('aria-hidden', 'true');
2040                x.appendChild(document.createTextNode('×'));
2041                btn.appendChild(x);
2042            alert.appendChild(btn);
2043
2044        if (code == 'jsvalidate_msg') {
2045            $('#error_box #jsvalidate_msg').remove();
2046            $('#error_box').append(alert);
2047        } else if ( ! $('#error_box #'+code).length) {
2048            $('#error_box').append(alert);
2049        };
2050
2051        $('#error_box_anchor').click();
2052    };
2053
2054
2055    
2056    ScnStore.prototype._isset = function(v) {
2057        return (typeof v !== 'undefined') ? true : false;
2058    };
2059
2060    ScnStore.prototype._pageLoaded = function() {
2061        var that = this;
2062
2063        
2064        
2065        window.onload = function() {
2066            that.isPageLoad = false;
2067
2068            if ( ! $.isEmptyObject(that.settings.orderForm)) {
2069                that.UpdateOrderForm();
2070            };
2071        }
2072    };
2073
2074    ScnStore.prototype._isChrome = function() {
2075        if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
2076            return true;
2077        };
2078
2079        return false;
2080    };
2081
2082
2083    ScnStore.prototype._updateProductAttrs = function(newItem) {
2084
2085
2086        var uniqueId = newItem.UniqueId,
2087            itemCode = newItem.ProductId,
2088            quantity = newItem.Quantity,
2089            subtotal = newItem.SubtotalPrice,
2090            unitPrice= newItem.UnitPrice,
2091            locale   = this.settings.locale.split('_'),
2092            currency = this.settings.currency,
2093            lang     = locale[0],
2094            that     = this
2095
2096        
2097        var $item = $('.cart-item[data-scnstore-uniqueid='+uniqueId+']');
2098        $item.attr('id', 'cart_item_'+itemCode);
2099        $item.find('label[for^=language_]').attr('for', 'language_'+itemCode);
2100        $item.find('select[name^=language_]').attr('name', 'language_'+itemCode);
2101        $item.find('select[id^=language_]').attr('id', 'language_'+itemCode);
2102        $item.find('label[for^=quantity_]').attr('for', 'quantity_'+itemCode);
2103        $item.find('input[name^=quantity_]').attr('name', 'quantity_'+itemCode);
2104        $item.find('input[id^=quantity_]').attr('id', 'quantity_'+itemCode);
2105
2106
2107        
2108        $.get('/store/ajax/product-images.action', function(data) {
2109            $.each(data, function(key, prod) {
2110                if (uniqueId == key) {
2111                    if ($item.find('.image img').attr('src') != prod.Image) {
2112
2113                        
2114                        
2115                        var proxy = '/imagecache/scalefit-170x1000@as=1@qa=65@fm=jpeg@bg=ffffff';
2116
2117                        var parseUrl = function(href) {
2118                            var l = document.createElement("a");
2119                            l.href = href;
2120                            return l;
2121                        };
2122                        var url = parseUrl(prod.Image),
2123                            host = "/_alias/f.edgesuite.net",
2124                            path = url.pathname.replace(host, ""),
2125                            link = host + proxy + path;
2126                        that._logger('Updating image url with: ' + link);
2127                        $item.find('.image img').attr('src', link);
2128                    };
2129                };
2130            });
2131        });
2132
2133        
2134        
2135        $item.find('.unit-price-data').html(
2136            window.FormatCurrency(lang, currency, unitPrice, true));
2137        $item.find('.total-price').html(
2138            window.FormatCurrency(lang, currency, subtotal, true));
2139
2140        $item.find('select').removeAttr('disabled');
2141        $item.find('input').removeAttr('disabled');
2142
2143    };
2144
2145    
2146
2147    ScnStore.prototype._sortProperties = function(obj, isNumericSort)
2148    {
2149        isNumericSort=isNumericSort || false; 
2150        var sortable=[];
2151        for(var key in obj) {
2152            if(obj.hasOwnProperty(key))
2153                sortable.push([key, obj[key]]);
2154            if(isNumericSort) {
2155                sortable.sort(function(a, b) {
2156                    return a[1]-b[1];
2157                });
2158            } else {
2159                sortable.sort(function(a, b) {
2160                    var x=a[1].toLowerCase(),
2161                        y=b[1].toLowerCase();
2162                    return x<y ? -1 : x>y ? 1 : 0;
2163                });
2164            }
2165        }
2166
2167        
2168        obj = {};
2169        $.each(sortable, function(i, arr) {
2170            obj[arr[0]] = arr[1];
2171        });
2172
2173        sorted = obj;
2174        return sorted;
2175    };
2176
2177    ScnStore.prototype._redirect = function(url) {
2178        var ua        = navigator.userAgent.toLowerCase(),
2179            isIE      = ua.indexOf('msie') !== -1,
2180            version   = parseInt(ua.substr(4, 2), 10);
2181
2182        
2183        if (isIE && version < 9) {
2184            var link = document.createElement('a');
2185            link.href = url;
2186            document.body.appendChild(link);
2187            link.click();
2188        }
2189
2190        
2191        else { window.location.href = url; }
2192    };
2193
2194
2195    $.fn.serializeObject = function() {
2196        var o = {};
2197        var a = this.serializeArray();
2198        $.each(a, function() {
2199            if (o[this.name] !== undefined) {
2200                if (!o[this.name].push) {
2201                    o[this.name] = [o[this.name]];
2202                }
2203                o[this.name].push(this.value || '');
2204            } else {
2205                o[this.name] = this.value || '';
2206            }
2207        });
2208
2209        return o;
2210    };
2211
2212    ScnStore.prototype._click = function(selector) {
2213        var linkEl = $( selector );
2214        if ( linkEl.attr ( 'onclick' ) === undefined ) {
2215            document.location = linkEl.attr ( 'href' );
2216        } else {
2217            linkEl.click ();
2218        }
2219    };
2220
2221    
2222
2223    ScnStore.prototype._shipQuoteValidationList = {
2224        PostCodeRequired: [
2225            "DZ", 
2226            "AD", 
2227            "AR", 
2228            "AM", 
2229            "AU", 
2230            "AT", 
2231            "AZ", 
2232            "BD", 
2233            "BY", 
2234            "BE", 
2235            "BA", 
2236            "BR", 
2237            "BG", 
2238            "CA", 
2239            "CN", 
2240            "CO", 
2241            "HR", 
2242            "CY", 
2243            "CZ", 
2244            "DK", 
2245            "EC", 
2246            "EE", 
2247            "FI", 
2248            "FR", 
2249            "GE", 
2250            "DE", 
2251            "GR", 
2252            "GL", 
2253            "HU", 
2254            "IS", 
2255            "IN", 
2256            "ID", 
2257            "IL", 
2258            "IT", 
2259            "JP", 
2260            "KZ", 
2261            "KG", 
2262            "LV", 
2263            "LI", 
2264            "LT", 
2265            "LU", 
2266            "MK", 
2267            "MY", 
2268            "MH", 
2269            "MX", 
2270            "FM", 
2271            "MD", 
2272            "MN", 
2273            "ME", 
2274            "NL", 
2275            "NZ", 
2276            "NO", 
2277            "PK", 
2278            "PW", 
2279            "PH", 
2280            "PL", 
2281            "PT", 
2282            "RO", 
2283            "RU", 
2284            "SM", 
2285            "SA", 
2286            "RS", 
2287            "SG", 
2288            "SK", 
2289            "SI", 
2290            "ZA", 
2291            "KR", 
2292            "ES", 
2293            "LK", 
2294            "SE", 
2295            "CH", 
2296            "TW", 
2297            "TJ", 
2298            "TH", 
2299            "TN", 
2300            "TR", 
2301            "TM", 
2302            "UA", 
2303            "GB", 
2304            "US", 
2305            "UY", 
2306            "UZ", 
2307            "VU", 
2308            "VN", 
2309        ],
2310        RegionRequired: [
2311            "AL", 
2312            "AG", 
2313            "KY", 
2314            "CL", 
2315            "JM", 
2316            "KW", 
2317            "NG", 
2318            "PA", 
2319            "PE", 
2320            "TT", 
2321            "VE", 
2322            "ZW" 
2323        ]
2324    };
2325
2326
2327    
2328
2329    $.fn.ScnStore = function(options){
2330        return this.each(function(index,el){
2331            el.ScnStore = new ScnStore(el,options);
2332        });
2333    };
2334});

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.