{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$back_link}">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.country.list_region}{$country_name}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<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>{$lang.admin_help.ref_regions}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a {if $active eq "maps"} class="current" {else} href="admin_settings.php?section=22" {/if}>maps</a>
    </li>
    <li>
        <a {if $active eq "distance"} class="current" {else} href="admin_distance.php" {/if}>distans</a>
    </li>
    <li>
        <a {if $active eq "country"} class="current" {else} href="admin_countries.php" {/if}>countries</a>
    </li>
    </ul>
    <div class="cr"></div>
<div class="user_operation_line">
    <div class="uol_item">
        <div class="uol_in_item" onclick="javascript: if(confirm('{$form.confirm|escape:javascript}')){literal}{{/literal}Delete();{literal}}{/literal}">{$lang.button.delete}</div>
    </div>
</div>
<div class="cr"></div>
<div style="float: left; width: 100%; margin-top: 10px; margin-bottom: 20px;">
					<table  cellSpacing="3" cellPadding="0" >
						<form method="post" action="{$form.action}"  enctype="multipart/form-data" name=add_form>
						{$form.hiddens}
							<tr>
								<td align="right" class="main_header_text">
								&nbsp;{$lang.country.region}:&nbsp;
								</td>
								<td class="main_content_text" align="left"><input type="text" name="name" value="{$name}" size=30></td>
								<td class="main_content_text" align="left"><a class="admin_button_major" onclick="javascript: document.add_form.submit();">{$lang.button.save}<span>&nbsp;</span></a></td>
							</tr>
							</form>
					</table>
</div>
    	<!-- /form -->

<div id="country_list" {if $sec eq 1} class="user_status_elem_active" {else}class="user_status_elem" onclick="document.location.href='admin_countries.php?section=1'"{/if} width="80px">
    {if $sec eq 1}{$lang.admin.country.list}{else}<a>{$lang.admin.country.list}</a>{/if}
</div>
<div id="country_first" {if $sec eq 2} class="user_status_elem_active" {else}class="user_status_elem" onclick="document.location.href='admin_countries.php?section=2'"{/if} width="80px">
    {if $sec eq 2}{$lang.admin.country.first_list}{else}<a>{$lang.admin.country.first_list}</a>{/if}
</div>
<div id="country_install" {if $sec eq 3} class="user_status_elem_active" {else}class="user_status_elem" onclick="document.location.href='admin_countries.php?section=3&sel=install'"{/if} width="80px">
    {if $sec eq 3}{$lang.install_spr.install_country}{else}<a>{$lang.install_spr.install_country}</a>{/if}
</div>
{/if}
<div id="tooltip" onclick="hideToolTip()" style="text-align:center; background-color: #FFFFFF; border: 1px dotted; text-align: {$default_left}; position:absolute; display:none; padding:5px;"></div>
{literal}
<script type="text/javascript">
$(function() {
$('#tool_tip_4 *').tooltip();
});
</script>
{/literal}
    <div id="list_regions" style="float: left; width: 100%;">
				<table border=0 cellspacing=0 cellpadding=0 width="50%">
				            <tr class="table_header">
								<td align="center" width="5%"><input type="checkbox" name="select_all" onclick="PutAll()" /></td>
								<td align="left" width="80%">{$lang.country.region}</td>
								<td align="center" width="15%">{$lang.users.actions}</td>
							</tr>
							{if $regions}
							{section name=spr loop=$regions}
							<tr {if $smarty.section.spr.index mod 2 eq 1}class="even"{else}class="odd"{/if}>
								<td align="center"><input type="checkbox" name="delete" id="delete" value="{$regions[spr].id}" /></td>
								<td align="left" style="padding-left: 10px;">									
									<div style="float: left;"><a id="link{$regions[spr].id}" href="{$regions[spr].editlink}">{$regions[spr].name}</a></div>
									<div style="float: left;"><input id="text_input{$regions[spr].id}" type="text" value="{$regions[spr].name}" style="display:none"/></div>
                                    <div id="inform_div{$regions[spr].id}" class="error_msg" style="display:none"></div>
								</td>
								<td align="center">
                                    <div class="block_action">
                                        <img id="edit_button{$regions[spr].id}" src="{$site_root}{$template_root}/images/edit.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.edit}');return false" alt="" height="13" style="cursor: pointer; margin-left: 10px;" onclick="javascript: editAction({$regions[spr].id});" />
                                        <img id="save_button{$regions[spr].id}" src="{$site_root}{$template_root}/images/success.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.save}');return false" alt="" height="13" style="cursor: pointer; display:none; margin-left: 10px;" onclick="javascript: saveAction({$regions[spr].id});" />
                                        <img src="{$site_root}{$template_root}/images/photo_delete.png" alt="" height="13" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" style="cursor: pointer; margin-left: 10px;" onclick="javascript: if(confirm('{$form.confirm|escape:javascript}')){literal}{{/literal}location.href='{$regions[spr].deletelink}'{literal}}{/literal}" />
									</div>
								</td>
							</tr>
							{/section}
							{else}
							<tr height="40">
								<td class="main_error_text" align="left" colspan="4" bgcolor="#FFFFFF">{$lang.country.empty_region}</td>
							</tr>
							{/if}
                            <tr class="table_header">
		                        <td colspan="11">
		                            &nbsp;&nbsp;
		                            {if $links}
		                            {foreach item=item from=$links.pages}
		                                &nbsp;<a onclick="PageList('users_table_div', '{$item.link}');" class="page_link" {if $item.selected} style=" font-weight: bold; text-decoration: none;" {/if}>{$item.name}</a>&nbsp;
		                            {/foreach}
		                            {/if}
		                            <div class="page_navigation">
		                            {if $links.previous}
		                                <a onclick="PageList('users_table_div', '{$links.previous}');">< {$lang.content.previous} {$per_page}</a>
		                            {/if}
		                            {if $links.next}
		                                <a onclick="PageList('users_table_div', '{$links.next}');">{$lang.content.next} {$per_page} ></a>
		                            {/if}
		                            </div>
		                        </td>
		                    </tr>
					</table>
