<script type="text/javascript">
$(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
    $("#test").dataTable( {
        "iDisplayLength": 10,
		 "aLengthMenu": [5,10,25,50,100],
		 "sPaginationType": "full_numbers", "aoColumns": [ 
		 	{"bSortable": false },   
			null, 
			null,
			null,
			null,
			{"bSortable": false } ]});

    $("table.editable").on("click",".remove",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_delete").dialog("open");
    });
    $("table.editable").on("click",".edit",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text(); 
        $("#row_edit").dialog("open");
    });
    $("table.editable").on("click",".shipto",function(){
        rRow = $(this).parents("tr");
        ID = $('td:first', $(this).parents('tr')).text();
		urls = "shiptolist/" + ID; 
			window.location.replace(urls);    
	});
    $("#row_edit").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Continue...": function() {
				window.location.href = "newAgent?ID=" + ID;		
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
    function remove_row(row){
        row.remove();
 		$.ajax({
  			type: "POST",
  			url: "agent_delete",
			data:"ID="+ID,
  			success: function(){
				alert('Row has been deleted...');
			},
		});       // Here your ajax action after delete confirmed
    }
    $("#row_delete").dialog({
        autoOpen: false,
        resizable: false,        
        modal: true,
        buttons: {
            "Delete": function() {
                remove_row(rRow);
                $(this).dialog("close");
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        }
    });    
}); 

function printagentlist(){
	var df = $('#selDateFrom').val();
	var dt = $('#selDateTo').val();
	window.open("<?php echo base_url();?>SaleAgentSetup/agentPrint");
	
}
</script>
<div id="content">                        
	<div class="wrap">
		<div class="head">
			<div class="info">
				<!--<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
				<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>-->
				<ul class="breadcrumb">
					<li><a href='<?php echo base_url() ."home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
					<li><a href='<?php echo base_url() ."setting/companysetup" ?>'><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
					<li class="active"><?php echo $this->lang->line('titlelist') ?></li>
				</ul>
			</div>
			<div class="search">
				<form action="<?php echo base_url() ?>admin/search" method="post">
					<input name="search_text" type="text" placeholder="search..."/>                                
					<button type="submit"><span class="i-magnifier"></span></button>
				</form>
			</div>                        
		</div><!-- head --> 
		<div class="content">
			<div class="row-fluid">
				<div class="span12">
				
					<div class="block">
						<div class="head">
							<h2><?php echo $this->lang->line('titlelist') ?></h2>    
							<ul class="buttons">
								<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
							</ul>
							<div class="side fr">           
								<a href="<?php echo base_url(); ?>graph/print-list" class="btn-form btn-success-form" name="updatePosting" target="_blank"><?php echo $this->lang->line('print') ?></a>
								<a href="<?php echo base_url(); ?>graph/new_graph" class="btn-icon btn-warning-form" title="New"><span class="i-plus-2"></span></a>                          
							</div>                                        
						</div>
						<div class="content np table-sorting">
							<table cellpadding="0" cellspacing="0" width="100%" id="test" class="editable">
								<thead>
									<tr>
										<th style="display:none"></th>
										<th>#</th>
										<th><?php echo $this->lang->line('graphName') ?></th>
										<th><?php echo $this->lang->line('page') ?></th>
										<th><?php echo $this->lang->line('status') ?></th>
										<th width="55" class="tac"><?php echo $this->lang->line('action') ?></th>
									</tr>
								</thead>
								<tbody>
									<?php $bil = 0; 
									if($datatbls){
										foreach($datatbls as $datatbl):
										//print_r($datatbl);
										$bil++?>
									<tr>
										<td style="display:none" ><?php echo $datatbl->id; ?></td>
										<td><?php echo $bil; ?></td>
										<td><a title="Edit" class="btn btn-mini btn-link edit"><?php echo $datatbl->name; ?></a></td>
										<td><a href="<?php echo base_url().$datatbl->urls; ?>" target="_blank" title="Edit" class="btn btn-mini btn-link"><?php echo !empty($datatbl->parentPage)?$this->lang->line($datatbl->parentPage)." -> ".$this->lang->line($datatbl->pageName):$this->lang->line($datatbl->pageName); ?></td>
										<td><a href="<?php echo base_url(); ?>graph/disable/<?php echo $datatbl->thisID.'/'.$datatbl->active; ?>"><?php echo !$datatbl->active?'Activate':'Deactivate'; ?></a></td>
										<td class="tac">
											<a href="<?php echo base_url(); ?>graph/removeGraph/<?php echo $datatbl->thisID; ?>" class="btn-icon btn-mini btn-danger-form"><span class="i-trashcan"></span></a>
										</td>
									</tr>
									<?php endforeach; }?>
								</tbody>
							</table>                                         
						</div> <!--content np -->
					</div> <!--block -->					
				</div> <!--span12-->
			</div> <!--row fluid-->			
			
		</div> <!--content class-->
	</div> <!--wrap-->
</div> <!--content id-->

<div class="dialog" id="row_delete" style="display: none;" title="Are you sure to Delete?">
    <p><?php echo $this->lang->line('message1') ?></p>
</div>   
<div class="dialog" id="row_edit" style="display: none;" title="Are you sure to Edit ?">
    <p><?php echo $this->lang->line('message2') ?></p>
</div>


