var lharm=0;
var lhseat=0;
var corner=0;
var rhseat=0;
var centreseat=0;
var rharm=0;

function load()
{
	showPrice(cart_quantity)
	P7_initPM(1,8,1,-20,10)
}

function take_there(form)
{
    var version = navigator.appVersion;
    prod_value=form.model.value;
    destination="product_info.php?products_id="+prod_value;
    if(destination!="no_page")
    {
      if (version.indexOf("MSIE") >= -1)
      {
         window.location.href=destination;
      }
      else
      {
         window.open(destination, target="_self");
      }
    }
}

function img_act(imgName,optionValue,newAltText) {
	   imgSource="/images/options/"+optionValue+".jpg"
	   if (document[imgName])
	   {
        document[imgName].src = imgSource;
        var alttext=document.getElementById(imgName);
		alttext.alt=newAltText;
       }
}

function FormatNumber(num)
   {
	 if(isNaN(num)) { num = "0"; }
     sign = (num == (num = Math.abs(num)));
     num = Math.floor(num*100+0.50000000001);
     cents = num%100;
     num = Math.floor(num/100).toString();
     if(cents<10) { cents = "0" + cents; }
     for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
     {
       num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
     }
     return (((sign)?'':'-') + num + '.' + cents);
   }

function changePipingSelected(pulldown)
{
	var optiontext=(pulldown.options[pulldown.selectedIndex].text);
	var prefix='';
	var myRegExp = / - Yes/;
	var matchPos1 = optiontext.search(myRegExp);
	var res="No";
	if(matchPos1!=-1)
	{
		var res="Yes";
	}
	var element=document.getElementById('piping_selected');
	element.value=res;
}

function updatePrice(pulldown,counter,percentage,origprice)
{
	var optiontext=(pulldown.options[pulldown.selectedIndex].text);
	var prefix='';
	var myRegExp = / - Yes/;
	var matchPos1 = optiontext.search(myRegExp);
	if(matchPos1!=-1)
	{
		prefix="+";
	}
	var myRegExp2 = /\(-.*\)/;
	var matchPos2 = optiontext.search(myRegExp2);
	if(matchPos2!=-1)
	{
		prefix="-";
	}
	var pricefield="price-"+counter;
	var priceobject=document.getElementById(pricefield);
	var price=priceobject.innerHTML;
	price=price.substring(1);
	price=parseInt(price);
	var pricediff=price*(percentage/100);
	pricediff=Math.floor(pricediff);
	pricediff=parseInt(pricediff);
	if(prefix=="+")
	{
		var newprice=price+pricediff;
	}
	else if(prefix=="-")
	{
		newprice=price-pricediff;
	}
	else
	{
		newprice=origprice;
	}
	priceobject.innerHTML="£"+newprice;
}

function updateAllCovers(pulldown,itemtype,counter)
{
	var newvalue=(pulldown.options[pulldown.selectedIndex].value);
	for(var i=1;i<counter+1;i++)
	{
		partdesc=itemtype+'-'+i;
		var part=document.getElementById(partdesc);
		if(part)
		{
			part.value=newvalue;
		}
	}
}

function updateTwoToneChecked(twotoneid)
{
	if(twotoneid != 'null') {
		var element=document.getElementById(twotoneid);
		if(element.length != 0) {
			var fielddesc=element.id.split("_");
			var fieldid=fielddesc[1];
			var elementname="quantity_"+fieldid;
			var element2=document.getElementById(elementname);
			var pulldown=document.getElementById('twotonesel');
			var twotone=(pulldown.options[pulldown.selectedIndex].text);
			if(twotone=="None")
			{
				element.checked=0;
				element2.value=0;
			}
			else
			{
				element.checked=1;
				element2.value=1;
			}
		}
	}
}

function updateAllPrices(pulldown,counter,percentage,origprices)
{
	var origpricelist=origprices.split(",");
	var optiontext=(pulldown.options[pulldown.selectedIndex].text);
	var prefix='';
	var myRegExp = / - Yes/;
	var matchPos1 = optiontext.search(myRegExp);
	if(matchPos1!=-1)
	{
		prefix="+";
	}
	var myRegExp2 = /\(-.*\)/;
	var matchPos2 = optiontext.search(myRegExp2);
	if(matchPos2!=-1)
	{
		prefix="-";
	}
	for(var i=1;i<counter+1;i++)
	{
		var pricefield="price-"+i;
		var priceobject=document.getElementById(pricefield);
		var price=priceobject.innerHTML;
		price=price.substring(1);
		price=parseInt(price);
		var pricediff=price*(percentage/100);
		pricediff=Math.floor(pricediff);
		pricediff=parseInt(pricediff);
		if(prefix=="+")
		{
			var newprice=price+pricediff;
		}
		else if(prefix=="-")
		{
			newprice=price-pricediff;
		}
		else
		{
			newprice=origpricelist[i-1];
		}
		priceobject.innerHTML="£"+newprice;
	}
}

