//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 showhide2(mylayer_ref1,hide) { 

if (hide == 1) {var state2 = 'block'; }
else {var state2 = 'none'; }
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + mylayer_ref1 + ".style.display = state2"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[mylayer_ref1].display = state2; 
} 
if (document.getElementById &&!document.all) { 
hza1 = document.getElementById(mylayer_ref1); 
hza1.style.display = state2; 
} 
} 

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 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() {
      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);
      document.Myform.mec.value=conmjf.fmtF(6,2);
      document.Myform.mec.value=conmjf.fmtF(6,2);

      }


function calc() {
      for (var i=0; i < document.Myform.sex.length; i++ )
      {
        if (document.Myform.sex[i].checked) {
           var gen = document.Myform.sex[i].value;}
      }
      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) && (gen == 1)) {
          memreq = 0.4227;
          }
      if ((bio == 1) && (gen == 2)) {
          memreq = (0.4227*1.15);
          }
      if ((bio == 2) && (gen == 1)) {
          memreq = 0.5013;
          }
      if ((bio == 2) && (gen == 2)) {
          memreq = (0.5013*1.15);
          }
      if ((bio == 3) && (gen == 1)) {
          memreq = 0.4227;
          }
      if ((bio == 3) && (gen == 2)) {
          memreq = (0.4227*1.15);
          }
      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;}
      grazf = document.Myform.grazf.value;
      bcsadjf = document.Myform.bcsadjf.value;
      gestme = document.Myform.gestme.value;
      accadjf = document.Myform.accadjf.value;
      condmi = document.Myform.condmi.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);
      memu = mbw*memreq*grazf*bcsadjf+accadjf/1;
      meg = adgp*megreq;
      met = adgn * 0.0239;
      km = 0.503 + (0.019 * mec);
      mem = memu - (met / km);
      metot = (mem+meg); 
      metot2 = metot + gestme/1;
      dmi = metot2/mec;
      dmilb = dmi/.454;
      dmibw = (dmi/bw) * 100;

    
      var memf = new ToFmt(mem);
      var memuf = new ToFmt(memu);
      var megf = new ToFmt(meg);
      var metf = new ToFmt(metot);
      var dmif = new ToFmt(dmi);
      var dmilbf = new ToFmt(dmilb);
      var dmibwf = new ToFmt(dmibw);		
      var dmibwf = new ToFmt(dmibw);	
      var gestmef = new ToFmt(gestme);
      var metot2f = new ToFmt(metot2);

      document.Myform.text1.value=memf.fmtF(8,2)+"  MJ";
      document.Myform.text1a.value=memuf.fmtF(8,2)+"  MJ";
      document.Myform.text2.value=megf.fmtF(8,2)+"  MJ";
      document.Myform.text3.value=metf.fmtF(8,2)+"  MJ";
      document.Myform.text3a.value=gestmef.fmtF(8,2)+"  MJ";
      document.Myform.text3b.value=metot2f.fmtF(8,2)+"  MJ";
	  document.Myform.text5.value=dmif.fmtF(8,2)+"  kg ("+LTrim(dmilbf.fmtF(8,2))+"  lbs)";
	  document.Myform.text6.value=dmibwf.fmtF(8,2)+"  %";

      dmibw2 = (dmi/condmi/bw) * 100;
      var dmi2f = new ToFmt(dmi/condmi);
      var dmilb2f = new ToFmt(dmilb/condmi);
      var dmibw2f = new ToFmt(dmibw2);
	  document.Myform.text7.value=dmi2f.fmtF(8,2)+"  kg ("+LTrim(dmilb2f.fmtF(8,2))+"  lbs)";
	  document.Myform.text8.value=dmibw2f.fmtF(8,2)+"  %";


document.cookie = "Enabled=true";
   var cookieValid = document.cookie;

   if (cookieValid.indexOf("Enabled=true") != -1)
   {
      cookiesEnabled = true;
   }
   else
   {
      cookiesEnabled = false;
   }

