	/* kalkulator lokat */
	function odsetki(kwota, stopa, okres,jednostka) {
		kwota=kwota*1
		wynik=kwota+((kwota*stopa*okres)/(jednostka*100))
		return wynik;
	}
	
	function podstaw() {
    frm = document.getElementById('form');
		kwota=frm.kwota.value;
		stopa=frm.stopa.value;
		okres=frm.okres.value;
		jednostka=frm.jednostka.value;
		kapitalizacja=frm.kapitalizacja.value;
		czas=okres*(1/jednostka)
				
		if (kapitalizacja!=0) {
			lokresow='';
			if ((jednostka==1) && (kapitalizacja==2)) {lokresow=12}
			if ((jednostka==1) && (kapitalizacja==3)) {lokresow=4}
			if ((jednostka==1) && (kapitalizacja==4)) {lokresow=1}
			if ((jednostka==12) && (kapitalizacja==2)) {lokresow=12}
			if ((jednostka==365) && (kapitalizacja==1)) {lokresow=365}
			if (lokresow=='') {
				window.alert("Nie mona obliczyć wyniku przy takim ustawieniu okresu lokaty i sposobu kapitalizacji"); 
			} else {
				wynik=Math.floor((kwota*Math.pow((1+stopa/(100*lokresow)),lokresow*czas))*100)/100;
        wynik_tmp = Math.floor(wynik-kwota);  
			  if (isNaN(wynik_tmp)) {wynik_tmp='';};
        $('.wynik').html(wynik_tmp);
				esp_tmp=Math.floor((((wynik-kwota)*100/kwota)/czas)*100)/100;
			  if (isNaN(esp_tmp)) {esp_tmp='';};
			  $('.esp').html(esp_tmp);
			}
		} else {
		    suma_lacznie = Math.floor((odsetki(kwota, stopa,okres, jednostka))*100)/100;
        wynik_tmp = suma_lacznie-kwota;	  
			  if (isNaN(wynik_tmp)) {wynik_tmp='';};
        $('.wynik').html(wynik_tmp);
			  esp_tmp=Math.floor((((suma_lacznie-kwota)*100/kwota)/czas)*100)/100;
			  if (isNaN(esp_tmp)) {esp_tmp='';};
			  $('.esp').html(esp_tmp);	
		}
	}
	
    function bezkropek(arg) {
        if (arg.value!=''){
            var r, re;
            re = /,/g;
            r = arg.value.replace(re, ".");
            arg.value=r;
        }
    }
	
    function na_calkowite(arg) {
        if (arg.value!='') {
            var r, re;
            var s = arg.value;
            re = /,/g;
            r = arg.value.replace(re, ".");
            
            arg.value=Math.floor(r);
            if (arg.value=="NaN") {arg.value='';};
        }
    }

    $('.krok-srodek input#kwota, .krok-srodek input#okres').keypress(function(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode==8) return true;
        //if ($(this).attr('value').length>20) return false;
        if (charCode > 47 && charCode < 58 ){
            return true;
        }
        return false;
    });
	/* // kalkulator lokat */


/*  kalkulator emerytur */
function kalkulator_emerytur(opcja) {
    //console.log('opcja: '+opcja);
    if(opcja == 1) {
        for(i=0; i <= 59; i++) {
            tmp_id = 'text_'+i;
            //console.log('i -> '+i+' -- '+tmp_id);
            inputfield = document.getElementById(tmp_id);
            //console.log('ssa');
            
            inputfield.disabled = true;
            inputfield.style.backgroundColor = "#eee";
            inputfield.style.border = "2px solid #ddd";

            //console.log('3');
            
            tmp_id = "box_"+i;
            select_box = document.getElementById(tmp_id);
            select_box.innerHTML = '';
            
            radiobox = document.createElement('input'); 
            radiobox.setAttribute('type','radio');
            radiobox.setAttribute('name','rok');
            radiobox.setAttribute('value',(1950+i));
            radiobox.temp = i;
            
            //console.log('ss');
            
            if(i > 49) radiobox.setAttribute('disabled',true); // nie można wybrac mniej niż 10 lat
            radiobox.onclick = function() {
                kalkulator_emerytur_input_text(this, 1);
            };
            select_box.appendChild(radiobox);
            //console.log('koniec');
        }
    } else {
        var liczba_zaznaczonych = 0;
        for(i=0; i <= 59; i++) {
            tmp_id = 'text_'+i;
            inputfield = document.getElementById(tmp_id);
            inputfield.disabled = true;
            inputfield.style.backgroundColor = "#eee";
            inputfield.style.border = "2px solid #ddd";
            
            tmp_id = "box_"+i;
            select_box = document.getElementById(tmp_id);
            select_box.innerHTML = '';
            
            checkbox = document.createElement('input'); 
            checkbox.setAttribute('type','checkbox');
            checkbox.setAttribute('name','rok['+(1950+i)+']');
            checkbox.temp = i;
            checkbox.onclick = function() {
                kalkulator_emerytur_input_text(this, 2);
            }
            select_box.appendChild(checkbox);
        }
    }
}

