<div id="primary_header">
  <h1><?php print $this->translate('Mail Relay')?></h1>
</div>

<div id="primary_content">
  <div id="primary_content_inner">
  <div id="Flash" class="flash_notice"><?php print $this->translate('The settings have been updated') ?></div>
	
  <form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/services/mailrelaysave">

    <input type="hidden" name="save" value="1" />
	<!-- Specify default settings not available to edit -->

	
	<table class="settings">
		<tr>
			<td class="label"><?php print $this->translate('Filter by IP:')?></td>
			<td class="filterinput">
				<input type="text" name="mailrelayFilter" id="mailrelayFilter" class='panelFilter' value=""/> 
				<small><?php print $this->translate('Specify an IP or netblock to filter results')?></small>
			</td>
			<td class="filterdomain">
				&nbsp;
			</td>
		</tr>               
	</table>
	

	<div id="relay-table">	
	</div>

	<table style="margin-top: 5px;" id="" class="settings">

		<tbody><tr>

			<td>
    <div class="mail_row_paginator_aliases">

		<div id="back_button_delete_selected" class="filterdomain">
			<a href="#">
				<span class="stronglastword"><?php echo $this->translate('Delete Selected') ?></span>
			</a>
		</div>

	</div>
	</td>
	</tr>
	</tbody>
	</table>

		<div class="divider"/>
		
	<table class="settings">
      
      <tr>
		<td class="label"><?php print $this->translate('IP Address or Net-block')?></td>
        <td>
            <input type="text" class="large" name='IPaddress' id='IPaddress' />
<small><?php print $this->translate('Enter an IP address or Netblock in CIDR notation to allow SMTP relay of email messages')?></small>
		</td>
      </tr>

      <tr>
		<td class="label"><?php print $this->translate('Type')?></td>
        <td class="tdstyle">
			<div class="styled-select">
			        <span class="arrow"></span>
            <select name='Account'>
				<option value="System"><?php echo $this->translate('Permanent ( System )') ?></option>
				<option value="User"><?php echo $this->translate('Expire after 60 mins ( User )') ?></option>
			</select>
			</div>
			
			<small><?php print $this->translate('Choose if the relay is permanent, or expire after 60 minutes')?></small>
			
		</td>
      </tr>
	</table>
	
	<table class='settings' id='' style="margin-top: 5px;">
	
	<tr>
		<td class="label"></td>
		<td>
			<div id="back_button_add_alias" class="filterdomain">
				<a href="">
			<span class="stronglastword"><?php echo $this->translate('Add IP') ?></span>
		</a>
	</div>
	
	</tr>
		
	</table>
	

  </div>
  </form>
</div>

<script type="text/javascript">
$( function()
{
	var tabId = "#Mail_Relay";
	perform_service_common_binds(tabId);

	// Load the email-alias list
	$.php('<?php echo $this->moduleBaseUrl ?>/services/mailrelaylist');

	$('#back_button_add_alias a', tabId).bind("click", function()
	{

		$(tabId + " #Flash").hide();
		$('#settingsForm', tabId).submit()
		return false

	});        

	// Filter results
	$('#back_button_filter a', tabId).bind("click", function()
	{

		$(tabId + " #Flash").hide();
		$.php('<?php echo $this->moduleBaseUrl ?>/services/mailrelaylist/filter/' + $("#mailrelayFilter", tabId).val() );
		return false

	}); 

	var search_timeout = 0;
	$('#mailrelayFilter', tabId).bind('keyup', function()
	{

		if ( search_timeout != undefined ) 
		{

			clearTimeout(search_timeout);

		}

		var thecall = this; // save reference to 'this' so we can use it in timeout function
		search_timeout = setTimeout( function() 
									{

										search_timeout = undefined;
										$.php('<?php echo $this->moduleBaseUrl ?>/services/mailrelaylist/filter/' + $("#mailrelayFilter", tabId).val() );

									}, 300);

	});

	// Delete multiple entries
	$("#back_button_delete_selected", tabId).bind("click", function() {

        $id = $("#checkEntry", tabId).serializeArray();
        for($i = 0; $i < $id.length; $i++) {
            $idVal = $id[$i].value;
            $idStr = "#checkEntry[value=".concat($idVal);
            $idStr = $idStr.concat("]");
            $($idStr, ".relayRow").parent().parent().fadeOut();
            $.php('<?php echo $this->moduleBaseUrl ?>/services/mailrelaydelete/', {'id' : $idVal});
        }

	});     
});
</script>