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

function save_buyer_house_renovation_monitoring(){
				var monitoring_details		= 	$('#buyer_house_renovation_monitoring_form').serialize(); 
				var mods 					=	$('#main_page').val();
				var types 					=	$('#main_type').val(); 
				var action 					=	$('#main_action').val();
				var mainid					=	$('#main_id').val();  
 
				var dataString		=	monitoring_details+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid);
				 
						$.post("./ajax/buyer_house_renovation_monitoring.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=buyer_house_renovation_monitoring'; }, 1000);
								}else{
									bootbox.alert("Failed in saving.");
								}
						}); 
}

//LOADING MONITORING OF FOLDERS DETAILS
function load_buyer_house_renovation_monitoring(){ 
				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_buyer_house_renovation_monitoring.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								var full_name				=	obj.data[0].full_name; 
								var take_out_date			=	obj.data[0].take_out_date; 
								
								var block					=	obj.data[0].block; 
								var lot						=	obj.data[0].lot; 
								var phase					=	obj.data[0].phase; 
							    
							   
								var PermitToConstructNo			=	obj.data[0].PermitToConstructNo; 
								var ConstructionBondPaid		=	obj.data[0].ConstructionBondPaid; 
								var RefundDate					=	obj.data[0].RefundDate; 
								var FullRefundOrWithViolation	=	obj.data[0].FullRefundOrWithViolation; 
								var Penalty						=	Comma(parseFloat(obj.data[0].Penalty.replace(/,/g, "")).toFixed(2));    
								var Remarks						=	obj.data[0].Remarks; 
								var Amount						=	Comma(parseFloat(obj.data[0].Amount.replace(/,/g, "")).toFixed(2));   

 

								var ConstructionBondPaidAmount	=	Comma(parseFloat(obj.data[0].ConstructionBondPaidAmount.replace(/,/g, "")).toFixed(2));     
								var Remarks2					=	obj.data[0].Remarks2;   
								var PaymentDetails				=	obj.data[0].PaymentDetails;   
								var CheckReleaseDetails			=	obj.data[0].CheckReleaseDetails;   

							   if(ConstructionBondPaid=="01/01/1970"){	ConstructionBondPaid = "";	}
							   if(RefundDate=="01/01/1970"){	RefundDate = "";	} 
							   
								$('#bsm_fullname').val(full_name); 
								$('#bsm_take_out_date').val(take_out_date); 
								$('#bsm_phase').val(phase); 
								$('#bsm_block').val(block); 
								$('#bsm_lot').val(lot);  
								
								
								$('#bsm_permit_to_construct_no').val(PermitToConstructNo); 
								$('#bsm_fullrefund_or_withviolation').select2('val',FullRefundOrWithViolation); 
								$('#bsm_fullrefund_or_withviolation1').val(FullRefundOrWithViolation);
								
								$('#bsm_construction_bond_paid').val(ConstructionBondPaid); 
								$('#bsm_penalty').val(Penalty); 
								$('#bsm_amount').val(Amount); 
								$('#bsm_refund_date').val(RefundDate); 
								$('#bsm_remarks').val(Remarks);    

								$('#bsm_construction_bond_paid_amount').val(ConstructionBondPaidAmount); 
								$('#bsm_remarks2').val(Remarks2); 
								$('#bsm_check_release_details').val(CheckReleaseDetails); 
								$('#bsm_payment_details').val(PaymentDetails);  
								/**********************/

  
		var current_user = $('#current_user').val(); 
		if(current_user=='accounting1'){
			$('#bsm_remarks').attr('readonly',true);
			$('#bsm_refund_date').attr('readonly',true);
			$('#bsm_amount').attr('readonly',true);
			$('#bsm_penalty').attr('readonly',true);
			$('#bsm_fullrefund_or_withviolation').css('cursor','not-allowed');  
			$('#bsm_fullrefund_or_withviolation').attr('readonly',true); 
			$('#bsm_refund_date').removeClass('datepicker');
			$('#bsm_construction_bond_paid').addClass('datepicker');

			$('#accounting_on').hide();
			$('#accounting_off').show(); 
			$('#bsm_construction_bond_paid').attr('readonly',false);
			$('#bsm_construction_bond_paid_amount').attr('readonly',false);

			
			$('#bsm_permit_to_construct_no').attr('readonly',false);
			$('#bsm_remarks').attr('readonly',false);
			$('#bsm_payment_details').attr('readonly',false);

			$('#bsm_remarks2').attr('readonly',true);
			$('#bsm_check_release_details').attr('readonly',true);
			
		}else if(current_user=='accounting2'){
			$('#accounting_on').show();
			$('#accounting_off').hide(); 
			$('#bsm_construction_bond_paid').removeClass('datepicker');
			$('#bsm_refund_date').addClass('datepicker');
			$('#bsm_construction_bond_paid').attr('readonly',true); 
			$('#bsm_construction_bond_paid_amount').attr('readonly',true); 
			

			$('#bsm_permit_to_construct_no').attr('readonly',true);
			$('#bsm_remarks').attr('readonly',true);
			$('#bsm_payment_details').attr('readonly',true);
			 
			$('#bsm_remarks2').attr('readonly',false);
			$('#bsm_check_release_details').attr('readonly',false);
			
			$('#bsm_refund_date').attr('readonly',false);
			$('#bsm_amount').attr('readonly',false);
			$('#bsm_penalty').attr('readonly',false);
			
			$('#bsm_fullrefund_or_withviolation').attr('readonly',false); 
		} 
		
								/**********************/
						});
}


