//Copyright 2002 CurtainShack and Sandy Point Soft Furnishings.  All Rights Reserved.
//Prod ID Structure
//p wwwww ddddd l i cc fff qqqqqq f ss ff rrrrrr ff fff ssss
//1 23456 78901 2 3 45 678 901234 5 67 89 012345 67 890 1234
//1 10000 10000 1 0 0 131 034600 0 1
function descprodtype(curtain)
{
	switch (parseFloat(curtain.slice(0,1)))
	{
		case 1:return "Curtain";break;
		case 2:return "Cushion";break;
		case 3:return "Curtain Pole";break;
		case 4:return "Pelmet";break;
		case 5:return "Tieback";break;
		case 6:return "Roman Blind";break;
		case 7:return "Accessory";break;
	}
}
function descwidth(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 3:
		case 4:
		case 6:
		case 1 :	return numstr(parseFloat(curtain.slice(1,6))/100,false);break;
		default:	return '';
	}
}
function descdrop(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		default:return '';break;
		case 6:
		case 4:
		case 1 :return numstr(parseFloat(curtain.slice(6,11))/100,false);
	}
}
function descfeature(curtain)
{
	var myfeature=parseFloat(curtain.slice(35,37));
	var myfeaturesize=parseFloat(curtain.slice(41,44))/100;
	var prodtype=parseFloat(curtain.slice(0,1));
	if (prodtype==6)
	{
		switch(myfeature)
		{
			default:	s= '';break;
			case 1: 	s= "Shaped Bottom ";break;
			case 2:		s= "Bottom Eyelet Punched Bottom ";break;
 			case 3:		s= "Tab Top ";break;
			case 11: 	s= "Zig-Zag Bottom ";break;
			case 21: 	s= "Border (bottom only) ";break;
			case 22: 	s= "Border (sides and bottom) "		;break;
			case 23: 	s= "Border (Sides Only) ";break;
 			case 24:	s= "Horizontal Band ";break;
		}
	}
	else
	{
		return "";
	}
	if (myfeaturesize>0&&myfeature>20)
		s=s+numstr(myfeaturesize,false)+" cm ";
	return s;
}
function descfeaturefabric(curtain)
{
	var myfeaturefabric=parseFloat(curtain.slice(37,40));
	var prodtype=parseFloat(curtain.slice(0,1));
	if (prodtype==6&&myfeaturefabric>=0)
	{
		if (myfeaturefabric==0)
			return "same fabric as blind";
		else
			return fabname(myfeaturefabric);
	}
	else
	{
		return "";
	}
}
function descfeaturesize(curtain)
{
	var myfeaturesize=parseFloat(curtain.slice(40,44))/100;
	var prodtype=parseFloat(curtain.slice(0,1));
	if (prodtype==6)
	{
			return numstr(myfeaturesize,false);
	}
	else
	{
		return "";
	}
}
function desclining(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 6:
		case 1: switch (parseFloat(curtain.slice(11,12))){case 1:return "Standard";break;case 2:return "Blackout";break;case 3:return "No Lining";break;};break;
		default:return '';
	}
}
function descfitting(curtain)
{
	var myfit=parseFloat(curtain.slice(27,29));
	switch(myfit)
	{
		case 11:return "Non-Recessed";break;
		case 12:return "In recess";break;
		case 1:return "Pole";break;
		case 2:return "Curtain Shack Metal Curtain Pole";break;
		case 3:return "Curtain Shack Wooden Curtain Pole";break;
		case 4:return "Track";break;
		default:return '';
	}
}
function descreturn(curtain)
{
	var myret=parseFloat(curtain.slice(29,35));
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 1: return 'Std Allowance';break;
		case 4: return numstr(parseFloat(myret)/100,false);break;
		default:return '';
	}
}
function descinterlining(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 6:
		case 1: switch (parseFloat(curtain.slice(12,13))){case 0:return "None";break;case 1:return "Interlined";break;};break;
		default:return '';
	}
}
function descconfig(curtain)
{
	var config=parseFloat(curtain.slice(13,15));
	switch (config)
	{
		case 1:return "Pair of curtains";break;
		case 2:return "Single Curtain";break;
		case 21:return "45cm square";break;
		case 22:return "50cm square";break;
		case 23:return "55cm square";break;
		case 24:return "60cm square";break;
		case 31:return "100cm";break;
		case 32:return "150cm";break;
		case 33:return "180cm";break;
		case 34:return "200cm";break;
		case 35:return "240cm";break;
		case 36:return "300cm";break;
		case 37:return "360cm";break;
		case 41:return "91cm";break;
		case 42:return "122cm";break;
		case 43:return "183cm";break;
		case 44:return "244cm";break;
		case 51:return "Left Drawpull";break;
		case 52:return "Right Drawpull";break;
		default: return '';
	}
}
function descfabric(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 1:
		case 4:
		case 5:
		case 6:
		case 2: return fabname(parseFloat(curtain.slice(15,18)));break;
		default: return '';
	}
}
function descquote(curtain)
{return numstr(parseFloat(curtain.slice(18,24))/100,true);}
function descfamily(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
	switch(prodtype)
	{
		case 6:
		case 1:
				if (vertrep(parseFloat(curtain.slice(15,18)))>0)
				{
					if (parseFloat(curtain.slice(24,25))==1) return "(no other items in this fabric in same room)";else return "(other curtains in this fabric in same room)";
				}
				else
				{
					return "";
				}
		default:return '';
	}
}
function descstyle(curtain)
{
	var mystyle=parseFloat(curtain.slice(25,27));
	switch(mystyle)
	{
		case 1:return "Pencil Pleat";break;
		case 2:return "Pinch Pleat";break;
		case 3:return "Tab Top";break;
		case 4:return "Eyelet 2cm";break;
		case 5:return "Eyelet 4cm";;break;
		case 21:return "Oxford";break;
		case 22:return "Piped";break;
		case 31:return "Crescent";break;
		case 41:return "Black Metal (Basket Finials)";break;
		case 42:return "Black Metal (Scroll Finials)";break;
		case 43:return "Black Metal (Fleur de Lys Finials)";break;
		case 44:return "Black Metal (Cannonball Finials)";break;
		case 51:return "Wooden Natural Finish";break;
		case 52:return "Wooden Rosewood Finish";break;
		case 53:return "Wooden Teak Finish";break;
		case 54:return "Wooden Walnut Finish";break;
		case 55:return "Wooden White Finish";break;
		case 61:return "Regular";break;
		case 62:return "Cascade";break;
		case 71:return "Hard";break;
		case 72:return "Soft (Vallance)";break;
		case 81:return "Black Metal Curved Holdback style H1";break;
		case 82:return "Black Metal Curved Holdback style H3";break;
		case 83:return "Black Metal Curved Holdback style H5";break;
		case 84:return "Black Metal Curved Holdback style H6";break;
		case 85:return "Black Metal Straight Holdback style SH5";break;
		case 86:return "Black Metal Tieback Hook";break;
		default:return '';
	}
}
function getquote(curtain)
{return parseFloat(curtain.slice(18,24))/100;}

