function myCon() {
  var FromVal, ToVal, FromName, ToName, v1;

  v1 = document.MainForm.what.value;
  v1 = stripBad(v1);
  v1 = parseFloat(v1);
  if (isNaN(v1)) v1 = 0;
  document.MainForm.what.value = v1;
  
  FromVal = document.MainForm.from[document.MainForm.from.selectedIndex].value;
  ToVal = document.MainForm.to[document.MainForm.to.selectedIndex].value;
  FromName = document.MainForm.from.options[document.MainForm.from.selectedIndex].text;
  ToName = document.MainForm.to.options[document.MainForm.to.selectedIndex].text;

  var ConvertedTemp = get_fact(v1, FromVal, ToVal);
  if (ConvertedTemp == "Below Absolute Zero"){
    document.MainForm.answer.value = "Your input cannot be below absolute zero.";
  } else {
    document.MainForm.answer.value = v1 + " " + FromName + " = " + ConvertedTemp + " " + ToName;
  }
}

function resetanswer() {
  document.MainForm.answer.value = "";
}

function get_fact(ff,from_val,to_val){
 // first convert to kelvin
 if (from_val == 0){
   ff = ff + 273.15;
 } else if (from_val == 1){
   ff = ((ff - 32)/ 1.8) + 273.15;
 } else if (from_val == 2){
   ff = ff / 1.8;
 } else if (from_val == 3){
   ff = (ff * 1.25) + 273.15;
 }

 if (ff < 0){
   // Below absolute zero
   return "Below Absolute Zero";
 }

 // now convert kelvin to unit
 if (to_val == 0){
   ff = ff - 273.15;
 } else if (to_val == 1){
   ff = (1.8 * (ff -273.15)) + 32;
 } else if (to_val == 2){
   ff = ff * 1.8;
 } else if (to_val == 3){
   ff = (ff - 273.15) / 1.25;
 }
 
 // round it off
 if (Number.prototype.toFixed) {
   ff = ff.toFixed(7);
   ff = parseFloat(ff);
 }
 else {
   var leftSide = Math.floor(ff);
   var rightSide = ff - leftSide;
   ff = leftSide + Math.round(rightSide *10000000)/10000000;
 }

return ff;
}

function stripBad(string) {
    for (var i=0, output='', valid="eE-0123456789."; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
}


function calculate(){

	var unit = Number(document.volumeconverter.unit.selectedIndex);
	var conv = Number(document.volumeconverter.conv.selectedIndex);
	var input = Number(document.volumeconverter.input.value);
	var output = 0;
	var x = 0;
	if ( unit == 0 ){ x = input * 1;}
	if ( unit == 1 ){ x = input * 1728;}
	if ( unit == 2 ){ x = input * 46656;}
	if ( unit == 3 ){ x = input * 0.293893129771;}
	if ( unit == 4 ){ x = input * 0.90234375;}
	if ( unit == 5 ){ x = input * 1.8046875;}
	if ( unit == 6 ){ x = input * 1.733875;}
	if ( unit == 7 ){ x = input * 7.21875;}
	if ( unit == 8 ){ x = input * 14.4375;}
	if ( unit == 9 ){ x = input * 28.875;}
	if ( unit == 10 ){ x = input * 57.75;}
	if ( unit == 11 ){ x = input * 231;}
	if ( unit == 12 ){ x = input * 277.42;}
	if ( unit == 13 ){ x = input * 33.6;}
	if ( unit == 14 ){ x = input * 67.2;}
	if ( unit == 15 ){ x = input * 537.6;}
	if ( unit == 16 ){ x = input * 2150.42;}
	if ( unit == 17 ){ x = input * 2219.36;}
	if ( unit == 18 ){ x = input * 0.061023377953;}
	if ( unit == 19 ){ x = input * 61.023377953;}
	if ( unit == 20 ){ x = input * 61023.377953;}
	if ( unit == 21 ){ x = input * 0.061023377953;}
	if ( unit == 22 ){ x = input * 0.61023377953;}
	if ( unit == 23 ){ x = input * 6.1023377953;}
	if ( unit == 24 ){ x = input * 61.023377953;}
	if ( unit == 25 ){ x = input * 610.23377953;}
	if ( unit == 26 ){ x = input * 6102.3377953;}
	if ( unit == 27 ){ x = input * 61023.377953;}

	if ( conv == 0 ){ output = x / 1;}
	if ( conv == 1 ){ output = x / 1728;}
	if ( conv == 2 ){ output = x / 46656;}
	if ( conv == 3 ){ output = x / 0.293893129771;}
	if ( conv == 4 ){ output = x / 0.90234375;}
	if ( conv == 5 ){ output = x / 1.8046875;}
	if ( conv == 6 ){ output = x / 1.733875;}
	if ( conv == 7 ){ output = x / 7.21875;}
	if ( conv == 8 ){ output = x / 14.4375;}
	if ( conv == 9 ){ output = x / 28.875;}
	if ( conv == 10 ){ output = x / 57.75;}
	if ( conv == 11 ){ output = x / 231;}
	if ( conv == 12 ){ output = x / 277.42;}
	if ( conv == 13 ){ output = x / 33.6;}
	if ( conv == 14 ){ output = x / 67.2;}
	if ( conv == 15 ){ output = x / 537.6;}
	if ( conv == 16 ){ output = x / 2150.42;}
	if ( conv == 17 ){ output = x / 2219.36;}
	if ( conv == 18 ){ output = x / 0.061023377953;}
	if ( conv == 19 ){ output = x / 61.023377953;}
	if ( conv == 20 ){ output = x / 61023.377953;}
	if ( conv == 21 ){ output = x / 0.061023377953;}
	if ( conv == 22 ){ output = x / 0.61023377953;}
	if ( conv == 23 ){ output = x / 6.1023377953;}
	if ( conv == 24 ){ output = x / 61.023377953;}
	if ( conv == 25 ){ output = x / 610.23377953;}
	if ( conv == 26 ){ output = x / 6102.3377953;}
	if ( conv == 27 ){ output = x / 61023.377953;}

	document.volumeconverter.output.value = Math.round( 10000000000000000 * output)/ 10000000000000000;

}

