//pre-load image for printable
Image1= new Image(312,245);
Image1.src = "../../images/new_garza.png";
Image1= new Image(312,245);
Image1.src = "../../images/print.png";

var state = 'block'; 

function showhide(mylayer_ref1,mylayer_ref2,mylayer_ref3,mylayer_ref4,mylayer_ref5,mylayer_ref6) { 

if (state == 'none') { 
state = 'block'; 
} 
else { 
state = 'none'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + mylayer_ref1 + ".style.display = state"); 
eval( "document.all." + mylayer_ref2 + ".style.display = state"); 
eval( "document.all." + mylayer_ref3 + ".style.display = state"); 
eval( "document.all." + mylayer_ref4 + ".style.display = state"); 
eval( "document.all." + mylayer_ref5 + ".style.display = state"); 
eval( "document.all." + mylayer_ref6 + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[mylayer_ref1].display = state; 
document.layers[mylayer_ref2].display = state; 
document.layers[mylayer_ref3].display = state; 
document.layers[mylayer_ref4].display = state; 
document.layers[mylayer_ref5].display = state; 
document.layers[mylayer_ref6].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza1 = document.getElementById(mylayer_ref1); 
hza1.style.display = state; 
hza2 = document.getElementById(mylayer_ref2); 
hza2.style.display = state; 
hza3 = document.getElementById(mylayer_ref3); 
hza3.style.display = state; 
hza4 = document.getElementById(mylayer_ref4); 
hza4.style.display = state; 
hza5 = document.getElementById(mylayer_ref5); 
hza5.style.display = state; 
hza6 = document.getElementById(mylayer_ref6); 
hza6.style.display = state; 
} 
} 

function showhidet(mylayer_ref6) { 

if (state == 'none') { 
state = 'block'; 
} 
else { 
state = 'none'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + mylayer_ref6 + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[mylayer_ref6].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza6 = document.getElementById(mylayer_ref6); 
hza6.style.display = state; 
} 
} 


function openWin1( windowURL, windowName, windowFeatures ) {
for (var i=0; i < document.Myform.bio.length; i++ )
      {
        if (document.Myform.bio[i].checked) {
           var bio = document.Myform.bio[i].value;}
      }
if ((bio == 1) && (windowName == 'ME'))  {windowURL= 'me2pop.html';} 
if ((bio == 2) && (windowName == 'ME'))  {windowURL= 'me3pop.html';} 
if ((bio == 3) && (windowName == 'ME'))  {windowURL= 'me4pop.html';} 
if ((bio == 4) && (windowName == 'ME'))  {windowURL= 'memp2pop.html';} 
if ((bio == 1) && (windowName == 'MP'))  {windowURL= 'mp1pop.html';} 
if ((bio == 2) && (windowName == 'MP'))  {windowURL= 'mp2pop.html';} 
if ((bio == 3) && (windowName == 'MP'))  {windowURL= 'mp3pop.html';} 
if ((bio == 4) && (windowName == 'MP'))  {windowURL= 'memp2pop.html';}
if ((bio == 1) && (windowName == 'FI'))  {windowURL= 'fi4popsn.html';} 
if ((bio == 2) && (windowName == 'FI'))  {windowURL= 'fi3popsn.html';} 
if ((bio == 3) && (windowName == 'FI'))  {windowURL= 'fi1popsn.html';} 
if ((bio == 4) && (windowName == 'FI'))  {windowURL= 'fi2popsn.html';} 
if ((bio == 1) && (windowName == 'FIA'))  {windowURL= 'fi4Apopsn.html';} 
if ((bio == 2) && (windowName == 'FIA'))  {windowURL= 'fi3Apopsn.html';} 
if ((bio == 3) && (windowName == 'FIA'))  {windowURL= 'fi1Apopsn.html';} 
if ((bio == 4) && (windowName == 'FIA'))  {windowURL= 'fi2Apopsn.html';} 

   return window.open( windowURL, windowName); //,config='toolbar=0,location=0,directories=0,top=10,left=10, fullscreen=0,status=0,menuBar=0,scrollBars=1,resizable=0,width=375,height=350');
 }  

function regular(string) {
if (!string) return false;
var Chars = "0123456789.-";

for (var i = 0; i < string.length; i++)
{ if (Chars.indexOf(string.charAt(i)) == -1)
return false;
}
return true;
} 

function convert() {
      var conbwf = new ToFmt(document.Myform.conbw.value*.454);
if (document.Myform.conbw.value != "") {document.Myform.bw.value=conbwf.fmtF(6,1);}
//    else {document.Myform.bw.value="";}
      var conadgf = new ToFmt(document.Myform.conadg.value*454);
if (document.Myform.conadg.value != "") {document.Myform.adg.value=conadgf.fmtI(6);}
//    else {document.Myform.adg.value="";}
      }

