function save_contractor(){ 
	var mods 					=	$('#main_page').val();
	var types 					=	$('#main_type').val(); 
	var action 					=	$('#main_action').val();
	var mainid					=	$('#main_id').val(); 
	var contractor  			=	$('#contractor_form').serialize(); 
    
	var dataString				=	contractor+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid)+"&types="+encodeURIComponent(types);  
	$.post('./ajax/contractor.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_contractor(id){
		var transaction		=	"contractor";
		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);
								}	
						});
} 



	var action 					=	$('#main_action').val();
if(action!='create'){
load_contractor();	
}


function load_contractor(){
				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_contractor.php', dataString, function(msg){ 
								var obj				= $.parseJSON(msg); 
								var contractor_id	=	obj.data[0].id; 
								var contractor		=	obj.data[0].contractor; 
								var contact_person	=	obj.data[0].contact_person; 
								var contactno		=	obj.data[0].contactno; 
								var email			=	obj.data[0].email; 
								var address			=	obj.data[0].address; 
  								     
								$('#broker_broker').val(contractor); 
								$('#broker_contact_person').val(contact_person); 
								$('#broker_contact').val(contactno);
								$('#broker_email').val(email);
								$('#broker_address').val(address); 
   
   								if(action=='view'){
   									$('#broker_broker').attr('readonly',true); 
									$('#broker_contact_person').attr('readonly',true); 
									$('#broker_contact').attr('readonly',true); 
									$('#broker_email').attr('readonly',true); 
									$('#broker_address').attr('readonly',true);  
   								}
   					}); 
}

