function calcPoncho(){
/* @copyright 2004 Lucia Liljegren*/

pester = document.location;
p =document.ponchoForm;

expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);
username = pester;

document.cookie="pester=" + username + "expires="+ expireDate.toGMTString(); 

if(document.cookie ==""){
/* @copyright 2004 Lucia Liljegren
*/

    alert("Please set your browser to accept cookies. You must accept cookies to run this page.");
}
else {
    pesterZero=document.cookie.split("/")[0];  //figure out if local or away.    
    pesterRead = document.cookie.split("/")[4];
    pesterAway=document.cookie.split("/")[2];    
}
pester = "yes";
    if(pesterZero == "pester=file" || pesterRead =="lucia"){pester="no"}
else if(pesterZero == "pester=http:" || pesterAway == "www.thedietdiary.com"){pester="no"}
else if(pesterZero == "pester=http:" || pesterAway == "thedietdiary.com"){pester="no"}
 
else{ pester = "yes"; 
   p.mainStIn.value=0.01;
    p.mainRowIn.value=0.01;
    alert(" Please run my programs from my site at www.thedietdiary.com!"  ) } ;
//===================
if(pester == "no"){
/* @copyright 2004 Lucia Liljegren*/

    var shoulderDrop = 1;

    // mimic other code as much as possible.
    
   

    if(eval(p.mainStIn.value) < 0.00001) {p.mainStIn.value = 0.001; }
    if(eval(p.mainRowIn.value) < 0.00001) {p.mainRowIn.value = 0.001; }

    // calculate number of stitches to cast on:
    p.tooFewStitches.value = "Calculating" ;
    p.tooBigHead.value="no warning";
    testValue = sub(p.shoulderWidth.value,p.neckWidth.value);
    if(testValue < 0){p.tooBigHead.value="Fix your entry." }
    
    sleeveLength=eval(p.sleeveLength.value);
    p.castOn.value=castOn= Math.round(mult(p.mainStIn.value,p.sleeveLength.value));
	p.castOn4.value=castOn;
    p.firstRows.value=firstRows=2* Math.round(mult(sleeveLength/2, p.mainRowIn.value));

      // half neck width then take hypoteneuse. 
    p.frontNeckDepth.value=frontNeckDepth= divide(p.neckWidth.value,2);
    neckDiagonal= mult(Math.sqrt(2),frontNeckDepth);
    p.headOpening.value=headOpening= Math.round(40*neckDiagonal)/10;
    p.filledHeadOpening.value=filledHeadOpening= Math.round(10*add(2*neckDiagonal,p.neckWidth.value))/10;
      
    p.secondRows.value=p.secondRows2.value=secondRows=Math.round(mult(neckDiagonal/2,p.mainRowIn.value))*2;

    dartLength= divide(sub(p.shoulderWidth.value,p.neckWidth.value)/2,Math.sqrt(2));
    
    rowStitchRatio=3/2; //(3 stitches/ 4 rows multiplied by two because it takes two passes to make I cord.)
    rowStitchRatio = 2 * divide(p.mainStIn.value,p.mainRowIn.value); // this is really a row pass ratio.  

// for darts    This should keep the angle between 33 and 45 for nearly all conceivable gauges.
    one = 1;
    if( 1.25< rowStitchRatio ) {one = 2}  // tall stitches.
    else if( 2 < rowStitchRatio){one = 3} // very tall stitches.
    three=one+2;
    p.one.value=p.one2.value=one;
    p.perFour.value=three;
    
    dartStitches=three*Math.round(mult(dartLength,p.mainStIn.value)/three);// to permit simple directions
    
    p.dartStitches.value=dartStitches;
    p.dartRows.value=dartRows=mult(4,dartStitches/three);
// smoothing rows-- stitches must be even because three per pass.
    four=5;
    maxSmoothStitches = Math.round(dartStitches/3);// this really is 3-- hard. 
    dartStitchSmooth = Math.min(2*Math.round(divide(p.mainStIn.value,2)),maxSmoothStitches);  //1" or less worth of smoothing. 
    
    dartSmoothTimes= Math.round(divide(dartStitchSmooth,four));
    dartStitchSmooth = mult(dartSmoothTimes,four);// make sure correct multiple
    
    
	p.dartStitchSmoothTimes.value= dartSmoothTimes
	p.dartStitchSmoothTimes2.value= dartSmoothTimes; // 
    p.skipSmooth.value=p.skipSmooth2.value= "Work this instruction."
    if(dartSmoothTimes<1){p.skipSmooth.value=p.skipSmooth2.value="Skip this instruction"}
    
    p.dartStitchesTotal.value=dartStitchesTotal= add(dartStitches,dartStitchSmooth)
    p.dartRowsSmooth.value=dartRowsSmooth= mult(dartSmoothTimes,2);
    p.dartRowsTotal.value=p.dartRowsTotal2.value= dartRowsTotal=add(p.dartRows.value,dartRowsSmooth);
    
  
    //second  piece  - comment out because I figured out how to do it exactly like the first dart. 
    //p.castOn2.value=p.castOn.value;

        
    /*  
    p.secondRows3.value=p.secondRows4.value=secondRows;
   p.firstRows2.value=p.firstRows.value
    p.dartRowsTotal3.value=p.dartRowsTotal4.value=p.dartRowsTotal.value;
    */
  
    // neck  -- I need approximately 16% extra stitches because usually the rows are too short to  make the 45
    halfBackNeckNeedles= Math.round(1.00 * mult(p.neckWidth.value,p.mainStIn.value)/2);
    //halfFrontNeckNeedles= Math.round(0.95* mult(neckDiagonal, p.mainStIn.value));
    
    
    
    //p.halfBackNeedles.value=halfBackNeckNeedles;
    p.neckNeedles.value=mult(halfBackNeckNeedles,2)
    p.neckIcord.value= mult(halfBackNeckNeedles,4)+8;
    p.neckNeedlesHalf.value=halfBackNeckNeedles;
    //p.halfBackNeckFilled.value = Math.round(0.825*halfBackNeckNeedles); 
    
    
    minRow=Math.round(p.mainRowIn.value/2)*2
    //p.rowsFinalNeck.value = Math.max(minRow,4);
    
    //assemble
    p.castOn3.value=p.castOn.value;
    
    // notes to HKers
    p.secondRows5.value=p.secondRows.value    
    p.lengthDiagonal.value=Math.round(neckDiagonal*10)/10
    p.firstRows3.value=p.firstRows.value
    p.sleeveLenght2.value=p.sleeveLength.value
    
    // idoot cord trim.
    // 2 rows/ per stitch cast on, 1 row per side, plus extra to be safe.
    
    halfIdiotCordRow=eval(p.castOn.value)+ (3/2)*(eval( p.firstRows.value)+ 2* eval(p.secondRows.value)+ 2* eval(p.dartRowsTotal.value) )+20
     //p.firstRows6.value=p.firstRows.value
    
    mark0 = 20;
    // extra 2 is to add a stitch for the corner.
        
   
    
    
     
    mark1 =  2* Math.round(0.5* rowStitchRatio*( 2* eval(p.secondRows.value)+ 2* eval(p.dartRowsTotal.value))); 
    mark1B = 2* Math.round(0.5*rowStitchRatio*( 2* eval(p.secondRows.value)));
    p.mark1Half.value = divide(mark1,2);
    
    mark2 =  2* Math.round(0.5*rowStitchRatio*(eval( p.firstRows.value)))+2;
    centerIcordRows = add(p.castOn.value,2); // the extra one is for the corner
    mark3 = centerIcordRows;
    mark4 = centerIcordRows;
    
    p.mark1.value=mark1
    p.mark2.value=mark2
    p.mark3.value=mark3

     p.mark4.value=mark3
     p.mark5.value=mark2
     p.mark6.value=mark1B
     p.mark6Half.value=divide(mark1B,2);
     
     // Yarn guess
     y=3^2
     
// estimate yardage by thickness ratio.
    theirStitchRatio = divide(6.65,p.mainStIn.value)
    theirRowRatio=divide(10.22,p.mainRowIn.value)
    theirRatio = (theirStitchRatio*theirStitchRatio + theirRowRatio*theirRowRatio)/2;
     thickRatio=  Math.sqrt( theirRatio );
     
     p.thickRatio.value= Math.round(10*thickRatio)/10
     myYarn= 16;
         //alert(thickRatio +", " + theirYarn+", " +theirRowRatio+", " +theirRowRatio  +", "+theirRatio )
    myYardPerLb= 2240; // heather 2/20

     
    myStitch= 153+10; // 10 is for 2 sides of  I cord
    myRows=(236+ 2* 58 + 2*22*(153-0.5*25)/153  ) + 3;// 3 is for I cord -- eqivalent in rows.  Fraction is for partial rows in darts.
     myLength=divide(myRows, 10.22)
     myWidth=divide(myStitch,6.65);
     myArea=myLength*myWidth;
          
     theirRows = eval( p.firstRows.value)+ 2* eval(p.secondRows.value)+ 2* eval(p.dartRowsTotal.value)*(castOn-0.5*dartStitchesTotal)/castOn + 3 ;
     theirStitch = eval(p.castOn.value) + 10;
     theirLength = divide(theirRows,p.mainRowIn.value);
     theirWidth=divide(theirStitch, p.mainStIn.value);
     theirArea= theirWidth*theirLength;
     
     areaRatio = theirArea/myArea;
     p.areaRatio.value= Math.round(areaRatio*10)/10;
     
     effectOfThick = Math.pow(thickRatio,1/3);
     theirYarn= Math.round( myYarn*effectOfThick*areaRatio*10)/10;
     //alert(myYarn +" * " + effectOfThick +" *" +areaRatio +" = " + theirYarn +" myRows " + myRows +" = " + theirRows +" = " + castOn +" = " + dartStitchesTotal)

      p.ounces.value=theirYarn
      p.myYardage.value=myYardage= myYarn * myYardPerLb/16
      
      p.theirYardage.value= theirYardage =Math.round(myYardage*areaRatio /thickRatio);  // twice gauge means half length to cover area. 
     
    /* 
@copyright 2004 Lucia Liljegren
*/

p.tooFewStitches.value = "Thanks for running this from lucia's site. I'll fill the boxes now!" ;
}

