function save_releases_to_broker_for_wht(){
	//alert('saving...'); 
	var mods 					=	$('#main_page').val();
	var types 					=	$('#main_type').val(); 
	var action 					=	$('#main_action').val();
	var mainid					=	$('#main_id').val(); 
	var releases_to_broker		=	$('#releases_to_broker_for_wht_form').serialize(); 
  
	var dataString				=	releases_to_broker+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid)+"&types="+encodeURIComponent(types);  
	var balance_check 			= $('#balancereleasecheckbox').prop("checked");
	var full_check 				= $('#full_release_checkbox').prop("checked");
 
 	if(balance_check==true){
		dataString += "&balance_checkbox=on";
		$('#balancereleasecheckbox').attr("checked",true);
	}

	if(full_check==true){
		dataString += "&full_checkbox=on";
		$('#full_release_checkbox').attr("checked",true);
	}
 
	$.post('./ajax/releases_to_broker_for_wht.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='+types; }, 1000);
			}else{
				bootbox.alert("Failed in saving.");
			}
	}); 
}


load_releases_to_broker_for_wht();


$('#bpm_date_rf_deposited').change(function(e){
	e.preventDefault();
	computeBalaceReservationLessCa();
	computeMiscExpense();
	computeBasisCommission();
	computeCommission();
	releaseStatus();
});

