				var action 					=	$('#main_action').val();
				var types 					=	$('#main_type').val(); 
				if((action=="edit" || action=="view")&& types=="units"){
					load_units();
				}
//SAVING UNITS
function save_units(){
				var mods 					=	$('#main_page').val();
				var types 					=	$('#main_type').val(); 
				var action 					=	$('#main_action').val();
				var mainid					=	$('#main_id').val();
				var myform 					=	$('#units_form');

				myform.find('select:disabled').removeAttr('disabled');
				myform.find(':input:disabled').removeAttr('disabled');
				var unit_details	=	$('#units_form').serialize(); 
				var dataString		=	unit_details+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid);
						$.post('./ajax/units.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_units(id){
		var transaction		=	"units";
		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 UNITS  
function load_units(){
				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;
 
									html = '<tr>'; 
										html += '<td><label>Block</label></td>';
							            html += '<td><input type="text" name="UnitBlock[]" value="'+block+'"  maxlength="5" class="form-control"></td>';
							            html += '<td><label>Lot</label></td>';
							            html += '<td><input type="number" name="UnitLot[]" value="'+lot+'" class="form-control"></td>';
							            html += '<td><button type="button" class="btn btn-danger btn-xs" onclick="deleteRow(this);"><span class="glyphicon glyphicon-trash"></span></button></td>';
							        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();  
								}
						});						
}