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.
numPieces = 4;
point="down";

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

p.tooFewStitches.value = "Calculating" ;
p.chevTotRep.value = Math.round(Math.max( eval(p.chevTotRep.value), 2) );
chevTotRep = eval(p.chevTotRep.value); // this will change when I add a toggle.
    p.firstRepRows.value = eval(p.chevTotRep.value)-1;
/* make sure the toggle doesn't fill with letters! 
Should be redundant: coding of HTML page should also give text box and toggles different names.
*/

// figure out alpha, beta.

var tanAlpha = divide(p.mainRowIn.value, chevTotRep*p.mainStIn.value);
var alpha = Math.atan(tanAlpha);
var alphaDeg = alpha * 180/Math.PI;
flareDeg = 2*alphaDeg;


//p.alpha.value= justRound(alpha);
p.alphaDeg.value=justRound(alphaDeg);
    p.alphaDeg2.value=p.alphaDeg.value
    p.flareDeg.value = justRound(flareDeg);
    
// reference: slant if shoulder dart is alpha
//var min2alpha = Math.PI/2 - 2*alpha;
//var min2alphaDeg = min2alpha * 180/Math.PI;

bestBetaDeg = 10;

bestGammaDeg = 90-alphaDeg-bestBetaDeg;
bestGamma = bestGammaDeg * Math.PI/180;
p.gammaDeg.value  = bestGammaDeg;

beta = bestBetaDeg* Math.PI/180; // fix later.
gamma = bestGamma;// fix later.

topTrap= eval(p.headOpening.value)/4 ;// inches
stitchesTopTrap = Math.round(topTrap* p.mainStIn.value)
topTrap= divide(stitchesTopTrap,p.mainStIn.value);
    p.stitchesTopTrap2.value=stitchesTopTrap;
    p.stitchesTopTrap.value = stitchesTopTrap;

shortenFront = eval(p.shortenFront.value);
rowsLessFront = 2*Math.round(shortenFront*p.mainRowIn.value/2);
p.rowsLessFront.value=rowsLessFront;

shortenFront = divide(rowsLessFront,p.mainRowIn.value);
widthToRight = shortenFront*Math.sin(alpha);
tanPhi= shortenFront/(topTrap+widthToRight);
phi=Math.atan(tanPhi)
phiDeg = phi*180/Math.PI;

/* 
@copyright 2004 Lucia Liljegren
*/


p.phiDeg.value = justRound(phiDeg);
p.shortenFront.value=justRound(shortenFront);
p.headOpeningReal.value = Math.round(2*topTrap*(1+1/Math.cos(phi))*10)/10; // it's really longer.. fix later.

halfShoulderWidth = eval(p.shoulderWidth.value)/2;
p.neckWidth.value = justRound(topTrap);
p.backNeckDepth.value = justRound(topTrap * Math.sin(alpha));
p.backNeckWidth.value = justRound(2*topTrap * Math.cos(alpha));


  // this may not be rounded.  That's ok. 
p.frontNeckDepth.value = justRound(eval(p.backNeckDepth.value)+ shortenFront)

if(point== "down"){ neckContribution = topTrap*Math.cos(alpha);}
    // side only happens when there are 4 pieces.
//if(point =="side"){ neckContribution = topTrap/2 + (topTrap/2)*Math.cos(2*alpha); }  

unSlantRemHalfShoulder = halfShoulderWidth - neckContribution;
slantRemHalfShould = unSlantRemHalfShoulder/Math.cos(beta);  // This is the slanted 

//alert(beta + "|"+ alpha + "|"+ topTrap  + "|"+ neckContribution  + "|"+ halfShoulderWidth+ "|")
//alert(+ unSlantRemHalfShoulder + "|"+slantRemHalfShould)

//alert (topTrap +" : neck contr=  "+ neckContribution+" : unslant= "+ unSlantRemHalfShoulder+" <"+ slantRemHalfShould)


if(unSlantRemHalfShoulder<0.1){
    p.tooBigHead.value = "Neck opening is wider than shoulders. Please make the head size smaller or the shoulder larger. "}
else {p.tooBigHead.value ="" }

    // put into as knitted coordinate system and divide by two for half shoulder.
