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.fullPrice * $conversionRate);
																					 $('allOverCoverPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate);
																					 if(checkoutSave == true){
																						 addPriceToCheckoutTotal(prices.discountPrice);
																						 writeBasketLink($allOverCoverLine[0]);
																				 		 writeBasketLink($allOverCoverLine[1]);
																					 }
																				 } 
											});
}



function updateScatterCusionCovers(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('scatterCushionFabricFront');
	$swatchID = getRadioFieldId('scatterCushionFabricFront').replace('scatterCushionFabricFront','');
		
	//console.debug($swatchID);
	//get the chosen fit option - 6 sizes
	$scatterCushionLine = [];
	$qtyFields = new Array('scatterCushionQTY16','scatterCushionQTY18','scatterCushionQTY20','scatterCushionQTY25','scatterCushionQTYOblong');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$cubaBack =  getRadioFieldValue('scatterCubaBack');
	$fabricName = $swatchName+' '+$cubaBack+' on reverse';
	
	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){
					
					$qty = $($fieldID).value;
					$fitOptionText = $($fieldID).name;
					scatterUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 5, 'productDescription' : 'Double sided cushion covers' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption+1, 'fitOptionText' : $fitOptionText};
					$scatterCushionLine[$scatterCushionLine.length] = scatterUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	
	
	setScatterCushionList($scatterCushionLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	updateScatterCushionPrice($scatterCushionLine,checkoutSave);

}

function updateScatterCushionPrice($scatterCushionLine,checkoutSave){
			pars = 'array='+$scatterCushionLine.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;
																					 
																					 if(prices.fullPrice == prices.discountPrice){
																						 $('scatterCushionPriceWas').style.visibility = 'hidden';
																						 $$('#scatterCushionPriceSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																						 if(prices.fullPrice == prices.discountPrice){
																						 $('scatterCushionPriceWas').style.visibility = 'visible';
																						 $$('#scatterCushionPriceSale .priceLabel')[0].innerHTML = 'Sale Price';
																					 }
																					 }
																					 $('scatterCushionPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate);
																					 $('scatterCushionPriceFigure').innerHTML = $currencySymbol+(prices.discountPrice * $conversionRate).toFixed(2);
																					 
																					 if(checkoutSave == true){
																						 addPriceToCheckoutTotal(prices.discountPrice);
																			 			for($i = 0; $i<$scatterCushionLine.length; $i++){
																							writeBasketLink($scatterCushionLine[$i]);
																						}
																					 }
																				 } 
											});

}

function setScatterCushionList($scatterCushionLine){
	$('leatherDoubleProductOpt').innerHTML = '';
	for($i = 0; $i<$scatterCushionLine.length; $i++){
		$('leatherDoubleProductOpt').innerHTML += $scatterCushionLine[$i].qty +' x '+$scatterCushionLine[$i].fitOptionText+'<br/>';
	}
	$('leatherDoubleFabricColour').innerHTML = $scatterCushionLine[0].swatchName;
	$cubaBack =  getRadioFieldValue('scatterCubaBack');
	$('leatherDoubleFabricChoiceBack').innerHTML = $cubaBack+' on reverse'; 

}

