//                        [Pa], [MPa] , [bar] ,[atmfiz], [kG/m2] , [kG/cm2=at tech], [kG/mm2] , [dyn/cm2], [mmHg]   , [mmH2O], [PSI]
var TabWspCisn = new Array( 1, 1000000, 100000, 101325 , 9.80665 , 98066.5         , 9806650  , 0.1      , 133.32237, 9.80665, 6894.7573 ) ;
var dane1=0;
var dane2=0;
var dane3=0;
var sel1 = 0;
var sel2 = 0;
function ustaw(co)
{ 
  if(co==1 && document.getElementById("pole1").value == "wpisz wartość")
    document.getElementById("pole1").value="";
}
function przelicz()
{
  sel1 = document.getElementById("jednostka1").value;
  sel2 = document.getElementById("jednostka2").value;
  dane1 = document.getElementById("pole1").value;
  dane1 = dane1.toString().replace(/,/g,'.');
  dane1 = dane1.replace(/\s/, '');  
  dane2 = dane1 * TabWspCisn[sel1-1];
  dane3 = dane2 / TabWspCisn[sel2-1];
  
if(Math.round(dane3)==dane3)document.getElementById("pole2").value=formatuj_kwote(dane3);
  else document.getElementById("pole2").value=formatuj_kwote(dane3.toFixed(5));
  //alert(dane3);
}

function formatuj_kwote(wartosc) {
    v = wartosc.toString().replace(/,/g,'.');
    v = v.replace(/\s/, '');
    if (isNaN(v)) {
        return wartosc;
    }
    wartosc = v;
    znak = (wartosc == (wartosc = Math.abs(wartosc)));
    wartosc = Math.floor(wartosc*100+0.50000000001);
    grosze = wartosc%100;
    wartosc = Math.floor(wartosc/100).toString();
    if (grosze<10) {
        grosze = "0" + grosze;
    }

    for (var i = 0; i < Math.floor((wartosc.length-(1+i))/3); i++) {
        wartosc = wartosc.substring(0,wartosc.length-(4*i+3))+' '+wartosc.substring(wartosc.length-(4*i+3));
    }

    return (((znak)?'':'-') + wartosc + ',' + grosze);
}


