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


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

		$('#mdl-address-id').val(json.id);
		$('#mdl-address-type').val(json.type);
		$('#mdl-address').val(json.address);
		$('#mdl-address-postcode').val(json.postcode);
		$('#mdl-address-city').val(json.city);
		$('#mdl-address-state-id').val(json.state_id).trigger('change');
		$('#mdl-address-country-id').val(json.country_id).trigger('change');
		$('#mdl-address-contact-no').val(json.contact_no);
	}

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

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

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