function scatterCushionSwatchSet($swatchId) {
	//console.debug('infunction with swatchId '+$swatchId);
	//$(scatterCushionSwatchBack);
	$('scatterCushionFabricFront'+$swatchId).checked = true;
	$swatchImage = ($('scatterCushionFabricFrontImage'+$swatchId)) ? $('scatterCushionFabricFrontImage'+$swatchId).src : '';
	$('swatchBackChosenFabric').src = $swatchImage;
	$('swatchFrontChosenFabric3').src = $swatchImage;

	$('scatterCushionFrontSelected').innerHTML = $('fabricSwatchName'+$swatchId).innerHTML;
	
	updateScatterCusionCovers();
	
	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(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  '100 percent Polyester';//getRadioFieldValue('scatterCushionFabricFront');
	//$swatchID = getRadioFieldId('scatterCushionFabricFront').replace('scatterCushionFabricFront','');
	$swatchID = 63;
	
	//console.debug($swatchID);
	//get the chosen fit option - 6 sizes
	$infillCushionLine = [];
	$qtyFields = new Array('infillCushionQTY16','infillCushionQTY18','infillCushionQTY20','infillCushionQTY25','infillCushionQTYOblong');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$fabricName = $swatchName;
	
	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){
					
					$qty = $($fieldID).value;
					$fitOptionText = $($fieldID).name;
					infillUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 18, 'productDescription' : 'Cushion Infill Pads' , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption+1, 'fitOptionText' : $fitOptionText};
					$infillCushionLine[$infillCushionLine.length] = infillUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	
	
	setInfillCushionList($infillCushionLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	
	updateInfillCushionsPrice($infillCushionLine,checkoutSave);

}

function updateInfillCushionsPrice($infillCushionLine,checkoutSave){
			pars = 'array='+$infillCushionLine.toJSON();
			//console.debug(pars);
		if(checkoutSave == true){ 
			pars += '&save=true';

			
		}
		//console.debug(pars);
		 new Ajax.Request('/checkout/getPrice', {method:'post', parameters : pars , onSuccess : function(transport) { 
																					 prices = eval('(' + transport.responseText + ')');
																					 $conversionRate = $('conversionRate').value;
																					 $currencySymbol = $('currencySymbol').value;
																					 
																					 if(prices.fullPrice == prices.discountPrice){
																						 	$('infillerWas').style.visibility = 'hidden';
																							$$('#infillerSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																						 	$('infillerWas').style.visibility = 'visible';
																							$$('#infillerSale .priceLabel')[0].innerHTML = 'Sale Price';
																					 }
																					 
																					 $('infillCushionPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate);
																					 $('infillCushionPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate);
																					 if(checkoutSave == true){
																						 addPriceToCheckoutTotal(prices.discountPrice);
																						for($i = 0; $i<$infillCushionLine.length; $i++){
																							writeBasketLink($infillCushionLine[$i]);
																						}
																					 }
																				 } 
											});

}

function setInfillCushionList($infillCushionLine){
	$('infillProductOpt').innerHTML = '';
	for($i = 0; $i<$infillCushionLine.length; $i++){
		$('infillProductOpt').innerHTML += $infillCushionLine[$i].qty +' x '+$infillCushionLine[$i].fitOptionText+'<br/>';
	}
	//$('infillFabricColour').innerHTML = $scatterCushionLine[0].swatchName;
}



function throwSwatchSet($swatchId) {
	//console.debug('infunction with swatchId '+$swatchId);
	//$(scatterCushionSwatchBack);
	$('throwFabricFront'+$swatchId).checked = true;
	$swatchImage = ($('throwFabricFrontImage'+$swatchId)) ?  $('throwFabricFrontImage'+$swatchId).src : '';
	$('swatchFrontChosenFabricThrow').src = $swatchImage;
	$('swatchFrontChosenFabricThrow2').src = $swatchImage;
	$('throwFrontSelected').innerHTML = $('fabricSwatchNameThrow'+$swatchId).innerHTML;
	
	updateThrows(false);
	
	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' });
			updateThrows();
	}
	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){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('throwFabricFront');
	$swatchID = getRadioFieldId('throwFabricFront').replace('throwFabricFront','');
		
	//console.debug($swatchID);
	//get the chosen fit option - 6 sizes
	$throwLine = [];
	$qtyFields = new Array('paddedThrowQTY56');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$cubaBack =  getRadioFieldValue('throwCubaBack');
	$fabricName = $swatchName+' '+$cubaBack +' on reverse';
	
	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) ? 'Padded Throw' : 'Padded Arm Throw';
					$fitOptionText  = 	($i == 0) ? '56" x 52"' : '10" x 30"';
					
					$qty = $($fieldID).value;
					throwUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 6, 'productDescription' : $description , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption+1, 'fitOptionText' : $fitOptionText};
					$throwLine[$i] = throwUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	
	
	setThrowList($throwLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	updateThrowPrice($throwLine,checkoutSave);

}
function updateThrowPrice($throwLine,checkoutSave){
			pars = 'array='+$throwLine.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;
																					 
																					 if(prices.fullPrice == prices.discountPrice){
																						 $('throwWas').style.visibility = 'hidden';
																						 $$('#throwSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																						 $('throwWas').style.visibility = 'visible';
																						 $$('#throwSale .priceLabel')[0].innerHTML = 'Sale Price';
																					 
																					 }
																					 
																					 $('throwPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate,2);
																					 $('paddedThrowPriceFigure').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 setThrowList($throwLine){
	//console.debug($throwLine);
	$('throwProductOpt').innerHTML = '';
	for($i = 0; $i<$throwLine.length; $i++){
		$('throwProductOpt').innerHTML += $throwLine[$i].qty +' x '+$throwLine[$i].fitOptionText+'<br/>';
		$fabricName = $throwLine[$i].fabric.split(' - ');
		//$('throwFabricColour').innerHTML = $fabricName[1];
	}

	$('throwFabricChoiceFront').innerHTML = $throwLine[0].swatchName;
	//$('throwFabricChoiceFront').innerHTML = $fabricName[0]+' '+$fabricName[1];
	
//	$('throwFabricChoice').innerHTML = $fabricName[0];

	$cubaBack =  getRadioFieldValue('throwCubaBack');
	//console.debug($cubaBack  + ' ' + $('throwFabricChoiceBack').innerHTML);
	$('throwFabricChoiceBack').innerHTML = $cubaBack+' on reverse'; 
}

function updateArmThrows(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('paddedArmFabric');
	$swatchID = getRadioFieldId('paddedArmFabric').replace('paddedArmFabric','');
		
	//console.debug($swatchID);
	//get the chosen fit option - 6 sizes
	$throwLine = [];
	$qtyFields = new Array('paddedThrowQTY10');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$fabricName = $swatchName;
	
	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 = 	'Padded Arm Throw';
					$fitOptionText  = '38" x 22"';
					
					$qty = $($fieldID).value;
					throwUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 12, 'productDescription' : $description , 'fabric' : $fabricName , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : $fitOption+1, 'fitOptionText' : $fitOptionText};
					$throwLine[$i] = throwUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	
	
	setArmThrowList($throwLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	updateArmThrowPrice($throwLine,checkoutSave);

}
function updateArmThrowPrice($throwLine,checkoutSave){
			pars = 'array='+$throwLine.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;
																					 
																					 if(prices.priceFull == prices.priceDiscount){
																						 $('armThrowWas').style.visibility = 'hidden';
																						 $$('#armThrowSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																						 $('armThrowWas').style.visibility = 'visible';
																						 $$('#armThrowSale .priceLabel')[0].innerHTML = 'Sale Price';
																					 }
																					 
																					 $('paddedArmThrowPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate,2);
																					 $('paddedArmThrowPriceFigure').innerHTML = $currencySymbol+Math.floor(prices.discountPrice * $conversionRate,2);
																					 if(checkoutSave == true){
																						 addPriceToCheckoutTotal(prices.discountPrice);
																						for($i = 0; $i<$throwLine.length; $i++){
																							writeBasketLink($throwLine[$i]);
																						}
																					 }
																				 } 
											});

}

function setArmThrowList($throwLine){
	//console.debug($throwLine);
	$('armThrowProductOpt').innerHTML = '';
	for($i = 0; $i<$throwLine.length; $i++){
		$('armThrowProductOpt').innerHTML += $throwLine[$i].qty +' x '+$throwLine[$i].fitOptionText+'<br/>';
		$fabricName = $throwLine[$i].fabric.split(' - ');
		$('armThrowFabricColour').innerHTML = $throwLine[$i].swatchName;
	}
	
	$('armThrowFabricColour').innerHTML = $fabricName[1];
}

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.fullPrice * $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 updatePipedCushions(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('pipedCushionFabricFront');
	$swatchID = getRadioFieldId('pipedCushionFabricFront').replace('pipedCushionFabricFront','');
		
	//console.debug($swatchID); return false;
	//get the chosen fit option - 6 sizes
	$cushionsLine = [];
	$qtyFields = new Array('pipedScatterQTY');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$fabric = $swatchName;
	//$fabricName = $swatchName.split('-');
	//$fabricName  = $fabricName[0];
	//console.debug($swatchName);
	//return false;
	for($i = 0; $i<$qtyFields.length; $i++){
		//$fitOptionText = ($fitOption == 0) ? 'Standard Fit' : 'Premier Fit';
		$fitOptionText = '';
		//console.debug($qtyFields[$fieldID ]);
		$fieldID = $qtyFields[$i];
//alert($($fieldID).outerHTML);
		if($($fieldID).value!='' && $($fieldID).value!=0){
					//$description = 	($i == 0) ? 'Loose Seat Cushions' : 'Loose Back Cushions';
					$description = 	'Piped Scatter Cushion Covers';
					$fitOptionText  = ' ';
					
					$qty = $($fieldID).value;
					if($qty > 10){ $($fieldID).value = 10;  $qty = 10}
					
					cushionUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 9, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
					$cushionsLine[$cushionsLine.length] = cushionUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	//console.debug($cushionsLine);
	setPipedCushionList($cushionsLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	
	updatePipedCushionPrice($cushionsLine,checkoutSave);

}
function updatePipedCushionPrice($cushionLine,checkoutSave){
//return false;
//console.debug($cushionLine);
			pars = 'array='+$cushionLine.toJSON();
		if(checkoutSave == true){ 
			pars += '&save=true';
			//for($i = 0; $i<$cushionLine.length; $i++){
			//	writeBasketLink($cushionLine[$i]);
			//}
			
		}
		//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.fullPrice == prices.discountPrice){

																			 $$('#pipedCushionWas .priceLabel')[0].style.visibility = 'hidden'; 
																			 $$('#cushionPriceFull')[0].style.visibility = 'hidden';
																			 $$('#pipedCushionSale .priceLabel')[0].innerHTML = 'Only';
																		 }	
																	 else{
																		 	//console.debug('price is different');
																			 $('#pipedCushionWas').style.visibility = 'visible';
																			 $$('#pipedCushionSale')[0].innerHTML = 'Sale Price';
																		 }
																					 
																					 
													 if(prices.fullPrice == prices.discountPrice)
													$('cushionPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate,2);
													$('cushionPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate,2);
													



																					if(checkoutSave == true){
																						for($i = 0; $i<$cushionLine.length; $i++){
																							writeBasketLink($cushionLine[$i]);
																						}
																						 addPriceToCheckoutTotal(prices.discountPrice);
																					 }
																				 } 
											});

}

function setPipedCushionList($cushionLine){
	//console.debug($cushionLine);
	$('scatterProductOpt').innerHTML = '';
	for($i = 0; $i<$cushionLine.length; $i++){
		$('scatterProductOpt').innerHTML += $cushionLine[$i].qty +' x '+$cushionLine[$i].productDescription+'<br/>';
		$fabricName = $cushionLine[$i].fabric.split('-');
		//console.debug($fabricName);
		$('scatterFabricChoice').innerHTML = $cushionLine[$i].swatchName;
	}

	
	//$('scatterFabricColour').innerHTML = $fabricName[1];
		
}


function updatePipedArmCovers(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('armCoverFabricFront');
	$swatchID = getRadioFieldId('armCoverFabricFront').replace('armCoverFabricFront','');
		
	
	//get the chosen fit option - 6 sizes
	$coverLine = [];
	$qtyFields = new Array('armcoverQTYField');
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  = 0;
	
	$fabric = $swatchName;
	//$fabricName = $swatchName.split('-');
	//$fabricName  = $fabricName[0];
	//console.debug($swatchName);
	//return false;
	for($i = 0; $i<$qtyFields.length; $i++){
		//$fitOptionText = ($fitOption == 0) ? 'Standard Fit' : 'Premier Fit';
		$fitOptionText = '';
		//console.debug($qtyFields[$fieldID ]);
		$fieldID = $qtyFields[$i];
		

		if($($fieldID).value!='' && $($fieldID).value!=0){
					//$description = 	($i == 0) ? 'Loose Seat Cushions' : 'Loose Back Cushions';
					$description = 	'Piped Arm Covers';
					$fitOptionText  = ' ';
					
					$qty = $($fieldID).value;
//alert('qty is '+ $($fieldID).value)
					if($qty > 10){ $($fieldID).value = 10;  $qty = 10}
					
					coverUpdateObject = {'currentCount' : $currentCount , 'qty' : $qty , 'product' : 14, 'productDescription' : $description , 'fabric' : $fabric , 'swatch' : $swatchID, 'swatchid' : $swatchID, 'swatchName' : $swatchName , 'fitOption' : (parseInt($fitOption)+1), 'fitOptionText' : $fitOptionText};
					$coverLine[$coverLine.length] = coverUpdateObject;
					$currentCount++;
		}
		$fitOption++;
	}
	//console.debug($throwLine);

	setPipedArmCoverList($coverLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	
	updatePipedArmCoverPrice($coverLine,checkoutSave);

}
function updatePipedArmCoverPrice($cushionLine,checkoutSave){
//return false;

			pars = 'array='+$cushionLine.toJSON();
		if(checkoutSave == true){ 
			pars += '&save=true';			
		}
		//console.debug($throwLine);
		//return false;

		 new Ajax.Request('/checkout/getPrice', {method:'post', parameters : pars , onSuccess : function(transport) { 
					//alert(prices)
					prices = eval('(' + transport.responseText + ')');
					//alert(prices)	;
					
					if(prices.fullPrice == prices.discountPrice){
						$('armPriceWas').style.visibility = 'hidden';
						$$('#armPriceSale .priceLabel')[0].innerHTML = 'Only';
					}
					else{
						$('armPriceWas').style.visibility = 'visible';
						$$('#armPriceSale .priceLabel')[0].innerHTML = 'Sale Price';
					}
					
					$conversionRate = $('conversionRate').value;
					$currencySymbol = $('currencySymbol').value;
																					
					//alert(Math.round(prices.discountPrice * $conversionRate,2))																 
					$('armCoverPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate,2);
					$('armCoverPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate,2);
					
					if(checkoutSave == true){
								addPriceToCheckoutTotal(prices.discountPrice);
								for($i = 0; $i<$cushionLine.length; $i++){
								writeBasketLink($cushionLine[$i]);
								}
											}
					
								 } 
											});
		//prices = null;
		//$cushionLine = null;

}

function setPipedArmCoverList($coverLine){
	//console.debug($coverLine);
	$('pipedArmProductOpt').innerHTML = '';
	for($i = 0; $i<$coverLine.length; $i++){
		$('pipedArmProductOpt').innerHTML += $coverLine[$i].qty +' pair '+$coverLine[$i].productDescription+'<br/>';
		$fabricName = $coverLine[$i].fabric.split('-');
		$('pipedArmFabricChoice').innerHTML = $coverLine[$i].swatchName;
	}

	
	//$('pipedArmFabricColour').innerHTML = $fabricName[1];
		
}



function updateFootstool(addToCheckout){
	//hard coded rush job - weee
	
	$form = $('orderForm');

	//get the chosen fabric (Front) - only one fabric for all over covers
	$swatchName =  getRadioFieldValue('footstoolFabric');
	$swatchID = getRadioFieldId('footstoolFabric').replace('footstoolFabric','');
		
	
	//get the chosen fit option - 6 sizes
	$footstoolLine = [];
	$qtyFields = new Array();
	$currentCount =	parseInt($('basketCount').innerHTML);
	$fitOption  =  getRadioFieldValue('footstoolOption');
	if($fitOption == 2){
		//show the other fabrics;
		if($('footstoolVarious').style.display == 'none'){
			$('footstoolFabric38').checked = true;
		}
		$('footstoolVarious').style.display = 'block';
		$('footstoolRomo').style.display = 'none';
		
	}
	else{
		if($('footstoolVarious').style.display == 'block'){
			//reset the fabric to a romo fabric
			$('footstoolFabric38').checked = true;
			$('footstoolVarious').style.display = 'none';
		}
		$('footstoolRomo').style.display = 'block';
		
	}
	
	$qty = 1;
	
	
	$fabric = $swatchName;
	//$fabricName = $swatchName.split('-');
	//$fabricName  = $fabricName[0];
	//console.debug($swatchName);
	//return false;
	//for($i = 0; $i<$qtyFields.length; $i++){
		//$fitOptionText = ($fitOption == 0) ? 'Standard Fit' : 'Premier Fit';
		
		$fitOptionArray = new Array('Simple Style', 'Valance Style', 'Cotton and Cotton feel Range');
		$fitOptionText = $fitOptionArray[$fitOption];
		//console.debug($qtyFields[$fieldID ]);
		//$fieldID = $qtyFields[$i];
		
		//if($($fieldID).value!='' && $($fieldID).value!=0){
					//$description = 	($i == 0) ? 'Loose Seat Cushions' : 'Loose Back Cushions';
					$description = 	'Footstool Covers';
					//$fitOptionText  = ' ';
					
					//$qty = $($fieldID).value;
					//if($qty > 10){ $($fieldID).value = 10;  $qty = 10}
					
					footstoolUpdateObject = {'currentCount' : $currentCount , '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++;
		//}
		//$fitOption++;
	//}
	//console.debug($throwLine);
	setFootstooloverList($footstoolLine);
	
	checkoutSave = (addToCheckout=='undefined') ? false : addToCheckout;
	
	updateFootstoolPrice($footstoolLine,checkoutSave);

}
function updateFootstoolPrice($footstoolLine,checkoutSave){
//return false;
			pars = 'array='+$footstoolLine.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.fullPrice == prices.discountPrice){
																						 $('footstoolWas').style.visibility = 'hidden';
																						 $$('#footstoolSale .priceLabel')[0].innerHTML = 'Only';
																					 }
																					 else{
																						 $('footstoolWas').style.visibility = 'visible';
																						 $$('#footstoolSale .priceLabel')[0].innerHTML = 'Sale Price';																						 
																					 }
																					 $('footstoolPriceFull').innerHTML = $currencySymbol+Math.round(prices.fullPrice * $conversionRate,2);
																					 $('footstoolPriceFigure').innerHTML = $currencySymbol+Math.round(prices.discountPrice * $conversionRate,2);
																					 
																					 if(checkoutSave == true){
																						 addPriceToCheckoutTotal(prices.discountPrice);
																			 			for($i = 0; $i<$footstoolLine.length; $i++){
																							writeBasketLink($footstoolLine[$i]);
																						}
																					 }
																				 } 
											});

}

function setFootstooloverList($footstoolLine){
	//console.debug($coverLine);
	$('footstoolProductOpt').innerHTML = '';
	for($i = 0; $i<$footstoolLine.length; $i++){
		$('footstoolProductOpt').innerHTML += $footstoolLine[$i].fitOptionText+'<br/>';
		$fabricName = $footstoolLine[$i].fabric.split('-');
		$('footstoolFabricChoice').innerHTML = $fabricName[0]+' Fabric';
	}

	
	$('footstoolFabricColour').innerHTML = $fabricName[1];
		
}



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);

}
