function identity() {
alert("Version 5b of Calculator with support for curtains, blinds, roller blinds and cushions")
}

function staffOn()
{
var today = new Date();
var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
setCookie('STAFF', 'YES', expiry)
}

function staffOff()
{
var today = new Date();
var expiry = new Date(today.getTime() - 1); // plus 28 days
setCookie('STAFF', 'NO', expiry)
}

function  calculate() 
{
// set some constants
var lining_price = 3.77;
var blackout_lining_price = 6.08;
var interlining_price = 6.08
var carriage = 5
var hem_base = 20
var makeup_per_width = 0            // This will be the multiplier per width
var makeup_curtain = 21.51          // Includes Pencil Pleat
var makeup_voile = 10.08             // Includes Pencil Pleat
var makeup_interlined = 39.15       // includes hand slipped sides & Pencil Pleat
var makeup_heading_triple = 7.98
var makeup_heading_goblet = 7.98
var makeup_heading_cartridge = 7.98
var makeup_heading_tab = 7.98
var makeup_heading_tie = 7.98
var makeup_heading_eyelet_25 = 17.13
var makeup_heading_eyelet_40 = 17.13
var makeup_heading_eyelet_66 = 30.57
var makeup_heading_pelmet = 8.4
var makeup_heading_slotted = 0  
var makeup_heading_box = 0            // Pelmets only. Price needs working out.
var makeup_pelmet_lined = 11.93       // Includes cost of pencil pleat heading
var makeup_pelmet_heading = 5.71      // additional cost of special headings
var makeup_pelmet_interlined = 17.01  // 
var makeup_length_18 = 1.68
var makeup_length_25 = 3.36
var makeup_length = 0;
var makeup_width_min = 1.5;
var calc_curtain_width = 0;
var curtain_width = 0;
var tieback_fabric = 0.25
var makeup_length_18 = 1.68
var makeup_length_25 = 3.36
var makeup_length = 0;
widths_per_curtain_charging = 0
var finished_length=0;
var cut_length=0;
var eyelet_text = ""		      // defines extra description for 5cm stand up
var length_unit=1
var width_unit=1
//
// get some initial variables
var calc_type=document.forms[2].calc_type.value;
// staff=document.forms[2].staff.value;
//if (staff=="yes")
//{
   var fabric_width   = document.forms[2].fabric_width.value  // data should always be in cm.
   var fabric_price   = document.forms[2].fabric_price.value
   var pattern_repeat = document.forms[2].pattern_repeat.value // data should always be in cm.
   var fabric_name    = document.forms[2].fabric_name.value
//}
//else
//   fabric_name    = getCookie('C_NAME_FABRIC')	 // now get rest of data from cookies
 //  fabric_width   = getCookie('C_WIDTH_FABRIC')
  // pattern_repeat = getCookie('C_REPEAT_FABRIC')//
   if (getCookie('C_PRICE_FABRIC').charAt(0)=="£") 
     {fabric_price = getCookie('C_PRICE_FABRIC').substr(1) 
   //  alert ('from prod'+fabric_price)
     }
   else
     {fabric_price   = getCookie('C_PRICE_FABRIC')
   //  alert ('from property'+fabric_price)
     }
//}
fabric_price=fabric_price*1

// which units are being used?
if (document.forms[2].length_unit)
{ length_unit=document.forms[2].length_unit.value}
if (document.forms[2].width_unit)
{ width_unit=document.forms[2].width_unit.value }
if (length_unit==1) 
  {length_unit_desc="cm"}
else
  {length_unit_desc=" inches"}
if (width_unit==1) 
  {width_unit_desc="cm"}
else
  {width_unit_desc=" inches"}


switch (calc_type) 
{
// if curtain 
   case "Curtain":  //    OR dress curtain, pelmet, reversible 
//   set constants for curtains
//   validate input for curtain
     curtain_type=document.forms[2].curtain_type.value
	 heading_type=document.forms[2].heading_type.value     
	 eyelet_colour=document.forms[2].eyelet_colour.value
	 curtain_width=Math.round(document.forms[2].curtain_width.value*width_unit)
//	 heading_height=Math.round(document.forms[2].heading_height.value	) 
//    hook_drop=Math.round(document.forms[2].hook_drop.value)
     finished_length=Math.round(document.forms[2].finished_length.value*length_unit)
	 curtain_lining=document.forms[2].curtain_lining.value
	 curtain_tieback=document.forms[2].curtain_tieback.value
	 
// determine curtain type and set up further constants
 //    finished_length=hook_drop+heading_height
	 
switch (curtain_type) {
 case "Curtain":
    treatment="A pair of curtains"
    curtain_number = 2;	
    // Calculate heading adjustments for cut length and widths
    switch (heading_type) {
     case "Pencil":
	  treatment += " with a pencil pleat heading. "
      calc_curtain_width=curtain_width+20
      hem=5+hem_base
      fullness=2.25
	  min_fullness=2
	  max_fullness=2.5
	 break;
     case "Triple":
	  treatment += " with a triple pleat heading. "	 
      calc_curtain_width=curtain_width+20
      hem=15+hem_base
      fullness=2.25 // 2 - 2.5
	  min_fullness=2
	  max_fullness=2.5	  
     break;
     case "Tab":
	  treatment += " with a tab top heading. "	 
      calc_curtain_width=curtain_width
      hem=0+hem_base
      fullness=1.5 //  1.5-2.0
	  min_fullness=1.5
	  max_fullness=2.0	  
     break;
     case "Pelmet": 
	  treatment += " with a pelmet heading. "	 	 
      calc_curtain_width=curtain_width+20
      hem=(finished_length/6)+2*hem_base 
      fullness=2.25 //  2-2.5
	  min_fullness=2
	  max_fullness=2.5	  
     break;
     case "Slotted":
	  treatment += " with a slotted pocket heading. "	 	 
      calc_curtain_width=curtain_width	 
      hem=20+hem_base
      fullness=2.25 //  2-2.5
	  min_fullness=2
	  max_fullness=2.5	  
     break;
     case "Goblet":
	  treatment += " with a goblet heading. "	 	 
      calc_curtain_width=curtain_width+20
      hem=15+hem_base
      fullness=2.25 // 2-2.5
	  min_fullness=2
	  max_fullness=2.5	  
     break;
     case "Cartridge":
	  treatment += " with a cartridge heading. "	 	 
      calc_curtain_width=curtain_width+20
      hem=15+hem_base
      fullness=2.25 //  2-2.5
	  min_fullness=2
	  max_fullness=2.5	  
     break;	 
     case "Tie":
	  treatment += " with a tie-top heading. "	 	 
      calc_curtain_width=curtain_width	 
      hem=0+hem_base
      fullness=2.0 // 1.8-2.5
	  min_fullness=1.8
	  max_fullness=2.5	  
     break;
     case "Eyelet 25mm":
	  treatment += " with a 25mm eyelet heading. "	 	 
      calc_curtain_width=curtain_width+20
      hem=20+hem_base
      fullness=1.8 // 1.8-2.25
	  min_fullness=1.8
	  max_fullness=2.25	 
	  eyelet_text=" plus 5cm stand-up"
     break;	 
     case "Eyelet 40mm":
	  treatment += " with a 40mm eyelet heading. "	 
      calc_curtain_width=curtain_width+20
      hem=20+hem_base
      fullness=1.8 // 1.8-2.25
	  min_fullness=1.8
	  max_fullness=2.25	 
	  eyelet_text=" plus 5cm stand-up"
     break;
     case "Eyelet 66mm":
	  treatment += " with a 66mm eyelet heading. "	 
      calc_curtain_width=curtain_width+20
      hem=20+hem_base
      fullness=1.8 // 1.8-2.25
	  min_fullness=1.8
	  max_fullness=2.25	 
	  eyelet_text=" plus 5cm stand-up"
     break;
     default:
     alert("Curtains are only available with Pencil, Triple, Tab, Pelmet, Slotted, Goblet, Cartridge, Tie or Eyelet headings.")
     return;
	}
	break;
  case "Dress Curtain":
    curtain_number = 2;  
    treatment="A pair of dress curtains"
    // Calculate heading adjustments for cut length and widths
    switch (heading_type) {
     case "Pencil":
	  treatment += " with a pencil pleat heading. "	 
      calc_curtain_width=curtain_width	 
      hem=0+hem_base
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;
     case "Triple":
 	  treatment += " with a triple pleat heading. "
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=1.3
  	  min_fullness=1
	  max_fullness=1.5	
     break;
     case "Tab":
	  treatment += " with a tab top heading. "	 
      calc_curtain_width=curtain_width	 
      hem=0+hem_base
      fullness=0.87
	  min_fullness=0.6
	  max_fullness=1.0		  
     break;
     case "Pelmet":
	  treatment += " with a pelmet heading. "	 	 
      calc_curtain_width=curtain_width	 
      hem=(finished_length/6)+2*hem_base 
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;
     case "Slotted":
	  treatment += " with a slotted pocket heading. "		 
      calc_curtain_width=curtain_width	 
      hem=20+hem_base
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;
     case "Goblet":
	  treatment += " with a goblet heading. "	 	 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;
     case "Cartridge":
	  treatment += " with a cartridge heading. "		 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;	 
     case "Tie":
	  treatment += " with a tie-top heading. "		 
      calc_curtain_width=curtain_width	 
      hem=0+hem_base
      fullness=1.3
	  min_fullness=1
	  max_fullness=1.5		  
     break;
     case "Eyelet 25mm":
	  treatment += " with a 25mm eyelet heading. "	 
      calc_curtain_width=curtain_width	 
      hem=20+hem_base
      fullness=0.87
	  min_fullness=0.6
	  max_fullness=1.0	  
	  eyelet_text=" plus 5cm stand-up"
     break;	 
     case "Eyelet 40mm":
	  treatment += " with a 40mm eyelet heading. "	 
      calc_curtain_width=curtain_width	 
      hem=20+hem_base
      fullness=0.87
	  min_fullness=0.6
	  max_fullness=1.0	  
	  eyelet_text=" plus 5cm stand-up"
     break;
     case "Eyelet 66mm":
	  treatment += " with a 66mm eyelet heading. "	 
      calc_curtain_width=curtain_width	 
      hem=20+hem_base
      fullness=0.87
	  min_fullness=0.6
	  max_fullness=1.0	
	  eyelet_text=" plus 5cm stand-up"
     break;
     default:
      alert("Dress curtains are only available with Pencil, Triple, Tab, Pelmet, Slotted, Goblet, Cartridge, Tie or Eyelet headings.")
      return;
     }
   break;
   case "Pelmet":
    treatment="A pelmet"
    curtain_number = 1;
    // Calculate heading adjustments for cut length and widths
    makeup_interlined = makeup_pelmet_interlined  
    makeup_curtain = makeup_pelmet_lined
    switch (heading_type) {
     case "Pencil":
	  treatment += " with a pencil pleat heading. "	 
      calc_curtain_width=curtain_width	 
      hem=0+hem_base
      fullness=2.25
	  min_fullness=2
	  max_fullness=2.5	  
     break;
     case "Triple":
	  treatment += " with a triple pleat heading. "	 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=2.25
	  min_fullness=2
	  max_fullness=2.5	  
      makeup_heading_triple = makeup_pelmet_heading  // replace curtain heading cost with pelmet
     break;
     case "Goblet":
	  treatment += " with a goblet heading. "	 	 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=2.25
	  min_fullness=2
	  max_fullness=2.5	 	  
      makeup_heading_goblet = makeup_pelmet_heading  // replace curtain heading cost with pelmet
     break;
     case "Cartridge":
	  treatment += " with a cartridge heading. "		 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=2.25
	  min_fullness=2
	  max_fullness=2.5	  	  
      makeup_heading_cartridge = makeup_pelmet_heading  // replace curtain heading cost with pelmet
     break;	 
     case "Box":
	  treatment += " with a box heading. "	 
      calc_curtain_width=curtain_width	 
      hem=15+hem_base
      fullness=3.0
	  min_fullness=3.0
	  max_fullness=3.2		  
      makeup_heading_box = makeup_pelmet_heading  // replace curtain heading cost with pelmet
     break;
     default:
     alert("Pelmets are only available with Pencil, Triple, Goblet, Cartridge or Box headings.")
     return;
    }
  break;
}
//   calculate fabric requirement & Cost

     number_of_widths = (calc_curtain_width*fullness)/fabric_width 
     number_of_widths = Math.round(number_of_widths) // and round up or down
// add code to check fullness min and max are not breached //////////////////////////////////////////////////////////////	 
     if ( number_of_widths < 1) { number_of_widths = 1 }   // this solves requirement for min width of 1
     widths_per_curtain = number_of_widths/curtain_number
     cut_length = hem + finished_length
//   calculate patterns per drop
     if (pattern_repeat == 0) {patterns_per_drop = 0;} else {patterns_per_drop = Math.ceil(cut_length / pattern_repeat); }
//   calculate fabric required
     if (pattern_repeat == 0) {
	    if (heading_type == "Tab" || heading_type =="Tie") {fabric_required = Math.ceil((cut_length+50) * number_of_widths * .1)/10;} 
        else {fabric_required = Math.ceil(cut_length * number_of_widths * .1)/10;	}
     }
     else
     {
        if (heading_type == "Tab" || heading_type =="Tie") {fabric_required = Math.ceil(((patterns_per_drop*pattern_repeat)+50)*number_of_widths * .10) / 10;}
        else {fabric_required = Math.ceil(patterns_per_drop * pattern_repeat * number_of_widths * .10) / 10;}
     }

//   extra fabric for tiebacks?  
     if (curtain_tieback == "selfpiped")    {fabric_required = fabric_required + (tieback_fabric * curtain_number)  }
//   calculate charge for fabric
     fabric_total = Math.round(fabric_required * fabric_price*100)/100;
//   surcharge to offset discount strategy
     fabric_total = Math.round(fabric_total*1.1)




//   calculate charge for lining fabric and prepare descriptions and makeup per width 
     switch (curtain_lining) {
     case "voile":
       lining_price = 0.00
       lined="Not lined."
       makeup_per_width = makeup_per_width + makeup_voile	   
     break;
     case "lined":
       lined="Lined with 100% cotton sateen."
       makeup_per_width = makeup_per_width + makeup_curtain	   
     break;
     case "interlined":
       lining_price = lining_price + interlining_price
       lined="Interlined and lined with 100% cotton sateen."
	   makeup_per_width = makeup_per_width + makeup_interlined
     break;
     case "blackout":
       lining_price = blackout_lining_price
       lined="Lined with blackout lining."
       makeup_per_width = makeup_per_width + makeup_curtain	   
     break;
     }
//   calculate charge for lining type
     lining_total = Math.round(fabric_required * lining_price)
//   surcharge to offset discount strategy
     lining_total = Math.round(lining_total*1.1)
	 
//   calculate Heading charge for makeup_per_width
     switch (heading_type) {
      case "Pencil":
       makeup_per_width = makeup_per_width
      break;
      case "Triple":
       makeup_per_width = makeup_per_width + makeup_heading_triple
      break;
      case "Goblet":
       makeup_per_width = makeup_per_width + makeup_heading_goblet
      break;
      case "Cartridge":
       makeup_per_width = makeup_per_width + makeup_heading_cartridge
      break; 
      case "Tab":
       makeup_per_width = makeup_per_width + makeup_heading_tab
      break;
      case "Tie":
       makeup_per_width = makeup_per_width + makeup_heading_tie
      break;
      case "Eyelet 25mm":
       makeup_per_width = makeup_per_width + makeup_heading_eyelet_25
      break; 
      case "Eyelet 40mm":
       makeup_per_width = makeup_per_width + makeup_heading_eyelet_40
      break;
      case "Eyelet 66mm":
       makeup_per_width = makeup_per_width + makeup_heading_eyelet_66
      break;
      case "Pelmet":
       makeup_per_width = makeup_per_width + makeup_heading_pelmet
      break;
      case "Slotted":
       makeup_per_width = makeup_per_width + makeup_heading_slotted
      break;
      case "Box":
       makeup_per_width = makeup_per_width + makeup_heading_box
      break;
     }
//   Calculate length - additional charge for makeup_per_width
     if( finished_length < 180) {
     makeup_per_width = makeup_per_width + 0
     } else if(finished_length >= 180 && finished_length < 250){
       makeup_per_width = makeup_per_width + makeup_length_18
     } else if(finished_length >= 250 ){
       makeup_per_width = makeup_per_width + makeup_length_25
     }
//   Final makeup charge  for curtains
     if (widths_per_curtain < 1.5)
       { widths_per_curtain_charging = 1.5 }
       else { widths_per_curtain_charging = widths_per_curtain }
     makeup_final = makeup_per_width * widths_per_curtain_charging * curtain_number
     makeup_final = Math.round(makeup_final*100)/100; // round to 2 dec places
//   surcharge to offset discount strategy
     makeup_final = Math.round(makeup_final*1.1)
//   Tieback surcharge  
     if (curtain_tieback == "selfpiped")
       { makeup_final = makeup_final +26 }
       else { makeup_final = makeup_final}  
  
//   prepare price variable + £5 towards carriage + 10% to support discount strategy 
     price = (makeup_final+lining_total+fabric_total+5)
     price = Math.round(price); // round to 0 dec places
	 //alert('Fabric req '+fabric_required+' Makeup '+makeup_final+' lining total '+lining_total+' fabric_total '+fabric_total)
//   pepare description variable
// alert(treatment)
     if (heading_type=="Eyelet 25mm" || heading_type=="Eyelet 40mm" || heading_type=="Eyelet 66mm")
     {
       treatment += eyelet_colour+' eyelet colour.'
	 }
     desc = treatment
     desc+=' '+lined+
           ' Widths per curtain: '+ widths_per_curtain+
	       '. For a track/pole length of '+Math.round(document.forms[2].curtain_width.value)+width_unit_desc+
       //    'cm and drop of '+ finished_length+ 'cm (heading '+heading_height+'cm, hook drop '+hook_drop+'cm).'+
	         ' and drop of '+ Math.round(document.forms[2].finished_length.value) + length_unit_desc+eyelet_text+'.'+
           ' Tiebacks: '+ curtain_tieback+
           '. '+ fabric_name
    
//    prepare price variable
//    to cookies for display
      var today = new Date();
      var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
      setCookie('CURTAIN_TYPE', curtain_type, expiry)	  
	  setCookie('HEADING_TYPE', heading_type, expiry)      
	  setCookie('EYELET_COLOUR', eyelet_colour, expiry)  	  
      setCookie('CURTAIN_WIDTH', Math.round(document.forms[2].curtain_width.value), expiry)
//	  setCookie('HEADING_HEIGHT', heading_height, expiry)	  
//	  setCookie('HOOK_DROP', hook_drop, expiry)	  
      setCookie('FINISHED_LENGTH', Math.round(document.forms[2].finished_length.value), expiry)	 
	  setCookie('CURTAIN_LINING', curtain_lining, expiry)	 
	  setCookie('CURTAIN_TIEBACK', curtain_tieback, expiry)	
	  setCookie('CURTAIN_DESCRIPTION', desc, expiry)
      setCookie('CURTAIN_PRICE', price, expiry)		  
	  
//    to fields for Actinic	
       // generate random number for for loop between 1 and 10
       blank_max = Math.round(10*Math.random())
       blanks = "."
       for (var blank_no = 1; blank_no <= blank_max; blank_no=blank_no+1)
         { blanks += "."; }
	  item_desc=desc + blanks  
      document.forms[2].Q_Curtain.value=price	 
      document.forms[2].O_Curtain.value=item_desc
	//  alert(item_desc)

//    write fields for email form
      document.forms[3].Name.value="gerald lee "
      document.forms[3].Subject.value="Queenshill Curtain Calc - v5b"
      document.forms[3].EmailAddress.value="gerald.lee@queenshill.com" // for v8
	  staff_data = " \r\nPrice: "+price+" \r\nFabric width :"+fabric_width+"  \r\npattern repeat :"+pattern_repeat
	  staff_data +=' \r\nFabric req :'+fabric_required+'  \r\nMakeup :'+makeup_final
	  staff_data +='  \r\nlining total :'+lining_total+'  \r\nfabric_total :'+fabric_total
	  message = desc+staff_data
	  document.forms[3].Message.value=message
      document.forms[3].ACTION.click()
	  // update relevent staff cookie
	  setCookie('STAFF_DATA_CURTAIN', staff_data, expiry)	
      history.go()
   break;
// if roman blind ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   case "Fabric Blind":   
//    set constants for roman blind
      hem_allowance = 20	  
      price=0

//    validate input for roman blind
      blind_width=Math.round(document.forms[2].blind_width.value)*width_unit
      if (isNaN(blind_width))  {alert("Please enter width."); return;}
	  if (blind_width<=30)  {alert("Minimum width is 30cm."); return;}  
	  if (blind_width>250)  {alert("Maximum width is 250cm."); return;}  	  
      blind_length=Math.round(document.forms[2].blind_length.value)*length_unit
      if (isNaN(blind_length))  {alert("Please enter length."); return;}
	  if (blind_length<=50)  {alert("Minimum length is 50cm."); return;}  
	  if (blind_length>275)  {alert("Maximum length is 275cm."); return;} 	  
	  blind_recess=document.forms[2].blind_recess.value
      blind_type=document.forms[2].blind_type.value	
      blind_pull=document.forms[2].blind_pull.value
      blind_chain=document.forms[2].blind_chain.value	
      blind_lining=document.forms[2].blind_lining.value	

//    calculate fabric required
      calc_blind_width=blind_width+6
	  number_of_widths = Math.ceil(calc_blind_width/fabric_width) 	  
      drop_length=blind_length+hem_allowance
	  if (pattern_repeat <=0) 
	    {fabric_required=drop_length*number_of_widths} //  
	  else 
	    {repeats_per_drop=Math.ceil(drop_length/pattern_repeat) 
		fabric_required = pattern_repeat*repeats_per_drop*number_of_widths}

//    calculate charge for fabric - convert from cm to m
      fabric_total = Math.round(fabric_required * fabric_price)/100;
//    calculate makeup charge by calling roller makeup prices and returning makeup_final
      roman_makeup_price()

//    Calculate Material Cost of Linings and prepare descriptions and modify makeup_final
      switch (blind_lining) {
        case "voile":
          lining_price = 0.00
          lined="not lined"
          break;
        case "lined":
          lined="lined with 100% cotton sateen"
          break;
        case "interlined":
          lining_price = lining_price + interlining_price
          lined="interlined and lined with 100% cotton sateen"
		  makeup_final = makeup_final * 1.25 //    Add 25% for Interlining
          break;
        case "blackout":
          lining_price = blackout_lining_price
          lined="lined with blackout lining"
		  makeup_final = makeup_final * 1.05 //    Add 5% for Blackout
          break;
      }
      lining_total = Math.round(fabric_required * lining_price)/100
	       
//    calculate surcharge for handsewn
//    prepare price variable + £5 towards carriage + 10% to support discount strategy 
      price = (makeup_final+lining_total+fabric_total)*1.1+5
	  price = Math.round(price); // round to 0 dec places
	  
//    prepare description variable
      if(blind_recess=="Inside recess") {blind_text="recess "} else {blind_text="blind "}
      if (blind_type=="sidewinder") {blind_type_text=blind_type+" with "+blind_chain+" chain"} else {blind_type_text=blind_type}
	  desc = "A roman blind " +lined + '. '+
	         "Widths per blind: "+number_of_widths +".  "+
			 "For a "+blind_text+" width of "+Math.round(document.forms[2].blind_width.value)+width_unit_desc+
			 " and drop of "+Math.round(document.forms[2].blind_length.value)+length_unit_desc+
			 ". Mechanism: "+blind_type_text+'.  '+
			 "Location: "+blind_recess+'.  '+
			 'Pull: '+blind_pull+'.  '+
			 "Made from: "+ fabric_name
			 
//    to cookies for display
      var today = new Date();
      var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
      setCookie('ROMAN_DESCRIPTION', desc, expiry)
      setCookie('ROMAN_PRICE', price, expiry)	  
      setCookie('ROMAN_BLIND_WIDTH', Math.round(document.forms[2].blind_width.value), expiry)
      setCookie('ROMAN_BLIND_LENGTH', Math.round(document.forms[2].blind_length.value) , expiry) 
      setCookie('ROMAN_BLIND_RECESS', blind_recess, expiry)
      setCookie('ROMAN_BLIND_TYPE', blind_type, expiry)
      setCookie('ROMAN_BLIND_PULL', blind_pull, expiry)	  
      setCookie('ROMAN_BLIND_CHAIN', blind_chain, expiry)
      setCookie('ROMAN_BLIND_LINING', blind_lining, expiry)
//    to fields for Actinic	
       // generate random number for for loop between 1 and 10
       blank_max = Math.round(10*Math.random())
       blanks = "."
       for (var blank_no = 1; blank_no <= blank_max; blank_no=blank_no+1)
         { blanks += "."; }
	  item_desc=desc + blanks  
      document.forms[2].Q_Roman.value=price	 
      document.forms[2].O_Roman.value=item_desc
//    write fields for email form
      document.forms[3].Name.value="gerald lee "
      document.forms[3].Subject.value="Queenshill Roman Blind Calc - v5b"
      document.forms[3].EmailAddress.value="gerald.lee@queenshill.com" // for v8
	  staff_data = " \r\nPrice: "+price+" \r\nFabric width :"+fabric_width+" \r\npattern repeat :"+pattern_repeat
  	  staff_data +=" \r\nFabric req :"+fabric_required+" \r\nMakeup :"+makeup_final+" \r\nlining total :"+lining_total+" \r\nfabric_total :"+fabric_total
	  message = desc+staff_data
      document.forms[3].Message.value=message
      document.forms[3].ACTION.click()	  
	  // update relevent staff cookie
	  setCookie('STAFF_DATA_ROMAN', staff_data, expiry)	
	  history.go()
   break;
// if cushions ////////////////////////////////////////////////////////////////////////////////////////
   case "Cushion": 
   
//    set constants for cushions
	  carriage = 3  // m2m carriage surcharge
      fabric_required=0
	  makeup_charge=0
	  makeup_price= new Array(12.1, 13.88, 14.75);
      pad_price = new Array;
      synthetic_pad_price =  new Array( 5.33, 5.94, 7.39, 8.04); 
	  feather_pad_price =  new Array( 5.55, 6.53, 8.57, 10.05); 	  
	  
//    validate input for cushions
      cushion_type=document.forms[2].cushion_type.value
	  cushion_size=document.forms[2].cushion_size.value
	  pad_type=document.forms[2].pad_type.value	
      cushion_qty=document.forms[2].cushion_qty.value
	  
//    calculate fabric requirement - repeats not allowed for
      fabric_required = (cushion_size/100)+0.10  //  convert to metres then add 0.1m for hems etc
	  if (cushion_qty*fabric_required<=0.99) // minimum of 100cm for total fabric requirement
	     {fabric_required=1}
		 
//    calculate charge for fabric
	  fabric_charge  = fabric_required*fabric_price
	  fabric_charge  = Math.round(fabric_charge*100)/100
	  
//    calculate makeup charge
	  if (cushion_type=="Plain") {j=0}
	  if (cushion_type=="Self Piped") {j=1}
	  if (cushion_type=="Oxford") {j=2}	  
	  makeup_charge = makeup_price[j]
	  
//    calculate charge for pad type and choose cushion_size_text
      if (pad_type=="Feather")  // Feather or Synthetic pad?
	     {pad_price=feather_pad_price
          i=4
          if (cushion_size == 55)
	         {i = 3
			 cushion_size_text='55cm (22")'		  
			 }
          if (cushion_size == 50)
	         {i = 2
			 cushion_size_text='50cm (20")'
			 }
          if (cushion_size == 45)
	         {i = 1
			 cushion_size_text='45cm (18")'
			 }
          if (cushion_size == 40)
	         {i = 0
			 cushion_size_text='40cm (16")'
			 }	 	 	 	 
	      pad_charge = pad_price[i]
		 }
		 else
		 {pad_price=synthetic_pad_price
          i=4
          if (cushion_size == 55)
	         {i = 3
			 cushion_size_text='55cm (22 inches)'		  
			 }
          if (cushion_size == 50)
	         {i = 2
			 cushion_size_text='50cm (20 inches)'
			 }
          if (cushion_size == 45)
	         {i = 1
			 cushion_size_text='45cm (18 inches)'
			 }
          if (cushion_size == 40)
	         {i = 0
			 cushion_size_text='40cm (16 inches)'
			 }		 	 	 	 
	      pad_charge = pad_price[i]
		 }
//    calculate final price + 10% to support disctount strategy
	  unit_charge = Math.round(1.1*(fabric_charge + pad_charge + makeup_charge + carriage)); 

//    write fields for staff forms
//      if (document.forms[2].staff.value) 
//	  {
 //     staff=document.forms[2].staff.value;
 //     if (staff=="yes")
//	  {
 //     document.forms[4].fabric_required.value = fabric_required
 // 	  document.forms[4].fabric_cost.value = fabric_charge
//	  document.forms[4].makeup_cost.value = makeup_charge
//	  document.forms[4].pad_cost.value = pad_charge	  		  
 //     document.forms[4].unit_charge.value = unit_charge
 //     document.forms[4].total_fabric_required.value = Math.round(fabric_required*cushion_qty*10)/10
//	  document.forms[4].total_fabric_cost.value=fabric_charge*cushion_qty
//	  document.forms[4].total_makeup_cost.value=(makeup_charge)*cushion_qty
//	  document.forms[4].total_pad_cost.value = pad_charge*cushion_qty	  
  //    document.forms[4].total_charge.value = (unit_charge*cushion_qty)	 
//	  }
//	  }
	  
//    prepare description variable
      desc =  cushion_qty+" "+cushion_type+" cushion with "+pad_type+" pad and zip. Size : "+cushion_size_text+" by "+cushion_size_text+". "+fabric_name

//    prepare price variable
      price = unit_charge*cushion_qty

//    to cookies for display
      var today = new Date();
      var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
      setCookie('CUSHION_DESCRIPTION', desc, expiry)
	  setCookie('CUSHION_PRICE', price, expiry)
	  setCookie('CUSHION_UNIT_PRICE', unit_charge, expiry)
      setCookie('NAME_FABRIC_OLD', fabric_name, expiry)

//    to fields for Actinic	
       // generate random number for for loop between 1 and 10
       blank_max = Math.round(10*Math.random())
       blanks = "."
       for (var blank_no = 1; blank_no <= blank_max; blank_no=blank_no+1)
         { blanks += "."; }
	  item_desc=desc + blanks  
      document.forms[2].Q_Cushion.value=price	 
      document.forms[2].O_Cushion.value=item_desc
//	  alert(document.forms[2].O_Cushion.value)
 //   alert(document.forms[2].Q_Cushion.value)
 
//    write fields for email form
      document.forms[3].Name.value="gerald lee "
      document.forms[3].Subject.value="Queenshill Cushion Calc - v5b"
//	  alert(document.forms[3].Subject.value)
      document.forms[3].EmailAddress.value="gerald.lee@queenshill.com" // for v8
	  staff_data="\r\n\r\n"
	  staff_data+="Price: £ "+((unit_charge*cushion_qty))+"\r\n"
	  staff_data+="fabric_price "+fabric_price+"\r\n"
	  staff_data+="fabric_width "+fabric_width+"\r\n"
	  staff_data+="pattern_repeat "+pattern_repeat+"\r\n"
	  staff_data+="fabric_required_per_cushion "+fabric_required+"\r\n"
  	  staff_data+= "fabric_charge_per_cushion "+fabric_charge+"\r\n"
	  staff_data+= "makeup_charge_per_cushion "+makeup_charge+"\r\n"
	  staff_data+= "pad_charge_per_cushion "+pad_charge	+"\r\n"  		  
      staff_data+= "unit_charge_per_cushion "+unit_charge+"\r\n"
      staff_data+= "total_fabric_required "+Math.round(fabric_required*cushion_qty*10)/10+"\r\n"
	  staff_data+= "total_fabric_charge "+fabric_charge*cushion_qty+"\r\n"
	  staff_data+= "total_makeup_charge "+(makeup_charge)*cushion_qty+"\r\n"
	  staff_data+= "total_pad_charge "+pad_charge*cushion_qty	  +"\r\n"
      staff_data+= "total_unit_charge "+(unit_charge*cushion_qty)	+"\r\n"
	  message= desc+staff_data
	  document.forms[3].Message.value=message
	  //alert(message)
	  // update relevent staff cookie
	  setCookie('STAFF_DATA_CUSHION', staff_data, expiry)	

      document.forms[3].ACTION.click()
      history.go()

   break;
   
// if roller blinds   
   case "Roller":  
//    set constants for roller blinds
	  carriage = 3  // m2m carriage surcharge
      fabric_required=0
	  makeup_charge=0
      lining_price = 3.78;
      blackout_lining_price = 6.07;
      interlining_price = 6.07
	  blind_width=0
      blind_length=0
	  repeats_per_drop=0
//    validate input for roller blinds
      blind_width=Math.round(document.forms[2].blind_width.value)/width_unit
      if (blind_width > 220 ) {alert ("Our maximum blind width is 220cm.");return;}  
	  if (blind_width >175 && blind_length >160) {alert ("For blinds wider than 175cm our maximum length is 160cm."); return;}
      if (blind_width <30) {alert("Minimum blind width is 30cm. Please re-enter"); return;}	  
      blind_length=Math.round(document.forms[2].blind_length.value)/length_unit
	  blind_recess=document.forms[2].blind_recess.value
	  blind_type=document.forms[2].blind_type.value	
	  blind_pull=document.forms[2].blind_pull.value
	  if (blind_type=="sprung") {blind_pull="centre"}
	  blind_reverse=document.forms[2].blind_reverse.value	 
	  blind_backing=document.forms[2].blind_backing.value
	  blind_edge_shape=document.forms[2].blind_edge_shape.value
  	  blind_pole=document.forms[2].blind_pole.value
	  blind_trim=document.forms[2].blind_base_trim.value
	  blind_chain=document.forms[2].blind_chain.value
	  if (blind_type=="sprung") {blind_chain="white cord"} else {blind_chain+=" chain"}


//    calculate fabric requirement
    // number of widths - rounds up also solves requirement for min width of 1 
	  widths=Math.ceil(blind_width/fabric_width) 
	// calculate fabric length required
	  if(blind_edge_shape=="straight") {allowance=40} else {allowance=70}
	  drop_length=blind_length+allowance
	  if (pattern_repeat <=0) 
	    {fabric_required=drop_length*widths} //  
	  else 
	    {repeats_per_drop=Math.ceil(drop_length/pattern_repeat) 
		fabric_required = pattern_repeat*repeats_per_drop*widths
		} 
//    calculate charge for fabric - convert from cm to m
      fabric_total = Math.round(fabric_required * fabric_price)/100;

//    calculate makeup charge by calling roller makeup prices and returning makeup_final
      roller_makeup_price()
 
//    add 20% if using blackout backing
      if (blind_backing=="blackout white" || blind_backing=="blackout cream")
	    {makeup_final=makeup_final*1.2}

//    pepare description variable
      if (blind_edge_shape=="turret") {turret_type=" with "+blind_pole+" pole"} else {turret_type=""}

      desc = "A laminated roller blind "+blind_width+ "cm wide and "+blind_length+"cm long. Widths per blind "+widths+". "+blind_recess+". Mechanism is "+blind_type+" with "+blind_pull+" pull, "+blind_chain+". Roller is "+blind_reverse+" rolled. Backing is "+blind_backing+". Bottom edge shape is "+blind_edge_shape+turret_type+" with "+blind_trim+' trim. Fabric name: '+ fabric_name 
	  	  
//    prepare price variable + £5 towards carriage + 10% to support discount strategy 
      price = (makeup_final+fabric_total+5)*1.1
	  price = Math.round(price); // round to 0 dec places
	  
//    to cookies for display
      var today = new Date();
      var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
      setCookie('ROLLER_DESCRIPTION', desc, expiry)
	  setCookie('ROLLER_PRICE', price, expiry)
	  setCookie('ROLLER_BLIND_WIDTH', blind_width, expiry)
	  setCookie('ROLLER_BLIND_LENGTH', blind_length, expiry)
	  setCookie('ROLLER_BLIND_RECESS', blind_recess, expiry)
	  setCookie('ROLLER_BLIND_TYPE', blind_type, expiry)
	  setCookie('ROLLER_BLIND_PULL', blind_pull, expiry)	  
	  setCookie('ROLLER_BLIND_REVERSE', blind_reverse, expiry)
	  setCookie('ROLLER_BLIND_BACKING', blind_backing, expiry)	  
	  setCookie('ROLLER_BLIND_EDGE', blind_edge_shape, expiry)	  	
 	  setCookie('ROLLER_BLIND_TRIM', blind_trim, expiry)
	  setCookie('ROLLER_BLIND_POLE', blind_pole, expiry)
	  setCookie('ROLLER_BLIND_CHAIN', blind_chain, expiry)	  
//    to fields for Actinic	
      // do on page from cookie
       // generate random number for for loop between 1 and 10
       blank_max = Math.round(10*Math.random())
       blanks = "."
       for (var blank_no = 1; blank_no <= blank_max; blank_no=blank_no+1)
         { blanks += "."; }
	  item_desc=desc + blanks 	  
      document.forms[2].Q_Roller.value=price	 
      document.forms[2].O_Roller.value=item_desc


//    write fields for email form
      document.forms[3].Name.value="gerald lee "
      document.forms[3].Subject.value="Queenshill Roller Blind Calc - v5b"
      document.forms[3].EmailAddress.value="gerald.lee@queenshill.com" // for v8

	  staff_data = ". \r\nwidth :"+fabric_width+".  \r\n"+
				"pattern repeat :"+pattern_repeat+".  \r\n"+
				"widths :"+widths+".  \r\n"+
				"repeats per drop :"+repeats_per_drop+".  \r\n"+
				"fabric required :"+fabric_required+".  \r\n"+
				"drop_length :"+drop_length+".  \r\n"+
	            "Fabric Total :"+fabric_total+".  \r\n"+
				"Makeup Final :"+makeup_final+".  \r\n"+
				"total price :"+price+".  \r\n"+
				"The amount of fabric required is "+fabric_required+" cm."
	  message = desc+staff_data				
      document.forms[3].Message.value=message
      document.forms[3].ACTION.click()
	  // update relevent staff cookie
	  setCookie('STAFF_DATA_ROLLER', staff_data, expiry)
	   history.go()
   break;
   
   default: alert("Sorry, we can't quote automatically for these yet. Please call us.") 
} // end of calctype switch
//
	  setCookie('C_NAME_FABRIC_OLD', getCookie('C_NAME_FABRIC'), expiry)	
      setCookie('WIDTH_UNIT', width_unit, expiry)	
      setCookie('LENGTH_UNIT', length_unit, expiry)	

//   add surcharge for carriage on m2m to final price
//   write cookies for public page
//   write fields for Actinic
//   write fields for staff forms
//   write fields for email form
}
//  End of Calculator


