//pre-load image for printable
Image1= new Image(312,245);
Image1.src = "../../images/new_garza.png";

var state = 'block'; 

function showhide(mylayer_ref1,mylayer_ref2,mylayer_ref3,mylayer_ref4,mylayer_ref5) { 

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"); 
} 
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; 
} 
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; 
} 
} 


function checkedbox_values()
{
var checkedValue = new Array();
var per = new Array();
var type = new Array();
var j = 0;

for (var i=0; i < document.Myform.forage.length; i++)
   {
   if (document.Myform.forage[i].checked)
      {
         checkedValue[j] = document.Myform.forage[i].value; 
         type[j] = checkedValue[j].substr(0,1); 
         j++;
      }
   }
var feedstuffs = new Array(
new Array("f1","Acacia macracantha leaves","0.224","0.30","0.62","0.030","0.021","0.07","0.90","1.66"),
new Array("f2","Alfalfa hay","0.183","0.25","0.65","0.290","0.180","0.00","0.92","9.08"),
new Array("f3","Alfalfa meal","0.192","0.28","0.66","0.067","0.125","0.00","1.00","9.25"),
new Array("c43","Ammonium chloride","1.642","1.00","0.00","","0.000","0.00","1.00","0"),
new Array("c44","Apple pomace","0.063","0.25","0.61","0.035","0.315","0.00","1.00","10.42"),
new Array("c45","Barley grain","0.138","0.25","0.70","0.350","0.050","0.00","0.29","12.72"),
new Array("f7","Barley hay","0.125","0.22","0.60","0.080","0.093","0.09","0.93","8.74"),
new Array("f8","Bermudagrass hay","0.100","0.37","0.52","0.080","0.088","0.03","0.25","7.41"),
new Array("c46","Blood meal","0.955","0.10","0.61","0.019","0.010","0.28","0.00","10.00"),
new Array("c47","Bone meal","0.132","0.18","0.48","0.072","0.000","0.34","0.00","0"),
new Array("c48","Brewers spent grain","0.292","0.18","0.65","0.047","0.120","0.05","0.75","10.00"),
new Array("c49","Casava chips (tapioca),","0.038","0.25","0.70","0.120","0.050","0.00","0.45","14.14"),
new Array("f13","Casava peel silage","0.058","0.14","0.39","0.070","0.080","0.39","1.00","13.02"),
new Array("c50","Chickpea","0.266","0.12","0.82","0.071","0.010","0.05","0.23","13.50"),
new Array("f15","Chickpea straw","0.085","0.30","0.35","0.053","0.177","0.17","0.00","7.43"),
new Array("c51","Coconut meal","0.213","0.28","0.65","0.087","0.030","0.04","0.75","11.34"),
new Array("c1","Concentrate","0.137","0.58","0.30","0.063","0.022","0.09","0.45",""),
new Array("c2","Corn grain (ground)","0.094","0.24","0.73","0.049","0.032","0.00","0.73","13.31"),
new Array("c3","Corn bran","0.119","0.45","0.49","0.070","0.005","0.06","0.80","12.27"),
new Array("c4","Corn gluten meal","0.650","0.04","0.91","0.023","0.046","0.01","0.75","13.47"),
new Array("f17","Corn stalks","0.041","0.20","0.66","0.040","0.136","0.00","0.95","9.96"),
new Array("c6","Cottonseed meal","0.449","0.26","0.56","0.068","0.040","0.15","0.40","11.34"),
new Array("f18","Cottonseed hulls","0.041","0.30","0.35","0.053","0.177","0.17","0.00","6.36"),
new Array("c8","Dried beet pulp","0.100","0.05","0.91","0.020","0.060","0.00","0.96","12.09"),
new Array("c9","Faba bean seed","0.314","0.67","0.33","0.039","0.020","0.00","0.23","13.10"),
new Array("f19","Flemingia macrophylla leaves ","0.112","0.13","0.13","0.002","0.017","0.73","0.96","10.78"),
new Array("f20","Gliricidia leaves","0.183","0.29","0.45","0.074","0.250","0.01","1.00","10.78"),
new Array("f21","Groundnut hulls","0.078","0.23","0.76","0.050","0.087","0.00","0.00","2.22"),
new Array("c13","Groundnut cake","0.518","0.62","0.37","0.161","0.021","0.00","0.23","12.46"),
new Array("f22","Guatemala grass","0.087","0.23","0.68","0.020","0.089","0.00","0.25","7.43"),
new Array("f23","Guinea grass","0.094","0.06","0.57","0.073","0.089","0.28","0.25","7.43"),
new Array("f24","Krishnachura leaves","0.145","0.18","0.60","0.028","0.200","0.02","0.92","10.78"),
new Array("f25","Leucaena leaves","0.269","0.30","0.62","0.030","0.021","0.07","0.90","10.78"),
new Array("c18","Lupin seed","0.345","0.30","0.67","0.261","0.034","0.00","0.68","11.80"),
new Array("c19","Meat meal","0.576","0.35","0.40","0.060","0.032","0.22","0.27","11.34"),
new Array("c20","Molasses","0.085","0.74","0.26","0.032","0.000","0.00","1.00","10.88"),
new Array("f26","Mulberry (Morus alba), leaves","0.208","0.20","0.50","0.026","0.200","0.10","0.92","11.34"),
new Array("c22","Mustard oil cake","0.385","0.23","0.70","0.104","0.063","0.00","0.65","11.34"),
new Array("f27","Napier grass","0.078","0.46","0.52","0.110","0.022","0.00","0.02","6.88"),
new Array("f28","Oat hay ","0.058","0.35","0.53","0.043","0.103","0.02","0.93","8.03"),
new Array("f29","Orchardgrass hay","0.130","0.25","0.69","0.110","0.061","0.00","0.96","8.16"),
new Array("f30","Paragrass (Brachiaria mutica), hay","0.092","0.09","0.70","0.054","0.110","0.10","0.95","6.13"),
new Array("f31","Peanut hay","0.171","0.39","0.50","0.140","0.099","0.02","0.96","8.36"),
new Array("f32","Rhodesgrass hay","0.066","0.28","0.53","0.050","0.167","0.02","0.96","8.36"),
new Array("f34","Rice straw (NaOH treated),","0.035","0.36","0.37","0.067","0.292","0.00","0.95","6.5"),
new Array("f35","Rice straw (urea treated),","0.035","0.11","0.66","0.034","0.138","0.09","0.95","6.5"),
new Array("f36","Rice straw ","0.053","0.41","0.42","0.023","0.168","0.00","0.95","5.57"),
new Array("f37","Sesbania grandiflora leaves","0.208","0.11","0.79","0.183","0.100","0.01","0.96","9.30"),
new Array("c34","Sorghum grain","0.116","0.19","0.79","0.055","0.086","0.00","0.33","12.38"),
new Array("f38","Sorghum-sudan hay","0.094","0.28","0.53","0.050","0.128","0.06","0.95","8.49"),
new Array("c36","Soybean meal","0.499","0.05","0.93","0.037","0.020","0.00","0.55","13.18"),
new Array("c37","Soybean meal - formaldehyde treated","0.471","0.07","0.93","0.028","0.000","0.00","0.55","13.18"),
new Array("f39","Sugar cane bagasse","0.030","0.03","0.49","0.049","0.315","0.17","0.96","4.83"),
new Array("c39","Urea","2.880","1.00","0.00","","0.000","0.00","1.00","0"),
new Array("c40","Vetch bran","0.256","0.56","0.44","0.167","0.010","0.00","0.96","10.59"),
new Array("c41","Wheat bran","0.173","0.34","0.63","0.200","0.081","0.00","0.75","10.59"),
new Array("c42","Rice bran","0.155","0.33","0.49","0.050","0.026","0.16","0.80","10.59"),
new Array("f40","Wheat straw","0.048","0.09","0.51","0.014","0.292","0.10","0.95","6.19"),
new Array("c52","Barley grain, rolled","0.124","0.3","0.61","0.23","0.04","0.05","0.29","12.72"),
new Array("c53","Canola meal","0.393","0.18","0.81","0.044","0.064","0","0.65","10.42"),
new Array("c54","Coconut meal","0.213","0.28","0.65","0.087","0.03","0.04","0.75","11.34"),
new Array("c55","Feather meal","0.92","0.23","0.24","0.066","0.32","0.21","0.89","10.29"),
new Array("c56","Fish meal","0.685","0.23","0.72","0.014","0.01","0.04","0","11.05"),
new Array("c57","Grape skin cake","0.067","0.27","0.62","0.11","0.11","0","0.96","3.71"),
new Array("c58","Meat and bone meal","0.542","0.18","0.48","0.072","0.032","0.31","0.27","11.34"),
new Array("c59","Oats","0.132","0.65","0.29","0.174","0.023","0.04","0.19","11.63"),
new Array("c60","Palm kernel cake","0.194","0.24","0.7","0.07","0.097","0","0.75","12.09"),
new Array("c61","Soybean hulls","0.141","0.23","0.72","0.062","0.072","0","0.72","12.09"),
new Array("c62","Soybean meal, heat-treated","0.463","0.09","0.91","0.02","0.01","0","0.84","13.18"),
new Array("c63","Sunflower meal","0.284","0.42","0.53","0.292","0.049","0","1","10.23"),
new Array("c64","Wheat middlings","0.185","0.4","0.54","0.15","0.03","0.03","0.75","13.39"),
new Array("f41","Barley straw","0.043","0.47","0.27","0.12","0.257","0","0.95","6.07"),
new Array("f42","Clover hay","0.178","0.39","0.5","0.14","0.067","0.05","0.96","8.33"),
new Array("f43","Corn silage","0.087","0.51","0.3","0.044","0.091","0.09","1","10.88"),
new Array("f44","Dehydrated alfalfa pellets","0.192","0.28","0.66","0.07","0.13","0","1","9.25"),
new Array("f45","Grass hay","0.133","0.37","0.52","0.081","0.09","0.03","0.02","8.92"),
new Array("f46","Grass silage","0.14","0.63","0.31","0.13","0.058","0.09","1","9.48"),
new Array("f47","Ground peanut hulls","0.078","0.23","0.76","0.05","0.09","0","0","2.22"),
new Array("f48","Mixed grass hay","0.106","0.37","0.5","0.09","0.1","0.03","0.05","7.43"),
new Array("f49","Oat/sorghum hay","0.093","0.32","0.53","0.05","0.1","0.06","0.94","8.18"),
new Array("f50","Oaten chaff","0.091","0.35","0.53","0.04","0.07","0.05","0.93","5.31"),
new Array("f51","Sugar beet pulp silage","0.1","0.05","0.91","0.02","0.06","0","0.96","7.62"),
new Array("f52","Barley straw, urea treated","0.07","0.7","0.2","0.08","0.098","0","0.98","6.07"),
new Array("m1","Mineral/Vitamin Supplement","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0")
);


var win2 = window.open('', 'Feeds'); //, 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');
win2.document.open('text/html');
win2.document.write('<html>\n');
win2.document.write('<head><title>Feed Ingredients</title>\n');
win2.document.write('<SCRIPT Language=JavaScript>\n');

win2.document.write('function showhide(mylayer_ref1,state) { \n');
win2.document.write(' \n');
win2.document.write('if (document.all) { //IS IE 4 or 5 (or 6 beta) \n');
win2.document.write('eval( "document.all." + mylayer_ref1 + ".style.display = state"); \n');
win2.document.write('} \n');
win2.document.write('if (document.layers) { //IS NETSCAPE 4 or below \n');
win2.document.write('document.layers[mylayer_ref1].display = state; \n');
win2.document.write('} \n');
win2.document.write('if (document.getElementById &&!document.all) { \n');
win2.document.write('hza1 = document.getElementById(mylayer_ref1); \n');
win2.document.write('hza1.style.display = state; \n');
win2.document.write('} \n');
win2.document.write('\n');
win2.document.write('} \n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('function calc3() {\n');
win2.document.write('var feed = new Array();\n');
win2.document.write('var type = new Array();\n');
win2.document.write('var percft = 0;\n');
win2.document.write('var percct = 0;\n');
win2.document.write('tempc = tempf = 0;\n');
win2.document.write('\n');
win2.document.write('j = document.Myform.j.value;\n');
win2.document.write('for (var i=0; i<j;i++){\n');
win2.document.write('  feed[i] = new Array();\n');
win2.document.write('   eval("feed[i][0] = document.Myform.hidden" + i + ".value");\n');
win2.document.write('   eval("feed[i][1] = document.Myform.per" + i + ".value");\n');
win2.document.write('   eval("feed[i][2] = document.Myform.me" + i + ".value");\n');
win2.document.write('   eval("feed[i][3] = document.Myform.cp" + i + ".value");\n');
win2.document.write('   type[i] = feed[i][0].substr(0,1); \n');
win2.document.write('      if (type[i] == "f") {tempf = feed[i][1]; percft += tempf/1;}\n');
win2.document.write('      if (type[i] == "c") {tempc = feed[i][1]; percct += tempc/1;}\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('var feedstuffs = new Array(\n');
win2.document.write('new Array("f1","Acacia macracantha leaves","0.224","0.30","0.62","0.030","0.021","0.07","0.90","1.66"),\n');
win2.document.write('new Array("f2","Alfalfa hay","0.183","0.25","0.65","0.290","0.180","0.00","0.92","9.08"),\n');
win2.document.write('new Array("f3","Alfalfa meal","0.192","0.28","0.66","0.067","0.125","0.00","1.00","9.25"),\n');
win2.document.write('new Array("c43","Ammonium chloride","1.642","1.00","0.00","","0.000","0.00","1.00","0"),\n');
win2.document.write('new Array("c44","Apple pomace","0.063","0.25","0.61","0.035","0.315","0.00","1.00","10.42"),\n');
win2.document.write('new Array("c45","Barley grain","0.138","0.25","0.70","0.350","0.050","0.00","0.29","12.72"),\n');
win2.document.write('new Array("f7","Barley hay","0.125","0.22","0.60","0.080","0.093","0.09","0.93","8.74"),\n');
win2.document.write('new Array("f8","Bermudagrass hay","0.100","0.37","0.52","0.080","0.088","0.03","0.25","7.41"),\n');
win2.document.write('new Array("c46","Blood meal","0.955","0.10","0.61","0.019","0.010","0.28","0.00","10.00"),\n');
win2.document.write('new Array("c47","Bone meal","0.132","0.18","0.48","0.072","0.000","0.34","0.00","0"),\n');
win2.document.write('new Array("c48","Brewers spent grain","0.292","0.18","0.65","0.047","0.120","0.05","0.75","10.00"),\n');
win2.document.write('new Array("c49","Casava chips (tapioca),","0.038","0.25","0.70","0.120","0.050","0.00","0.45","14.14"),\n');
win2.document.write('new Array("f13","Casava peel silage","0.058","0.14","0.39","0.070","0.080","0.39","1.00","13.02"),\n');
win2.document.write('new Array("c50","Chickpea","0.266","0.12","0.82","0.071","0.010","0.05","0.23","13.50"),\n');
win2.document.write('new Array("f15","Chickpea straw","0.085","0.30","0.35","0.053","0.177","0.17","0.00","7.43"),\n');
win2.document.write('new Array("c51","Coconut meal","0.213","0.28","0.65","0.087","0.030","0.04","0.75","11.34"),\n');
win2.document.write('new Array("c1","Concentrate","0.137","0.58","0.30","0.063","0.022","0.09","0.45",""),\n');
win2.document.write('new Array("c2","Corn grain (ground)","0.094","0.24","0.73","0.049","0.032","0.00","0.73","13.31"),\n');
win2.document.write('new Array("c3","Corn bran","0.119","0.45","0.49","0.070","0.005","0.06","0.80","12.27"),\n');
win2.document.write('new Array("c4","Corn gluten meal","0.650","0.04","0.91","0.023","0.046","0.01","0.75","13.47"),\n');
win2.document.write('new Array("f17","Corn stalks","0.041","0.20","0.66","0.040","0.136","0.00","0.95","9.96"),\n');
win2.document.write('new Array("c6","Cottonseed meal","0.449","0.26","0.56","0.068","0.040","0.15","0.40","11.34"),\n');
win2.document.write('new Array("f18","Cottonseed hulls","0.041","0.30","0.35","0.053","0.177","0.17","0.00","6.36"),\n');
win2.document.write('new Array("c8","Dried beet pulp","0.100","0.05","0.91","0.020","0.060","0.00","0.96","12.09"),\n');
win2.document.write('new Array("c9","Faba bean seed","0.314","0.67","0.33","0.039","0.020","0.00","0.23","13.10"),\n');
win2.document.write('new Array("f19","Flemingia macrophylla leaves ","0.112","0.13","0.13","0.002","0.017","0.73","0.96","10.78"),\n');
win2.document.write('new Array("f20","Gliricidia leaves","0.183","0.29","0.45","0.074","0.250","0.01","1.00","10.78"),\n');
win2.document.write('new Array("f21","Groundnut hulls","0.078","0.23","0.76","0.050","0.087","0.00","0.00","2.22"),\n');
win2.document.write('new Array("c13","Groundnut cake","0.518","0.62","0.37","0.161","0.021","0.00","0.23","12.46"),\n');
win2.document.write('new Array("f22","Guatemala grass","0.087","0.23","0.68","0.020","0.089","0.00","0.25","7.43"),\n');
win2.document.write('new Array("f23","Guinea grass","0.094","0.06","0.57","0.073","0.089","0.28","0.25","7.43"),\n');
win2.document.write('new Array("f24","Krishnachura leaves","0.145","0.18","0.60","0.028","0.200","0.02","0.92","10.78"),\n');
win2.document.write('new Array("f25","Leucaena leaves","0.269","0.30","0.62","0.030","0.021","0.07","0.90","10.78"),\n');
win2.document.write('new Array("c18","Lupin seed","0.345","0.30","0.67","0.261","0.034","0.00","0.68","11.80"),\n');
win2.document.write('new Array("c19","Meat meal","0.576","0.35","0.40","0.060","0.032","0.22","0.27","11.34"),\n');
win2.document.write('new Array("c20","Molasses","0.085","0.74","0.26","0.032","0.000","0.00","1.00","10.88"),\n');
win2.document.write('new Array("f26","Mulberry (Morus alba), leaves","0.208","0.20","0.50","0.026","0.200","0.10","0.92","11.34"),\n');
win2.document.write('new Array("c22","Mustard oil cake","0.385","0.23","0.70","0.104","0.063","0.00","0.65","11.34"),\n');
win2.document.write('new Array("f27","Napier grass","0.078","0.46","0.52","0.110","0.022","0.00","0.02","6.88"),\n');
win2.document.write('new Array("f28","Oat hay ","0.058","0.35","0.53","0.043","0.103","0.02","0.93","8.03"),\n');
win2.document.write('new Array("f29","Orchardgrass hay","0.130","0.25","0.69","0.110","0.061","0.00","0.96","8.16"),\n');
win2.document.write('new Array("f30","Paragrass (Brachiaria mutica), hay","0.092","0.09","0.70","0.054","0.110","0.10","0.95","6.13"),\n');
win2.document.write('new Array("f31","Peanut hay","0.171","0.39","0.50","0.140","0.099","0.02","0.96","8.36"),\n');
win2.document.write('new Array("f32","Rhodesgrass hay","0.066","0.28","0.53","0.050","0.167","0.02","0.96","8.36"),\n');
win2.document.write('new Array("f34","Rice straw (NaOH treated),","0.035","0.36","0.37","0.067","0.292","0.00","0.95","6.5"),\n');
win2.document.write('new Array("f35","Rice straw (urea treated),","0.035","0.11","0.66","0.034","0.138","0.09","0.95","6.5"),\n');
win2.document.write('new Array("f36","Rice straw ","0.053","0.41","0.42","0.023","0.168","0.00","0.95","5.57"),\n');
win2.document.write('new Array("f37","Sesbania grandiflora leaves","0.208","0.11","0.79","0.183","0.100","0.01","0.96","9.30"),\n');
win2.document.write('new Array("c34","Sorghum grain","0.116","0.19","0.79","0.055","0.086","0.00","0.33","12.38"),\n');
win2.document.write('new Array("f38","Sorghum-sudan hay","0.094","0.28","0.53","0.050","0.128","0.06","0.95","8.49"),\n');
win2.document.write('new Array("c36","Soybean meal","0.499","0.05","0.93","0.037","0.020","0.00","0.55","13.18"),\n');
win2.document.write('new Array("c37","Soybean meal - formaldehyde treated","0.471","0.07","0.93","0.028","0.000","0.00","0.55","13.18"),\n');
win2.document.write('new Array("f39","Sugar cane bagasse","0.030","0.03","0.49","0.049","0.315","0.17","0.96","4.83"),\n');
win2.document.write('new Array("c39","Urea","2.880","1.00","0.00","","0.000","0.00","1.00","0"),\n');
win2.document.write('new Array("c40","Vetch bran","0.256","0.56","0.44","0.167","0.010","0.00","0.96","10.59"),\n');
win2.document.write('new Array("c41","Wheat bran","0.173","0.34","0.63","0.200","0.081","0.00","0.75","10.59"),\n');
win2.document.write('new Array("c42","Rice bran","0.155","0.33","0.49","0.050","0.026","0.16","0.80","10.59"),\n');
win2.document.write('new Array("f40","Wheat straw","0.048","0.09","0.51","0.014","0.292","0.10","0.95","6.19"),\n');
win2.document.write('new Array("c52","Barley grain, rolled","0.124","0.3","0.61","0.23","0.04","0.05","0.29","12.72"),\n');
win2.document.write('new Array("c53","Canola meal","0.393","0.18","0.81","0.044","0.064","0","0.65","10.42"),\n');
win2.document.write('new Array("c54","Coconut meal","0.213","0.28","0.65","0.087","0.03","0.04","0.75","11.34"),\n');
win2.document.write('new Array("c55","Feather meal","0.92","0.23","0.24","0.066","0.32","0.21","0.89","10.29"),\n');
win2.document.write('new Array("c56","Fish meal","0.685","0.23","0.72","0.014","0.01","0.04","0","11.05"),\n');
win2.document.write('new Array("c57","Grape skin cake","0.067","0.27","0.62","0.11","0.11","0","0.96","3.71"),\n');
win2.document.write('new Array("c58","Meat and bone meal","0.542","0.18","0.48","0.072","0.032","0.31","0.27","11.34"),\n');
win2.document.write('new Array("c59","Oats","0.132","0.65","0.29","0.174","0.023","0.04","0.19","11.63"),\n');
win2.document.write('new Array("c60","Palm kernel cake","0.194","0.24","0.7","0.07","0.097","0","0.75","12.09"),\n');
win2.document.write('new Array("c61","Soybean hulls","0.141","0.23","0.72","0.062","0.072","0","0.72","12.09"),\n');
win2.document.write('new Array("c62","Soybean meal, heat-treated","0.463","0.09","0.91","0.02","0.01","0","0.84","13.18"),\n');
win2.document.write('new Array("c63","Sunflower meal","0.284","0.42","0.53","0.292","0.049","0","1","10.23"),\n');
win2.document.write('new Array("c64","Wheat middlings","0.185","0.4","0.54","0.15","0.03","0.03","0.75","13.39"),\n');
win2.document.write('new Array("f41","Barley straw","0.043","0.47","0.27","0.12","0.257","0","0.95","6.07"),\n');
win2.document.write('new Array("f42","Clover hay","0.178","0.39","0.5","0.14","0.067","0.05","0.96","8.33"),\n');
win2.document.write('new Array("f43","Corn silage","0.087","0.51","0.3","0.044","0.091","0.09","1","10.88"),\n');
win2.document.write('new Array("f44","Dehydrated alfalfa pellets","0.192","0.28","0.66","0.07","0.13","0","1","9.25"),\n');
win2.document.write('new Array("f45","Grass hay","0.133","0.37","0.52","0.081","0.09","0.03","0.02","8.92"),\n');
win2.document.write('new Array("f46","Grass silage","0.14","0.63","0.31","0.13","0.058","0.09","1","9.48"),\n');
win2.document.write('new Array("f47","Ground peanut hulls","0.078","0.23","0.76","0.05","0.09","0","0","2.22"),\n');
win2.document.write('new Array("f48","Mixed grass hay","0.106","0.37","0.5","0.09","0.1","0.03","0.05","7.43"),\n');
win2.document.write('new Array("f49","Oat/sorghum hay","0.093","0.32","0.53","0.05","0.1","0.06","0.94","8.18"),\n');
win2.document.write('new Array("f50","Oaten chaff","0.091","0.35","0.53","0.04","0.07","0.05","0.93","5.31"),\n');
win2.document.write('new Array("f51","Sugar beet pulp silage","0.1","0.05","0.91","0.02","0.06","0","0.96","7.62"),\n');
win2.document.write('new Array("f52","Barley straw, urea treated","0.07","0.7","0.2","0.08","0.098","0","0.98","6.07")\n');
win2.document.write(');\n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('var cpf = 0;\n');
win2.document.write('var solpf = 0;\n');
win2.document.write('var sdpf = 0;\n');
win2.document.write('var kdf = 0;\n');
win2.document.write('var adipf = 0;\n');
win2.document.write('var drudpf = 0;\n');
win2.document.write('var npcpf = 0;\n');
win2.document.write('var cpc = 0;\n');
win2.document.write('var solpc = 0;\n');
win2.document.write('var sdpc = 0;\n');
win2.document.write('var kdc = 0;\n');
win2.document.write('var adipc = 0;\n');
win2.document.write('var drudpc = 0;\n');
win2.document.write('var npcpc = 0;\n');
win2.document.write('\n');
win2.document.write('var mef = 0;\n');
win2.document.write('var mec = 0;\n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('//for (var i=0; i<j; i++){\n');
win2.document.write('//      if (type[i] == "f") {percft += (feed[i][1]/1);}\n');
win2.document.write('//      if (type[i] == "c") {percct += (feed[i][1]/1);}\n');
win2.document.write('//}\n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('for (var i=0; i<j; i++){\n');
win2.document.write('  for (var ii=0; ii < feedstuffs.length; ii++){\n');
win2.document.write('   if (feed[i][0] == feedstuffs[ii][0]) {\n');
win2.document.write('      if (type[i] == "f") {\n');
win2.document.write('//         cpf += (feedstuffs[ii][2] * feed[i][1] / percft*1);\n');
win2.document.write('         solpf += (feedstuffs[ii][3] * feed[i][1] / percft*1);\n');
win2.document.write('         sdpf += (feedstuffs[ii][4] * feed[i][1] / percft*1);\n');
win2.document.write('         kdf += (feedstuffs[ii][5] * feed[i][1] / percft*1);\n');
win2.document.write('         adipf += (feedstuffs[ii][6] * feed[i][1] / percft*1);\n');
win2.document.write('         drudpf += (feedstuffs[ii][7] * feed[i][1] / percft*1);\n');
win2.document.write('         npcpf += (feedstuffs[ii][8] * feed[i][1] / percft*1);\n');
win2.document.write('         mef += (feed[i][2] * feed[i][1] / percft*1);\n');
win2.document.write('         cpf += (feed[i][3] * feed[i][1] / percft*1);\n');
win2.document.write('      }\n');
win2.document.write('      if (type[i] == "c") {\n');
win2.document.write('//         cpc += (feedstuffs[ii][2] * feed[i][1] / percct*1);\n');
win2.document.write('         solpc += (feedstuffs[ii][3] * feed[i][1] / percct*1);\n');
win2.document.write('         sdpc += (feedstuffs[ii][4] * feed[i][1] / percct*1);\n');
win2.document.write('         kdc += (feedstuffs[ii][5] * feed[i][1] / percct*1);\n');
win2.document.write('         adipc += (feedstuffs[ii][6] * feed[i][1] / percct*1);\n');
win2.document.write('         drudpc += (feedstuffs[ii][7] * feed[i][1] / percct*1);\n');
win2.document.write('         npcpc += (feedstuffs[ii][8] * feed[i][1] / percct*1);\n');
win2.document.write('         mec += (feed[i][2] * feed[i][1] / percct*1);\n');
win2.document.write('         cpc += (feed[i][3] * feed[i][1] / percct*1);\n');
win2.document.write('      }\n');
win2.document.write('   }\n');
win2.document.write('   }\n');
win2.document.write('} \n');
win2.document.write('\n');
win2.document.write('cpf = cpf/100;\n');
win2.document.write('cpc = cpc/100;\n');
win2.document.write('\n');
win2.document.write('//for (var i=0; i<j; i++){\n');
win2.document.write('//  for (var ii=0; ii < FeedME.length; ii++){\n');
win2.document.write('//   if (feed[i][0] == FeedME[ii][0]) {\n');
win2.document.write('//      if (type[i] == "f") {\n');
win2.document.write('//         mef += (FeedME[ii][2] * feed[i][1] / percft*1);\n');
win2.document.write('//      }\n');
win2.document.write('//      if (type[i] == "c") {\n');
win2.document.write('//         mec += (FeedME[ii][2] * feed[i][1] / percct*1);\n');
win2.document.write('//      }\n');
win2.document.write('//   }\n');
win2.document.write('//   }\n');
win2.document.write('//} \n');
win2.document.write('\n');
win2.document.write('\n');
win2.document.write('         var cpf2 = new ToFmt(cpf);\n');
win2.document.write('         var solpf2 = new ToFmt(solpf);\n');
win2.document.write('         var sdpf2 = new ToFmt(sdpf);\n');
win2.document.write('         var kdf2 = new ToFmt(kdf);\n');
win2.document.write('         var adipf2 = new ToFmt(adipf);\n');
win2.document.write('         var drudpf2 = new ToFmt(drudpf);\n');
win2.document.write('         var npcpf2 = new ToFmt(npcpf);\n');
win2.document.write('         var cpc2 = new ToFmt(cpc);\n');
win2.document.write('         var solpc2 = new ToFmt(solpc);\n');
win2.document.write('         var sdpc2 = new ToFmt(sdpc);\n');
win2.document.write('         var kdc2 = new ToFmt(kdc);\n');
win2.document.write('         var adipc2 = new ToFmt(adipc);\n');
win2.document.write('         var drudpc2 = new ToFmt(drudpc);\n');
win2.document.write('         var npcpc2 = new ToFmt(npcpc);\n');
win2.document.write('         var meff = new ToFmt(mef);\n');
win2.document.write('         var mecf = new ToFmt(mec);\n');
win2.document.write('\n');
win2.document.write('//      var mpif = new ToFmt(mpi);\n');
win2.document.write('//      var mpiptf = new ToFmt(mpipt);\n');
win2.document.write('\n');
win2.document.write('    window.opener.document.Myform.cpf.value = cpf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.solpf.value = solpf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.sdpf.value = sdpf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.kdf.value = kdf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.adipf.value = adipf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.drudpf.value = drudpf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.npcpf.value = npcpf2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.cpc.value = cpc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.solpc.value = solpc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.sdpc.value = sdpc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.kdc.value = kdc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.adipc.value = adipc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.drudpc.value = drudpc2.fmtF(6,3);\n');
win2.document.write('    window.opener.document.Myform.npcpc.value = npcpc2.fmtF(6,3);\n');
win2.document.write('    var p2 = new ToFmt((percct*1 / (percct*1+percft*1) * 100));\n');
win2.document.write('    var p3 = new ToFmt((percft*1 / (percct*1+percft*1) * 100));\n');
win2.document.write('    window.opener.document.Myform.ptdc.value = p2.fmtF(6,2);\n');
win2.document.write('     window.opener.document.Myform.ptdf.value = p3.fmtF(6,2);\n');
win2.document.write('     window.opener.document.Myform.mecc.value = mecf.fmtF(6,2);\n');
win2.document.write('     window.opener.document.Myform.mecf.value = meff.fmtF(6,2);\n');
win2.document.write('showhide("myObject1","block");\n');
win2.document.write('\n');
win2.document.write('    }\n');
win2.document.write('function regular(string) {\n');
win2.document.write('if (!string) return false;\n');
win2.document.write('var Chars = "0123456789.-";\n');
win2.document.write('\n');
win2.document.write('for (var i = 0; i < string.length; i++)\n');
win2.document.write('{ if (Chars.indexOf(string.charAt(i)) == -1)\n');
win2.document.write('return false;\n');
win2.document.write('}\n');
win2.document.write('return true;\n');
win2.document.write('} \n');
win2.document.write('function LTrim(str)\n');
win2.document.write('/*\n');
win2.document.write('   PURPOSE: Remove leading blanks from our string.\n');
win2.document.write('   IN: str - the string we want to LTrim\n');
win2.document.write('*/\n');
win2.document.write('{\n');
win2.document.write('   var whitespace = new String(" \\t\\n\\r");\n');
win2.document.write('\n');
win2.document.write('   var s = new String(str);\n');
win2.document.write('\n');
win2.document.write('   if (whitespace.indexOf(s.charAt(0)) != -1) {\n');
win2.document.write('      // We have a string with leading blank(s)...\n');
win2.document.write('\n');
win2.document.write('      var j=0, i = s.length;\n');
win2.document.write('\n');
win2.document.write('      // Iterate from the far left of string until we\n');
win2.document.write('      // don"t have any more whitespace...\n');
win2.document.write('      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)\n');
win2.document.write('         j++;\n');
win2.document.write('\n');
win2.document.write('      // Get the substring from the first non-whitespace\n');
win2.document.write('      // character to the end of the string...\n');
win2.document.write('      s = s.substring(j, i);\n');
win2.document.write('   }\n');
win2.document.write('   return s;\n');
win2.document.write('}\n');
win2.document.write('// JS Object: ToFmt \n');
win2.document.write('// Author: David Mosley, E-mail: David.Mosley@fundp.ac.be or davmos@fcmail.com\n');
win2.document.write('// August 1998.\n');
win2.document.write('// Contains a limited set of formatting routines for\n');
win2.document.write('// use in JavaScript scripts.\n');
win2.document.write('// Feel free to use this code in your scripts. I would be grateful if you\n');
win2.document.write('// could keep this header intact. \n');
win2.document.write('// Please let me know if you find the code useful.\n');
win2.document.write('// Please report any bugs you find or improvements you make to the script. \n');
win2.document.write('// The code has been tested, but no guarantee can be made of it functioning\n');
win2.document.write('// correctly. Use is entirely at your own risk.\n');
win2.document.write('// \n');
win2.document.write('// Summary of methods\n');
win2.document.write('// fmt00(): Tags leading zero onto numbers 0 - 9.\n');
win2.document.write('// Particularly useful for displaying results from Date methods.\n');
win2.document.write('//\n');
win2.document.write('// fmtF(w,d): formats in a style similar to Fortran"s Fw.d, where w is the\n');
win2.document.write('// width of the field and d is the number of figures after the decimal\n');
win2.document.write('// point. \n');
win2.document.write('// The result is aligned to the right of the field.  The default\n');
win2.document.write('// padding character is a space " ". This can be modified using the \n');
win2.document.write('// setSpacer(string) method of ToFmt. \n');
win2.document.write('// If the result will not fit in the field , the field will be returned\n');
win2.document.write('// containing w asterisks.\n');
win2.document.write('//\n');
win2.document.write('// fmtE(w,d): formats in a style similar to Fortran"s Ew.d, where w is the\n');
win2.document.write('// width of the field and d is the number of figures after the decimal\n');
win2.document.write('// point. \n');
win2.document.write('// The result is aligned to the right of the field.  The default\n');
win2.document.write('// padding character is a space " ". This can be modified using the \n');
win2.document.write('// setSpacer(string) method of ToFmt. \n');
win2.document.write('// If the result will not fit in the field , the field will be returned\n');
win2.document.write('// containing w asterisks.\n');
win2.document.write('//\n');
win2.document.write('// fmtI(w): formats in a style similar to Fortran"s Iw, where w is the\n');
win2.document.write('// width of the field.\n');
win2.document.write('// Floating point values are truncated (rounded down) for integer\n');
win2.document.write('// representation.\n');
win2.document.write('// The result is aligned to the right of the field.  The default\n');
win2.document.write('// padding character is a space " ". This can be modified using the \n');
win2.document.write('// setSpacer(string) method of ToFmt. \n');
win2.document.write('// If the result will not fit in the field , the field will be returned\n');
win2.document.write('// containing w asterisks.\n');
win2.document.write('\n');
win2.document.write('function ToFmt(x){\n');
win2.document.write(' this.x=x;\n');
win2.document.write(' this.fmt00 = fmt00;\n');
win2.document.write(' this.fmtF = fmtF;\n');
win2.document.write(' this.fmtE=fmtE;\n');
win2.document.write(' this.fmtI=fmtI;\n');
win2.document.write(' this.spacer=" ";\n');
win2.document.write(' this.setSpacer=setSpacer;\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function fmt00(){\n');
win2.document.write(' // fmt00: Tags leading zero onto numbers 0 - 9.\n');
win2.document.write(' // Particularly useful for displaying results from Date methods.\n');
win2.document.write(' //\n');
win2.document.write(' if (parseInt(this.x) < 0) var neg = true;\n');
win2.document.write(' if (Math.abs(parseInt(this.x)) < 10){\n');
win2.document.write('  this.x = "0"+ Math.abs(this.x);\n');
win2.document.write(' }\n');
win2.document.write(' if (neg) this.x = "-"+this.x;\n');
win2.document.write(' return this.x;\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function fmtF(w,d){\n');
win2.document.write('\n');
win2.document.write(' // fmtF: formats in a style similar to Fortran"s Fw.d, where w is the\n');
win2.document.write(' // width of the field and d is the number of figures after the decimal\n');
win2.document.write(' // point. \n');
win2.document.write(' // The result is aligned to the right of the field.  The default\n');
win2.document.write(' // padding character is a space " ". This can be modified using the \n');
win2.document.write(' // setSpacer(string) method of ToFmt. \n');
win2.document.write(' // If the result will not fit in the field , the field will be returned\n');
win2.document.write(' // containing w asterisks.\n');
win2.document.write(' var width=w;\n');
win2.document.write(' var dpls=d;\n');
win2.document.write(' var lt1=false;\n');
win2.document.write(' var len=this.x.toString().length;\n');
win2.document.write(' var junk;\n');
win2.document.write(' var res="";\n');
win2.document.write('// First check for valid format request\n');
win2.document.write(' if ( width < (dpls+2)){\n');
win2.document.write('  junk = filljunk(width);\n');
win2.document.write('  return junk;\n');
win2.document.write(' }\n');
win2.document.write('// Work with absolute value\n');
win2.document.write(' var absx=Math.abs(this.x);\n');
win2.document.write('// Nasty fix to deal with numbers < 1 and problems with leading zeros!\n');
win2.document.write(' if ((absx < 1) && (absx > 0)){\n');
win2.document.write('  lt1 = true;\n');
win2.document.write('  absx+=10;\n');
win2.document.write(' }\n');
win2.document.write('// Get postion of decimal point\n');
win2.document.write(' var pt_pos = absx.toString().indexOf(".");\n');
win2.document.write(' if ( pt_pos == -1){\n');
win2.document.write('  res+= absx;\n');
win2.document.write('  res+= ".";\n');
win2.document.write('  for (var i = 0; i < dpls; i++){\n');
win2.document.write('   res += 0;\n');
win2.document.write('  }  \n');
win2.document.write(' }\n');
win2.document.write(' else{\n');
win2.document.write('  res = Math.round(absx * Math.pow(10,dpls));\n');
win2.document.write('  res=res.toString();\n');
win2.document.write('  if (res.length == \n');
win2.document.write('      Math.round(Math.floor(absx * Math.pow(10,dpls))).toString().length){ \n');
win2.document.write('   res = res.substring(0,pt_pos) + "." + \n');
win2.document.write('         res.substring(pt_pos,res.length);\n');
win2.document.write('  }\n');
win2.document.write('  else{\n');
win2.document.write('   pt_pos++;\n');
win2.document.write('   res = res.substring(0,pt_pos) + "." + \n');
win2.document.write('          res.substring(pt_pos,res.length);\n');
win2.document.write('  } \n');
win2.document.write('// Remove leading 1 from  numbers < 1 (Nasty fix!)\n');
win2.document.write('  if (lt1) {\n');
win2.document.write('   res=res.substring(1,res.length);\n');
win2.document.write('  }\n');
win2.document.write(' }\n');
win2.document.write(' // Final formatting statements\n');
win2.document.write(' // Reinsert - sign for negative numbers\n');
win2.document.write(' if (this.x < 0)res = "-"+res;\n');
win2.document.write(' // Check whether the result fits in the width of the field specified\n');
win2.document.write(' if (res.length > width){\n');
win2.document.write('  res=filljunk(width);\n');
win2.document.write(' }\n');
win2.document.write(' // If necessary, pad from the left with the spacer string\n');
win2.document.write(' else if (res.length < width){\n');
win2.document.write('  var res_bl="";\n');
win2.document.write('  for (var i = 0; i < (width - res.length); i++){\n');
win2.document.write('   res_bl += this.spacer ;\n');
win2.document.write('  } \n');
win2.document.write('  res = res_bl + res;\n');
win2.document.write(' }\n');
win2.document.write(' return res;\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function fmtE(w,d){\n');
win2.document.write('\n');
win2.document.write(' // fmtE: formats in a style similar to Fortran"s Ew.d, where w is the\n');
win2.document.write(' // width of the field and d is the number of figures after the decimal\n');
win2.document.write(' // point. \n');
win2.document.write(' // The result is aligned to the right of the field.  The default\n');
win2.document.write(' // padding character is a space " ". This can be modified using the \n');
win2.document.write(' // setSpacer(string) method of ToFmt. \n');
win2.document.write(' // If the result will not fit in the field , the field will be returned\n');
win2.document.write(' // containing w asterisks.\n');
win2.document.write(' //\n');
win2.document.write(' var width=w;\n');
win2.document.write(' var dpls=d;\n');
win2.document.write(' var e="E+";\n');
win2.document.write(' var len=this.x.toString().length;\n');
win2.document.write(' var pow10;\n');
win2.document.write(' var xp10;\n');
win2.document.write(' var junk;\n');
win2.document.write(' var res="";\n');
win2.document.write('// First check for valid format request\n');
win2.document.write(' if ( width < (dpls+5)){\n');
win2.document.write('  junk = filljunk(w);\n');
win2.document.write('  return junk;\n');
win2.document.write(' }\n');
win2.document.write('// Work with absolute value\n');
win2.document.write(' var absx=Math.abs(this.x);\n');
win2.document.write('// Get postion of decimal point\n');
win2.document.write(' var pt_pos = absx.toString().indexOf(".");\n');
win2.document.write('// For x=0\n');
win2.document.write(' if (absx == 0){\n');
win2.document.write('  res +="0.";\n');
win2.document.write('  for (var i=0; i< dpls; i++){\n');
win2.document.write('   res += "0";\n');
win2.document.write('  }\n');
win2.document.write('  res  += "E+00";\n');
win2.document.write(' }\n');
win2.document.write('// For abs(x) >= 1 \n');
win2.document.write(' else if (absx >= 1.0){\n');
win2.document.write('  pow10=1;\n');
win2.document.write('  xp10 = absx;\n');
win2.document.write('  while (xp10 >= 1.){\n');
win2.document.write('   pow10++;\n');
win2.document.write('   xp10 /= 10;\n');
win2.document.write('  }\n');
win2.document.write('  res = Math.round(xp10 * Math.pow(10,dpls));\n');
win2.document.write('  res=res.toString();\n');
win2.document.write('  if (res.length == \n');
win2.document.write('      Math.round(Math.floor(xp10 * Math.pow(10,dpls))).toString().length){ \n');
win2.document.write('    pow10--;\n');
win2.document.write('  }\n');
win2.document.write('  res = "0." + res.substring(0,dpls) + e + (new ToFmt(pow10)).fmt00();\n');
win2.document.write(' }\n');
win2.document.write('// For abs(x) < 1\n');
win2.document.write(' else if (absx < 1.0){\n');
win2.document.write('  pow10=1;\n');
win2.document.write('  xp10 = absx;\n');
win2.document.write('  while (xp10 < 1.){\n');
win2.document.write('   pow10--;\n');
win2.document.write('   xp10 *= 10;\n');
win2.document.write('  }\n');
win2.document.write('  res = Math.round(xp10/10 * Math.pow(10,dpls));\n');
win2.document.write('  res=res.toString();\n');
win2.document.write('  if (res.length != \n');
win2.document.write('      Math.round(Math.floor(xp10/10 * Math.pow(10,dpls))).toString().length){ \n');
win2.document.write('    pow10++;\n');
win2.document.write('  }\n');
win2.document.write('  if (pow10 < 0) e = "E-";\n');
win2.document.write('  res = "0." + res.substring(0,dpls) + e + (new ToFmt(Math.abs(pow10))).fmt00();\n');
win2.document.write(' }\n');
win2.document.write(' \n');
win2.document.write(' if (this.x < 0)res = "-"+res;\n');
win2.document.write(' if (res.length > width){\n');
win2.document.write('  res=filljunk(width);\n');
win2.document.write(' }\n');
win2.document.write(' else if (res.length < width){\n');
win2.document.write('  var res_bl="";\n');
win2.document.write('  for (var i = 0; i < (width - res.length); i++){\n');
win2.document.write('   res_bl += this.spacer ;\n');
win2.document.write('  } \n');
win2.document.write('  res = res_bl + res;\n');
win2.document.write(' }\n');
win2.document.write(' return res;\n');
win2.document.write(' \n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function fmtI(w){\n');
win2.document.write('\n');
win2.document.write(' // fmtI: formats in a style similar to Fortran"s Iw, where w is the\n');
win2.document.write(' // width of the field.\n');
win2.document.write(' // Floating point values are truncated (rounded down) for integer\n');
win2.document.write(' // representation.\n');
win2.document.write(' // The result is aligned to the right of the field.  The default\n');
win2.document.write(' // padding character is a space " ". This can be modified using the \n');
win2.document.write(' // setSpacer(string) method of ToFmt. \n');
win2.document.write(' // If the result will not fit in the field , the field will be returned\n');
win2.document.write(' // containing w asterisks.\n');
win2.document.write(' var width=w;\n');
win2.document.write(' var lt0=false;\n');
win2.document.write(' var len=this.x.toString().length;\n');
win2.document.write(' var junk;\n');
win2.document.write(' var res="";\n');
win2.document.write('// Work with absolute value\n');
win2.document.write(' var absx = Math.abs(this.x);\n');
win2.document.write('\n');
win2.document.write('// Test for < 0\n');
win2.document.write(' if (parseInt(this.x) < 0){\n');
win2.document.write('  lt0 = true;\n');
win2.document.write(' }\n');
win2.document.write(' res = Math.round(Math.floor((absx))).toString();\n');
win2.document.write(' if (lt0){\n');
win2.document.write('  res = "-"+res;\n');
win2.document.write(' }\n');
win2.document.write(' if (res.length > width){\n');
win2.document.write('  res=filljunk(width);\n');
win2.document.write(' }\n');
win2.document.write(' else if (res.length < width){\n');
win2.document.write('  var res_bl="";\n');
win2.document.write('  for (var i = 0; i < (width - res.length); i++){\n');
win2.document.write('   res_bl += this.spacer ;\n');
win2.document.write('  } \n');
win2.document.write('  res = res_bl + res;\n');
win2.document.write(' }\n');
win2.document.write(' return res;\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function filljunk(lenf){\n');
win2.document.write(' // Fills field of length lenf with asterisks\n');
win2.document.write(' var str="";\n');
win2.document.write(' for (var i=0; i < lenf; i++){\n');
win2.document.write('  str +="*";\n');
win2.document.write(' }\n');
win2.document.write(' return str;\n');
win2.document.write('}\n');
win2.document.write('\n');
win2.document.write('function setSpacer(spc){\n');
win2.document.write(' var spc;\n');
win2.document.write(' this.spacer=spc;\n');
win2.document.write(' return this.spacer;\n');
win2.document.write('}   \n');


win2.document.write('</SCRIPT>\n');
win2.document.write('</head>\n');
win2.document.write('<body onLoad="showhide(\'myObject1\',\'none\')">\n');
win2.document.write('<FORM name=Myform method=post>\n');
win2.document.write('<h2>The ME and CP values for the feed ingredients that you have chosen are listed in the table.  You may change them, if needed.</h2>\n');
win2.document.write('<table cellspacing="0" cellpadding="2" border="1" width="100%">\n'); 
win2.document.write('<tr><th>Feed Ingredient</th><th>Dietary percentage (DM basis)</th><th>ME (MJ/kg DM)</th><th>CP (% DM)</th></tr>\n'); 
for (var i=0; i < j; i++)   {
   for (var ii=0; ii < feedstuffs.length; ii++) {
   if (checkedValue[i] == feedstuffs[ii][0]) {
   win2.document.write('<tr><td width="50%"><input type="hidden" name=hidden'+i+' value="'+checkedValue[i]+'">');
//   win2.document.write('<tr><td>');
   win2.document.write(feedstuffs[ii][1]);
   win2.document.write('</td><td align="center"><INPUT maxLength=6 onchange="if (!regular(this.value)) alert(\'Not a valid number.  Please enter a numeric value.\')" size=10 name=per'+i+' tabindex='+(i+1)+'></td>\n');
   win2.document.write('<td align="center"><INPUT maxLength=6 onchange="if (!regular(this.value)) alert(\'Not a valid number.  Please enter a numeric value.\')" size=10 name=me'+i+' value="'+feedstuffs[ii][9]+'" align=center tabindex='+(i+5)+'></td>\n');
   win2.document.write('<td align="center"><INPUT maxLength=6 onchange="if (!regular(this.value)) alert(\'Not a valid number.  Please enter a numeric value.\')" size=10 name=cp'+i+' value="'+feedstuffs[ii][2]*100+'" align=center tabindex='+(i+9)+'></td></tr>\n');
//win2.document.write('</tr>\n');
   }
   }
}
win2.document.write('</table>\n');
win2.document.write('<CENTER><INPUT onclick=calc3() type=button value="Calculate Total Diet Composition Values">&nbsp;&nbsp;&nbsp;&nbsp;<INPUT type=reset value=Reset name=reset> <p>\n');
win2.document.write('<div id="myObject1">');
win2.document.write('<p>Your Feed Ingredient Properties have been loaded into the calculator, please close this window and continue with calculations.');
win2.document.write('<P align="center"><INPUT onclick=window.close() type=button value="Close Window"></p>\n');
win2.document.write('<input type="hidden" name=j value="'+j+'"></div>');
win2.document.write('</center></FORM>\n');
win2.document.write('</body>\n');
win2.document.write('</html>');
win2.document.close();
}

function openWin1( windowURL, windowName, windowFeatures ) {
   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 condmf = new ToFmt(document.Myform.condm.value*.454);
if (document.Myform.condm.value != "") {document.Myform.dmi.value=condmf.fmtF(6,1);}
//    else {document.Myform.dmi.value="";}
      }

function convert2() {
      var conmjf = new ToFmt(document.Myform.contdn.value*15.104/100);
//	  conmjf = conmjf-1.8749;
      document.Myform.textmj.value=conmjf.fmtF(6,2);
      var conmcf = new ToFmt(document.Myform.contdn.value*3.61/100);
//	  conmcf = conmcf-0.45998;
      document.Myform.textmc.value=conmcf.fmtF(6,2);

      }

function calc() {
      bw = document.Myform.bw.value;
      cpc = document.Myform.cpc.value;
      solpc = document.Myform.solpc.value;
      sdpc = document.Myform.sdpc.value;
      kdc = document.Myform.kdc.value;
      adipc = document.Myform.adipc.value;
      drudpc = document.Myform.drudpc.value;
      npcpc = document.Myform.npcpc.value;
      cpf = document.Myform.cpf.value;
      solpf = document.Myform.solpf.value;
      sdpf = document.Myform.sdpf.value;
      kdf = document.Myform.kdf.value;
      adipf = document.Myform.adipf.value;
      drudpf = document.Myform.drudpf.value;
      npcpf = document.Myform.npcpf.value;
      dmi = document.Myform.dmi.value;
      ptdc = document.Myform.ptdc.value;
      mecc = document.Myform.mecc.value;
      ptdf = document.Myform.ptdf.value;
      mecc = document.Myform.mecc.value;
      mecf = document.Myform.mecf.value;

mec = ((ptdc / 100) * mecc) + ((ptdf / 100) * mecf);
cp = (((ptdc  /100) * cpc) + ((ptdf / 100) * cpf))*dmi;
solp = (((ptdc  /100) * solpc) + ((ptdf / 100) * solpf))*cp;
sdp = (((ptdc  /100) * sdpc) + ((ptdf / 100) * sdpf))*cp;
kd = ((ptdc  /100) * kdc) + ((ptdf / 100) * kdf);
adip = (((ptdc  /100) * adipc) + ((ptdf / 100) * adipf))*cp;
drudp = (((ptdc  /100) * drudpc) + ((ptdf / 100) * drudpf))*cp;
npcp = (((ptdc  /100) * npcpc) + ((ptdf / 100) * npcpf))*solp;
soltp = solp - npcp;
solnp = npcp;
dmic = dmi * (ptdc / 100);
dmif = dmi * (ptdf / 100);
mei = dmi * mec;
km = 0.503 + (0.019 * mec);
mbw = Math.pow(bw,.75);
mem = (mbw * 0.315) / km;
l = mei / mem;
kp = -0.024 + (0.179 * (1 - (Math.exp(-0.278 * l))));
kl = (kp - 0.0018) / 0.360;
exsoltp = soltp * (0.084 / (0.084 + kl));
exsdp = sdp * (kd / (kd + kp));
udsoltp = soltp - exsoltp;
udsdp = sdp - exsdp;
ruddp = drudp;
rudp = udsoltp + udsdp + ruddp;
dudp = rudp * 0.9;
erdp = (0.8 * solnp) + (0.8 * exsoltp) + exsdp;
rfec = dmic * mecc * 0.926;
rfef = dmif * mecf * 0.820;
rfe = rfec + rfef;
micpg = (7 + (6 * (1 - (Math.exp(-0.35 * l))))) * rfe;
micpkg = micpg / 1000;
micp = micpkg;
if (micpkg > erdp) {micp = erdp;}
dmtp = micp * 0.6375;
mpi = dudp + dmtp;
mpi2 = mpi*1000;
mpipt = (mpi / dmi) * 100;
  
      var mpif = new ToFmt(mpi2);
      var mpiptf = new ToFmt(mpipt);

      document.Myform.text1.value=mpif.fmtF(6,1)+"  g";
      document.Myform.text2.value=mpiptf.fmtF(6,2)+"  %";
    }
    
function Printable() {
var win1 = window.open('', 'Printable');
win1.document.open('text/html');
win1.document.write('<html>\n')
win1.document.write('<head><title>Metabolizable Protein (MP) Intake Based on Estimates of Ruminally Undegraded Protein (UIP) and Microbial Protein Synthesis</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>');
win1.document.write('<p class="first-line">Metabolizable Protein (MP) Intake Based on Estimates of Ruminally Undegraded Protein (UIP) and Microbial Protein Synthesis</p>\n');
//win1.document.write('<P class=full>(Meat, Dairy, And Indigenous; &le;1.5 Years Of Age)</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%">Body weight</td><td colspan=2 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><td>&nbsp;</td><td align=center>Concentrate</td><td align=center>Forage</td></tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Total dietary CP concentration</td><td align="center">');
win1.document.write(document.Myform.cpc.value);
win1.document.write(' % DM</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.cpf.value);
win1.document.write(' % DM</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Soluble CP</td><td align="center">');
win1.document.write(document.Myform.solpc.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.solpf.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Intact protein slowly degradable in the rumen</td><td align="center">');
win1.document.write(document.Myform.sdpc.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.sdpf.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Rate of degradation of SDP</td><td align="center">');
win1.document.write(document.Myform.kdc.value);
win1.document.write(' /hour</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.kdf.value);
win1.document.write(' /hour</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Acid detergent insoluble CP</td><td align="center">');
win1.document.write(document.Myform.adipc.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.adipf.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Ruminally undegraded but intestinally digestible protein</td><td align="center">');
win1.document.write(document.Myform.drudpc.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.drudpf.value);
win1.document.write(' g/g total CP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Non-protein CP</td><td align="center">');
win1.document.write(document.Myform.npcpc.value);
win1.document.write(' g/g SolP</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.npcpf.value);
win1.document.write(' g/g SolP</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DM intake</td><td colspan=2 align="center">');
win1.document.write(document.Myform.dmi.value);
win1.document.write(' kg (');
      var dmip = new ToFmt((document.Myform.dmi.value)/.454);
win1.document.write(LTrim(dmip.fmtF(6,1)));
win1.document.write(' lbs)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Percentage of concentrate/forage in the diet</td><td align="center">');
win1.document.write(document.Myform.ptdc.value);
win1.document.write('% (DM basis)</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.ptdf.value);
win1.document.write('% (DM basis)</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">ME concentration in concentrate/forage</td><td align="center">');
win1.document.write(document.Myform.mecc.value);
win1.document.write(' MJ/kg</td>');
win1.document.write('<td align="center">');
win1.document.write(document.Myform.mecf.value);
win1.document.write(' MJ/kg</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%">MP intake</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%">MP intake (% DM)</td><td align="center">');
win1.document.write(document.Myform.text2.value);
win1.document.write('</td>');
win1.document.write('</tr>')
win1.document.write('</table>');
win1.document.write('</body>\n')
win1.document.write('</html>')
win1.document.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;
}   
