function mkBeret(){
p =document.hatForm;

pester = document.location;

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(pesterAway == "www.thedietdiary.com"){pester="no"}
else if(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! " + " xaway  =" + pesterAway +":" ) } ;

//
stitchCount=0;// for yardage estimator!
p.tooFewStitches.value = "javascript is on";

if(p.felted.selectedIndex == 0){felted=1; }
  else{felted = 0; p.mainStIn.value=p.mainStInBefore.value; p.mainRowIn.value=p.mainRowInBefore.value; }

p.tightnessFactor.value = Math.max(p.tightnessFactor.value, -20);

p.hatCircumference.value= Math.round(mult(p.headCircumference.value, 1-eval(p.tightnessFactor.value)/100)*10)/10;
 circumference = mult(p.hatCircumference.value,1);
 headCircumference = eval(p.headCircumference.value);
 
 p.hatCircumference.value =  Math.round(circumference*10)/10;
 
  hatDiameter=  circumference/Math.PI;
  headDiameter = headCircumference/Math.PI;
  refDiam=22/Math.PI;// this is a size medium womans-- and will 25/3 inches long
  refFlange=1.7; // 1.5" flipped out brim. This seems comparable to Wallmart rain hats.
  
 
hatRadius= hatDiameter/2;
flangeLength=refFlange*(hatDiameter/refDiam);
bodyLength=2.05*hatRadius;
outerLength= bodyLength+flangeLength;// the factor of 2 for the beenie depth seems to match my other hats well.


//I want the left needles to come 2/3 of the extra radius in.  that reduced the hat diameter some, but not completely.
// to make totally flat, with the swirls, 

crownRows= Math.round(mult(hatRadius,p.mainRowIn.value)/1.05);// close to flat top. 1.207 would be average length of stitch column and diagonal that becomes swirl.
hatStitches=Math.round(mult(circumference,p.mainStIn.value)/2)*2;
p.hatCircumference.value=Math.round(divide(hatStitches,p.mainStIn.value)*10)/10;

p.hatStitches.value=hatStitches;

numWedge=8;
afterFirstDec=hatStitches-numWedge;
p.afterFirstDec.value=afterFirstDec;


placeCrownMarkers= new placeMarkers(numWedge,hatStitches)

p.betDecFirst.value=placeCrownMarkers.smallRepSt;
p.betDecSecond2.value=placeCrownMarkers.largeRepSt;

p.nTimes1.value=placeCrownMarkers.numLarge;
p.nTimes2.value=placeCrownMarkers.numSmall;
    
// number of rows between crown decreasese. 
finalStitches=placeCrownMarkers.finalStitches;
p.finalStitches.value=finalStitches/2; // in instructions, after k2tog.
stitchToDec=(hatStitches-finalStitches)/numWedge;

crownShaping= new crownSequence(crownRows-1,stitchToDec); // -1 because there is an extra row after the fnal shape
p.aFew.value =crownShaping.short2; p.crown1.value=crownShaping.nTimes2; 
    p.stitchesAfterFirstShape.value= hatStitches-numWedge*crownShaping.nTimes2

p.aFew2.value=crownShaping.short1; p.crown2.value=  crownShaping.nTimes1;
    p.stitchesAfterSecondShape.value= hatStitches-numWedge*(crownShaping.nTimes1+crownShaping.nTimes2);
// find number of stitches at edge of brim

extraFlangeStitch = Math.round(mult(flangeLength*1.6*Math.PI, p.mainStIn.value)/numWedge)*numWedge; 
adjustStitch = Math.round(mult(flangeLength*1.6*Math.PI, p.mainStIn.value)/2)*2 -extraFlangeStitch;
adjustStitch=Math.min(adjustStitch,6); 
adjustStitch=Math.max(adjustStitch,0);
flangeRows = Math.round(mult(flangeLength,p.mainRowIn.value));
p.adjustStitch.value=adjustStitch

brimStitches=hatStitches+extraFlangeStitch+adjustStitch;
p.castOnP1.value=brimStitches;
p.castOn.value=add(p.castOnP1.value,1);
p.castOnM2.value=sub(p.castOnP1.value,1);
p.afterFirstDecBrim.value=sub(brimStitches,numWedge);

placeBrimMarkers= new placeMarkers(numWedge, brimStitches);
p.betDecBrim.value=placeBrimMarkers.smallRepSt;
p.betDecSecond2Brim.value=placeBrimMarkers.largeRepSt;

p.nTimes1Brim.value=placeBrimMarkers.numSmall;
p.nTimes2Brim.value=placeBrimMarkers.numLarge;
// shape flange

flangeShaping = new crownSequence(flangeRows-1,extraFlangeStitch/numWedge); // -1 because of last shape.
p.aFewBrim.value =flangeShaping.short2; p.brim1.value=flangeShaping.nTimes2; 
    p.stitchesAfterFirstShapeB.value= brimStitches-numWedge*flangeShaping.nTimes2

p.aFew2Brim.value=flangeShaping.short1; p.brim2.value=  flangeShaping.nTimes1;
bodyRows=Math.round(mult(bodyLength,p.mainRowIn.value))

p.threeInchesRounds.value=bodyRows-crownRows;
p.threeInches.value = Math.round(10*divide(p.threeInchesRounds.value,p.mainRowInBefore.value))/10;


// estimate yardage:
stitchCount = 0
stitchCount += stitchCount+eval(p.castOnP1.value)*4;
//stitchCount +=

}

function crownSequence(crownRows,stitches){


    shapes=stitches;
    crownOps=crownRows
    short1=Math.floor(crownOps/shapes)-1;
    short2=Math.ceil(crownOps/shapes)-1;
    nTimes2=crownOps%shapes;
    nTimes1=shapes-nTimes2;
        

this.shapes=shapes;
this.short1=short1;
this.short2=short2;
this.nTimes2=nTimes2;
this.nTimes1=nTimes1;

}

function placeMarkers(numWedge,hatStitches){

halfWedge=numWedge/2;
smallRepSt=Math.floor((hatStitches/2)/halfWedge);
largeRepSt=Math.ceil((hatStitches/2)/halfWedge);


numLarge= (hatStitches/2)%halfWedge;
numSmall=halfWedge-numLarge;
two=2;
finalStitches=(numSmall+2*numLarge)*two;

if(numSmall == numLarge){  numSmall=1; numLarge=1; two= numWedge/2;  }

this.numSmall= numSmall;
this.numLarge =numLarge ;
this.smallRepSt = smallRepSt;
this.largeRepSt = largeRepSt;
this.two=two;
this.finalStitches=finalStitches;

}

