var mods 			=	$('#main_page').val();
var types 			=	$('#main_type').val(); 
var action 			=	$('#main_action').val();
if(mods=="reservation" && types=="checklist_of_requirements" && (action=="edit" || action=="view")){
	load_checklist_details(); 
}


//AUG 28, 2021 TO TICK COMPLETED DOCUMENTARY REQUIREMENTS IF ALL ARE CHECKED ABOVE
$(".standardreq").change(function(){
	var len  = $('.standardreq').length - 1;
	var clen = $('.standardreq:checked').length; 

	//STANDARD REQUIREMENTS
    if(len!==clen){
    	$('.completed_documentary_requirement').attr('checked', false); // Unchecks it
    	$('.completed_documentary_requirement').prop('checked', false); // Unchecks it
 	}else if(len==clen){
    	$('.completed_documentary_requirement').attr('checked', true); // checks it
    	$('.completed_documentary_requirement').prop('checked', true); // checks it
 	}else if(len>clen){
    	$('.completed_documentary_requirement').attr('checked', true); // checks it
    	$('.completed_documentary_requirement').prop('checked', true); // checks it
 	} 
   
});

 
$(".bankstandardreq").change(function(){
	 
	//STANDARD REQUIREMENTS BANK FINANCING 
	var bankreqs = [];

	$('.bankstandardreq:checked').each(function () {
       var checkVal = (this.checked ? $(this).val() : "");

       		if(jQuery.inArray(checkVal, bankreqs)==-1){
       			bankreqs.push(checkVal);	
       		} 
  	});


  	        var isSingleCenomar = jQuery.inArray("single_cenomar", bankreqs);
  	        var isBarangay 		= jQuery.inArray("barangay_certificate", bankreqs);
  	        var isValidId 		= jQuery.inArray("valid_id", bankreqs);
  	        var isIdPhoto 		= jQuery.inArray("id_photo", bankreqs);

  	        var isMarried 		= jQuery.inArray("married_psa", bankreqs);
  	        var isValidSpouse	= jQuery.inArray("valid_id_spouse", bankreqs);
  	        var isProof 		= jQuery.inArray("proof_of_income", bankreqs);
 
       if(isSingleCenomar!==-1 && isBarangay!=-1 && isValidId!=-1 && isIdPhoto!=-1){
       		$('.completed_documentary_requirement_bank').attr('checked', true); // checks it
    		$('.completed_documentary_requirement_bank').prop('checked', true); // checks it
       }else if(isMarried!=-1 && isBarangay!=-1 && isValidId!=-1 && isIdPhoto!=-1 && isValidSpouse!=-1 && isProof!=-1){
       		$('.completed_documentary_requirement_bank').attr('checked', true); // checks it
    		$('.completed_documentary_requirement_bank').prop('checked', true); // checks it
       }else{
       		$('.completed_documentary_requirement_bank').attr('checked', false); // Unchecks it
    		$('.completed_documentary_requirement_bank').prop('checked', false); // Unchecks it
       }
  	 
});

isBankReqComplete();
function isBankReqComplete(){
	//STANDARD REQUIREMENTS BANK FINANCING 
	var bankreqs = [];

	$('.bankstandardreq:checked').each(function () {
       var checkVal = (this.checked ? $(this).val() : "");

       		if(jQuery.inArray(checkVal, bankreqs)==-1){
       			bankreqs.push(checkVal);	
       		} 
  	});


  	        var isSingleCenomar = jQuery.inArray("single_cenomar", bankreqs);
  	        var isBarangay 		= jQuery.inArray("barangay_certificate", bankreqs);
  	        var isValidId 		= jQuery.inArray("valid_id", bankreqs);
  	        var isIdPhoto 		= jQuery.inArray("id_photo", bankreqs);

  	        var isMarried 		= jQuery.inArray("married_psa", bankreqs);
  	        var isValidSpouse	= jQuery.inArray("valid_id_spouse", bankreqs);
  	        var isProof 		= jQuery.inArray("proof_of_income", bankreqs);
 
       if(isSingleCenomar!==-1 && isBarangay!=-1 && isValidId!=-1 && isIdPhoto!=-1){
       		$('.completed_documentary_requirement_bank').attr('checked', true); // checks it
    		$('.completed_documentary_requirement_bank').prop('checked', true); // checks it
       }else if(isMarried!=-1 && isBarangay!=-1 && isValidId!=-1 && isIdPhoto!=-1 && isValidSpouse!=-1 && isProof!=-1){
       		$('.completed_documentary_requirement_bank').attr('checked', true); // checks it
    		$('.completed_documentary_requirement_bank').prop('checked', true); // checks it
       }else{
       		$('.completed_documentary_requirement_bank').attr('checked', false); // Unchecks it
    		$('.completed_documentary_requirement_bank').prop('checked', false); // Unchecks it
       }
}
//AUG 28, 2021 TO TICK COMPLETED DOCUMENTARY REQUIREMENTS IF ALL ARE CHECKED ABOVE