if(cookiesEnabled) {
expireDate = new Date;
expireDate.setMonth(expireDate.getMonth()+12);
var MEValues = "";

MEValues += "&"+"me3"+":"+"Mature Goats";
MEValues += ":"+bio;
MEValues += ":"+gen;
MEValues += ":"+bw;
MEValues += ":"+adg;
MEValues += ":"+mec;
MEValues += ":"+grazf;
MEValues += ":"+bcsadjf;
MEValues += ":"+accadjf;      
MEValues += ":"+mem;
MEValues += ":"+memu;
MEValues += ":"+meg;
MEValues += ":"+metot2;
MEValues += ":"+metot;
MEValues += ":"+gestme;
MEValues += ":"+document.Myform.hidden1.value;
MEValues += ":"+document.Myform.hidden2.value;
MEValues += ":"+document.Myform.hidden3.value;

document.cookie = "ME_Values="+MEValues+";expires="+expireDate.toGMTString();
if (MEValues == "") {document.cookie = "ME_Values="+MEValues+"; expires=Fri, 02-Jan-1970 00:00:00 GMT";}
}

if (window.opener && window.opener.location == "http://www2.luresext.edu/goats/research/rationbalancer.htm") { 
if (confirm("Your values have been saved for use in the \"Total Mixed Ration Calculator\".\n\nIf you are ready to return to the \"Total Mixed Ration Calculator\", then click \"OK\" to close this window.\n\nIf you would like to linger in this calculator, then click \"Cancel\".  You will have to manually close this window to return to the \"Total Mixed Ration Calculator\".")) {window.close();}
}

//if (window.opener && window.opener.location == "http://www2.luresext.edu/goats/research/rationbalancer.htm") {window.close();}
    }

function Printable() {
var win1 = window.open('', 'Printable');
win1.document.open('text/html');
win1.document.write('<html>\n')
win1.document.write('<head><title>Metabolizable Energy (ME) Requirement For Mature 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>');win1.document.write('<p class=first-line>Metabolizable Energy (ME) Requirement For Mature Goats</p>\n');
win1.document.write('<P class=full>(Meat, Dairy, And Indigenous; &gt; 1.5 Years Of Age; Non-lactating And Lactating)</P>\n');
win1.document.write('<h3>INPUTS</h3>\n');
for (var i=0; i < document.Myform.sex.length; i++ )
      {
        if (document.Myform.sex[i].checked) {
           var gen = document.Myform.sex[i].value;}
      }
      for (var i=0; i < document.Myform.bio.length; i++ )
      {
        if (document.Myform.bio[i].checked) {
           var bio = document.Myform.bio[i].value;}
      }
win1.document.write('<table cellspacing="0" cellpadding="2" border="1" width="100%">');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Biotype</td>');
if (bio == 1) {win1.document.write('<td align="center">meat, 50% or more Boer</td>');}
else if (bio == 2) {win1.document.write('<td align="center">dairy</td>');} 
else {win1.document.write('<td align="center">indigenous or local</td>');}
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Gender</td>');
if (gen == 1) {win1.document.write('<td align="center">female or wether</td>');}
else {win1.document.write('<td align="center">intact male</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%">Dietary ME concentration (Dietary 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%">Grazing factor</td><td align="center">');
win1.document.write(document.Myform.grazf.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Body condition score factor</td><td align="center">');
win1.document.write(document.Myform.bcsadjf.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Acclimatization factor</td><td align="center">');
win1.document.write(document.Myform.accadjf.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Gestation energy requirement</td><td align="center">');
win1.document.write(document.Myform.gestme.value+' MJ');
win1.document.write('<br>based on:<br>'+document.Myform.hidden1.value+' kg birth weight (');
var birwtp = new ToFmt((document.Myform.hidden1.value)/.454);
win1.document.write(birwtp.fmtF(6,1)+' lbs), ');
win1.document.write(' day of gestation = '+document.Myform.hidden2.value+', litter size = '+document.Myform.hidden3.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">DM in diet</td><td align="center">');
win1.document.write(document.Myform.condmi.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%">ME requirement for maintenance</td><td align="center">');
win1.document.write(document.Myform.text1a.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Dietary ME used for maintenance</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%">ME requirement for gain</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%">Dietary ME used for maintenance and gain</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%">ME requirement for gestation (MJ)</td><td align="center">');
win1.document.write(document.Myform.text3a.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Total ME requirement</td><td align="center">');
win1.document.write(document.Myform.text3b.value);
win1.document.write('</td>');
win1.document.write('</tr>');
win1.document.write('<tr>');
win1.document.write('<td width="50%">Dry matter intake for dietary ME requirement</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%">Dry matter intake for dietary ME requirement (% body weight)</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 intake for dietary ME requirement</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%">As fed intake for dietary ME requirement (% body weight)</td><td align="center">');
win1.document.write(document.Myform.text8.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();

}
    
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;
}   
