<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">$(document).ready(function() {

	// Setup

	var debug = false;

	// Options styling 

	$('#tieback-single--pair,#tieback-pole-width,#tieback-style').wrapAll('&lt;div class="card border-top"&gt;&lt;div class="card-body"&gt;&lt;/div&gt;&lt;/div&gt;');

	// Control the Tieback Single Pair hidden checkboxes using the inserted select box

	$( "#tieback-single--pair .checkbox-controller" ).change(function() {
		$( "#product-pricing" ).hide();
	    var self = $(this);
	    pricing.single_pair = checkboxController(self);
	});

	// Control the Tieback Size hidden checkboxes using the inserted select box

	$( "#tieback-pole-width .checkbox-controller" ).change(function() {
		$( "#product-pricing" ).hide();
	    var self = $(this);
	    var size = checkboxController(self);
	    pricing.size = size;
	});
	
	// Control the Tieback Style hidden checkboxes using the inserted select box

	$( "#tieback-style .checkbox-controller" ).change(function() {
		$( "#product-pricing" ).hide();
	    var self = $(this);
	    pricing.style = checkboxController(self);
	});

	// Run the calculate price script on button click

	$( "#calculate-price" ).click(function() {
	    calculateTiebackPrice(pricing);
	});

	// Submit on return

	$( "#product-options input" ).keypress(function (e) {
		if (e.which == 13) {
			calculateTiebackPrice(pricing);
			return false;
		}
	});

	// Handle the options before adding to basket

	$( "#custom-button-cart" ).click(function() {
		calculateTiebackPrice(pricing);
		controlOptions(pricing);
		$('#button-cart').click();
		$('#calculate-reset').show();
		$('#calculate-price').hide();
		resetPage();
	});

	// // // Calculate the curtain prices // // //

	function calculateTiebackPrice(pricing) {

		// Form Validation

		$( "#product-options .form-group" ).removeClass('invalid');

		var valid = true;

		if ( !pricing.single_pair ) {
			$( "#tieback-single--pair" ).addClass('invalid');
			valid = false;
		}
		if ( !pricing.size ) {
			$( "#tieback-pole-width" ).addClass('invalid');
			valid = false;
		}
		if ( !pricing.style ) {
			$( "#tieback-style" ).addClass('invalid');
			valid = false;
		}


		if ( valid ) {

			$( ".form-group-calculate" ).hide();
			$( '#calculation-alert' ).html('');

			// Set the fabric variables from product attributes 

			var fabric = {
			    fabricWidth : attributes.fabricWidth,
			    patternRepeat : attributes.patternRepeat,
			    fabricPrice : attributes.fabricPrice,
			};
			
			pricing.data = product_data[pricing.style][pricing.size][pricing.single_pair];

			pricing.totalFabricPrice = (pricing.data.fabric_length * attributes.fabricPrice);
			pricing.totalMakeupPrice = pricing.data.make_up;

			pricing.totalPrice = (
				+pricing.totalFabricPrice +
				+pricing.totalMakeupPrice).toFixed(2);

			// If fabric discounted calculate and show price before discount
			pricing.totalDiscount = 0;
			if ( attributes.discount ){
				pricing.priceBeforeDiscount = (pricing.totalPrice * ( 1 + (attributes.discount/100) )).toFixed(2);
				pricing.totalDiscount = parseFloat(pricing.totalDiscount) + parseFloat(pricing.totalPrice * attributes.discount / 100);
			}else{
				pricing.priceBeforeDiscount = parseFloat(pricing.totalPrice).toFixed(2);
			}

			// Apply total discounts

			if (pricing.totalDiscount &gt; 0) {
				$( "#totalPriceBeforeDiscount" ).html("Was: &lt;span class=\"c-contrast line-through\"&gt;&amp;pound;" + pricing.priceBeforeDiscount + "&lt;/span&gt;");
				pricing.totalPrice = (pricing.priceBeforeDiscount - pricing.totalDiscount).toFixed(2);
				$( "#totalDiscount" ).html( parseFloat(pricing.totalDiscount).toFixed(2) );
				$( "#product-discount" ).show();
				var totalPriceText = "Now: &amp;pound;" + pricing.totalPrice;
			}else{
				$( "#totalDiscount" ).html("");
				$( "#totalPriceBeforeDiscount" ).html("");
				var totalPriceText = "Our Price: &amp;pound;" + pricing.totalPrice;
			}

			$( "#totalPrice" ).html(totalPriceText);

			// Reveal the product pricing area 

			if ( pricing.totalPrice &gt; 10 &amp;&amp; pricing.totalPrice != "NaN" ){
				$( "#product-pricing" ).show();

				// Setup Worksheet Data
				$( "#worksheet textarea" ).val(JSON.stringify(worksheet));
			
			}else{
				if (debug) { console.log(pricing); }
			}

		}else{
			$( '#calculation-alert' ).html('&lt;p class="c-danger"&gt;&lt;i class="fa fa-exclamation-triangle"&gt;&lt;/i&gt; There is a problem with your order, please try again.&lt;/p&gt;');
			if (debug) { console.log(pricing); }
		}

	}

	function checkboxController(self){
		var parent = self.parent();
		var option_value = self.val().split("Â£");
		var option_name = "";
		var price = option_value[1];
		$( parent ).find( "input" ).prop( "checked", false );
	    $( parent ).find( ".checkbox" ).removeClass('checked');

	   	$( parent ).find('input[type=checkbox]').each(function (e) {
	    	var self = $(this);
			if ( self.val() == option_value[0] ) {
				option_name = self.parent().find('.option_name').html();
			    self.prop( "checked", true );
			    self.parent().parent().addClass('checked');
			}
		});
		$( parent ).next().removeClass('show');
	    if (price &gt; 0){
	    	$( parent ).next().addClass('show');
	    }
	    var option_name_parts = option_name.split("(");
	    option_name = option_name_parts[0].replace( /cm/g, "").replace( / /g, "").toLowerCase();

	    return option_name;
	}

	function controlOptions(pricing) {

		// Clear the cloned checkboxes then add in the checkboxes according to current sizes
		$( ".checkbox.clone" ).remove();
		var i;

		var price100 = 1;
		var price10 = 1;
		var price1 = 1;
		var price = (pricing.totalPrice * 100) / vatrate;

		price -= 111;
		var count = Math.floor(price / 100);
		price100 += count;
		price -= count*100;
		count = Math.floor(price / 10);
		price10 += count;
		price -= count*10;
		count = Math.floor(price / 1);
		price1 += count;

		// Size checkboxes 100
		for (i = 1; i &lt; price100; i++) {
			var checked = $( "#tieback-single--pair .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}

		// Style checkboxes 10
		for (i = 1; i &lt; price10; i++) {
			var checked = $( "#tieback-pole-width .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}

		// Filling checkboxes 1
		for (i = 1; i &lt; price1; i++) {
			var checked = $( "#tieback-style .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}

	}

});</pre></body></html>