				var action 					=	$('#main_action').val();
				var types 					=	$('#main_type').val(); 
				if((action=="edit" || action=="view")&& types=="permits_and_licenses"){
					load_permits_and_licenses();
					load_units_permits_and_licenses();
				}
//SAVING PERMITS AND LICENSES
function save_permits_and_licenses(){
				var mods 					=	$('#main_page').val();
				var types 					=	$('#main_type').val(); 
				var action 					=	$('#main_action').val();
				var mainid					=	$('#main_id').val();
				var myform 					=	$('#permits_and_licenses_form');

				//myform.find('select:disabled').removeAttr('disabled');
				//alert(action);
				//myform.find(':input:disabled').removeAttr('disabled');
				var permits_and_licenses_details	=	$('#permits_and_licenses_form').serialize();  
				var dataString		=	permits_and_licenses_details+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid);
					

						$.post("./ajax/permits_and_licenses.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.");
								}
						});
}

  
function delete_permits_and_licenses(id){
		var transaction		=	"permits_and_licenses";
		var mods 			=	$('#main_page').val();
		var types 			=	$('#main_type').val(); 
		var dataString		=	"mainid="+encodeURIComponent(id)+"&transaction="+encodeURIComponent(transaction)+"&types="+encodeURIComponent(types);
						$.post('./ajax/delete_transaction.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									bootbox.alert("Successfully Deleted ..."); 
									window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}else{
									bootbox.alert("Failed in Deleting ..."); 
									window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}	
						});
} 


//LOADING PERMITS_AND_LICENSES  
function load_permits_and_licenses(){
				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_permits_and_licenses.php', dataString, function(msg){ 
								var obj	= $.parseJSON(msg);
								var block			=	obj.data[0].block;
								var lot				=	obj.data[0].lot;   
								var tax_dec_land_processed			=	obj.data[0].tax_dec_land_processed;
								var tax_dec_land_released			=	obj.data[0].tax_dec_land_released; 

								var tax_dec_building_processed		=	obj.data[0].tax_dec_building_processed;
								var tax_dec_building_released		=	obj.data[0].tax_dec_building_released;

								var tax_receipt_land_processed		=	obj.data[0].tax_receipt_land_processed;
								var tax_receipt_land_released		=	obj.data[0].tax_receipt_land_released;  								
								 
								var tax_receipt_building_processed	=	obj.data[0].tax_receipt_building_processed;	 
								var tax_receipt_building_released	=	obj.data[0].tax_receipt_building_released;	 

								var building_permit_processed		=	obj.data[0].building_permit_processed;	 
								var building_permit_released		=	obj.data[0].building_permit_released;

								var electrical_permit_processed		=	obj.data[0].electrical_permit_processed;
								var electrical_permit_released		=	obj.data[0].electrical_permit_released; 

								var sanitary_permit_processed		=	obj.data[0].sanitary_permit_processed;
								var sanitary_permit_released		=	obj.data[0].sanitary_permit_released;
								
								var occupancy_permit_processed		=	obj.data[0].occupancy_permit_processed;
								var occupancy_permit_released		=	obj.data[0].occupancy_permit_released;							 		
									  
								$('#block').val(block);  
								$('#lot').val(lot); 
								$('#tax_dec_land_processed').val(tax_dec_land_processed);  
								$('#tax_dec_land_released').val(tax_dec_land_released); 
								$('#tax_dec_building_processed').val(tax_dec_building_processed); 
								$('#tax_dec_building_released').val(tax_dec_building_released);  
								$('#tax_receipt_land_processed').val(tax_receipt_land_processed); 
								$('#tax_receipt_land_released').val(tax_receipt_land_released); 
								
								$('#tax_receipt_building_processed').val(tax_receipt_building_processed); 
								$('#tax_receipt_building_released').val(tax_receipt_building_released); 
								$('#building_permit_processed').val(building_permit_processed); 
								$('#building_permit_released').val(building_permit_released); 
								$('#electrical_permit_processed').val(electrical_permit_processed); 
								$('#electrical_permit_released').val(electrical_permit_released); 
								$('#sanitary_permit_processed').val(sanitary_permit_processed); 
								$('#sanitary_permit_released').val(sanitary_permit_released); 

								$('#occupancy_permit_processed').val(occupancy_permit_processed); 
								$('#occupancy_permit_released').val(occupancy_permit_released); 



								if(action=="view"){
									$('input').attr("disabled", true);
									$('textarea').attr("disabled", true);
									$('select').attr("disabled", true); 
									$('.glyphicon-trash').hide();
									$('.glyphicon-plus').hide();  
								}
						});						
}





//LOADING UNITS  
function load_units_permits_and_licenses(){
				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_units.php', dataString, function(msg){ 
								var obj	= $.parseJSON(msg);
								 
								var html = '';
								for(let a=0; a<obj.data.length; a++){
									let block		=	obj.data[a].block;
									let lot			=	obj.data[a].lot;
									let landno		=	obj.data[a].landno;
									let bldgno		=	obj.data[a].bldgno;
									let unitid 		=	obj.data[a].id;
 	
									html = '<tr>';  
							            html += '<td><input type="text" 	readonly name="UnitBlock[]" 	value="'+block+'"  maxlength="5" class="form-control"></td>';
							            html += '<td><input type="number" 	readonly name="UnitLot[]" 	value="'+lot+'" class="form-control"></td>';
							            html += '<td><input type="text" 	name="LandNo[]" 	value="'+landno+'" maxlength="15" class="form-control"></td>';
							            html += '<td><input type="text" 	name="BldgNo[]" 	value="'+bldgno+'" maxlength="15" class="form-control"></td>';
										html += '<input type="hidden" 	name="UnitId[]" 	value="'+unitid+'"  class="form-control">';							             
							        html += '</tr>';
							 
							        var row = document.getElementById("tbody").insertRow();
							        row.innerHTML = html;
								}
								   
								if(action=="view"){
									$('input').attr("disabled", true);
									$('textarea').attr("disabled", true);
									$('select').attr("disabled", true); 
									$('.glyphicon-trash').hide();
									$('.glyphicon-plus').hide();  
								}
						});						
}