<table id="serverList" class="aliases genericList">
	<tbody>
		<tr class="header">
			<td class="td1" style="vertical-align: middle; padding-bottom: 5px;">
				<b><?php echo $this->translate('Description'); ?></b>
			</td>
			<td class="td2" style="vertical-align: middle; padding-bottom: 5px;">
				<b><?php echo $this->translate('Type'); ?></b>
			</td>
			<td class="td3" style="vertical-align: middle; padding-bottom: 5px;">
				<b><?php echo $this->translate('Uri'); ?></b>
			</td>
			<td class="td4" style="vertical-align: middle; padding-bottom: 5px;">
				<b><?php echo $this->translate('Username'); ?></b>
			</td>
			<td class="td5" style="vertical-align: middle; padding-bottom: 5px;">
				<b><?php echo $this->translate('Action'); ?></b>
			</td>
		</tr>
		<?php if( count($this->accounts) == 0 ) :?>
		<tr class='divide' id="noservers">
			<td class='td1'>&nbsp;</td>
			<td class='td2'><?php echo $this->translate('No server accounts currently defined'); ?></td>
			<td class='td3'>&nbsp;</td>
			<td class='td4'>&nbsp;</td>
			<td class='td5'>&nbsp;</td>
		</tr>
		<?php endif ?>
		
		<?php foreach( $this->accounts as $externalAccount ) : ?>
		<tr class="divide" id="<?php echo $externalAccount['id']; ?>">
			<td class="td1">
				<?php echo $externalAccount['name']; ?>
			</td>
			<td class="td2">
				<?php echo $externalAccount['protocol']; ?>
			</td>
			<td class="td3">
				<?php echo $externalAccount['uri']; ?>
			</td>
			<td class="td4">
				<?php echo $externalAccount['username']; ?>
			</td>
			<td class="td5">
				<a class="externalAccountEdit" href="#" id="<?php echo $externalAccount['id']; ?>"><?php echo $this->translate('Edit'); ?></a>
				<a class="externalAccountDelete" href="#" id="<?php echo $externalAccount['id']; ?>"><?php echo $this->translate('Delete'); ?></a>
			</td>
			<input type="hidden" id="externalAccountID" value="<?php echo $externalAccount['id']; ?>" />
		</tr>
		<?php endforeach; ?>
	</tbody>
	<input type="hidden" id="total_servers" value="<?php echo count($this->accounts); ?>" />
</table>

<script>
function perform_abook_settings_binds()
{
	$(".externalAccountDelete", "#serverList").unbind("click");
	$(".externalAccountDelete", "#serverList").bind("click", function() 
	{
		var externalAccountId = $(this).parent().parent().children('#externalAccountID').attr('value');
		if(externalAccountId == '' || externalAccountId == "Unknown" || externalAccountId == undefined)
		{
			externalAccountId = $(this).attr('id');
		}	
		$.php('<?php echo $this->moduleBaseUrl ?>/settings/externalaccountdelete', {'serverId[]':(externalAccountId)});
	
	});	
	$(".externalAccountEdit", "#serverList").unbind("click");
	$(".externalAccountEdit", "#serverList").bind("click", function() 
	{                                                                           
		//var rowId = $(this).parent().parent().parent().children('tr').index( $(this).parent().parent() ); //ignore header row
		var externalAccountId = $(this).parent().parent().children('#externalAccountID').attr('value');
		if(externalAccountId == '' || externalAccountId == "Unknown" || externalAccountId == undefined)
		{
			externalAccountId = $(this).attr('id');
		}
		$.php('<?php echo $this->moduleBaseUrl ?>/settings/externalaccountedit', {'serverId[]':(externalAccountId)});	
	});	
}

$( function() 
{
	perform_abook_settings_binds();
}); 

</script>
