<?php 
if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}

$myID = fetch_postget_val('id',$_POST, $_GET);
$pemohon = fetch_postget_val('pemohon',$_POST, $_GET);
$program = fetch_postget_val('program',$_POST, $_GET);
$borangitem = fetch_postget_val('borangitem',$_POST, $_GET);
$reloadBtn = fetch_postget_val('reloadBtn',$_POST, $_GET);
$readonly = fetch_postget_val('readonly',$_POST, $_GET);
$uniqueId = time(); //to prevent duplicated form name

$indicator_Query = "SELECT B.*
				  FROM u_pautanborang A
				  LEFT JOIN u_borangitem B ON A.id_borangitem = B.id_borangitem
				  WHERE 
				  B.linked_borangitem = ? 
				  AND A.id_program = ?
				  ORDER BY B.susunan";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $borangitem, PDO::PARAM_INT);
$PDO_stmt->bindValue(2, $program, PDO::PARAM_INT);
$PDO_stmt->execute();
$borangList = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$borangList[] = $result;
}

$indicator_Query = "SELECT *
				  FROM u_datatableitem
				  WHERE type = 1 AND id_borangitem = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $borangitem, PDO::PARAM_INT);
$PDO_stmt->execute();
$datatableitem = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT A.*, B.nama_pemohon, B.kpbaru_pemohon
				  FROM {$datatableitem['table_name']} A
				  LEFT JOIN m_pemohon B ON B.id_pemohon = A.id_pemohon
				  WHERE A.{$datatableitem['column_name']} = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
?>
<div class="modal-header">
	<h5 class="modal-title">Permohonan Baru / Kemaskini Program Anak Emas</h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeBtn" name="closeBtn" ></button>