function load_releases_to_broker_for_wht(){
				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); 


				if(action=='edit' || action=='view' || action=='create'){
						$.post('./ajax/load_releases_to_broker_for_wht.php', dataString, function(msg){ 
								var obj	= $.parseJSON(msg); 
								var date_rf_deposited	=	obj.data[0].date_rf_deposited;
								var model				=	obj.data[0].model;
						 		var block				=	obj.data[0].block;
								var lot					=	obj.data[0].lot; 
						 		var full_name			=	obj.data[0].full_name; 
								var tcp					=	parseFloat(obj.data[0].tcp);
								var discount			=	parseFloat(obj.data[0].less_discount); 
								var broker				=	obj.data[0].broker; 
								var agent				=	obj.data[0].agent;
								var realty				=	obj.data[0].realty; 
								var reservation_id		=	obj.data[0].id; 


								var reservation_less_ca		=	obj.data[0].reservation_less_ca; 
								var reservation				=	obj.data[0].reservation; 
								var less_ca					=	obj.data[0].less_ca; 

								var misc_expense_rate 				= obj.data[0].misc_expense_rate;
								var rate 							= obj.data[0].rate; 
								var wht 							= obj.data[0].wht; 
								var first_release_checkbox 			= obj.data[0].first_release_checkbox; 
								var ca_checkbox 					= obj.data[0].ca_checkbox; 
								var first_release_type 				= obj.data[0].first_release_type;
								var first_release_broker_amount 	= (obj.data[0].first_release_broker_amount=='NaN' || obj.data[0].first_release_broker_amount=='0.00' || obj.data[0].first_release_broker_amount=='' || obj.data[0].first_release_broker_amount==null) ? 0.00 : obj.data[0].first_release_broker_amount; 
								var first_release_agent_amount 		= (obj.data[0].first_release_agent_amount=='NaN' || obj.data[0].first_release_agent_amount=='0.00' || obj.data[0].first_release_agent_amount=='' || obj.data[0].first_release_agent_amount==null) ? 0.00 : obj.data[0].first_release_agent_amount; 
								var first_release_wht  				= obj.data[0].first_release_wht; 
								var first_release_cash 				= obj.data[0].first_release_cash; 
								var first_release_net 				= obj.data[0].first_release_net; 
								var first_release_date 				= obj.data[0].first_release_date; 
								var first_release_broker_check 		= obj.data[0].first_release_broker_check; 
								var first_release_agent_check 		= obj.data[0].first_release_agent_check; 

								var second_release_checkbox 	 	= obj.data[0].second_release_checkbox;
								var second_release_type				= obj.data[0].second_release_type; 
								var second_release_broker_amount 	= (obj.data[0].second_release_broker_amount=='NaN' || obj.data[0].second_release_broker_amount=='0.00' || obj.data[0].second_release_broker_amount=='' || obj.data[0].second_release_broker_amount==null) ? 0.00 : obj.data[0].second_release_broker_amount; 
								var second_release_agent_amount 	= (obj.data[0].second_release_agent_amount=='NaN' || obj.data[0].second_release_agent_amount=='0.00' || obj.data[0].second_release_agent_amount=='' || obj.data[0].second_release_agent_amount==null) ? 0.00 : obj.data[0].second_release_agent_amount; 
								var second_release_wht 				= obj.data[0].second_release_wht; 
								var second_release_cash 			= obj.data[0].second_release_cash; 
								var second_release_net 				= obj.data[0].second_release_net; 
								var second_release_date				= obj.data[0].second_release_date; 
								var second_release_broker_check	 	= obj.data[0].second_release_broker_check; 
								var second_release_agent_check	 	= obj.data[0].second_release_agent_check; 

								var third_release_checkbox			= obj.data[0].third_release_checkbox;
								var third_release_type				= obj.data[0].third_release_type;  
								var third_release_broker_amount		= (obj.data[0].third_release_broker_amount=='NaN' || obj.data[0].third_release_broker_amount=='0.00' || obj.data[0].third_release_broker_amount=='' || obj.data[0].third_release_broker_amount==null) ? 0.00 : obj.data[0].third_release_broker_amount; 
								var third_release_agent_amount		= (obj.data[0].third_release_agent_amount=='NaN' || obj.data[0].third_release_agent_amount=='0.00' || obj.data[0].third_release_agent_amount=='' || obj.data[0].third_release_agent_amount==null) ? 0.00 : obj.data[0].third_release_agent_amount; 
								var third_release_wht				= obj.data[0].third_release_wht; 
								var third_release_cash				= obj.data[0].third_release_cash; 
								var third_release_net				= obj.data[0].third_release_net; 
								var third_release_date				= obj.data[0].third_release_date;
								var third_release_broker_check		= obj.data[0].third_release_broker_check; 
								var third_release_agent_check		= obj.data[0].third_release_agent_check; 
 
								var fourth_release_checkbox			= obj.data[0].fourth_release_checkbox;
								var fourth_release_type				= obj.data[0].fourth_release_type;   
								var fourth_release_broker_amount	= (obj.data[0].fourth_release_broker_amount=='NaN' || obj.data[0].fourth_release_broker_amount=='0.00' || obj.data[0].fourth_release_broker_amount=='' || obj.data[0].fourth_release_broker_amount==null) ? 0.00 : obj.data[0].fourth_release_broker_amount; 
								var fourth_release_agent_amount		= (obj.data[0].fourth_release_agent_amount=='NaN' || obj.data[0].fourth_release_agent_amount=='0.00' || obj.data[0].fourth_release_agent_amount=='' || obj.data[0].fourth_release_agent_amount==null) ? 0.00 : obj.data[0].fourth_release_agent_amount; 
								var fourth_release_wht				= obj.data[0].fourth_release_wht; 
								var fourth_release_cash				= obj.data[0].fourth_release_cash; 
								var fourth_release_net				= obj.data[0].fourth_release_net; 
								var fourth_release_date				= obj.data[0].fourth_release_date; 
								var fourth_release_broker_check		= obj.data[0].fourth_release_broker_check; 
								var fourth_release_agent_check		= obj.data[0].fourth_release_agent_check; 

								var fifth_release_checkbox			= obj.data[0].fifth_release_checkbox;
								var fifth_release_type				= obj.data[0].fifth_release_type;    
								var fifth_release_broker_amount		= (obj.data[0].fifth_release_broker_amount=='NaN' || obj.data[0].fifth_release_broker_amount=='0.00' || obj.data[0].fifth_release_broker_amount=='' || obj.data[0].fifth_release_broker_amount==null) ? 0.00 : obj.data[0].fifth_release_broker_amount; 
								var fifth_release_agent_amount		= (obj.data[0].fifth_release_agent_amount=='NaN' || obj.data[0].fifth_release_agent_amount=='0.00' || obj.data[0].fifth_release_agent_amount=='' || obj.data[0].fifth_release_agent_amount==null) ? 0.00 : obj.data[0].fifth_release_agent_amount; 
								var fifth_release_wht				= obj.data[0].fifth_release_wht; 
								var fifth_release_cash				= obj.data[0].fifth_release_cash; 
								var fifth_release_net				= obj.data[0].fifth_release_net; 
								var fifth_release_date				= obj.data[0].fifth_release_date; 
								var fifth_release_broker_check		= obj.data[0].fifth_release_broker_check; 
								var fifth_release_agent_check		= obj.data[0].fifth_release_agent_check; 

								var six_release_checkbox			= obj.data[0].six_release_checkbox; 
								var six_release_type				= obj.data[0].six_release_type;    
								var six_release_broker_amount		= (obj.data[0].six_release_broker_amount=='NaN' || obj.data[0].six_release_broker_amount=='0.00' || obj.data[0].six_release_broker_amount=='' || obj.data[0].six_release_broker_amount==null) ? 0.00 : obj.data[0].six_release_broker_amount; 
								var six_release_agent_amount		= (obj.data[0].six_release_agent_amount=='NaN' || obj.data[0].six_release_agent_amount=='0.00' || obj.data[0].six_release_agent_amount=='' || obj.data[0].six_release_agent_amount==null) ? 0.00 : obj.data[0].six_release_agent_amount; 
								var six_release_wht					= obj.data[0].six_release_wht; 
								var six_release_cash				= obj.data[0].six_release_cash; 
								var six_release_net					= obj.data[0].six_release_net; 
								var six_release_date				= obj.data[0].six_release_date; 
								var six_release_broker_check		= obj.data[0].six_release_broker_check; 
								var six_release_agent_check			= obj.data[0].six_release_agent_check; 

								var seven_release_checkbox			= obj.data[0].seven_release_checkbox;
								var seven_release_type				= obj.data[0].seven_release_type;     
								var seven_release_broker_amount		= (obj.data[0].seven_release_broker_amount=='NaN' || obj.data[0].seven_release_broker_amount=='0.00' || obj.data[0].seven_release_broker_amount=='' || obj.data[0].seven_release_broker_amount==null) ? 0.00 : obj.data[0].seven_release_broker_amount; 
								var seven_release_agent_amount		= (obj.data[0].seven_release_agent_amount=='NaN' || obj.data[0].seven_release_agent_amount=='0.00' || obj.data[0].seven_release_agent_amount=='' || obj.data[0].seven_release_agent_amount==null) ? 0.00 : obj.data[0].seven_release_agent_amount; 
								var seven_release_wht				= obj.data[0].seven_release_wht; 
								var seven_release_cash				= obj.data[0].seven_release_cash; 
								var seven_release_net				= obj.data[0].seven_release_net; 
								var seven_release_date				= obj.data[0].seven_release_date; 
								var seven_release_broker_check		= obj.data[0].seven_release_broker_check; 
								var seven_release_agent_check		= obj.data[0].seven_release_agent_check; 

								var eight_release_checkbox			= obj.data[0].eight_release_checkbox; 
								var eight_release_type				= obj.data[0].eight_release_type;     
								var eight_release_broker_amount		= (obj.data[0].eight_release_broker_amount=='NaN' || obj.data[0].eight_release_broker_amount=='0.00' || obj.data[0].eight_release_broker_amount=='' || obj.data[0].eight_release_broker_amount==null) ? 0.00 : obj.data[0].eight_release_broker_amount; 
								var eight_release_agent_amount		= (obj.data[0].eight_release_agent_amount=='NaN' || obj.data[0].eight_release_agent_amount=='0.00' || obj.data[0].eight_release_agent_amount=='' || obj.data[0].eight_release_agent_amount==null) ? 0.00 : obj.data[0].eight_release_agent_amount; 
								var eight_release_wht				= obj.data[0].eight_release_wht; 
								var eight_release_cash				= obj.data[0].eight_release_cash; 
								var eight_release_net				= obj.data[0].eight_release_net; 
								var eight_release_date				= obj.data[0].eight_release_date; 
								var eight_release_broker_check		= obj.data[0].eight_release_broker_check; 
								var eight_release_agent_check		= obj.data[0].eight_release_agent_check; 

								var nine_release_checkbox			= obj.data[0].nine_release_checkbox; 
								var nine_release_type				= obj.data[0].nine_release_type;     
								var nine_release_broker_amount		= (obj.data[0].nine_release_broker_amount=='NaN' || obj.data[0].nine_release_broker_amount=='0.00' || obj.data[0].nine_release_broker_amount=='' || obj.data[0].nine_release_broker_amount==null) ? 0.00 : obj.data[0].nine_release_broker_amount; 
								var nine_release_agent_amount		= (obj.data[0].nine_release_agent_amount=='NaN' || obj.data[0].nine_release_agent_amount=='0.00' || obj.data[0].nine_release_agent_amount=='' || obj.data[0].nine_release_agent_amount==null) ? 0.00 : obj.data[0].nine_release_agent_amount; 
								var nine_release_wht				= obj.data[0].nine_release_wht; 
								var nine_release_cash				= obj.data[0].nine_release_cash; 
								var nine_release_net				= obj.data[0].nine_release_net; 
								var nine_release_date				= obj.data[0].nine_release_date; 
								var nine_release_broker_check		= obj.data[0].nine_release_broker_check; 
								var nine_release_agent_check		= obj.data[0].nine_release_agent_check; 

								var ten_release_checkbox			= obj.data[0].ten_release_checkbox; 
								var ten_release_type				= obj.data[0].ten_release_type;     
								var ten_release_broker_amount		= (obj.data[0].ten_release_broker_amount=='NaN' || obj.data[0].ten_release_broker_amount=='0.00' || obj.data[0].ten_release_broker_amount=='' || obj.data[0].ten_release_broker_amount==null) ? 0.00 : obj.data[0].ten_release_broker_amount; 
								var ten_release_agent_amount		= (obj.data[0].ten_release_agent_amount=='NaN' || obj.data[0].ten_release_agent_amount=='0.00' || obj.data[0].ten_release_agent_amount=='' || obj.data[0].ten_release_agent_amount==null) ? 0.00 : obj.data[0].ten_release_agent_amount; 
								var ten_release_wht					= obj.data[0].ten_release_wht; 
								var ten_release_cash				= obj.data[0].ten_release_cash; 
								var ten_release_net					= obj.data[0].ten_release_net; 
								var ten_release_date				= obj.data[0].ten_release_date; 
								var ten_release_broker_check		= obj.data[0].ten_release_broker_check; 
								var ten_release_agent_check			= obj.data[0].ten_release_agent_check; 


								var eleven_release_checkbox			= obj.data[0].eleven_release_checkbox; 
								var eleven_release_type				= obj.data[0].eleven_release_type;     
								var eleven_release_broker_amount	= (obj.data[0].eleven_release_broker_amount=='NaN' || obj.data[0].eleven_release_broker_amount=='0.00' || obj.data[0].eleven_release_broker_amount=='' || obj.data[0].eleven_release_broker_amount==null) ? 0.00 : obj.data[0].eleven_release_broker_amount; 
								var eleven_release_agent_amount		= (obj.data[0].eleven_release_agent_amount=='NaN' || obj.data[0].eleven_release_agent_amount=='0.00' || obj.data[0].eleven_release_agent_amount=='' || obj.data[0].eleven_release_agent_amount==null) ? 0.00 : obj.data[0].eleven_release_agent_amount; 
								var eleven_release_wht				= obj.data[0].eleven_release_wht; 
								var eleven_release_cash				= obj.data[0].eleven_release_cash; 
								var eleven_release_net				= obj.data[0].eleven_release_net; 
								var eleven_release_date				= obj.data[0].eleven_release_date; 
								var eleven_release_broker_check		= obj.data[0].eleven_release_broker_check; 
								var eleven_release_agent_check		= obj.data[0].eleven_release_agent_check; 


								var twelve_release_checkbox			= obj.data[0].twelve_release_checkbox; 
								var twelve_release_type				= obj.data[0].twelve_release_type;     
								var twelve_release_broker_amount	= (obj.data[0].twelve_release_broker_amount=='NaN' || obj.data[0].twelve_release_broker_amount=='0.00' || obj.data[0].twelve_release_broker_amount=='' || obj.data[0].twelve_release_broker_amount==null) ? 0.00 : obj.data[0].twelve_release_broker_amount; 
								var twelve_release_agent_amount		= (obj.data[0].twelve_release_agent_amount=='NaN' || obj.data[0].twelve_release_agent_amount=='0.00' || obj.data[0].twelve_release_agent_amount=='' || obj.data[0].twelve_release_agent_amount==null) ? 0.00 : obj.data[0].twelve_release_agent_amount; 
								var twelve_release_wht				= obj.data[0].twelve_release_wht; 
								var twelve_release_cash				= obj.data[0].twelve_release_cash; 
								var twelve_release_net				= obj.data[0].twelve_release_net; 
								var twelve_release_date				= obj.data[0].twelve_release_date; 
								var twelve_release_broker_check		= obj.data[0].twelve_release_broker_check; 
								var twelve_release_agent_check		= obj.data[0].twelve_release_agent_check; 


								var partial_date				= obj.data[0].partial_date; 
								var full_date					= obj.data[0].full_date; 
								var total_date					= obj.data[0].total_date; 

								var subtotal_amount				= obj.data[0].subtotal_amount; 
								var balance_checkbox			= obj.data[0].balance_checkbox; 
								var balance_amount				= obj.data[0].balance_amount; 
								var partial_amount				= obj.data[0].partial_amount; 
								var partial_wht					= obj.data[0].partial_wht; 	
								var partial_cash				= obj.data[0].partial_cash; 	
								var partial_net					= obj.data[0].partial_net; 	
								var partial_check				= obj.data[0].partial_check; 	
								var full_checkbox				= obj.data[0].full_checkbox; 
								var full_amount					= (obj.data[0].full_amount!='NaN' || obj.data[0].full_amount!='' || obj.data[0].full_amount!=null) ? obj.data[0].full_amount : '0.00'; 	
								var full_wht					= (obj.data[0].full_wht!='NaN' || obj.data[0].full_wht!='' || obj.data[0].full_wht!=null) ? obj.data[0].full_wht : '0.00'; 	
								var full_cash					= (obj.data[0].full_cash!='NaN' || obj.data[0].full_cash!='' || obj.data[0].full_cash!=null) ? obj.data[0].full_cash : '0.00'; 	
								var full_net					= (obj.data[0].full_net!='NaN' || obj.data[0].full_net!='' || obj.data[0].full_net!=null) ? obj.data[0].full_net : '0.00'; 	
								var full_check					= obj.data[0].full_check; 	
 
								var total_release_amount		= (obj.data[0].total_release_amount!='NaN') ? obj.data[0].total_release_amount : '0.00'; 
								var total_release_wht			= (obj.data[0].total_release_wht!='NaN') ? obj.data[0].total_release_wht : '0.00'; 
								var total_release_cash			= (obj.data[0].total_release_cash!='NaN') ? obj.data[0].total_release_cash : '0.00';  
								var total_release_net			= (obj.data[0].total_release_net!='NaN') ? obj.data[0].total_release_net : '0.00'; 
								var total_release_check			= obj.data[0].total_release_check; 	
  
								var release_status				= obj.data[0].release_status; 
								var release_remarks				= obj.data[0].release_remarks; 

								var take_out_date				= obj.data[0].take_out_date; 
								/****************/  
								
								if(first_release_net=='NaN' || first_release_net=='0.00' || first_release_net=='' || first_release_net==null){
									first_release_net = '0.00';
								}

								if(first_release_cash=='NaN' || first_release_cash=='0.00' || first_release_cash=='' || first_release_cash==null){
									first_release_cash = '0.00';
								}

								if(second_release_cash=='NaN' || second_release_cash=='0.00' || second_release_cash==''){
									second_release_cash = '0.00';
								}

								if(third_release_cash=='NaN' || third_release_cash=='0.00' || third_release_cash==''){
									third_release_cash = '0.00';
								}
								
								if(total_release_cash=='NaN' || total_release_cash=='0.00' || total_release_cash==''){
									total_release_cash = '0.00';
								}

								if(first_release_date=='01/01/1970'){
									first_release_date = '';
								}

								if(second_release_date=='01/01/1970'){
									second_release_date = '';
								}

								if(third_release_date=='01/01/1970'){
									third_release_date = '';
								}

								if(fourth_release_date=='01/01/1970'){
									fourth_release_date = '';
								}

								if(fifth_release_date=='01/01/1970'){
									fifth_release_date = '';
								}

								if(six_release_date=='01/01/1970'){
									six_release_date = '';
								}

								if(seven_release_date=='01/01/1970'){
									seven_release_date = '';
								}

								if(eight_release_date=='01/01/1970'){
									eight_release_date = '';
								}

								if(nine_release_date=='01/01/1970'){
									nine_release_date = '';
								}

								if(ten_release_date=='01/01/1970'){
									ten_release_date = '';
								}

								if(eleven_release_date=='01/01/1970'){
									eleven_release_date = '';
								}

								if(twelve_release_date=='01/01/1970'){
									twelve_release_date = '';
								}


								if(partial_date=='01/01/1970'){
									partial_date = '';
								}

								if(full_date=='01/01/1970'){
									full_date = '';
								}

								if(total_date=='01/01/1970'){
									total_date = '';
								}

								if(ca_checkbox=='on'){
									$('#ca_checkbox').attr('checked',true);
								}
 
								if(first_release_checkbox=='on'){
									$('#first_release_checkbox').attr('checked',true);
									$('#first_release_checkbox').attr('disabled',false);
									$('#first_release_broker_amount').val(first_release_broker_amount);
									$('#first_release_agent_amount').val(first_release_agent_amount);									
								}
	 							 
								if(second_release_checkbox=='on'){
									$('#second_release_checkbox').attr('checked',true);
									$('#second_release_checkbox').attr('disabled',false);
									$('#second_release_broker_amount').val(second_release_broker_amount);
									$('#second_release_agent_amount').val(second_release_agent_amount);
								}
								  
								if(third_release_checkbox=='on'){
									$('#third_release_checkbox').attr('checked',true);
									$('#third_release_checkbox').attr('disabled',false);
									$('#third_release_agent_amount').val(third_release_agent_amount);
									$('#third_release_broker_amount').val(third_release_broker_amount);
								}
 
								if(fourth_release_checkbox=='on'){
									$('#fourth_release_checkbox').attr('checked',true);
									$('#fourth_release_checkbox').attr('disabled',false);
									$('#fourth_release_agent_amount').val(fourth_release_agent_amount);
									$('#fourth_release_broker_amount').val(fourth_release_broker_amount);
								}

								if(fifth_release_checkbox=='on'){
									$('#fifth_release_checkbox').attr('checked',true);
									$('#fifth_release_checkbox').attr('disabled',false);
									$('#fifth_release_broker_amount').val(fifth_release_broker_amount);
									$('#fifth_release_agent_amount').val(fifth_release_agent_amount);
								}

								if(six_release_checkbox=='on'){
									$('#six_release_checkbox').attr('checked',true);
									$('#six_release_checkbox').attr('disabled',false);
									$('#six_release_broker_amount').val(six_release_broker_amount);
									$('#six_release_agent_amount').val(six_release_agent_amount);
								}

								if(seven_release_checkbox=='on'){
									$('#seven_release_checkbox').attr('checked',true);
									$('#seven_release_checkbox').attr('disabled',false);
									$('#seven_release_broker_amount').val(seven_release_broker_amount);
									$('#seven_release_agent_amount').val(seven_release_agent_amount);
								}

								if(eight_release_checkbox=='on'){
									$('#eight_release_checkbox').attr('checked',true);
									$('#eight_release_checkbox').attr('disabled',false);
									$('#eight_release_broker_amount').val(eight_release_broker_amount);
									$('#eight_release_agent_amount').val(eight_release_agent_amount);
								}

								if(nine_release_checkbox=='on'){
									$('#nine_release_checkbox').attr('checked',true);
									$('#nine_release_checkbox').attr('disabled',false);
									$('#nine_release_agent_amount').val(nine_release_agent_amount);
									$('#nine_release_broker_amount').val(nine_release_broker_amount);
								}

								if(ten_release_checkbox=='on'){
									$('#ten_release_checkbox').attr('checked',true);
									$('#ten_release_checkbox').attr('disabled',false);
									$('#ten_release_broker_amount').val(ten_release_broker_amount); 
									$('#ten_release_agent_amount').val(ten_release_agent_amount);
								}

								if(eleven_release_checkbox=='on'){
									$('#eleven_release_checkbox').attr('checked',true);
									$('#eleven_release_checkbox').attr('disabled',false);
									$('#eleven_release_broker_amount').val(eleven_release_broker_amount); 
									$('#eleven_release_agent_amount').val(eleven_release_agent_amount);
								}

								if(twelve_release_checkbox=='on'){
									$('#twelve_release_checkbox').attr('checked',true);
									$('#twelve_release_checkbox').attr('disabled',false);
									$('#twelve_release_broker_amount').val(twelve_release_broker_amount); 
									$('#twelve_release_agent_amount').val(twelve_release_agent_amount);
								}
 
								$('#first_release_type').val(first_release_type);
								$('#second_release_type').val(second_release_type);
								$('#third_release_type').val(third_release_type);
								$('#fourth_release_type').val(fourth_release_type);
								$('#fifth_release_type').val(fifth_release_type);
								$('#six_release_type').val(six_release_type);
								$('#seven_release_type').val(seven_release_type);
								$('#eight_release_type').val(eight_release_type);
								$('#nine_release_type').val(nine_release_type);
								$('#ten_release_type').val(ten_release_type);
								$('#eleven_release_type').val(eleven_release_type);
								$('#twelve_release_type').val(twelve_release_type);


								$('#first_release_broker_check').val(first_release_broker_check);
								$('#first_release_agent_check').val(first_release_agent_check);
								
								$('#second_release_broker_check').val(second_release_broker_check);
								$('#second_release_agent_check').val(second_release_agent_check);
								
								$('#third_release_broker_check').val(third_release_broker_check);
								$('#third_release_agent_check').val(third_release_agent_check);
								
								$('#fourth_release_broker_check').val(fourth_release_broker_check);
								$('#fourth_release_agent_check').val(fourth_release_agent_check);
								
								$('#fifth_release_broker_check').val(fifth_release_broker_check);
								$('#fifth_release_agent_check').val(fifth_release_agent_check);
								
								$('#six_release_broker_check').val(six_release_broker_check);
								$('#six_release_agent_check').val(six_release_agent_check);
								
								$('#seven_release_broker_check').val(seven_release_broker_check);
								$('#seven_release_agent_check').val(seven_release_agent_check);

								$('#eight_release_broker_check').val(eight_release_broker_check);
								$('#eight_release_agent_check').val(eight_release_agent_check);
								
								$('#nine_release_broker_check').val(nine_release_broker_check);
								$('#nine_release_agent_check').val(nine_release_agent_check);
								
								$('#ten_release_broker_check').val(ten_release_broker_check);
								$('#ten_release_agent_check').val(ten_release_agent_check);

								$('#eleven_release_broker_check').val(eleven_release_broker_check);
								$('#eleven_release_agent_check').val(eleven_release_agent_check);

								$('#twelve_release_broker_check').val(twelve_release_broker_check);
								$('#twelve_release_agent_check').val(twelve_release_agent_check);
								

								if(take_out_date == '01/01/1970'){
									take_out_date = '';
								} 								
								$('#bpm_take_out_date').val(take_out_date);
								 
								tcp    		= Comma(parseFloat(tcp).toFixed(2));
								 
								discount	= Comma(parseFloat(discount).toFixed(2));
						
								$('#bpm_tcp').val(tcp); 
 
								$('#first_release_date').val(first_release_date);
								$('#second_release_date').val(second_release_date); 
								$('#third_release_date').val(third_release_date);
								$('#fourth_release_date').val(fourth_release_date);
								$('#fifth_release_date').val(fifth_release_date);
								$('#six_release_date').val(six_release_date);
								$('#seven_release_date').val(seven_release_date);
								$('#eight_release_date').val(eight_release_date);
								$('#nine_release_date').val(nine_release_date);
								$('#ten_release_date').val(ten_release_date);
								$('#eleven_release_date').val(eleven_release_date);
								$('#twelve_release_date').val(twelve_release_date);

								$('#partial_date').val(partial_date);
								$('#full_date').val(full_date);
								$('#total_date').val(total_date);
 
								$('#subtotal_release_amount').val(subtotal_amount);
								$('#balancereleasecheckbox').val(balance_checkbox);
								$('#balance_amount').val(balance_amount);

								$('#full_release_checkbox').val(full_checkbox);

 
								$('#partial_amount').val(partial_amount);
								$('#partial_wht').val(partial_wht);
								$('#partial_cash_advance').val(partial_cash);
								$('#partial_net').val(partial_net);
								$('#partial_check').val(partial_check);

								$('#full_amount').val(full_amount);
								$('#full_wht').val(full_wht);
								$('#full_cash_advance').val(full_cash);
								$('#full_net').val(full_net);
								$('#full_check').val(full_check);

								$('#total_amount').val(total_release_amount);
								$('#total_wht').val(total_release_wht);
								$('#total_cash_advance').val(total_release_cash);
								$('#total_net').val(total_release_net);
								$('#total_check').val(total_release_check);
 
								$('#releases_status').val(release_status);
								$('#releases_remarks').val(release_remarks);
 
								$('#withholding_tax').val(wht);
								$('#bpm_less_discount').val(discount);					
								$('#bpm_rate').val(rate);
								$('#bpm_misc_expense_rate').val(misc_expense_rate);

								$('#bpm_buyer').val(full_name);

								if(date_rf_deposited=='01/01/1970'){
									date_rf_deposited = '';
								}

								$('#bpm_date_rf_deposited').val(date_rf_deposited);
								$('#bpm_block').val(block);
								$('#bpm_broker').val(broker);
								$('#bpm_agent').val(agent);
								$('#bpm_realty').val(realty);
								$('#bpm_lot').val(lot);
								$('#reservation_id').val(reservation_id);
								 
								reservation	= Comma(parseFloat(reservation).toFixed(2)); 
								if(reservation=='' || reservation=='NaN' || reservation==undefined || reservation==null){
									$('#bpm_reservation').val(parseFloat(0.00).toFixed(2));	
								}else{
									$('#bpm_reservation').val(reservation);
								}
								
								less_ca	= Comma(parseFloat(less_ca).toFixed(2)); 
								if(less_ca=='' || less_ca=='NaN' || less_ca==undefined || less_ca==null){
									$('#bpm_less_ca').val(parseFloat(0.00).toFixed(2));	
									$('#ca_cash').val(parseFloat(0.00).toFixed(2));	
								}else{
									$('#bpm_less_ca').val(less_ca);
									$('#ca_cash').val(less_ca);
								}
								
								
								bpm_reservation_less_ca	= Comma(parseFloat(bpm_reservation_less_ca).toFixed(2)); 
								if(bpm_reservation_less_ca=='' || bpm_reservation_less_ca=='NaN' || bpm_reservation_less_ca==undefined || bpm_reservation_less_ca==null){
									$('#bpm_reservation_less_ca').val(parseFloat(0.00).toFixed(2));	
								}else{
									$('#bpm_reservation_less_ca').val(reservation_less_ca);
								}
								
 
								//if no values will set default values of 
								var default_reservation = $('#bpm_reservation').val();
								  
								if(default_reservation=='' || default_reservation=='0' || default_reservation=='0.00' || default_reservation=='NaN' || default_reservation=='0'){
 								 	$('#first_release_cash').val('0.00');
									$('#first_release_net').val('0.00');
									$('#total_release_cash').val('0.00');
									$('#total_release_net').val('0.00');
									$('#bpm_reservation').val('0.00');
									$('#bpm_less_discount').val('0.00');
								}

								 
 
								var default_less_discount = $('#bpm_less_discount').val();
								if(default_less_discount=='NaN' || default_less_discount=='' || default_less_discount=='0.00' || default_less_discount=='0'){
									$('#bpm_less_discount').val('10,000.00');
								}

								var default_rate = $('#bpm_rate').val();
								if(default_rate=='NaN' || default_rate=='' || default_rate=='0.00' || default_rate=='0'){
									$('#bpm_rate').val(7);
								}
								
								var default_misc_expense_rate = $('#bpm_misc_expense_rate').val();
								if(default_misc_expense_rate=='NaN' || default_misc_expense_rate=='' || default_misc_expense_rate=='0.00' || default_misc_expense_rate=='0'){
									$('#bpm_misc_expense_rate').val(14);
								}
								
								var default_less_ca = $('#bpm_less_ca').val();
								if(default_less_ca=='NaN' || default_less_ca=='' || default_less_ca=='0.00' || default_less_ca=='0'){
									//$('#bpm_less_ca').val('5,000.00'); 
								}

								var default_witholding = $('#withholding_tax').val();
								if(default_witholding=='NaN' || default_witholding=='' || default_witholding=='0.00' || default_witholding=='0'){
									$('#withholding_tax').val(10);
								}


								 	if(balance_checkbox=="on"){ 
										$('#balancereleasecheckbox').attr("checked",true);
									}

									if(full_checkbox=="on"){ 
										$('#full_release_checkbox').attr("checked",true);
									}
								 

 
								computeBalaceReservationLessCa();
								computeMiscExpense();
								computeBasisCommission();
								computeCommission(); 
								computeWHT();
								releaseStatus();

						});
			}
}