yRem = slantRemHalfShould*Math.cos(gamma); // rows
xRem = slantRemHalfShould*Math.sin(gamma); // stitches
perfectXoverY = xRem/yRem;

totRowsShoulder = 2*Math.ceil(mult(yRem,p.mainRowIn.value)/2);
actYRem=divide(totRowsShoulder,p.mainRowIn.value);
bestXrem=actYRem*perfectXoverY;
totStitchesShoulder= Math.round(mult(bestXrem,p.mainStIn.value));
actXRem = divide(totStitchesShoulder,p.mainStIn.value);

tanGamma=actXRem/actYRem
gamma=Math.atan(tanGamma)
gammaDeg=gamma*180/Math.PI;
    p.gammaDeg.value=justRound(gammaDeg);
betaDeg=90-gammaDeg-alphaDeg;
    beta = betaDeg*Math.PI/180;
p.betaDeg.value = justRound(betaDeg);

p.totRowsShoulder.value = totRowsShoulder;
p.totStitchesShoulder.value = totStitchesShoulder;

// find number of repeats for back diagonal on shoulderside.


bestHeightTrap = eval(p.diagonalLength.value, Math.cos(alpha));
firstRows= 2*Math.round(chevTotRep/2);
    p.firstRows.value= firstRows;
heightFirstRows = firstRows/eval(p.mainRowIn.value);

heightToShoulder=(bestHeightTrap-actYRem);
numRepeatsToShoulder = Math.round( ( heightToShoulder-heightFirstRows)*eval(p.mainRowIn.value) /chevTotRep )
    p.chevTotRepTimes.value= numRepeatsToShoulder;
rowsToShapeToShoulder = chevTotRep*numRepeatsToShoulder;

boundOffOnLeft=numRepeatsToShoulder;

endShoulderRows = rowsToShapeToShoulder+firstRows
    p.endShoulderRows.value=endShoulderRows;
    
if(endShoulderRows%2 == 0) {oneShoulder = 1; oneShoulderMirror=0}
else {oneShoulder = 0;oneShoulderMirror=1}
p.oneShoulder.value = oneShoulder;
p.oneShoulderMirror.value =oneShoulderMirror

shapeOpportunities = totRowsShoulder/2 ;
    numShoulderRep=shapeOpportunities;
ratioStitchesToOpps = totStitchesShoulder/shapeOpportunities;

endBackRows=endShoulderRows +totRowsShoulder-1+oneShoulder;
boundOffOnLeft=boundOffOnLeft+totStitchesShoulder;




p.endBackRows.value =endBackRows;// extra one to get to right side and shape.

if(1 < ratioStitchesToOpps ){  
    shapeTimes=shapeOpportunities;
    minStitch=Math.floor(totStitchesShoulder/shapeOpportunities)
    maxStitch=minStitch+1
    maxTimes=totStitchesShoulder%shapeOpportunities
    minTimes=shapeTimes-maxTimes-1;
    rowsBetweenMin=1;
    rowsBetweenMax=1;
}
else{
alert("I haven't coded this type of shoulder because i don't belive anyone wants this poncho.  Please check your stitch and row gauge.")
    shapeTimes="XXX";
    minStitch="XXX"
    maxStitch="XXX"
    maxTimes="XXX"
    minTimes="XXX";
    rowsBetweenMin=1;
    rowsBetweenMax=1;

}

p.minStitch.value = minStitch
p.minStitch2.value =p.minStitch.value
p.maxStitch.value = maxStitch

p.maxTimes.value = maxTimes
p.minTimes.value = minTimes

p.rowsBetweenMin.value = rowsBetweenMin
p.rowsBetweenMax.value = rowsBetweenMax


// now row count for front.
rowsLessFront = rowsLessFront-endBackRows%2
rowCountToNeck = endBackRows-rowsLessFront;
p.rowCountToNeck.value=rowCountToNeck
numberStitchesAlreadyDec= Math.ceil((rowCountToNeck-firstRows)/chevTotRep)
numberOfStitchesNoShape=Math.ceil( (endBackRows-firstRows)/chevTotRep);

