function raglanCalcs(){

// gauge


p=document.sweaterForm;
warning=" ";
p.tooFewStitches.value ="No warning";

calcGauge();

if(eval(p.sizeRange.selectedIndex)==0){setMissesSizes();}
else if(p.sizeRange.selectedIndex==1){setMensSizes();}
Trim()


// button or hem.
if(p.buttonOrHem.selectedIndex==0){ 
    buttonOrHem="a button band"} 
else{
    buttonOrHem="a hung hem"
    if(custom==0 ){ 	
	p.buttonBandWidth.value= Math.abs( divide(p.buttonBandWidth.value,2) )
	widthTwoRows=divide(2,p.mainRowIn.value);
	buttonBandWidth=eval(p.buttonBandWidth.value);
	p.buttonBandWidth.value = Math.max( Math.ceil(widthTwoRows*100)/100, buttonBandWidth);	
	}
    }

// hoodie or not	
if(p.hood.selectedIndex==1){
    p.frontNeckDepth.value=p.backNeckDepth.value; 
    hood="is a hoodie";
    
}
else{ hood = "has no hood"}


/// rib or roll hem.
if(p.rollOrRib.selectedIndex==1){
    rollOrRib = "roll trim"
    if(custom==0 ){ // half as deep.
	p.bodyTrim.value=divide(p.bodyTrim.value,2);
	p.cuffTrim.value=divide(p.cuffTrim.value,2);
    }

    } 
else{ rollOrRib="ribbed bands" } 

//alert(hood +" : " +buttonOrHem +" : "+ rollOrRib );

calcMasterValues();

if(p.hood.selectedIndex ==1){hoodCalcs()}
// else{} // no hood.


// do this calc last so date only fills if window fills. 
now=new Date;
currentYear= now.getYear() + 1900;
currentMonth = now.getMonth() + 1;
currentDate=now.getHours() +":"+ now.getMinutes() +":"+ now.getSeconds() + " on " +currentMonth+ "/" +now.getDate() +"/"+currentYear;
p.patternCreationDate.value=currentDate;
}

//
function calcGauge(){

    mainStIn=divide(p.stitches.value,p.widthAfter.value); p.mainStIn.value=Math.round(100*mainStIn)/100;
    mainRowIn=divide(p.rows.value,p.lengthAfter.value); p.mainRowIn.value=Math.round(100*mainRowIn)/100;

    //ribStIn=divide(p.ribStitches.value,p.widthRib.value); p.ribStIn.value=Math.round(100*ribStIn)/100;
   // ribRowIn=divide(p.ribRows.value,p.lengthRib.value); p.ribRowIn.value=Math.round(100*ribRowIn)/100;

   // lengthFactor=divide(p.lengthRib.value,p.lengthAfter.value);
    //widthFactor=divide(p.widthRib,p.widthAfter.value);
}

// 
function buttonBand(){
p.bandStIn.value=divide(p.stitchesBand.value, p.width.value)
p.bandRowIn.value=divide(p.rowsBand.value, p.length.value)

p.bandWidth2.value=p.buttonBandWidth.value;
halfBand=Math.round(mult(p.buttonBandWidth.value,p.bandStIn.value) +0.5)
bandStitches=halfBand*2+1; p.bandStitches.value=bandStitches;
fourNeedles=Math.ceil((halfBand-1)/3); p.fourNeedles.value=fourNeedles;
insideNeedles=Math.floor( (halfBand-1)/3);
p.three.value=halfBand-add(p.fourNeedles.value,insideNeedles);
// find length 1
length1= sub(p.totalLength.value,p.frontNeckDepth.value);
p.length1.value = length1;


// note frontNeckDepth is NOT equals to p.frontNeckDepth.value because it's adjusted for the sleeve.
lengthToFrontSleeve=Math.sqrt(frontNeckDepth*frontNeckDepth + frontNeckWidth*frontNeckWidth/4)
lengthToBackSleeve=mult(2,p.backNeckDepth.value); // two because of the way I accounted for the front neck depth.
lengthOfBack=neckWidth;

length2=2*(lengthToFrontSleeve+lengthToBackSleeve)+ lengthOfBack + length1;
p.length2.value=length2+length1

rowLastButton=Math.round( mult(p.length1.value,p.bandRowIn.value));
p.rows1.value=rowLastButton;

totalButtonRows =Math.round(mult(p.length2.value,p.bandRowIn.value)); p.totalRows.value=totalButtonRows

buttonRow1=Math.round(mult(1,p.bandRowIn.value));



buttonSpaceRows=sub(rowLastButton,buttonRow1);

numButtons=p.numButtons.value;

remButtons=sub(p.numButtons.value,1);
smallRows=Math.floor(divide(buttonSpaceRows,remButtons));
largeRows=smallRows +1;
remainder=buttonSpaceRows%remButtons;
firstSet=remButtons-remainder

RC=buttonRow1;
buttonHoleRows = "Work the first buttonhole  on row "+RC + ".  ";
buttonHoleRows += " After working each of the first "+ firstSet + " buttonholes knit "+ smallRows + " rows. ";
if(0<remainder){ buttonHoleRows += "Then, knit "+ largeRows +" after the remaining buttonholes. ";}
buttonHoleRows +=" In other words, work buttonholes on these rows: ( ";
buttonHoleRows+=buttonRow1;

for(i=0; i<remButtons; i++){
    if(i< firstSet){RC += smallRows;} else {RC += largeRows;}
    buttonHoleRows+=  ",  " +RC; 
}

buttonHoleRows += " ).";



rows2=Math.round( mult(  length1+    lengthToFrontSleeve,  				p.bandRowIn.value))
rows3=Math.round( mult(  length1+    lengthToFrontSleeve +  lengthToBackSleeve,		p.bandRowIn.value))
rows4=Math.round( mult(  length1+    lengthToFrontSleeve+   lengthToBackSleeve + lengthOfBack,p.bandRowIn.value))
rows5=Math.round( mult(  length1+    lengthToFrontSleeve+ 2* lengthToBackSleeve +lengthOfBack,p.bandRowIn.value))
rows6=Math.round( mult(  length1+ 2*lengthToFrontSleeve+  2*lengthToBackSleeve +lengthOfBack,p.bandRowIn.value))
rows7=Math.round( mult(  2* length1+ 2*lengthToFrontSleeve+  2*lengthToBackSleeve +lengthOfBack ,p.bandRowIn.value))

lengthOfFront= length1+lengthToFrontSleeve+lengthToBackSleeve/2;
minTotalLength= add(mult(2,p.totalLength.value),p.neckWidth.value);

//alert(lengthOfFront + " : "   +p.totalLength.value + ": row GAuge= " + p.bandRowIn.value );
//alert(length1+ " : "   + lengthToFrontSleeve + " : " + lengthToBackSleeve  + " : "+lengthOfBack + " : min=" +minTotalLength );

markRows ="   Optional: Hang Markers on these rows: ( ";
markRows += rows2+ ",  "+rows3+ ",  "+rows4+ ","+rows5+ ",  "+rows6 + "," + rows7 ;
markRows += " ).  These locations line up with the short rows you worked to shape the raglan and the top of the V on the other side.  Line them up when you attach the band.";

p.buttonHoleDetails.value = buttonHoleRows;
p.buttonHoleDetails.value += markRows;

}