// Start of Laer functions
function showElements(show,names) // switches layers
{ if (show) show = 'block'; else show = 'none';
var e;
for (var i = 1; i < arguments.length; i++) {
e = document.getElementById(arguments[i]);
if (e) e.style.display = show;
}
}


function headingType(type) // allows div layers to be switched by onChange
{
 if (type=="Eyelet 66mm" || type=="Eyelet 25mm" || type=="Eyelet 40mm")
  {
   showElements( true,'eyelet1', 'eyelet2');
   }
  else
    {
   showElements( NaN,'eyelet1', 'eyelet2');
   }
}

function blindType(type) // allows div layers to be switched by onChange
{
 if (type=="sprung") {showElements(NaN,'pull1','pull2','chain1','chain2');} 
 else {showElements( true,'pull1','pull2','chain1','chain2'); }
}

function romanBlindType(type) // allows div layers to be switched by onChange
{
 if (type=="sidewinder") {showElements(true,'chain1','chain2');} 
 else {showElements( NaN,'chain1','chain2'); }
}


function blindEdge(type) // allows div layers to be switched by onChange
{
 if (type=="turret") { showElements( true,'pole1', 'pole2'); } else { showElements( NaN,'pole1', 'pole2'); }
}

function displayStaff(type)
{
  if (type=="YES") { showElements( true,'staff') } else { showElements( NaN,'staff'); }	
}

