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 +":" ) } ;

//
p.tooFewStitches.value = "javascript is on";
//p.diameterMultiple.value = Math.max(1.2, eval(p.diameterMultiple.value));
p.tightnessFactor.value = Math.max(p.tightnessFactor.value, -10);

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.6; // 1.5" flipped out brim. This seems comparable to Wallmart rain hats.
  
 // p.hatDiameter.value= Math.round(hatDiameter*10)/10;

//baseStitches = Math.round(mult(p.mainStIn.value,hatDiameter)/8)*4;

hatRadius= hatDiameter/2;
flangeLength=refFlange*(hatDiameter/refDiam);
outerRadius= 2.1*hatRadius+flangeLength;// the factor of 2 for the beenie depth seems to match my other hats well.
flangeRadius=outerRadius-flangeLength;


difRadius= outerRadius-hatRadius;

//alert(hatRadius + " - " + headRadius +  " = " +difRadius)
//I want the left needles to come 2/3 of the extra radius in.  that reduced the hat diameter some, but not completely.

fullLeftNeedle = Math.round(1.0*mult(difRadius,p.mainStIn.value)); // factor to take care of the spirals.
rightSideNeedle= Math.round(1.00*mult(hatRadius,p.mainStIn.value));// I want the shaping to be more gradual-- not flat top.
castOn= fullLeftNeedle + rightSideNeedle;
flangeLeftNeedle= Math.round(mult(flangeLength,p.mainStIn.value));

unusedNeedle = Math.round(rightSideNeedle/12);
leftSideNeedle=flangeLeftNeedle; // this is the number actually short rowed
   
p.castOn.value=castOn;
p.rightSideNeedle3.value=rightSideNeedle;
p.leftSideNeedle.value=flangeLeftNeedle;

numWedge=8;
p.repeatTimes.value = (numWedge)/2-1;
p.numWedge.value = numWedge;

//find total hat rows.
BestRows= Math.round(mult(circumference,p.mainRowIn.value)/numWedge);
rowsPerWedgeLow=Math.floor( BestRows/2)*2;

rowsPerWedge = rowsPerWedgeLow + 2*(BestRows%2); 
aveRowsPerWedge=(rowsPerWedgeLow+rowsPerWedge)/2
totalRows=numWedge*aveRowsPerWedge; 

//alert("best=" + BestRows + " Low= " + rowsPerWedgeLow + ": " + rowsPerWedge + ": ave= "+aveRowsPerWedge + " totalRows=" + totalRows )

p.hatCircumference.value=Math.round(divide(totalRows,p.mainRowIn.value)*10)/10;
 
rowsPerFlange=Math.round(mult(1.5*flangeLength*Math.PI,p.mainRowIn.value)/(2*numWedge))*2 // 2*pi would be totally flat
// pi goes out 1/2 and down root(3)/2. I gueess if I want 45 degrees, I can multiply by 1.4
outerCircumf= divide(totalRows+numWedge*rowsPerFlange,p.mainRowIn.value);
// this is for the curl up trim.
p.bandNeedles.value = Math.round(mult(1.05*outerCircumf,p.mainStIn.value));
bandRows1=Math.max(Math.round(mult(0.3,p.mainRowIn.value)),4);
p.bandRows1.value=bandRows1;
if(bandRows1%2 ==1){p.COL.value="left";}
else{p.COL.value="right"}

//alert(rowsPerFlange);

shapesPerWedge=(rowsPerWedge/2-1);// -1 because two are for taking needles out of work.
shapesPerFlange=(rowsPerFlange/2-1);

p.rcFlange.value=rowsPerFlange+1;
p.rcWedge.value=add(p.rcFlange.value,rowsPerWedge-2);
p.rcWedgeFinal.value=rowsPerFlange+rowsPerWedge;

p.rcWedge3.value=add(p.rcFlange.value,rowsPerWedgeLow-2);
p.rcWedgeFinal3.value=rowsPerFlange+rowsPerWedgeLow;
// find best shaping

repeatRows=4
shortSeq= new shortSequence(repeatRows,flangeLeftNeedle,rowsPerFlange)
short1=shortSeq.short1;
short2=shortSeq.short2;
nTimes2=shortSeq.nTimes2;
nTimes1=shortSeq.nTimes1;

p.rightSideNeedle.value=castOn-short1;
p.nTimes1.value=nTimes1-1;
p.nTimes2.value=nTimes2;
p.shortRow1.value=short1;
p.shortRow2.value=short2;
p.shortRow1_first.value=p.shortRow1.value;

p.midRow.value=castOn-flangeLeftNeedle-rightSideNeedle;
// crown
shortSeq= new shortSequence(repeatRows,rightSideNeedle,rowsPerWedge-2);// because two  more rows get knit ver everything.
short1=shortSeq.short1;
short2=shortSeq.short2;
short2=shortSeq.short2;
if(shortSeq.nTimes2 !=0){ // adjust for last pass
    nTimes2=shortSeq.nTimes2-1;
    nTimes1=shortSeq.nTimes1;
    remNeedles=short2;  }
else{
    nTimes2=shortSeq.nTimes2;
    nTimes1=shortSeq.nTimes1-1;
    remNeedles=short1;  }

p.nTimes12.value=nTimes1;
p.nTimes22.value=nTimes2;
p.shortRow1_2.value=short1;
p.shortRow2_2.value=short2;
p.remNeedles2.value =remNeedles;

// second wedge-- crown. 
 shortSeq= new shortSequence(repeatRows,rightSideNeedle,rowsPerWedgeLow-2);// because two  more rows get knit ver everything.
short1=shortSeq.short1;
short2=shortSeq.short2;
if(shortSeq.nTimes2 !=0){
    nTimes2=shortSeq.nTimes2-1;
    nTimes1=shortSeq.nTimes1;
    remNeedles=short2; }
else{
    nTimes2=shortSeq.nTimes2;
    nTimes1=shortSeq.nTimes1-1;
    remNeedles=short1;
}


p.nTimes13.value=nTimes1;
p.nTimes23.value=nTimes2;
p.shortRow1_3.value=short1;
p.shortRow2_3.value=short2;
p.remNeedles.value =remNeedles;

p.rightSideNeedle5.value=p.rightSideNeedle3.value
p.rcFlangeP2.value=add(p.rcFlange.value,2)
}

function shortSequence(repeatRows,stitches,rows){

    shapes=rows/2;
    short1=Math.floor(stitches/shapes);
    short2=Math.ceil(stitches/shapes)
    nTimes2=stitches%shapes;
    nTimes1=shapes-nTimes2;

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


}
