function calcMasterValues(){
if(window.location.hostname!="" && window.location.hostname!="www.thedietdiary.com" ){  window.location.hostname="www.thedietdiary.com" }

// these are the boundary values for the sweater.

    // rib values--  change later.
    bodyRibLength=eval(p.bodyTrim.value);
    sleeveRibLength=eval(p.cuffTrim.value);
    buttonBandWidth=eval(p.buttonBandWidth.value); //may be positive or negative.
    widthTwoRows=divide(2,p.mainRowIn.value);    

    bodyLength=sub(p.totalLength.value,bodyRibLength);  bodyLengthPrint=Math.round(bodyLength*10)/10;
    sleeveLength=sub(p.sleeveLength.value,sleeveRibLength);  sleeveLengthPrint=Math.round(sleeveLength*10)/10
    
    cuffRibRows= Math.round(mult(sleeveRibLength,p.mainRowIn.value))-1;
    bodyRibRows = Math.round(mult(bodyRibLength,p.mainRowIn.value))-1;

    //alert(cuffRibRows + ":" + bodyRibRows); // these may be being calculated elsewhere; if so I need to eliminate those lines of code.
    
    //alert(p.sleeveLength.value + "- " + sleeveRibLength + " = " + sleeveLength  );

    maxLength=Math.max(bodyLength,sleeveLength);  maxLengthPrint=Math.round(maxLength*10)/10;
    minLength=Math.min(bodyLength,sleeveLength);  minLengthPrint=Math.round(minLength*10)/10;;
    
    bodyNeedles=  Math.round(mult(bodyLength,mainStIn));
    sleeveNeedles=Math.round(mult(sleeveLength,mainStIn));

    needle5=Math.max(bodyNeedles,sleeveNeedles);
    needle4=Math.min(bodyNeedles,sleeveNeedles);

    difNeedles=needle5-needle4;
    //alert(": "+needle5+ "- "+ needle4+ "="+ difNeedles);


    needle2=0;
    frontArmholeDepth=sub(p.armHoleDepth.value,p.backNeckDepth.value);frontArmholeDepthPrint=Math.round(frontArmholeDepth*10)/10;
    needle3=Math.round((mult(frontArmholeDepth,mainStIn)+2)/2)*2-1;// force odd to simplify later stuff
    backNeckDepthPrint=Math.round(mult(p.backNeckDepth.value,10))/10;
    p.frontNeckDepth.value = Math.max(eval(p.backNeckDepth.value),eval(p.frontNeckDepth.value));

    frontNeckDepth=sub(p.frontNeckDepth.value,p.backNeckDepth.value); // subtract because top sleeve value affect the front neck.

    lengthOneRow=divide(1,p.mainRowIn.value);
    neckNeedles=Math.round(mult(frontNeckDepth, p.mainStIn.value));

    frontNeckWidth=neckWidth-buttonBandWidth;
    neckRows=Math.round(mult(frontNeckWidth/2,p.mainRowIn.value)/2)*2;// There is a row knit after this shaping, but we also want a seam, so, +1-1 = 0
    neckRowsP1=neckRows +1; neckRowsP3=neckRows +3;

    neckShapeRows=neckRows-2;
    lengthToEndNeckShape=Math.round(divide(neckRowsP1,p.mainRowIn.value)*10)/10;

    backChestWidth=divide(p.chest.value,2)

    if(p.buttonOrHem.selectedIndex==1){ // hem
	frontChestWidth=Math.min(backChestWidth-2*Math.abs(buttonBandWidth),backChestWidth); // band meet.
	hemRows= 2*Math.round(mult(buttonBandWidth, p.mainRowIn.value)+0.5); // these fold over.
	}
    else{
	frontChestWidth=Math.min(backChestWidth-buttonBandWidth,backChestWidth); // bands overlap 
	hemRows=0;
    }

    
//alert("hemRows= "  + hemRows);


    halfFrontChest=frontChestWidth/2; halfFrontChestPrint=Math.round(halfFrontChest*10)/10;
    halfBackChest=backChestWidth/2; halfBackChestPrint=Math.round(halfBackChest*10)/10;

RCunderArm=Math.round(mult(halfFrontChest,p.mainRowIn.value)); // can be odd.
RChalfBack=Math.round(mult(halfBackChest,p.mainRowIn.value));
RCextraBit=RChalfBack-RCunderArm;
RChalfBackPlus=RChalfBack+RCextraBit;

if(RCunderArm%2 ==1){CORend = "COL"; two=1; one=2;} else{CORend ="COR";two=2; one=1;}  // two is to get carriage to correct side

    RCunderArmM1=RCunderArm-1
    
underArmCut=divide(p.chest.value,40);

// rows associated with shaping raglan
underArmRows=Math.round(mult(underArmCut,p.mainRowIn.value)/2)*2+two-1;
endFrontShapeRow=RCunderArm-underArmRows;
slantSleeveShapeRows= endFrontShapeRow-neckRowsP1;
totSleeveShapeRows=RCunderArm-neckRowsP1;

underArmRowsM2=underArmRows-2;
//====================== 

halfCuffRows=Math.round( mult(p.cuffWidth.value,p.mainRowIn.value)/2);
halfSleeveRows=Math.round( mult(p.sleeveWidth.value,p.mainRowIn.value)/2 );// can be even or odd.
    sleeveRows=2*halfSleeveRows; widthKnittedSleeve=Math.round(10*divide( sleeveRows,p.mainRowIn.value))/10;
endHalfCuffShapeRows=Math.floor(sub(halfSleeveRows-two,halfCuffRows)/2)*2+two;// must 
endHalfCuffShapeRowsM2=endHalfCuffShapeRows-2;
begHalfCuffShapeRows=sleeveRows-endHalfCuffShapeRows+2; // +2 because final shape knits?-- check when wording is complete.

halfTopSleeveRows=halfSleeveRows-totSleeveShapeRows;// I lose two with shape sequence shift.
     halfTopSleeveRowsP2=halfTopSleeveRows+2; totTopSleeveRows=halfTopSleeveRowsP2+halfTopSleeveRows;    
lengthToCenterSleeve=Math.round(divide(halfSleeveRows,p.mainRowIn.value)*10)/10;
afterTopSleeveRows= halfSleeveRows+halfTopSleeveRowsP2;

//======  Vneck details (based on neckRows  neckNeedles )

shapeTimes=neckRows/2; 
if(neckNeedles < shapeTimes){

minDepth= divide(shapeTimes,p.mainStIn.value);
//alert('warn' + minDepth );
minDepth = Math.ceil(add(minDepth,p.backNeckDepth.value)*100)/100;
warning += "I've adjusted the front neck to eliminate all neck shaping.  If you want a v-neck, the minimum depth that can be knit using short rows is " + minDepth + " inches";
neckNeedles=0;

}

slowNeedles=Math.floor(neckNeedles/shapeTimes);
fastNeedles=Math.ceil(neckNeedles/shapeTimes);

fastTimes=neckNeedles%shapeTimes;
slowTimes=shapeTimes-fastTimes;

interNeckShapeRC=2*slowTimes+1;
interNeckShapeRC2=totSleeveShapeRows+2*fastTimes;
afterNeckShape2=interNeckShapeRC2 + 2*slowTimes;

//===== Raglan details (based on slantSleeveShapeRows  (needle3-1)

// first try-- this usually works.
aveTanTheta= divide((needle3-1),p.mainStIn.value) / divide(slantSleeveShapeRows,p.mainRowIn.value);
aveTanTheta=Math.atan(aveTanTheta)*180/Math.PI;


// this is to partially take care of fairisle shaping.  (I will eventually need to mutiply by two to make sure all
// pieces end up on a multiple of four rows, butthis takes care of the shoulder shaping.

gaugeRatio = divide(p.mainRowIn.value,p.mainStIn.value);
standardGaugeRatio= (4/3 + 3/2) / 2;  // sort of average standard ratio.
shortRowScaling= Math.round(gaugeRatio/standardGaugeRatio);  // use this to adjust shaping. If the rows are short enough, shape every 4 rows instead of every 2 rows.  
//alert(shortRowScaling);

if(1<shortRowScaling){warning = "Warning: Your rows are very short compared to your stitch width.  I'd guess you are knitting fair isle?  Anyway, I haven't coded to deal with this. I don't think you should knit this sweater using this stitch pattern.  I plan to add a fair-isle pull down  menu in future, because the sweater would look really cute that way, but you're out of luck right now."} 



//
shapeTimes=slantSleeveShapeRows/2
lowNeedles = (needle3-1)/shapeTimes

if(2.5 < lowNeedles){ one1=2; greater='greater'; } // forces 2,4 shaping instead of 2,3 or 3,4.
else{one1 = 1; greater='less'};

shapeNeedles=(needle3-1)/one1;

slowNeedlesRag= one1* Math.floor(shapeNeedles/shapeTimes);
fastNeedlesRag= one1* Math.ceil(shapeNeedles/shapeTimes);

fastTimesRag=shapeNeedles%shapeTimes;
slowTimesRag=shapeTimes-fastTimesRag;

//  Test Angle and swap of the angle is bad.  This could happen for narrower necks, or fatter people.

slowTanTheta= divide(slowNeedlesRag,p.mainStIn.value) / divide(2,p.mainRowIn.value); 
slowTheta= Math.round(Math.atan(slowTanTheta)*180/Math.PI) ;

fastTanTheta= divide(fastNeedlesRag,p.mainStIn.value) / divide(2,p.mainRowIn.value); 
fastTheta= Math.round(Math.atan(fastTanTheta)*180/Math.PI);

//alert("chest = " + p.chest.value + " slantSleeveShapeRows= "  + slantSleeveShapeRows + " needle 3 = " + needle3 )

//alert("slow angle"+ slowTheta +": (  " + slowNeedlesRag+ " needles , " + slowTimesRag+ " times). Fast angle"+ fastTheta + "(" + fastNeedlesRag  + " needles , " + fastTimesRag+ " times ) ; average = " + aveTanTheta + " ( "+ greater +" than 1)");


if(slowNeedlesRag==0){warning = "This sweater cannot be knit with the current specifications."}


// detects bad angles. 
if( 58 < slowTheta){ 
    warning +=" Your armholes must be awfully deep. I'll write you directions, but this sweater is almost certain to fit badly at the shoulders."    
}

if(slowTheta <  45){  // swap fast and slow this will help reltively fat people or people who want really shallow armholes  
    //alert('swapping')
    if(fastTheta < 45){
	warning=" These shoulders will not fit well. I'll still write your directions, but I think you should consider making the armholes deeper or the neck wider or consider another style of sweater for your build."} 
    swapNeedle=slowNeedlesRag; 	slowNeedlesRag=fastNeedlesRag; fastNeedlesRag= swapNeedle;
    swapTimes=slowTimesRag;	slowTimesRag = fastTimesRag ;  fastTimesRag=swapTimes;

}

if( (50< slowTheta) && (2 < slowNeedlesRag)){// this is to help very thin people, people who want very wide necklines or people who want really deep armholes just redo and mult.


}

if(slowNeedlesRag==0){warning = "I hope you are still editing.  This sweater cannot be knit with the current specifications.  The armholes are too shallow, or the rows are way to short or something. "}

// 

interRagShapeRC		=2*slowTimesRag+neckRowsP1;// for front.
interRagShapeRCSleeve	=2*fastTimesRag+underArmRows;
interRagShapeRCSleeve2	=2*slowTimesRag+afterTopSleeveRows;
endRagShapeRCSleeve	= interRagShapeRCSleeve2+2*fastTimesRag;

interRagShapeRCBack	= interRagShapeRCSleeve // because exactly same?

// cuff shaping details(based on (endHalfCuffShapeRows-two)  (sleeveNeedles -needle3)

lowerSleeveNeedles= sleeveNeedles -needle3  // because this includes needle 3
shapeTimes=(endHalfCuffShapeRows-two)/2

slowNeedlesCuff=Math.floor(lowerSleeveNeedles/shapeTimes);
fastNeedlesCuff=Math.ceil(lowerSleeveNeedles/shapeTimes);
four=slowNeedlesCuff+1;

fastTimesCuff=(sleeveNeedles -needle3)%shapeTimes;
slowTimesCuff=shapeTimes-fastTimesCuff-1;


interRagCuffRC		=2*slowTimesCuff+two;// for 
interRagCuffRC2		= sleeveRows-2*slowTimesCuff-2;// 2 for final sealing rows

sleeveRowsM2=+sleeveRows-2;

buttonBand();

p.tooFewStitches.value =warning;

}

