function updateAllOverCovers(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchID =  getRadioFieldValue('allOverCoverFabric');
	$fabricName = 'Bolero';
	$swatchName = ($swatchID == 15) ? 'Black' : 'Chocolate';
	$fabricName = $fabricName +' '+ $swatchName;
	
	//console.debug($swatchID);
	//get the chosen fit option - simple or standard fit
	$fitOption =  getRadioFieldValue('allOverCoverFitType');
	
	$fitOptionText = ($fitOption == 0) ? 'Standard Fit' : 'Premier Fit';
	
	//how many covers
	$sofaQTY = $form['allOverCoverQtySofa'].value;
	$chairQTY = $form['allOverCoverQtyChair'].value;
	
	$currentCount =	parseInt($('basketCount').innerHTML);
	
	//console.debug($sofaQTY+' '+$chairQTY);
	sofaUpdateObject = {'currentCount' : $currentCount , 'qty' : $sofaQTY , 'product' : 8, 'productDescription' : 'All Over Sofa Covers' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : parseInt($fitOption)+1, 'fitOptionText' : $fitOptionText};
	if($sofaQTY !=0) $currentCount++;
	chairUpdateObject = {'currentCount' : $currentCount , 'qty' : $chairQTY , 'product' : 11, 'productDescription' : 'All Over Chair Covers' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : parseInt($fitOption)+1, 'fitOptionText' : $fitOptionText};

	$allOverCoverLine = [sofaUpdateObject , chairUpdateObject];
	//console.debug($allOverCoverLine);
	
	setAllOverCoverOptionList($allOverCoverLine);
	
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	updateAllOverCoverPrice($allOverCoverLine,checkoutSave);

}

function setAllOverCoverOptionList($allOverCoverLine){
	$sofaUpdateObject = $allOverCoverLine[0];
	$chairUpdateObject = $allOverCoverLine[1];
	
	$fabricName = $sofaUpdateObject.fabric;
	$colour = $sofaUpdateObject.swatchName;
	$fitOptionText = $sofaUpdateObject.fitOptionText;
	
	$('allOverCoverName').innerHTML = 'All Over Cover';
	$('allOverCoverFabricText').innerHTML = $fabricName+' fabric';
	$('allOverCoverColor').innerHTML = $colour;
	$('allOverCoverFit').innerHTML = $fitOptionText;
	
	$qtyString = ($sofaUpdateObject.qty!=0) ? $sofaUpdateObject.qty+' x '+$sofaUpdateObject.productDescription+'<br/>' : '';
	
	$qtyString += ($chairUpdateObject.qty!=0) ? $chairUpdateObject.qty+' x '+$chairUpdateObject.productDescription : '';
	$('allOverCoverQuantities').innerHTML = $qtyString;
}

function updateAllOverCoverPrice($allOverCoverLine,checkoutSave){
		pars = 'array='+$allOverCoverLine.toJSON();
		if(checkoutSave == true){ 
			pars += '&save=true';
		}
		 new Ajax.Request('/checkout/getPrice', {method:'post', parameters : pars , onSuccess : function(transport) { 
																					 prices = eval('(' + transport.responseText + ')');
																					 $conversionRate = $('conversionRate').value;
																					 $currencySymbol = $('currencySymbol').value;
																					 $('allOverCoverPriceFull').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate);
																					 $('allOverCoverPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate);
																					 if(checkoutSave == true){
																						 //addPriceToCheckoutTotal(prices.discountPrice);
																						 writeBasketLink($allOverCoverLine[0]);
																				 		 writeBasketLink($allOverCoverLine[1]);
																					 }
																				 } 
											});
}




function scatterCushionSwatchSet($swatchId)
{
	$('scatterCushionFabricFront'+$swatchId).checked = true;
	$swatchImage = ($('scatterCushionFabricFrontImage'+$swatchId)) ? $('scatterCushionFabricFrontImage'+$swatchId).src : '';
	$('swatchBackChosenFabric').src = $swatchImage;
	$('swatchFrontChosenFabric3').src = $swatchImage;

	$swatchName = jQuery("input[name='scatterCushionFabricFront']:checked").val();
	$('scatterCushionFrontSelected').innerHTML = $swatchName;//$('fabricSwatchName'+$swatchId).innerHTML;

	new Effect.SlideUp('scatterCushionSwatchFront');
	new Effect.SlideDown('scatterCushionSwatchBack', { queue: 'end' });	
}