var rfdep = $('#bpm_date_rf_deposited').val();
//check if rf deposited have values otherwise reservation and CA should be empty, it will be filled up once rf deposited had been selected

if(rfdep==''){
	$('#bpm_reservation').val('0.00');
	$('#bpm_less_ca').val('0.00');	
}



$('#bpm_date_rf_deposited').change(function(e){
	e.preventDefault();  
	//if the date reservation deposited changed/selected check condition in release to broker database table if there's values already in reservation and less ca incase admin has made some modifications.  
	//If there's no existing values will used the fixed values P10,000 for reservation and P5,000 for less CA

	$('#bpm_reservation').val('10,000.00');
	$('#bpm_less_ca').val('5,000.00');
	$('#ca_cash').val('5,000.00'); 
});
  
function computeBalaceReservationLessCa(){
	var reservation = $('#bpm_reservation').val().replace(/,/g, "");
	var less_ca = $('#bpm_less_ca').val().replace(/,/g, "");
	var total = reservation - less_ca;
	total = Comma(total.toFixed(2));
	$('#bpm_reservation_less_ca').val(total);
}


function computeMiscExpense(){ 
	var misc_expense_rate 	=	$('#bpm_misc_expense_rate').val().replace(/,/g, "");
	var tcp 				=	$('#bpm_tcp').val().replace(/,/g, "");
	var discount			=	$('#bpm_less_discount').val().replace(/,/g, "");
 
	var total 				=	(tcp - discount) * (misc_expense_rate/100);
	total 					=	Comma(total.toFixed(2));
	$('#bpm_misc_expenses').val(total);	
}
 

