var calculator = {
    show: function(id,state) {
        if (e=document.getElementById(id)) e.style.display=state;
    },
    visible: function(id,state) {
        if (e=document.getElementById(id)) e.style.visibility=state;
    },
    refresh: function (e) {
       if (e.value=='pracownik') {
            this.show('nnw','none');
            if (e.form.elements['kalkulator[umowa]'].value=='praca') {
                this.show('zlecenie','none');
                //this.show('rozliczenie','block');
                this.show('koszty','block');
                this.show('zarobki_t','block');
                this.visible('zarobki_p','visible');
                this.show('nnw_skladka','none');

            } else {
                //this.show('rozliczenie','none');
                this.show('koszty','none');
                this.show('zarobki_t','none');
                this.visible('zarobki_p','hidden');
            }
       } else if (e.value=='pracodawca') {


            if (e.form.elements['kalkulator[umowa]'].value=='praca') {

                this.show('koszty','block');
                this.show('nnw_skladka','block');
                this.show('zlecenie','none');
                this.show('zarobki_t','block');
                this.visible('zarobki_p','visible');
            } else {
                this.show('nnw','block');
                this.show('zlecenie','block');
                this.show('zarobki_t','none');
                this.visible('zarobki_p','hidden');
                //this.show('rozliczenie','none');
                this.show('koszty','none');
            }

       } else if (e.value=='praca') {
            this.show('zarobki_t','block');
            this.visible('zarobki_p','visible');
            this.show('koszty','block');
            if (e.form.elements['kalkulator[typ]'].value=='pracownik') {
                this.show('nnw_skladka','none');
                this.show('zlecenie','none');
                //this.show('rozliczenie','block');

            } else {

                this.show('zlecenie','none');
                this.show('nnw_skladka','block');
            }
       } else if (e.value=='zlecenie' ) {
            this.show('nnw','none');
            this.show('zarobki_t','none');
            this.visible('zarobki_p','hidden');
            //this.show('rozliczenie','none');
            this.show('koszty','none');
            this.show('zlecenie','block');
            if (e.form.elements['kalkulator[typ]'].value=='pracodawca') {
                this.show('nnw','block');

            }
        }
    },
    checkNumber: function(e) {
        if (!/^[0-9,\.%]*$/.test(e.valueval)) {

        }

    },
    checkOverheads: function (e) {
        val = parseFloat(e.value.replace(",","."));
        if (!(val>=0 && val<=100)) e.value=100;
        if (e.value==100) {
            e.form.elements['kalkulator[kosztyUzyskania]'][0].disabled=true;
            e.form.elements['kalkulator[kosztyUzyskania]'][1].disabled=true;
        } else {
            e.form.elements['kalkulator[kosztyUzyskania]'][0].disabled=false;
            e.form.elements['kalkulator[kosztyUzyskania]'][1].disabled=false;
        }
    },
    checkNNW: function (e) {
        val = parseFloat(e.value.replace(",","."));
        if (!(val>=0.9 && val<=3.6)) e.value=1.8;
    }
    ,
    checkForm: function (form) {
    },
    fill: function(f) {
        for (i=1;i<=12;i++) {
            field = 'kalkulator[zarobki]['+i+']';
            f.elements['kalkulator[zarobki]['+i+']'].value = f.elements['kalkulator[zarobki_ogolne]'].value;
        }
    }

}
