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

//

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

p.tooFewStitches.value = "javascript is on";

  preCircumference = eval(p.hatCircumference.value);
  p.hatCircumference.value =  Math.round(preCircumference *100)/100;
  headDiameter=  preCircumference /Math.PI;  
  headRadius= headDiameter/2;
  
  numShape=6;
  castOn= Math.round(mult(0.93*preCircumference ,p.mainStIn.value));// 
    p.castOn.value=castOn;
    //p.castOnM1.value=castOn;
    //p.castOnM2.value = castOn-1;
    
  brimRows=Math.floor(mult(p.brimDepth.value,p.mainRowIn.value));
        
    p.brimRows.value=Math.max(brimRows,2);
      p.brimRows2.value=eval(p.brimRows.value)-1;// the fidge fold means this needs to be one less.
    
    minHatCirc=preCircumference*1.10;
    minHatStitches= Math.round(mult( minHatCirc ,p.mainStIn.value)/numShape)*numShape;
    hatStitches = Math.ceil((castOn+3)/numShape)*numShape;
    hatStitches=Math.max(hatStitches,minHatStitches);
    circumference = divide(hatStitches,p.mainStIn.value);
    p.hatCircumference2.value =  Math.round(circumference*10)/10; 
    hatDiameter=  circumference/Math.PI;
    hatRadius= hatDiameter/2;
    
    p.hatStitches.value=hatStitches;
    totalInc=hatStitches-castOn;
    p.totalInc.value=totalInc;


// adust for whatever is smaller.

p.brimCircumferencePre.value= Math.round(preCircumference*divide(p.mainStIn.value,p.mainStInBefore.value)*10)/10;
p.hatCircumferencePre.value = Math.round(circumference*divide(p.mainStIn.value,p.mainStInBefore.value)*10)/10;

lengthThree= divide(1-eval(p.brimRows.value),p.mainRowIn.value)
feltLengthRatio=divide(p.mainRowIn.value,p.mainRowInBefore.value);
minLength=Math.max((hatRadius-headRadius)*1.1,1.1*hatRadius+lengthThree); //  needs to be long enough to go out like a beret!
p.threeInches.value=Math.round(feltLengthRatio*(minLength)*10)/10;
//p.fiveInches.value=Math.round(add(p.threeInches.value,p.bandDepth.value)*10)/10;


// decrease top of hat.
betDecFirst = hatStitches/numShape;
p.betDecFirst.value=betDecFirst;
p.betDecFirst2.value=betDecFirst;


between=betDecFirst-4; // 4 involved in reductios.
odd=between%2;

betDecFirstHalf =1;
betDecFirstHalf2=between-betDecFirstHalf;

//p.betDecFirstHalf.value=betDecFirstHalf;
p.betDecFirstHalf2.value=betDecFirstHalf2;
// next round
betDecSecond = betDecFirst-2
p.betDecSecond.value=betDecSecond;

//p.betDecSecondHalf.value=betDecFirstHalf;
p.betDecSecondHalf2.value=betDecFirstHalf2-2;
//
betDecThird=betDecSecond-2
p.betDecThird.value=betDecThird;

rowsToCenter=Math.round(mult(hatRadius,p.mainRowIn.value))-2-3;  // 1 is for the actual final decrease, the extra is because it's stretchy, 3 is for the three before you start the repeats.
decToCenter=Math.round(rowsToCenter/4); // 4 rows between decreases.
finalBetween = Math.max(betDecFirst-2*decToCenter,4+between%2);  // 2 decreased per wedge.
p.finalBetween.value=4-odd;
stDecToCenter=sub(betDecFirst,p.finalBetween.value);
//alert(stDecToCenter);

//p.threeRows.value=Math.round(mult(p.threeInches.value,p.mainRowIn.value));

allBillStitches = Math.ceil(castOn/6)*3;
ExtraStitches=(Math.ceil(castOn/5)*3-allBillStitches)/2;

halfAllBillStitches= allBillStitches/2;
extraPerSide=Math.floor(ExtraStitches/2);

p.extraPerSide.value=extraPerSide;
p.extraPerSide2.value=extraPerSide;
p.allBillStitches.value=allBillStitches+2*extraPerSide;
reduced=sub(p.allBillStitches.value,halfAllBillStitches);

allBillRows=2*Math.round(0.85*mult(p.threeInches.value,p.mainRowInBefore.value)/2-3/2);// length matches length before felting.
two=Math.round(reduced/allBillRows);

reducedStitches=two*allBillRows;
p.frontBillStitches.value=sub(p.allBillStitches.value,reducedStitches);

p.two.value=Math.max(two,1);
p.four.value=2*eval(p.two.value);

p.two2.value = p.two.value
p.two3.value = p.two.value
//p.two4.value = p.two.value;

p.four2.value= p.four.value

widthChangePer24Stitch=divide(24,p.mainStIn.value)
lengthChangePer24=divide(widthChangePer24Stitch,2* Math.PI)
rowsPer24StitchAlt = Math.floor(mult(lengthChangePer24,p.mainRowIn.value));
// account for the placement row, the k2 tog row and the last dec row -3
// then back off because the rest of the rows are associated with the beg. Dec.
rowsPer24Stitch=Math.round((rowsToCenter-3)/((stDecToCenter-2)*6) * 24);// if anything, it's best to decrease too slow.  
//alert(rowsPer24Stitch + " alt " + rowsPer24StitchAlt)

seven=rowsPer24Stitch+1;
p.five.value=Math.floor(rowsPer24Stitch /2)+2
p.aFew.value=sub(p.five.value,2)-1;
p.aFewMore.value=sub(seven,p.five.value);
p.six.value=rowsPer24Stitch;



}