<!--
// 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;
}

// -->

<!--
// Fenix Calculator by Jason Hitesman for MGM Internet Solutions for Fenix Technology
// Copyright June 2000
// This script requires the use of the ToFmt() object by David Mosley

// First we define functions used to calculate the various values necessary
// All of these functions follow the convention of a single indent representing
// normal calculations done within the function, and a double indent being
// used to show calculations done to prepare for the final calculation.
// Each function represents one formula as provided by Fenix

//Find the value for K<SUB>0</SUB>
function findK0(Fp, Gt, Al, B) {
		var tmp=Fp/Gt;
		var rside=Math.pow(tmp,(1/5));
		var lside=(Al*25.4)/B;
	K0=1.28*lside*rside;
	return K0
}

// Find the value for C
function findC ( A, K0, Pw, Pe) {
		var ac=Math.pow(A,4);
		var kc=Math.pow(K0,4);
		var T=Pw/3;
		var Ts=Math.pow(T,2);
		var tmp=(2*Pe*ac*Ts)/(kc);
	var C=Math.pow(tmp,(1/3))*100;
	return C;
}

// Find the value for L
function findL (Pw, C) {
		var T=Pw/3;
		var Ts=Math.pow(T,2);
	var L=Ts/C;
	return L;
}

// Find the value for V
function findV (Pe,C) {
		var tmp=((2*Pe)/(C));
	var V=Math.pow(tmp,(1/2))*1000;
	return V;
}
	
// Find the value for PCA
function findPCA (L,C,V) {
		var tmp=L/C;
	var PCA=V/(2*(Math.pow(tmp,(1/2))));
	return PCA;
}


// Find the value for RMS
function findRMS (Pw,Rr,PCA) {
		var tmp=((Pw*Rr)/1000000);
	var RMS=.703*PCA*(Math.pow(tmp,(1/2)));
	return RMS;
}

// Find the value for Alpha
function findA (L,C,K0,V) {
		var Z=Math.sqrt((L/C));
		var tmp=Math.pow((V*Z),(1/2));
	var A=K0/tmp;
	return A;
}

// Find the value for Pe
function findPe (C,V) {
//	alert("C as passed = " + C);
	C=C*(Math.pow(10,-6));
//	alert("C*10^-6 = " + C);
	var tmp=Math.pow((V),2);
//	alert("tmp = " + tmp);
	var Pe=.5*tmp*C;
//	alert("Pe to return =" + Pe);
	return Pe;
}


// Find the value for Wl
function findWl (Pe,Rr,Al,B) {
		var tmp=Al*2.54*B*(3.14159/10);
		var tmp2=Pe*Rr;
	var Wl=tmp2/tmp;
	return Wl;
}

// Find the value for Pee
function findPee (Pe,B,Al,Pw) {
		var tmp1=Math.pow((Pw),(1/2));
		var tmp2=3.64*B*Al*tmp1;
		var tmp3=Pe/tmp2;
	var Pee=100*tmp3;
	return Pee;
}

function doReset() {
	window.document.fenix_calc.B.value=4;
	window.document.fenix_calc.Al.value=3;
	window.document.fenix_calc.Gt.selectedIndex=1;
	window.document.fenix_calc.Pe.value=120;
	window.document.fenix_calc.Pw.value=300;
	window.document.fenix_calc.Rr.value=10;
	window.document.fenix_calc.A.value=0.8;
	window.document.fenix_calc.Fp.value=450;	
	window.document.fenix_calc.Wl.value=125.32;
	window.document.fenix_calc.Pee.value=16;
	docalcs();
}


