<script type="text/javascript">
/*
	function to construct form for editing 
	[todo]
		1. this function can be improved, to avoid repetitive 
*/
function formConstruct() {

	//---------------
	//addresss
	//
	var address_string = '<?php echo(!empty($addresses))?json_encode($addresses):""; ?>';
	console.log('address_string');
	console.log(address_string);
	if(address_string){
		var stored_address = JSON.parse(address_string);
		if(stored_address){
			$.each(stored_address,function(index,value){
				var list = {
					id : value.id,
					user_id : value.user_id,
					type : value.type,
					address : value.address,
					postcode : value.postcode,
					city : value.city,
					// state : value.state_name,
					// country : value.country_name,
					state: value.state_id,
					country : value.country_id,
					contact_header :'',
					contact_number : value.contact_no,
				};
				addressList.push(list);
			});
			createtable('#tbl-address');
		}
	}
	//---------------


	//---------------
	//family information
	//
	var family_info = '<?php echo(!empty($family_info))?json_encode($family_info):"";?>';
	if(family_info){
		var stored_families = JSON.parse(family_info);
		if(stored_families){
			$.each(stored_families,function(index,value){
				var list = {
					id : value.id,
					user_id : value.user_id,
					ic_no : value.ic_no,
					address : value.address,
					birthdate : value.birthdate,
					contact_header : '',
					contact_no : value.phone_no,
					email : value.email,
					academic_level : value.academic_lavel,
					academic_institution : value.academic_institution,
					name : value.name,
					relation : value.relation,
					occupation : value.occupation,
					oku_status : value.oku_status,
					student_status : value.study_status,
				}
				familyList.push(list);
			});
			createtable('#tbl-familyInfo');
		}
	}
	//---------------


	//---------------
	//academic qualification
	//
	var academic_qualification = '<?php echo (!empty($academic_qualification))?json_encode($academic_qualification):""; ?>';
	if(academic_qualification){
		var stored_academic = JSON.parse(academic_qualification);
		console.log('stored_academic');
		console.log(stored_academic);
		if(stored_academic){
			$.each(stored_academic,function(index,value){
				var mask_id = (value.mask_id).split('->');
				var maskID = '';

				$.each(mask_id, function(key,row){
					maskID += '<li>'+row+'</li>';
				});
				
				if(maskID){
					table = {
						orig_name : maskID,
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}
				// if(value.mask_id){
				// 	table = {
				// 		orig_name : value.mask_id
				// 	}
				// }else{
				// 	table = {
				// 		error : '<b>no image</b>',
				// 	}
				// }
				
				var list = {
					id : value.id,
					user_id: value.user_id,
					level_id: value.level_id,
					program: value.program,
					institution: value.institution,
					year: value.year,
					cgpa:value.cgpa,
					table: JSON.stringify(table),
				};

				academicList.push(list);
			});
			createtable('#tbl-academicQualification');
		}
	}
	//---------------


	//--------------
	//personal attachment
	//
	var add_personal_data = '<?php echo (!empty($additional_personal_data))?json_encode($additional_personal_data):""; ?>';
	if(add_personal_data){
		var stored_personal = JSON.parse(add_personal_data);
		if(stored_personal){
			$.each(stored_personal,function(index,value){

				if(value.mask_id){
					table = {
						orig_name : value.attachment_name,
						location : value.location,
						file_name : value.attachment_name,
						file_type : value.file_type,
						file_ext : value.file_ext,
						mask_id : value.mask_id,
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}
				
				var list = {
					id : value.id,
					user_id : value.user_id,
					detail : value.detail,
					description : value.description,
					table : JSON.stringify(table),
				};

				additionalPersonalList.push(list);
			});
			createtable('#tbl-personalData');
		}  
	}
	//--------------


	//--------------
	//previous employment details
	//
	var prev_jobs = '<?php echo (!empty($previous_employment_history))?json_encode($previous_employment_history):""; ?>';
	if(prev_jobs){
		var stored_jobs = JSON.parse(prev_jobs);
		console.log(stored_jobs);
		if(stored_jobs){
			$.each(stored_jobs,function(index,value){
				var list = {
					id: value.id,
					user_id: value.user_id,
					employer_name:value.employer_name,
					employer_address:value.employer_address,
					position:value.position,
					date_enter:value.date_enter,
					date_exit:value.date_exit,
					length_of_service:value.length_of_service,
					description:value.description,
				};
				prevEmpList.push(list);
			});
			createtable('#tbl-previousEmployment');
		}
	}
	//--------------


	//--------------
	//profesional memberships
	//	
	var professional_membership = '<?php echo (!empty($professional_membership))?json_encode($professional_membership):""; ?>';
	if(professional_membership){
		var stored_membership = JSON.parse(professional_membership);
		if(stored_membership){
			$.each(stored_membership,function(index,value){

				if(value.mask_id){
					table = {
						orig_name : value.mask_id
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}

				var list = {
					id: value.id,
					user_id : value.user_id,
					professional_body : value.professional_body,
					certificate : value.certificate,
					membership : value.membership,
					membership_no : value.membership_no,
					year : value.year,
					table : JSON.stringify(table),
				};
				proMembershipList.push(list);
			});
			createtable('#tbl-professionalMembership');
		}
	}
	//--------------


	//--------------
	//professional license
	//
	var professional_license = '<?php echo (!empty($professional_license))?json_encode($professional_license):""; ?>';
	if(professional_license){
		var stored_license = JSON.parse(professional_license);
		if(stored_license){
			$.each(stored_license,function(index,value){

				console.log('value for the pro license');
				console.log(value);

				if(value.mask_id){
					table = {
						orig_name : value.mask_id
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}


				var list = {
					id : value.id,
					user_id : value.user_id,
					profession: value.profession,
					license_no: value.license_no,
					license_body_authority: value.license_body_authority,
					register_date: value.register_date,
					renewal_date: value.renewal_date,
					next_renewal_date: value.next_renewal_date,
					table:JSON.stringify(table),
				}
				proLicenseList.push(list);
			});
			createtable('#tbl-professionalLicense');
		}
	}
	//--------------


	//--------------
	//recognition
	//
	var recognition = '<?php echo (!empty($recognition))?json_encode($recognition):""; ?>';
	if(recognition){
		var stored_recognition = JSON.parse(recognition);
		if(stored_recognition){
			$.each(stored_recognition,function(index,value){

				console.log('value for recognition');
				console.log(value);

				if(value.mask_id){
					table = {
						orig_name : value.mask_id
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}

				var list = {
					id: value.id,
					user_id:value.user_id,
					achievement:value.achievement,
					award:value.award,
					year:value.year,
					table:JSON.stringify(table),
				}
				recognitionList.push(list);
			});
			createtable('#tbl-recognition');
		}
	}
	//--------------

	//--------------
	//bank details
	//
	var bank_details = '<?php echo (!empty($bank_details))?json_encode($bank_details):""; ?>';
	if(bank_details){
		var stored_bank = JSON.parse(bank_details);
		if(stored_bank){
			$.each(stored_bank,function(index,value){

				console.log('value for bank details');
				console.log(value);

				if(value.mask_id){
					table = {
						orig_name : value.mask_id
					}
				}else{
					table = {
						error : '<b>no image</b>',
					}
				}

				var list = {
					id : value.id,
					user_id : value.user_id,
					bank_id : value.bank_id,
					branch  : value.branch,
					acc_no  : value.acc_no,
					status  : value.status,
					table   : JSON.stringify(table),
				}

				bankList.push(list);
			});
			createtable('#tbl-bankDetail');
		}
	}
	//--------------

	//--------------
	//recurring payments
	//
	var recur_payments = '<?php echo (!empty($recurring_payments))?json_encode($recurring_payments):""; ?>';
	if(recur_payments){
		stored_recur_payments = JSON.parse(recur_payments);
		if(stored_recur_payments){
			$.each(stored_recur_payments,function(index,value){
				var list = {
					id:value.id,
					user_id:value.user_id,
					date_from:value.date_start,
					date_to:value.date_end,
					recurring:value.recurring_type,
					type:value.type,
					amount:value.amount,
					status:value.status,
				};
			recurList.push(list);
			});
			createtable('#tbl-recurring');
		}
	}
	//--------------


	//--------------
	//recurring deduction
	//	
	var recur_deduction = '<?php echo (!empty($recurring_deductions))?json_encode($recurring_deductions):""; ?>';
	if(recur_deduction){
		stored_deduction = JSON.parse(recur_deduction);
		if(stored_deduction){
			$.each(stored_deduction,function(index,value){
				var list = {
					id:value.id,
					user_id:value.user_id,
					date_from:value.date_start,
					date_to:value.date_end,
					recurring:value.recurring_type,
					type:value.type,
					amount:value.amount,
					status:value.status,
				};
				recurList.push(list);
			});
			createtable('#tbl-recurring');
		}
	}
	//--------------


	//--------------
	//third party payments
	//
	var third_party = '<?php echo (!empty($third_party_payments))?json_encode($third_party_payments):""; ?>';
	if(third_party){
		third_party_payments = JSON.parse(third_party);
		if(third_party_payments){
			$.each(third_party_payments,function(index,value){
				var list = {
					id:value.id,
					user_id:value.user_id,
					date_start:value.date_start,
					date_end:value.date_end,
					type:value.type,
					amount:value.amount,
					status:value.status,
				}
				thirdPartyList.push(list);

			});
			createtable('#tbl-thirdParty');
		}
	}
	//--------------

	//--------------
	//education in progress
	//	
	var pursuing_study = '<?php echo (!empty($pursuing_study))?json_encode($pursuing_study):""; ?>';
	if(pursuing_study){
		var stored_pursuing_study = JSON.parse(pursuing_study);
		if(stored_pursuing_study){
			$.each(stored_pursuing_study,function(index,value){
				// if(value.status == 0)
				// {
				// 	var status = 'On Going';
				// }
				var list = {
					id: value.id,
					user_id : value.user_id,
					date_start : value.date_start,
					date_end : value.date_end,
					progress_paper : value.progress_paper,
					institution : value.institution,
					program : value.program,
					status : value.status,
					table : JSON.stringify(table),
				};
				eipList.push(list);
			});
			createtable('#tbl-educationInProgress');
		}
	}
	//--------------

	//--------------
	//emergency contact
	//	
	var emergency_contact = '<?php echo (!empty($emergency_contact))?json_encode($emergency_contact):""; ?>';
	if(emergency_contact){
		var stored_emergency_contact = JSON.parse(emergency_contact);
		if(stored_emergency_contact){
			$.each(stored_emergency_contact,function(index,value){
				var list = {
					id: value.id,
					user_id : value.user_id,
					name : value.name,
					relation : value.relation,
					phone : value.phone_no,
					email : value.email,
					address : value.address,
					table : JSON.stringify(table),
				};
				ecList.push(list);
			});
			createtable('#tbl-emergencyContact');
		}
	}
	//--------------

	//--------------
	//professional education
	//	
	var professional_academic = '<?php echo (!empty($professional_academic))?json_encode($professional_academic):""; ?>';
	if(professional_academic){
		var stored_professional_academic = JSON.parse(professional_academic);
		if(stored_professional_academic){
			$.each(stored_professional_academic,function(index,value){
				if(value.type == 0){
					if(value.mask_id){
						table = {
							orig_name : value.mask_id
						}
					}else{
						table = {
							error : '<b>no image</b>',
						}
					}
					
					var list = {
						id: value.id,
						user_id : value.user_id,
						type : value.type,
						level : value.level,
						associate_name : value.associate_name,
						program : value.program,
						date_finish : value.date_finish,
						result : value.result,
						table : JSON.stringify(table),
					};
					proEducationList.push(list);
				}
			});
			createtable('#tbl-professionalEducation');
		}
	}
	//--------------

	//--------------
	//professional education
	//	
	var professional_academic = '<?php echo (!empty($professional_academic))?json_encode($professional_academic):""; ?>';
	if(professional_academic){
		var stored_professional_academic = JSON.parse(professional_academic);
		if(stored_professional_academic){
			$.each(stored_professional_academic,function(index,value){
				if(value.type == 1){
					if(value.mask_id){
						table = {
							orig_name : value.mask_id
						}
					}else{
						table = {
							error : '<b>no image</b>',
						}
					}

					var list = {
						id: value.id,
						user_id : value.user_id,
						type : value.type,
						associate_name : value.associate_name,
						program : value.program,
						date_finish : value.date_finish,
						result : value.result,
						table : JSON.stringify(table),
					};
					proCertificateList.push(list);
				}
			});
			createtable('#tbl-professionalCertificate');
		}
	}
	//--------------
}

/*
	populate modal

	todo 
		- dropdown issue
		1. contact number 
		2. length of service 
*/
var dataset_key = null;


function editAddress(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key	= $(elem).data('key');

	$('#edit_address_type').val(content.type);
	$('#edit_address').val(content.address);
	$('#edit_address_postcode').val(content.postcode);
	$('#edit_address_city').val(content.city)
	$('#edit_address_state').val(content.state);
	$('#edit_address_country').val(content.country);
	$('#edit_address_contact_number').val(content.contact_number);
	console.log(content);
}

function editFamilyInfo(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key	= $(elem).data('key');
	$('#edit_family_name').val(content.name);
	$('#edit_family_nric').val(content.ic_no);
	$('#edit_family_birthdate').val(content.birthdate);
	$('#edit_family_relation').val(content.relation);
	$('#edit_family_contact_number').val(content.contact_no);
	$('#edit_family_email').val(content.email);
	$('#edit_family_address').val(content.address); 
	$('#edit_family_oku_status').val(content.oku_status);
	$('#edit_family_student_status').val(content.student_status);
	$('#edit_family_occupation').val(content.occupation);
	$('#edit_family_academic_level').val(content.academic_level);
	$('#edit_family_academic_insitution').val(content.academic_institution);

	console.log(content);
}

function editAQualification(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key	= $(elem).data('key');

	$('#edit_academic_qualification_level').val(content.level_id);
	$('#edit_academic_qualification_year_graduate').val(content.year);
	$('#edit_academic_qualification_institution').val(content.institution);
	$('#edit_academic_qualification_program').val(content.program);
	console.log(content);
}

function editPersonalData(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_personal_data_detail').val(content.detail);
	$('#edit_personal_data_description').val(content.description);

	console.log(content);
}

function editPreviousEmpHistory(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_prev_emp_date_join').val(content.date_enter);
	$('#edit_prev_emp_date_to').val(content.date_exit);
	$('#edit_prev_emp_name').val(content.employer_name);
	$('#edit_prev_emp_address').val(content.employer_address);
	$('#edit_prev_emp_position').val(content.position);
	$('#edit_prev_emp_los').val(content.length_of_service);	
	$('#edit_prev_emp_description').val(content.description);

	console.log(content);
}

function editProfessionalMembership(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_professional_membership_bodies').val(content.professional_body);
	$('#edit_professional_membership_certificate').val(content.certificate);
	$('#edit_professional_membership').val(content.membership);
	$('#edit_professional_membership_number').val(content.membership_no);
	$('#edit_professional_membership_year').val(content.year);

	console.log(content);
}

function editProfessionalLicense(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_pro_license_profession').val(content.profession);
	$('#edit_pro_license_no').val(content.license_no);
	$('#edit_pro_license_body_authority').val(content.license_body_authority);
	$('#edit_pro_license_reg_date').val(content.register_date);
	$('#edit_pro_license_renewal_date').val(content.renewal_date);
	$('#edit_pro_license_next_renewal_date').val(content.next_renewal_date);

	console.log(content);
}

function editRecognition(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_recognition_achievement').val(content.achievement);
	$('#edit_recognition_award').val(content.award);
	$('#edit_recognition_year').val(content.year);

	console.log(content);
}

function editBankDetail(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_bank_detail_name').val(content.bank_id);
	$('#edit_bank_detail_branch').val(content.branch);
	$('#edit_bank_detail_acct_no').val(content.acc_no);
	$('#edit_bank_detail_status').val(content.status);

	console.log(content);
}

/*
	todo 
		1. status not updated
*/
function editRecurring(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_recurring_date_from').val(content.date_from);
	$('#edit_recurring_date_to').val(content.date_to);
	$('#edit_recurring').val(content.recurring);
	$('#edit_recurring_type').val(content.type);
	$('#edit_recurring_amount').val(content.amount);

	console.log(content);
}

function editThirdParty(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_third_party_date_from').val(content.date_start);
	$('#edit_third_party_date_to').val(content.date_end);
	$('#edit_third_party_institution').val(content.type);
	$('#edit_third_party_amount').val(content.amount);
	$('#edit_third_party_status').val(content.status);

	console.log(content);
}

function editEducationInProgress(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_eip_date_start').val(content.date_start);
	$('#edit_eip_date_end').val(content.date_end);
	$('#edit_eip_institution').val(content.institution);
	$('#edit_eip_program').val(content.program);
	$('#edit_eip_progress_paper').val(content.progress_paper);
	$('#edit_eip_status').val(content.status);

	console.log(content);
}

function editEmergencyContact(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_ec_name').val(content.name);
	$('#edit_ec_relation').val(content.relation);
	$('#edit_ec_phone').val(content.phone);
	$('#edit_ec_email').val(content.email);
	$('#edit_ec_address').val(content.address);

	console.log(content);
}

function editProfessionalEducation(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_professional_education_associate_name').val(content.associate_name);
	$('#edit_professional_education_program').val(content.program);
	$('#edit_professional_education_date_finish').val(content.date_finish);
	$('#edit_professional_education_result').val(content.result);

	console.log(content);
}

function editProfessionalCertificate(elem) {
	var content = JSON.parse(atob($(elem).data('content')));
	dataset_key = $(elem).data('key');

	$('#edit_professional_certificate_associate_name').val(content.associate_name);
	$('#edit_professional_certificate_program').val(content.program);
	$('#edit_professional_certificate_date_finish').val(content.date_finish);
	$('#edit_professional_certificate_result').val(content.result);

	console.log(content);
}







/*
	change value of dataset to save
*/

/*
	todo 
		1. country name and state should be id not name.
		2. contact no
*/
function updateAddress() {
	console.log('update address dataset, key : '+dataset_key);
	console.log(addressList);

	//addresses --
	addressList[dataset_key].address 		= $('#edit_address').val();
	addressList[dataset_key].city 			= $('#edit_address_city').val();
	addressList[dataset_key].contact_number = $('#edit_address_contact_number').val();
	addressList[dataset_key].country 		= $('#edit_address_country').val();
	addressList[dataset_key].postcode 		= $('#edit_address_postcode').val();
	addressList[dataset_key].state 			= $('#edit_address_state').val();
	addressList[dataset_key].type 			= $('#edit_address_type').val();

	createtable('#tbl-address');
}

/*
	todo 
		1. contact number
*/
function updateFamilyInfo() {
	console.log('update family information dataset, key : '+dataset_key);
	console.log(familyList);

	familyList[dataset_key].academic_institution 	= $('#edit_family_academic_insitution').val();
	familyList[dataset_key].academic_level 			= $('#edit_family_academic_level').val();
	familyList[dataset_key].address 				= $('#edit_family_address').val();
	familyList[dataset_key].birthdate 				= $('#edit_family_birthdate').val();
	familyList[dataset_key].contact_no  			= $('#edit_family_contact_number').val();
	familyList[dataset_key].email 					= $('#edit_family_email').val();
	familyList[dataset_key].ic_no 					= $('#edit_family_nric').val();
	familyList[dataset_key].name 					= $('#edit_family_name').val();
	familyList[dataset_key].occupation 				= $('#edit_family_occupation').val();
	familyList[dataset_key].oku_status 				= $('#edit_family_oku_status').val();
	familyList[dataset_key].relation 				= $('#edit_family_relation').val();
	familyList[dataset_key].student_status 			= $('#edit_family_student_status').val();

	createtable('#tbl-familyInfo');
}

/*
	todo 
		1. no attachment in edit modal 
*/
function updateAcademicQualification() {
	console.log('update academic qualification, key : '+dataset_key);
	console.log(academicList);

	academicList[dataset_key].institution 	= $('#edit_academic_qualification_institution').val();
	academicList[dataset_key].level_id  	= $('#edit_academic_qualification_level').val();
	academicList[dataset_key].program 		= $('#edit_academic_qualification_program').val();
	academicList[dataset_key].year 			= $('#edit_academic_qualification_year_graduate').val();

	createtable('#tbl-academicQualification');
}

/*
	todo 
		1. update attachment not done
*/
function updatePersonalData() {
	console.log('update personal data dataset, key : '+dataset_key);
	console.log(additionalPersonalList);

	additionalPersonalList[dataset_key].detail 		= $('#edit_personal_data_detail').val();
	additionalPersonalList[dataset_key].description 	= $('#edit_personal_data_description').val();

	createtable('#tbl-personalData');
}

/*
	todo 
		1. length of service no combobox in edit modal
*/
function updatePreviousEmployment(){
	console.log('update previous employment history, key : '+dataset_key);
	console.log(prevEmpList);

	prevEmpList[dataset_key].date_enter 		= $('#edit_prev_emp_date_join').val();
	prevEmpList[dataset_key].date_exit 			= $('#edit_prev_emp_date_to').val();
	prevEmpList[dataset_key].description 		= $('#edit_prev_emp_description').val();
	prevEmpList[dataset_key].employer_address 	= $('#edit_prev_emp_address').val();
	prevEmpList[dataset_key].employer_name 		= $('#edit_prev_emp_name').val();
	prevEmpList[dataset_key].length_of_service 	= $('#edit_prev_emp_los').val();
	prevEmpList[dataset_key].position 			= $('#edit_prev_emp_position').val();

	createtable('#tbl-previousEmployment');
}


/*
	todo 
		1. attachment 
*/
function updateProfessionalMembership() {
	console.log('update personal membership, key : '+dataset_key);
	console.log(proMembershipList);

	proMembershipList[dataset_key].certificate 		 = $('#edit_professional_membership_certificate').val();
	proMembershipList[dataset_key].membership  		 = $('#edit_professional_membership').val();
	proMembershipList[dataset_key].membership_no 	 = $('#edit_professional_membership_number').val();
	proMembershipList[dataset_key].professional_body = $('#edit_professional_membership_bodies').val();
	proMembershipList[dataset_key].year 			 = $('#edit_professional_membership_year').val();

	createtable('#tbl-professionalMembership');
}

/*
	todo 
		1. attachment
*/
function updateProfessionalLicense() {
	console.log('update professional license, key : '+dataset_key);
	console.log(proLicenseList);

	proLicenseList[dataset_key].license_no 				= $('#edit_pro_license_no').val();
	proLicenseList[dataset_key].profession 				= $('#edit_pro_license_profession').val();
	proLicenseList[dataset_key].license_body_authority 	= $('#edit_pro_license_body_authority').val();
	proLicenseList[dataset_key].register_date 			= $('#edit_pro_license_reg_date').val();
	proLicenseList[dataset_key].renewal_date 			= $('#edit_pro_license_renewal_date').val();
	proLicenseList[dataset_key].next_renewal_date 		= $('#edit_pro_license_next_renewal_date').val();

	createtable('#tbl-professionalLicense');
}

/*
	todo 
		1. attachment
*/
function updateRecognition() {
	console.log('update recognition, key : '+dataset_key);
	console.log(recognitionList);

	recognitionList[dataset_key].achievement 	= $('#edit_recognition_achievement').val();
	recognitionList[dataset_key].award 			= $('#edit_recognition_award').val();
	recognitionList[dataset_key].year 			= $('#edit_recognition_year').val();

	createtable('#tbl-recognition');
}

/*
	todo 
		1. attachment
*/
function updateBank() {
	console.log('update bank, key : '+dataset_key);
	console.log(bankList);

	bankList[dataset_key].acc_no 	= $('#edit_bank_detail_acct_no').val();
	bankList[dataset_key].bank_id	= $('#edit_bank_detail_name').val();
	bankList[dataset_key].branch 	= $('#edit_bank_detail_branch').val();
	bankList[dataset_key].status 	= $('#edit_bank_detail_status').val();

	createtable('#tbl-bankDetail');
}

function updateRecurring() {
	console.log('update recurring, key : '+dataset_key);
	console.log(recurList);

	recurList[dataset_key].amount 		= $('#edit_recurring_amount').val();
	recurList[dataset_key].date_from	= $('#edit_recurring_date_from').val();
	recurList[dataset_key].date_to 		= $('#edit_recurring_date_to').val();
	recurList[dataset_key].recurring 	= $('#edit_recurring').val();
	recurList[dataset_key].status 		= $('#edit_recurring_status').val();
	recurList[dataset_key].type 		= $('#edit_recurring_type').val();

	createtable('#tbl-recurring');
}

function updateThirdParty() {
	console.log('update third party, key : '+dataset_key);
	console.log(thirdPartyList);

	thirdPartyList[dataset_key].amount 		= $('#edit_third_party_amount').val();
	thirdPartyList[dataset_key].date_end	= $('#edit_third_party_date_to').val();
	thirdPartyList[dataset_key].date_start 	= $('#edit_third_party_date_from').val();
	thirdPartyList[dataset_key].status 		= $('#edit_third_party_status').val();
	thirdPartyList[dataset_key].type 		= $('#edit_third_party_institution').val();

	createtable('#tbl-thirdParty');
}

function updateEducationInProgress() {
	console.log('update education in progress, key : '+dataset_key);
	console.log(eipList);

	// if($('#edit_eip_status').val() == 0)
	// {
	// 	var status = 'On Going';
	// }

	eipList[dataset_key].program 			= $('#edit_eip_program').val();
	eipList[dataset_key].institution 		= $('#edit_eip_institution').val();
	eipList[dataset_key].progress_paper 	= $('#edit_eip_progress_paper').val();
	eipList[dataset_key].date_start 		= $('#edit_eip_date_start').val();
	eipList[dataset_key].date_end 			= $('#edit_eip_date_end').val();
	eipList[dataset_key].status 			= $('#edit_eip_status').val();

	createtable('#tbl-educationInProgress');
}

function updateEmergencyContact() {
	console.log('update mergency contact, key : '+dataset_key);
	console.log(ecList);

	ecList[dataset_key].name			= $('#edit_ec_name').val();
	ecList[dataset_key].relation		= $('#edit_ec_relation').val();
	ecList[dataset_key].phone			= $('#edit_ec_phone').val();
	ecList[dataset_key].email			= $('#edit_ec_email').val();
	ecList[dataset_key].address			= $('#edit_ec_address').val();

	createtable('#tbl-emergencyContact');
}

function updateProfessionalEducation() {
	console.log('update professional education, key : '+dataset_key);
	console.log(proEducationList);

	proEducationList[dataset_key].associate_name	= $('#edit_professional_education_associate_name').val();
	proEducationList[dataset_key].program			= $('#edit_professional_education_program').val();
	proEducationList[dataset_key].date_finish		= $('#edit_professional_education_date_finish').val();
	proEducationList[dataset_key].result			= $('#edit_professional_education_result').val();

	createtable('#tbl-professionalEducation');
}

function updateProfessionalCertificate() {
	console.log('update professional certificate, key : '+dataset_key);
	console.log(proCertificateList);

	proCertificateList[dataset_key].associate_name	= $('#edit_professional_certificate_associate_name').val();
	proCertificateList[dataset_key].program			= $('#edit_professional_certificate_program').val();
	proCertificateList[dataset_key].date_finish		= $('#edit_professional_certificate_date_finish').val();
	proCertificateList[dataset_key].result			= $('#edit_professional_certificate_result').val();

	createtable('#tbl-professionalCertificate');
}

</script>