p.numDecRight.value = numberOfStitchesNoShape-numRepeatsToShoulder;

numStitchesLeft=(numberOfStitchesNoShape-numberStitchesAlreadyDec)+stitchesTopTrap;

p.totFrontNeckStitches.value=numStitchesLeft
p.totFrontNeckRows.value = rowsLessFront;

shapeOpportunities=rowsLessFront/2+1;

    shapeTimes=shapeOpportunities;
    p.minStitchNeck.value=minStitch= Math.floor(numStitchesLeft/shapeOpportunities)
    p.minStitchNeck2.value=p.minStitchNeck.value;
    p.maxStitchNeck.value=maxStitch=minStitch+1
    p.maxTimesNeck.value =maxTimes=numStitchesLeft%shapeOpportunities
    p.minTimesNeck.value=shapeTimes-maxTimes-1;
    
    //boundOffOnLeft=0
    //stitchesTopTrap=0
    //numberOfStitchesNoShape=0;
    
    castOn=boundOffOnLeft+stitchesTopTrap+numberOfStitchesNoShape
    //alert( " ( "+numRepeatsToShoulder+ " + "+totStitchesShoulder +" ) =" +boundOffOnLeft+" : "+stitchesTopTrap+" : "+numberOfStitchesNoShape)
    
    	p.castOn.value = castOn
   p.stitchesAtShoulder.value = eval( p.castOn.value)-2*numRepeatsToShoulder;
   p.hemWidth.value = divide(p.castOn.value,p.mainStIn.value);
   p.height.value=divide(endBackRows,p.mainRowIn.value);