function IsNumeric(data){
    return parseFloat(data)==data;
}
function showPrice(form,coverorigprice)
  {
    var myTotalPrice = 0;
    var showUP = 0;
    var myMathProblem = "";
    var quantity = form.qty.value;
    var istwotone=0;
    var isfabriccover=0;
    var ispiping=0;
    var pipingcost=0;
    var twotonecost=0;
    var extraprice=0;

	realprice= $('[name=base_price]').val();
    myItemPrice = parseFloat(realprice);
    for (var i = 0; i < form.elements.length; i++) {
      var e = form.elements[i];
      if ( e.type == 'select-one') {  	
      	showUP = 1;
        Item = e.selectedIndex;
        myPrice = e.options[Item].text;
        description = e.options[Item].text;
        var fabriccover=description.indexOf("EC: ",0);
        var fabriccovernone=description.indexOf("EC: None",0);
        if(fabriccover!=-1 && fabriccovernone==-1) {
        	isfabriccover=1;
        }
        var twotone=description.indexOf("TT: ",0);
        var twotonenone=description.indexOf("TT: None",0);
        if(twotone!=-1 && twotonenone==-1) {
        	istwotone=1;
        }
        var piping=description.indexOf("Piping - Yes",0);
        if(piping!=-1) {
        	ispiping=1;
        }

        myPlusSign = myPrice.indexOf("+",0)
        myDollarSign = myPrice.indexOf("(",0)
        if ( myDollarSign != "-1" ) {
          myParSign = myDollarSign+8;
          if ( myPlusSign != "-1" ) {
          	myAttributeString = myPrice.substring(myDollarSign+3, myParSign);
      	  } else {
	      	myAttributeString = myPrice.substring(myDollarSign+2, myParSign);
      	  }

		  if(myAttributeString == "ee Abo") {
			myAttributeString = "0";
		  }
          myAttributeString = myAttributeString.replace(/,/,"");
		  myAttributePrice = parseFloat(myAttributeString);
          myMathProblem = myPrice.charAt(myDollarSign + 1);
          if(piping!=-1) {
        	pipingcost=myAttributePrice;
          }
          if(twotone!=-1 && twotonenone==-1) {
        	twotonecost=myAttributePrice;
          } 
        } else {
	        myAttributePrice = 0;
        }
        for(var j=0;j<e.length;j++) {
	 		var fabriccoverall=description.indexOf("EC: ",0);
	      	if(fabriccoverall!=-1) {
	        	myNewPrice=coverorigprice;
				if(istwotone==1) {
					myNewPrice+=twotonecost;		
				}	
				if(ispiping==1) {
					//var percentage=coverorigprice*(35/100);
					//percentage=Math.floor(percentage);
					myNewPrice+=pipingcost;
				}
				myPlusSign2 = e.options[j].text.indexOf("+",0)
		        myDollarSign2 = e.options[j].text.indexOf("(",0)
		        if ( myDollarSign2 != "-1" ) {
		        	myParSign2 = myDollarSign2+8;
		        	if ( myPlusSign2 != "-1" ) {
		          		myAttributeString2 = e.options[j].text.substring(myDollarSign2+3, myParSign2);
		      		} else {
			     		myAttributeString2 = e.options[j].text.substring(myDollarSign2+2, myParSign2);
		      		}
		        	myAttributeString2 = myAttributeString2.replace(/,/,"");
		       	 	myAttributePrice2 = parseFloat(myAttributeString2);
		        } else {
		        	myAttributePrice2=0;
		        }
				e.options[j].text=e.options[j].text.replace(myAttributePrice2,myNewPrice);
				if(fabriccovernone==-1) {
					extraprice=myNewPrice-myAttributePrice;		
				}
	        }
    	}

        //if(fabriccover!=-1 && fabriccovernone==-1)
        //{
		//	if(ispiping)
		//	{
		//		var percentage=myAttributePrice*(35/100);
		//		percentage=Math.floor(percentage);
		//		extraprice+=percentage;
		//	}	
        //}
        myFabricSplit=myPrice.indexOf("-",0)
        if ( myFabricSplit != "-1" ) {
	     	fabtype=myPrice.substring(0,myFabricSplit-1)
	     	if(fabtype=="Matrix") fabtype="A"
	     	else if (fabtype=="Faux Suede") fabtype="B"
	     	else if (fabtype=="Chenile") fabtype="C"
	     	else fabtype="D"
	     	myPriceEnd=myPrice.indexOf("(",0)
	     	if (myPriceEnd == "-1") {
		     	myPriceEnd=myPrice.length
		     	myPriceEnd = myPriceEnd + 1
	     	}
	     	myPriceEnd = myPriceEnd - 1
	     	fabcol=myPrice.substring(myFabricSplit+2,myPriceEnd)
	     	fabimg=fabtype + fabcol
	     	pic='images/half/' + fabimg + '.jpg'
        }
          if (myMathProblem == "-") {
            myTotalPrice = myTotalPrice - myAttributePrice;
          } else {
            myTotalPrice = myTotalPrice + myAttributePrice;
          }
      } else if(e.type=='hidden') {
      	myPrice = e.value;
        myPlusSign = myPrice.indexOf("+",0)
        myDollarSign = myPrice.indexOf("(",0)
        if ( myDollarSign != "-1" ) {
          myParSign = myDollarSign+8;
          if ( myPlusSign != "-1" ) {
          	myAttributeString = myPrice.substring(myDollarSign+3, myParSign);
      	  } else {
	      	myAttributeString = myPrice.substring(myDollarSign+2, myParSign);
      	  }
          myAttributeString = myAttributeString.replace(/,/,"");
          myAttributePrice = parseFloat(myAttributeString);
          myMathProblem = myPrice.charAt(myDollarSign + 1);
        } else {
	        myAttributePrice = 0;
        }
        myFabricSplit=myPrice.indexOf("-",0)
        if ( myFabricSplit != "-1" ) {
	     	fabtype=myPrice.substring(0,myFabricSplit-1)
	     	if(fabtype=="Matrix") fabtype="A"
	     	else if (fabtype=="Faux Suede") fabtype="B"
	     	else if (fabtype=="Chenile") fabtype="C"
	     	else fabtype="D"
	     	myPriceEnd=myPrice.indexOf("(",0)
	     	if (myPriceEnd == "-1") {
		     	myPriceEnd=myPrice.length
		     	myPriceEnd = myPriceEnd + 1
	     	}
	     	myPriceEnd = myPriceEnd - 1
	     	fabcol=myPrice.substring(myFabricSplit+2,myPriceEnd)
	     	fabimg=fabtype + fabcol
	     	pic='images/half/' + fabimg + '.jpg'
        }
          if (myMathProblem == "-") {
            myTotalPrice = myTotalPrice - myAttributePrice;
          } else {
            myTotalPrice = myTotalPrice + myAttributePrice;
          }
      }
    }
    //if(isfabriccover && istwotone)
    //{
    //	myTotalPrice=myTotalPrice+20;
    //}
    myTotalPrice=myTotalPrice+extraprice;
    if ( showUP ) {
        myTotalPrice = '&pound;' + parseInt(myTotalPrice + myItemPrice);
       	$('div.product_main .price').html(myTotalPrice);
    }

    var counter=0;
    for (var i = 0; i < form.elements.length; i++) {
	  var e = form.elements[i];
	  if ( e.type == 'select-one' ) {
	    Item = e.selectedIndex;
	    pic=''
		optionCode=e.options[Item].value
		docElement="optionpic"+counter
        myAlt = e.options[Item].text;
		img_act(docElement,optionCode,myAlt)
		counter+=1;
	  }
	}
  }
