ROTOR_RADIUS= 'rotorRadius';
RPM= 'rpm';
RCF= 'rcf';
CALC_RCF= 'calcRCF';
CALC_RPM= 'calcRPM';
RESULT= 'result';

function rcfToRPM() {
  var el= document.getElementById(ROTOR_RADIUS);
  try {
    var radius = parseFloat(el.value);
    el= document.getElementById(RCF); 
    var rcf = parseInt(el.value);
    if (radius!=0 && rcf!=0 && !isNaN(radius) && !isNaN(rcf)) {
      var rpm=Math.sqrt(rcf/(.00001118*radius));

      el= document.getElementById(RESULT);
      if (el.firstChild==null)
        el.appendChild(document.createTextNode(''));
      el.firstChild.nodeValue= 'The RPM value for a rotor with a '+radius+'cm radius '
	+' at '+rcf+'xg is '+parseInt(rpm)+'RPM.';
    }
  } catch (e) {
    alert('Please check the values entered');
  }
}

function rpmToRCF() {
  var el= document.getElementById(ROTOR_RADIUS);
  try {
    var radius = parseFloat(el.value);
    el= document.getElementById(RPM); 
    var rpm = parseInt(el.value);
    var x=0.00001118;  
    if (radius!=0 && rpm!=0 && !isNaN(radius) && !isNaN(rpm)) {
      var rcf=x*radius*(rpm*rpm);

      el= document.getElementById(RESULT);
      if (el.firstChild==null)
        el.appendChild(document.createTextNode(''));
      el.firstChild.nodeValue= 'The RCF(xg) value for a rotor with a '+radius+'cm radius '
        +'at '+rpm+'RPM is '+parseInt(rcf)+'xg.';
    }
  } catch (e) {
    alert('Please check the values entered ');
  }
}

function init() {
  var el= document.getElementById(CALC_RPM);
  if (el) el.onclick= rcfToRPM;
  el= document.getElementById(CALC_RCF);
  if (el) el.onclick= rpmToRCF;
}