function describe(curtain)
{
	var prodtype=parseFloat(curtain.slice(0,1));
  	var fabric=descfabric(curtain);
  	var width=descwidth(curtain);
  	var drop=descdrop(curtain);
  	var quote=descquote(curtain);
  	var family=descfamily(curtain);
  	var lining=desclining(curtain);
  	var interlining=descinterlining(curtain);
  	var config=descconfig(curtain);
  	var style=descstyle(curtain);
  	var ret=descreturn(curtain);
  	var fit=descfitting(curtain);
  	var feat=descfeature(curtain)+' in ' +descfeaturefabric(curtain);
  	s='';
  	pt=descprodtype(curtain);
  	switch (prodtype)
	{
			case 6: s=pt+' in '+fabric+', width '+width+' cm by drop '+drop+' cm. '+feat;break;
			case 1: s=pt+' in '+fabric+', width '+width+' cm by drop '+drop+' cm.';break;
			case 2: s=pt+' in '+fabric+', style '+style+', size '+config+'.';break;
			case 3: s=pt+' '+style+' size '+config+'.';break;
			case 4: s=pt+' '+style+' in '+fabric+'.';break;
			case 5: s=pt+' '+style+' in '+fabric+'.';break;
			case 7: s=pt+' '+style+'.';break;
	}
  	return s;
}
function Cookie(document)
{
    this.$document = document;
    this.$name = "curtainshack";
    var hours=240;
    this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    this.$path = null;
    this.$domain = null;
    this.$secure = false;
	this.numitems=0;
	this.prods="";
	this.M_subtotal=0;
	this.M_total=0;
	this.M_carriage=0;
	this.M_specs='';
	this.M_calcs='';
	this.M_deliverycountry='GB';
}
Cookie.prototype.store = function () {

    var cookieval = "";
    for(var prop in this) {
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';
    this.$document.cookie = cookie;
}
Cookie.prototype.load = function()
{
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;
    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;
    start += this.$name.length + 1;
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);
    var a = cookieval.split('&');
    for(var i=0; i < a.length; i++)
        a[i] = a[i].split(':');
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
    return true;
}
Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie = cookie;
}
Cookie.prototype.additem =function (q,prodtype)
{
	if (q.M_quote<=0)
		{
			alert('No total amount, item not added');
			return;
		}
	if (q.M_prodtype==0)
	{
		if (q.checkinputs()==false)
		{
			return;
		}
		if (q.M_drop<=0)
		{
			alert('Drop must be greater than zero, so item was not added');
			return;
		}
		if (q.M_width<=0)
		{
			alert('Width must be greater than zero, so the item was not added');
			return;
		}
	}
	//Multiply widths by 100 and save as integers
	var quotepence=Math.round(q.M_quote*100);
	var drop100=Math.round(q.M_drop*100);
	var width100=Math.round(q.M_width*100);
	var ret100=Math.round(q.M_return*100);
	var fs100=Math.round(q.M_featuresize*100);
	//
 	var prodid=q.M_prodtype.toString()+padnum(width100,5)+padnum(drop100,5)+q.M_lining.toString()+q.M_interlining.toString()+padnum(q.M_config,2)+padnum(q.M_fabric,3)+padnum(quotepence,6)+q.M_family.toString()+padnum(q.M_style,2)+padnum(q.M_fitting,2)+padnum(ret100,6)+padnum(q.M_feature,2)+padnum(q.M_featurefabric,3)+padnum(fs100,4);
 	this.numitems++;
 	this.prods=this.prods+'_'+prodid;
 	this.M_calcs=this.M_calcs+'_\n'+q.M_calc;
 	this.store();
 	this.calccart();
 	return;
}
Quote.prototype.load=function(curtainno)
{
}
Quote.prototype.update=function(curtainno)
{
}
Cookie.prototype.writetotal = function ()
{
	document.write(numstr(this.M_total,true));
}
Cookie.prototype.setspecs = function (specs)
{
	this.M_specs=specs;
	this.store();
}
Cookie.prototype.setdeliverycountry = function (deliverycountry)
{
	this.M_deliverycountry=deliverycountry;
	this.store();
}
Cookie.prototype.carriage = function (deliverycountry,numitems)
{
	heavies=this.numprods(1)+this.numprods(6)+this.numprods(4);
	separates=this.numprods(7)+this.numprods(3);
	lights=this.numprods(2)+this.numprods(5)/2;
	c=0;
	if (heavies>0)
	{
		if (heavies==1)
			c=8;
		if (heavies==2)
			c=10;
		if (heavies==3)
			c=12;
		if (heavies==4)
			c=14;
		else if (heavies<=5)
			c=16;
		else
			c=16+(heavies-5)*2;
	}
	if (separates>0)
	{
		c=c+7+(separates-1)*1.00;
	}
	if (lights>0)
		if (heavies>0)
			c=c+lights*1;
		else
			c=c+5+(lights-1)*1;
	return c;
}
Cookie.prototype.calccart = function ()
{
	this.M_subtotal=0.0;
 	curtains=this.prods.split("_");
 	for (i=1;i<= this.numitems;i++)
 	{
  		this.M_subtotal=this.M_subtotal+getquote(curtains[i]);
 	}
 	this.M_subtotal=sround(this.M_subtotal,0.01);
 	if (this.numitems>0)
 	{
 		this.M_carriage=this.carriage(this.M_deliverycountry,this.numitems);
 	}
 	else
 	{
 		this.M_carriage=0;
 	}
 	this.M_total=this.M_subtotal+this.M_carriage;
 	this.M_total=sround(this.M_total,0.01);
 	this.store();
}
Cookie.prototype.oktogo = function (form)
{
	this.load();
	if (this.numitems<=0)
	{
		alert ('Order not submitted: there are no items in your shopping cart');
	}
	else if (this.M_subtotal<=0||this.M_total<=0)
	{
		alert ('Order not submitted: your shopping cart has no monetary value');
	}
	else if (this.prods=="")
	{
		alert ('Order not submitted: there are no products in your cart');
	}
	else if (form.email.value=="")
	{
		alert ('Order not submitted: there is no email address');
	}
	else if (form.M_deliverypostcode.value=="")
	{
		alert ('Order not submitted: there is no delivery postcode');
	}
	else if (form.M_deliverycountry.value=="")
	{
		alert ('Order not submitted: there is no delivery country');
	}
	else if (form.M_address1.value==""&&form.M_address2.value=="")
	{
		alert ('Order not submitted: there is no address');
	}
	else if (form.M_state.value=="")
	{
		alert ('Order not submitted: there is no state/county');
	}
	else if (form.M_town.value=="")
	{
		alert ('Order not submitted: there is no delivery town');
	}
	else if (form.tel.value=="")
	{
		alert ('Order not submitted: there is no contact telephone');
	}
	else if (form.M_deliveryname.value=="")
	{
		alert ('Order not submitted: there is no name');
	}
	else
		return true;
	return false;
}
Cookie.prototype.checkover = function (form)
{
		form.action='checkover.php';
		form.submit();
}
Cookie.prototype.buy = function (form)
{
	if (this.oktogo(form))
	{
		form.action='transfer.php';
		form.M_orderid.value=this.prods;
		form.amount.value =this.M_total;
		form.desc.value=this.numitems.toString()+' items: ' +this.showord();
		form.M_subtotal.value=this.M_subtotal;
		form.M_carriage.value=this.M_carriage
		form.M_numitems.value=this.numitems;
		form.M_specs.value=this.M_specs;

		form.submit();
	}
}
Cookie.prototype.showord = function ()
{
	var s='';

 	curtains=this.prods.split("_");
 	for (i=1;i<= this.numitems;i++)
 	{
 		//could order later
 		if (this.numitems>1)
  			s=s+' ('+i.toString()+') '+describe(curtains[i]);
  		else
  			s=s+describe(curtains[i]);
 	}
 	return s;
}
Cookie.prototype.numprods=function(prodtype)
{
	var num=0;
	curtains=this.prods.split("_");
	for (i=1;i<= this.numitems;i++)
	{
		ptype=parseFloat(curtains[i].slice(0,1));
		if (ptype==prodtype)
			num++
	}
	return num;
}
Cookie.prototype.showcart = function (withfunc)
{
	curtains=this.prods.split("_");
	document.write('<TABLE class="cart">');
	fabreq=0;widreq=0;dropreq=0;famreq=0;liningreq=0;interliningreq=0;configreq=0;stylereq=0;retreq=0;fitreq=0;featreq=0;
	for (i=1;i<= this.numitems;i++)
	{
	 		fabreq=fabreq+parseInt(curtains[i].slice(15,18));
  			widreq=widreq+parseFloat(curtains[i].slice(1,6));
  			dropreq=dropreq+parseFloat(curtains[i].slice(0,1));
  			if (vertrep(parseFloat(curtains[i].slice(15,18)))>0)
  			{
  				famreq=famreq+parseFloat(curtains[i].slice(24,25));
  			}
  			liningreq=liningreq+parseFloat(curtains[i].slice(11,12));
  			interliningreq=interliningreq+parseFloat(curtains[i].slice(12,13));
  			configreq=configreq+parseFloat(curtains[i].slice(13,15));
  			stylereq=stylereq+parseFloat(curtains[i].slice(25,27));
  			retreq=retreq+parseFloat(curtains[i].slice(29,35));
  			fitreq=parseFloat(curtains[i].slice(27,29));
  			featreq=featreq+parseFloat(curtains[i].slice(35,37));
	}
	var cols=2;
	h='<COL><COL>';
	s='<THEAD><TR><TH class=cart><TH class=cart>Item';
	if (stylereq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Style';
		cols++;
	}
	if (configreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Configuration';
		cols++;
	}
	if (fabreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Fabric';
		cols++;
	}
	if (widreq>0)
	{
		h=h+'<COL style="text-align:right;">';
		s=s+'<TH class=cart>Width<BR>(cm)';
		cols++;
	}
	if (dropreq>0)
	{
		h=h+'<COL style="text-align:right;">';
		s=s+'<TH class=cart>Drop<BR>(cm)';
		cols++;
	}
	if (liningreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Lining';
		cols++;
	}
	if (interliningreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Interlining';
		cols++;
	}
	if (fitreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Fitting';
		cols++;
	}
	if (retreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Return';
		cols++;
	}
	if (featreq>0)
	{
		h=h+'<COL>';
		s=s+'<TH class=cart>Feature';
		cols++;
	}
	h=h+'<COL style="text-align:right;"><COL>';
	s=s+'<TH class=cart>Price<TH class=cart>';
	document.write(h);
 	itemno=0;
 	for (p=1;p<=7;p++)
 	{
	 	for (i=1;i<= this.numitems;i++)
	 	{
	 		ptype=parseFloat(curtains[i].slice(0,1));
	 		if (ptype==p)
	 		{
	 			itemno=itemno+1;
	  			s=s+'<TR class=bord><TD class=cart>'+itemno.toString()
	  			s=s+'<TD class=cart>'+descprodtype(curtains[i]);
				if (stylereq>0)
				{
					s=s+'<TD class=cart>'+descstyle(curtains[i]);
				}
				if (configreq>0)
				{
					s=s+'<TD class=cart>'+descconfig(curtains[i]);
				}
				if (fabreq>0)
				{
					s=s+'<TD class=cart>'+descfabric(curtains[i]);
					if (famreq>0)
					{
						s=s+' '+descfamily(curtains[i]);
					}
				}
				if (widreq>0)
				{
					s=s+'<TD class=cart>'+descwidth(curtains[i]);
				}
				if (dropreq>0)
				{
					s=s+'<TD class=cart>'+descdrop(curtains[i]);
				}
				if (liningreq>0)
				{
					s=s+'<TD class=cart>'+desclining(curtains[i]);
				}
				if (interliningreq>0)
				{
					s=s+'<TD class=cart>'+descinterlining(curtains[i]);
				}
				if (fitreq>0)
				{
					s=s+'<TD class=cart>'+descfitting(curtains[i]);
				}
				if (retreq>0)
				{
					s=s+'<TD class=cart>'+descreturn(curtains[i]);
				}
				if (featreq>0)
				{
					s=s+'<TD class=cart>'+descfeature(curtains[i])+descfeaturefabric(curtains[i]);
				}
				s=s+'<TD class=cart>'+descquote(curtains[i]);
	  			if (withfunc==true)
		  			s=s+'<TD class=cart><A HREF=javascript:curtaindata.deleteitem('+intstr(i)+')>'+'<SPAN TITLE="Click here to delete this curtain from your order" class=smallprint>Delete</SPAN></A>';
		  }
	 	}
 	}
 	this.calccart();
 	document.write(s);
 	document.write('<TR style="bordertop:thin green solid;background-color:#EEF3F7;"><TD colspan='+cols.toString()+'>Total:<TD>'+numstr(this.M_subtotal,true));
 	document.write('<TR style="background-color:#EEF3F7;"><TD colspan='+cols.toString()+'>Carriage:<TD>'+numstr(this.M_carriage,true));
 	document.write('<TR style="font-weight:bold;background-color:#EEF3F7;"><TD colspan='+cols.toString()+'>Grand Total:<TD>'+numstr(this.M_total,true));
 	document.write('</TABLE>');
 	document.write('<INPUT TYPE=hidden size=50 name="M_calcs"  VALUE="'+this.M_calcs+'">');
 	//alert ('dbg: showcart concluded successfully');
}
Cookie.prototype.updatespecs=function(form)
{
	form.M_specs.value=this.M_specs;
	form.M_deliverycountry.value=this.M_deliverycountry;
}
Cookie.prototype.edititem = function(itemno)
{
 	this.store();
}
Cookie.prototype.deleteitem = function(itemno)
{
 	curtains=this.prods.split("_");
 	curtains.splice(itemno,1);
 	this.prods=curtains.join('_');
 	this.numitems--;
 	calcs=this.M_calcs.split("_");
 	calcs.splice(itemno,1);
 	this.M_calcs=calcs.join('_');
 	this.store()
 	window.open(this.$document.URL,this.$name);
}
Cookie.prototype.updateorder = function(form,mode)
{
	if (mode==1)
	{
		form.M_orderid.value=this.prods;
		form.M_numitems.value=this.numitems;
		form.M_subtotal.value=this.M_subtotal;
		form.M_carriage.value=this.M_carriage;
		form.amount.value=this.M_total;
		form.M_specs.value=this.M_specs;
		form.M_deliverycountry.value=this.M_deliverycountry;
	}
}
Cookie.prototype.pushdescart=function(form)
{
	if (this.numitems==0)
	{
		form.descart.value='';
	}
	else if (this.numitems==1)
		form.descart.value='You have '+this.numitems+' item totalling £' +numstr(this.M_subtotal)+' in your order';
	else
		form.descart.value='You have '+this.numitems+' items totalling £' +numstr(this.M_subtotal)+' in your order';
}
function Quote(prodtype)
{
		this.M_prodtype=parseInt(prodtype);
		switch (prodtype)
		{
			case 1: this.M_lining=1;this.M_style=1;this.M_config=1;this.M_fitting=1;break;
			case 2: this.M_lining=0;this.M_style=21;this.M_config=21;this.M_fitting=0;break;
			case 3: this.M_lining=0;this.M_style=41;this.M_config=31;this.M_fitting=0;break;
			case 4: this.M_lining=0;this.M_style=71;this.M_config=0;this.M_fitting=0;break;
			case 5: this.M_lining=0;this.M_style=31;this.M_config=0;this.M_fitting=0;break;
			case 6: this.M_lining=1;this.M_style=61;this.M_config=51;this.M_fitting=11;break;
			case 7: this.M_lining=0;this.M_style=81;this.M_config=0;this.M_fitting=0;break;;;
			default: alert('illegal product type');
		}
		this.M_calc='';
		//this.M_fabric=defaultfabric();		//could be set to -1 for 'select'
		this.M_fabric=0;
		this.M_width=0;
		this.M_drop=0;
		this.M_interlining=0;
		this.M_quote=0;
		this.M_family=0;
		this.M_patterndrop=0;
		this.M_return=0;
		this.M_vat=0.0;
		this.M_fabricprice=0;
		//this.M_featureprice=0;
		//this.M_featurefabricprice=0;
		this.M_featuresize=5;
		this.M_labourprice=0;
		this.M_liningprice=0;
		this.M_interliningprice=0;
		this.M_lininglength=0;
		this.M_interlininglength=0;
		this.M_fabriclength=0;
		this.d=0;
		this.M_labourwidths=0;
		this.M_fabricwidths=0;
		this.setupcharge=15;
		this.vatrate=0;
		this.M_feature=0;
		this.M_featurefabric=0;
}
Quote.prototype.checkdrop =function(drop)
{
	if(drop>300)
	{
		alert('Error: your drop ('+numstr(drop,true)+') is greater than the maximum of 300 cm');
		return false;
	}
	else if(drop<40&&drop!=0)
	{
		alert('Error: your drop ('+numstr(drop,true)+') is less than the minimum of 40 cm');
		return false;
	}
	else
	{
		return true;
	}
}
Quote.prototype.checkwidth =function(width)
{
	if (this.M_prodtype==6&&width>260)
	{
		alert("Can't have a blind wider than 260cm");
		return false;
	}
	else if (width>500)
	{
		alert('Error: your width ('+numstr(width,true)+') is greater than the maximum of 500 cm');
		return false;
	}
	else if (width<35&&width!=0)
	{
		alert('Error: your width ('+numstr(width,true)+') is less than the minimum of 35 cm');
		return false;
	}
	else
	{
		return true;
	}
}
Quote.prototype.checkstylefeature =function()
{
	if (this.M_prodtype==6)
	{
		if (this.M_style==62&&(this.M_feature==1||this.M_feature==2||this.M_feature==11))
		{
			alert ('You cannot have a cascade blind with that particular feature, check your inputs');
			return false;
		}
	}
	return true;
}
Quote.prototype.checkinputs = function()
{
	if (this.checkdrop(this.M_drop)==false||this.checkwidth(this.M_width)==false)
	{
		return false;
	}
	return true;
}
Quote.prototype.cushcalc = function()
{
	var fcost,padcost,labourcost,fabreq;
	if (this.M_fabric<=0)
		this.M_quote=0;
	else
	{
		fcost=fabcost(this.M_fabric);
		labourcost=15;
		switch(this.M_config)
		{
			case 21:	padcost=4;fabreq=0.50;break;
			case 22:  	padcost=5;fabreq=0.55;labourcost=labourcost*1.1;break;
			case 23:	padcost=6;fabreq=0.60;labourcost=labourcost*1.2;break;
			case 24:  	padcost=7;fabreq=0.65;labourcost=labourcost*1.3;break;
		}
		switch (this.M_style)
		{
			case 21:	break;
			case 22:	labourcost=labourcost*1.1;break;
		}
		this.M_quote=padcost+labourcost+fcost*fabreq;
	}
}
Quote.prototype.pelmcalc = function()
{
	if (this.M_width<=0||this.M_drop<=0||this.M_fabric<=0)
		this.M_quote=0;
	else
	{
		switch(this.M_style)
		{
			case 71:	ft=sceiling(this.M_width/30,1);
						widths=sceiling(this.M_width/135,1)
						labourprice=8*1.6*ft;
						break;
			case 72:	widths=sceiling(this.M_width*2.3/135,1)
						labourprice=widths*14;
						break;
		}
		fabricprice=widths*(this.M_drop+10)/100*fabcost(this.M_fabric);
		this.M_quote=labourprice+fabricprice;
	}
}
Quote.prototype.tiecalc = function()
{
	if (this.M_fabric<=0)
		this.M_quote=0;
	else
	{
		this.M_labourprice=13;
		this.M_fabricprice=fabcost(parseFloat(this.M_fabric))*0.5;
		this.M_quote=this.M_labourprice+this.M_fabricprice;
	}
}
Quote.prototype.acccalc = function()
{
	var markup=1.3;
	var c;
	switch (this.M_style)
	{
		case 81:	c=22.4;break;
		case 82:	c=22.4;break;
		case 83: 	c=22.4;break;
		case 84: 	c=22.4;break;
		case 85: 	c=14.56;break;
		case 86: 	c=5.04;break;
	}
	this.M_quote=sceiling(c*markup*1.175,0.50);
}