function computeWHT(){ 

	var withhold 				=	$('#withholding_tax').val();
  	
  	var first_broker_amount		=	$('#first_release_broker_amount').val().replace(/,/g, "");
	first_broker_amount 		=	first_broker_amount * (withhold/100);
	var first_agent_amount		=	$('#first_release_agent_amount').val().replace(/,/g, "");
	first_agent_amount 			=	first_agent_amount * (withhold/100);
	var first_broker_agent 		= 	first_broker_amount + first_agent_amount;
	first_broker_agent 			=	Comma(first_broker_agent.toFixed(2)); 
	$('#first_release_wht').val(first_broker_agent); 

  	var second_broker_amount	=	$('#second_release_broker_amount').val().replace(/,/g, "");
	second_broker_amount 		=	second_broker_amount * (withhold/100);
	var second_agent_amount		=	$('#second_release_agent_amount').val().replace(/,/g, "");
	second_agent_amount 		=	second_agent_amount * (withhold/100);
	var second_broker_agent 	= 	second_broker_amount + second_agent_amount;
	second_broker_agent 		=	Comma(second_broker_agent.toFixed(2)); 
	$('#second_release_wht').val(second_broker_agent); 

  	var third_broker_amount		=	$('#third_release_broker_amount').val().replace(/,/g, "");
	third_broker_amount 		=	third_broker_amount * (withhold/100);
	var third_agent_amount		=	$('#third_release_agent_amount').val().replace(/,/g, "");
	third_agent_amount 			=	third_agent_amount * (withhold/100);
	var third_broker_agent 		= 	third_broker_amount + third_agent_amount;
	third_broker_agent 			=	Comma(third_broker_agent.toFixed(2)); 
	$('#third_release_wht').val(third_broker_agent); 


  	var fourth_broker_amount		=	$('#fourth_release_broker_amount').val().replace(/,/g, "");
	fourth_broker_amount 			=	fourth_broker_amount * (withhold/100);
	var fourth_agent_amount			=	$('#fourth_release_agent_amount').val().replace(/,/g, "");
	fourth_agent_amount 			=	fourth_agent_amount * (withhold/100);
	var fourth_broker_agent 		= 	fourth_broker_amount + fourth_agent_amount;
	fourth_broker_agent 			=	Comma(fourth_broker_agent.toFixed(2)); 
	$('#fourth_release_wht').val(fourth_broker_agent); 

  	var fifth_broker_amount		=	$('#fifth_release_broker_amount').val().replace(/,/g, "");
	fifth_broker_amount 		=	fifth_broker_amount * (withhold/100);
	var fifth_agent_amount		=	$('#fifth_release_agent_amount').val().replace(/,/g, "");
	fifth_agent_amount 			=	fifth_agent_amount * (withhold/100);
	var fifth_broker_agent 		= 	fifth_broker_amount + fifth_agent_amount;
	fifth_broker_agent 			=	Comma(fifth_broker_agent.toFixed(2)); 
	$('#fifth_release_wht').val(fifth_broker_agent); 


  	var six_broker_amount		=	$('#six_release_broker_amount').val().replace(/,/g, "");
	six_broker_amount 			=	six_broker_amount * (withhold/100);
	var six_agent_amount		=	$('#six_release_agent_amount').val().replace(/,/g, "");
	six_agent_amount 			=	six_agent_amount * (withhold/100);
	var six_broker_agent 		= 	six_broker_amount + six_agent_amount;
	six_broker_agent 			=	Comma(six_broker_agent.toFixed(2)); 
	$('#six_release_wht').val(six_broker_agent); 

  	var seven_broker_amount		=	$('#seven_release_broker_amount').val().replace(/,/g, "");
	seven_broker_amount 		=	seven_broker_amount * (withhold/100);
	var seven_agent_amount		=	$('#seven_release_agent_amount').val().replace(/,/g, "");
	seven_agent_amount 			=	seven_agent_amount * (withhold/100);
	var seven_broker_agent 		= 	seven_broker_amount + seven_agent_amount;
	seven_broker_agent 			=	Comma(seven_broker_agent.toFixed(2)); 
	$('#seven_release_wht').val(seven_broker_agent); 

  	var eight_broker_amount		=	$('#eight_release_broker_amount').val().replace(/,/g, "");
	eight_broker_amount			=	eight_broker_amount * (withhold/100);
	var eight_agent_amount		=	$('#eight_release_agent_amount').val().replace(/,/g, "");
	eight_agent_amount 			=	eight_agent_amount * (withhold/100);
	var eight_broker_agent 		= 	eight_broker_amount + eight_agent_amount;
	eight_broker_agent 			=	Comma(eight_broker_agent.toFixed(2)); 
	$('#eight_release_wht').val(eight_broker_agent); 

  	var nine_broker_amount		=	$('#nine_release_broker_amount').val().replace(/,/g, "");
	nine_broker_amount 			=	nine_broker_amount * (withhold/100);
	var nine_agent_amount		=	$('#nine_release_agent_amount').val().replace(/,/g, "");
	nine_agent_amount 			=	nine_agent_amount * (withhold/100);
	var nine_broker_agent 		= 	nine_broker_amount + nine_agent_amount;
	nine_broker_agent 			=	Comma(nine_broker_agent.toFixed(2)); 
	$('#nine_release_wht').val(nine_broker_agent); 

  	var ten_broker_amount		=	$('#ten_release_broker_amount').val().replace(/,/g, "");
	ten_broker_amount 			=	ten_broker_amount * (withhold/100);
	var ten_agent_amount		=	$('#ten_release_agent_amount').val().replace(/,/g, "");
	ten_agent_amount 			=	ten_agent_amount * (withhold/100);
	var ten_broker_agent 		= 	ten_broker_amount + ten_agent_amount;
	ten_broker_agent 			=	Comma(ten_broker_agent.toFixed(2)); 
	$('#ten_release_wht').val(ten_broker_agent); 


	var eleven_broker_amount	=	$('#eleven_release_broker_amount').val().replace(/,/g, "");
	eleven_broker_amount 		=	eleven_broker_amount * (withhold/100);
	var eleven_agent_amount		=	$('#eleven_release_agent_amount').val().replace(/,/g, "");
	eleven_agent_amount 		=	eleven_agent_amount * (withhold/100);
	var eleven_broker_agent 	= 	eleven_broker_amount + ten_agent_amount;
	eleven_broker_agent 		=	Comma(eleven_broker_agent.toFixed(2)); 
	$('#eleven_release_wht').val(eleven_broker_agent); 


	var twelve_broker_amount	=	$('#twelve_release_broker_amount').val().replace(/,/g, "");
	twelve_broker_amount 		=	twelve_broker_amount * (withhold/100);
	var twelve_agent_amount		=	$('#twelve_release_agent_amount').val().replace(/,/g, "");
	twelve_agent_amount 		=	twelve_agent_amount * (withhold/100);
	var twelve_broker_agent 	= 	twelve_broker_amount + twelve_agent_amount;
	twelve_broker_agent 		=	Comma(twelve_broker_agent.toFixed(2)); 
	$('#twelve_release_wht').val(twelve_broker_agent); 

	computeNetCom();
  
}