else {
     alert(" Please run my programs from my site at www.thedietdiary.com!"  )
    alert("Sorry! I didn't fill the boxes. Please run this page from my site at www.thedietdiary.com!")
    p.tooFewStitches.value = "Please run this from lucia's site!  I'm not filling the result boxes.  ("+pesterZero +" : "+ pesterAway+" : "+pesterRead +")";
    p.mainStIn.value=0.01;
    p.mainRowIn.value=0.01;
}

}

//================ROW STITCH TABLE-----------------------------------
function rowStitchTable(){
    rowStitchWindow= window.open('','rowStitch','toolbar=yes, location=yes, scrollbars=yes, resizable=yes, width=300, height=600, left=0,top=0')
    rowStitchWindow.document.write("<HTML><HEAD><BODY><H1>Row-Stitch Table For Poncho</H1>")
    rowStitchWindow.document.write("<p>This table decribes the needle set up for your poncho.<p><HR>")
    
    rowStitchWindow.document.write("<p>I haven't written this portion of the code yet.  Since the number of stitches on the bed remains constant, it's probably just going to indicate the rows where you hang markers!<HR>")

    
     rowStitchWindow.document.write("<p>Note: When a value is positive, the needle indicated is in work. When it is negative, that needles is taken out of work. This is because there is no 0 needle on the machine bed. If you are a hand knitter, and want to use this sheet, hang yarn between the center two stitches.  Each needle represents one stitch, and you should count stitches to the right and left of center.<HR>")
     // calculate values for table.
     
     
    // first row in table    
    rowStitchWindow.document.writeln("<p><Table Caption= 'Poncho Rectangle 1'><tr> <td>row<\/td> <td>[left,<\/td> <td>right]<\/td> <td>total in row <\/td> <\/tr>")
    // table rows.
    rowStitchWindow.document.writeln("<tr> <td>row<\/td> <td>[left needle,<\/td> <td>right needle]<\/td> <td>total in row <\/td> <\/tr>")
    // final row in table.
    
   // rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+"<\/td> <\/tr>")
   
    // close table
    rowStitchWindow.document.writeln("</Table>")
    
    // close both windows-----------------------------------
    rowStitchWindow.document.write("<\/BODY><\/HEAD><\/HTML>")
    rowStitchWindow.document.close();
    
}
/* 
@copyright 2004 Lucia Liljegren */
