// Расчёт параметров PCR 

var chk=true;
var n;
var rez;

Darr=new Array(1, 1e3, 1e6, 1e9, 1e12, 1e15);
Marr=new Array("mkg", "ng", "pg", "fg", "ag", "zg");
Carr=new Array("mkg/mkl", "ng/mkl", "pg/mkl", "fg/mkl", "ag/mkl", "zg/mkl");
Oarr=new Array(4.8e6, 3.9e6, 3.3e6, 3.1e6, 3e6, 2.7e6, 1.2e6, 1.4e5, 8e4, 7e4, 5.4e4, 1.5e4, 4.7e3, 48.5);

function out(a)
{
	n=0;
	while(n<5&&a<1) {n++; a = a*1e3};
	if(a>0.1){rez = Math.round(a*10)/10;} else {rez = a;};
}


function cpcr()
{
if(chk) {return true};
fpcr();
}


function Lpcr()
{
L = parseFloat(document.pcr.L.value.replace(/,/g,".")); 
if(isNaN(L)||L==0){alert(alt14_01); document.pcr.L.focus(); return true;};
L = Math.abs(L);
document.pcr.L.value=L;
}


function mpcr()
{
Lpcr();

m = parseFloat(document.pcr.m.value.replace(/,/g,".")); 
if(isNaN(m)||m==0){alert(alt14_02b); document.pcr.m.focus(); return true;};
m = Math.abs(m);
document.pcr.m.value=m;
D = Darr[document.pcr.D.selectedIndex];

mq=m / D / 6.49e5 / L;
out(mq);
document.pcr.mq.value = rez;
document.pcr.Dq.selectedIndex = n;

mn=mq * 6.022e2;
out(mn);
document.pcr.mn.value = rez;
document.pcr.Dn.selectedIndex = n;

mg=m / D / L * Oarr[document.pcr.org.selectedIndex];
out(mg);
document.pcr.mg.value = rez;
document.pcr.Dg.selectedIndex = n;

if(chk) {return true};
fpcr();
}

function qpcr()
{
Lpcr();

mq = parseFloat(document.pcr.mq.value.replace(/,/g,".")); 
if(isNaN(mq)||mq==0){alert(alt14_02); document.pcr.mq.focus(); return true;};
mq = Math.abs(mq);
document.pcr.mq.value=mq;
Dq = Darr[document.pcr.Dq.selectedIndex];

m = 6.49e5 * mq * L / Dq;
out(m);
document.pcr.m.value = rez;
document.pcr.D.selectedIndex = n;

mn=mq / Dq * 6.022e2;
out(mn);
document.pcr.mn.value = rez;
document.pcr.Dn.selectedIndex = n;

mg = 6.49e5 * mq / Dq * Oarr[document.pcr.org.selectedIndex];
out(mg);
document.pcr.mg.value = rez;
document.pcr.Dg.selectedIndex = n;

if(chk) {return true};
fpcr();
}

function npcr()
{
Lpcr();

mn = parseFloat(document.pcr.mn.value.replace(/,/g,".")); 
if(isNaN(mn)||mn==0){alert(alt14_02); document.pcr.mn.focus(); return true;};
mn = Math.abs(mn);
document.pcr.mn.value=mn;
Dn = Darr[document.pcr.Dn.selectedIndex];

m = 1.078e3 * mn * L / Dn;
out(m);
document.pcr.m.value = rez;
document.pcr.D.selectedIndex = n;

mq = mn / Dn / 6.022e2;
out(mq);
document.pcr.mq.value = rez;
document.pcr.Dq.selectedIndex = n;

mg = m / L * Oarr[document.pcr.org.selectedIndex];
out(mg);
document.pcr.mg.value = rez;
document.pcr.Dg.selectedIndex = n;

if(chk) {return true};
fpcr();
}

function gpcr()
{
Lpcr();

mg = parseFloat(document.pcr.mg.value.replace(/,/g,".")); 
if(isNaN(mg)||mg==0){alert(alt14_02a); document.pcr.mg.focus(); return true;};
mg = Math.abs(mg);
document.pcr.mg.value=mg;
Dg = Darr[document.pcr.Dg.selectedIndex];

m = mg / Dg * L / Oarr[document.pcr.org.selectedIndex];
out(m);
document.pcr.m.value = rez;
document.pcr.D.selectedIndex = n;

mq = mg / Dg / 6.49e5 / Oarr[document.pcr.org.selectedIndex];
out(mq);
document.pcr.mq.value = rez;
document.pcr.Dq.selectedIndex = n;

mn = mq * 6.022e2;
out(mn);
document.pcr.mn.value = rez;
document.pcr.Dn.selectedIndex = n;

if(chk) {return true};
fpcr();
}