function computeBasisCommission(){ 
	var tcp 					=	$('#bpm_tcp').val().replace(/,/g, "");
	var bpm_less_discount 		=	$('#bpm_less_discount').val().replace(/,/g, "");
	var bpm_misc_expenses		=	$('#bpm_misc_expenses').val().replace(/,/g, "");
	var commission				=	tcp - bpm_less_discount - bpm_misc_expenses;
	commission 					=	Comma(commission.toFixed(2)); 
	$('#bpm_basis_commission').val(commission);	
}

function computeBalance(){
	var bpm_reservation		=	$('#bpm_reservation').val().replace(/,/g, "");
	var bpm_less_ca			=	$('#bpm_less_ca').val().replace(/,/g, "");
	var ca_cash 			=	$('#bpm_less_ca').val();
	$('#ca_cash').val(ca_cash);

 	var balance 			=	bpm_reservation - bpm_less_ca; 
 	balance					=	Comma(balance.toFixed(2)); 
	$('#bpm_reservation_less_ca').val(balance); 
}

function computeCommission(){	
  	var bpm_basis_commission	=	$('#bpm_basis_commission').val().replace(/,/g, "");
	var bpm_rate				=	$('#bpm_rate').val().replace(/,/g, "");
 	var total 					=	bpm_basis_commission * (bpm_rate/100);
 	total 						=	Comma(total.toFixed(2));
 	 
	$('#bpm_commission').val(total);
	var partial_amount = '50,000.00';
	$('#partial_amount').val(partial_amount); //FIXED AMOUNT OF 50,000.00
	
	var full_amount =	total.replace(/,/g, "") - partial_amount.replace(/,/g, "");
	full_amount		=	(full_amount!='NaN' || full_amount!='' || full_amount!=null) ? Comma(full_amount.toFixed(2)) : '0.00';
	$('#full_amount').val(full_amount);
	$('#total_amount').val(total);
 
 	computeAmountBalance();
}