function convert2() {
if (document.Myform.contdn.value) {
      var conmjf = new ToFmt(document.Myform.contdn.value*15.104/100);
      document.Myform.textmj.value=conmjf.fmtF(6,2);
      var conmcf = new ToFmt(document.Myform.contdn.value*3.61/100);
      document.Myform.textmc.value=conmcf.fmtF(6,2);
      document.Myform.mecc.value=conmjf.fmtF(6,2);
      }

if (document.Myform.contdn2.value) {
      var conmjf2 = new ToFmt(document.Myform.contdn2.value*15.104/100);
      document.Myform.textmj2.value=conmjf2.fmtF(6,2);
      var conmcf2 = new ToFmt(document.Myform.contdn2.value*3.61/100);
      document.Myform.textmc2.value=conmcf2.fmtF(6,2);
      document.Myform.mec.value=conmjf2.fmtF(6,2);
      }
}

function calc() {
      bw = document.Myform.bw.value;
      adg = document.Myform.adg.value;
      mec = document.Myform.mec.value;
      if ((adg < 0) && (mec == "")) {alert('Please enter a positive numeric value for ME.'); return;}
      metot = document.Myform.mepop.value;
      mptot = document.Myform.mppop.value;
      dmibwfu = document.Myform.dmibwfu.value;
      mecc = document.Myform.mecc.value;
      cpcf = document.Myform.cpcf.value;
      cpcc = document.Myform.cpcc.value;
      uipcf = document.Myform.uipcf.value;
      uipcc = document.Myform.uipcc.value;
      condmif = document.Myform.condmif.value/100;
      condmic = document.Myform.condmic.value/100;
      adgn = 0; 
      adgp = 0;
      if (adg < 0) {adgn = adg * -1;}
      if (adg > 0) {adgp = adg;}
      megreq = 0.0285;
      mbw = Math.pow(bw,.75);
mer = metot;
mecf = mec;
mpr = mptot;

dmifu = bw * (dmibwfu / 100);
meifu = mecf * dmifu;
merfu = mer - meifu;
edmicux = merfu / mecc; 
edmicu = edmicux; 
if (edmicux < 0) {edmicu = 0;}
digf = (mecf*1 + 1.8749)/0.1867
;
edmibwcu = (edmicu / bw) * 100;

if (cpcf >= 6.0) {esubnx = -1 * ((-0.0007 - (0.2491 * edmibwcu) + (0.7641 * edmibwcu * edmibwcu)  - (0.2006 * edmibwcu * edmibwcu * edmibwcu)) - ((55 - digf) * 0.04));}
  else {esubnx = 0;}
esubn = esubnx; 
  
if (esubnx > 0) {esubn = 0;}
if (edmibwcu <= 0.50) {esubn = 0;}

if ((cpcf < 6.0) && (cpcc > 15.0)) {esubpx = (1.0398 - (0.2323 * edmibwcu) - (0.7047 * edmibwcu * edmibwcu)  + (0.3757 * edmibwcu * edmibwcu * edmibwcu)) - ((6 - cpcf) * 0.05);}
   else {esubpx = 0;}
esubp = esubpx; 

if (esubpx < 0) {esubp = 0;}
esub = esubn;
if ((cpcf < 6.0) && (cpcc > 15.0)) {esub = esubp;}

edmifx = dmifu + (esub * edmicu); 
edmif = edmifx; 
if (edmifx < 0) {edmif = 0;}

emeif = edmif * mecf;
emerf = mer - emeif;
edmicx = emerf / mecc; 
edmic = edmicx; 
if (edmicx < 0) {edmic = 0;}
edmibwcu = (edmicu / bw) * 100;

mpcf = ((64 + (uipcf * 0.16)) * cpcf )/ 100;
mpcc = ((64 + (uipcc * 0.16)) * cpcc )/ 100;
mpifu = dmifu * (mpcf / 100);
mprfu = (mpr / 1000) - mpifu;
pdmicux = mprfu / (mpcc / 100); 
pdmicu = pdmicux; 
if (pdmicux < 0) {pdmicu = 0;}

pdmibwcu = (pdmicu / bw) * 100;

if (cpcf >= 6.0) {psubnx = -1 * ((-0.0007 - (0.2491 * edmibwcu) + (0.7641 * edmibwcu * edmibwcu)  - (0.2006 * edmibwcu * edmibwcu * edmibwcu)) - ((55 - digf) * 0.04));}
   else {psubnx = 0;}
psubn = psubnx; 
if (psubnx > 0) {psubn = 0;}
if (edmibwcu <= 0.50) {psubn = 0;} 

if ((cpcf < 6.0) && (cpcc > 15.0)) {psubpx = (1.0398 - (0.2323 * edmibwcu) - (0.7047 * edmibwcu * edmibwcu)  + (0.3757 * edmibwcu * edmibwcu * edmibwcu)) - ((6 - cpcf) * 0.05);}
  else {psubpx=0;}
psubp = psubpx; 
if (psubpx < 0) {psubp = 0;}
psub = psubn;
if ((cpcf < 6.0) && (cpcc > 15.0)) {psub = psubp;}

pdmifx = dmifu + (psub * pdmicu); 
pdmif = pdmifx; 
if (pdmifx < 0) {pdmif = 0;}

pmpif = pdmif * (mpcf / 100);
pmprf = (mpr / 1000) - pmpif;
pdmicx = pmprf / (mpcc / 100); 
pdmic = pdmicx; 
if (pdmicx < 0) {pdmic = 0;}

dmif = edmif; 
if (pdmic > edmic) {dmif = pdmif;}
dmibwf = (dmif / bw) * 100;
dmic = edmic; 
if (pdmic > edmic) {dmic = pdmic;}
dmibwc = (dmic / bw) * 100;
dmi = dmif + dmic;
dmibw = (dmi / bw) * 100;
dmibw2 = (dmif / bw) * 100;
dmiptc = (dmic / dmi) * 100;
dmiptf = (dmif / dmi) * 100;

meif = dmif * mecf;
meic = dmic * mecc;
mei = meif + meic;

mect = mei / dmi;
tdn = (mec*1 + 1.8749) / 0.18617;
tdnintg = dmi * (tdn / 100) * 1000;
diprg = tdnintg * 0.09;
dipcf = 100 - uipcf;
dipcc = 100 - uipcc;
dipigf = dmif * 1000 * (cpcf / 100) * (dipcf / 100);
dipigc = dmic * 1000 * (cpcc / 100) * (dipcc / 100);
dipig = dipigf + dipigc;


mpif = dmif * (mpcf / 100) * 1000;
mpic = dmic * (mpcc / 100) * 1000;
mpi = mpif + mpic;

mecd = mei / dmi;
mpcd = ((mpi /1000) / dmi) * 100;
cpif = (cpcf / 100) * dmif;
cpic = (cpcc / 100) * dmic;
cpi = cpif + cpic;
cpcd = (cpi / dmi) * 100;

emerfcor = mer-meif;
pmprfcor = mpr-mpif;

if (mei > mer) {optmeccx = emerfcor / dmic;}
if (dmic == 0) {optmeccx = " ";}
if (mei == mer) {optmeccx = " ";}
if ((mei < 0.99*mer) || (mei > 1.01*mer)) {optmeccx = " ";}
optmecc = optmeccx;
if (optmeccx < 0) {optmecc = " ";}

if (mpi > mpr) {optmpccx = (pmprfcor / (dmic*1000)) * 100;}
if (dmic == 0) {optmpccx = " ";}
if (mpi == mpr) {optmpccx = " ";}
if ((mpi > 0.99*mpr) && (mpi < 1.01*mpr)) {optmpccx = " ";}
optmpcc = optmpccx; 
if (optmpccx < 0) {optmpcc = " ";}

optcpcc = optmpcc/(.64 + ((uipcc/100)*.16));

    
      var dmiff = new ToFmt(dmi);
      var dmilbff = new ToFmt(dmi/.454);
      var dmibwff = new ToFmt(dmibw);
      var dmicf2 = new ToFmt(dmic);
      var dmilbcf2 = new ToFmt(dmic/.454);
      var dmibwcf = new ToFmt(dmibwc);
      var dmif2 = new ToFmt(dmif);
      var dmilbf2 = new ToFmt(dmif/.454);
      var dmibwf2 = new ToFmt(dmibw);
      var dmibw2f = new ToFmt(dmibw2);
      var dmiptcf = new ToFmt(dmiptc);
      var dmiptff = new ToFmt(dmiptf);
      var meiff = new ToFmt(meif);
      var meicf = new ToFmt(meic);
      var meif2 = new ToFmt(mei);
      var mpiff = new ToFmt(mpif);
      var mpicf = new ToFmt(mpic);
      var mpif2 = new ToFmt(mpi);
      var diprgf = new ToFmt(diprg);
      var dipigf = new ToFmt(dipig);
      var optmeccf = new ToFmt(optmecc);	
      var optmpccf = new ToFmt(optmpcc);	
      var optcpccf = new ToFmt(optcpcc);	
	
//      document.Myform.text1.value=dmiff.fmtF(8,2)+"  kg";
      document.Myform.text1.value=dmiff.fmtF(8,2)+"  kg ("+LTrim(dmilbff.fmtF(8,2))+"  lbs)";
      document.Myform.text2.value=dmibwff.fmtF(8,2)+"  %";
//      document.Myform.text3.value=dmicf2.fmtF(8,2)+"  kg";
      document.Myform.text3.value=dmicf2.fmtF(8,2)+"  kg ("+LTrim(dmilbcf2.fmtF(8,2))+"  lbs)";
      document.Myform.text4.value=dmibwcf.fmtF(8,2)+"  %";
//      document.Myform.text5.value=dmif2.fmtF(8,2)+"  kg";
      document.Myform.text5.value=dmif2.fmtF(8,2)+"  kg ("+LTrim(dmilbf2.fmtF(8,2))+"  lbs)";
      document.Myform.text6.value=dmibw2f.fmtF(8,2)+"  %";
      document.Myform.text7.value=dmiptcf.fmtF(8,2)+"  %";
      document.Myform.text8.value=dmiptff.fmtF(8,2)+"  %";
      document.Myform.text9.value=meiff.fmtF(8,2)+"  MJ";
      document.Myform.text10.value=meicf.fmtF(8,2)+"  MJ";
      document.Myform.text11.value=meif2.fmtF(8,2)+"  MJ";
      document.Myform.text12.value=mpiff.fmtF(8,2)+"  g";
      document.Myform.text13.value=mpicf.fmtF(8,2)+"  g";
      document.Myform.text14.value=mpif2.fmtF(8,2)+"  g";
if (optmecc == " ") {document.Myform.text15.value = optmecc;}	  
else {document.Myform.text15.value=optmeccf.fmtF(8,2)+"  MJ/kg DM";}
if (optmpcc == " ") {document.Myform.text16.value = optmpcc; document.Myform.text16a.value=optmpcc; }	
else {document.Myform.text16.value=optmpccf.fmtF(8,2)+"  %"; document.Myform.text16a.value=optcpccf.fmtF(8,2)+"  %";}
      document.Myform.text17.value=diprgf.fmtF(8,2)+"  g";
      document.Myform.text18.value=dipigf.fmtF(8,2)+"  g";
if (optmecc == " ") {document.Myform.text16b.value= optmecc;}
else {opttdnf = new ToFmt(optmecc/0.15104);
document.Myform.text16b.value=opttdnf.fmtF(8,1)+" % DM";}
//Tshoot();   

      dmibw2f = (dmif/condmif/bw) * 100;
      var dmi2ff = new ToFmt(dmif/condmif);
      var dmilbf = dmif/.454;
      var dmilb2ff = new ToFmt(dmilbf/condmif);
      var dmibw2ff = new ToFmt(dmibw2f);
	  document.Myform.text6a.value=dmi2ff.fmtF(8,2)+"  kg ("+LTrim(dmilb2ff.fmtF(8,2))+"  lbs)";
	  document.Myform.text6b.value=dmibw2ff.fmtF(8,2)+"  %"; 

      dmibw2c = (dmic/condmic/bw) * 100;
      var dmi2cf = new ToFmt(dmic/condmic);
      var dmilbc = dmic/.454;
      var dmilb2cf = new ToFmt(dmilbc/condmic);
      var dmibw2cf = new ToFmt(dmibw2c);
	  document.Myform.text4a.value=dmi2cf.fmtF(8,2)+"  kg ("+LTrim(dmilb2cf.fmtF(8,2))+"  lbs)";
	  document.Myform.text4b.value=dmibw2cf.fmtF(8,2)+"  %"; 

      var dmi2tf = (dmic/condmic)+(dmif/condmif);
      var dmilbt = (dmic/condmic/.454)+(dmif/condmif/.454);
      var dmibw2tf= dmibw2f+dmibw2c;
      var dmi2tf = new ToFmt(dmi2tf);
      var dmilb2tf = new ToFmt(dmilbt);
      var dmibw2tf = new ToFmt(dmibw2tf);

	  document.Myform.text6c.value=dmi2tf.fmtF(8,2)+"  kg ("+LTrim(dmilb2tf.fmtF(8,2))+"  lbs)";
	  document.Myform.text6d.value=dmibw2tf.fmtF(8,2)+"  %"; 
}
    
    
function Printable() {
for (var i=0; i < document.Myform.bio.length; i++ )
      {
        if (document.Myform.bio[i].checked) {
           var bio = document.Myform.bio[i].value;}
      }
var win1 = window.open('', 'Printable');
win1.document.open('text/html');
win1.document.write('<html>\n')
if (bio == 1) {win1.document.write('<head><title>Estimating Supplemental Concentrate Needs For Growing Goats</title>\n');} 
if (bio == 2) {win1.document.write('<head><title>Estimating Supplemental Concentrate Needs For Mature Goats</title>\n');} 
if (bio == 4) {win1.document.write('<head><title>Estimating Supplemental Concentrate Needs For Angora Goats</title>\n');} 
if (bio == 3) {win1.document.write('<head><title>Estimating Supplemental Concentrate Needs For Lactating Goats</title>\n');} 
win1.document.write('<script type="text/javascript" language="JavaScript">\n<!--\n');
win1.document.write('function _onclick() \n{\nwindow.print();\n}\n');
win1.document.write('-->\n<\/script>\n');
win1.document.write('<link rel=stylesheet href="../scripts/scripts_css.css" type="text/css">\n');
win1.document.write('</head>\n');
win1.document.write('<body>\n');
win1.document.write('<table cellspacing="0" cellpadding="2" width="100%">');
win1.document.write('<tr><td align=left valign="bottom"><img src="../../images/new_garza.png" width="312" height="245" border="0" alt=""></td>\n');
win1.document.write('<td align=right valign="bottom"><INPUT onclick="_onclick()" type=button value="Print" style="width: 5em;"><p>');
win1.document.write('<INPUT onclick="window.close()" type=button value="Close" style="width: 5em;"></td></tr>');
win1.document.write('</table>');
if (bio == 1) {win1.document.write('<p class="first-line">Estimating Supplemental Concentrate Needs For Growing Goats</p>\n');} 
if (bio == 2) {win1.document.write('<p class="first-line">Estimating Supplemental Concentrate Needs For Mature Goats</p>\n');} 
if (bio == 4) {win1.document.write('<p class="first-line">Estimating Supplemental Concentrate Needs For Angora Goats</p>\n');} 
if (bio == 3) {win1.document.write('<p class="first-line">Estimating Supplemental Concentrate Needs For Lactating Goats</p>\n');} 
win1.document.write('<h3>INPUTS</h3>\n');
win1.document.write('<table cellspacing="0" cellpadding="2" border="1" width="100%">');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Class</td>');
if (bio == 1) {win1.document.write('<td align="center">growing</td>');}
else if (bio == 2) {win1.document.write('<td align="center">mature</td>');} 
else if (bio == 3) {win1.document.write('<td align="center">lactating</td>');} 
else {win1.document.write('<td align="center">Angora</td>');}

if (bio != 4) {
win1.document.write('<tr>');
win1.document.write('<td width="50%">Biotype</td>');
var  bio2 = document.Myform.hidden4.value;
if (bio2 == 1) {win1.document.write('<td align="center">meat, 50% or more Boer</td>');}
else if (bio2 == 2) {win1.document.write('<td align="center">dairy</td>');} 
else if (bio2 == 3) {win1.document.write('<td align="center">indigenous or local</td>');} 
else {win1.document.write('<td align="center">undefined</td>');}
win1.document.write('</tr>');
}

win1.document.write('<tr>');
win1.document.write('<td width="50%">Gender</td>');
var  gen = document.Myform.hidden5.value;
if (gen == 1) {win1.document.write('<td align="center">female or wether</td>');}
else if (gen == 2) {win1.document.write('<td align="center">intact male</td>');} 
else {win1.document.write('<td align="center">undefined</td>');}
win1.document.write('</tr>');

if (bio == 4) {
win1.document.write('<tr>');
win1.document.write('<td width="50%">Maturity</td>');
var  mat = document.Myform.hidden6.value;
if (mat == 1) {win1.document.write('<td align="center">growing (&le; 1 year)</td>');}
else if (mat == 2) {win1.document.write('<td align="center">mature (&gt; 1 year)</td>');} 
else {win1.document.write('<td align="center">undefined</td>');}
}


win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Body weight</td><td align="center">');
win1.document.write(document.Myform.bw.value);
win1.document.write(' kg (');
      var bwp = new ToFmt((document.Myform.bw.value)/.454);
win1.document.write(LTrim(bwp.fmtI(6)));
win1.document.write(' lbs)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Average daily gain</td><td align="center">');
win1.document.write(document.Myform.adg.value);
win1.document.write(' g/day (');
var adgp = new ToFmt((document.Myform.adg.value)/454);
win1.document.write(LTrim(adgp.fmtF(6,2)));
win1.document.write(' lbs/day)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">ME requirement</td><td align="center">');
win1.document.write(document.Myform.mepop.value);
win1.document.write(' MJ');
if ((bio == 3) && (document.Myform.hidden1.value != "0")) {
win1.document.write('<br>based on:<br>'+document.Myform.hidden1.value+' kg milk yield (');
var birwtp = new ToFmt((document.Myform.hidden1.value)/.454);
win1.document.write(LTrim(birwtp.fmtF(6,1))+' lbs), ');
win1.document.write(' milk fat concentration = '+document.Myform.hidden2.value+'%');
}
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">MP requirement</td><td align="center">');
win1.document.write(document.Myform.mppop.value);
win1.document.write(' g');
if ((bio == 3) && (document.Myform.hidden1.value != "0")) {
win1.document.write('<br>based on:<br>'+document.Myform.hidden1.value+' kg milk yield (');
var birwtp = new ToFmt((document.Myform.hidden1.value)/.454);
win1.document.write(birwtp.fmtF(6,1)+' lbs), ');
win1.document.write(' milk protein concentration = '+document.Myform.hidden3.value+'%');
}
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Intake of forage without supplementation</td><td align="center">');
win1.document.write(document.Myform.dmibwfu.value);
win1.document.write(' % of body weight</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Forage ME concentration (forage TDN concentration)</td><td align="center">');
win1.document.write(document.Myform.mec.value);
win1.document.write(' MJ/kg dry matter (');
var tdndiet = new ToFmt((document.Myform.mec.value)/.1504);
win1.document.write(LTrim(tdndiet.fmtF(6,1)));
win1.document.write('% dry matter)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Forage CP concentration</td><td align="center">');
win1.document.write(document.Myform.cpcf.value);
win1.document.write(' %</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Supplemental concentrate ME concentration (supplemental concentrate TDN concentration)</td><td align="center">');
win1.document.write(document.Myform.mecc.value);
win1.document.write(' MJ/kg dry matter (');
var tdndiet = new ToFmt((document.Myform.mecc.value)/.1504);
win1.document.write(LTrim(tdndiet.fmtF(6,1)));
win1.document.write('% dry matter)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Supplemental concentrate CP concentration</td><td align="center">');
win1.document.write(document.Myform.cpcc.value);
win1.document.write(' %</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">UIP concentration in forage</td><td align="center">');
win1.document.write(document.Myform.uipcf.value);
win1.document.write('% total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">UIP undegraded protein concentration in supplemental concentrate </td><td align="center">');
win1.document.write(document.Myform.uipcc.value);
win1.document.write('% total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DM concentration in forage</td><td align="center">');
win1.document.write(document.Myform.condmif.value);
win1.document.write('%</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DM in supplemental concentration</td><td align="center">');
win1.document.write(document.Myform.condmic.value);
win1.document.write('%</td>');
win1.document.write('</tr>');
win1.document.write('</table>');
win1.document.write('<h3>OUTPUTS</h3>\n');
win1.document.write('<table cellspacing="0" cellpadding="2" border="1" width="100%">');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Final estimate of total intake, which is that based on ME or MP, dependent upon the greater estimate of supplemental concentrate intake (kg)</td><td align="center">');
win1.document.write(document.Myform.text1.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Total intake (% BW)</td><td align="center">');
win1.document.write(document.Myform.text2.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Final estimate of supplemental concentrate intake, which is that based on ME or MP, whichever is greater (kg)</td><td align="center">');
win1.document.write(document.Myform.text3.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Supplemental concentrate intake (% BW)</td><td align="center">');
win1.document.write(document.Myform.text4.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed supplemental concetrate intake</td><td align="center">');
win1.document.write(document.Myform.text4a.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed supplemental concentrate intake (% body weight)</td><td align="center">');
win1.document.write(document.Myform.text4b.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Forage DM intake (kg)</td><td align="center">');
win1.document.write(document.Myform.text5.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Forage DM intake (% BW)</td><td align="center">');
win1.document.write(document.Myform.text6.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed forage intake</td><td align="center">');
win1.document.write(document.Myform.text6a.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed forage intake (% body weight)</td><td align="center">');
win1.document.write(document.Myform.text6b.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed total intake</td><td align="center">');
win1.document.write(document.Myform.text6c.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">As fed total intake (% body weight)</td><td align="center">');
win1.document.write(document.Myform.text6d.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Supplemental concentrate intake (% total diet)</td><td align="center">');
win1.document.write(document.Myform.text7.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Forage intake (% total diet)</td><td align="center">');
win1.document.write(document.Myform.text8.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">ME from forage (MJ)</td><td align="center">');
win1.document.write(document.Myform.text9.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">ME from concentrate (MJ)</td><td align="center">');
win1.document.write(document.Myform.text10.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Total ME intake (MJ)</td><td align="center">');
win1.document.write(document.Myform.text11.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">MP from forage (g)</td><td align="center">');
win1.document.write(document.Myform.text12.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">MP from concentrate (g)</td><td align="center">');
win1.document.write(document.Myform.text13.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Total MP intake (g)</td><td align="center">');
win1.document.write(document.Myform.text14.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DIP requirement (g)</td><td align="center">');
win1.document.write(document.Myform.text17.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DIP from the diet (g)</td><td align="center">');
win1.document.write(document.Myform.text18.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Optimal supplemental concentrate <b class=\"highlight\">ME</b> concentration when the amount of supplement needed to meet the MP requirement was greater than that for ME (MJ/kg DM)</td><td align="center">');
win1.document.write(document.Myform.text15.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Optimal supplemental concentrate <b class=\"highlight\">TDN</b> concentration when the amount of supplement needed to meet the ME requirement was greater than that for MP (% DM)</td><td align="center">');
win1.document.write(document.Myform.text16b.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Optimal supplemental concentrate <b class=\"highlight\">MP</b> concentration when the amount of supplement needed to meet the ME requirement was greater than that for MP (% DM)</td><td align="center">');
win1.document.write(document.Myform.text16.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Optimal supplemental concentrate <b class=\"highlight\">CP</b> concentration when the amount of supplement needed to meet the ME requirement was greater than that for MP (% DM)</td><td align="center">');
win1.document.write(document.Myform.text16a.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('</table>');
//win1.document.write('<INPUT onclick="_onclick()" type=button value="Print">');
//win1.document.write('<img onClick="_onclick()" src="../../images/print.png">');
win1.document.write('</body>\n')
win1.document.write('</html>')
win1.document.close();
//win1.print();
//if (win1.confirm("If you were able to print from the \"Printer Dialogue\" box, then click \"OK\" to close this window and to return to the calculator.\n\nIf the \"Printer Dialogue\" box did not appear, then click \"Cancel\", manually print this window, and manually close this window to return to the calculator.")) {
//            win1.close();
//        }
//win1.close();
}


function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

// JS Object: ToFmt 
// Author: David Mosley, E-mail: David.Mosley@fundp.ac.be or davmos@fcmail.com
// August 1998.
// Contains a limited set of formatting routines for
// use in JavaScript scripts.
// Feel free to use this code in your scripts. I would be grateful if you
// could keep this header intact. 
// Please let me know if you find the code useful.
// Please report any bugs you find or improvements you make to the script. 
// The code has been tested, but no guarantee can be made of it functioning
// correctly. Use is entirely at your own risk.
// 
// Summary of methods
// fmt00(): Tags leading zero onto numbers 0 - 9.
// Particularly useful for displaying results from Date methods.
//
// fmtF(w,d): formats in a style similar to Fortran's Fw.d, where w is the
// width of the field and d is the number of figures after the decimal
// point. 
// The result is aligned to the right of the field.  The default
// padding character is a space " ". This can be modified using the 
// setSpacer(string) method of ToFmt. 
// If the result will not fit in the field , the field will be returned
// containing w asterisks.
//
// fmtE(w,d): formats in a style similar to Fortran's Ew.d, where w is the
// width of the field and d is the number of figures after the decimal
// point. 
// The result is aligned to the right of the field.  The default
// padding character is a space " ". This can be modified using the 
// setSpacer(string) method of ToFmt. 
// If the result will not fit in the field , the field will be returned
// containing w asterisks.
//
// fmtI(w): formats in a style similar to Fortran's Iw, where w is the
// width of the field.
// Floating point values are truncated (rounded down) for integer
// representation.
// The result is aligned to the right of the field.  The default
// padding character is a space " ". This can be modified using the 
// setSpacer(string) method of ToFmt. 
// If the result will not fit in the field , the field will be returned
// containing w asterisks.

function ToFmt(x){
 this.x=x;
 this.fmt00 = fmt00;
 this.fmtF = fmtF;
 this.fmtE=fmtE;
 this.fmtI=fmtI;
 this.spacer=" ";
 this.setSpacer=setSpacer;
}

function fmt00(){
 // fmt00: Tags leading zero onto numbers 0 - 9.
 // Particularly useful for displaying results from Date methods.
 //
 if (parseInt(this.x) < 0) var neg = true;
 if (Math.abs(parseInt(this.x)) < 10){
  this.x = "0"+ Math.abs(this.x);
 }
 if (neg) this.x = "-"+this.x;
 return this.x;
}

function fmtF(w,d){

 // fmtF: formats in a style similar to Fortran's Fw.d, where w is the
 // width of the field and d is the number of figures after the decimal
 // point. 
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the 
 // setSpacer(string) method of ToFmt. 
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 var width=w;
 var dpls=d;
 var lt1=false;
 var len=this.x.toString().length;
 var junk;
 var res="";
// First check for valid format request
 if ( width < (dpls+2)){
  window.alert("Illegal format specified : w = " + d +
               " w = " + d +
                "\nUsage: [ToFmt].fmtF(w,d)" +
                "\nWidth (w) of field must be greater or equal to the number " +
                "\nof digits to the right of the decimal point (d) + 2");
  junk = filljunk(width);
  return junk;
 }
// Work with absolute value
 var absx=Math.abs(this.x);
// Nasty fix to deal with numbers < 1 and problems with leading zeros!
 if ((absx < 1) && (absx > 0)){
  lt1 = true;
  absx+=10;
 }
// Get postion of decimal point
 var pt_pos = absx.toString().indexOf(".");
 if ( pt_pos == -1){
  res+= absx;
  res+= ".";
  for (var i = 0; i < dpls; i++){
   res += 0;
  }  
 }
 else{
  res = Math.round(absx * Math.pow(10,dpls));
  res=res.toString();
  if (res.length == 
      Math.round(Math.floor(absx * Math.pow(10,dpls))).toString().length){ 
   res = res.substring(0,pt_pos) + "." + 
         res.substring(pt_pos,res.length);
  }
  else{
   pt_pos++;
   res = res.substring(0,pt_pos) + "." + 
          res.substring(pt_pos,res.length);
  } 
// Remove leading 1 from  numbers < 1 (Nasty fix!)
  if (lt1) {
   res=res.substring(1,res.length);
  }
 }
 // Final formatting statements
 // Reinsert - sign for negative numbers
 if (this.x < 0)res = "-"+res;
 // Check whether the result fits in the width of the field specified
 if (res.length > width){
  res=filljunk(width);
 }
 // If necessary, pad from the left with the spacer string
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  } 
  res = res_bl + res;
 }
 return res;
}

function fmtE(w,d){

 // fmtE: formats in a style similar to Fortran's Ew.d, where w is the
 // width of the field and d is the number of figures after the decimal
 // point. 
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the 
 // setSpacer(string) method of ToFmt. 
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 //
 var width=w;
 var dpls=d;
 var e="E+";
 var len=this.x.toString().length;
 var pow10;
 var xp10;
 var junk;
 var res="";
// First check for valid format request
 if ( width < (dpls+5)){
  window.alert("Illegal format specified : w = " + d +
               " w = " + d +
                "\nUsage: [ToFmt].fmtE(w,d)" +
                "\nWidth (w) of field must be greater or equal to the number " +
                "\nof digits to the right of the decimal point (d) + 6");
  junk = filljunk(w);
  return junk;
 }
// Work with absolute value
 var absx=Math.abs(this.x);
// Get postion of decimal point
 var pt_pos = absx.toString().indexOf(".");
// For x=0
 if (absx == 0){
  res +="0.";
  for (var i=0; i< dpls; i++){
   res += "0";
  }
  res  += "E+00";
 }
// For abs(x) >= 1 
 else if (absx >= 1.0){
  pow10=1;
  xp10 = absx;
  while (xp10 >= 1.){
   pow10++;
   xp10 /= 10;
  }
  res = Math.round(xp10 * Math.pow(10,dpls));
  res=res.toString();
  if (res.length == 
      Math.round(Math.floor(xp10 * Math.pow(10,dpls))).toString().length){ 
    pow10--;
  }
  res = "0." + res.substring(0,dpls) + e + (new ToFmt(pow10)).fmt00();
 }
// For abs(x) < 1
 else if (absx < 1.0){
  pow10=1;
  xp10 = absx;
  while (xp10 < 1.){
   pow10--;
   xp10 *= 10;
  }
  res = Math.round(xp10/10 * Math.pow(10,dpls));
  res=res.toString();
  if (res.length != 
      Math.round(Math.floor(xp10/10 * Math.pow(10,dpls))).toString().length){ 
    pow10++;
  }
  if (pow10 < 0) e = "E-";
  res = "0." + res.substring(0,dpls) + e + (new ToFmt(Math.abs(pow10))).fmt00();
 }
 
 if (this.x < 0)res = "-"+res;
 if (res.length > width){
  res=filljunk(width);
 }
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  } 
  res = res_bl + res;
 }
 return res;
 
}

function fmtI(w){

 // fmtI: formats in a style similar to Fortran's Iw, where w is the
 // width of the field.
 // Floating point values are truncated (rounded down) for integer
 // representation.
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the 
 // setSpacer(string) method of ToFmt. 
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 var width=w;
 var lt0=false;
 var len=this.x.toString().length;
 var junk;
 var res="";
// Work with absolute value
 var absx = Math.abs(this.x);

// Test for < 0
 if (parseInt(this.x) < 0){
  lt0 = true;
 }
 res = Math.round(Math.floor((absx))).toString();
 if (lt0){
  res = "-"+res;
 }
 if (res.length > width){
  res=filljunk(width);
 }
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  } 
  res = res_bl + res;
 }
 return res;
}

function filljunk(lenf){
 // Fills field of length lenf with asterisks
 var str="";
 for (var i=0; i < lenf; i++){
  str +="*";
 }
 return str;
}

function setSpacer(spc){
 var spc;
 this.spacer=spc;
 return this.spacer;
}   