function fpcr()
{
Lpcr();

c = parseFloat(document.pcr.c.value.replace(/,/g,".")); 
if(isNaN(c)||c==0){alert(alt14_03); document.pcr.c.focus(); return true;};
c = Math.abs(c);
document.pcr.c.value=c;

q = parseFloat(document.pcr.q.value.replace(/,/g,".")); 
if(isNaN(q)||q==0){alert(alt14_04); document.pcr.q.focus(); return true;};
q = Math.abs(q);
document.pcr.q.value=q;

a = parseFloat(document.pcr.a.value.replace(/,/g,".")); 
if(isNaN(a)||a==0){alert(alt14_05); document.pcr.a.focus(); return true;};
a = Math.abs(a);
document.pcr.q.value=q;

V = parseFloat(document.pcr.V.value.replace(/,/g,".")); 
if(isNaN(V)||V==0){alert(alt14_06); document.pcr.V.focus(); return true;};
V = Math.abs(V);
document.pcr.V.value=V;

m = parseFloat(document.pcr.m.value.replace(/,/g,".")); 
if(isNaN(m)||m==0){alert(alt14_02); document.pcr.m.focus(); return true;};
m = Math.abs(m);
document.pcr.m.value=m;

mi = parseFloat(document.pcr.mi.value.replace(/,/g,".")); 
if(isNaN(mi)){alert(alt14_07); document.pcr.mi.focus(); return true;};
mi = Math.abs(mi);
document.pcr.mi.value=mi;

sek = parseFloat(document.pcr.sek.value.replace(/,/g,".")); 
if(isNaN(sek)){alert(alt14_08); document.pcr.sek.focus(); return true;};
sek = Math.abs(sek);
document.pcr.sek.value=sek;
t = mi + sek/60;
if(t==0){alert(alt14_09); document.pcr.sek.focus(); return true;};
D = Darr[document.pcr.D.selectedIndex];

mn = V * 1.298 * c;
mp = 0.649 * q * L;
mm = Math.min(mn, mp);
mc = 0.1081666 * a * t;
if(mm <= m/D){alert(alt14_10); document.pcr.m.focus(); return true;};
document.pcr.nc.value  = 1+ Math.floor(Math.log(D*mm/m)/Math.log(2));
document.pcr.na.value = 1+ Math.floor(Math.log(D*mc/m)/Math.log(2));
document.pcr.lmax.value = 2*t;

if(mn>mp){
	document.pcr.balans.value = alt14_11 + alt14_12;
	document.pcr.excess.value = alt14_13;
};
if(mp>mn){
	document.pcr.balans.value = alt14_11 + alt14_13;
	document.pcr.excess.value = alt14_12;
};
proc = Math.round(100*mm/Math.max(mn, mp));
document.pcr.proc.value = proc;
if(proc>90){
	document.pcr.balans.value = alt14_14;
};

Cmm = mm / V;
Qmm = Cmm / 6.49e5 /L;
out(mm);
document.pcr.mm.value = rez;
document.pcr.Dmm.selectedIndex = n;
out(Cmm);
document.pcr.Cmm.value = rez;
document.pcr.DCmm.selectedIndex = n;
out(Qmm);
document.pcr.Qmm.value = rez;
document.pcr.DQmm.selectedIndex = n;

Cmc = mc / V;
Qmc = Cmc / 6.49e5 /L;
out(mc);
document.pcr.mc.value = rez;
document.pcr.Dmc.selectedIndex = n;
out(Cmc);
document.pcr.Cmc.value = rez;
document.pcr.DCmc.selectedIndex = n;
out(Qmc);
document.pcr.Qmc.value = rez;
document.pcr.DQmc.selectedIndex = n;

chk=false;
}

function rclc1()
{
if(chk){alert(alt14_15); return true};
document.pcr.mm.value = mm*Math.pow(10,3*document.pcr.Dmm.selectedIndex);
}

function rclc2()
{
if(chk){alert(alt14_15); return true};
document.pcr.Cmm.value = Cmm*Math.pow(10,3*document.pcr.DCmm.selectedIndex);
}

function rclc3()
{
if(chk){alert(alt14_15); return true};
document.pcr.Qmm.value = Qmm*Math.pow(10,3*document.pcr.DQmm.selectedIndex);
}
function rclc4()
{
if(chk){alert(alt14_15); return true};
document.pcr.mc.value = mc*Math.pow(10,3*document.pcr.Dmc.selectedIndex);
}
function rclc5()
{
if(chk){alert(alt14_15); return true};
document.pcr.Cmc.value = Cmc*Math.pow(10,3*document.pcr.DCmc.selectedIndex);
}
function rclc6()
{
if(chk){alert(alt14_15); return true};
document.pcr.Qmc.value = Qmc*Math.pow(10,3*document.pcr.DQmc.selectedIndex);
}