//interface.js  April 2002
//Communicates between the wireless js toolkit - wireless.js and 
//toolkit.xhtml

/*  
 Copyright Psand Ltd. 2002. Author: Spacepleb@psand.net).
Psand Limited, 54 Goodwin Road, Ramsgate, Kent, CT11 0JJ, United Kingdom.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

function feet_to_metres(form){
  form.metres.value=decimal(feet_m(parseFloat(form.feet.value)),3);
}

function metres_to_feet(form){
  form.feet.value=decimal(m_feet(parseFloat(form.metres.value)),3);
}

function inches_to_mm(form){
  form.mm.value=decimal(inches_mm(parseFloat(form.inches.value)),3);
}

function mm_to_inches(form){
  form.inches.value=decimal(mm_inches(parseFloat(form.mm.value)),3);
}

function metres_to_miles(form){
  form.miles.value=decimal(metres_miles(parseFloat(form.metres.value)),3);
}

function miles_to_metres(form){
  form.metres.value=decimal(miles_metres(parseFloat(form.miles.value)),3);
}

function diameter_to_circumference(form){
  form.circumference.value=decimal(diam_circ(parseFloat(form.diameter.value)),3);
}

function circumference_to_diameter(form){
  form.diameter.value=decimal(circ_diam(parseFloat(form.circumference.value)),3);
}

function free_space_loss(form){
 
 var iD = metres_miles(parseFloat(form.distance.value)); 

  form.db.value = decimal(fsl(iD,parseFloat(form.frequency.value)),3);
}

function free_space_range(form){
  // calculates distance in metres given
  // free space loss in dB
  // at 2.44GHz

  form.distance.value = decimal(miles_metres(fsl_d(parseFloat(form.fsl.value))),3);
}

function effective_r_p(form){
  form.erpdbm.value = decimal(erp_dbm (parseFloat(form.transmit.value) , parseFloat(form.antenna.value),  parseFloat(form.cable.value)),3);
  form.erpmw.value = decimal(dbm_milliwatts(parseFloat(form.erpdbm.value)),3);
}

function margin(form){
  //calculate fade margin or system operating margin

  form.fade_margin.value=decimal(parseFloat(form.transmit.value)+parseFloat(form.transmit_ant.value)+parseFloat(form.receive_ant.value)+parseFloat(form.receive.value)-parseFloat(form.fsl.value),3);
}

function dbm_to_milliwatts(form){
form.milliwatts.value = decimal(dbm_milliwatts(parseFloat(form.dbm.value)),3);
}

function milliwatts_to_dbm(form){
form.dbm.value = decimal(milliwatts_dbm(parseFloat(form.milliwatts.value)),3);
}












