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; }
felted = 0;
   
//     if(p.size.selectedIndex==1){extra += 1}
//    else if(p.size.selectedIndex==2){extra += 2}
//    else if(p.size.selectedIndex==3){extra += 3}
//    else if(p.size.selectedIndex==4){extra += 4}

    
    normSize= extra;
    circumference = (5.4 + normSize/2.5) ;
    
    stdLength=.95*circumference;
    p.stdWidth.value=Math.round(circumference*100)/100;
    
    castOn=Math.round(mult(circumference, p.mainStIn.value)/2);
    p.castOn.value= castOn;
    p.ribCastOn.value=2*castOn;
      
        
    lengthFour=divide(8,p.mainRowIn.value);
    ribLength=Math.max(lengthFour, stdLength/3.5);
    ratio =divide(p.mainRowIn.value,p.mainStIn.value);
    if(1.8< ratio  ){p.tooFewStitches.value="Warning: Something seems wrong.  This code needs you to enter the number of rows per inch knit flat."}
    
    p.ribRows.value = Math.round(mult(ribLength,p.mainRowIn.value)); // don't divide by two because I'm folding them!
   
    preThumbLength=Math.max(circumference/9.5,lengthFour);//shorter than for mittens
    preThumbRows=Math.round( mult(preThumbLength,p.mainRowIn.value)/2 - felted)*4;
    p.preThumbRows.value=preThumbRows;// because carriage passes are doubled.
    
    thumbGussetLength=Math.max(circumference/4.5,lengthFour);
    thumbStitches = Math.round(mult(thumbGussetLength,p.mainRowIn.value)/2)+1+ felted;
    thumbGussetRows=4*thumbStitches;
    p.thumbStitches.value=thumbStitches;
    p.thumbGussetRows.value= thumbGussetRows;
    
    totalRows=Math.ceil(mult(stdLength,p.mainRowIn.value))*2;
    
    mittenAfterThumbRows=(totalRows-preThumbRows-thumbGussetRows);
    upperHandRows=Math.round(mittenAfterThumbRows/5.7)*2;
    fingerRows=mittenAfterThumbRows-upperHandRows;
    //p.mittenAfterThumbLength.value=Math.round(divide(mittenAfterThumbRows,p.mainRowIn.value)*10)/10;
    
    afterThumbRows=Math.max(2*Math.round(upperHandRows),4)/2;
    
    fingerRows=  mittenAfterThumbRows-afterThumbRows;
    fingerLength=divide(fingerRows,p.mainRowIn.value);// this will be the middle finger.
    
    p.afterThumbRows.value= afterThumbRows;// cut compared to mittens.   
    p.afterThumbLength.value=Math.round( divide(p.afterThumbRows.value,p.mainRowIn.value)*10)/20
    
    palmLength=Math.round((stdLength-fingerLength)*10)/10;
    
    pinky = Math.floor((castOn+1)/4);  
    extra=(castOn+1)%4;
/*         
    p.indexStitches.value=Math.round(pinky)+Math.ceil(extra/4); 
    extra=Math.max(extra-1,0)
    
    
    p.middleStitches.value=Math.round(pinky)+Math.ceil(extra/4)
    extra=Math.max(extra-1,0)    
    
    p.ringStitches.value=Math.round(pinky)+Math.ceil(extra/4);
    extra=Math.max(extra-1,0)    

    pinkyStitches= Math.round(pinky);
    halfPinkyStitches=Math.round(pinky/8);
    
    p.frontPinkyStitches.value=sub(pinkyStitches,halfPinkyStitches);
    p.backPinkyStitches.value=add(pinkyStitches,halfPinkyStitches);
 */
    
    leftRaise=Math.max(Math.round(pinky/2.5),1);
    p.leftRaise.value=leftRaise;
    p.leftRaise2.value=leftRaise;
    p.leftRaise3.value=leftRaise;
    p.leftRaise4.value=Math.max(Math.floor(leftRaise/2),1);
    p.rightRaise.value=Math.max(leftRaise-1,1);
    
    // adjust finger stitches for left raise on thumb.
    
    extraThumb= eval(p.leftRaise4.value)-1;
    extraStitch=Math.floor(extraThumb/4);
    extraStitch2=(extraThumb)%4;
    
     p.castOnP2.value=castOn+eval(p.leftRaise4.value);
     stitchesToDistribute = eval(p.castOnP2.value);
    pinky = Math.floor(stitchesToDistribute/4);  
    if(pinky < 4){ p.tooFewStitches.value = "There are fewer than 4 pinky stitches. Please use thinner yarn to knit gloves this size.  Better yet, consider knitting mittens. "}  
    extra=stitchesToDistribute%4;
         
    p.indexStitches.value=Math.round(pinky)+Math.ceil(extra/4); 
    extra=Math.max(extra-1,0)
    
    
    p.middleStitches.value=Math.round(pinky)+Math.ceil(extra/4)
    extra=Math.max(extra-1,0)    
    
    p.ringStitches.value=Math.round(pinky)+Math.ceil(extra/4);
    extra=Math.max(extra-1,0)    

    pinkyStitches= Math.round(pinky);
    halfPinkyStitches=Math.round(pinky/8);
    
    p.frontPinkyStitches.value=sub(pinkyStitches,halfPinkyStitches);
    p.backPinkyStitches.value=add(pinkyStitches,halfPinkyStitches);
    
  

     

    //p.pinkyStitches2.value=p.pinkyStitches.value;
    
// rows befor shaping.    

    p.middleRows.value=fingerRows - 6;
    p.pinkyRows.value=Math.round((fingerRows*0.75-6)/2)*2;
    p.indexRows.value=Math.round( (fingerRows*0.9 -6) /2)*2;  
    p.ringRows.value=Math.round( (fingerRows*0.9-6)/2)*2;
     
   // p.middleLength.value=Math.round(fingerLength*10)/10;
    
    p.stdLength.value = Math.round(10*stdLength)/10; 
    
    p.ThumbStitchesP2.value=2*thumbStitches;
    thumbLength= Math.max(stdLength/3.6,lengthFour);
    thumbShapeTimes=Math.floor((eval(p.ThumbStitchesP2.value)/2+1-6)/2);
    p.thumbRows.value=Math.max(2*Math.round(mult(thumbLength,p.mainRowIn.value))-6,2);
    p.thumbRows2.value=  p.thumbRows.value
    p.thumbLength.value= Math.round(10*divide(eval(p.thumbRows.value)+6,p.mainRowIn.value))/20;
    
    //

p.Tension2.value=p.Tension.value;
p.TensionM2.value= sub(p.Tension.value,2);





}

