function designBack(){
/* 
@copyright 2004 Lucia Liljegren
*/

//cookie shuffling.
// set a cookie with a cookie name equal to the document  location.
p =document.sweaterForm;
q=document.sweaterForm;

pester = document.location;

expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+6);
username = pester;

document.cookie="pester=" + username + "expires="+ expireDate.toGMTString(); 

if(document.cookie ==""){
    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(pesterZero == "pester=http:" || pesterAway == "www.thedietdiary.com"){pester="no"}
 
else{ pester = "yes"; alert(" Please run my programs from my site at www.thedietdiary.com!"  )} ;

if(pester == "no"){
// 

//make sure the toggle doesn't fill with letters! 
//Should be redundant: coding of HTML page should also give text box and toggles different names.

// fill flare angle and shoulder dart information-- later from form.
// from arm/sleeve how to pick select values! type =p2.sleeve_cap.options[p2.sleeve_cap.selectedIndex].value

  if(eval(p.mainStIn.value) < 0.00001) {p.mainStIn.value = 0.001; }
  if(eval(p.mainRowIn.value) < 0.00001) {p.mainRowIn.value = 0.001; }
  
  if(eval(p.ribStIn.value) < 0.00001) {p.ribStIn.value = 0.001; }
  if(eval(p.ribRowIn.value) < 0.00001) {p.ribRowIn.value = 0.001; }
  
  p.ribNeedle.value = eval(p.mainNeedle.value)-1;
  p.mainNeedle2.value= p.mainNeedle.value;
  
mainStIn= eval(p.mainStIn.value);
mainRowIn=eval(p.mainRowIn.value);

ribStIn= eval(p.ribStIn.value);
ribRowIn=eval(p.ribRowIn.value);

p.ratio.value=ratio=Math.round(10*mainRowIn/mainStIn)/10;
if( ratio < 1.0 || 1.6< ratio){ratioFlag = "may not"}
else {ratioFlag = "is"}
p.ratioFlag.value = ratioFlag


halfChest=eval(p.chest.value)/2;

seam=2;

if(p.ribInc.selectedIndex==1){ ribFactor=(10/11)}// tighten for "yes"
else{				ribFactor=1}

if(p.ribType.selectedIndex==0){ ribType="real"}// tighten for "yes"
else{ribType="mock"}

//=== various rib tups
 ribFraction= 1;  
if(p.ribType.selectedIndex == 0){ ribType="real"; ribLength = 1.5;  ribFraction= 1;}
else if(p.ribType.selectedIndex==1 ){ ribType="mock"; ribLength=3.0; ribFraction= 2/3; }  // 2 x 1 mock ribbing
else if(p.ribType.selectedIndex==2 ){ ribType="mock"; ribLength=3.0; ribFraction= 1/2;  } // 1 x 1 
else if(p.ribType.selectedIndex==3 ){ ribType="mock"; ribLength=3.0; ribFraction= 1;  }  // hung hem.



if(p.hkOrMk.selectedIndex==1){method="mk"} 
else{method="hk"}

p.castOn.value=castOn = 2*Math.round(ribFactor*halfChest*mainStIn/2)+seam;
p.ribWidth.value = 2* divide((castOn-seam),ribStIn);
p.chestStitches.value=chestStitches = 2*Math.round(halfChest*mainStIn/2)+seam;
p.incStitches.value=incStitches=  chestStitches-  castOn;

shoulderWidth=eval(p.shoulderWidth.value);
p.shouldStitches.value=shoulderStitches=2*Math.round(shoulderWidth*mainStIn/2)+seam;

neckWidth = eval(p.neckWidth.value);
neckStitches= 2*Math.round(neckWidth*mainStIn/2);


ribDepth=eval(p.ribDepth.value)
p.ribRows.value= ribRows=  2*Math.round(ribDepth*ribRowIn/2);


// real depths so things work out.
ribDepth=ribRows/ribRowIn;
p.ribDepth2.value= justRound(ribDepth);
// calculate shoulder shaping

shoulderSlope=eval(p.shoulderSlope.value);
rowsShoulder=Math.round(shoulderSlope*mainRowIn/2)*2;

shoulderSlope=rowsShoulder/mainRowIn;


// now calculate body.
totalLength=eval(p.totalLength.value);
bodyLength=totalLength-ribDepth;
bodyRows=Math.round(bodyLength*mainRowIn/2)*2;
bodyLength=bodyRows/mainRowIn;
totalRows=bodyRows+ribRows;
p.totalRows.value=totalRows


// calcullate Armhole depth

armHoleDepth = eval(p.armHoleDepth.value);
rowsArmhole= Math.round(armHoleDepth*mainRowIn/2)*2;

armHoleDepth = rowsArmhole/mainRowIn;

lengthToUnderArm =bodyLength-shoulderSlope-armHoleDepth;

p.preShoulderLength.value = justRound(totalLength-shoulderSlope);

//
p.stockingRows.value =stockingRows= Math.round(lengthToUnderArm*mainRowIn/2)*2;
lengthToUnderArm = divide(p.stockingRows.value,mainRowIn);

p.cumUArmRows.value = eval(p.stockingRows.value)+eval(p.ribRows.value);
p.uArmLength.value =ribDepth+lengthToUnderArm;


decArmhole=(eval(p.chestStitches.value)-eval(p.shouldStitches.value))/2; // single sided.
p.firstArmBindOff.value =firstArmBindOff=Math.floor(decArmhole/2)

remArmhole=decArmhole-firstArmBindOff;

secondArmhole = 2 * Math.floor(remArmhole/4); // about 1/2 of remainder get bound off.
p.maxArmBindOffTimes.value = secondArmhole/2;// number of times because I dec 2

lastArmhole = remArmhole-secondArmhole;
p.minArmBindOffTimes.value= lastArmhole;


totalArmholerows= (eval(p.minArmBindOffTimes.value)+eval(p.maxArmBindOffTimes.value)+1)*2;
p.armholeRows.value=rowsArmhole-totalArmholerows;


p.endUArmRows.value=eval(p.cumUArmRows.value)+totalArmholerows;


p.begShoulderRows.value=eval(p.endUArmRows.value)+eval(p.armholeRows.value)

// calculate shoulder decreases.
decShoulderSt= (shoulderStitches-neckStitches)/2;


decTimes=rowsShoulder/2;

p.minShoulderBindOff.value=minDec=Math.floor(decShoulderSt/decTimes);
p.maxShoulderBindOff.value=maxDec=minDec+1;

p.maxShoulderBindOffTimes.value=nTimeMax=decShoulderSt%decTimes;
p.minShoulderBindOffTimes.value =nTimesMin=decTimes-nTimeMax;


p.NeckStitches.value=neckStitches;


ribStitchFactor = ribFraction; // set with toggle.

totalStitches = (castOn+1)*ribRows*ribStitchFactor+ chestStitches*stockingRows + rowsArmhole*shoulderStitches +totalArmholerows*(shoulderStitches+chestStitches)/2+ (shoulderStitches+neckStitches)*(rowsShoulder+1)/2;

weightBack = 100*mult((totalStitches/1000)/100, p.ouncePer1000.value);

p.weightBack.value = Math.ceil(weightBack*100)/100;
p.backStitches.value = Math.round(totalStitches/10)*10;
// V neck.
neckDepth=eval(p.neckDepth.value);
neckRows=Math.round(neckDepth*mainRowIn/2)*2;
neckDepth=neckRows/mainRowIn;

p.VneckLength.value=VneckLength=totalLength-neckDepth;
p.VneckRow.value=VneckRow=totalRows-neckRows;

// make sure the neck shaping ends a little early.
neckPadRows=2*Math.ceil(neckWidth*mainRowIn/20);

realNeckRows=neckRows;
if(method == "hk"){ realNeckRows= 2*Math.floor(0.95*neckRows/2 )}

neckShapeRows= realNeckRows-neckPadRows;

halfNeckStitches=neckStitches/2;
neckShapeTimes=halfNeckStitches;
neckShapeOps=neckShapeRows/2

neckStTimeRows = neckShapeRows*neckStitches/2+neckPadRows*neckStitches  ; //traingle plus littel square 
totalFrontStitches= totalStitches-neckStTimeRows;
p.weightFront.value = weightFront= 100*mult((totalFrontStitches/1000)/100, p.ouncePer1000.value);

p.weightFront.value = Math.round(weightFront*100)/100;
p.frontStitches.value = Math.round(totalFrontStitches/10)*10;

minNeckBindOffRows= 2* Math.floor(neckShapeOps/neckShapeTimes); 
    q.minNeckBindOffRows.value=minNeckBindOffRows-1;
    if(minNeckBindOffRows<2){	
	minNeckRows = neckStitches+1 + neckPadRows ;
	minNeckDepth = Math.ceil( 10* minNeckRows/mainRowIn)/10; 
	p.neckDepth.value=minNeckDepth;
    }
    
maxNeckBindOffRows= minNeckBindOffRows+2; 
    q.maxNeckBindOffRows.value=maxNeckBindOffRows-1;

q.maxNeckBindOffTimes.value=maxNeckBindOffTimes = neckShapeOps%(neckShapeTimes);
q.minNeckBindOffTimes.value=minxNeckBindOffTimes= neckShapeTimes-maxNeckBindOffTimes

decMaxRow=maxNeckBindOffTimes*maxNeckBindOffRows
decMinRow=maxNeckBindOffTimes*minNeckBindOffRows

p.endNeckRows.value=endNeckRows=VneckRow+neckShapeRows+1;
lastBindOff = maxNeckBindOffRows;
if(maxNeckBindOffRows==0){lastBindOff = minNeckBindOffRows;}

p.endNeckRowsM1.value=eval(p.endNeckRows.value)-maxNeckBindOffRows;

neckTrim();
// extra armscye-- don't count the part that matches.
var extraArmscye=2* eval(p.armholeRows.value)/mainRowIn;

redo=0;
redoMax=10
sleeveAlertMssg ="none";
series = "";
narrow = "??"

while (redo<=redoMax){
redo = redo+1;
designSleeve(1.05*extraArmscye);

}

if(sleeveAlertMssg != "none"){
p.sleeveAlert.value=p.sleeveAlert2.value=sleeveAlertMssg;}
else{p.sleeveAlert.value=p.sleeveAlert2.value="Sleeve fits in armhole."}


p.tooFewStitches.value="I checked and you are running this web site. ("+ pesterAway + pesterRead + "). Since it seems to be one of mine,  I'll fill all the boxes!";


}
//------------------------
else {
    alert("Sorry! I didn't fill the boxes. Please run this page from my site at www.thedietdiary.com!")
    p.tooFewStitches.value = "Sorry! I'm not going to fill all your boxes correctly.  Please load this page from my web site at www.thedietdiary.com!"; 
     
    p.mainStIn.value=0.01;
    p.mainRowIn.value=0.01;
}
}


