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.floor(mult(circumference, p.mainStIn.value)/2)*2+1;    
    incSt=Math.round(castOn/10)
    p.castOn.value= castOn;    
    p.ribCastOn.value=castOn-incSt;
    p.incStitches.value=incSt;
    halfcastOn=Math.floor((castOn-1)/2);
    p.halfcastOn.value=halfcastOn
    p.halfcastOn2.value=(castOn-1)-halfcastOn;
      
        
    lengthFour=divide(8,p.mainRowIn.value);
    ribLength=Math.max(lengthFour, stdLength/3.5);
    p.ribLength.value=Math.round(ribLength*100)/100;
    
    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."}
    

    preThumbLength=Math.max(circumference/9.5,lengthFour);//shorter than for mittens
    preThumbRows=Math.round( mult(preThumbLength,p.mainRowIn.value));
    p.preThumbRows.value=preThumbRows-1;// 
    
    thumbGussetLength=Math.max(circumference/4.5,lengthFour);
    thumbStitches = 2* (Math.round(mult(thumbGussetLength,p.mainRowIn.value)/2) );
    thumbGussetRows=thumbStitches;
    p.thumbGussetStitches.value=thumbStitches;
    p.thumbStitches.value=thumbStitches+1;
    //p.thumbGussetRows.value= thumbGussetRows;
    
    totalRows=Math.ceil(mult(stdLength,p.mainRowIn.value));
    
    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-1;// cut compared to mittens.   
    p.afterThumbLength.value=Math.round( divide(p.afterThumbRows.value,p.mainRowIn.value)*10)/10
    
    palmLength=Math.round((stdLength-fingerLength)*10)/10;
    
    frontCastOn=2*Math.ceil(castOn/2);
    
    pinky = Math.floor((frontCastOn)/8); 
    
     leftRaise=Math.max(Math.round(pinky/2.5),1);
    p.leftRaise.value=leftRaise;
    p.leftRaise2.value=leftRaise;
    p.leftRaise3.value=leftRaise;
    p.leftRaise4.value=2*Math.max(Math.floor(leftRaise/2),1);
    
    p.rightRaise3.value=p.leftRaise4.value;
    p.rightRaise.value=Math.max(leftRaise-1,1);
    p.rightRaise1.value=p.rightRaise.value
    p.rightRaise2.value=p.rightRaise.value

      p.castOnP2.value=eval(p.castOn.value)-1+eval(p.leftRaise4.value);
 // adjust for extra stitches.
      
    frontCastOn=Math.ceil(eval(p.castOnP2.value)/2);
    pinky = Math.floor((frontCastOn)/4); 
 
    pinkyStitches= 2*Math.round(pinky);
    p.pinkyStitches.value= pinkyStitches;
    halfPinkyStitches=Math.round(pinky/8);
    //alert(pinky + " :"+ halfPinkyStitches);
    
        
    frontPinkyStitches=Math.floor(( pinky-halfPinkyStitches))
    backPinkyStitches= pinkyStitches-frontPinkyStitches;
    // p.frontPinkyStitches.value=frontPinkyStitches;
    //p.backPinkyStitches.value=add(pinkyStitches,halfPinkyStitches);


    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=(frontCastOn)%4;
      
	//alert(pinky +" : "+ extra)
    p.allIndexStitches.value=2*(Math.round(pinky)+Math.ceil(extra/4));
    extra=Math.max(extra-1,0)
    p.totalIndex.value=add(p.allIndexStitches.value,leftRaise);
    
    p.middleStitches1.value=Math.round(pinky)+Math.ceil(extra/4)
    extra=Math.max(extra-1,0) 
    p.totalMiddle.value =2*eval(p.middleStitches1.value)+2*leftRaise-1   
    
    p.ringStitches.value=Math.round(pinky)+Math.ceil(extra/4);
    extra=Math.max(extra-1,0)    
    p.totalRing.value =2*eval(p.ringStitches.value)+2*leftRaise-1 
    
    p.totalPinky.value=pinkyStitches+leftRaise-1 ;
    
    frontFingers= frontPinkyStitches+eval(p.allIndexStitches.value)+eval(p.middleStitches1.value)+eval(p.ringStitches.value)
    p.frontFingers.value=frontFingers;
    p.frontFingers2.value=backPinkyStitches+eval(p.allIndexStitches.value)+eval(p.middleStitches1.value)+eval(p.ringStitches.value)
      // p.allPinkyStitches.value=pinkyStitches;
    
    //p.pinkyStitches2.value=p.pinkyStitches.value;
    
// rows befor shaping.    

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

    p.Tension2.value=p.Tension.value;





}

