function yarnUsed(){
// swatch
    swSt=Math.ceil(mult(4.5,p.mainStIn.value)+4);
    swRs=Math.ceil(mult(4.5,p.mainRowIn.value)+6);
    totStSwatch=swSt*swRs;

// body
    // rib
    totStitchesBodyRib= castOnBody*(mult( p.bodyTrim.value, p.mainRowIn.value)*1.1+1);// 1 for cast on. 1.1 because rib
    totStitchesBod=bodyStitches*(rowsToUnderArm+2);// 2 for mismeasure slop.

// sleeves
    // rib
    totStitchesCuffRib=castOnCuff*(mult(p.cuffTrim.value,p.mainRowIn.value)*1.1+1);// 1 for cast on.
    totStitchesSleeve=(cuffStitches+stitchesAfterFast+1)*fastRows/2 + (stitchesAfterFast+ bicepStitches)*slowRows/2+ bicepStitches*(extraRows);

// yoke
    stitchesBaseYoke=frontYoke+backYoke+2*sleeveYoke;
    stitchesAfterFirst= stitchesBaseYoke-8*largeTimesRag; largeRows=(largRegRag+1)*largeTimesRag;
    stitchesAfterSecond=stitchesAfterFirst - 8*smallTimesRag;  smallRows=(smallRegRag+1)*smallTimesRag
    
    totStitchesYoke=stitchesBaseYoke*(smallRegRag+2)+ smallRows *(stitchesAfterSecond+stitchesAfterFirst)/2 + (stitchesBaseYoke+stitchesAfterFirst)*largeRows/2
  
    if(placket=="yes"){  // add only once because you also bind off.
	placketRows=Math.ceil(mult(placketDepth,p.mainRowIn.value)/2)*2+2;  // one for pick up, one for bind off.
	totalPlacketStitches = placketStitches*placketRows;    

    }
    else{totalPlacketStitches=0; }
    
    totStitchesYoke +=totalPlacketStitches;
    
// neck or collar-- estimate,. 
    totStitchesNeckTrim=(stitchesAfterSecond*1.10+placketStitches+2)*(mult( p.collarHeight.value, p.mainRowIn.value)+1)*1.10; // 1 for bind off; 110% for rib, 10% for extra stitches for shaping neck.

// total  yarn yused
    yardageFactor=Math.PI*1.02*1.02 // current factor.  about pi * some fudge  (1.02 is the empirical factor. I'm adding 2% safety to help just a touch. This should be enough for sewing up etc/


if(eval(p.stitchPat.selectedIndex)==0){
    stitchPat="stockinette"; // stockinette
     twelve=0
    }
else if(eval(p.stitchPat.selectedIndex)==1) {
    brokenRib=1;yardageFactor=yardageFactor*1.11/1.02;
    stitchPat="broken rib"
    twelve=12
    }
else{
    yardageFactor=yardageFactor*1.24;
    stitchPat="mystery use lots of yarn pattern."
     twelve=24
    } // what the heck!

inchPerStitch=divide(1,p.mainStIn.value)*lengthBeforeRatio; 
inchPerRow=divide(1,p.mainRowIn.value)*widthBeforeRatio;

normalizedInch= Math.sqrt(inchPerStitch*inchPerStitch+ inchPerRow*inchPerRow);

metersPerYard= 36*2.54/100;

 
 //alert(recStitch + ":"+ recRows+ ":"+ yardageFactor + ":"+ stitchesForGaugeSwatch);
swatchYds= yardageFactor*normalizedInch* totStSwatch/36 ; swatchMeters = swatchYds*metersPerYard;

bodyYards     =  yardageFactor*normalizedInch* (totStitchesBod+totStitchesBodyRib)/36; 		bodyMeters=bodyYards*metersPerYard
sleeveYards   =2*yardageFactor* normalizedInch*(totStitchesSleeve+totStitchesCuffRib)/36;	sleeveMeters=sleeveYards*metersPerYard
yokeYards     = yardageFactor*normalizedInch* totStitchesYoke/36;				yokeMeters=yokeYards*metersPerYard


collarYards   =yardageFactor*normalizedInch* totStitchesNeckTrim/36;				collarMeters=collarYards*metersPerYard

totalYards=bodyYards+sleeveYards+yokeYards+collarYards +swatchYds ;  		totalMeters=totalYards*metersPerYard

}
function yarnUsedText(){
 stuff+= "<H2>Yarn Requirements.<\/H2><\/ol>";
 stuff+= "I predict you will need the following amount of yarn for the whole sweater and various individual parts of the sweater. I assume you are knitting the sweater in the following stitch pattern: " + stitchPat+".  This uses " + twelve + "% more yarn per stitch than stockinette knit at the same gauge. The yarn estimate is based on the gauge <em>before</em> washing your swatch. ";

 
  stuff+= "<table>";
stuff+= "<tr><td>Item<\/td>		<td> yards required<\/td>	<td> meters required<\/td><\/tr>";
stuff+= "<tr><td>Whole Sweater<\/td>	<td>" + Math.round(totalYards)   +" yards<\/td>	<td>"+ Math.round(totalMeters)    +" meters<\/td><\/tr>";
 stuff+= "<tr><td>Two lower Sleeves<\/td><td>"+  Math.round(sleeveYards)  +" yards<\/td>	<td>"+ Math.round(bodyMeters)  +" meters<\/td><\/tr>";
 stuff+= " <tr><td>Lower Body<\/td>	<td>" + Math.round(bodyYards)   +" yards<\/td>	<td>"+ Math.round(sleeveMeters)   +" meters<\/td><\/tr>";
 stuff+= " <tr><td>Yoke<\/td>		<td>" + Math.round(yokeYards)   +" yards<\/td>	<td>"+ Math.round(yokeMeters) +" meters<\/td><\/tr>";
  stuff+= " <tr><td>A "+ p.collarHeight.value + " inch collar<\/td><td>"+ Math.round(collarYards)+" yards<\/td>	<td>"+ Math.round(collarMeters)  +" meters<\/td><\/tr>";
   stuff+= " <tr><td>Recommended for swatch:<\/td><td>"+ Math.round(swatchYds)+" yards<\/td>	<td>"+ Math.round(swatchMeters)  +" meters<\/td><\/tr>";
 stuff+= " <\/table>";
     
 patternWindow.document.writeln(stuff);stuff="";
}