function rollHat(){
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.hatDiameter.value= mult(p.headDiameter.value, 1-eval(p.tightnessFactor.value)/100);
baseStitches = Math.round(mult(p.mainStIn.value, p.hatDiameter.value)/4)*4
p.castOn.value= baseStitches + 1;
totalLength= mult(p.hatDiameter.value, 0.4);
p.totalLength.value=Math.round(totalLength*10)/10;

lastThird=totalLength/5;
firstLength = totalLength-lastThird;
//alert(p.hatDiameter.value + " : length="+  totalLength +" : lastThird="+ lastThird +" : firstLength="+ firstLength)

lastRounds=Math.max(Math.round(mult(lastThird,p.mainRowIn.value)),6);
p.firstLength.value=Math.round(firstLength*10)/10;
p.lastLength.value= Math.round(lastThird*10)/10;
p.roundsBefore1.value=Math.round(mult(firstLength,p.mainRowIn.value));
roundsAfter1 = Math.round(0.65*lastRounds)-1-2; // accouns for dec. row
roundsAfter2 = lastRounds-(roundsAfter1+1) -1-2; //accounts for dec. round
p.roundsAfter1.value=roundsAfter1;
p.roundsAfter2.value=roundsAfter2;

p.stitchesAfter1.value= 3*baseStitches/4;
p.stitchesAfter2.value = Math.floor(mult(2/3,p.stitchesAfter1.value));
p.stitchesAfter3.value= Math.floor(mult(1/2, p.stitchesAfter2.value));

}

