function rollHat(){
p =document.mittenForm;
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.  Thanks! I can calculate.";


// guess for foot length based on shoe size.   
    var extra;
     var stdRatio = 1.8;
     
     extra= eval(p.size.selectedIndex);
     
	if(p.range.selectedIndex == 0){extra += 5;}	
	else if(p.range.selectedIndex == 1){ extra += 0;}
	else if(p.range.selectedIndex == 2){ extra += 11;}
  
  
  if(p.felted.selectedIndex == 0){felted=1; }
  else{felted = 0; }
   if(p.fairisle.selectedIndex == 0){fairIsle=2; two=2 }// double number of rounds on outside.
  else{fairIsle= 1;two=1; }

rowStitchRatio=divide(p.mainRowIn.value,p.mainStIn.value)
if(2 < rowStitchRatio ){p.tooFewStitches.value= "Please double check your gauge. You must enter rows of knitting per inch on a swatch knit flat.  When knitting fair isle flat, two carriage passes are required to knit 1 full row."}
   
    
   normSize= extra;
    circumference = (5.4 + normSize/2.5) ;// this is for mitts with thumb to the side.
    stdLength=1.03*circumference;
    p.stdLength.value = Math.round(10*stdLength)/10; 
     
    lengthFour=divide(8,p.mainRowIn.value);
    flangeLength=Math.max(lengthFour, stdLength/3.5);
    flangeRows= 2*two*Math.round(mult(flangeLength,p.mainRowIn.value));
   // p.flangeRows.value = 2;
    //p.flangeRows2.value=p.flangeRows.value // don't divide by two because I'm folding them!
    
    ribLength=Math.max(lengthFour,3*stdLength/10);
    
    ribRows=Math.round(mult(ribLength,p.mainRowIn.value) )*2;// no two because not fair Isle
    p.ribRows2.value=add(ribRows,2);
   
    //preThumbLength=Math.max(circumference/5.,lengthFour);
   // preThumbRows=(Math.round( mult(preThumbLength,p.mainRowIn.value))-felted)*2*two;// 1 fewer to account for extra for felting.
   
    
    //thumbGussetLength=Math.max(circumference/4,lengthFour);
    thumbStitches = Math.round(mult(circumference/5.,p.mainStIn.value))+felted;
    // add width to include thumb
    thumbWidth=divide(thumbStitches,p.mainStIn.value);// add a little for the thumb width compared to my other mittens.
    circumference += thumbWidth/2;
    p.circumference.value=Math.round(circumference*10)/10;
    
    p.thumbStitches.value=thumbStitches;
    //p.thumbGussetRows.value= 2*thumbStitches;
    
    totalRows=2*two*Math.ceil(mult(stdLength,p.mainRowIn.value));
    
     
     preThumbRows=Math.round(totalRows/(5*two))*2*two;//made more
     p.preThumbRows.value=preThumbRows;
     p.preThumbRows2.value=add( p.preThumbRows.value,p.ribRows2.value);
   
     p.totalRows.value=add(totalRows,p.ribRows2.value);
    p.totalRows2.value=totalRows/two -2;
    
    p.ThumbStitchesP2.value=thumbStitches+1;
    redThumb=Math.max(2*Math.round((thumbStitches+1)/4),2);
    p.ThumbStitchesEnd.value=sub(p.ThumbStitchesP2.value,redThumb);
    thumbLength= Math.max(stdLength/2.5,lengthFour);// longer than other thumb because no gusset for part of length.
    p.thumbRows.value=2*Math.round(mult(thumbLength,p.mainRowIn.value));// stockinette
    
    //

p.Tension2.value=sub(p.Tension.value,2);
//p.Tension3.value=p.Tension.value
p.Tension4.value=sub(p.Tension.value,0);
p.TensionM2.value= sub(p.Tension.value,1);
p.TensionM1.value=sub(p.Tension.value,0);

castOn=2*Math.round(mult(circumference, p.mainStIn.value)/2+felted);

reduceTimes=Math.round((castOn/2)/4);
p.topNeedles.value=castOn/2 -reduceTimes*2;
p.repTimes.value=reduceTimes-1;
//p.afterThumbRows.value= totalRows-preThumbRows-thumbGussetRows -reduceTimes*fairIsle*4; 
   p.two.value=two*2;
 
p.afterThumbRows.value= totalRows-preThumbRows-reduceTimes*fairIsle*2;
p.afterThumbRows2.value=add(p.afterThumbRows.value, p.preThumbRows2.value);
p.liningRows1.value=(totalRows-preThumbRows)/two;
p.thumbStitchesM1.value=sub(p.thumbStitches.value,1)

//p.stripRows.value=Math.ceil(divide(p.mainRowIn.value,p.mainStIn.value)*castOn);

 incAfterCuff=Math.round(castOn/20);
 //alert(incAfterCuff);
 
p.incAfterCuff.value= incAfterCuff
p.castOn.value= castOn - 2* incAfterCuff;

p.castOnHalf.value=divide(p.castOn.value,2);
p.mittenHalf.value= castOn/2;
p.castOnHalf2.value=p.castOnHalf.value;
p.castOnHalfM2.value=sub(p.castOnHalf.value,2);


}