function computeAmountBalance(){
	//GET BROKER AMOUNT
	var first_release_broker_amount		= $('#first_release_broker_amount').val().replace(/,/g, "");
	var second_release_broker_amount	= $('#second_release_broker_amount').val().replace(/,/g, "");
	var third_release_broker_amount		= $('#third_release_broker_amount').val().replace(/,/g, "");
	var fourth_release_broker_amount	= $('#fourth_release_broker_amount').val().replace(/,/g, "");
  	var fifth_release_broker_amount		= $('#fifth_release_broker_amount').val().replace(/,/g, "");
	var six_release_broker_amount		= $('#six_release_broker_amount').val().replace(/,/g, "");
	var seven_release_broker_amount		= $('#seven_release_broker_amount').val().replace(/,/g, "");
	var eight_release_broker_amount		= $('#eight_release_broker_amount').val().replace(/,/g, "");
	var nine_release_broker_amount		= $('#nine_release_broker_amount').val().replace(/,/g, "");
	var ten_release_broker_amount		= $('#ten_release_broker_amount').val().replace(/,/g, "");
	var eleven_release_broker_amount	= $('#eleven_release_broker_amount').val().replace(/,/g, "");
	var twelve_release_broker_amount	= $('#twelve_release_broker_amount').val().replace(/,/g, "");


	//GET AGENT AMOUNT
	var first_release_agent_amount 		= $('#first_release_agent_amount').val().replace(/,/g, "");
	var second_release_agent_amount		= $('#second_release_agent_amount').val().replace(/,/g, "");
	var third_release_agent_amount		= $('#third_release_agent_amount').val().replace(/,/g, "");
	var fourth_release_agent_amount		= $('#fourth_release_agent_amount').val().replace(/,/g, "");
  	var fifth_release_agent_amount		= $('#fifth_release_agent_amount').val().replace(/,/g, "");
	var six_release_agent_amount		= $('#six_release_agent_amount').val().replace(/,/g, "");
	var seven_release_agent_amount		= $('#seven_release_agent_amount').val().replace(/,/g, "");
	var eight_release_agent_amount		= $('#eight_release_agent_amount').val().replace(/,/g, "");
	var nine_release_agent_amount		= $('#nine_release_agent_amount').val().replace(/,/g, "");
	var ten_release_agent_amount		= $('#ten_release_agent_amount').val().replace(/,/g, "");
	var eleven_release_agent_amount		= $('#eleven_release_agent_amount').val().replace(/,/g, "");
	var twelve_release_agent_amount		= $('#twelve_release_agent_amount').val().replace(/,/g, "");

	var subtotal_broker 		= parseFloat(first_release_broker_amount) + parseFloat(second_release_broker_amount)  + parseFloat(third_release_broker_amount) + parseFloat(fourth_release_broker_amount) + parseFloat(fifth_release_broker_amount) + parseFloat(six_release_broker_amount) + parseFloat(seven_release_broker_amount) + parseFloat(eight_release_broker_amount) + parseFloat(nine_release_broker_amount) + parseFloat(ten_release_broker_amount) + parseFloat(eleven_release_broker_amount) + parseFloat(twelve_release_broker_amount);

	var csubtotal_broker		= Comma(subtotal_broker.toFixed(2));
	$('#subtotal_release_broker_amount').val(csubtotal_broker);

	var subtotal_agent 		= parseFloat(first_release_agent_amount) + parseFloat(second_release_agent_amount)  + parseFloat(third_release_agent_amount) + parseFloat(fourth_release_agent_amount) + parseFloat(fifth_release_agent_amount) + parseFloat(six_release_agent_amount) + parseFloat(seven_release_agent_amount) + parseFloat(eight_release_agent_amount) + parseFloat(nine_release_agent_amount) + parseFloat(ten_release_agent_amount) + parseFloat(eleven_release_agent_amount) + parseFloat(twelve_release_agent_amount);
	var csubtotal_agent		= Comma(subtotal_agent.toFixed(2));
	$('#subtotal_release_agent_amount').val(csubtotal_agent);

	var subtotal_broker_agent 		= subtotal_broker + subtotal_agent;
	var csubtotal_broker_agent		= Comma(subtotal_broker_agent.toFixed(2));
	$('#subtotal_release_amount').val(csubtotal_broker_agent);

 
	var partial_amount 	= $('#partial_amount').val().replace(/,/g, "");
	var balance_amount 	= parseFloat(partial_amount) - parseFloat(subtotal_broker_agent);
	var cbalance_amount = Comma(balance_amount.toFixed(2));
	$('#balance_amount').val(cbalance_amount);

	var ca_cash = $('#ca_cash').val();
	$('#partial_cash_advance').val(ca_cash);


	//GET WHT
	var withhold 		=	$('#withholding_tax').val();
	var partial_amount 	=	$('#partial_amount').val().replace(/,/g, "");
	partial_amount 		=	partial_amount * (withhold/100);
	partial_amount		=	Comma(partial_amount.toFixed(2)); 
	$('#partial_wht').val(partial_amount); 
 
 	var full_amount 	=	$('#full_amount').val().replace(/,/g, "");
	var full_wht 		=	full_amount * (withhold/100);
	var cfull_amount	=	Comma(full_wht.toFixed(2)); 
	$('#full_wht').val(cfull_amount); 
	var full_net   		=	parseFloat(full_amount) - parseFloat(full_wht);
	var cfull_net		=	Comma(full_net.toFixed(2)); 
	$('#full_net').val(cfull_net);
 
 	var total_amount 	=	$('#total_amount').val().replace(/,/g, "");
	total_amount 		=	total_amount * (withhold/100);
	total_amount		=	Comma(total_amount.toFixed(2)); 
	$('#total_wht').val(total_amount); 


	//partial_net = balance - partial_wht - ca 
	var balance_amount 	=	$('#balance_amount').val().replace(/,/g, ""); 
	var partial_wht 	=	$('#partial_wht').val().replace(/,/g, ""); 
	var ca_cash 		=	$('#ca_cash').val().replace(/,/g, "");
	var partial_amount 	=	$('#partial_amount').val().replace(/,/g, ""); 
	if(balance_amount!='0.00'){
		var partial_net_compute = parseFloat(balance_amount) - parseFloat(partial_wht) - parseFloat(ca_cash);	
	}else{
		var partial_net_compute = parseFloat(partial_amount) - parseFloat(partial_wht) - parseFloat(ca_cash);
	}
	
	var cpartial_net_compute	=	Comma(partial_net_compute.toFixed(2)); 
	$('#partial_net').val(cpartial_net_compute);

	var partial_net 	=	$('#partial_net').val().replace(/,/g, ""); 
	var full_net 		=	$('#full_net').val().replace(/,/g, ""); 
	var partial_full	=   parseFloat(partial_net) + parseFloat(full_net);
	var cpartial_full	=	Comma(partial_full.toFixed(2)); 
	$('#total_net').val(cpartial_full);
    
}