function scatterCushionBackSet(fabric)
{
	if(fabric!=''){
			$('scatterCushionBack'+fabric).checked = 'checked';
			$backSource = $('scatterCushionFabricBack'+fabric).src
			$('swatchBackChosenFabric3').src = $backSource;
			new Effect.SlideUp('scatterCushionSwatchBack');
			new Effect.SlideDown('scatterCushionSwatch3', { queue: 'end' });
			//updateScatterCusionCovers();
	}
	else{
		$('scatterCushionSwatch3').style.display = 'none';
		new Effect.SlideDown('scatterCushionSwatchBack');
	}
	
}

function scatterCushionSwatchUnset(){
	$('scatterCushionSwatch3').style.display = 'none';
	new Effect.SlideUp('scatterCushionSwatchBack');
	new Effect.SlideDown('scatterCushionSwatchFront', { queue: 'end' });
}



function updateInfillCushions(section,addToCheckout)
{
	$form = $('accessoriesOrderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  '100 percent Polyester';
	$swatchID = 63;
	
	
	//get the chosen fit option - 6 sizes
	$scatterCushionLine = [];
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	

	if(section != 'accessories-pipe-scatter-cushions')
	{
		$cubaBackswatchName = jQuery("input[name='scatterCubaBack']:checked").val();
		$cubaBackswatchID = jQuery("input[name='scatterCubaBack']:checked").attr('id').replace('scatterCushionBack','');;
		$cubaBack =  $cubaBackswatchName;
		$fabricName = $swatchName+' '+$cubaBack+' on reverse';
	}
	else
	{
		$fabricName = $swatchName;
	}
	
	jQuery('.infill_cushion_qty',jQuery('#'+section)).each(function() { 
											
					$qty = jQuery(this).val();//$($fieldID).value;
					$fitOption =  jQuery('.'+jQuery(this).attr('id') + 'Fit').val()
				
					$fitOptionText = jQuery(this).attr('title'); //$($fieldID).name;		 
					
					scatterUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 18, 'productDescription' : 'Cushion Infill Pads' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption, 'fitOptionText' : $fitOptionText};
					$scatterCushionLine[$scatterCushionLine.length] = scatterUpdateObject;
					$currentCount++;
					
												   })
	
	//setScatterCushionList($scatterCushionLine);
    checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	updateInfillCushionsPrice($scatterCushionLine,checkoutSave,section);		
	
}

function updateInfillCushionsPrice($infillCushionLine,checkoutSave,section)
{
	pars = 'array='+ jQuery.toJSON($infillCushionLine);
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);

	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	for($i = 0; $i < $infillCushionLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($infillCushionLine[$i].qty);
	}
	
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	
	$parent = jQuery('#'+section)

	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery(".typeOption:checked", jQuery('.cushionInfillStyle', jQuery($parent))).parent().parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery(".typeOption:checked", jQuery('.cushionInfillStyle', jQuery($parent))).parent().parent()).attr('src').replace(/54x41/,'100x76') })
	jQuery('.fitOption').html('');	
	
	
	jQuery('.qty:gt(0)').remove();

	
	jQuery('.infill_cushion_qty',jQuery('#'+section)).each(function() { 
	
		if(jQuery(this).val() > 0)
		{
			$newRow = jQuery('.qty:eq(0)').clone()
			jQuery('strong', jQuery($newRow)).html(jQuery(this).val());
			jQuery('span', jQuery($newRow)).html(jQuery(this).attr('title'));	
			jQuery('.fitOption').before($newRow)
		}
		
	})
	jQuery('.qty:eq(0)').remove();
	
	jQuery('.price', jQuery('.pricePanelLarge',jQuery('.cushionInfillStyle', jQuery('#'+section)))).html($currencySymbol+prices.discountPrice);
	
}