function kalkulator_emerytur_input_text(elem, opcja) {
    if(opcja == 1) {
        for(x=0; x <= 59; x++) {
            tmp_id = 'text_'+x;
            inputfield = document.getElementById(tmp_id);
            if(x >= elem.temp && x < elem.temp+10) {
                inputfield.disabled = false;
                inputfield.style.backgroundColor =  "#fff";
                inputfield.style.border = "2px solid #ddd";
            }else {
                inputfield.disabled = true;
                inputfield.style.backgroundColor = "#eee";
                inputfield.style.border = "2px solid #ddd";
            }
        }
    }
    else {
        tmp_id = 'text_'+elem.temp;
        inputfield = document.getElementById(tmp_id);
        if(elem.checked == true) {
            inputfield.disabled = false;
            inputfield.style.backgroundColor =  "#fff";
            inputfield.style.border = "2px solid #ddd";
        } else {
            inputfield.disabled = true;
            inputfield.style.backgroundColor = "#eee";
            inputfield.style.border = "2px solid #ddd";
        }
    }
    return true;
}

function kalkulator_emerytury_poradnik(elem) {
    poradnik = document.getElementById('jak_wyliczyc');
    if(poradnik.style.display == 'none') {
        poradnik.style.display = 'block';
    } else {
       poradnik.style.display = 'none';
    }
}
/*  //kalkulator emerytur */

	
	
function clear(){
 	$('#info_krok1').hide();
	$('#info_krok2').hide();
	$('#info_krok3').hide();
	$("#info_krok4").html("");
	$('#info_krok4').hide();
}	
	