</div>
<div class="modal-body">
	<input type="hidden" id="dz_myID" value="<?=$myID?>">
	<form action="javascript:;" class="form-horizontal" name="indicator_form_<?=$uniqueId?>" id="indicator_form_<?=$uniqueId?>">
		<div class="form-body">
			<div class="row">
				<div class="col-md-12">
					<ul class="nav nav-tabs" id="myTab" role="tablist">
						<li class="nav-item">
							<a class="nav-link active" id="info-tab" data-toggle="tab" href="#info">
								<span class="nav-text">Maklumat Anak Emas</span>
							</a>
						</li>
						<li class="nav-item">
							<a class="nav-link <?php echo ($myID > 0)?'':'disabled'; ?>" id="document-tab" data-toggle="tab" href="#document">
								<span class="nav-text">Dokumen Lampiran</span>
							</a>
						</li>
						<li class="nav-item">
							<a class="nav-link <?php echo ($myID > 0)?'':'disabled'; ?>" id="akuan-tab" data-toggle="tab" href="#akuan">
								<span class="nav-text">Akuan Permohonan</span>
							</a>
						</li>
					</ul>
					<div class="tab-content" id="myTabContent">
						<div class="tab-pane fade show active" id="info" role="tabpanel" aria-labelledby="info-tab">
							<div class="row">
								<div class="col-md-12" style="margin-top: 20px;">
									<?php
										foreach($borangList as $key => $item)
										{
											switch ($item['id_inputtype']) 
											{
												case '1': //textbox
													createTextBox($item['label'], $item['input_name'], $item['placeholder']!=''?$item['placeholder']:$item['label'], $indicator_List[$item['value']], $item['label_size'], $readonly, $item['input_size'], $item['div_size'], $item['extra_param'], 'text');
													break;
												case '2': //dropdown
													createDropDown($PDO, $item['label'], $item['extra_param'], $item['input_name'], $indicator_List[$item['value']], $item['placeholder'], $item['input_size'], $item['label_size'], $item['div_size'], $readonly);
													break;
												case '3': //dropdown_sql
													createDropDown_sql($PDO, $item['label'], $item['extra_param'], $item['input_name'], $indicator_List[$item['value']], $item['placeholder'], $item['input_size'], $item['label_size'], $item['div_size'], $readonly);
													break;
												case '5': //custom
													echo $item['extra_param'];
													break;
												case '7': //action insert
													//script_url<BRE>borang_div<BRE>table_name<BRE>id_table<BRE>id_insert<BRE>id_update
													$action_value = 'general-borang_insert.php'.'<BRE>'.$borangitem.'<BRE>'.$item['value'];
													$allInfo = explode('<BRE>', $item['value']);
													echo '<input type="hidden" id="saveAction_'.$uniqueId.'" value=\''.$action_value.'\'>';
													break;
												case '8': //textbox uncopyable
													createTextBox($item['label'], $item['input_name'], $item['placeholder']!=''?$item['placeholder']:$item['label'], $indicator_List[$item['value']], $item['label_size'], $readonly, $item['input_size'], $item['div_size'], $item['extra_param'], 'text', '', ' oncopy="return false" onpaste="return false" ');
													break;
												case '12': //hidden input
													echo '<input type="hidden" id="'.$item['input_name'].'" value=\''.$indicator_List[$item['value']].'\'>';
													break;
												case '21':
													$p_Query = "SELECT *
																	  FROM m_pemohon
																	  WHERE id_pemohon = ?";
													$PDO_stmt = $PDO->prepare($p_Query);
													$PDO_stmt->bindValue(1, $pemohon, PDO::PARAM_INT);
													$PDO_stmt->execute();
													$pemohon_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
													
													$my_array = [];
													$my_array[] = array($pemohon_List['nama_pemohon'], $pemohon_List['nama_pemohon']);
													/*if($pemohon_List['nama_pasangan'] != '')
													{
														$my_array[] = array($pemohon_List['nama_pasangan'], $pemohon_List['nama_pasangan']);
													}*/
													//createDropDown_Array($item['label'], $my_array, $item['input_name'], $indicator_List[$item['value']]==""?"0":$indicator_List[$item['value']], 'Pilih '.$item['label'], $item['input_size'], $item['label_size'], $item['div_size'], $readonly);
													createDropDown_Array($item['label'], $my_array, $item['input_name'], $pemohon_List['nama_pemohon'], 'Pilih '.$item['label'], $item['input_size'], $item['label_size'], $item['div_size'], $readonly);
													break;
											  default:
												echo '';
											}
											
											//build a json that will be use for validation here
											if($item['checking_type'] != '')
											{
												$validator[] = array($item['input_name'], $item['label'], $item['checking_type']);
											}
										}
										
										//set all hidden input for action
										foreach($actionArray as $actKey => $actItem)
										{
											echo '<input type="hidden" id="'.$actKey.'" value=\''.join(',', $actItem).'\'>';
										}
										
										echo '<input type="hidden" id="formValidator_'.$uniqueId.'" value=\''.json_encode($validator).'\'>';
										if($readonly == 0)
										{
											echo '<div style="text-align:center;margin-top: 10px;">';
												echo '<button type="button" class="btn btn-primary" id="simpanBtn">Simpan & Seterusnya</button>';
											echo '</div>';
										}
									?>
								</div>
							</div>
						</div>
						<div class="tab-pane fade show" id="document" role="tabpanel" aria-labelledby="document-tab">
							<div class="row">
								<div class="col-md-12" style="margin-top: 20px;">
									<?php
										//hardcode dropzone here
										//get all i_dokumenprogram
										$dok_Query = "SELECT i_dokumen.id_dokumen, i_dokumenprogram.flag_wajib, i_dokumen.desk_dokumen
														FROM i_dokumenprogram 
														LEFT JOIN i_dokumen ON i_dokumenprogram.id_dokumen = i_dokumen.id_dokumen
														WHERE id_program = $program";
										$dok_Result = $PDO->prepare($dok_Query);
										$dok_Result->execute();
										// put all into hash for easier comparison
										$dokList = array();
										$dokWajibList = array();
										while($res = $dok_Result->fetch(PDO::FETCH_ASSOC)) {
											if($res['flag_wajib'] == 1)
											{
												$dokWajibList[]= $res;
											}
											else
											{
												$dokList[]= $res;
											}
										}
										echo '<h3>Senarai Dokumen Yang Diperlukan</h3>';
										//echo '<div class="checkbox-list">';
										$doc_counter = 1;
											foreach($dokWajibList as $wkey => $witem) 
											{
												echo $doc_counter++.'. '.$witem['desk_dokumen'].'<a title="Dokumen Wajib">'.$Wajib_svg.'</a><br>';
												$checkDocList .= $witem['id_dokumen'].',';
											}
											foreach($dokList as $wkey => $witem) 
											{
												echo $doc_counter++.'. '.$witem['desk_dokumen'].'<br>';
											}
											echo '<hr>';
										//echo '</div>';
										echo '<div class="form-group row">
											<div class="col-md-12">
												<input type="hidden" id="file_count_anakemas_DZ" value="0">
												<div class="dropzone dropzone-default" id="anakemas_DZ">
													<div class="dropzone-msg dz-message needsclick">
														<h3 class="dropzone-msg-title">Klik di sini untuk muat naik dokumen</h3>
														<span class="dropzone-msg-desc">Hanya gambar / pdf sahaja</span>
													</div>
												</div>
												*Klik pada ruangan diatas untuk muatnaik dokumen (hanya format gambar/pdf sahaja)
											</div>
										</div>';
										createModal('AE_large_photo-modal');
										if($readonly == 0)
										{
											echo '<div style="text-align:center;margin-top: 10px;">';
												echo '<button type="button" class="btn btn-primary" id="simpandocBtn">Simpan & Seterusnya</button>';
											echo '</div>';
										}
									?>
								</div>
							</div>
						</div>
						<div class="tab-pane fade show" id="akuan" role="tabpanel" aria-labelledby="akuan-tab">
							<!--<div class="row">
								<div class="col-md-12" style="margin-top: 20px;">
    								<div class="accordion accordion-toggle-arrow" id="accordionExample4">
    									<div class="card">
    										<div class="card-header" id="headingOne4">
    											<div class="card-title" data-toggle="collapse" data-target="#collapseOne4">
    											<i class="flaticon2-layers-1"></i>Maklumat Permohonan Program Anak Emas</div>
    										</div>
    										<div id="collapseOne4" class="collapse show" data-parent="#accordionExample4">
    											<div class="card-body">
    										
    											<table>
    												<tr>
    													<td>Nama Pemohon</td>
    													<td style="width:10%">:</td>
    													<td><b><?=$indicator_List['nama_pemohon']?></b></td>
    												</tr>
    												<tr>
    													<td>No KP Pemohon</td>
    													<td style="width:10%">:</td>
    													<td><b><?=$indicator_List['kpbaru_pemohon']?></b></td>
    												</tr>
    												<tr>
    													<td>Nama Anak Emas</td>
    													<td style="width:10%">:</td>
    													<td><b><?=$indicator_List['nama_anakemas']?></b></td>
    												</tr>
    												<tr>
    													<td>No Mykid Anak Emas</td>
    													<td style="width:10%">:</td>
    													<td><b><?=$indicator_List['kpbaru_anakemas']?></b></td>
    												</tr>
    											</table>
    											
    											</div>
    										</div>
    									</div><br>
    								</div>
								</div>
							</div>-->
							<div class="row">								
								<div class="col-md-12" style="margin-bottom: 10px;">
								</div>
								<?php
								createDropDown($PDO, 'Cara Hantar Borang', 'i_carahantar', 'borang_carahantarae', '', 'Pilih Cara Hantar', 7, 3, 12);
								?>
								<div class="col-md-12" style="margin-top: 20px;">
									<label class="checkbox">
										<input type="checkbox" id="akui_anakemas" onchange="checkUncheckCB_AE('akui_anakemas', 'ae_submitBtn')" >
										<span></span>
										&nbsp; &nbsp;Saya dengan ini mengesahkan maklumat yang diberikan bagi permohonan ini adalah benar dan tepat.
									</label>
								</div>
								<div class="col-md-12" style="margin-top: 20px;">
									<div style="text-align:center;margin-top: 10px;">
										<button type="button" class="btn btn-primary" id="ae_submitBtn">Hantar</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				
			</div>
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		//echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		if($readonly == 0)
		{
			//echo '<button type="button" class="btn btn-primary" id="simpanBtn">Simpan</button>';
		}
	?>
