<script type="text/javascript">
	$(document).ready(function(){
		console.log('tab previous employment detail loaded..');
	});


	function btnEditJobs(elem) {
		var b64 = $(elem).data('content');
		var json = JSON.parse(atob(b64));


		$('#mdl-job-history-id').val(json.id);
		var [yy_enter, mm_enter, dd_enter] = json.date_enter.split('-');
		var [yy_exit, mm_exit, dd_exit] 	 = json.date_exit.split('-');

		$('#mdl-job-history-date-join').val(dd_enter+'-'+mm_enter+'-'+yy_enter);
		$('#mdl-job-history-date-exit').val(dd_exit+'-'+mm_exit+'-'+yy_exit);
		$('#mdl-job-history-employer-name').val(json.employer_name);
		$('#mdl-job-history-employer-address').val(json.employer_address);
		$('#mdl-job-history-position').val(json.position);
		$('#mdl-job-history-los').val(json.length_of_service);
		$('#mdl-job-history-description').val(json.description);
	}	


	function btnRemoveJobs(id){
	    iziToast.question({
	        title: '',
	        timeout:20000,
	        close: false,
	        toastOnce: true,
	        message: 'Are you sure you want to remove this record? ',
	        position:"center",
	        buttons: [
	                    ['<button><b>YES</b></button>', function (instance, toast) {
	                        _removeJobs(id);
	                        instance.hide(toast, {
	                            transitionOut: 'fadeOutUp'
	                        });
	                    }],
	                    ["<button>No</button>", function (instance, toast) {
	                        instance.hide(toast, {
	                            transitionOut: 'fadeOutUp'
	                        });

	                        iziToast.warning({
	                            position: 'bottomRight',
	                            message: 'Operation cancelled.'
	                        });

	                    },true]
	                ]
	        });
	}

	function _removeJobs(id) {
		var frmData = new FormData();
		frmData.append('id',id);

		$.ajax({
            url:"<?php echo base_url('hr/StaffProfile/removeJobs/'); ?>",
            type:'post',
            dataType:'json', //return type value
            data:frmData,
            processData: false,
            contentType: false,
            success:function(data){
                iziToast.success({
                    title: '',
                    message:'success'
                });
                window.location.replace("<?php echo base_url('hr/StaffProfile/staffDetail/'.$this->uri->segment(4)); ?>");            
            },error:function(){
                iziToast.error({
                    title: '',
                    message: '500 internal server error'
                });
            }
        });
	}
</script>