{if $ajax eq 0}{include file="$admingentemplates/admin_top.tpl"}{/if}
<script>
{literal}
var tab_last = '1';
{/literal}
</script>
{if $ajax eq 0}
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$info.name}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
{if $info.help != ''}
    <div class="help_text" style="display:block;">
        <div class="close_help">
            <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
        </div>
        <div class="help_body">
            <span class="help_title">{$lang.help}:</span>{$info.help}
        </div>
    </div>
{/if}
<ul class="tabs">
    <li>
        <a {if $info.active == "reports"} class="current" {else} href="admin_abuse_reports.php"  {/if}>{$lang.admin_abuse_reports.razdel_name} ({$count.new_abuse}/{$count.all_abuse})</a>
    </li>
    <li>
        <a {if $info.active == "bad_words"} class="current" {else} href="admin_badwords.php" {/if}>{$lang.admin_menu.bad_words} ({$count.badwords})</a>
    </li>
    <li>
        <a {if $info.active == "ip_check"} class="current" {else} href="admin_block_ip.php" {/if}>{$lang.admin_menu.block_ip} ({$count.ip})</a>
    </li>
    <li>
        <a {if $info.active == "approve"} class="current" {else} href="admin_upload.php" {/if}>{$lang.admin_menu.uploads_approve} ({$count.approve})</a>
    </li>
</ul>
<div id="show_block" style="display:table;width:100%;">{/if}
<div class="user_operation_line" style="height:4px;font-size:0px;">       

</div>
<div class="cr"></div>

<div onclick="ShowEditor('1','admin_block_ip.php?sel=addform&ajax=1');" id="tab_1" class="user_status_elem_active" style="width: 120px" align="center">
    {$lang.admin_menu.new_ban} 
</div>
<div onclick="ShowEditor('2','admin_block_ip.php?ajax=1');" id="tab_2"  class="user_status_elem" style="width:120px;" align="center">
    <a>{$lang.admin_menu.banned_ip} ({$ip_count})</a>
</div>
    
<!--div class="user_status_elem_active" style="width: 120px" align="center">
    {$lang.admin_menu.new_ban} 
</div>
<div class="user_status_elem" style="width:120px;" align="center">
    <a href="admin_block_ip.php" >{$lang.admin_menu.banned_ip} ({$ip_count})</a>
</div-->

	<div class="panel_subtabs" style="width: 100%">
		<div class="panel_content" style="width: 97%">
	<div id="add_ip" style="float: left; width: 100%;">
		<form action="{$action}" name="block_ip" method="POST">
		<input type="hidden" name="sel" value="add">
		<input type="hidden" name="id_ip" id="id_ip" value="">
		<input type="hidden" name="ip_type" id="ip_type" value="">
		<table cellpadding="2" cellspacing="1" border="0">
			<tr>
				<td width="30%">
					<input type="radio" id="type_a" name="type" value="address" {if $error_ip && $ip_type == 'address'} checked {/if} onclick="javascript: ChangeIpType('address');">
					<font class="text" style="margin-bottom:20px;">{$lang.admin_block_ip.ip_address}</font>
				</td>
				<td width="30%">
					<input type="radio" id="type_r" name="type" value="range" {if $error_ip && $ip_type == 'range'} checked {/if} onclick="javascript: ChangeIpType('range');">
					<font class="text">{$lang.admin_block_ip.ip_range}</font>
				</td>
				<td width="30%">
					<input type="radio" id="type_c" name="type" value="country" {if $error_ip && $ip_type == 'country'} checked {/if} onclick="javascript: ChangeIpType('country');">
					<font class="text">{$lang.admin_block_ip.ip_country}</font>
				</td>
			</tr>
			<tr>
				<td>
					{$lang.admin_block_ip.ip_address}
				</td>
				<td colspan="3">
					<input type="text" id="ip_address" name="ip_address" disabled="true" size="20" {if $error_ip.ip_start} value="{$error_ip.ip_start}" {/if} >
				</td>
			</tr>
			<tr>
				<td>
					{$lang.admin_block_ip.ip_range}
				</td>
				<td colspan="3">
					<input type="text" id="range_start" name="range_start" disabled="true" size="20" {if $error_ip.ip_end} value="{$error_ip.ip_start}" {/if} />&nbsp;-&nbsp;<input type="text" id="range_end" name="range_end" disabled="true" size="20" {if $error_ip.ip_end} value="{$error_ip.ip_end}" {/if} />
				</td>
			</tr>
			<tr>
				<td>
					{$lang.admin_block_ip.ip_country}
				</td>
				<td colspan="3">
					<select id="ip_country" name="ip_country" disabled="true">
						<option value="" id="null">{$lang.admin_block_ip.block_ip.please_select}</option>
						{section name=i loop=$country}
							<option value="{$country[i].name}" id="{$country[i].index}">{$country[i].name}</option>
						{/section}
					</select>
				</td>
			</tr>
		</table>
		</form>
	</div>
</div>
</div><a class="admin_button_major" onclick="javascript: Save();" >{$lang.button.save}<span>&nbsp;</span></a>					
    
<script type="text/javascript">
{if $error_ip}
ChangeIpType('{$ip_type}');
{/if}
{literal}
function ChangeIpType(par) {
	if (par == 'address') {
		$('#ip_address').removeAttr('disabled');
		$('#range_start').attr('disabled', 'disabled');
		$('#range_end').attr('disabled', 'disabled');
		$('#ip_country').attr('disabled', 'disabled');
		$('#range_start').val('');
		$('#range_end').val('');
		
	}
	if (par == 'range') {
		$('#ip_address').attr('disabled', 'disabled');
		$('#range_start').removeAttr('disabled');
		$('#range_end').removeAttr('disabled');
		$('#ip_country').attr('disabled', 'disabled');
		$('#ip_address').val('');
	}
	if (par == 'country') {
		$('#ip_address').attr('disabled', 'disabled');
		$('#range_start').attr('disabled', 'disabled');
		$('#range_end').attr('disabled', 'disabled');
		$('#ip_country').removeAttr('disabled');
		$('#ip_address').val('');
		$('#range_start').val('');
		$('#range_end').val('');
	}
	$('#ip_type').val(par);
}
function Save() {
	var re = /^([1-9][0-9]{0,2})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ip_address = $('#ip_address').val();
	var range_start = $('#range_start').val();
	var range_end = $('#range_end').val();
	var ip_country = $('#ip_country').val();
	var type_c = $('#type_c').val(); 
	var type_r = $('#type_r').val();
	var type_a = $('#type_a').val();
	var ip_type = $('#ip_type').val();
	var err = 0;
	if (
		(ip_type == 'address' && ip_address == '') ||
		(ip_type == 'range' && range_start == '' && range_end == '') ||
		(ip_type == 'country' && ip_country == '') || 
		(ip_type == '')
		) { 
		err = 1;
	}
	if (err == 0) { 
		if (ip_address != '' && !document.getElementById('ip_address').value.match(re)) {
			err = 1;
		}
		if (range_start != '' && !document.getElementById('range_start').value.match(re)) {
			err = 1;
		}
		if (range_end != '' && !document.getElementById('range_end').value.match(re)) {
			err = 1;
		}
		if (err == 1) {
			//document.getElementById('err').style.display = 'block';
			//document.getElementById('err').innerHTML = '<font class="error_msg">*&nbsp;{/literal}{$lang.err.block_ip.incorrect}{literal}</font>';
		}
	}
	if (err == 0) {
		document.block_ip.submit();
	}
	
}


{/literal}
</script>
{if $ajax eq 0}{include file="$admingentemplates/admin_bottom.tpl"}{/if}