// docalcs is called when one of the main input values is changed.  
// doCalcs() will find the values for K0,C,L,V,PCA, and RMS then
// place the formatted results into the proper form fields on the page.
// we format to 2 decimal places with 8 characters total including the decimal point.
function docalcs() {
 if ((document.domain=="www.fenixtechnology.com") || (document.domain=="fenixtechnology.com") || (document.domain=="dunetrader.com") || (document.domain=="www.dunetrader.com")) {
	var the_select = window.document.fenix_calc.Gt;
	var the_index = the_select.selectedIndex;
	var Gt_value = the_select.options[the_index].value;

	var K0_formatted = new ToFmt(findK0(window.document.fenix_calc.Fp.value,Gt_value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.K0.value=K0_formatted.fmtF(8,2);

	var C_formatted = new ToFmt(findC(window.document.fenix_calc.A.value,window.document.fenix_calc.K0.value,window.document.fenix_calc.Pw.value,window.document.fenix_calc.Pe.value));
	window.document.fenix_calc.C.value=C_formatted.fmtF(8,2);

	var L_formatted = new ToFmt(findL(window.document.fenix_calc.Pw.value,window.document.fenix_calc.C.value));
	window.document.fenix_calc.L.value=L_formatted.fmtF(8,2);

	var V_formatted = new ToFmt(findV(window.document.fenix_calc.Pe.value,window.document.fenix_calc.C.value));
	window.document.fenix_calc.V.value=V_formatted.fmtF(8,2);

	var tmp_C = window.document.fenix_calc.C.value;
	var Pe_formatted= new ToFmt(findPe(tmp_C,window.document.fenix_calc.V.value));
	window.document.fenix_calc.Pe.value=Pe_formatted.fmtF(8,2);

	var PCA_formatted = new ToFmt(findPCA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.PCA.value=PCA_formatted.fmtF(8,2);

	var RMS_formatted = new ToFmt(findRMS(window.document.fenix_calc.Pw.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.PCA.value));
	window.document.fenix_calc.RMS.value=RMS_formatted.fmtF(8,2);

	var A_formatted= new ToFmt(findA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.K0.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.A.value=A_formatted.fmtF(8,2);
	
	var Wl_formatted= new ToFmt(findWl(window.document.fenix_calc.Pe.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.Wl.value=Wl_formatted.fmtF(8,2);
	
	var Pee_formatted= new ToFmt(findPee(window.document.fenix_calc.Pe.value,window.document.fenix_calc.B.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.Pw.value));
	window.document.fenix_calc.Pee.value=Pee_formatted.fmtF(6,2);

	}
	else {alert("Sorry, you must go to http://www.fenixtechnology.com for this page to work");}
}


// newC() finds the values for L,V,PCA, and RMS when a user inputs their own value for C, these values 
// are then formatted and placed into the proper form fields.
function newC() {
	var the_select = window.document.fenix_calc.Gt;
	var the_index = the_select.selectedIndex;
	var Gt_value = the_select.options[the_index].value;
	
	var K0_formatted = new ToFmt(findK0(window.document.fenix_calc.Fp.value,Gt_value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.K0.value=K0_formatted.fmtF(8,2);

	var L_formatted = new ToFmt(findL(window.document.fenix_calc.Pw.value,window.document.fenix_calc.C.value));
	window.document.fenix_calc.L.value=L_formatted.fmtF(8,2);

	var V_formatted = new ToFmt(findV(window.document.fenix_calc.Pe.value,window.document.fenix_calc.C.value));
	window.document.fenix_calc.V.value=V_formatted.fmtF(8,2);

	var Pe_formatted= new ToFmt(findPe(window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.Pe.value=Pe_formatted.fmtF(8,2);

	var PCA_formatted = new ToFmt(findPCA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.PCA.value=PCA_formatted.fmtF(8,2);

	var RMS_formatted = new ToFmt(findRMS(window.document.fenix_calc.Pw.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.PCA.value));
	window.document.fenix_calc.RMS.value=RMS_formatted.fmtF(8,2);

	var A_formatted= new ToFmt(findA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.K0.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.A.value=A_formatted.fmtF(8,2);

	var Wl_formatted= new ToFmt(findWl(window.document.fenix_calc.Pe.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.Wl.value=Wl_formatted.fmtF(8,2);
	
	var Pee_formatted= new ToFmt(findPee(window.document.fenix_calc.Pe.value,window.document.fenix_calc.B.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.Pw.value));
	window.document.fenix_calc.Pee.value=Pee_formatted.fmtF(6,2);

}

// newL finds the values for V,PCA, and RMS when a user inputs their own value for L, these values 
// are then formatted and placed into the proper form fields.
function newL() {
	var the_select = window.document.fenix_calc.Gt;
	var the_index = the_select.selectedIndex;
	var Gt_value = the_select.options[the_index].value;

	var K0_formatted = new ToFmt(findK0(window.document.fenix_calc.Fp.value,Gt_value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.K0.value=K0_formatted.fmtF(8,2);

	var V_formatted = new ToFmt(findV(window.document.fenix_calc.Pe.value,window.document.fenix_calc.C.value));
	window.document.fenix_calc.V.value=V_formatted.fmtF(8,2);

	var Pe_formatted= new ToFmt(findPe(window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.Pe.value=Pe_formatted.fmtF(8,2);

	var PCA_formatted = new ToFmt(findPCA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.PCA.value=PCA_formatted.fmtF(8,2);

	var RMS_formatted = new ToFmt(findRMS(window.document.fenix_calc.Pw.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.PCA.value));
	window.document.fenix_calc.RMS.value=RMS_formatted.fmtF(8,2);

	var A_formatted= new ToFmt(findA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.K0.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.A.value=A_formatted.fmtF(8,2);

	var Wl_formatted= new ToFmt(findWl(window.document.fenix_calc.Pe.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.Wl.value=Wl_formatted.fmtF(8,2);
	
	var Pee_formatted= new ToFmt(findPee(window.document.fenix_calc.Pe.value,window.document.fenix_calc.B.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.Pw.value));
	window.document.fenix_calc.Pee.value=Pee_formatted.fmtF(6,2);

}

// newV finds the values for PCA and RMS when a user inputs their own value for V, these values 
// are then formatted and placed into the proper form fields.
function newV() {
	var the_select = window.document.fenix_calc.Gt;
	var the_index = the_select.selectedIndex;
	var Gt_value = the_select.options[the_index].value;

	var K0_formatted = new ToFmt(findK0(window.document.fenix_calc.Fp.value,Gt_value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.K0.value=K0_formatted.fmtF(8,2);

	var Pe_formatted= new ToFmt(findPe(window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.Pe.value=Pe_formatted.fmtF(8,2);

	var PCA_formatted = new ToFmt(findPCA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.PCA.value=PCA_formatted.fmtF(8,2);

	var RMS_formatted = new ToFmt(findRMS(window.document.fenix_calc.Pw.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.PCA.value));
	window.document.fenix_calc.RMS.value=RMS_formatted.fmtF(8,2);

	var A_formatted= new ToFmt(findA(window.document.fenix_calc.L.value,window.document.fenix_calc.C.value,window.document.fenix_calc.K0.value,window.document.fenix_calc.V.value));
	window.document.fenix_calc.A.value=A_formatted.fmtF(8,2);

	var Wl_formatted= new ToFmt(findWl(window.document.fenix_calc.Pe.value,window.document.fenix_calc.Rr.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.B.value));
	window.document.fenix_calc.Wl.value=Wl_formatted.fmtF(8,2);
	
	var Pee_formatted= new ToFmt(findPee(window.document.fenix_calc.Pe.value,window.document.fenix_calc.B.value,window.document.fenix_calc.Al.value,window.document.fenix_calc.Pw.value));
	window.document.fenix_calc.Pee.value=Pee_formatted.fmtF(6,2);

}
//-->