$(document).ready(function(){

	$('#kod').attr('disabled', true);
	$('#radio2_1').attr('disabled', true);
	$('#radio2_2').attr('disabled', true);
	$('#radio3_1').attr('disabled', true);
	$('#radio3_2').attr('disabled', true);
		
	clear();
			
	$('input[name=zus_stopa]:radio').change( function(){
		if($('input[name=zus_stopa]:checked').val()==0) {
			$('#radio2_1').attr('disabled', false);
			$('#radio2_2').attr('disabled', false);
			clear();
		}
		else{
		
				
			$('#kod').attr('disabled', true);
			$('#radio2_1').attr('disabled', true);
			$('#radio2_2').attr('disabled', true);
			$('#radio3_1').attr('disabled', true);
			$('#radio3_2').attr('disabled', true);
			
      clear();
      
			$('#radio2_1').attr('checked', false);
			$('#radio2_2').attr('checked', false);
			$('#radio3_1').attr('checked', false);
			$('#radio3_2').attr('checked', false);	
			$('#info_krok1').show();
		}
	});

	$('input[name=osob]:radio').change( function(){
		if($('input[name=osob]:checked').val()==0) {
			$('#radio3_1').attr('disabled', false);
			$('#radio3_2').attr('disabled', false);
			
			clear();
		}
		else{
			$('#kod').attr('disabled', true);
			$('#radio3_1').attr('disabled', true);
			$('#radio3_2').attr('disabled', true);
			
			clear();
			
			$('#radio3_1').attr('checked', false);
			$('#radio3_2').attr('checked', false);		
			$('#info_krok2').show();
		}
	});
	
	$('input[name=regon]:radio').change( function(){
		if($('input[name=regon]:checked').val()==1) {
			$('#kod').attr('disabled', false);
			$('#info_krok3').hide();
		}
		else{
			$('#kod').attr('disabled', true);
			$('#info_krok3').show();
		}
	});	
	
	// MIREK 
	
	$('#oblicz_button').click( function(){
		var x = $('#kod').val();		
		x = x.substr(0,2);
		var y = 0;
		if(x.length==0 || x.length==1){
			alert("Nie podano kodu PKD lub podany kod jest nie prawidłowy");
		}
		else{
			if(x=='01' || x=='02' || x=='24' || x=='25')
				y = '2,53%';
			else if(x=='03' || x=='10' || x=='11' || x=='12' || x=='20' || x=='21' || x=='35' || x=='36')
				y = '1,73%';
			else if(x=='05' || x=='06' || x=='07' || x=='08' || x=='09') 
				y = '3,33%';
			else if(x=='13' || x=='14' || x=='15' || x=='68' || x=='77')
				y = '1,20%';
			else if(x==16)
				y = '2,80%';
			else if(x==17 || x==18 || x==19 || x==26 || x==27 || x==33 || x==37 || x==38 || x==39 || x==45 || x==46 || x==47 || x==48 || x==49 || x==50 || x==51 || x==52 || x==53 || x==58 || x==59 || x==60 || x==61 || x==62 || x==63 || x==79 || x==80 || x==81 || x==82 || x==86 || x==87 || x==88 || x==89 || x==90 || x==91 || x==92 || x==93 || x==94 || x==94 || x==95 || x==96 || x==97 || x==98)
				y = '1,47%';
			else if(x==22 || x==28 || x==31 || x==32 || x==41 || x==42 || x==43)
				y = '2,00%';
			else if(x==29 || x==30)
				y = '2,26%';
			else if(x==55 || x==56 || x==69-75 || x==78 || x==84 || x==99 || x==85)
				y = '0,93%';
			else if(x==64 || x==65 || x==66)
				y = '0,67%';
			else
				y = '1,67% podstawy wymiaru';
			$('#info_krok4').show();
			$("#info_krok4").html("Składka: "+y+"");
		}
	});
		


    /* tab kalkulatory/wskazniki*/  
    kalk = document.domain+'/kalkulatory';
    wsk = document.domain+'/wskazniki';
    
    if(document.URL.search(kalk) != -1)  
    {
        $('div#zakladkikal ul').idTabs("tabs1");
        //console.log(' jestem w kalkulatorach ');  
    }
    else if(document.URL.search(wsk) != -1)  
    {
        $('div#zakladkikal ul').idTabs("tabs2");   
        //console.log(' jestem we wskaznikach ');   
    }
    else
    {
        $('div#zakladkikal ul').idTabs("tabs1");
        //console.log(' pozostale ');         
    }
 
    if(document.URL.search(kalk) != -1)  
    {
        $('div.stronaglkal ul').idTabs("tabik5a");
        //console.log(' jestem w kalkulatorach ');  
    } 

                   
    
 });  
 
 


    function przepisz() {
        frm = document.getElementById('form');
        if (frm.kwota.value!='') {
            //console.log(frm.kwota.value);
            var r, re;
            var s = frm.kwota.value;
            re = /,/g;
            r = frm.kwota.value.replace(re, ".");
            frm.kwota.value=r;
            for (i=4;i<16;i++){
                //console.log(frm.elements[i].name);
                frm.elements[i].value=r;
            }
        }
    }  
    
    $.fn.exists = function(){return $(this).length>0;}

    
    /* kalkulator odsetek ustawowych*/
   /*
    $(document).ready(function(){
				
        if( $('#data_od').exists() || $('#data_do').exists()  )
        {			
            $('#data_od').DatePicker({
                format:'d.m.Y',
                date: $('#data_od').val(),
                current: $('#data_od').val(),
                starts: 1,
                position: 'right',
                onBeforeShow: function(){
                    $('#inputDate').DatePickerSetDate($('#data_od').val(), true);
                },
                onChange: function(formated, dates){
                    $('#data_od').val(formated);
                }
            });
            $('#data_do').DatePicker({
                format:'d.m.Y',
                date: $('#data_do').val(),
                current: $('#data_do').val(),
                starts: 1,
                position: 'right',
                onBeforeShow: function(){
                    $('#inputDate').DatePickerSetDate($('#data_do').val(), true);
                },
                onChange: function(formated, dates){
                    $('#data_do').val(formated);
                }
            });
        }
    });
    */
    


    /* TEST kalkulator odsetek ustawowych*/
    $(document).ready(function(){
				
        if( $('#data_od').exists() || $('#data_do').exists()  )
        {			
            $('#data_od_kalk').DatePicker({
                format:'d.m.Y',
                date: $('#data_od').val(),
                current: $('#data_od').val(),
                starts: 1,
                position: 'right',
                onBeforeShow: function(){
                    $('#inputDate').DatePickerSetDate($('#data_od').val(), true);
                },
                onChange: function(formated, dates){
                    $('#data_od').val(formated);
                }
            });           
           
            $('#data_do_kalk').DatePicker({
                format:'d.m.Y',
                date: $('#data_do').val(),
                current: $('#data_do').val(),
                starts: 1,
                position: 'right',
                onBeforeShow: function(){
                    $('#inputDate').DatePickerSetDate($('#data_do').val(), true);
                },
                onChange: function(formated, dates){
                    $('#data_do').val(formated);
                }
            });
            
        }
    });
    
    
