var App_ECommerce_Checkout = { _paymentElementId: 'servicePayment-type-element', _form: null, _cardTipId: 'cardCode-tip', init: function(formId) { if (formId) { this._form = $('#' + formId); var obj = this; var paymentElements = $('#' + this._paymentElementId); if ($(paymentElements).size()) { var cardTip = $('#' + obj._cardTipId); if (cardTip.size()) { cardTip.qtip({ content: { text: $('#' + obj._cardTipId + '-value').val() } }); } paymentElements.find('input').click(function() { obj._onPaymentClick(this); }); var paymentChecked = paymentElements.find('input:checked, input[type="hidden"]'); if (paymentChecked) { obj._onPaymentClick(paymentChecked); } } } }, _onPaymentClick: function(element) { $('.payment').hide(); $('#servicePayment-fieldset-' + $(element).val() + 'Methods').show(); }, onAsBillingClick: function (asBilling, type) { for (var i = 0; i < this.options.addressFields.length; i++) { var name = this.options.addressFields[i]; var selector = '#' + type + '-' + name; if ($(asBilling).is(':checked')) { $(selector).attr('disabled', 'disabled'); this.setElementValue(type, name, this.getElementValue(this.options.inheritedAddress, name)); } else { $(selector).removeAttr('disabled'); if (!this.getElementValue(type, name)) { this.setElementValue(type, name, this.getElementValue(this.options.inheritedAddress, name)); } } } return true; } }; var App_ECommerce_Checkout_OtherServices = { _containerId: null, init: function(id) { this._containerId = id; $('#' + this._containerId).find('input[type=checkbox]').click(function() { var valueFieldId = $(this).attr('id') + 'Value-element' ; var valueField = $('#' + valueFieldId); if ($(this).is(':checked')) { valueField.show(); } else { valueField.hide(); } }); }, _removeErrors: function() { $('#' + this._containerId).find('ul.errors').remove(); }, _addErrors: function(message, afterContainer) { afterContainer.after(''); }, applyAction: function(requestAction, element) { this._removeErrors(); var obj = this; var request = { code: $(element).parent().children('input').val() }; request.action = requestAction; qs.ajax(qs.constant('BASE_URL') + '/' + qs.constant('CURRENT_PAGE'), request).done(function(data){ if (!data.success) { obj._addErrors(data.message, $(element)); } else { var inputId = $(element).parent().children('input').attr('id'); var checkboxId = inputId.replace('Value', ''); $('#' + checkboxId + '-label').remove(); $('#' + checkboxId + '-element').remove(); $('#' + inputId + '-label').show(); $('#' + inputId + '-element').html(data.elementValue).show(); noty({text: data.message, timeout: 3000}); } }).fail(function(status) {alert(status.responseText);}); }, applyPromoCode: function(element) { this.applyAction('applyPromoCode', element); }, applyGiftCard: function(element) { this.applyAction('applyGiftCard', element); } };