// Length conversion
var isn01 = new Object();
isn01[0] = "~01~10.3937~20.03281~30.01094~40.01~50.0004971~60.00001~70.000006214~80.0000053996~9";
isn01[1] = "~02.540~11~20.08333~30.02778~40.0254~50.001263~60.0000254~70.00001578~80.0000137149~9";
isn01[2] = "~030.48~112~21~30.3333~40.3048~50.01515~60.0003048~70.0001894~80.0001645787~9";
isn01[3] = "~091.44~136~23~31~40.9144~50.04545~60.0009144~70.0005682~80.00049373695~9";
isn01[4] = "~0100~139.37~23.281~31.0936~41~50.04971~60.001~70.0006214~80.0005399568~9";
isn01[5] = "~02012~1792~266~322~420.12~51~60.0212~70.0125~80.01349892~9";
isn01[6] = "~0100000~139370~23281~31093.6~41000~549.71~61~70.6214~80.5399568~9";
isn01[7] = "~0160934~163360~25280~31760~41609~580~61.609~71~80.8689758~9";
isn01[8] = "~0185200~172913.4~26076.12~32025.37~41852~574.08~61.852~71.15078~81~9";

function lenCon() {
  // First, get the variables checked by the user
  leni = document.isnform01.elements[1].selectedIndex;
  leninm = document.isnform01.elements[1].options[leni].text;

  leno = document.isnform01.elements[3].selectedIndex;
  lenonm = document.isnform01.elements[3].options[leno].text;

  // Now grab the number input by user and parse to be sure numeric
  if (document.isnform01.leninp.value=="")
    document.isnform01.leninp.value=1;
  useri = parseInt(document.isnform01.leninp.value,10);
  if (useri==0) 
	{
    useri = 1;
    document.isnform01.leninp.value = useri;
  }
  mulstr = isn01[leni];
  picker = "~" + leno;
  ps = mulstr.indexOf(picker);
  leno++;
  picker = "~" + leno;
  ps1 = mulstr.indexOf(picker);
  mulstr = mulstr.substring((ps + 2),ps1);
  ps = (document.isnform01.leninp.value * mulstr);
  picker = "";
  picker += ps
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
    // Correct for binary/floating point conversion error
    ps = ps + .000001;
    picker = "";
    picker += ps;
    ps2 = picker.indexOf("e");
    if (ps2 < 0) {
      picker = picker.substring(0,(ps1 + 6));
      }
    if (ps2 == 0 || ps2 > 0) {
      ps3 = picker.indexOf("00000");
      if (ps3 > 0) {
        picker = picker.substring(0,ps3 + 1) + picker.substring(ps2,picker.length);
        }
      }
    }
// only show 2 decimals
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
   picker = picker.substring(0,(ps1 + 3));
  }

  picker = document.isnform01.leninp.value + " " + leninm + " = " + picker + " " + lenonm
  document.isnform01.lenout.value = picker;
  }

// mass conversion
var isn06 = new Object();
isn06[0] = "~01~115432~232.15~335.27~42.6792~52.205~60.001102~70.0009842~80.001~9";
isn06[1] = "~06.48e-5~11~20.002083~30.002286~40.0001736~50.0001429~67.143e-8~76.378e-8~86.48e-8~9";
isn06[2] = "~00.0311~1480~21~31.09714~40.083333~50.06857~63.429e-5~73.061e-5~83.11e-5~9";
isn06[3] = "~00.02835~1437.5~20.9115~31~40.07595~50.0625~63.125e-5~72.79e-5~82.835e-5~9";
isn06[4] = "~00.3732~15760~212~313.17~41~50.8229~64.114e-4~73.673e-4~83.732e-4~9";
isn06[5] = "~00.4536~17000~214.58~316~41.215~51~60.0005~74.464e-4~84.536e-4~9";
isn06[6] = "~0907.2~114000000~229167~332000~42431~52000~61~70.8929~80.9072~9";
isn06[7] = "~01016~115680000~232667~335840~42722~52240~61.12~71~81.016~9";
isn06[8] = "~01000~115432356~232151~335274~42679~52205~61.102~70.9842~81~9";


function masCon() {
  // First, get the variables checked by the user
  masi = document.isnform06.elements[1].selectedIndex;
  masinm = document.isnform06.elements[1].options[masi].text;

  maso = document.isnform06.elements[3].selectedIndex;
  masonm = document.isnform06.elements[3].options[maso].text;

  // Now grab the numeric input by user and parse to be sure numeric
  if (document.isnform06.masinp.value=="")
    document.isnform06.masinp.value=1;
  useri = parseInt(document.isnform06.masinp.value,10);
  if (useri==0) {
    useri = 1;
    document.isnform06.masinp.value = useri;
    }
  mulstr = isn06[masi];
  picker = "~" + maso;
  ps = mulstr.indexOf(picker);
  maso++;
  picker = "~" + maso;
  ps1 = mulstr.indexOf(picker);
  mulstr = mulstr.substring((ps + 2),ps1);
  ps = (document.isnform06.masinp.value * mulstr);
  picker = "";
  picker += ps
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
    // Correct for binary/floating point conversion error
    ps = ps + .000001;
    picker = "";
    picker += ps;
    ps2 = picker.indexOf("e");
    if (ps2 < 0) {
      picker = picker.substring(0,(ps1 + 6));
      }
    if (ps2 == 0 || ps2 > 0) {
      ps3 = picker.indexOf("00000");
      if (ps3 > 0) {
        picker = picker.substring(0,ps3 + 1) + picker.substring(ps2,picker.length);
        }
      }
    }
