function myCon3() {
  var from3Val, to3Val, from3Name, to3Name, v1;

  v1 = document.calc3.what3.value;
  v1 = stripBad(v1);
  v1 = parseFloat(v1);
  if (isNaN(v1)) v1 = 0;
  document.calc3.what3.value = v1;
  
  from3Val = document.calc3.from3[document.calc3.from3.selectedIndex].value;
  to3Val = document.calc3.to3[document.calc3.to3.selectedIndex].value;
  from3Name = document.calc3.from3.options[document.calc3.from3.selectedIndex].text;
  to3Name = document.calc3.to3.options[document.calc3.to3.selectedIndex].text;

  var ConvertedTemp = get_fact(v1, from3Val, to3Val);
  if (ConvertedTemp == "Below Absolute Zero"){
    document.calc3.answer3.value = "Your input cannot be below absolute zero.";
  } else {
    document.calc3.answer3.value = ConvertedTemp ;
  }
}

function resetanswer3() {
  document.calc3.answer3.value = "";
}

function get_fact(ff,from3_val,to3_val){
 // first convert to3 kelvin
 if (from3_val == 0){
   ff = ff + 273.15;
 } else if (from3_val == 1){
   ff = ((ff - 32)/ 1.8) + 273.15;
 } else if (from3_val == 2){
   ff = ff / 1.8;
 } else if (from3_val == 3){
   ff = (ff * 1.25) + 273.15;
 }

 if (ff < 0){
   // Below absolute zero
   return "Below Absolute Zero";
 }

 // now convert kelvin to3 unit
 if (to3_val == 0){
   ff = ff - 273.15;
 } else if (to3_val == 1){
   ff = (1.8 * (ff -273.15)) + 32;
 } else if (to3_val == 2){
   ff = ff * 1.8;
 } else if (to3_val == 3){
   ff = (ff - 273.15) / 1.25;
 }
 
 // round it off
 if (Number.prototype.to3Fixed) {
   ff = ff.to3Fixed(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;
} 