$('#bpm_misc_expense_rate').change(function(e){
	e.preventDefault();
	computeMiscExpense();	
	computeBasisCommission();
	computeCommission();
	releaseStatus();
});


$('#bpm_less_discount').change(function(e){
	e.preventDefault();
	computeBasisCommission();
	computeCommission();
});

$('#bpm_rate').change(function(e){
	e.preventDefault();
	computeCommission();	
});


function computeNetCom(){
 
	var first_broker_amount		= parseFloat($('#first_release_broker_amount').val().replace(/,/g, ""));
	var first_agent_amount		= parseFloat($('#first_release_agent_amount').val().replace(/,/g, ""));
	var first_wht 				= parseFloat($('#first_release_wht').val().replace(/,/g, ""));	 
	var first_net 				= Comma(((parseFloat(first_broker_amount) + parseFloat(first_agent_amount)) - first_wht).toFixed(2));
	$('#first_release_net').val(first_net);  

	var second_broker_amount	= parseFloat($('#second_release_broker_amount').val().replace(/,/g, ""));
	var second_agent_amount		= parseFloat($('#second_release_agent_amount').val().replace(/,/g, ""));
	var second_wht 				= parseFloat($('#second_release_wht').val().replace(/,/g, ""));	 
	var second_net 				= Comma(((parseFloat(second_broker_amount) + parseFloat(second_agent_amount)) - second_wht).toFixed(2));
	$('#second_release_net').val(second_net);

	var third_broker_amount		= parseFloat($('#third_release_broker_amount').val().replace(/,/g, ""));
	var third_agent_amount		= parseFloat($('#third_release_agent_amount').val().replace(/,/g, ""));
	var third_wht 				= parseFloat($('#third_release_wht').val().replace(/,/g, ""));	 
	var third_net 				= Comma(((parseFloat(third_broker_amount) + parseFloat(third_agent_amount)) - third_wht).toFixed(2));
	$('#third_release_net').val(third_net);  

	var fourth_broker_amount	= parseFloat($('#fourth_release_broker_amount').val().replace(/,/g, ""));
	var fourth_agent_amount		= parseFloat($('#fourth_release_agent_amount').val().replace(/,/g, ""));
	var fourth_wht 				= parseFloat($('#fourth_release_wht').val().replace(/,/g, ""));	 
	var fourth_net 				= Comma(((parseFloat(fourth_broker_amount) + parseFloat(fourth_agent_amount)) - fourth_wht).toFixed(2));
	$('#fourth_release_net').val(fourth_net);  

	var fifth_broker_amount		= parseFloat($('#fifth_release_broker_amount').val().replace(/,/g, ""));
	var fifth_agent_amount		= parseFloat($('#fifth_release_agent_amount').val().replace(/,/g, ""));
	var fifth_wht 				= parseFloat($('#fifth_release_wht').val().replace(/,/g, ""));	 
	var fifth_net 				= Comma(((parseFloat(fifth_broker_amount) + parseFloat(fifth_agent_amount)) - fifth_wht).toFixed(2));
	$('#fifth_release_net').val(fifth_net);  

	var six_broker_amount		= parseFloat($('#six_release_broker_amount').val().replace(/,/g, ""));
	var six_agent_amount		= parseFloat($('#six_release_agent_amount').val().replace(/,/g, ""));
	var six_wht 				= parseFloat($('#six_release_wht').val().replace(/,/g, ""));	 
	var six_net 				= Comma(((parseFloat(six_broker_amount) + parseFloat(six_agent_amount)) - six_wht).toFixed(2));
	$('#six_release_net').val(six_net);  

	var seven_broker_amount		= parseFloat($('#seven_release_broker_amount').val().replace(/,/g, ""));
	var seven_agent_amount		= parseFloat($('#seven_release_agent_amount').val().replace(/,/g, ""));
	var seven_wht 				= parseFloat($('#seven_release_wht').val().replace(/,/g, ""));	 
	var seven_net 				= Comma(((parseFloat(seven_broker_amount) + parseFloat(seven_agent_amount)) - seven_wht).toFixed(2));
	$('#seven_release_net').val(seven_net);  


	var eight_broker_amount		= parseFloat($('#eight_release_broker_amount').val().replace(/,/g, ""));
	var eight_agent_amount		= parseFloat($('#eight_release_agent_amount').val().replace(/,/g, ""));
	var eight_wht 				= parseFloat($('#eight_release_wht').val().replace(/,/g, ""));	 
	var eight_net 				= Comma(((parseFloat(eight_broker_amount) + parseFloat(eight_agent_amount)) - eight_wht).toFixed(2));
	$('#eight_release_net').val(eight_net);  

	var nine_broker_amount		= parseFloat($('#nine_release_broker_amount').val().replace(/,/g, ""));
	var nine_agent_amount		= parseFloat($('#nine_release_agent_amount').val().replace(/,/g, ""));
	var nine_wht 				= parseFloat($('#nine_release_wht').val().replace(/,/g, ""));	 
	var nine_net 				= Comma(((parseFloat(nine_broker_amount) + parseFloat(nine_agent_amount)) - nine_wht).toFixed(2));
	$('#nine_release_net').val(nine_net);  

	var ten_broker_amount		= parseFloat($('#ten_release_broker_amount').val().replace(/,/g, ""));
	var ten_agent_amount		= parseFloat($('#ten_release_agent_amount').val().replace(/,/g, ""));
	var ten_wht 				= parseFloat($('#ten_release_wht').val().replace(/,/g, ""));	 
	var ten_net 				= Comma(((parseFloat(ten_broker_amount) + parseFloat(ten_agent_amount)) - ten_wht).toFixed(2));
	$('#ten_release_net').val(ten_net);  

	var eleven_broker_amount	= parseFloat($('#eleven_release_broker_amount').val().replace(/,/g, ""));
	var eleven_agent_amount		= parseFloat($('#eleven_release_agent_amount').val().replace(/,/g, ""));
	var eleven_wht 				= parseFloat($('#eleven_release_wht').val().replace(/,/g, ""));	 
	var eleven_net 				= Comma(((parseFloat(eleven_broker_amount) + parseFloat(eleven_agent_amount)) - eleven_wht).toFixed(2));
	$('#eleven_release_net').val(eleven_net);  

	var twelve_broker_amount	= parseFloat($('#twelve_release_broker_amount').val().replace(/,/g, ""));
	var twelve_agent_amount		= parseFloat($('#twelve_release_agent_amount').val().replace(/,/g, ""));
	var twelve_wht 				= parseFloat($('#twelve_release_wht').val().replace(/,/g, ""));	 
	var twelve_net 				= Comma(((parseFloat(twelve_broker_amount) + parseFloat(twelve_agent_amount)) - twelve_wht).toFixed(2));
	$('#twelve_release_net').val(twelve_net);  
}
  

