<div class="col-md-6" style="max-height:400px; overflow-x: scroll;">
    <table class="table table-condensed table-striped table-bordered">
    	<tr><th class="text-success">Assign New Areas</th>
        	<th><button type="button" class="btn btn-success pull-right btn-sm allareas" id="add">Add All</button></th></tr>
    	<tr><th>Area</th><th>Add</th></tr>
        <?php foreach($areas as $ar){
			if($this->db->get_where("agent_areas",array("area_id"=>$ar->area_id,"agent_id"=>$agent))->num_rows()==0){?>
        <tr><td><?php echo $ar->area_name.' '.$ar->area_pincode;?></td>
            <td><a href="#" id="<?php echo $ar->area_id;?>" class="btn btn-sm btn-success addarea"><i class="fa fa-check"></i> Add</a></td></tr>
      <?php }}?>
    </table>
</div>
<div class="col-md-6" style="max-height:400px; overflow-x: scroll;">
    <table class="table table-condensed table-striped table-bordered">
    	<tr><th class="text-warning">Assigned Areas</th>
        	<th><button type="button" class="btn btn-danger pull-right btn-sm allareas" id="remove">Remove All</button></th></tr>
    	<tr><th>Area</th><th>Add</th></tr>
        <?php foreach($agent_areas as $ar){?>
        <tr><td><?php echo $ar->area_name.' '.$ar->area_pincode;?></td>
            <td><a href="#" id="<?php echo $ar->area_id;?>" class="btn btn-sm btn-danger addarea"><i class="fa fa-times"></i> Remove</a></td></tr>
      <?php }?>
    </table>
</div>
<script>
$(document).ready(function(){//alert("asdf");

$(".allareas").click(function(e){e.preventDefault();
	var id=$(this).attr("id");
	//alert(id);
	$.ajax({
		 type: "POST",
		 url: '<?php echo base_url();?>admin/ajax_addall_area',
		 data: {type:id,agent:'<?php echo $agent;?>',city:'<?php echo $city;?>'},
		 success: function(res){
			// alert(res);
			reload_data(<?php echo $agent;?>,<?php echo $city;?>)
		 }
	});
});

$(".addarea").click(function(e){e.preventDefault();
	var id=$(this).attr("id");
	//alert(id);
	$.ajax({
		 type: "POST",
		 url: '<?php echo base_url();?>admin/ajax_agent_areas_assign',
		 data: {id:id,agent:<?php echo $agent;?>},
		 success: function(res){
			// alert(res);
			reload_data(<?php echo $agent;?>,<?php echo $city;?>)
		 }
	});
});
function reload_data(id1,id2){
	var id=id1+'-'+id2;
	$.ajax({
		 type: "POST",
		 url: '<?php echo base_url();?>admin/ajax_agent_areas',
		 data: {id:id},
		 success: function(res){
			$(".agent_areas_div").html(res);
		 }
	});	
}
});
</script>