Quote.prototype.polecalc = function()
{
	var markup=1.3;
	var c;
	switch (this.M_style)
	{
		case 41:	switch(this.M_config){case 31:c=43;break;case 32:c=47;break;case 34:c=60;break;case 36:c=70;break;};break;
		case 42:	switch(this.M_config){case 31:c=43;break;case 32:c=47;break;case 34:c=60;break;case 36:c=70;break;};break;
		case 43: 	switch(this.M_config){case 31:c=41;break;case 32:c=45;break;case 34:c=58;break;case 36:c=68;break;};break;
		case 44: 	switch(this.M_config){case 31:c=38;break;case 32:c=42;break;case 34:c=55;break;case 36:c=65;break;};break;
		case 51:
		case 52:
		case 53:
		case 54:
		case 55: 	switch(this.M_config){case 33:c=16.50;break;case 35:c=21.50;break;case 36:c=25.50;break;case 37:c=28.50;break;};break;
	}
	this.M_quote=sceiling(c*markup*1.175,0.50);
}
Quote.prototype.calc = function()
{
	if (this.checkinputs()==false) return;
	if (this.M_drop<=0||this.M_width<=0||this.M_fabric<=0)
	{
		this.M_quote=0;
		return;
	}
 	if (this.M_config==2)
 		numcurts=1;
 	else
 		numcurts=2;
 	pleatsperwid=4;
 	switch(this.M_style)
 	{
 		case 1:	this.M_labourprice=21;
 				topallowance=20;
 				springback=1.075;
 				targetfullness=2.5;
 				targetpleatsize=18.75;
 				overlap=15;
 				break;
 		case 2:	this.M_labourprice=23;
 				topallowance=25;
				targetfullness=2.5;
 				targetpleatsize=18.75;
 				springback=1.075;
 				overlap=15;
 				break;
 		case 3:	this.M_labourprice=26;
 				topallowance=30;
 				targetfullness=1.5;
 				targetpleatsize=18.75;
 				springback=1.075;
 				overlap=15;
 				break;
 		case 4: this.M_labourprice=26;
 				topallowance=35;
 				targetfullness=1.5;
 				targetpleatsize=18.75;
 				springback=1.075;
 				overlap=15;
 				break;
 		case 5: this.M_labourprice=26;
 				topallowance=35;
 				targetfullness=1.5;
 				targetpleatsize=18.75;
 				springback=1.075;
 				overlap=15;
 				break;
 		default: alert('illegal curtain style');
 				 abort();
 	}
 	lastpleaterror=99;
 	lastfullnesserror=99;
 	lastwidths=0;
 	this.M_fabricwidths=sceiling(this.M_width*targetfullness/135,1);
 	for (i=1;i<=20;i++)
 	{
 		fullness=this.M_fabricwidths*135/this.M_width;
 		pleatsize=(135-(this.M_width*springback+numcurts*overlap)/this.M_fabricwidths)/pleatsperwid;
 		pleaterror=targetpleatsize-pleatsize;
 		fullnesserror=targetfullness-fullness;
 		if (Math.abs(pleaterror)>Math.abs(lastpleaterror))
 		{
 			this.M_fabricwidths=lastwidths;
 			break;
 		}
 		lastwidths=this.M_fabricwidths;
 		if (pleaterror<0)
 			this.M_fabricwidths++;
 		else
 			this.M_fabricwidths--;
 		lastpleaterror=pleaterror;
 		lastfullnesserror=fullnesserror;
 	}
 	if (i>=20||this.M_fabricwidths<=0) alert ("Sorry, the width calculation for your curtain failed, please email us with your requirements ("+fabricwidths.toString()+")");
 	if (this.M_config==2) 	//single curtain
 		this.M_labourwidths=this.M_fabricwidths;
 	else
 		this.M_labourwidths=sceiling(this.M_fabricwidths/2,1)*2; //pair
 	if (this.M_interlining==1)
 		this.M_labourprice=this.M_labourprice+8;
 	this.M_labourprice=this.M_labourprice*this.M_labourwidths;
 	var verticalrepeat=vertrep(this.M_fabric);
	if (this.M_family==0&&verticalrepeat>0)
    	this.M_patterndrop=Math.round(this.M_drop/verticalrepeat+.5)*verticalrepeat;
  	else
    	this.M_patterndrop=this.M_drop;
 	this.M_fabriclength=sceiling((this.M_patterndrop+topallowance)*this.M_fabricwidths,10);
 	this.M_fabricprice=this.M_fabriclength/100*fabcost(this.M_fabric);
    this.M_lininglength=this.M_fabriclength;
    if (this.M_interlining==1)
    {
    	this.M_interlininglength=this.M_fabriclength;
    	this.M_interliningprice=this.M_interlininglength*4/100;
	}
	else
		this.M_interliningprice=0;
  	switch (this.M_lining)
  	{
    	case 1:	liningcost=3.50;
    			break;
    	case 2: liningcost=5.50;
    			break;
    	case 3: liningcost=0;
    			break;
    	default: alert('illegal lining type');
  	};
  	this.M_liningprice=this.M_lininglength*liningcost/100;
  	this.M_quote=sround(this.M_labourprice+this.M_liningprice+this.M_interliningprice+this.M_fabricprice+this.setupcharge,0.01);;
  	this.M_vat=sround(this.vatrate*(this.M_quote),0.01);
  	this.M_quote=this.M_quote+this.M_vat;
  	this.M_quote=sround(this.M_quote,0.01);
  	this.M_calc='PARAMETERS\nFabric Length  '+numstr(this.M_fabriclength);
  	this.M_calc=this.M_calc+'\nLining Length  '+numstr(this.M_lininglength);
  	this.M_calc=this.M_calc+'\nFabric Widths  '+numstr(this.M_fabricwidths);
  	this.M_calc=this.M_calc+'\nLabour Widths  '+numstr(this.M_labourwidths);
  	this.M_calc=this.M_calc+'\nPRICE BREAKDOWN:'
  	this.M_calc=this.M_calc+'\nLabour         '+numstr(this.M_labourprice);
  	this.M_calc=this.M_calc+'\nLining Fabric  '+numstr(this.M_liningprice);
  	this.M_calc=this.M_calc+'\nInterLining c  '+numstr(this.M_interliningprice);
  	this.M_calc=this.M_calc+'\nMain Fabric    '+numstr(this.M_fabricprice);
  	this.M_calc=this.M_calc+'\nSetup          '+numstr(this.setupcharge);
  	if (this.M_VAT>0) this.M_calc=this.M_calc+'\nVAT            '+numstr(this.M_VAT);
  	this.M_calc=this.M_calc+'\nTOTAL curtain    '+numstr(this.M_quote)+'\n';
  	return this.M_quote;
}
Quote.prototype.romcalc = function()
{
	//alert('dbg: romcalc');
	if (this.checkinputs()==false) return;
  	if (this.M_drop==0||this.M_width==0||this.M_fabric<=0)
  	{
    	M_quote=0;
		return 0;
 	}
 	var widthft=sceiling(this.M_width/30,0.5);
 	var dropft=sceiling(this.M_drop/30,0.5);
  	var sqft=widthft*dropft;
  	this.M_labourprice=sqft*5.25;
  	if (this.M_style==62)
  	{
  		this.M_labourprice=this.M_labourprice*(1+.1*0);//premium for cascade removed oct07
  	}
  	if (this.M_interlining==1)
  	{
  		this.M_labourprice=this.M_labourprice+3*sqft;
  		interliningcost=4;
  	}
  	else
  	{
  		interliningcost=0;
  	}
  	verticalrepeat=vertrep(this.M_fabric);
	if (this.M_family==0&&verticalrepeat>0)
    	this.M_patterndrop=Math.round(this.M_drop/verticalrepeat+.5)*verticalrepeat;
  	else
    	this.M_patterndrop=this.M_drop;
  	if (this.M_width>125)
  		{
      	this.M_fabriclength=this.M_patterndrop*2;
      	numwidths=2;
        }
  	else
  		{
    	this.M_fabriclength=this.M_patterndrop;
    	numwidths=1;
    	}
    this.M_fabriclength=sceiling(this.M_fabriclength,10);
    var fabriccost=fabcost(this.M_fabric);
    this.M_fabriclength=this.M_fabriclength+20*numwidths;
    this.M_lininglength=sceiling(this.M_drop*numwidths,10);
    var pocketallowance=0.1;
  	switch (this.M_lining)
  	{
    	case 1:	liningcost=3.50;
    			this.M_lininglength=this.M_lininglength*(1+pocketallowance);
    			break;
    	case 2: liningcost=5.50;
    			this.M_lininglength=this.M_lininglength*(1+pocketallowance);
    			break;
    	case 3: liningcost=0;
    			this.M_fabriclength=this.M_fabriclength*(1+pocketallowance);
    			break;
  	};
  	this.M_fabricprice=this.M_fabriclength*fabriccost/100;
  	//Add'l Features
  	switch(this.M_feature)
  	{
  			case 1: 	this.M_labourprice=this.M_labourprice+widthft*6;break;//Shaped Bottom
			case 2:		this.M_labourprice=this.M_labourprice+widthft*6;break;//Bottom Eyelet Punched Bottom
 			case 3:		break;//Tab Top
			case 11: 	if (this.M_featurefabric!=this.M_fabric&&this.M_featurefabric>0)
						{
							this.M_labourprice=this.M_labourprice+widthft*7;
							this.M_fabricprice=this.M_fabricprice+0.5*fabcost(this.M_featurefabric)*numwidths;
						}
						else
						{
							this.M_labourprice=this.M_labourprice+widthft*6;
				    	}
				    	break;
			case 21:  	this.M_labourprice=this.M_labourprice+1.5*sceiling(this.M_width,10)/30;
						if (this.M_featurefabric!=this.M_fabric&&this.M_featurefabric>0)
						{
							this.M_fabricprice=this.M_fabricprice+((this.M_featuresize+10)*numwidths)/100*fabcost(this.M_featurefabric);
						}
						break;//Border (bottom only)
			case 22:  	this.M_labourprice=this.M_labourprice+1.5*(sceiling(this.M_drop,10)/30*2*(1+pocketallowance)+sceiling(this.M_width,10)/30)+8;
						//alert('dbg: '+this.M_featurefabric);
						if (this.M_featurefabric!=this.M_fabric&&this.M_featurefabric>0)
						{
							//alert('dbg: '+this.M_featuresize);
							this.M_fabricprice=this.M_fabricprice+(this.M_drop+10+(this.M_featuresize+10)*numwidths)/100*fabcost(this.M_featurefabric);
						}
						break;//Border (sides and bottom)
			case 23:  	this.M_labourprice=this.M_labourprice+1.5*(sceiling(this.M_drop,10)/30*2*(1+pocketallowance));
						if (this.M_featurefabric!=this.M_fabric&&this.M_featurefabric>0)
						{
							this.M_fabricprice=this.M_fabricprice+(this.M_drop+10)/100*fabcost(this.M_featurefabric);
						}
					  	break; 			//Border (Sides Only)
			case 24: 	this.M_labourprice=this.M_labourprice+1.5*sceiling(this.M_width,10)/30;
						if (this.M_featurefabric!=this.M_fabric&&this.M_featurefabric>0)
						{
							this.M_fabricprice=this.M_fabricprice+((this.M_featuresize+10)*numwidths)/100*fabcost(this.M_featurefabric);
						}
 						break; 			//Horizontal Band
  	}
  	//lining
  	this.M_lininglength=this.M_lininglength+10;
  	this.M_liningprice=this.M_lininglength*liningcost/100;
  	this.M_interlininglength=this.M_lininglength;
  	this.M_interliningprice=this.M_interlininglength*interliningcost/100;
  	//final calcs
  	this.M_quote=sround(this.M_labourprice+this.M_liningprice+this.M_interliningprice+this.M_fabricprice+this.setupcharge,0.01);;
  	this.M_vat=sround(this.vatrate*(this.M_quote),0.01);
  	this.M_quote=this.M_quote+this.M_vat;
  	this.M_quote=sround(this.M_quote,0.01);
  	this.M_calc='PARAMETERS\nFabric Length  '+numstr(this.M_fabriclength)
  	this.M_calc=this.M_calc+'\nLining Length  '+numstr(this.M_lininglength)
  	this.M_calc=this.M_calc+'\nPRICE BREAKDOWN:'
  	this.M_calc=this.M_calc+'\nLabour         '+numstr(this.M_labourprice)+'  ('+numstr(sqft)+' sqft x '+numstr(this.labourrate)+' x ( 1 + '+numstr(this.M_pocktype)+' x '+numstr(this.cascadepremium)+') )';
  	this.M_calc=this.M_calc+'\nLining Fabric  '+numstr(this.M_liningprice);
  	this.M_calc=this.M_calc+'\nInterLining Fabric'+numstr(this.M_interliningprice);
  	this.M_calc=this.M_calc+'\nMain Fabric    '+numstr(this.M_fabricprice)+'  ('+numstr(this.M_fabriclength/100)+'m x '+numstr(fabriccost)+')';
  	this.M_calc=this.M_calc+'\nSetup          '+numstr(this.setupcharge);
  	if (this.M_vat>0) this.M_calc=this.M_calc+'\nVAT            '+numstr(this.M_vat);
  	this.M_calc=this.M_calc+'\nTOTAL BLIND    '+numstr(this.M_quote)+'\n';
  	//alert (this.M_calc);
  	return this.M_quote;
}
Quote.prototype.popfab = function(fab)
{
	//popfab(this.M_fabric);
	popfab(parseInt(fab));
}
function checkhighlight(swatchrangeobj,swatchobj)
{
	if (swatchobj.value<=0)
	{
		swatchobj.style.color='#0000FF';
	}
	else
	{
		swatchobj.style.color='black';
	}
	if (swatchrangeobj.value<=0)
	{
		swatchrangeobj.style.color='#0000FF';
	}
	else
	{
		swatchrangeobj.style.color='black';
	}
}
Quote.prototype.updatecushform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	updatefabricfields(form,this.M_fabric);
	form.M_fabric.value=this.M_fabric;
	form.M_style.value=this.M_style;
	form.M_config.value=this.M_config;
	updatefabricthumb(form,this.M_fabric);
	this.cushcalc();
	form.M_quote.value=numstr(this.M_quote,true);
}
Quote.prototype.changeconfig = function(form)
{
	switch (this.M_style)
	{
		case 41:
		case 42:
		case 43:
		case 44:	form.M_config.options.length=0;
					form.M_config.options.length=4;
					form.M_config.options[0]=new Option("100cm", "31") ;
					form.M_config.options[1]=new Option("150cm", "32");
					form.M_config.options[2]=new Option("200cm", "34");
					form.M_config.options[3]=new Option("300cm", "36");
					switch (this.M_config)
					{
						case 33:	this.M_config=34;break;
						case 35:	this.M_config=34;break;
						case 37:	this.M_config=36;break;
					}
					break;
		case 51:
		case 52:
		case 53:
		case 54:
		case 55:	form.M_config.options.length=0;
					form.M_config.options.length=4;
					form.M_config.options[0]=new Option("180cm", "33");
					form.M_config.options[1]=new Option("240cm", "35");
					form.M_config.options[2]=new Option("300cm", "36");
					form.M_config.options[3]=new Option("360cm", "37");
					switch (this.M_config)
					{
						case 31:	this.M_config=33;break;
						case 32:	this.M_config=33;break;
						case 34:	this.M_config=35;break;
					}
					break;
	}
	form.M_config.value=this.M_config;
}
Quote.prototype.updatepoleform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	form.M_style.value=this.M_style;
	form.M_config.value=this.M_config;
	this.polecalc();
	form.M_quote.value=numstr(this.M_quote,true);
}
function updatefabricthumb(form,fabno)
{
	//alert('updatefabricthumb');
	if (fabno>0)
	{
		form.fabricthumb.src='http://www.romansdirect.co.uk/fabrics/fab'+fabno.toString()+'t.jpg';
		form.fabricthumb.title='click for a larger picture of '+fabname(fabno);
		reveal(form.fabricthumb);
	}
	else
	{
		hide(form.fabricthumb);
	}
}
function updatefeaturefabricthumb(form,fabno)
{
	//alert('updatefeaturefabricthumb');
	if (fabno>0)
	{
		form.featurefabricthumb.src='http://www.romansdirect.co.uk/fabrics/fab'+fabno.toString()+'t.jpg';
		form.featurefabricthumb.title='click for a larger picture of '+fabname(fabno);
		reveal(form.featurefabricthumb);
	}
	else
	{
		hide(form.featurefabricthumb);
	}
}
function updatefabricfields(form,fabno)
{
	//alert('updatefabricfields');
	checkhighlight(form.fabricrange,form.M_fabric);
	if (fabno>=0)
		form.fabricrange.value=fabricrangelookup(fabno);
	fabricpopulate(parseInt(form.fabricrange.value),form.M_fabric,1);
}
function updatefeaturefabricfields(form,fabno)
{
	//alert('dbg:beg updatefeaturefabricfields feature fabric='+form.M_featurefabric.value);
	checkhighlight(form.featurefabricrange,form.M_featurefabric);
	if (fabno>=0)
		form.featurefabricrange.value=fabricrangelookup(fabno);
	//alert('dbg:just before updatefeaturefabricfields feature fabric='+form.M_featurefabric.value);
	//NEED TO KNOW WHEN RANGE HAS CHANGED AND WE NEED TO REST FAB BACK TO -1.
	//WE WILL NEED A COOKIE VAR TO HOLD THE CURRENT VALUE OF THE RANGE, ONE FOR FAB AND ONE FOR FEATURE FAB.
	fabricpopulate(parseInt(form.featurefabricrange.value),form.M_featurefabric,1);
	//alert('dbg:end updatefeaturefabricfields feature fabric='+form.M_featurefabric.value);
}
Quote.prototype.updateform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	updatefabricfields(form,this.M_fabric);
	form.M_fabric.value=this.M_fabric;
	form.M_width.value=numstr(this.M_width,false);
	form.M_drop.value=numstr(this.M_drop,false);
	form.M_style.value=this.M_style;
	form.M_config.value=this.M_config;
	form.M_family.value=this.M_family;
	form.M_lining.value=this.M_lining;
	form.M_fitting.value=this.M_fitting;
	form.M_interlining.value=this.M_interlining;
	updatefabricthumb(form,this.M_fabric);
	if (vertrep(this.M_fabric)>0)
	{
		reveal(form.M_family);
	}
	else
	{
		hide(form.M_family);
	}
	this.calc();
	form.M_quote.value=numstr(this.M_quote,true);
}
Quote.prototype.updateromform = function(form)
{
	//alert ('dbg:updateromform');
	form.M_prodtype.value=this.M_prodtype;
	updatefabricfields(form,this.M_fabric);
	updatefabricthumb(form,this.M_fabric);
	form.M_fabric.value=this.M_fabric;
	form.M_width.value=numstr(this.M_width,false);
	form.M_drop.value=numstr(this.M_drop,false);
	form.M_style.value=this.M_style;
	form.M_config.value=this.M_config;
	form.M_family.value=this.M_family;
	form.M_lining.value=this.M_lining;
	form.M_interlining.value=this.M_interlining;
	form.M_fitting.value=this.M_fitting;
	this.M_feature=parseInt(this.M_feature)	;
	if (form.M_feature!=undefined) form.M_feature.value=this.M_feature;
	if (this.M_style==62)
		form.stylegif.src="cascade.GIF";
	else
		form.stylegif.src="regular.GIF";
	switch (this.M_feature)
	{
			case 0:
			default:	form.featgif.src='featblank.GIF';break;
			case 1: 	form.featgif.src='shaped.GIF';break;
			case 2:		form.featgif.src='eyelet.GIF';break;
 			case 3:		form.featgif.src='tabtop.GIF';break;
			case 11: 	form.featgif.src='zigzag.GIF';break;
			case 21: 	form.featgif.src='bot.GIF';break;
			case 22: 	form.featgif.src='botsides.GIF';break;
			case 23: 	form.featgif.src='sides.GIF';break;
 			case 24:	form.featgif.src='band.GIF';break;
    }
	if (vertrep(this.M_fabric)>0)
	{
		reveal(form.M_family);
	}
	else
	{
		hide(form.M_family);
	}
	if (form.M_featurefabric!=undefined&&form.M_feature!=undefined)
	{
		form.M_featurefabric.value=this.M_featurefabric;
		form.M_featuresize.value=numstr(this.M_featuresize,false);
		updatefeaturefabricfields(form,this.M_featurefabric);
		updatefeaturefabricthumb(form,this.M_featurefabric);
		switch(this.M_feature)
		{
			case 11:	form.featurefabriclabel.value="Bottom Fabric:";break;
			case 21:
			case 22:
			case 23:	form.featuresizelabel.value="Width of border (cm):";
						form.featurefabriclabel.value="Border Fabric:";
						break;
			case 24:	form.featuresizelabel.value="Width horiz band (cm):";
						form.featurefabriclabel.value="Band Fabric:";
						break;
			default:	form.featuresizelabel.value="Width of feature (cm):";
						form.featurefabriclabel.value="Feature Fabric:";
		}
		if (this.M_feature>10&&this.M_feature<30)
		{
			reveal(form.M_featurefabric);
			reveal(form.featurefabricrange);
			reveal(form.featurefabricthumb);
			reveal(form.featureshortbox);
			reveal(form.featurefabriclabel);
			if (this.M_feature!=11)
			{
				reveal(form.M_featuresize);
				reveal(form.featuresizelabel);
			}
		}
		else
		{
			hide(form.M_featurefabric);
			hide(form.featurefabricrange);
			hide(form.featurefabricthumb);
			hide(form.featureshortbox);
			hide(form.featurefabriclabel);
			if (this.M_feature!=11)
			{
				hide(form.M_featuresize);
				hide(form.featuresizelabel);
			}
		}
	}
	this.romcalc();
	form.M_quote.value=numstr(this.M_quote,true);
	//alert ('dbg:end updateromform');
}
Quote.prototype.updatepelmform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	updatefabricfields(form,this.M_fabric);
	form.M_fabric.value=this.M_fabric;
	form.M_width.value=numstr(this.M_width,false);
	form.M_drop.value=numstr(this.M_drop,false);
	form.M_return.value=numstr(this.M_return,false);
	form.M_style.value=this.M_style;
	updatefabricthumb(form,this.M_fabric);
	this.pelmcalc();
	form.M_quote.value=numstr(this.M_quote,true);
}
Quote.prototype.updateaccform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	form.M_style.value=this.M_style;
	this.acccalc();
	form.M_quote.value=numstr(this.M_quote,true);
}
Quote.prototype.updatetieform = function(form)
{
	form.M_prodtype.value=this.M_prodtype;
	updatefabricfields(form,this.M_fabric);
	form.M_fabric.value=this.M_fabric;
	form.M_style.value=this.M_style;
	updatefabricthumb(form,this.M_fabric);
	this.tiecalc();
	form.M_quote.value=numstr(this.M_quote,true);
}
Quote.prototype.setlining = function(lining,form)
{
	this.M_lining=parseInt(lining);
	this.updateform(form);
}
Quote.prototype.setromlining = function(lining,form)
{
	this.M_lining=parseInt(lining);
	this.updateromform(form);
}
Quote.prototype.setinterlining = function(interlining,form)
{
	this.M_interlining=parseInt(interlining);
	this.updateform(form);
}
Quote.prototype.setrominterlining = function(interlining,form)
{
	this.M_interlining=parseInt(interlining);
	this.updateromform(form);
}
Quote.prototype.setconfig = function(config,form)
{
	this.M_config=parseInt(config);
	this.updateform(form);
}
Quote.prototype.setromconfig = function(config,form)
{
	this.M_config=parseInt(config);
	this.updateromform(form);
}
Quote.prototype.setcushconfig = function(config,form)
{
	this.M_config=parseInt(config);
	this.updatecushform(form);
}
Quote.prototype.setpoleconfig = function(config,form)
{
	this.M_config=parseInt(config);
	this.updatepoleform(form);
}
Quote.prototype.setstyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.updateform(form);
}
Quote.prototype.setaccstyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.updateaccform(form);
}