/***exceed 6 months**********/
function checkDateWithinRange(checkDateId){
	var checkDate			= 	$(checkDateId).val();
	var curDate				=	moment().format('MM/DD/YYYY'); 
	var curDateSixAgo		=	moment().subtract(6, 'months').format('MM/DD/YYYY'); 
	var diffDate			= 	moment(checkDate).isBetween(curDateSixAgo, curDate); 
	if(diffDate==false && (curDate!=checkDate)){
	  bootbox.alert("Document date submitted exceeded 6 months");
	  $(checkDateId).val("");
	  exit;
	  return false;
	}else{
		return true;
	}
}

/***exceed 12 months**********/
function checkDateWithinRange2(checkDateId){
	var checkDate			= 	$(checkDateId).val();
	var curDate				=	moment().format('MM/DD/YYYY'); 
	var curDateTwelveAgo	=	moment().subtract(12, 'months').format('MM/DD/YYYY'); 
	var diffDate			= 	moment(checkDate).isBetween(curDateTwelveAgo, curDate); 
	if(diffDate==false && (curDate!=checkDate)){
	  bootbox.alert("Document date submitted exceeded 12 months");
	  $(checkDateId).val("");
	  exit;
	  return false;
	}else{
		return true;
	}
}

function save_checklist(){
				var checklist_details		= $('#checklist_of_requirements_form').serialize(); 
				var mods 					=	$('#main_page').val();
				var types 					=	$('#main_type').val(); 
				var action 					=	$('#main_action').val();
				var mainid					=	$('#main_id').val(); 
				var checklist_submission_date		=	$('#checklist_submission_date').val(); 
				var dataString				=	checklist_details+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid);
				if(checklist_submission_date==""){
					bootbox.alert("Required Submission Date ");
				}else{
						$.post('./ajax/checklist.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									bootbox.alert("Successfully Saved ...");
									window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type=reservation'; }, 1000);
								}else{
									bootbox.alert("Failed in saving.");
								}
						});
				}		
}