//===============

function neckTrim(){
/* 
@copyright 2004 Lucia Liljegren
*/

 
    // neck trim
    halfBackNeck = eval(p.neckWidth.value)/2
    neckDiag= Math.sqrt(halfBackNeck*halfBackNeck +  neckDepth*neckDepth)
    
    backNeckRibSt=Math.floor(0.8*p.neckWidth.value*ribStIn);
    backNeckMainSt=Math.floor(0.9*p.neckWidth.value*mainStIn);
    
    frontDiagMainSt=Math.round(0.9*neckDiag*mainStIn);
    frontDiagRibSt = Math.round(0.8*neckDiag*ribStIn);
    
    p.halfBackMainSt.value = halfBackMainSt=Math.round(0.9*halfBackNeck * mainStIn);
    halfBackRibSt=Math.round(0.8*halfBackNeck * ribStIn);
    
    p.neckTrim2.value=p.neckTrim.value
    p.neckRibRows.value=Math.round(p.neckTrim.value*ribRowIn);
    
    // MK main stitch, done in two pieces.
    p.neckMainStitches.value=halfBackMainSt+frontDiagMainSt;
    p.neckMainRows.value=p.neckMainRows2.value=Math.round(p.neckTrim.value*mainRowIn/2)-1;
    // MK mock ribbing, done in two pieces.
    p.neckRibRows.value=Math.round(p.neckTrim.value*ribRowIn/4)-1; // 2 to account for folding *and* the fact that this isn't rows-- it's number of times to do double rows in directions.
    
    neckRibRows = 2*Math.round( (eval(p.neckTrim.value)*ribRowIn)/2);//
    p.neckRibStitches.value=halfBackRibSt+frontDiagRibSt ;
    
 
    
    // actual ribbing
    p.neckRibRows2.value=neckRibRows;//  no 2 because not folded.
   p.fullNeckRibStitches2.value=  2*eval(p.neckRibStitches.value);
   p.fullNeckRibStitches.value =  eval(p.fullNeckRibStitches2.value)-neckRibRows;
   p.fullNeckRibStitches3.value=p.fullNeckRibStitches2.value;
   
   p.fullBackNeckRibStitches.value=p.fullBackNeckRibStitches2.value = 2*halfBackRibSt;
   p.neckTrim2.value=p.neckTrim.value
   
   rowsStitchTrim= halfBackRibSt*Math.round(p.neckTrim.value*ribRowIn)
   weightTrim=4*mult((rowsStitchTrim/1000), p.ouncePer1000.value);
   
   // check head
openingSize = neckWidth + 2* Math.sqrt(halfBackNeck*halfBackNeck + neckDepth*neckDepth);
p.openingSize.value = Math.round(openingSize*10)/10;
}
/* 
@copyright 2004 Lucia Liljegren
*/