function calcTabs(type) // 
{
switch(type)
{
case "1":
  showElements( true,'1_t');
  showElements( NaN, '2_t', '3_t', '4_t');
  break;
case "2":
  //document.getElementById("measuring").style.backgroundColor = "#dcdcdc";
  showElements( true,'2_t');
  showElements( NaN,'1_t', '3_t', '4_t');
  break;
case "3":
  showElements( true,'3_t');
  showElements( NaN,'1_t','2_t', '4_t');
  break;
case "4":
  showElements( true, '4_t');
  showElements( NaN,'2_t', '3_t', '1_t');
  break;  
default:
  alert("no tab selected")
}
}
// End of layer functions

// redirects browser to search page
function goToURL() { window.location = "http://www.queenshill.com/acatalog/search.html"; }

// returns the amount in the .99 format
function cent(amount) {
    amount -= 0;
    amount = (Math.round(amount*100))/100;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

// combines search parameters into one field for Actinic
function  multisearch() {
// units in cm//
var form = 0
var loop = 0
var nIndex = 0
// Which form is SS in
	 for (nIndex = 0; nIndex < document.forms.length; nIndex++)
		  {
		  if (document.forms[nIndex] && document.forms[nIndex].searchtext)
	     {
           document.forms[nIndex].searchtext.focus()
	      }
	      }
// Which form is dropdown1 in
	 for (loop = 0; loop < document.forms.length; loop++)
		  {
		  if (document.forms[loop] && document.forms[loop].search_type)
	     {
           form = loop
	      }
	      }
// Get Inputs 
var d1 = document.forms[form].search_type.value
var d2 = document.forms[form].search_mfr.value
var d3 = document.forms[form].search_color.value
var d4 = document.forms[form].search_material.value
var d5 = document.forms[form].search_pattern.value
var d6 = document.forms[form].search_text.value

//    to cookies for display
var today = new Date();
var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
setCookie('SEARCH_TYPE', d1, expiry)
setCookie('SEARCH_MFR', d2, expiry)
setCookie('SEARCH_COLOR', d3, expiry)
setCookie('SEARCH_MATERIAL', d4, expiry)
setCookie('SEARCH_PATTERN', d5, expiry)
setCookie('SEARCH_TEXT', d6, expiry)
// Calculate
re = d1+" "+d2+" "+d3+" "+d4+" "+d5+" "+d6
setCookie('SEARCH', re, expiry)
// document.write(re)
// Display Results
document.forms[form].SS.value = re
//document.popform.result.value=re
}


// this will replace 'made'
function orderSample (reference, name, location)
{
var today = new Date();
var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
setCookie('PRODUCT_REFERENCE', reference, expiry)
setCookie('PRODUCT_NAME', name, expiry)
// price is already set as a cookie in Actinic
window.location=location // place file name here
}


// this will become obsolete
function made(price, name, width, repeat, image, location, product)  
{
// alert (product)
var staff="no"
if (document.forms[1].staff.value == "yes")
  {staff="yes" }
var prefix = "C_"
if (staff=="yes") 
  {prefix = "S_" }
var today = new Date();
var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
setCookie(prefix+'PRICE_FABRIC', price, expiry)
setCookie(prefix+'WIDTH_FABRIC', width, expiry)
setCookie(prefix+'NAME_FABRIC', name, expiry)
setCookie(prefix+'REPEAT_FABRIC', repeat, expiry)
setCookie(prefix+'IMAGE_FABRIC', image, expiry)
window.location=location // place file name here
setCookie(prefix+'PRODUCT_FABRIC', product, expiry)
}

function makePriceCookie(price)  
{
  var prefix = "C_"
  var today = new Date();
  var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
  setCookie(prefix+'PRICE_FABRIC', price, expiry)
}


function makeTheRestCookie(name, width, repeat, image, location, product)  
{
// alert (product)
var staff="no"
if (document.forms[1].staff.value == "yes")
  {staff="yes" }
var prefix = "C_"
if (staff=="yes") 
  {prefix = "S_" }
var today = new Date();
var expiry = new Date(today.getTime() + 2419200000); // plus 28 days
setCookie(prefix+'WIDTH_FABRIC', width, expiry)
setCookie(prefix+'NAME_FABRIC', name, expiry)
setCookie(prefix+'REPEAT_FABRIC', repeat, expiry)
setCookie(prefix+'IMAGE_FABRIC', image, expiry)
window.location=location // place file name here
setCookie(prefix+'PRODUCT_FABRIC', product, expiry)
}