//rowStitchTable()
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;
}

}

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 Back Poncho</H1>")
    rowStitchWindow.document.write("<p>This table decribes the needle set up for the row indicated when you knit the <b>first</b> back piece.  You  must mirror the directions for the right side. Note: When you reach the shoulder shaping, the row counts will be shifted by one when you mirror.<p><HR>")
    
    rowStitchWindow.document.writeln("<p><Table><tr> <td>row<\/td> <td>[left,<\/td> <td>right]<\/td> <td>total in row <\/td> <\/tr>")
    
    // cast on and first two rows.
    firstLeft=castOnLeft=Math.floor(castOn/2);
    firstRight=castOnRight=firstLeft+castOn%2;
    
    total=firstLeft+firstRight;
    rowCount=0
    
    rowStitchWindow.document.writeln("<tr> <td colspan=4><HR><\/td>  <\/tr>")
    rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+"<\/td> <\/tr>" )
    
    // now the diagonal repeats up to the shoulder.
    rowCount=rowCount+firstRows    
    
    for (var i=0; i<numRepeatsToShoulder; i++){
	
	firstLeft--;
	firstRight--;
	total=firstLeft+firstRight;
	rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+"<\/td> <\/tr>" )
	rowCount=rowCount+chevTotRep

    }
    rowStitchWindow.document.writeln("<tr> <td colspan=4><HR><\/td>  <\/tr>")
    
    // add row for shoulder
    if(oneShoulder==1){
       if(rowCount%chevTotRep ==0){firstRight--;}
       total=firstLeft+firstRight;
	rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+"(extra  row) <\/td> <\/tr>" )
    rowCount=rowCount+oneShoulder
    }
    // shoulder shaping print row by row now.
    var j=0 
    var reduceBeforeNeck=0
        for (var i=0; i< totRowsShoulder-1; i++){ 
	
    if(rowCount%2 ==1){
	j++;
	if( j<= eval(p.minTimes.value) || (numShoulderRep)==(j)){	
	    firstLeft=firstLeft-eval(p.minStitch.value);
	    if(rowCount <= rowCountToNeck){reduceBeforeNeck=reduceBeforeNeck+eval(p.minStitch.value)}	
	}
	else{	
	    firstLeft=firstLeft-eval(p.maxStitch.value);
	    if(rowCount <= rowCountToNeck){reduceBeforeNeck=reduceBeforeNeck+eval(p.maxStitch.value)}
	}
    }
    if(rowCount%chevTotRep ==0){firstRight--;}
    
    total=firstLeft+firstRight;
    rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+  "( sh. red. # "+ j +")<\/td> <\/tr>")
    rowCount=rowCount+1;
   
    }
    // final row!
    
    rowStitchWindow.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>"+total+"<\/td> <\/tr>")
    
    rowStitchWindow.document.writeln("</Table>")
    
    //-----------Front-----------
    rowStitchWindowFront= window.open('','rowStitchFront','toolbar=yes, location=yes, scrollbars=yes, resizable=yes, width=300, height=600, left=30,top=30')
    rowStitchWindowFront.document.write("<HTML><HEAD><BODY><H1>Row-Stitch Modifications For Front Poncho</H1>")
    
    if(rowsLessFront==0){rowStitchWindowFront.document.write("<p> The front is the same as the back.");}
    
    else{
    
    rowStitchWindowFront.document.write("<p>Note: When a value is positive, the needle indicates is in work. When it is negative, that needles is taken out of work. This is because there is no 0 needle. <HR>")
    
    rowStitchWindowFront.document.writeln("<br><Table><tr> <td>row<\/td> <td>[left,<\/td> <td>right]<\/td> <td>total in row <\/td> <\/tr>")
    rowStitchWindowFront.document.writeln("<tr> <td colspan=4><HR><\/td>  <\/tr>")
    rowCount=rowCountToNeck
    preCount=rowCount-1;
    
    if( preCount<endShoulderRows ){firstLeft=  castOnLeft-Math.floor( preCount/chevTotRep);}
    
    else{	firstLeft = castOnLeft-numRepeatsToShoulder-reduceBeforeNeck}
        
    
    firstRight=castOnRight-Math.floor(preCount/chevTotRep);// number before reducing.
    
    total=firstLeft+firstRight;
    
    
    rowStitchWindowFront.document.writeln("<tr> <td>" + preCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>  "+total+"  (same as for back)<\/td> <\/tr>")
    rowStitchWindowFront.document.writeln("<tr> <td colspan=4><HR><\/td>  <\/tr>")
    j=0;
    if(endShoulderRows < rowCount){j = Math.floor((rowCount-endShoulderRows+oneShoulder)/2); }
    var jneck=0;
/* 											@copyright 2004 Lucia Liljegren
*/
    
    
    for(var i=0; i<rowsLessFront+1; i++){
    // left side-----
    if( (rowCount<endShoulderRows)){
	if((rowCount-firstRows)%chevTotRep ==0){firstLeft--}
    }
    else if(rowCount%2 ==1){
    j++;
	if( j<= eval(p.minTimes.value) || (numShoulderRep)==(j)){	
	    firstLeft=firstLeft-eval(p.minStitch.value);
	    if(rowCount <= rowCountToNeck){reduceBeforeNeck=reduceBeforeNeck+eval(p.minStitch.value)}	
	}
	else{	
	    firstLeft=firstLeft-eval(p.maxStitch.value);
	    if(rowCount <= rowCountToNeck){reduceBeforeNeck=reduceBeforeNeck+eval(p.maxStitch.value)}
	}    
    }
    // right side
    
    if(rowCount%2==0){
	jneck++;
	if( jneck<=eval(p.minTimesNeck.value) || (shapeTimes-1)<jneck){
	      firstRight =firstRight-eval(p.minStitchNeck.value)}
	else{ firstRight =firstRight-eval(p.maxStitchNeck.value)}
    }
    
    total=firstLeft+firstRight;
    rowStitchWindowFront.document.writeln("<tr> <td>" + rowCount + "<\/td> <td> [ " + firstLeft +", <\/td> <td> "+firstRight+ "] <\/td> <td>  "+total+"( neck red. # "+ jneck+" sh. rep # "+j+" ) <\/td> <\/tr>")
     rowCount++;
    }
    rowStitchWindowFront.document.writeln("</Table>")
    
    }
    
// close both window
    rowStitchWindow.document.write("<\/BODY><\/HEAD><\/HTML>")
    rowStitchWindow.document.close();
    
    rowStitchWindowFront.document.write("<\/BODY><\/HEAD><\/HTML>")
    rowStitchWindowFront.document.close();
    
}

/* 
@copyright 2004 Lucia Liljegren */
