{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_settings.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.distance.list}</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_distances}
    </div>
</div>

<ul class="tabs">
    <li>
        <a {if $active eq "maps"} class="current" {else} href="admin_settings.php?section=22" {/if}>{$lang.settings.map_tab}</a>
    </li>
    <li>
        <a {if $active eq "distance"} class="current" {else} href="admin_distance.php" {/if}>{$lang.settings.distanse_tab}</a>
    </li>
    <li>
        <a {if $active eq "country"} class="current" {else} href="admin_countries.php" {/if}>{$lang.settings.counries_tab}</a>
    </li>
    </ul>
    <div class="cr"></div>
<div class="user_operation_line">
    <div class="uol_item">
        <div class="uol_in_item" onclick="Delete();">{$lang.button.delete}</div>
    </div>
</div>
<div class="cr"></div>

<div style="float: left; width: 100%; {if !$err}display: none;{/if}" id="err">
    {$err}
</div>
<form method="post" action="{$form.action}"  enctype="multipart/form-data" name="types_form">
    <div style="margin: 10px; float: left; width: 100%;">
        <div style="float: left; width: 70px;">
            Use:
        </div> 
        <div style="float: left; width: 70px;">
            <input type="radio" name="type" checked="" value="mile"/>{$lang.distance.mile}
        </div>
        <div style="float: left; width: 120px;">
            <input type="radio" name="type" value="km"/>{$lang.distance.km}
        </div>
    </div>

    <div style="margin: 10px; float: left; width: 100%;">
    {$form.hiddens}
        <div style="float: left; width: 70px;">{$lang.taketour.add}:</div>
        <div style="float: left; "><input type="text" id="name" name="name" value="{$data.name}" size=30 /></div>
        <div style="float: left; margin-left: 10px; margin-top: -10px;"><a class="admin_button_major" onclick="javascript:document.types_form.submit();">{$lang.button.add}<span>&nbsp;</span></a></div>
   </div>
</form>
{/if}
<div id="distance" style="float: left; width: 100%;">
<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}
			<table border=0 cellspacing=0 cellpadding=0 width="100%">
						<tr class="table_header">
							<td align="center" width="5%"><input type="checkbox" name="select_all" onclick="PutAll()" /></td>
							<td align="left" width="50%">{$lang.distance.name}</td>
                            <td align="right" width="45%">{$lang.users.actions}</td>
						</tr>
						{if $types}
						{section name=spr loop=$types}
							<tr {if $smarty.section.spr.index mod 2 eq 1}class="even"{else}class="odd"{/if}>
								<td align="center" width="20"><input type="checkbox" name="delete" id="delete" value="{$types[spr].id}" /></td>
								<td align="left" style="padding-left: 10px;">
                                    <div id="inform_div{$types[spr].id}" class="error_msg" style="display:none;float:right;"></div>
                                    <a id="link{$types[spr].id}" href="{$types[spr].editlink}">{$types[spr].name} {$types[spr].type}</a>
									<input id="text_input{$types[spr].id}" type="text" value="{$types[spr].name} {$types[spr].type}" style="display:none"/>
                                        
                                </td>
	                            <td align="right">
                                    <div class="block_action" >  
                                        <img id="edit_button{$types[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;" onclick="javascript: editAction({$types[spr].id});" />&nbsp;
                                        <img id="save_button{$types[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;" onclick="javascript: saveAction({$types[spr].id});" />&nbsp;
                                        <img src="{$site_root}{$template_root}/images/photo_delete.png" alt="" height="13" style="cursor: pointer;" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" onclick="javascript: if(confirm('{$form.confirm|escape:javascript}')){literal}{{/literal}location.href='{$types[spr].delete}'{literal}}{/literal}" />&nbsp;&nbsp;
                                    </div>
                                </td>   
                            </tr>
						{/section}
						{else}
							<tr height="40">
								<td class="main_error_text" align="left" colspan="2" bgcolor="#FFFFFF">{$lang.distance.empty}</td>
							</tr>
						{/if}
						<tr class="table_header"><td colspan="3">&nbsp;</td></tr>
					</table>
<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>
</div>
<script type="text/javascript">
{literal}
function AddNew(){
    var name = $("#name").val();
    if (name != ""){
        var par = "ajax=1&name="+name+"&sel=add&e=1";
        $.post("admin_distance.php", par, function(data){
            $("#distance").html(data);
        })   
    }        
    else
        alert("error")
}

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 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=change&id='+id+'&value='+value+'&e=1';
	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 Delete(){
    var mas=[]
    var i=0
    $('input[name=delete]:checked').each(function(){
        mas[i] = $(this).val()   
        i++    
    })
    var par = "ajax=1&id="+mas+"&sel=del";
        $.post("admin_distance.php", par, function(data){
            $("#distance").html(data);
        })  
}
{/literal}
</script>	
{if $ajax eq 0}		
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}