// only show 2 decimals
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
   picker = picker.substring(0,(ps1 + 3));
  }


  picker = document.isnform06.masinp.value + " " + masinm + " = " + picker + " " + masonm
  document.isnform06.masout.value = picker;
  }

// temparature converter
function temCon() {
  // First, get the variables checked by the user
  temi = document.isnform07.elements[1].selectedIndex;
  teminm = document.isnform07.elements[1].options[temi].text;

  temo = document.isnform07.elements[3].selectedIndex;
  temonm = document.isnform07.elements[3].options[temo].text;

  // Now grab the numeric input by user and parse to be sure numeric
  if (document.isnform07.teminp.value=="")
    document.isnform07.teminp.value=1;
  useri = parseInt(document.isnform07.teminp.value,10);
  //if (useri==0) {
  //  useri = 1;
  //  document.isnform07.teminp.value = useri;
  //}
    
  if (teminm == "Celsius") {
    if (temonm == "Fahrenheit") {
       res = ((9/5) * document.isnform07.teminp.value + 32);
    }else if (temonm == "Kelvin") {
       res = (document.isnform07.teminp.value - 0 + 273.15);
    } else {
       res = (document.isnform07.teminp.value);
    }
  } else if (teminm == "Fahrenheit") {
     if (temonm == "Celsius") {
        res = (5/9) * (document.isnform07.teminp.value - 32);
     }else if (temonm == "Kelvin") {
        res = ((5/9) * (document.isnform07.teminp.value - 32)) + 273.15;
     } else {
        res = (document.isnform07.teminp.value);
     }
  } else if (teminm == "Kelvin") {
     if (temonm == "Celsius") {
        res = (document.isnform07.teminp.value - 273.15);
     }else if (temonm == "Fahrenheit") {
        res = ((9/5) * (document.isnform07.teminp.value - 273.15) + 32);
     } else {
        res = (document.isnform07.teminp.value);
     }
  }
  
  // only show 1 decimals
  picker = "";
  picker += res

  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
   picker = picker.substring(0,(ps1 + 3));
  }


  document.isnform07.temout.value = document.isnform07.teminp.value + " " + teminm + " = " + picker + " " + temonm;
}

function selman1() {
  temi = document.isnform07.elements[1].selectedIndex;
  
  if (temi == 0) {
    document.isnform07.elements[3].selectedIndex = 0;
  } else {
    document.isnform07.elements[3].selectedIndex = 1;
  }
}

function selman2() {
  temi = document.isnform07.elements[3].selectedIndex;
  
  if (temi == 0) {
    document.isnform07.elements[1].selectedIndex = 0;
  } else {
    document.isnform07.elements[1].selectedIndex = 1;
  }
}

function formreset(cform) {
  document.forms[cform].elements[3].selectedIndex = 0;
  document.forms[cform].elements[1].selectedIndex = 0;
  document.forms[cform].elements[0].value = "";
  document.forms[cform].elements[2].value = "";
}

// volume converter
var isn09 = new Object();
isn09[0] = "~01~10.0610234~20.000035319837041~30.000001309338584~40.000001~50.000000000000001~62.39946128344e-16~7";
isn09[1] = "~016.387064~11~20.578634262037~30.021438614952~40.000016387064~50.000000000000016387064~60.000000000000008~7";
isn09[2] = "~028316.846592~11728~21~30.037025927037~40.028316846592~50.000000000028316846592~60.000000000006859~7";
isn09[3] = "~0764554.857984~146656~227~31~40.764554857984~57.64554857984e-10~60.000000000185193~7";
isn09[4] = "~01000000~161023.842953251101~235.314670111696704~31.307938785012881~41~50.000000001~60.000000000157464~7";
isn09[5] = "~01000000000000000~161023842953251.101~235314670111.696704~31307938785.012881~41000000000~51~60.239912535909247811~7";
isn09[6] = "~04168150745660504~1254358061056000~2147197952000~35451776000~44168150745.660504~54.168150745660504~61~7";

function volumeCon() {
  // First, get the variables checked by the user
  voli = document.isnform09.elements[1].selectedIndex;
  volinm = document.isnform09.elements[1].options[voli].text;

  volo = document.isnform09.elements[3].selectedIndex;
  volonm = document.isnform09.elements[3].options[volo].text;

  // Now grab the number input by user and parse to be sure numeric
  if (document.isnform09.volinp.value=="")
    document.isnform09.volinp.value=1;
  useri = parseInt(document.isnform09.volinp.value,10);
  if (useri==0) {
    useri = 1;
    document.isnform09.volinp.value = useri;
    }
  mulstr = isn09[voli];
  picker = "~" + volo;
  ps = mulstr.indexOf(picker);
  volo++;
  picker = "~" + volo;
  ps1 = mulstr.indexOf(picker);
  mulstr = mulstr.substring((ps + 2),ps1);
  ps = (document.isnform09.volinp.value * mulstr);
  picker = "";
  picker += ps
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
    // Correct for binary/floating point conversion error
    ps = ps + .000001;
    picker = "";
    picker += ps;
    ps2 = picker.indexOf("e");
    if (ps2 < 0) {
      picker = picker.substring(0,(ps1 + 6));
      }
    if (ps2 == 0 || ps2 > 0) {
      ps3 = picker.indexOf("00000");
      if (ps3 > 0) {
        picker = picker.substring(0,ps3 + 1) + picker.substring(ps2,picker.length);
        }
      }
    }
// only show 2 decimals
  ps1 = picker.indexOf(".");
  if (ps1 > -1) {
   picker = picker.substring(0,(ps1 + 3));
  }

  picker = document.isnform09.volinp.value + " " + volinm + " = " + picker + " " + volonm
  document.isnform09.volout.value = picker;
  }

