<div class="centering" style="width:500px;margin-top: 1%;">
    <div id='form_verzet' style="border: 1px solid #ffffff;">
		<div class="detil" style="padding: 2px;background-color: white;">
            <div>
                <form id="frm_add_pinjaman" method="post" action="<?php echo base_url().'manage_arsip_c/validateInputAddPinjaman';?>">
				<table id="tableDetilPerkara" style="font-size:14px;">
                		<col width="40%">
                        <col width="60%">
                        <tbody>
                            <tr>
                                <td colspan="2" style="background:white;border:0px;font-size: 20px;color: #648C03;" align="center"><?php echo $act=='add'?'TAMBAH':'EDIT' ?> DATA PINJAMAN ARSIP</td>
                            </tr>
                            <tr>
                                <td id="first-child">Tanggal Pinjam</td>
                                <td>
                                    <span>
                                        <input class="standard-input" id="tgl_pinjam" name="tgl_pinjam" value="<?php echo $this->tanggalhelper->convertToInputDate($tanggal_pinjam);?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td id="first-child">Peminjam Berkas</td>
                                <td>
                                    <span>
                                        <input class="standard-input" id="peminjam_id" name="peminjam_id" value="<?php echo $petugas_peminjam;?>" maxlength="50">
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td id="first-child">Tanggal Kembali</td>
                                <td>
                                    <span>
                                        <input class="standard-input" id="tgl_kembali" name="tgl_kembali" value="<?php echo $this->tanggalhelper->convertToInputDate($tanggal_kembali);?>" class="datepicker" maxlength="10" placeholder="tgl/bln/tahun">
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td id="first-child">Lama Hari</td>
                                <td>
                                    <span>
                                        <label id="lama_hari" name="lama_hari">
                                        <?php 
                                        echo $lama_hari;
                                        ?></label> Hari
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td id="first-child">Keterangan</td>
                                <td>
                                    <textarea class="standard-input" id='keterangan' name='keterangan'><?php echo $keterangan;?></textarea>
                                    <input type="hidden" id="act" name="act" value="<?php echo $act;?>">
                                    <input type="hidden" id="enc" name="enc" value="<?php echo $enc;?>">
                                    <input type="hidden" id="enc_pjm" name="enc_pjm" value="<?php echo $enc_pjm;?>">
                                    <input type="hidden" id="curr_date" value="<?php echo $today;?>">
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" style="background:white;" align="center">
                                    <input type="button" id='close_form_add_pinjaman' value="Kembali" class="btn close_form_add_pinjaman">
                                    <input id="simpan" class="btn" type="submit" value="Simpan">
                                </td>
                            </tr>
                        </tbody>
                	</table>               	
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.datepicker').ValidateDateInput();
    $('#frm_add_pinjaman').SubmitHandling({
        refresh:'1',
        setRefresh:1,
        divRef:'#konten',
        clicked:1,
        btnClicked:'#close_form_add_pinjaman',
        whenStatus:1
        
    });
    $('#close_form_add_pinjaman').closingFormWin();
    $('.close_form_add_pinjaman').click(function(event){
        if($('#refresh').val()==1){
            refreshPage();
        }
    });
    $('#tgl_pinjam').datepicker({
        beforeShowDay: $.datepicker.noWeekends,
        inline: true,
        showOtherMonths: true,
        dateFormat: 'dd/mm/yy',
        dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
        onSelect: function(dateText, inst) {
            var error = 0;
                
            var tmp = $(this).val().split("/");
            var tmp2 = $('#curr_date').val().split("/");
            if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
                message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
                error = 1
            }

            if(error==1){
                message_error_show(message);
                $(this).css("background-color", "red");
            }else{
                $(this).css("background-color", "#dedbdb");
            }
            error = 0;
        }
    });
    $('#tgl_kembali').datepicker({
        beforeShowDay: $.datepicker.noWeekends,
        inline: true,
        showOtherMonths: true,
        dateFormat: 'dd/mm/yy',
        dayNamesMin: ['Ming', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'],
        onSelect: function(dateText, inst) {
            var error = 0;
                
            var tmp = $(this).val().split("/");
            var tmp2 = $('#curr_date').val().split("/");
            if((new Date(tmp[2]+"-"+tmp[1]+"-"+tmp[0]+"T00:00:00").getTime() > new Date(tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0]+"T00:00:00").getTime())){
                message = 'Tidak Dapat Memilih Melebihi Hari ini. Sekarang Tanggal '+$('#curr_date').val();
                error = 1
            }

            if(error==1){
                message_error_show(message);
                $(this).css("background-color", "red");
            }else{
                $('#lama_hari').text(daydiff(parseDate($('#tgl_pinjam').val()), parseDate($('#tgl_kembali').val())));
                $(this).css("background-color", "#dedbdb");
            }
            error = 0;
        }
    });
    
    function parseDate(str) {
        var mdy = str.split('/')
        return new Date(mdy[2], mdy[1], mdy[0]-1);
    }
    
    function daydiff(first, second) {
        return Math.round((second-first)/(1000*60*60*24));
    }
</script>
