<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 = true;
	var minWidth = "30";
	var maxWidth = "550";
	var minDrop = "10";
	var maxDrop = "100";
	var product_style_name = "";

	// Options styling 
	
	$('#product-style').wrap('&lt;div class="card border-top"&gt;&lt;div class="card-body"&gt;&lt;/div&gt;&lt;/div&gt;');
	$('#measurements,#pelmet-width,#pelmet-drop').wrapAll('&lt;div class="card border-top"&gt;&lt;div class="card-body"&gt;&lt;/div&gt;&lt;/div&gt;');
	$('#pelmet-width,#pelmet-drop').wrapAll('&lt;div class="row form-group-inline"&lt;/div&gt;');
	$('#pelmet-width,#pelmet-drop').wrap('&lt;div class="col"&gt;&lt;/div&gt;');
	$('#product-lining,#product-interlining').wrapAll('&lt;div class="card border-top"&gt;&lt;div class="card-body"&gt;&lt;/div&gt;&lt;/div&gt;');

	$( "#pelmet-width" ).append("&lt;small&gt;Min: " + minWidth + "cm, Max: " + maxWidth + "cm.&lt;/small&gt;");
	$( "#pelmet-drop" ).append("&lt;small&gt;Min: " + minDrop + "cm, Max: " + maxDrop + "cm.&lt;/small&gt;");

	$('&lt;p&gt;All our pelmets are calculated with 15cm returns. Upon receipt of your order our team will be in touch to confirm your measurements.&lt;/p&gt;').insertAfter('#product-style');

	// Control the Product Style hidden checkboxes using the inserted select box

	$( "#product-style .checkbox-controller" ).change(function() {
	    var self = $(this);
	    var option_value = self.val().split("Â£");
		var option_name = "";

		$( "#product-style input" ).prop( "checked", false );
		$( "#product-style .checkbox" ).removeClass('checked');

	   	$( "#product-style" ).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 ).parent().parent().addClass('checked');
			}
		});

	    pricing.pelmetStyle = option_name;

	});


	// Control the Lining hidden checkboxes using the inserted select box

	$( "#product-lining .checkbox-controller" ).change(function() {
		$( "#product-pricing" ).hide();
	    var self = $(this);
	    $( "#product-interlining .checkbox-controller" ).prop('selectedIndex',0);
	    pricing.interliningPrice = "";
	    pricing.liningPrice = checkboxController(self);
	});

	// Control the Interlining hidden checkboxes using the inserted select box

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

	// Measurements change

	$( "#measurements input" ).change(function() {
		$( "#product-pricing" ).hide();
		var self = $(this);
		if ( self.hasClass('CM') ){
			// CM
			$( "#pelmet-width" ).find( "small" ).html("Min: " + minWidth + "cm, Max: " + maxWidth + "cm.");
			$( "#pelmet-drop" ).find( "small" ).html("Min: " + minDrop + "cm, Max: " + maxDrop + "cm.");
		}else{
			$( "#pelmet-width" ).find( "small" ).html("Min: " + Math.ceil(minWidth / inch) + "\", Max: " + Math.floor(maxWidth / inch) + "\".");
			$( "#pelmet-drop" ).find( "small" ).html("Min: " + Math.ceil(minDrop / inch) + "\", Max: " + Math.floor(maxDrop / inch) + "\".");
		}
		
	});

	// Run the calculate price script on button click

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

	// Submit on return

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

	// Handle the options before adding to basket

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


	// // // Calculate the pelmet prices // // //

	function calculatePelmetPrice(pricing) {

		// Hide the product pricing area 

		$( "#product-pricing" ).hide();

		// CM and Inch conversions

		if ( $( "#measurements input:checked" ).hasClass('CM') ) {
			// CM
			var size = {
			    pelmetWidth : parseFloat( $( "#pelmet-width input" ).val().replace(/[^0-9.,]/g, '') ),
			    pelmetDrop : parseFloat( $( "#pelmet-drop input" ).val().replace(/[^0-9.,]/g, '') ),
			};
		}else{
			// INCH
			var size = {
			    pelmetWidth : parseFloat( $( "#pelmet-width input" ).val().replace(/[^0-9.,]/g, '') * inch ),
			    pelmetDrop : parseFloat( $( "#pelmet-drop input" ).val().replace(/[^0-9.,]/g, '') * inch ),
			};
		}

		// Form Validation

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

		var valid = true;

		if ( !$.isNumeric($( "#pelmet-width input" ).val()) ) {
			$( "#pelmet-width" ).addClass('invalid');
			var valid = false;
		}

		if ( !$.isNumeric($( "#pelmet-drop input" ).val()) ) {
			$( "#pelmet-drop" ).addClass('invalid');
			var valid = false;
		}

		if ( !pricing.pelmetStyle ) {
			$( "#product-style" ).addClass('invalid');
			valid = false;
		}

		if ( !pricing.liningPrice ) {
			$( "#product-lining" ).addClass('invalid');
			valid = false;
		}

		if ( size.pelmetWidth &gt; maxWidth || size.pelmetWidth &lt; minWidth ) {
			$( "#pelmet-width" ).addClass('invalid');
			valid = false;
		}
		if ( size.pelmetDrop &gt; maxDrop || size.pelmetDrop &lt; minDrop ) {
			$( "#pelmet-drop" ).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,
			};
			
			// Set the pelmet variables from product attributes

			var pelmet = {
			    hem : Number(product_data.hem),
			    projection : Number(product_data.projection),
			    round : Number(product_data.round)
			};

			// // // Calculate the number of fabric units // // //

			// Calculate the number of vertical units (unitsY)

			pricing.unitsY = Math.ceil( ( size.pelmetDrop + pelmet.hem ) / fabric.patternRepeat );

			// Calculate the number of horizontal units (unitsX)


			if(pricing.pelmetStyle == "Both Sides"){
				size.pelmetWidth += pelmet.projection * 2;
			}else if(pricing.pelmetStyle == "Left Side Only"){
				size.pelmetWidth += pelmet.projection;
			}else if(pricing.pelmetStyle == "Right Side Only"){
				size.pelmetWidth += pelmet.projection;
			}

			console.log(size.pelmetWidth);

			pricing.unitsX = 1;
			pricing.unitsXDecimal = ( size.pelmetWidth / fabric.fabricWidth ).toFixed(3);
			pricing.unitsX = Math.ceil( pricing.unitsXDecimal );

			// Get the unit price and quantities from the attributes

			pricing.unitPrice = fabric.fabricPrice * fabric.patternRepeat / 100;
			pricing.unitQuantity = pricing.unitsY * pricing.unitsX;
			pricing.totalLiningUnits = pricing.unitsX * Math.ceil( ( size.pelmetDrop + pelmet.hem ) / 10 );
			pricing.makeupQuantity = Math.ceil(size.pelmetDrop / 5);

			// Select the makeup price

			if(size.pelmetDrop &lt;= 30){
				setMakeupPrice('30');
			}else if(size.pelmetDrop &lt;= 46){
				setMakeupPrice('46');
			}else{
				setMakeupPrice('61');
			}

			function setMakeupPrice(drop){
				$( '#make-up-price').find('input').prop( "checked", false );
				$( '#make-up-price .option_name:contains(' + drop + ')' ).parent().find('input').prop( "checked", true );
				var makeupPrice = $( '#make-up-price .option_name:contains(' + drop + ')' ).next('.option_price').html().split("Â£");
				pricing.makeupPrice = makeupPrice[1];
			}

			// Calculate the total price for customer

			pricing.totalFabricPrice = (pricing.unitPrice * pricing.unitQuantity).toFixed(2);
			pricing.totalMakeupPrice = (pricing.makeupQuantity * pricing.makeupPrice).toFixed(2);
			pricing.totalLiningPrice = (pricing.liningPrice * pricing.totalLiningUnits).toFixed(2);
			pricing.totalInteriningPrice = (pricing.interliningPrice * pricing.totalLiningUnits).toFixed(2);
			pricing.totalPrice = (
				+pricing.totalFabricPrice +
				+pricing.totalMakeupPrice +
				+pricing.totalLiningPrice +
				+pricing.totalInteriningPrice).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;
			}

			// Update the product page with pricing information

			$( "#unitQuantity" ).html(pricing.unitQuantity);
			$( "#unitPrice" ).html(pricing.unitPrice);
			$( "#makeupQuantity" ).html(pricing.unitsX);
			$( "#makeupPrice" ).html(pricing.makeupPrice);
			$( "#liningQuantity" ).html(pricing.totalLiningUnits);
			$( "#liningPrice" ).html(pricing.liningPrice);
			$( "#interliningQuantity" ).html(pricing.totalLiningUnits);
			$( "#interliningPrice" ).html(pricing.interliningPrice);
			$( "#eyeletQuantity" ).html(pricing.unitsX);
			$( "#eyeletPrice" ).html(pricing.eyeletPrice);
			$( "#input-unit-quantity" ).val(pricing.unitQuantity);
			$( "#totalPrice" ).html(totalPriceText);

			if (debug) { console.log(pricing); }

			// If discounted calculate and show price before discount
			
			if ( attributes.discount ){
				pricing.priceBeforeDiscount = (pricing.totalPrice * ( 1 + (attributes.discount/100) )).toFixed(2);
				$( "#discountPercent" ).html(attributes.discount);
				$( "#priceBeforeDiscount" ).html(pricing.priceBeforeDiscount);
				$( "#product-discount" ).show();
			}

			// Reveal the product pricing area 

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

				// Setup Worksheet Data
				worksheet.fabricLength = pricing.unitsY * fabric.patternRepeat;
				worksheet.widths = pricing.unitsX;
				worksheet.totalFabricPrice = pricing.totalFabricPrice;
				worksheet.totalLiningPrice = pricing.totalLiningPrice;
				worksheet.totalInteriningPrice = pricing.totalInteriningPrice;
				$( "#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');
	    }
	    return price;
	}

	function controlOptions(pricing) {

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

		// Fabric unit checkboxes
		for (i = 1; i &lt; pricing.unitQuantity; i++) {
			var checked = $( "#product-style .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}

		// Make up price checkboxes
		$("#make-up-price input:checked").parent().parent().addClass("checked");
		for (i = 1; i &lt; pricing.makeupQuantity; i++) {
			var checked = $( "#make-up-price .checkbox.checked" );
			$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
		}

		// Lining checkboxes
		if ( pricing.liningPrice &gt; 0 ) {
			for (i = 1; i &lt; pricing.totalLiningUnits; i++) {
				var checked = $( "#product-lining .checkbox.checked" );
				$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
			}
		}

		// Interining checkboxes
		if ( pricing.interliningPrice &gt; 0 ) {
			for (i = 1; i &lt; pricing.totalLiningUnits; i++) {
				var checked = $( "#product-interlining .checkbox.checked" );
				$( checked ).clone().insertAfter( checked ).removeClass('checked').addClass('clone');
			}
		}

	}

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