function throwSwatchSet($swatchId)
{
	$('throwFabricFront'+$swatchId).checked = true;
	$swatchImage = ($('throwFabricFrontImage'+$swatchId)) ?  $('throwFabricFrontImage'+$swatchId).src : '';
	jQuery('#swatchFrontChosenFabricThrow').attr({'src': $swatchImage })
	jQuery('#swatchFrontChosenFabricThrow2').attr({'src': $swatchImage })
		
	new Effect.SlideUp('throwSwatchFront');
	new Effect.SlideDown('throwSwatchBack', { queue: 'end' });
}

function throwBackSet(fabric)
{
	if(fabric!='')
	{
		$('throwBack'+fabric).checked = 'checked';
		$backSource = $('throwFabricBack'+fabric).src
		$('swatchBackChosenFabricThrow').src = $backSource;
		new Effect.SlideUp('throwSwatchBack');
		new Effect.SlideDown('throwSwatch3', { queue: 'end' });
	}
	else
	{
		$('throwSwatch3').style.display = 'none';
		new Effect.SlideDown('throwSwatchBack');
	}
}

function throwSwatchUnset()
{
	$('throwSwatch3').style.display = 'none';
	new Effect.SlideUp('throwSwatchBack');
	new Effect.SlideDown('throwSwatchFront', { queue: 'end' });
}