function updateFabricImage(pulldown,field)
{
	var item=pulldown.selectedIndex;
	optionCode=pulldown.options[item].value;
	myAlt=pulldown.options[item].text;
	img_act(field,optionCode,myAlt);
}

function updatelength(side,part,size,atype)
{
	if(atype=="ushape")
	{
		diff=97;
	}
	else
	{
		diff=0;
	}
	if(side=="left")
	{
		if(part=="arm")
		{
			lharm=size;
		}
		else if(part=="seat")
		{
			lhseat=size;
		}
	}
	else if(side=="right")
	{
		if(part=="arm")
		{
			rharm=size;
		}
		else if(part=="seat")
		{
			rhseat=size;
		}
	}
	else if(side=="centre")
	{
		if(part=="arm")
		{
			centrearm=size;
		}
		else if(part=="seat")
		{
			centreseat=size;
		}
	}
	else if(side=="both" && atype=="corner")
	{
		corner=size;
	}
	if(atype=="ushape")
	{
		if(side=="centre" && part=="seat")
		{
			centreseat=centreseat+97+97;
		}
	}
	document.getElementById("lhsize").innerHTML = lharm+lhseat+corner+diff+' cm';
	document.getElementById("rhsize").innerHTML = rharm+rhseat+corner+diff+' cm';
	if(atype=="ushape")
	{
		document.getElementById("centresize").innerHTML = centreseat+' cm';
	}

}