Quote.prototype.setromfeature = function(feature,form)
{
	//alert('dbg: setromfeature');
	this.checkstylefeature();
	this.M_feature=parseInt(feature);
	this.updateromform(form);
}
Quote.prototype.setromstyle = function(style,form)
{
	this.checkstylefeature();
	this.M_style=parseInt(style);
	this.updateromform(form);
}
Quote.prototype.setcushstyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.updatecushform(form);
}
Quote.prototype.setpolestyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.changeconfig(form);
	this.updatepoleform(form);
}
Quote.prototype.setpelmstyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.updatepelmform(form);
}
Quote.prototype.settiestyle = function(style,form)
{
	this.M_style=parseInt(style);
	this.updatetieform(form);
}
Quote.prototype.setfabric = function(fabric,form)
{
	this.M_fabric=parseInt(fabric);
	this.updateform(form);
}
Quote.prototype.setromfabric = function(fabric,form)
{
	//alert ('setromfabric');
	this.M_fabric=parseInt(fabric);
	this.updateromform(form);
}
Quote.prototype.setromfeaturefabric = function(featurefabric,form)
{
	//alert('dbg:setromfeaturefabric');
	this.M_featurefabric=parseInt(featurefabric);
	this.updateromform(form);
}
Quote.prototype.setromfeaturesize = function(featuresize,form)
{
	//alert('dbg:setromfeaturesize '+featuresize);
	if (parseFloat(featuresize)>20)
	{
		alert('Feature size must not exceed 20cm, check your inputs');
	}
	else
	{
		this.M_featuresize=parseFloat(featuresize);
	}
	this.updateromform(form);
}
Quote.prototype.setcushfabric = function(fabric,form)
{
	this.M_fabric=parseInt(fabric);
	this.updatecushform(form);
}
Quote.prototype.setpelmfabric = function(fabric,form)
{
	this.M_fabric=parseInt(fabric);
	this.updatepelmform(form);
}
Quote.prototype.settiefabric = function(fabric,form)
{
	this.M_fabric=parseInt(fabric);
	this.updatetieform(form);
}
Quote.prototype.setwidth = function(width,form)
{
	if (form==null) alert('Error: Null form in setwidth');
	width=parseFloat(width);
	if (isNaN(width)) width=0;
	if (this.checkwidth(width)==true)
	{
		this.M_width=width;
	}
	this.updateform(form);
}
Quote.prototype.setromwidth = function(width,form)
{
	if (form==null) alert('Error: Null form in setwidth');
	width=parseFloat(width);
	if (isNaN(width)) width=0;
	if (this.checkwidth(width)==true)
	{
		this.M_width=width;
	}
	this.updateromform(form);
}
Quote.prototype.setpelmwidth = function(width,form)
{
	if (form==null) alert('Error: Null form in setwidth');
	width=parseFloat(width);
	if (isNaN(width)) width=0;
	if (this.checkwidth(width)==true)
	{
		this.M_width=width;
	}
	this.updatepelmform(form);
}
Quote.prototype.settiewidth = function(width,form)
{
	if (form==null) alert('Error: Null form in setwidth');
	width=parseFloat(width);
	if (isNaN(width)) width=0;
	if (this.checkwidth(width)==true)
	{
		this.M_width=width;
	}
	this.updatetieform(form);
}
Quote.prototype.setdrop = function(drop,form)
{
	if (form==null) alert('Error: Null form in setdrop');
	drop=parseFloat(drop);
	if (isNaN(drop)) drop=0;
	if (this.checkdrop(drop)==true)
		this.M_drop=drop;
	this.updateform(form);
}
Quote.prototype.setpelmdrop = function(drop,form)
{
	if (form==null) alert('Error: Null form in setdrop');
	drop=parseFloat(drop);
	if (isNaN(drop)) drop=0;
	if (drop>=20&&drop<=60)
		this.M_drop=drop;
	else
		alert('Illegal Pelmet Drop');
	this.updatepelmform(form);
}
Quote.prototype.setromdrop = function(drop,form)
{
	if (form==null) alert('Error: Null form in setdrop');
	drop=parseFloat(drop);
	if (isNaN(drop)) drop=0;
	if (this.checkdrop(drop)==true)
		this.M_drop=drop;
	this.updateromform(form);
}
Quote.prototype.setfamily = function(family,form)
{
	this.M_family=parseInt(family);
	this.updateform(form);
}
Quote.prototype.setromfamily = function(family,form)
{
	this.M_family=parseInt(family);
	this.updateromform(form);
}
Quote.prototype.setromfitting = function(fitting,form)
{
	this.M_fitting=parseInt(fitting);
	this.updateromform(form);
}
Quote.prototype.setfitting = function(fitting,form)
{
	this.M_fitting=parseInt(fitting);
	this.updateform(form);
}
Quote.prototype.setpelmreturn = function(ret,form)
{
	ret=parseFloat(ret);
	if (isNaN(ret)) ret=0;
	if (ret>30)
		alert('illegal return, max 30cm');
	else
	{
		this.M_return=parseFloat(ret);
		this.updatepelmform(form);
	}
}
Cookie.prototype.setcountry = function (deliverycountry)
{
	this.M_deliverycountry=deliverycountry;
	this.store();
}