function updateThrows(addToCheckout)
{
	$swatchName = jQuery("input[name='throwFabricFront']:checked").val();
	$swatchID = jQuery("input[name='throwFabricFront']:checked").attr('id').replace('throwFabricFront','');;
	$qty = jQuery('.padded_throw_qty', jQuery('.paddedThrowStyle')).val();
	
	$cubaBack = jQuery("input[name='throwCubaBack']:checked").val();
	
	
//	$qty = 1;
	$fabricName = $swatchName+' '+$cubaBack +' on reverse';
	
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	$fitOptionText  = '56" x 52"';
	$throwLine = [];
	$description = 	'Padded Throw';
	throwUpdateObject = {'currentCount' : parseInt($('basketCount').innerHTML), 'qty' : $qty , 'product' : 6, 'productDescription' : $description , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$throwLine[$throwLine.length] = throwUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updateThrowPrice($throwLine,checkoutSave);
}

function updateThrowPrice($throwLine,checkoutSave)
{

	pars = 'array='+ jQuery.toJSON($throwLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	
	for($i = 0; $i < $throwLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($throwLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)//fullPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}
	
	
	$parent = jQuery('#accessories-padded-throw')
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[name='throwFabricFront']:checked", jQuery($parent)).parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[name='throwFabricFront']:checked", jQuery($parent)).parent()).attr('src').replace(/55x40/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
	jQuery('.qty:gt(0)').remove();
	jQuery('strong', jQuery('.qty')).html(jQuery('.calcPrice',	jQuery($parent)).val());
	jQuery('span', jQuery('.qty')).html('Padded Throws');
			
			



	
	jQuery('.price', jQuery('.pricePanelLarge', jQuery('.paddedThrowStyle', jQuery('#accessories-padded-throws')))).html($currencySymbol+prices.discountPrice)//fullPrice);

}


function updateArmThrows(addToCheckout)
{
	$swatchName = jQuery("input[name='paddedArmFabric']:checked").val();
	$swatchID = jQuery("input[name='paddedArmFabric']:checked").attr('id').replace('paddedArmFabric','');
	$qty = jQuery('.arm_throw_qty', jQuery('.armThrowStyle')).val();
	
//	$qty = 1;
	$fabricName = $swatchName;
	
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	$fitOptionText  = '10" x 30"';
	$throwLine = [];
	$description = 	'Padded Arm Throw';
	throwUpdateObject = {'currentCount' : parseInt($('basketCount').innerHTML), 'qty' : $qty , 'product' : 12, 'productDescription' : $description , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$throwLine[$throwLine.length] = throwUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updateArmThrowPrice($throwLine,checkoutSave)
}

function updateArmThrowPrice($footstoolLine,checkoutSave)
{
	pars = 'array='+ jQuery.toJSON($footstoolLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	for($i = 0; $i < $footstoolLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($footstoolLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	$parent = jQuery('#accessories-arm-throw')
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('src').replace(/63x50/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
	jQuery('.qty:gt(0)').remove();
	jQuery('strong', jQuery('.qty')).html(jQuery('.calcPrice',	jQuery($parent)).val());
	jQuery('span', jQuery('.qty')).html('Padded Throws');
			
			

	
	jQuery('.price', jQuery('.pricePanelLarge', jQuery('.armThrowStyle' ,jQuery('#accessories-padded-throws')))).html($currencySymbol+prices.discountPrice);
}


function updateLooseCushionsNew(addToCheckout)
{
	$form = $('accessoriesOrderForm');
	
	$swatchName = jQuery("input[name='scatterCushionFabric']:checked").val();
	$swatchID = jQuery("input[name='scatterCushionFabric']:checked").attr('id').replace('scatterCushionFabric','');;
	$qty = jQuery('#quantitySelect', jQuery('#accessories-pipe-scatter-cushions')).val();
	
//	$qty = 1;
	$fabric = $swatchName;
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	$fitOptionText  = ' ';
	$footstoolLine = [];
	$description = 	'Piped Scatter Cushion Covers';
	footstoolUpdateObject = {'currentCount' : parseInt($('basketCount').innerHTML) , 'qty' : $qty , 'product' : 9, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$footstoolLine[$footstoolLine.length] = footstoolUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updateLooseCushionPriceNew($footstoolLine,checkoutSave);					
}

function updateLooseCushionPriceNew($throwLine,checkoutSave)
{
	pars = 'array='+ jQuery.toJSON($footstoolLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	for($i = 0; $i < $footstoolLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($footstoolLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	jQuery('.price', jQuery('.pricePanel',jQuery('#accessories-pipe-scatter-cushions'))).html($currencySymbol+prices.discountPrice);
}

function updateLooseCushions(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('looseSeatFabric');
	$swatchID = getRadioFieldId('looseSeatFabric').replace('looseSeatFabric','');
		
	
	//get the chosen fit option - 6 sizes
	$throwLine = [];
	$qtyFields = new Array('looseSeatQTYSeat');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$fabricName = $swatchName;
	//return false;
	for($i = 0; $i<$qtyFields.length; $i++){
		$fitOptionText = ($fitOption == 0) ? 'Standard Fit' : 'Premier Fit';
		//console.debug($qtyFields[$fieldID ]);
		$fieldID = $qtyFields[$i];
		
		if($($fieldID).value!='' && $($fieldID).value!=0){
					$description = 	($i == 0) ? 'Loose Seat Cushions' : 'Loose Back Cushions';
					$fitOptionText  = '40" square';
					
					$qty = $($fieldID).value;
					throwUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 7, 'productDescription' : $description , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
					$throwLine[$throwLine.length] = throwUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	//console.debug($throwLine);
	setLooseCushionList($throwLine);
	
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updateLooseCushionPrice($throwLine,checkoutSave);

}
function updateLooseCushionPrice($throwLine,checkoutSave){

			pars = 'array='+$throwLine.toJSON();
		if(checkoutSave == true){ 
			pars += '&save=true';

			
		}
		//console.debug($throwLine);
		//return false;
		 new Ajax.Request('/checkout/getPrice', {method:'post', parameters : pars , onSuccess : function(transport) { 
																					 prices = eval('(' + transport.responseText + ')');
																					 $conversionRate = $('conversionRate').value;
																					 $currencySymbol = $('currencySymbol').value;
																					 
																					 if(prices.priceFull == prices.priceDiscount){
																						 $('looseSeatWas').style.visibility = 'hidden';
																						 $$('#looseSeatSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																					 }
																					 $('looseSeatPriceFull').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate,2);
																					 $('looseSeatPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate,2);
																					 if(checkoutSave == true){
																						 //addPriceToCheckoutTotal(prices.discountPrice);
																						for($i = 0; $i<$throwLine.length; $i++){
																							writeBasketLink($throwLine[$i]);
																						}
																					 }
																				 } 
											});

}

function setLooseCushionList($throwLine){
	//console.debug($throwLine);
	$('looseSeatProductOpt').innerHTML = '';
	for($i = 0; $i<$throwLine.length; $i++){
		$('looseSeatProductOpt').innerHTML += $throwLine[$i].qty +' x '+$throwLine[$i].fitOptionText+'<br/>';
		$fabricName = $throwLine[$i].fabric.split(' - ');
		//$('looseSeatFabricChoice').innerHTML = $throwLine[$i].swatchName;
	}

	
	$('scatterFabricColour').innerHTML = $fabricName[1];
		
}

function updateScatterCusionCovers(addToCheckout)
{
	$form = $('accessoriesOrderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName = jQuery("input[name='scatterCushionFabricFront']:checked").val();
	$swatchID = jQuery("input[name='scatterCushionFabricFront']:checked").attr('id').replace('scatterCushionFabricFront','');
	
	
	$scatterCushionLine = [];
	$qtyFields = new Array('scatterCushionQTY16','scatterCushionQTY18','scatterCushionQTY20','scatterCushionQTY25','scatterCushionQTYOblong');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	//$cubaBack =  getRadioFieldValue('scatterCubaBack');
	$cubaBackswatchName = jQuery("input[name='scatterCubaBack']:checked").val();
	$cubaBackswatchID = jQuery("input[name='scatterCubaBack']:checked").attr('id').replace('scatterCushionBack','');
	$cubaBack =  $cubaBackswatchName;
	$fabricName = $swatchName+' '+$cubaBack+' on reverse';
	jQuery('.scatter_cushion_qty').each(function() { 
											
					$qty = jQuery(this).val();//$($fieldID).value;
					$fitOptionText = jQuery(this).attr('title'); //$($fieldID).name;		 
					$fitOption =  jQuery('.'+jQuery(this).attr('id') + 'Fit').val()
				
					scatterUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 5, 'productDescription' : 'Double sided cushion covers' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption, 'fitOptionText' : $fitOptionText};
					$scatterCushionLine[$scatterCushionLine.length] = scatterUpdateObject;
					$currentCount++;
											
												   })
	
	//setScatterCushionList($scatterCushionLine);
    checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	updateScatterCushionPrice($scatterCushionLine,checkoutSave);		
	
}

function updateScatterCushionPrice($scatterCushionLine,checkoutSave)
{	 
	pars = 'array='+ jQuery.toJSON($scatterCushionLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);

	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	
	for($i = 0; $i < $scatterCushionLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($scatterCushionLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	
	$parent = jQuery('#accessories-double-sided-cushions')
	
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[name='scatterCushionFabricFront']:checked", jQuery($parent)).parent().parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[name='scatterCushionFabricFront']:checked", jQuery($parent)).parent().parent()).attr('src').replace(/55x40/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
		
	
	
	jQuery('.qty:gt(0)').remove();
	
	jQuery('.scatter_cushion_qty').each(function() { 
	
		if(jQuery(this).val() > 0)
		{
			$newRow = jQuery('.qty:eq(0)').clone()
			jQuery('strong', jQuery($newRow)).html(jQuery(this).val());
			jQuery('span', jQuery($newRow)).html(jQuery(this).attr('title'));	
			jQuery('.fitOption').before($newRow)
		}
		
	})
	jQuery('.qty:eq(0)').remove();
	
	
	
	
	jQuery('.price', jQuery('.pricePanelLarge',jQuery('.cushionBackStyle', jQuery('#accessories-double-sided-cushions')))).html($currencySymbol+prices.discountPrice);

}

function updatePipedCushions(addToCheckout)
{
	$form = $('accessoriesOrderForm');
	
	$swatchName = jQuery("input[name='pipeCushionFabric']:checked").val();
	$swatchID = jQuery("input[name='pipeCushionFabric']:checked").attr('id').replace('pipeCushionFabric','');;
	$qty = jQuery('#quantitySelect', jQuery('#accessories-pipe-scatter-cushions')).val();
	
//	$qty = 1;
	$fabric = $swatchName;
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	$fitOptionText  = ' ';
	$footstoolLine = [];
	$description = 	'Piped Scatter Cushion Covers';
	footstoolUpdateObject = {'currentCount' : parseInt($('basketCount').innerHTML) , 'qty' : $qty , 'product' : 9, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$footstoolLine[$footstoolLine.length] = footstoolUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updatePipedCushionPrice($footstoolLine,checkoutSave);					
}

function updatePipedCushionPrice($footstoolLine,checkoutSave)
{
	pars = 'array='+ jQuery.toJSON($footstoolLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	for($i = 0; $i < $footstoolLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($footstoolLine[$i].qty);
	}
	
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	
	
	$parent = jQuery('#accessories-pipe-scatter-cushions')
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('src').replace(/54x41/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
	jQuery('.qty:gt(0)').remove();
	jQuery('strong', jQuery('.qty')).html(jQuery('.calcPrice',	jQuery($parent)).val());
	jQuery('span', jQuery('.qty')).html('Scatter Cushions');
	
	jQuery('.price', jQuery('.pricePanel',jQuery('.cushionBackStyle', jQuery('#accessories-pipe-scatter-cushions')))).html($currencySymbol+prices.discountPrice);
}


function updatePipedArmCovers(addToCheckout)
{
	$form = $('accessoriesOrderForm');
	
	$swatchName = jQuery("input[name='armCushionFabric']:checked").val();
	$swatchID = jQuery("input[name='armCushionFabric']:checked").attr('id').replace('armCushionFabric','');;
	$qty = jQuery('#quantitySelect', jQuery('#accessories-arm-covers')).val();
	
//	$qty = 1;
	$fabric = $swatchName;
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	$fitOptionText  = ' ';
	$footstoolLine = [];
	$description = 	'Piped Scatter Cushion Covers';
	footstoolUpdateObject = {'currentCount' : 0 , 'qty' : $qty , 'product' : 14, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$footstoolLine[$footstoolLine.length] = footstoolUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	
	updatePipedArmCoverPrice($footstoolLine,checkoutSave);					
}
											   
function updatePipedArmCoverPrice($cushionLine,checkoutSave)
{
	pars = 'array='+ jQuery.toJSON($footstoolLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	
	for($i = 0; $i < $footstoolLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($footstoolLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	


	
	$parent = jQuery('#accessories-arm-covers')
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('src').replace(/54x41/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
	jQuery('.qty:gt(0)').remove();
	jQuery('strong', jQuery('.qty')).html(jQuery('.calcPrice',	jQuery($parent)).val());
	jQuery('span', jQuery('.qty')).html('Piped Arm Covers');

	jQuery('.price', jQuery('.pricePanel',jQuery('#accessories-arm-covers'))).html($currencySymbol+prices.discountPrice);
} 

function updateFootstool(addToCheckout)
{
	$form = $('accessoriesOrderForm');
	
	$swatchName = jQuery("input[name='footstoolFabric']:checked").val();
	$swatchID = jQuery("input[name='footstoolFabric']:checked").attr('id').replace('footstoolFabric','');;
	$qty = jQuery('#quantitySelect', jQuery('#accessories-footStoolCover')).val();
	
//	$qty = 1;
	$fabric = $swatchName;
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  =  jQuery("input[name='footstoolOption']:checked").val();
	
	if($fitOption == 2)
	{
		jQuery('#simpleStyle').hide();
		jQuery('#valanceStyle').show();
	}
	else
	{
		jQuery('#simpleStyle').show();
		jQuery('#valanceStyle').hide();
	}
	$fitOptionArray = new Array('Simple Style', 'Valance Style', 'Cotton and Cotton feel Range');
	$fitOptionText = $fitOptionArray[$fitOption];
	$footstoolLine = [];
	$description = 	'Footstool Covers';
	footstoolUpdateObject = {'currentCount' : 0 , 'qty' : $qty , 'product' : 15, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
	$footstoolLine[$footstoolLine.length] = footstoolUpdateObject;
	$currentCount++;	
	//setFootstooloverList($footstoolLine);
	checkoutSave = (addToCheckout==undefined) ? false : addToCheckout;
	jQuery('.description',jQuery('#accessories-footStoolCover')).val('sss')
	updateFootstoolPrice($footstoolLine,checkoutSave);				
}

function updateFootstoolPrice($footstoolLine,checkoutSave)
{
	pars = 'array='+ jQuery.toJSON($footstoolLine);
	
	if(checkoutSave == true){ 
		pars += '&save=true';
	}
	
	var html = jQuery.ajax({ 
					type: "POST",
					url: '/checkout/getPrice',
					async: false,
					data: pars	
				}).responseText;	
 	
	eval("prices = "+ html);
	
	$conversionRate = $('conversionRate').value;
	$currencySymbol = $('currencySymbol').value;
	additionalQty = 0
	for($i = 0; $i < $footstoolLine.length; $i++)
	{
		additionalQty = additionalQty + parseInt($footstoolLine[$i].qty);
	}
	
	if(checkoutSave == true)
	{ 
		//addPriceToCheckoutTotal(prices.discountPrice);
		new Ajax.Updater('stage4basketSummary', '/checkout/stage4BasketSummary');
	
		jQuery('#basketCount').html( parseInt(jQuery('#basketCount').html()) + additionalQty);
		//currentPrice = jQuery('#priceValue').html().replace(',','').substring(1, jQuery('#priceValue').html().length);
		
		//currentPrice = parseFloat(currentPrice) + parseFloat(prices.discountPrice)
		//jQuery('#priceValue').html($currencySymbol+currentPrice)
	}	
	
	$parent = jQuery('#accessories-footStoolCover')
	jQuery('.swatchName', jQuery('.basketOverlayWrapper')).html(jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('alt').replace(/-/, ' - '));
	jQuery('.detailImage', jQuery('.basketOverlayWrapper')).attr({'src': jQuery('img',jQuery("input[class='swatchRadio']:checked", jQuery($parent)).parent()).attr('src').replace(/54x41/,'100x76') })
	jQuery('.fitOption').html(jQuery(".typeOption:checked", jQuery($parent)).attr('title'));	
	jQuery('.qty:gt(0)').remove();
	jQuery('strong', jQuery('.qty')).html(jQuery('.calcPrice',	jQuery($parent)).val());
	jQuery('span', jQuery('.qty')).html('Footstool Covers');
			
			
	jQuery('.price', jQuery('.pricePanel',jQuery('#accessories-footStoolCover'))).html($currencySymbol+prices.discountPrice);
	
}

function changeTab(section)
{
	jQuery('.openCloseClosed:not(#'+section+')').hide();
	jQuery('#'+section).show();	
	if(jQuery('#'+section+'-tab',jQuery('.accessoriesNav')).is('.current'))
	{
		
	}
	else
	{
		jQuery('li',jQuery('.accessoriesNav')).removeClass('current');
		jQuery('#'+section+'-tab',jQuery('.accessoriesNav')).addClass('current');
		
	}
	
	
}

function getRadioFieldValue(radioGroupName){
	
	$form = $('orderForm');
	//console.debug($form.getInputs('radio',radioGroupName));
	
	//if no radio buttin at all is checked this throws an error so catch it
	try{
		var $value = $form.getInputs('radio',radioGroupName).find(function(radio) { return radio.checked; }).value;
	}
	catch (e){
			$value = '';
	}
	return $value;

}

function getRadioFieldId(radioGroupName){
	
	$form = $('orderForm');
	//console.debug($form.getInputs('radio',radioGroupName));
	
	//if no radio buttin at all is checked this throws an error so catch it
	try{
		var $value = $form.getInputs('radio',radioGroupName).find(function(radio) { return radio.checked; }).id;
	}
	catch (e){
			$value = '';
	}
	return $value;

}

function addPriceToCheckoutTotal(price){
		//console.debug('stuff');
	/*	conversionRate = $('conversionRate').value;
		currencySymbol = $('currencySymbol').value;
		
		oldPrice =  parseInt($('priceValue').innerHTML.replace(currencySymbol,''));
		price = price*conversionRate;
		price+= oldPrice;
		$('priceValue').innerHTML = currencySymbol+Math.round(price);
*/
}