function validateownchoices(final)
{
	var err='';
	var leftarm=getCheckedValue(document.forms['buildown'].elements['ownleftarm']);
	var leftseat=getCheckedValue(document.forms['buildown'].elements['ownleftseats']);
	var rightseat=getCheckedValue(document.forms['buildown'].elements['ownrightseats']);
	var rightarm=getCheckedValue(document.forms['buildown'].elements['ownrightarm']);
	var centre=getCheckedValue(document.forms['buildown'].elements['owncentre']);
	var la=itemarray[leftarm];
	var ls=itemarray[leftseat];
	var rs=itemarray[rightseat];
	var ra=itemarray[rightarm];
	var ce=itemarray[centre];
	if((ce=="Centre 1 Wide Seat" || ce=="Centre 2 Standard Seats" || ce=="Centre 1 Extra Wide Seat") && (ls=="LH 2 Seat Sofabed" || ls=="LH 1 Extra Wide Seat Sofabed" || ls=="LH 3 Seat Sofabed" || ls=="LH 2 Wide Seat Sofabed" || rs=="RH 2 Seat Sofabed" || rs=="RH 1 Extra Wide Seat Sofabed" || rs=="RH 3 Seat Sofabed" || rs=="RH 2 Wide Seat Sofabed"))
	{
		err=err+"You may not have a sofabed with 1 wide seat, 2 standard seats or 1 extra wide seat centres\n";
	}
	if(la=="LH Chaise" && (ls!="LH 1 Standard Seat" && ls!="LH 2 Standard Seats" && ls!=undefined && ls!="LH 1 Extra Wide Seat"))
	{
		err=err+"A LHS Arm selection of Chaise can only be made in combination with one standard seat, 2 standard seats or 1 extra wide seat\n";
	}
	if(la=="LH Chaise" && ls=="LH Chaise")
	{
		err=err+"A LH Seats selection of Chaise can only be made in combination with a LH Arm selection of No Arm\n";
	}
	if(ra=="RH Chaise" && rs=="RH Chaise")
	{
		err=err+"A RH Seats selection of Chaise can only be made in combination with a RH Arm selection of No Arm\n";
	}
	if (la!=undefined && (ls=="LH Chaise" && (la!="LH No Arm" && la!="LH Chaise")))
	{
		err=err+"A LH Seats selection of Chaise can only be made in combination with a LH Arm selection of No Arm\n";
	}
	if(la=="LH No Arm" && (ls=="LH 1 Extra Wide Seat Sofabed" || ls=="LH 2 Seat Sofabed" || ls=="LH 2 Wide Seat Sofabed" || ls=="LH 3 Seat Sofabed"))
	{
		err=err+"You must have an arm with a sofabed\n";
	}

	if(ra=="RH Chaise" && (rs!="RH 1 Standard Seat" && rs!="RH 2 Standard Seats" && rs!=undefined && rs!="RH 1 Extra Wide Seat"))
	{
		err=err+"A RHS Arm selection of Chaise can only be made in combination with one standard seat, 2 standard seats or 1 extra wide seat\n";
	}
	if (ra!=undefined && (rs=="RH Chaise" && (ra!="RH No Arm" && ra!="RH Chaise")))
	{
		err=err+"A RH Seats selection of Chaise can only be made in combination with a RH Arm selection of No Arm\n";
	}
	if(ra=="RH No Arm" && (rs=="RH 1 Extra Wide Seat Sofabed" || rs=="RH 2 Wide Seat Sofabed" || rs=="RH 2 Seat Sofabed" || rs=="RH 3 Seat Sofabed"))
	{
		err=err+"You must have an arm with a sofabed\n";
	}

	if((rs=="RH 2 Seat Sofabed" || rs=="RH 1 Extra Wide Seat Sofabed" || rs=="RH 3 Seat Sofabed" || rs=="RH 2 Wide Seat Sofabed") && (ls=="LH 2 Seat Sofabed" || ls=="LH 1 Extra Wide Seat Sofabed" || ls=="LH 3 Seat Sofabed" || ls=="LH 2 Wide Seat Sofabed"))
	{
		err=err+"You may not have a sofabed on both the left and right hand sides\n";
	}

	if(final==1)
	{
		if(leftarm=="")
		{
			err=err+"Please choose a left arm option\n";
		}
		if(leftseat=="")
		{
			err=err+"Please choose a left seat option\n";
		}
		if(rightseat=="")
		{
			err=err+"Please choose a right seat option\n";
		}
		if(rightarm=="")
		{
			err=err+"Please choose a right arm option\n";
		}
		if(centre=="")
		{
			err=err+"Please choose a centre\n";
		}
	}
	if(err!='')
	{
		err=err+"\nPlease change your selection\n";
		alert(err);
	}
	return (err=='');
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function validateOptions(scotchgards,corner,armlesstype,sofabed_seat,corner_sofa,sofabed_type,submitted)
{
	err='';
	var fabric=document.getElementById('Fabric');
	var afabric='';
	var fast=0;
	if(fabric)
	{
		afabric=fabric.options[fabric.selectedIndex].text;
		var end = afabric.indexOf("(",0);
		if(end==-1) end=afabric.length;
		afabric=afabric.substring(0,end);
		afabric=trimAll(afabric.toLowerCase());
		if(afabric.indexOf("fast")!=-1) fast=1;
	}

	var scotchgard=document.getElementById('Fabric_Protection');
	var ascotchgard='';
	if(scotchgard)
	{
		ascotchgard=scotchgard.options[scotchgard.selectedIndex].text;
		var end = ascotchgard.indexOf("(",0);
		if(end==-1) end=ascotchgard.length;
		ascotchgard=ascotchgard.substring(0,end);
		ascotchgard=trimAll(ascotchgard.toLowerCase());
	}

	var arms=document.getElementById('Arms');
	var aarms='';
	if(arms)
	{
		aarms=arms.options[arms.selectedIndex].text;
		var end = aarms.indexOf("(",0);
		if(end==-1) end=aarms.length;
		aarms=aarms.substring(0,end);
		aarms=trimAll(aarms.toLowerCase());
	}

	var feet=document.getElementById('Feet');
	var afeet='';
	if(feet)
	{
		afeet=feet.options[feet.selectedIndex].text;
		var end = afeet.indexOf("(",0);
		if(end==-1) end=afeet.length;
		afeet=afeet.substring(0,end);
		afeet=trimAll(afeet.toLowerCase());
	}

	var backcover=document.getElementById('Back_Cover');
	var abackcover='';
	if(backcover)
	{
		abackcover=backcover.options[backcover.selectedIndex].text;
		var end = abackcover.indexOf("(",0);
		if(end==-1) end=abackcover.length;
		abackcover=abackcover.substring(0,end);
		abackcover=trimAll(abackcover.toLowerCase());
	}

	var sofabed=document.getElementById('Sofabed');
	var asofabed='';
	if(sofabed)
	{
		asofabed=sofabed.options[sofabed.selectedIndex].text;
		var end = asofabed.indexOf("(",0);
		if(end==-1) end=asofabed.length;
		asofabed=asofabed.substring(0,end);
		asofabed=trimAll(asofabed.toLowerCase());
	}

	var orientation=document.getElementById('Orientation');
	var aorientation='';
	if(orientation)
	{
		aorientation=orientation.options[orientation.selectedIndex].text;
		var end = aorientation.indexOf("(",0);
		if(end==-1) end=aorientation.length;
		aorientation=aorientation.substring(0,end);
		aorientation=trimAll(aorientation.toLowerCase());
	}

	var chaise=document.getElementById('Chaise');
	var achaise='';
	if(chaise)
	{
		achaise=chaise.options[chaise.selectedIndex].text;
		var end = achaise.indexOf("(",0);
		if(end==-1) end=achaise.length;
		achaise=achaise.substring(0,end);
		achaise=trimAll(achaise.toLowerCase());
	}
	var aleftchaise='';
	var leftchaise=document.getElementById('Left_Chaise');
	if(leftchaise)
	{
		aleftchaise=leftchaise.options[leftchaise.selectedIndex].text;
		var end = aleftchaise.indexOf("(",0);
		if(end==-1) end=aleftchaise.length;
		aleftchaise=aleftchaise.substring(0,end);
		aleftchaise=trimAll(aleftchaise.toLowerCase());
	}
	var arightchaise='';
	var rightchaise=document.getElementById('Right_Chaise');
	if(rightchaise)
	{
		arightchaise=rightchaise.options[rightchaise.selectedIndex].text;
		var end = arightchaise.indexOf("(",0);
		if(end==-1) end=arightchaise.length;
		arightchaise=arightchaise.substring(0,end);
		arightchaise=trimAll(arightchaise.toLowerCase());
	}
	var aleftarm='';
	var leftarm=document.getElementById('Left_Arm_Option');
	if(leftarm)
	{
		aleftarm=leftarm.options[leftarm.selectedIndex].text;
		var end = aleftarm.indexOf("(",0);
		if(end==-1) end=aleftarm.length;
		aleftarm=aleftarm.substring(0,end);
		aleftarm=trimAll(aleftarm.toLowerCase());
	}
	var leftarm=document.getElementById('Left_SB_Arm');	
	if(leftarm)
	{
		aleftarm=leftarm.options[leftarm.selectedIndex].text;
		var end = aleftarm.indexOf("(",0);
		if(end==-1) end=aleftarm.length;
		aleftarm=aleftarm.substring(0,end);
		aleftarm=trimAll(aleftarm.toLowerCase());
	}

	var arightarm='';
	var rightarm=document.getElementById('Right_Arm_Option');
	var arightarm='';
	if(rightarm)
	{
		arightarm=rightarm.options[rightarm.selectedIndex].text;
		var end = arightarm.indexOf("(",0);
		if(end==-1) end=arightarm.length;
		arightarm=arightarm.substring(0,end);
		arightarm=trimAll(arightarm.toLowerCase());
	}
	var rightarm=document.getElementById('Right_SB_Arm');
	if(rightarm)
	{
		arightarm=rightarm.options[rightarm.selectedIndex].text;
		var end = arightarm.indexOf("(",0);
		if(end==-1) end=arightarm.length;
		arightarm=arightarm.substring(0,end);
		arightarm=trimAll(arightarm.toLowerCase());
	}

	var leftsbarm=document.getElementById('Left_SB_Arm');
	var aleftsbarm='';
	if(leftsbarm)
	{
		aleftsbarm=leftsbarm.options[leftsbarm.selectedIndex].text;
		var end = aleftsbarm.indexOf("(",0);
		if(end==-1) end=aleftsbarm.length;
		aleftsbarm=aleftsbarm.substring(0,end);
		aleftsbarm=trimAll(aleftsbarm.toLowerCase());
	}

	var rightsbarm=document.getElementById('Right_SB_Arm');
	var arightsbarm='';
	if(rightsbarm)
	{
		arightsbarm=rightsbarm.options[rightsbarm.selectedIndex].text;
		var end = arightsbarm.indexOf("(",0);
		if(end==-1) end=arightsbarm.length;
		arightsbarm=arightsbarm.substring(0,end);
		arightsbarm=trimAll(arightsbarm.toLowerCase());
	}

	var piping=document.getElementById('Piping');
	var apiping='';
	if(piping)
	{
		apiping=piping.options[piping.selectedIndex].text;
		var end = apiping.indexOf("(",0);
		if(end==-1) end=apiping.length;
		apiping=apiping.substring(0,end);
		apiping=trimAll(apiping.toLowerCase());
	}

	var storage=document.getElementById('Storage_Trays');
	var astorage='';
	if(storage)
	{
		astorage=storage.options[storage.selectedIndex].text;
		var end = astorage.indexOf("(",0);
		if(end==-1) end=astorage.length;
		astorage=astorage.substring(0,end);
		astorage=trimAll(astorage.toLowerCase());
	}

	if(submitted==1 && corner_sofa==1 && aleftchaise=="left chaise end" && arightchaise=="right chaise end")
	{
		resp=confirm("Warning: you have selected a corner sofa with two chaise ends. Is this correct?");
		if(resp==0) 
		{
			return 0;
		}
	}
	if(submitted==1 && corner_sofa==1 && arightarm=="chaise" && aleftarm=="chaise")
	{
		resp=confirm("Warning: you have selected a corner sofa with two chaise ends. Is this correct?");
		if(resp==0) 
		{
			return 0;
		}
	}
	if(submitted==1 && corner_sofa==1 && arightarm=="no right arm" && aleftarm=="no left arm")
	{
		resp=confirm("Warning: you have selected a corner sofa without any arms. Is this correct?");
		if(resp==0) 
		{
			return 0;
		}
	}
	if(submitted==1 && asofabed=="single sofabed - yes" && sofabed_type==1)
	{
		resp=confirm("Warning: you have selected a single sofa bed. Is this correct?");
		if(resp==0) 
		{
			return 0;
		}
	}

	if(astorage.match("yes") && asofabed.match("yes") && corner!=1)
	{
		err=err+"You cannot have storage trays with a sofabed since they occupy the same space";
		//storage.selectedIndex=0;
	}
	
	if(astorage.match("yes") && sofabed_seat==1)
	{
		err=err+"You cannot have storage trays with a sofabed since they occupy the same space";
		storage.selectedIndex=0;
	}

	if(asofabed=="large double sofabed - yes" && aorientation=="lear chaise 4x3" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot select left chaise end for the Left Chaise option if you want a large sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear chaise 3x4" && arightchaise=="right chaise end")
	{
		err=err+"You cannot select right chaise end for the Right Chaise option if you want a large sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear chaise 3x4" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot select left chaise end for the Left Chaise option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear chaise 4x3" && arightchaise=="right chaise end")
	{
		err=err+"You cannot select right chaise end for the Right Chaise option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear chaise 3x2" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot select left chaise end for the Left Chaise option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear chaise 2x3" && arightchaise=="right chaise end")
	{
		err=err+"You cannot select right chaise end for the Right Chaise option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear chaise 4x2" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot select left chaise end for the Left Chaise option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear chaise 2x4" && arightchaise=="right chaise end")
	{
		err=err+"You cannot select right chaise end for the Right Chaise option if you want a sofabed\n";
	}
	if(asofabed=="lhs single sofabed" && armlesstype=="4" && (aleftarm=="no left arm" || aleftarm=="chaise"))
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="rhs single sofabed" && armlesstype=="4" && (arightarm=="no right arm" || arightarm=="chaise"))
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed!="sofabed - no" && armlesstype=="6" && arightarm=="no right arm" && aleftarm=="no left arm")
	{
		err=err+"You cannot have a sofabed with no arms\n";
	}
	if(asofabed!="sofabed - no" && armlesstype=="7" && arightchaise=="right chaise end" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot have a sofabed with no chaise ends\n";
	}
	if(asofabed=="lhs single sofabed" && armlesstype=="5" && aleftchaise=="left chaise end")
	{
		err=err+"You cannot select left chaise end for the Left Chaise option if you want a sofabed\n";
	}
	if(asofabed=="rhs single sofabed" && armlesstype=="5" && arightchaise=="right chaise end")
	{
		err=err+"You cannot select right chaise end for the Right Chaise option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="koi armless long lhs" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="koi armless long rhs" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
    if(asofabed=="single sofabed - yes" && aorientation=="lear armless 3x2" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm or for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear armless 2x3" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear armless 3x5" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm or for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear armless 5x3" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="xan armless 2x3" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm or for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="xan armless 3x2" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear armless 4x2" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear armless 2x4" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="ula armless 3x2" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="ula armless 2x3" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear armless 4x3" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a large sofabed\n";
	}
	if(asofabed=="large double sofabed - yes" && aorientation=="lear armless 3x4" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a large sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear armless 3x4" && aleftarm=="no left arm")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if(asofabed=="single sofabed - yes" && aorientation=="lear armless 4x3" && arightarm=="no right arm")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}
	if(asofabed=="rhs single sofabed" && aorientation=="lear 3x2")
	{
		err=err+"You cannot have a right hand side sofabed with this orientation";
	}
	if(asofabed=="lhs single sofabed" && aorientation=="lear 2x3")
	{
		err=err+"You cannot have a left hand side sofabed with this orientation";
	}
	if(aleftarm=="no left arm" && arightarm=="no right arm" && armlesstype=="1")
	{
		err=err+"You must have 1 of left or right arm";
	}
	if(aleftarm!="no left arm" && arightarm!="no right arm" && armlesstype=="1")
	{
		err=err+"One of the sides must be armless";
	}
	if((armlesstype=="2" || armlesstype=="4" || armlesstype=="6") && aleftarm!="no left arm" && arightarm!="no right arm")
	{
		err=err+"One of the sides must be armless";
	}
	if((armlesstype=="3" || armlesstype=="5" || armlesstype=="7") && aleftchaise!="left chaise end" && arightchaise!="right chaise end")
	{
		err=err+"One of the sides must be a chaise";
	}
	if((armlesstype=="8") && aleftsbarm!="chaise" && arightsbarm!="chaise")
	{
		err=err+"One of the arms must be a chaise";
	}
	if((armlesstype=="8" && aleftsbarm=="chaise" && asofabed=="lhs single sofabed") || (armlesstype=="8" && arightsbarm=="chaise" && asofabed=="rhs single sofabed"))
	{
		err=err+"The side of the sofa that the bed is on must have an arm";
	}
	
	if(armlesstype=="2" && ((aleftarm == "no left arm" && asofabed.match(/lhs/i)) || (arightarm == "no right arm" && asofabed.match(/rhs/i))))
	{
		err=err+"The side of the sofa that the bed is on must have an arm";
	}
	if((aorientation=="alda armless 3x2" || aorientation=="alda armless 3x5" || aorientation=="alda armless 3x4") && aleftarm == "no left arm" && asofabed != "sofabed - no")
	{
		err=err+"You cannot select No Left Arm for the Left Arm option if you want a sofabed\n";
	}
	if((aorientation=="alda armless 2x3" || aorientation=="alda armless 5x3" || aorientation=="alda armless 4x3") && arightarm == "no right arm" && asofabed != "sofabed - no")
	{
		err=err+"You cannot select No Right Arm for the Right Arm option if you want a sofabed\n";
	}

	if(fabric != null) {	
    	fabid=fabric.options[fabric.selectedIndex].value;
    	sgfabric=(scotchgards[fabid]);
	} else {
		sgfabric = 0;
	}

    if(ascotchgard=="scotchgard - yes" && sgfabric==0)
    {
		err=err+"You cannot have ScotchGard with your choice of fabric\n";
		//scotchgard.selectedIndex=0;
	}

	if(fast && apiping=="piping - yes")
	{
		err=err+"You cannot have piping with a fast delivery sofa\n";
		//piping.selectedIndex=0;
	}
	if(err!='')
	{
		err=err+"\nPlease change your selection\n";
		alert(err);
	}
	return (err=='');
}


function checkFast(fastfabs,standard_date,fast_date)
{
	var fabric=document.getElementById('Fabric');
	var afabric='';
	if(fabric)
	{
		afabric=fabric.options[fabric.selectedIndex].value;
		afabric='"a'+afabric+'"';
	}
	
	var item1=document.getElementById('deldate1');
	var item2=document.getElementById('deldate2');
	var sofadate='';
	var fast=0;
	var dirty=JSON.stringify(fastfabs);
	dirty=dirty.substring(1,dirty.length-1);
	dirty=dirty.split(",");
	var i;
	for (i=0;i<dirty.length;i=i+1)
	{
		var fabitem=dirty[i];
		parts=fabitem.split(":");
		if(parts[0]==afabric && parts[1]=='"1"')
		{
			fast=1;
		}
		
	}
	if(fast)
	{
		sofadate=fast_date;
	}
	else
	{
		sofadate=standard_date;
	}
	if(item1)
	{
		item1.innerHTML=sofadate;
	}
	if(item2)
	{
		item2.innerHTML=sofadate;
	}

}

/*
function updateFabricTotal(form)
{
	var total=0;
	var twotonedone=0;
	var piping_percentage=document.getElementById("piping_percentage").value;
	var piping_choice=document.getElementById('piping_selected').value;
	if(piping_choice=="No")
	{
		piping_percentage=0;
	}
	var quantity=document.getElementById("quantity").value;
	pulldown=document.getElementById("twotonesel");
	Item = pulldown.selectedIndex;
	twotonetext = pulldown.options[Item].text;
	pricestart = twotonetext.indexOf("(",0);
	priceend = twotonetext.indexOf(")",0);
	percentage= twotonetext.indexOf("%",0);
	addition=twotonetext.indexOf("+",0);
	if(addition>0)
	{
		twotoneprice = twotonetext.substring(pricestart+3, priceend);
	}
	else if(percentage>0)
	{
		twotoneprice = twotonetext.substring(pricestart+2, priceend-1);
	}
		
	for (var i = 0; i < form.elements.length; i++)
    {
    	var e = form.elements[i];
      	if (( e.type == 'checkbox' && e.checked) || (e.type=="text" && parseInt(e.value)>0))
      	{
      		var checkboxid=e.id;
      		checkboxid=checkboxid.split("_");
      		checkboxid=checkboxid[1];
      		var pricefield="price-"+checkboxid;
			var priceobject=document.getElementById(pricefield);
			var price=priceobject.innerHTML;
			price=price.substring(1);
			price=parseInt(price);
			
			if(e.type=="text")
			{
				price=price*parseInt(e.value);
			}
			
			var pricediff=price*(piping_percentage/100);
			pricediff=Math.floor(pricediff);
			pricediff=parseInt(pricediff);
			price=price+pricediff;
			
      		total=total+(price*quantity);
      		
      		if(addition>0 && twotonedone==0)
      		{
      			total=total+(twotoneprice*quantity);
      			twotonedone=1;
      		}
      		if(percentage>0)
			{
				var discount=price*(twotoneprice/100);
				discount=Math.floor(discount);
				total=total-(discount*quantity);
			}
		}
	}
	var totalfield=document.getElementById('totalcost');
	totalfield.innerHTML=total;
}*/

function updateFabricTotal(form)
{
	var total=0;
	var twotonedone=0;
	var twotone_percentage=0;
	var piping_percentage=document.getElementById("piping_percentage").value;
	var piping_choice=document.getElementById('piping_selected').value;
	var both_percentage=0;
	if(piping_choice=="No")
	{
		piping_percentage=0;
	}
	var quantity=document.getElementById("quantity").value;
	pulldown=document.getElementById("twotonesel");
	Item = pulldown.selectedIndex;
	twotonetext = pulldown.options[Item].text;
	if(twotonetext=="TT: Only Seats and Back")
	{
		twotone_percentage=30;
	}
	pricestart = twotonetext.indexOf("(",0);
	priceend = twotonetext.indexOf(")",0);
	percentage= twotonetext.indexOf("%",0);
	addition=twotonetext.indexOf("+",0);
	if(addition>0)
	{
		twotoneprice = twotonetext.substring(pricestart+3, priceend);
	}
	else if(percentage>0)
	{
		twotoneprice = twotonetext.substring(pricestart+2, priceend-1);
	}
	
	if(twotone_percentage && piping_percentage)
	{
		both_percentage=1;
	}	
	for (var i = 0; i < form.elements.length; i++)
    {
    	var e = form.elements[i];
    	if (( e.type == 'checkbox' && e.checked) || (e.type=="text" && parseInt(e.value)>0))
      	{
      		var checkboxid=e.id;
      		checkboxid=checkboxid.split("_");
      		checkboxid=checkboxid[1];
      		var pricefield="price-"+checkboxid;
			var priceobject=document.getElementById(pricefield);
			var price=priceobject.innerHTML;
			price=price.substring(1);
			price=parseInt(price);
			
			if(e.type=="text")
			{
				price=price*parseInt(e.value);
			}
			
			var pricediff=price*(piping_percentage/100);
			pricediff=Math.floor(pricediff);
			pricediff=parseInt(pricediff);
			
			if(both_percentage==0)
			{
				price=price+pricediff;
			}
			
			var pricediff2=price*(twotone_percentage/100);
			pricediff2=Math.floor(pricediff2);
			pricediff2=parseInt(pricediff2);
			
			if(both_percentage==0)
			{
				price=price-pricediff2;
			}
			
			if(both_percentage==1)
			{
				price=price+pricediff-pricediff2;
			}
			
      		total=total+(price*quantity);
      		
      		if(addition>0 && twotonedone==0)
      		{
      			total=total+(twotoneprice*quantity);
      			twotonedone=1;
      		}
      		if(percentage>0)
			{
				var discount=price*(twotoneprice/100);
				discount=Math.floor(discount);
				total=total-(discount*quantity);
			}
		}
	}
	var totalfield=document.getElementById('totalcost');
	totalfield.innerHTML=total;
}


function validateFabricChoices(form,finalch,sofatype)
{
	var prev_cat=0;
	var error=0;
	var oneseat=0;
	var armselected=0;
	var leftarm=0;
	var left1stseat=0;
	var left2stseats=0;
	var left1xwdseat=0;
	var right1stseat=0;
	var right2stseats=0;
	var right1xwdseat=0;
	var leftarmless=0;
	var rightarmless=0;
	var rightarm=0;
	var leftseat=0;
	var leftchaisearm=0;
	var rightchaisearm=0;
	var leftsofabed=0;
	var rightsofabed=0;
	var rightseat=0;
	var centerseat=0;
	var centre1stseat=0;
	var centre2stseats=0;
	var centre1wdseat=0;
	var xwideseat=0;
	var bed=0;
	var extension=0;
	var description='';
	var extwarn=0;
	for (var i = 0; i < form.elements.length; i++)
    {
    	var e = form.elements[i];
      	if ( e.type == 'checkbox' && e.checked)
      	{
      		var checkboxid=e.id;
      		var checkboxcat=checkboxid.split("_");
      		description=checkboxcat[3];
      		checkboxcat=checkboxcat[2];
      		if(finalch==1)
      		{
	      		var myRegExp = /1-Standard-Seat/;
				var matchPos1 = description.search(myRegExp);
				myRegExp = /1-Wide-Seat/;
				var matchPos2 = description.search(myRegExp);
				myRegExp = /1-XWide-Seat/;
				var matchPos3 = description.search(myRegExp);
				if(matchPos1!=-1 || matchPos2!=-1 || matchPos3!=-1)
				{
					oneseat=1;
				}
				myRegExp = /XWide-Seat/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					xwideseat=1;
				}
				myRegExp = /Left-Arm/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					armselected=1;
					leftarm=1;
					myRegExp = /Armless/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						leftarmless=1;
					}
					myRegExp = /Chaise/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						leftchaisearm=1;
					}
				}
				myRegExp = /LHS-Seats/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					leftseat=1;
					myRegExp = /Sofa-Bed/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						leftsofabed=1;
					}
					myRegExp = /1-Standard-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						left1stseat=1;
					}
					myRegExp = /2-Standard-Seats/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						left2stseats=1;
					}
					myRegExp = /1-XWide-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						left1xwdseat=1;
					}
				}
				myRegExp = /RHS-Seats/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					rightseat=1;
					myRegExp = /Sofa-Bed/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						rightsofabed=1;
					}
					myRegExp = /1-Standard-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						right1stseat=1;
					}
					myRegExp = /2-Standard-Seats/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						right2stseats=1;
					}
					myRegExp = /1-XWide-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						right1xwdseat=1;
					}
				}
				myRegExp = /Centre-Seats/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					centerseat=1;
					myRegExp = /1-Standard-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						centre1stseat=1;
					}
					myRegExp = /2-Standard-Seats/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						centre2stseats=1;
					}
					myRegExp = /1-Wide-Seat/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						centre1wdseat=1;
					}
				}
				myRegExp = /Centre-Section/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					centerseat=1;
				}
				myRegExp = /Right-Arm/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					armselected=1;
					rightarm=1;
					myRegExp = /Armless/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						rightarmless=1;
					}
					myRegExp = /Chaise/;
					var matchPos1 = description.search(myRegExp);
					if(matchPos1!=-1)
					{
						rightchaisearm=1;
					}
				}
				myRegExp = /Sofa-Bed/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					bed=1;
				}
				myRegExp = /Extension/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1)
				{
					extension=1;
				}
			}
			else
			{
				myRegExp = /Extension/;
				var matchPos1 = description.search(myRegExp);
				if(matchPos1!=-1 && !extwarn)
				{
					alert("A seat without an arm cannot be an extension seat");
					extwarn=1;
				}
			}
      		if(prev_cat==checkboxcat)
      		{
      			alert("You may only choose one item from each section");
      			//e.checked=0;
      			error=1;
      		}
      		prev_cat=checkboxcat;
   		}
	}
	if(finalch==1)
	{
		if(sofatype=="sofa")
		{
			if(!leftarm || !rightarm || !centerseat)
			{
				alert("You must select something from each section except extension seats");
				error=1;
			}
			if(oneseat && leftarmless && rightarmless)
			{
				alert("You must select an arm with 1 standard seat, 1 wide seat or 1 extra wide seat")
				error=1;
			}
			if(bed && (leftarmless || rightarmless))
			{
				alert("You must select an arm for each side with a bed");
				error=1;
			}
			if(xwideseat && extension)
			{
				alert("You may not select an extension set with an extra wide centre seat");
				error=1;
			}
		}
		if(sofatype=="corner")
		{
			if(!leftarm || !rightarm || !leftseat || !rightseat)
			{
				alert("You must select something from each section except extension seats");
				error=1;
			}
			if(((leftarmless || leftchaisearm) && leftsofabed) || ((rightarmless || rightchaisearm) && rightsofabed))
			{
				alert("You must have an arm on a side of a sofabed");
				error=1;
			}
			if((leftchaisearm && !left1stseat && !left2stseats && !left1xwdseat) || (rightchaisearm && !right1stseat && !right2stseats && !right1xwdseat))
			{
				alert("You can only have 1 standard seat, 2 standard seats or 1 extra wide seat on the same side as a chaise");
				error=1;
			}
		}
		if(sofatype=="ushape")
		{
			if(!leftarm || !rightarm || !centerseat || !leftseat || !rightseat)
			{
				alert("You must select something from each section except extension seats");
				error=1;
			}
			if(((leftarmless || leftchaisearm) && leftsofabed) || ((rightarmless || rightchaisearm) && rightsofabed))
			{
				alert("You must have an arm on a side of a sofabed");
				error=1;
			}
			if((leftchaisearm && !left1stseat && !left2stseats && !left1xwdseat) || (rightchaisearm && !right1stseat && !right2stseats && !right1xwdseat))
			{
				alert("You can only have 1 standard seat, 2 standard seats or 1 extra wide seat on the same side as a chaise");
				error=1;
			}
			if(leftsofabed && rightsofabed)
			{
				alert("You cannot have a sofabed on both the left and right sides");
				error=1;
			}
			if((leftsofabed || rightsofabed) && (centre1stseat || centre2stseats || centre1wdseat))
			{
				alert("You may not have 1 standard seat, 2 standard seats or 1 wide seat in the centre with a sofabed");
				error=1;
			}
		}
		if(sofatype=="accessories")
		{
			
		}
	}
	if(error==1) 
	{
		return false;
	}
	else
	{
		return true;
	}
}