</div>

<?php
$jsItem['input_name'] = 'anakemas_DZ';
echo '<script type="text/javascript">';
	echo 'var uploadPath = "upload_anakemas";';
	
		echo 'var myDZ_'.$jsItem['input_name'].' = new Dropzone("div#'.$jsItem['input_name'].'", {
			acceptedFiles: "image/jpg,image/jpeg,image/png,image/bmp,application/pdf",
			//maxFiles: 1,
			maxFilesize: 2,//max file size in MB,
			url: "general-photo_upload.php",
			paramName: "uploadfile",
			dictDefaultMessage : \'<span style="font-style:italic"><h1>Drop files to upload</h1><h3>(or click)</h3></span>\',
			init: function() {
				$.get("general-photo_upload.php", {peranan:"'.$my_details->user_level.'", uploadId:$(\'#dz_myID\').val(), generalName:"", uploadFolder:uploadPath}, function(data) {
					$.each(data, function(key,value){
						var mockFile = { name: value.name, size: value.size };				
						myDZ_'.$jsItem['input_name'].'.emit("addedfile", mockFile);
						if(value.name.trim().endsWith(".pdf"))
						{
							myDZ_'.$jsItem['input_name'].'.emit("thumbnail", mockFile, uploadPath + "/pdf.jpg");
						}
						else
						{
							myDZ_'.$jsItem['input_name'].'.emit("thumbnail", mockFile, uploadPath + "/" + $(\'#dz_myID\').val() + "/" + value.name);
						}
						myDZ_'.$jsItem['input_name'].'.emit("complete", mockFile);
						myDZ_'.$jsItem['input_name'].'.files.push(mockFile);
					});
				});
			}
		});';

		echo '
		myDZ_'.$jsItem['input_name'].'.on("error", function(file, errorMessage) {
			alert("ERROR " + errorMessage);
			myDZ_'.$jsItem['input_name'].'.removeFile(file);
		});

		myDZ_'.$jsItem['input_name'].'.on("success", function(file, photoPath) {
			file.previewElement.querySelector("[data-dz-name]").innerHTML = photoPath;
			console.log(photoPath);
			console.log(photoPath.trim().endsWith(".pdf"));
			if(photoPath.trim().endsWith(".pdf"))
			{
				myDZ_'.$jsItem['input_name'].'.emit("thumbnail", file, uploadPath + "/pdf.jpg");
			}
			else
			{
				myDZ_'.$jsItem['input_name'].'.emit("thumbnail", file, uploadPath + "/" + $(\'#dz_myID\').val() + "/" + photoPath);
			}
		});

		myDZ_'.$jsItem['input_name'].'.on("sending", function(file, xhr, formData){
			formData.append("uploadId", $(\'#dz_myID\').val());
			formData.append("program", '.$program.');
			//formData.append("generalName", "banner.jpg");
			formData.append("uploadFolder", uploadPath);
			//myDropzone.removeAllFiles(); //remove all 1st
		});
			
		myDZ_'.$jsItem['input_name'].'.on("dictRemoveFileConfirmation", function(file, xhr, formData){
			formData.append("uploadId", $(\'#dz_myID\').val());
		});

		myDZ_'.$jsItem['input_name'].'.on("addedfile", function(file) {
			var deleted = false;
			if(deleted == false)
			{
				file.previewElement.addEventListener("click", function() {
					var filesrc = uploadPath + "/" + $(\'#dz_myID\').val() + "/" + file.previewElement.querySelector(\'[data-dz-name]\').innerHTML.trim();
					if(filesrc.endsWith(".pdf"))
					{
						window.open(filesrc);
					}
					else
					{
						loadMyModal(\'general-photo_view.php?src="\' + filesrc + \'"\', \'#AE_large_photo-modal\');
					}
				});
				
				// Create the remove button
				var removeButton = Dropzone.createElement(\'<a class="btn btn-xs red"><i class="fa fa-trash-o"></i>Remove Image</a>\');

				// Listen to the click event
				removeButton.addEventListener("click", function(e) {
					e.preventDefault();
					e.stopPropagation();

					var deleteFileName = file.previewElement.querySelector(\'[data-dz-name]\').innerHTML;
					x = confirm("Are you sure to delete " + deleteFileName + "?");
					if(!x)  return false;
					var name = deleteFileName;                
					$.ajax({
						type: "POST",
						url: "general-photo_delete.php",
						data: "uploadId=" + $(\'#dz_myID\').val() + "&filename="+name+ "&uploadFolder=" + uploadPath,
						dataType: "html"
					});
					myDZ_'.$jsItem['input_name'].'.removeFile(file);
					$(\'#file_count_'.$jsItem['input_name'].'\').val(Number($(\'#file_count_'.$jsItem['input_name'].'\').val()) - 1);
				});

				file.previewElement.appendChild(removeButton);
				$(\'#file_count_'.$jsItem['input_name'].'\').val(Number($(\'#file_count_'.$jsItem['input_name'].'\').val()) + 1);
			}
		});';
echo '</script>'; 

?>
<script>
function checkUncheckCB_AE(callerId, btnId)
{
	if( $("#" + callerId).is(':checked')) {
        $( "#" + btnId ).prop( "disabled", false );
    }
	else
	{
		$( "#" + btnId ).prop( "disabled", true );
	}
}

function loadMyModal(url, target)
{
	console.log('load ' + url);
	console.log('target ' + target);
	$(target + '_content').empty();
	$(target + '_content').load(url,function(result){
		$(target).modal({show:true});
	});
}
$(document).ready(function(){  
	$('.kp_tb, .numonly, #borang_kpbaru_anakemas, #borang_no_akaun_anakemas').keypress(function(evt){
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if ((charCode >= 48 && charCode <= 57)) {
			return true;
		}
		return false;
	});
	
	$('.select2').select2({ width: '100%' }); 

	$('#borang_tkh_lahiranakemas').datepicker({
		autoclose: true,
		clearBtn: true,
		format: "dd-mm-yyyy",
		todayHighlight: true,
		orientation: "bottom left",
		templates: {
			leftArrow: '<i class="la la-angle-left"></i>',
			rightArrow: '<i class="la la-angle-right"></i>'
		}
	});

	$('#borang_kpbaru_anakemas').change(function(){
		var info = processKP($('#borang_kpbaru_anakemas').val());
		var a = moment();
		var b = moment(info[0], 'DD-MM-YYYY');
		var age = a.diff(b, 'years');
		var maxAge = 2;//change here ifneeded
		if(age >= maxAge)
		{
			$('#simpanBtn').prop("disabled",true);
			swal.fire({
				text: "Program ini terbuka kepada bayi berumur " + maxAge + " tahun kebawah sahaja",
				icon: "error",
				buttonsStyling: false,
				confirmButtonText: "OK!",
				customClass: {
					confirmButton: "btn font-weight-bold btn-light-primary"
				}
			}).then(function() {
			});
		}
		else
		{
			$.ajax({
				type: "POST", 
				url: "general-borang_tambah_anakemas_check.php", 
				data: 'myID=' + "<?=$myID?>" + '&mykid=' + $('#borang_kpbaru_anakemas').val(),

				success: function(res){
					if(res > 0)
					{
						$('#borang_tkh_lahiranakemas').datepicker( "setDate", info[0]);
						$('#borang_jantina_anakemas').val(info[1]);
						$('#borang_jantina_anakemas').trigger('change');
						$('#borang_tkh_lahiranakemas').prop('disabled', true);
						$('#borang_jantina_anakemas').prop('disabled', true);
						$('#simpanBtn').prop("disabled",false);
					}
					else
					{
						swal.fire({
							text: "Error. " + res,
							icon: "error",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							$('#simpanBtn').prop("disabled",true);										
						});
					}
				} 
			});  //end ajax
		}
	});
	$('#borang_tkh_lahiranakemas').prop('disabled', true);
	$('#borang_jantina_anakemas').prop('disabled', true);

	$('#borang_bank_anakemas').change(function(){
		var element = $(this).find('option:selected'); 
		var cTag1 = element.attr("cTag1"); 
		var cTag2 = element.attr("cTag2"); 
		$('#borang_no_akaun_anakemas').val('');
		$("#borang_no_akaun_anakemas").prop('minLength', cTag1);
		$("#borang_no_akaun_anakemas").prop('maxLength', cTag2);
	});
	$('#borang_bank').trigger('change');
	
	var mylevel = "<?=$my_details->user_level?>";
	$('#ae_submitBtn').click(function(){
		var indicator_list = [[]];
		indicator_list.push(['borang_carahantarae', 'Cara Hantar', 'dd']);
		
		if (checkInput(indicator_list))
		{
			if( $('#borang_carahantarae').val() == 2 && Number($('#file_count_anakemas_DZ').val()) < 1)
			{
				swal.fire({
					text: "Sila muat naik dokumen yang diperlukan",
					icon: "error",
					buttonsStyling: false,
					confirmButtonText: "OK!",
					customClass: {
						confirmButton: "btn font-weight-bold btn-light-primary"
					}
				}).then(function() {
					
				});
			}
			else
			{
				Swal.fire({
					text: "Adakah anda pasti maklumat telah lengkap?.",
					icon: "success",
					showCancelButton: true,
					buttonsStyling: false,
					confirmButtonText: "Ya dan Hantar!",
					cancelButtonText: "Batal",
					customClass: {
						confirmButton: "btn font-weight-bold btn-primary",
						cancelButton: "btn font-weight-bold btn-default"
					}
				}).then(function (result) {
					if (result.value) {
						var param = 'id_anakemas=' + $('#dz_myID').val() + '&borang_carahantarae=' + $('#borang_carahantarae').val();
						$.ajax({
							type: "POST", 
							url: "general-borang_tambah_anakemas_akuan.php", 
							data: param,
							success: function(res){
								if(res > 0)
								{
									swal.fire({
										text: "Permohonan berjaya. Sila Cetak dan Hantar Borang Permohonan Anak Emas Yang Lengkap Dengan Lampirannya ke Pejabat Daerah & Tanah berhampiran. Permohonan Tidak Akan Diproses Tanpa Penghantaran Borang Permohonan yang Lengkap",
										icon: "success",
										buttonsStyling: false,
										confirmButtonText: "OK!",
										customClass: {
											confirmButton: "btn font-weight-bold btn-light-primary"
										}
									}).then(function() {
										$("#closeBtn").click();
										//$('#' + "<?=$reloadBtn?>").click();
										if(mylevel == 10)
										{
											window.location.href = "index_pemohon.php";
										}
										else
										{
											//window.location.href = "p05_terima.php";									
											window.location.reload;									
										}
									});
								}
								else
								{
									swal.fire({
										text: "Error. " + res,
										icon: "error",
										buttonsStyling: false,
										confirmButtonText: "OK!",
										customClass: {
											confirmButton: "btn font-weight-bold btn-light-primary"
										}
									}).then(function() {
										
									});
								}
								
							} 
						});  //end ajax
					} else if (result.dismiss === 'cancel') {
						Swal.fire({
							text: "Permohonan ini tidak diteruskan!.",
							icon: "error",
							buttonsStyling: false,
							confirmButtonText: "Ok!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-primary",
							}
						});
					}
				});
			}
		}
	});	
	
	$('#simpandocBtn').click(function() {
		$('#akuan-tab').click();
	});	
	
	$('#simpanBtn').click(function() {
		var formValidator = JSON.parse($('#formValidator_' + "<?=$uniqueId?>").val());
		console.log(formValidator);
		if (formValidator == null || checkInput(formValidator))
		{
			var saveAction = $('#saveAction_' + "<?=$uniqueId?>").val();
			if(saveAction != null)
			{
				//script_url<BRE>borang_div<BRE>table_name<BRE>id_table<BRE>id_insert<BRE>id_update
				var actions = saveAction.split("<BRE>");
				$(this).prop("disabled",true);
				var disabled = $('#indicator_form_' + "<?=$uniqueId?>").find(':input:disabled').removeAttr('disabled');
				var param = $('#indicator_form_' + "<?=$uniqueId?>").serialize();
				disabled.attr('disabled', 'disabled');
				param += '&type=2';
				param += '&current_id=' + "<?=$myID?>";
				param += '&program=' + $('#id_borang_program').val();
				param += '&id_pemohon=' + $('#id_pemohon_borang').val();
				param += '&borangitem=' + actions[1];
				param += '&table=' + actions[2];
				if(actions.length >= 3) param += '&id_table=' + actions[3];
				if(actions.length >= 4) param += '&id_insert=' + actions[4];
				if(actions.length >= 5) param += '&id_update=' + actions[5];
				$.ajax({
					type: "POST", 
					url: "general-borang_insert.php", 
					data: param,

					success: function(res){
						if(res > 0)
						{
							$(this).prop("disabled",false);
							$('#document-tab').removeClass( "disabled" );
							$('#akuan-tab').removeClass( "disabled" );
							$('#document-tab').click();
							$('#dz_myID').val(res);
							$('#' + "<?=$reloadBtn?>").click();
							/*
							swal.fire({
								text: "Berjaya Kemaskini Maklumat",
								icon: "success",
								buttonsStyling: false,
								confirmButtonText: "OK!",
								customClass: {
									confirmButton: "btn font-weight-bold btn-light-primary"
								}
							}).then(function() {
								//$('#' + "<?=$reloadBtn?>").click();
								//window.parent.reloadTable();
								//$("#closeBtn").click();
								$('#document-tab').removeClass( "disabled" );
								$('#akuan-tab').removeClass( "disabled" );
								$('#document-tab').click();
							});
							*/
						}
						else
						{
							swal.fire({
								text: "Error. " + res,
								icon: "error",
								buttonsStyling: false,
								confirmButtonText: "OK!",
								customClass: {
									confirmButton: "btn font-weight-bold btn-light-primary"
								}
							}).then(function() {
								$(this).prop("disabled",false);										
							});
						}
						
					} 
				});  //end ajax
			}
		}
	});		
});		
</script>