var App_ECommerce_Checkout = { _rateAction: 'getShippingRate', _rateTimeout: null, _shippingElementId: 'serviceShipping-type-element', _paymentElementId: 'servicePayment-type-element', _rateElementId: 'serviceShipping-rate-element', _form: null, _cardTipClass: 'cardCode-tip', _shippingAjaxRequest: undefined, init: function(formId) { if (formId) { this._form = $('#' + formId); var obj = this; var shippingElements = $('#' + this._shippingElementId); if ($(shippingElements).size()) { this._updateShippingRate(); shippingElements.find('input').change(function() { obj._onShippingClick(this); }); var shippingChecked = shippingElements.find('input:checked'); obj._onShippingClick(shippingChecked); this._initFedexAddressType(); this._updateFedexAddressType(); $('.shipping, #' + this._shippingElementId).find('input').bind('click', function() { obj._updateShippingRate(); }); $('[name*="[state]"], [name*="[zip]"]').change(function(){ obj._updateShippingRate(); }); } var paymentElements = $('#' + this._paymentElementId); if ($(paymentElements).size()) { $('.' + obj._cardTipClass).tooltip({html: true}); paymentElements.find('input').change(function() { obj._onPaymentClick(this); }); var paymentChecked = paymentElements.find('input:checked'); obj._onPaymentClick(paymentChecked); } App_User_Form.prototype.onAsBillingClick = obj.onAsBillingClick; $('[name^="billing["]', this._form).each(function () { $(this).blur(function () { obj._populateShippingInfo(obj._form); }); }); } // $("#checkout-total").affix({ // offset: { // top: 100, // bottom: ($("footer.block").outerHeight(true) + $("#checkout-footer").outerHeight(true) + 24) // } // }); }, _initFedexAddressType: function() { var obj = this; $('#serviceShipping-fedExAddressType-residential').bind('change', function() { obj._updateFedexAddressType() }); $('#serviceShipping-fedExAddressType-commercial').bind('change', function() { obj._updateFedexAddressType() }); }, _updateFedexAddressType: function() { var residential = $('#serviceShipping-fedExAddressType-residential'); var commercial = $('#serviceShipping-fedExAddressType-commercial'); if (residential.size() && commercial.size()) { var ground = $('label[for="serviceShipping-fedExMethod-FEDEXGROUND"]'); var home = $('label[for="serviceShipping-fedExMethod-GROUNDHOMEDELIVERY"]'); if (residential.is(':checked')) { ground.hide(); ground.next('br').hide(); home.next('br').show(); home.show(); if ($('input', ground).is(':checked')) { $('input', home).prop('checked', 'checked'); } } else if (commercial.is(':checked')) { home.next('br').hide(); home.hide(); ground.next('br').show(); ground.show(); if ($('input', home).is(':checked')) { $('input', ground).prop('checked', 'checked'); } } } }, _populateShippingInfo: function(_form) { var asBilling = $('#shipping-asBilling', _form); if ($(asBilling).is(':checked')) { $('[name^="billing["]', this._form).each(function () { var shippingFieldName = $(this).attr('name').replace('billing[', 'shipping['); var shippingField = $('[name="' + shippingFieldName + '"]'); if ($(shippingField).size()) { $(shippingField).val($(this).val()); } }); } }, _onShippingClick: function(element) { $('.shipping').closest('dd' ).hide(); $('#serviceShipping-' + $(element).val() + 'Methods-element').show(); }, _onPaymentClick: function(element) { $('.payment').closest('dd').hide(); $('#servicePayment-' + $(element).val() + 'Methods-element').show(); }, _updateShippingRate: function() { var obj = this; if (obj._rateTimeout) { clearTimeout(obj._rateTimeout); } obj._rateTimeout = setTimeout(function() { obj._getShippingRate(); }, 300); }, _getShippingRate: function() { var request = {}; $.each(this._form.serializeArray(), function(i, field) { request[field.name] = field.value; }); request.action = this._rateAction; var obj = this; if (typeof this._shippingAjaxRequest != 'undefined') { this._shippingAjaxRequest.abort(); this._shippingAjaxRequest = undefined; } this._shippingAjaxRequest = qs.ajax( qs.constant('BASE_URL') + '/' + qs.constant('CURRENT_PAGE'), request, { qsDefaultCallbacks: false } ); this._shippingAjaxRequest.done(function (response) { qs.hideLoading(); if (!response || response.isError) { var errorCallback = (response && response.errorCallback) ? response.errorCallback : {fn: qs.errorCallback, args: [response]}; qs.call(errorCallback); return this; } if (response && response.callbacks) { qs.call(response.callbacks); } var html = '$' + parseFloat(response.total).toFixed(2); if (response.message != '' && response.message) { html += '