</div>
<script type="text/javascript">
{literal}
		function showToolTip(e,text){
			if(document.all)e = event;
			var obj = document.getElementById('tooltip');
			obj.innerHTML = text;
			obj.style.display = 'block';
			var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
			if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;
			var leftPos = e.clientX - $('#tooltip').width()-10;
			if(leftPos<0)leftPos = 0;
			obj.style.left = leftPos + 'px';
			obj.style.top = e.clientY - obj.offsetHeight -10 + st + 'px';
		}
		function hideToolTip(){
			document.getElementById('tooltip').style.display = 'none';
		}
{/literal}		
</script>
<script type="text/javascript">
{literal}
function PutAll() {
         var o=document.getElementsByName('select_all')	
         var i
         if (o[0].checked){                    
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                o[i].checked = true
            }            
         }
         else{
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                o[i].checked = false
            }            
         }             
}

function Delete(){
    var mas=[]
    var i=0
    $('input[name=delete]:checked').each(function(){
        mas[i] = $(this).val()   
        i++    
    })
    var par = "ajax=1&id="+mas+"&sel=delr&id_country={/literal}{$id_country}{literal}";
        $.post("{/literal}{$form.action}{literal}", par, function(data){
            $("#list_regions").html(data);
        })  
}

    function PageList(id_div, par) {
        ajaxLoadingImage(1, 'list_regions');
        $.post("admin_countries.php", par, function(data){
            ajaxLoadingImage(0, 'list_regions');
            $('#list_regions').html(data);
        });
    }

function editAction(id){
	link_obj = getById('link'+id);
	text_input_obj = getById('text_input'+id);
	edit_button_ogj = getById('edit_button'+id);
	save_button_ogj = getById('save_button'+id);
	
	link_obj.style.display = 'none';
	text_input_obj.style.display = '';
	edit_button_ogj.style.display = 'none';
	save_button_ogj.style.display = '';
	
	text_input_obj.focus();
}

function saveAction(id){
	inform_div_obj = getById('inform_div'+id);
	link_obj = getById('link'+id);
	text_input_obj = getById('text_input'+id);
	edit_button_ogj = getById('edit_button'+id);
	save_button_ogj = getById('save_button'+id);
	value = text_input_obj.value;
	
	file_name = '{/literal}{$form.action}{literal}';
	str = 'sel=rename_region&id='+id+'&value='+value;
	destination_odj = inform_div_obj;
	tmp_text = 'Saving...';
	anisochronous = false;
	ShowAjaxError(tmp_text, '', 'info');
	
	ajaxRequest(file_name, str, destination_odj, tmp_text, anisochronous);
	
	CloseAjaxError(1);
	inform_div_obj.style.display = '';
	
	saved_obj = getById('saved'+id);
	saved = saved_obj.value;
	
	if (saved == '1'){
		link_obj.style.display = '';
		link_obj.innerHTML = value;
		text_input_obj.style.display = 'none';
		edit_button_ogj.style.display = '';
		save_button_ogj.style.display = 'none';
		edit_button_ogj.focus();
	}
}

function getById(name){
	return document.getElementById(name);
}
{/literal}
</script>
{if $ajax eq 0}
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}