//LOADING CHECKLIST OF REQUIREMENTS DETAILS
function load_checklist_details(){ 
				var mods 			=	$('#main_page').val();
				var types 			=	$('#main_type').val(); 
				var action 			=	$('#main_action').val();
				var mainid			=	$('#main_id').val();




				var dataString		=	"action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid);
						$.post('./ajax/load_checklist.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								var full_name			=	obj.data[0].full_name;
								 
								var employee_type		=	obj.data[0].employee_type;
								var num_borrower		=	obj.data[0].num_borrower;
								var details				=	obj.data[0].details;
								var submission_date		=	obj.data[0].submission_date;
								var billing_date		=	obj.data[0].billing_date;
								var barangay_date		=	obj.data[0].barangay_date;
								var notarized_date		=	obj.data[0].notarized_date;
								var payslip_date		=	obj.data[0].payslip_date;

								var itr_date			=	obj.data[0].itr_date;
								var other_field			=	obj.data[0].other_field;


								var thank_sent			=	obj.data[0].thank_you_sent;
								var thank_date			=	obj.data[0].thank_you_date;
								var standard_req		=	obj.data[0].standard_req;
								var additional_req		=	obj.data[0].additional_req;
								var c1_standard_req		=	obj.data[0].coborrower1_standard_req;
								var c1_additional_req	=	obj.data[0].coborrower1_additional_req;
								var c2_standard_req		=	obj.data[0].coborrower2_standard_req;
								var c2_additional_req	=	obj.data[0].coborrower2_additional_req;
								var c3_standard_req		=	obj.data[0].coborrower3_standard_req;
								var c3_additional_req	=	obj.data[0].coborrower3_additional_req;
								var financing			= 	obj.data[0].financing;
								var spouse				= 	obj.data[0].spouse;
								
								var billing_date1		=	obj.data[0].billing_date1; 
								var barangay_date1		=	obj.data[0].barangay_date1;
								var notarized_date1		=	obj.data[0].notarized_date1; 
								var payslip_date1		=	obj.data[0].payslip_date1; 
								var itr_date1			=	obj.data[0].itr_date1;
								var other_field1		=	obj.data[0].other_field1;
 
								var billing_date2		=	obj.data[0].billing_date2; 
								var barangay_date2		=	obj.data[0].barangay_date2;
								var notarized_date2		=	obj.data[0].notarized_date2; 
								var payslip_date2		=	obj.data[0].payslip_date2; 
								var itr_date2			=	obj.data[0].itr_date2;
								var other_field2		=	obj.data[0].other_field2;

								var billing_date3		=	obj.data[0].billing_date3; 
								var barangay_date3		=	obj.data[0].barangay_date3;
								var notarized_date3		=	obj.data[0].notarized_date3; 
								var payslip_date3		=	obj.data[0].payslip_date3;
								var itr_date3			=	obj.data[0].itr_date3;
								var other_field3		=	obj.data[0].other_field3;
								
								var phase				=	obj.data[0].phase;
								var block				=	obj.data[0].block;
								var lot					=	obj.data[0].lot;
								var lot_size			=	obj.data[0].lot_size;
								var floor_area			=	obj.data[0].floor_area;
								var loanable_amount		=	obj.data[0].loanable_amount;

								$('.private_div').hide();
								$('.overseas_div').hide();
								$('.self_employed_div').hide();
								$('.immigrant_div').hide();
								$('.online_div').hide();
										
								$('.private_div1').hide();
								$('.overseas_div1').hide();
								$('.self_employed_div1').hide();
								$('.immigrant_div1').hide();
								$('.online_div1').hide();

								$('.private_div2').hide();
								$('.overseas_div2').hide();
								$('.self_employed_div2').hide();
								$('.immigrant_div2').hide();
								$('.online_div2').hide();

								$('.private_div3').hide();
								$('.overseas_div3').hide();
								$('.self_employed_div3').hide();
								$('.immigrant_div3').hide();
								$('.online_div3').hide();
								 
								$('.bank_private_div').hide();
								$('.bank_overseas_div').hide();
								$('.bank_self_employed_div').hide();
								$('.bank_private_div1').hide();
								$('.bank_overseas_div1').hide();
								$('.bank_self_employed_div1').hide();
								$('.bank_private_div2').hide();
								$('.bank_overseas_div2').hide();
								$('.bank_self_employed_div2').hide();
								$('.bank_private_div3').hide();
								$('.bank_overseas_div3').hide();
								$('.bank_self_employed_div3').hide();
 

								//$('#checklist_submission_date').val(submission_date); 
								$('#checklist_financing').val(financing); 

								if(financing=='BANK'){
									$('.bank_standard_requirements').show(); 
									$('.pagibig_standard_requirements').hide();
 
									if(employee_type=="LOCALLY EMPLOYED"){									
										$('.bank_private_div').show();
										$('.bank_overseas_div').hide();
										$('.bank_self_employed_div').hide();

										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').hide();
										
										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
										$('.immigrant_div1').hide();
										$('.online_div1').hide();

										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
										$('.immigrant_div2').hide();
										$('.online_div2').hide();

										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();
										$('.immigrant_div3').hide();
										$('.online_div3').hide();
										  
									}else if(employee_type=="OFW"){									
										$('.bank_private_div').hide();
										$('.bank_overseas_div').show();
										$('.bank_self_employed_div').hide();

										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').hide();
										
										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
										$('.immigrant_div1').hide();
										$('.online_div1').hide();

										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
										$('.immigrant_div2').hide();
										$('.online_div2').hide();

										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();
										$('.immigrant_div3').hide();
										$('.online_div3').hide();
										 
									}else if(employee_type=="SELF-EMPLOYED / OWNED BUSINESS"){									
										$('.bank_private_div').hide();
										$('.bank_overseas_div').hide();
										$('.bank_self_employed_div').show();
 
 										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').hide();

										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
										$('.immigrant_div1').hide();
										$('.online_div1').hide();

										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
										$('.immigrant_div2').hide();
										$('.online_div2').hide();

										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();
										$('.immigrant_div3').hide();
										$('.online_div3').hide();
										 
									}else if(employee_type=="IMMIGRANT" || employee_type=="IMMIGRANTS"){									
										$('.bank_private_div').hide();
										$('.bank_overseas_div').hide();
										$('.bank_self_employed_div').hide();
 
 										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').show();
										$('.online_div').hide();

										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
										$('.immigrant_div1').hide();
										$('.online_div1').hide();

										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
										$('.immigrant_div2').hide();
										$('.online_div2').hide();

										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();
										$('.immigrant_div3').hide();
										$('.online_div3').hide();
										 
									}else if(employee_type=="ONLINE EMPLOYMENT"){									
										$('.bank_private_div').hide();
										$('.bank_overseas_div').hide();
										$('.bank_self_employed_div').hide();
 
 										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').show();

										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
										$('.immigrant_div1').hide();
										$('.online_div1').hide();

										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
										$('.immigrant_div2').hide();
										$('.online_div2').hide();

										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();
										$('.immigrant_div3').hide();
										$('.online_div3').hide();
										 
									}


								$('#proof_of_billing_date1').val(billing_date1);
								$('#barangay_clearance_date1').val(barangay_date1);
								$('#notarized_date1').val(notarized_date1);
								$('#last_month_date1').val(payslip_date1);

								$('#proof_of_billing_date2').val(billing_date2);
								$('#barangay_clearance_date2').val(barangay_date2);
								$('#notarized_date2').val(notarized_date2);
								$('#last_month_date2').val(payslip_date2);

								$('#proof_of_billing_date3').val(billing_date3);
								$('#barangay_clearance_date3').val(barangay_date3);
								$('#notarized_date3').val(notarized_date3);
								$('#last_month_date3').val(payslip_date3);
								
								

								}else{
									$('.bank_standard_requirements').hide(); 
									$('.pagibig_standard_requirements').show(); 

									if(financing!='BANK' && employee_type=="LOCALLY EMPLOYED"){									
										$('.private_div').show();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').hide();
									}else if(financing!='BANK' && employee_type=="OFW"){									
										$('.private_div').hide();
										$('.overseas_div').show();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').hide();
									}else if(financing!='BANK' && employee_type=="SELF-EMPLOYED / OWNED BUSINESS"){									
										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').show();
										$('.immigrant_div').hide();
										$('.online_div').hide();
									}else if(financing!='BANK' && (employee_type=="IMMIGRANT" || employee_type=="IMMIGRANTS")){									
										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').show();
										$('.online_div').hide();
									}else if(financing!='BANK' && employee_type=="ONLINE EMPLOYMENT"){									
										$('.private_div').hide();
										$('.overseas_div').hide();
										$('.self_employed_div').hide();
										$('.immigrant_div').hide();
										$('.online_div').show();
									}



								}	

								if(financing=='BANK' && (spouse!="N/A" || spouse!="")){
									$('#checklist_coborrower1_label').html('Spouse'); 	
									$('#checklist_coborrower2_label').html('Co-borrower 1');
									$('#checklist_coborrower3_label').html('Co-borrower 2');  
									$('.single_married').css('display','none');
								}else{
									$('#checklist_coborrower1_label').html('Co-borrower 1');
									$('#checklist_coborrower2_label').html('Co-borrower 2');
									$('#checklist_coborrower3_label').html('Co-borrower 3');  
								}

								$('#checklist_fullname').val(full_name);
								$('#checklist_employee_type').val(employee_type);
								
								$('#proof_of_billing_date1').val(billing_date1);
								$('#barangay_clearance_date1').val(barangay_date1);
								$('#notarized_date1').val(notarized_date1);
								$('#last_month_date1').val(payslip_date1);

								$('#proof_of_billing_date2').val(billing_date2);
								$('#barangay_clearance_date2').val(barangay_date2);
								$('#notarized_date2').val(notarized_date2);
								$('#last_month_date2').val(payslip_date2);

								$('#proof_of_billing_date3').val(billing_date3);
								$('#barangay_clearance_date3').val(barangay_date3);
								$('#notarized_date3').val(notarized_date3);
								$('#last_month_date3').val(payslip_date3);
								
								$('#checklist_floor_area').val(floor_area);
								$('#checklist_lot_size').val(lot_size);
								$('#checklist_phase').val(phase);
								$('#checklist_block').val(block);
								$('#checklist_lot').val(lot);
								$('#checklist_loanable').val(loanable_amount);

								var obj2	=	$.parseJSON(standard_req);
								var obj3	=	$.parseJSON(additional_req);
								
								$('.coborrower1_requirements').hide();
								$('.coborrower2_requirements').hide();
								$('.coborrower3_requirements').hide(); 
								if(num_borrower==1){ 
									$('.coborrower1_requirements').show();
								}else if(num_borrower==2){ 
									$('.coborrower1_requirements').show();
									$('.coborrower2_requirements').show(); 
								}else if(num_borrower==3){
									$('.coborrower1_requirements').show();
									$('.coborrower2_requirements').show();
									$('.coborrower3_requirements').show();
								}
								 
		
		if(financing=='BANK'){
						$('.complete_pagibig').hide();
						$('.complete_bank').show();
						$('.pagibig_req').hide();
						$('.bank_req').show();						

						if(obj2!=null){
								for(var c=0; c<obj2.length; c++){
									$("input[name='bank_standard_requirements[]']").each( function () {
										if(obj2[c]==$(this).val()){
											$(this).prop('checked', true);
										}
									});
								} 
						}
		}else{
						$('.complete_bank').hide();
						$('.complete_pagibig').show();
						$('.bank_req').hide();
						$('.pagibig_req').show();
						

						if(obj2!=null){
								for(var c=0; c<obj2.length; c++){
									$("input[name='standard_requirements[]']").each( function () {
										if(obj2[c]==$(this).val()){
											$(this).prop('checked', true);
										}
									});
								} 
						}
		}


		if(financing=='BANK'){
						if(obj3!=null){
								for(var c=0; c<obj3.length; c++){
									 $("input[name='bank_additional_requirements[]']").each( function () {
											if(obj3[c]==$(this).val()){
												$(this).prop('checked', true);
											}
									   });
								}
						}		
			
		}else{
						if(obj3!=null){
								for(var c=0; c<obj3.length; c++){
									 $("input[name='additional_requirements[]']").each( function () {
											if(obj3[c]==$(this).val()){
												$(this).prop('checked', true);
											}
									   });
								}
						}		
			
		}
								
								
								
								
								if(thank_sent=="yes"){
									$('#thank_you_letter_sent').prop('checked', true);
								}
								
								if(submission_date=="01/01/1970"){ 	submission_date = null; }
								if(thank_date=="01/01/1970"){ 		thank_date = null; 		}
								if(billing_date=="01/01/1970"){ 	billing_date = null; 	}
								if(barangay_date=="01/01/1970"){ 	barangay_date = null; 	}
								if(notarized_date=="01/01/1970"){ 	notarized_date = null; 	}
								if(payslip_date=="01/01/1970"){ 	payslip_date = null; 	}
								if(billing_date1=="01/01/1970"){ 	billing_date1 = null; 	}
								if(barangay_date1=="01/01/1970"){	barangay_date1 = null; 	}
								if(notarized_date1=="01/01/1970"){ 	notarized_date1 = null;	}
								if(payslip_date1=="01/01/1970"){ 	payslip_date1 = null; 	}
								if(billing_date2=="01/01/1970"){ 	billing_date2 = null; 	}
								if(barangay_date2=="01/01/1970"){ 	barangay_date2 = null; 	}
								if(notarized_date2=="01/01/1970"){ 	notarized_date2 = null; }
								if(payslip_date2=="01/01/1970"){ 	payslip_date2 = null; 	}
								if(billing_date3=="01/01/1970"){ 	billing_date3 = null; 	}
								if(barangay_date3=="01/01/1970"){ 	barangay_date3 = null; 	}
								if(notarized_date3=="01/01/1970"){ 	notarized_date3 = null; }
								if(payslip_date3=="01/01/1970"){ 	payslip_date3 = null; 	}
								
								
								$('#thank_you_date').val(thank_date);
								$('#checklist_submission_date').val(submission_date);
								
								$('#proof_of_billing_date').val(billing_date);
								$('#barangay_clearance_date').val(barangay_date);
								 	 
								if(financing=='BANK'){						
								 	 
								 	if(notarized_date!='01/01/1970'){
										$('#bank_notarized_date').val(notarized_date);
									}else{
										$('#bank_notarized_date').val('');
									}

									if(payslip_date!='01/01/1970'){
										$('#bank_last_month_date').val(payslip_date);
									}else{
										$('#bank_last_month_date').val('');
									}

									if(itr_date!='01/01/1970'){
										$('#bank_last_itr_date').val(itr_date);
									}else{
										$('#bank_last_itr_date').val(''); 
									}
									  
									if(other_field!='01/01/1970'){
										$('#bank_other_field').val(other_field); 	
									}else{
										$('#bank_other_field').val(''); 
									}


									if(itr_date1!='01/01/1970'){ 
										$('#bank_last_itr_date1').val(itr_date1); 
									}else{
										$('#bank_last_itr_date1').val(''); 
									}

									if(other_field1!='01/01/1970'){ 
										$('#bank_other_field1').val(other_field1); 
									}else{
										$('#bank_other_field1').val(''); 
									}
									
									if(itr_date2!='01/01/1970'){ 
										$('#bank_last_itr_date2').val(itr_date2);
									}else{
										$('#bank_last_itr_date2').val('');
									}
 
									if(other_field2!='01/01/1970'){ 
										$('#bank_other_field2').val(other_field2); 
									}else{
										$('#bank_other_field2').val(''); 
									}  
									 
									if(itr_date3!='01/01/1970'){ 
										$('#bank_last_itr_date3').val(itr_date3); 
									}else{
										$('#bank_last_itr_date3').val(''); 
									}
 
									if(other_field3!='01/01/1970'){ 
										$('#bank_other_field3').val(other_field3); 
									}else{
										$('#bank_other_field3').val(''); 
									}									
									

								}else{
									 
									if(notarized_date!='01/01/1970'){ 
										$('#notarized_date').val(notarized_date);
									}else{
										$('#notarized_date').val('');
									}									

									if(payslip_date!='01/01/1970'){ 
										$('#last_month_date').val(payslip_date);
									}else{
										$('#last_month_date').val('');
									}
									
								}


								$('#proof_of_billing_date1').val(billing_date1);
								$('#barangay_clearance_date1').val(barangay_date1);
								$('#notarized_date1').val(notarized_date1);
								$('#last_month_date1').val(payslip_date1);
								
								$('#proof_of_billing_date2').val(billing_date2);
								$('#barangay_clearance_date2').val(barangay_date2);
								$('#notarized_date2').val(notarized_date2);
								$('#last_month_date2').val(payslip_date2);
								
								$('#proof_of_billing_date3').val(billing_date3);
								$('#barangay_clearance_date3').val(barangay_date3);
								$('#notarized_date3').val(notarized_date3);
								$('#last_month_date3').val(payslip_date3);
								
								
								var codetails = "";
								var objd	= $.parseJSON(details);
								
								$('#checklist_employee_type1').val(objd.details[0].employee_type);
								$('#checklist_coborrower1').val(objd.details[0].coborrower); 
								$('#checklist_employee_type2').val(objd.details[1].employee_type);
								$('#checklist_coborrower2').val(objd.details[1].coborrower);
								$('#checklist_employee_type3').val(objd.details[2].employee_type);
								$('#checklist_coborrower3').val(objd.details[2].coborrower);

								var obj4	=	$.parseJSON(c1_standard_req);
								var obj5	=	$.parseJSON(c1_additional_req);
								var obj6	=	$.parseJSON(c2_standard_req);
								var obj7	=	$.parseJSON(c2_additional_req);
								var obj8	=	$.parseJSON(c3_standard_req);
								var obj9	=	$.parseJSON(c3_additional_req); 
								
								var employee_type1 = objd.details[0].employee_type;
								$('.private_div1').hide();
								$('.overseas_div1').hide();
								$('.self_employed_div1').hide();
								$('.immigrant_div1').hide();
								$('.online_div1').hide();


								if(employee_type1=="LOCALLY EMPLOYED"){
									
									if(financing=='BANK'){
										$('.bank_private_div1').show();
										$('.bank_overseas_div1').hide();
										$('.bank_self_employed_div1').hide(); 
									}else{
										$('.private_div1').show();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();	
									}
									$('.immigrant_div1').hide();
									$('.online_div1').hide();

								}else if(employee_type1=="OFW"){
									
									if(financing=='BANK'){
										$('.bank_private_div1').hide();
										$('.bank_overseas_div1').show();
										$('.bank_self_employed_div1').hide();
									}else{
										$('.private_div1').hide();
										$('.overseas_div1').show();
										$('.self_employed_div1').hide();
									}
									$('.immigrant_div1').hide();
									$('.online_div1').hide();

								}else if(employee_type1=="SELF-EMPLOYED / OWNED BUSINESS"){
									
									if(financing=='BANK'){
										$('.bank_private_div1').hide();
										$('.bank_overseas_div1').hide();
										$('.bank_self_employed_div1').show();
									}else{
										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').show();
									}
									$('.immigrant_div1').hide();
									$('.online_div1').hide();

								}else if(employee_type1=="IMMIGRANT" || employee_type1=="IMMIGRANTS"){
									
									if(financing=='BANK'){
										$('.bank_private_div1').hide();
										$('.bank_overseas_div1').hide();
										$('.bank_self_employed_div1').hide();
									}else{
										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
									}
									$('.immigrant_div1').show();
									$('.online_div1').hide();
									
								}else if(employee_type1=="ONLINE EMPLOYMENT"){
									
									if(financing=='BANK'){
										$('.bank_private_div1').hide();
										$('.bank_overseas_div1').hide();
										$('.bank_self_employed_div1').hide();
									}else{
										$('.private_div1').hide();
										$('.overseas_div1').hide();
										$('.self_employed_div1').hide();
									}
									$('.immigrant_div1').hide();
									$('.online_div1').show();
									
								}
								
								//employee2
								var employee_type2 = objd.details[1].employee_type;
								$('.private_div2').hide();
								$('.overseas_div2').hide();
								$('.self_employed_div2').hide();
								$('.immigrant_div2').hide();
								$('.online_div2').hide();
								 
								if(employee_type2=="LOCALLY EMPLOYED"){
									if(financing=='BANK'){
										$('.bank_private_div2').show();
										$('.bank_overseas_div2').hide();
										$('.bank_self_employed_div2').hide();
									}else{
										$('.private_div2').show();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
									}
									$('.immigrant_div2').hide();
									$('.online_div2').hide();
									
								}else if(employee_type2=="OFW"){
									if(financing=='BANK'){
										$('.bank_private_div2').hide();
										$('.bank_overseas_div2').show();
										$('.bank_self_employed_div2').hide();
									}else{
										$('.private_div2').hide();
										$('.overseas_div2').show();
										$('.self_employed_div2').hide();
									}	
									$('.immigrant_div2').hide();
									$('.online_div2').hide();
									
								}else if(employee_type2=="SELF-EMPLOYED / OWNED BUSINESS"){
									if(financing=='BANK'){
										$('.bank_private_div2').hide();
										$('.bank_overseas_div2').hide();
										$('.bank_self_employed_div2').show();
									}else{
										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').show();
									}	
									$('.immigrant_div2').hide();
									$('.online_div2').hide();
									
								}else if(employee_type2=="IMMIGRANT" || employee_type2=="IMMIGRANTS"){
									if(financing=='BANK'){
										$('.bank_private_div2').hide();
										$('.bank_overseas_div2').hide();
										$('.bank_self_employed_div2').hide();
									}else{
										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
									}	
									$('.immigrant_div2').show();
									$('.online_div2').hide();		

								}else if(employee_type2=="ONLINE EMPLOYMENT"){
									if(financing=='BANK'){
										$('.bank_private_div2').hide();
										$('.bank_overseas_div2').hide();
										$('.bank_self_employed_div2').hide();
									}else{
										$('.private_div2').hide();
										$('.overseas_div2').hide();
										$('.self_employed_div2').hide();
									}	
									$('.immigrant_div2').hide();
									$('.online_div2').show();		

								}
								
								//employee3
								var employee_type3 = objd.details[2].employee_type;
								$('.private_div3').hide();
								$('.overseas_div3').hide();
								$('.self_employed_div3').hide();
								$('.immigrant_div3').hide();
								$('.online_div3').hide();
								 
								if(employee_type3=="LOCALLY EMPLOYED"){
									
									if(financing=='BANK'){
										$('.bank_private_div3').show();
										$('.bank_overseas_div3').hide();
										$('.bank_self_employed_div3').hide();		
									}else{
										$('.private_div3').show();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();	
									}	
									$('.immigrant_div3').hide();
									$('.online_div3').hide();
									
								}else if(employee_type3=="OFW"){
 
									if(financing=='BANK'){
										$('.bank_private_div3').hide();
										$('.bank_overseas_div3').show();
										$('.bank_self_employed_div3').hide();		
									}else{
										$('.private_div3').hide();
										$('.overseas_div3').show();
										$('.self_employed_div3').hide();	
									}	
									$('.immigrant_div3').hide();
									$('.online_div3').hide();

								}else if(employee_type3=="SELF-EMPLOYED / OWNED BUSINESS"){
 
									if(financing=='BANK'){
										$('.bank_private_div3').hide();
										$('.bank_overseas_div3').hide();
										$('.bank_self_employed_div3').show();		
									}else{
										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').show();	
									}	
									$('.immigrant_div3').hide();
									$('.online_div3').hide();

								}else if(employee_type3=="IMMIGRANT" || employee_type3=="IMMIGRANTS"){
 
									if(financing=='BANK'){
										$('.bank_private_div3').hide();
										$('.bank_overseas_div3').hide();
										$('.bank_self_employed_div3').hide();		
									}else{
										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();	
									}	
									$('.immigrant_div3').show();
									$('.online_div3').hide();
									
								}else if(employee_type3=="ONLINE EMPLOYMENT"){
 
									if(financing=='BANK'){
										$('.bank_private_div3').hide();
										$('.bank_overseas_div3').hide();
										$('.bank_self_employed_div3').hide();		
									}else{
										$('.private_div3').hide();
										$('.overseas_div3').hide();
										$('.self_employed_div3').hide();	
									}	
									$('.immigrant_div3').hide();
									$('.online_div3').show();
									
								}
								
		if(financing=='BANK'){
								if(obj4!=null){
									for(var d=0; d<obj4.length; d++){
										 $("input[name='bank_standard_requirements1[]']").each( function () {						 
												if(obj4[d]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
								}
		}else{
								if(obj4!=null){
									for(var d=0; d<obj4.length; d++){
										 $("input[name='standard_requirements1[]']").each( function () {						 
												if(obj4[d]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
								}
		}						
								

		if(financing=='BANK'){
					if(obj5!=null){
									for(var c=0; c<obj5.length; c++){
										 $("input[name='bank_additional_requirements1[]']").each( function () {
												if(obj5[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
					}
		}else{
					if(obj5!=null){
									for(var c=0; c<obj5.length; c++){
										 $("input[name='additional_requirements1[]']").each( function () {
												if(obj5[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
					}
		}	
								
		
		if(financing=='BANK'){
							if(obj6!=null){
									for(var c=0; c<obj6.length; c++){
										 $("input[name='bank_standard_requirements2[]']").each( function () {
												if(obj6[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
							}
		}else{
							if(obj6!=null){
									for(var c=0; c<obj6.length; c++){
										 $("input[name='standard_requirements2[]']").each( function () {
												if(obj6[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
							}
		}						
								
		if(financing=='BANK'){
								if(obj7!=null){
									for(var c=0; c<obj7.length; c++){
										 $("input[name='bank_additional_requirements2[]']").each( function () {
												if(obj7[c]==$(this).val()){ $(this).prop('checked', true); }
										 });
									}
								}
		}else{
								if(obj7!=null){
									for(var c=0; c<obj7.length; c++){
										 $("input[name='additional_requirements2[]']").each( function () {
												if(obj7[c]==$(this).val()){ $(this).prop('checked', true); }
										 });
									}
								}
		}						
								
		
		if(financing=='BANK'){
						if(obj8!=null){
									for(var c=0; c<obj8.length; c++){
										 $("input[name='bank_standard_requirements3[]']").each( function () {
												if(obj8[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
						}
		}else{
						if(obj8!=null){
									for(var c=0; c<obj8.length; c++){
										 $("input[name='standard_requirements3[]']").each( function () {
												if(obj8[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
						}
		}						
								
		if(financing=='BANK'){
							if(obj9!=null){
									for(var c=0; c<obj9.length; c++){
										 $("input[name='bank_additional_requirements3[]']").each( function () {
												if(obj9[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
							 }
		}else{
							if(obj9!=null){
									for(var c=0; c<obj9.length; c++){
										 $("input[name='additional_requirements3[]']").each( function () {
												if(obj9[c]==$(this).val()){
													$(this).prop('checked', true);
												}
										   });
									}
							 }
		}						
							
						});
}