function releaseStatus(){
	 let balance_check 	= $('#balancereleasecheckbox').prop("checked");
	 let full_check 	= $('#full_release_checkbox').prop("checked");
	   
	if(balance_check==true && full_check==true){
		$('#releases_status').val('Fully Paid');
	}else{
		$('#releases_status').val('With Balance');
	} 

	if(balance_check==true && full_check==true){
		$(":input[name=total_check]").focus();	
	}else if(balance_check==true){
		$(":input[name=partial_check]").focus();	
	}else if(full_check==true){
		$(":input[name=full_check]").focus();	
	}
}

$('#balancereleasecheckbox').on('change',function(){
	releaseStatus(); 
}); 

$('#full_release_checkbox').on('change',function(){
	releaseStatus(); 
}); 
 



function checkCompleteRequirements(reservationId){
  
	var dataString				=	"reservation_id="+encodeURIComponent(reservationId); 
	$.post('./ajax/check_complete_requirements.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									//REQUIREMENTS ALL COMPLETE
									$('#complete_requirement').val('yes');
								}else{
									//REQUIREMENTS INCOMPLETE
									$('#complete_requirement').val('no');
								}
						}); 
}

function checkCompleteEquity(reservationId){
  
	var dataString				=	"reservation_id="+encodeURIComponent(reservationId); 
	$.post('./ajax/check_complete_equity.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									//EQUITY ALL COMPLETE
									$('#complete_equity').val('yes');
								}else{
									//EQUITY INCOMPLETE
									$('#complete_equity').val('no');
								}
						}); 
}
