<script type="text/javascript">
	function btnEditContractElement(elem) {
		var b64 = $(elem).data('content');
		var json = JSON.parse(atob(b64));

		$('#modal-contract-id').val(json.id);
		$('#modal-contract-type').val(json.contract_hiring_type_id);
		$('#modal-contract-confirmation').val(json.confirmation);
		$('#modal-contract-duration-period').val(json.duration);

		if(json.contract_hiring_type_id == 4){
			$('#modal-contract-confirmation-date').prop("disabled", true);
			$('#modal-contract-confirmation-date').val('');
			$('#modal-contract-confirmation-date2').val('');
		}else{
			$('#modal-contract-confirmation-date').prop("disabled", false);
			$('#modal-contract-confirmation-date').val(moment(json.confirmation_date,'YYYY-MM-DD').format('DD-MM-YYYY'));
			$('#modal-contract-confirmation-date2').val(moment(json.confirmation_date,'YYYY-MM-DD').format('DD-MM-YYYY'));
		}
		
		$('#modal-contract-probationary-period').val(json.probation);
		$('#modal-contract-probationary-duration').val(json.probation_duration);
		$('#modal-contract-er-period').val(json.er_notice);
		$('#modal-contract-er-duration').val(json.er_notice_duration);
		$('#modal-contract-ee-period').val(json.ee_notice);
		$('#modal-contract-ee-duration').val(json.ee_notice_duration);

		if(json.resign_date == '0000-00-00' || json.resign_date == null){
			$('#resign_date').val('');
		}else{
			$('#resign_date').val(moment(json.resign_date,'YYYY-MM-DD').format('DD-MM-YYYY'));
		}

		if(json.last_working_date == '0000-00-00' || json.last_working_date == null){
			$('#last_working_date').val('');
		}else{
			$('#last_working_date').val(moment(json.resign_date,'YYYY-MM-DD').format('DD-MM-YYYY'));
		}

		if(json.phy_last_working_date == '0000-00-00' || json.last_working_date == null){
			$('#phy_last_working_date').val('');
		}else{
			$('#phy_last_working_date').val(moment(json.resign_date,'YYYY-MM-DD').format('DD-MM-YYYY'));
		}
	}

	function btnRemoveContractElement(elem) {
		toastConfirm('Are you sure you want remove this contract element?',function(){
			var b64 = $(elem).data('content');
			var json = JSON.parse(atob(b64));
			var data = {
				id:json.id,
			}
			
			ajxRequest('<?php echo base_url('hr/StaffProfile/removeContractElement/');?>','POST',data,'<?php echo current_url(); ?>');

		});
	}

	function EditContractElem() {
		var data = {
			id:$('#modal-contract-id').val(),
			type_id:$('#modal-contract-type').val(),
			confirmation:$('#modal-contract-confirmation').val(),
			duration:$('#modal-contract-duration-period').val(),
			confirmation_date:$('#modal-contract-confirmation-date').val(),
			probationary_period:$('#modal-contract-probationary-period').val(),
			probationary_duration:$('#modal-contract-probationary-duration').val(),
			er_notice:$('#modal-contract-er-period').val(),
			er_notice_duration:$('#modal-contract-er-duration').val(),
			ee_notice:$('#modal-contract-ee-period').val(),
			ee_notice_duration:$('#modal-contract-ee-duration').val(),
			confirmation_reminder:$('#modal-contract-confirmation_reminder').val(),
			resign_date:$('#resign_date').val(),
			last_working_date:$('#last_working_date').val(),
			phy_last_working_date:$('#phy_last_working_date').val(),

		}

		ajxRequest('<?php echo base_url('hr/StaffProfile/updateContractElement/'); ?>','POST', data, '<?php echo current_url(); ?>');

		console.log('save contract');
		console.log(data);
	}
</script>