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

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

		console.log(json);

		$('#mdl-professional-membership-id').val(json.id);
		$('#mdl-promember-profbody').val(json.professional_body);
		$('#mdl-promember-cert').val(json.certificate);
		$('#mdl-promember-membership').val(json.membership);
		$('#mdl-promember-membership-no').val(json.membership_no);
		$('#mdl-promember-year').val(json.year);
		$('#mdl-professional-membership-attachment').val(json.attachment_id);
	}

	function btnRemoveProMember(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) {
	                        _removePromember(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 _removePromember(id) {
		var frmData = new FormData();
		frmData.append('id',id);

		$.ajax({
            url:"<?php echo base_url('hr/StaffProfile/removeMembership/'); ?>",
            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>