function log10(x) {
return(Math.log(x)/Math.log(10));

}

function round(number,X) {
// rounds number to X decimal places, defaults to 3
    X = (!X ? 3 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function populate(erp, dist, rxgain, mhgain, freq, feedlen )
{       // aim of this is to see if we have enough values and to populate the form if so
//var freq=0;
var lambda=0;
//var erp=0;
//var dist=0;
//var rxgain=0;
//var mhgain=0;
var mhmax=85;           // max level out of masthead
var rxv=0;
var feedloss=0.18;      // CT100 18dB/100m


var p_l_offset=32.45;
var c=2.998E8;          // speed of light
var ready=true;         // ready to go until false
//alert ("parsing");
if (parseFloat(erp) > 0 ) {
	erp=parseFloat(erp);
        }
        else
        {
	ready=false;
	return 0;
        }
        //alert("dist");
if (parseFloat(dist) > 0 ) {
	dist=parseFloat(dist);
        }
        else
        {
	ready=false;
        }
        //alert("freq");
if (parseFloat(rxgain) >= 0 ) {
	rxgain=parseFloat(rxgain);
        //alert("Rxgain "+ Math.pow(10,rxgain/20));
        }
if (parseFloat(mhgain) >= 0 ) {
	mhgain=parseFloat(mhgain);
        }


if (parseFloat(freq) > 0 ) {
        freq=parseFloat(freq);
        lambda=c/(freq*1000000);
        // alert("lambda");
        lambda=round(lambda,1);
        }
        else
        {
	ready=false;
        }
        //alert("plossc"+freq+" "+dist+"gh");
if (parseFloat(feedlen) >= 0 ) {
	cabloss=parseFloat(feedlen)*feedloss;
        }
        else
        {
        cabloss=0;
        feedlen=0;
        }

if (dist*erp > 0) {         // can work out field strength
//alert("Field strength");
fieldstr=Math.sqrt(30*erp)/(dist*1000);
fieldstr=round(fieldstr,6);
}

if (lambda*dist*erp > 0) {         // can work out antenna voltage
//alert("RX volts");
// alert this was the old RSGB method rxv=0.7071*lambda*fieldstr*Math.pow(10,rxgain/20)*Math.sqrt(75/73.2)/(2*3.1415926);
rxv=0.5*fieldstr*lambda/3.14145926*Math.pow(10,rxgain/20);
antdbuv=round(20*log10(rxv*1000000),1);
}

if (rxv > 0) {
	if ((mhgain > 0) && (mhgain+20*log10(rxv*1000000) > mhmax)) {
                alert("You are pushing your masthead with \n an output level of " + round(mhgain+(20*log10(rxv*1000000)),1) + "dBuV\nCheck specification for max level");

        	}
        rxdbuv=round(mhgain-cabloss+(20*log10(rxv*1000000)),1)

        }

return antdbuv;

}