function updatePartsTotal(form)
{
	var total=0;	
	for (var i = 0; i < form.elements.length; i++)
    {
    	var e = form.elements[i];
      	if ( e.type == 'text')
      	{
      		var fielddesc=e.id.split("_");
      		if(fielddesc[0]=="quantity" && parseInt(e.value)>0)
      		{
      			var quantity=parseInt(e.value);
      			var pricefield="price-"+fielddesc[1];
      			var frontandbackfield="frontandback-"+fielddesc[1];
 				var pulldown=document.getElementById(frontandbackfield);
 				var percentage=100;
 				if(pulldown)
 				{
					var Item = pulldown.selectedIndex;
					Item = pulldown.options[Item].text;
					var myRegExp = /Front/;
					var matchPos1 = Item.search(myRegExp);
					var myRegExp = /Rear/;
					var matchPos2 = Item.search(myRegExp);
					if(matchPos1!=-1 || matchPos2!=-1)
					{
						percentage=50;
					}
				}     			
				var priceobject=document.getElementById(pricefield);
				var price=priceobject.innerHTML;
				price=price.substring(1);
				price=parseInt(price);
				price=price*(percentage/100);
				price=Math.ceil(price);
	      		total=total+(price*quantity);
      		}
		}
	}
	var totalfield=document.getElementById('totalcost');
	totalfield.innerHTML=total;
}

function setQuantity(checkbox,fieldid)
{
	var quantity=0;
	if(checkbox.checked)
	{
		//quantity=document.getElementById("quantity").value;
		quantity=1;
	} 
	var elementname="quantity_"+fieldid;
	var element=document.getElementById(elementname);
	element.value=quantity;
}

function updateAllFabricQuantities(form)
{
	quantity=document.getElementById("quantity").value;
	for (var i = 0; i < form.elements.length; i++)
    {
    	var e = form.elements[i];
      	if ( e.type == 'hidden' && e.value>0)
      	{
      		e.value=quantity;
   		}
	}	
}