// Library release: v1.19.0.4, 16 February 2010
// Documentation: svn\Wiki\JavaScript\
BundleDisplay={version:"1.0.1",responseDisplay:$('<div class="clearfix" id="bundle_display_confirmation"></div>'),loadingIndicator:$('<p id="bundle_display_ajax_loader"><strong>Adding outfit to bag...</strong></p>'),formSubmitted:false,init:function(){$("#bundle_display_column_2").append(BundleDisplay.responseDisplay);$("#bundledetailsform").submit(function(){$("p#bundle_display_size_error").hide();BundleDisplay.responseDisplay.hide().empty();var bundleValid=BundleDisplay.validateBundle();if(!bundleValid)BundleDisplay.displayValidationError();else{if(BundleDisplay.formSubmitted){return false}else{BundleDisplay.formSubmitted=true;BundleDisplay.loaderApply();BundleDisplay.doAjaxCall();}}return false});},validateBundle:function(){var sizes=$("select.select_product_size");var bundleValid=true;sizes.each(function(){if(!this.selectedIndex)bundleValid=false});return bundleValid},displayValidationError:function(){$("p#buy_bundle").after("<p id=\"bundle_display_size_error\"><strong>You need to select a size for each item before you can add this outfit to your bag.</strong></p>");},doAjaxCall:function(){var inputs=[];$('#bundledetailsform input').each(function(){inputs.push(this.name+'='+escape(this.value));});$('#bundledetailsform select').each(function(){inputs.push(this.name+'='+escape(this.value));});$.ajax({type:"POST",url:'/webapp/wcs/stores/servlet/NewProductDetailsActionControl',data:inputs.join("&"),dataType:"json",cache:false,timeout:20000,success:function(response){if(response.success){if(typeof omniItemAddedToBag=="function"){omniItemAddedToBag();}BundleDisplay.loaderRemove(500,response);}else{BundleDisplay.loaderRemove(0,response);}},error:function(){var response={};response.message="Sorry, an error has occurred; please try again later.";BundleDisplay.loaderRemove(0,response);}});return false},loaderApply:function(){$("#bundle_display_column_2 ul").after(BundleDisplay.loadingIndicator.show());$('body').addClass('ajax_loading');},loaderRemove:function(duration,response){BundleDisplay.loadingIndicator.fadeOut(duration,function(){BundleDisplay.loadingIndicator.remove();BundleDisplay.formSubmitted=false;$("body").removeClass("ajax_loading");BundleDisplay.displayAJAXMessage(response);});},displayAJAXMessage:function(response){BundleDisplay.responseDisplay.show();if(response.success){var oufitName=$('#bundle_display_header h1').text();var outfitPrice=$('#buy_bundle_price').text();var checkoutUrl="OrderCalculate?langId=-1&storeId="+Arcadia.currentStoreId+"&catalogId="+Arcadia.currentCatalogId+"&updatePrices=1&calculationUsageId=-1&orderId=.&URL=OrderItemDisplay";var successDisplay="<p id=\"outfit_added_to_bag\">Outfit added to bag</p>";successDisplay+="<dl>";successDisplay+="	<dt>Outfit:</dt><dd>"+oufitName+"</dd>";successDisplay+="	<dt>Price:</dt><dd>"+Brand.storeCurrencySymbol+outfitPrice+"</dd>";successDisplay+="</dl>";successDisplay+="<p id=\"bundle_display_confirmation_bag\" href=\""+checkoutUrl+"\">";successDisplay+="<span class=\"bundle_display_confirmation_items\">"+response.items+"</span> item(s) in your bag<br />";successDisplay+="Subtotal: "+Brand.storeCurrencySymbol+"<strong class=\"bundle_display_confirmation_total\">"+response.total+"</strong></p>";successDisplay+="<p id=\"bundle_display_confirmation_bag_gotocheckout\" class=\"replace\"><a title=\"Go to checkout\" href=\""+checkoutUrl+"\">Go to checkout</a></p>";BundleDisplay.responseDisplay.html(successDisplay);var headerCart=$('#itemsummary a');headerCart.addClass('itemsummary_items').html(Brand.ProductConfig.mBasket);$('.headercart-items',headerCart).html(response.items);$('.headercart-total',headerCart).html(response.total.toFixed(2));}else{$(BundleDisplay.responseDisplay).html("<p id=\"bundle_display_error\">"+response.message+"</p>").show();}return false}};$(document).ready(function(){BundleDisplay.init();});