{if $ajax eq '0'}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$back_link}">{$lang.button.back}</a>
</div>
<div class="error_message"></div>
<div class="cr"></div>
<div class="red_header">{$lang.events.razdel_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.events}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a href="admin_events.php">{$lang.events.listform}</a>
    </li>
    <li>
        <a class="current">{$lang.events.event_types}</a>
    </li>
{*    <li>
        <a href="admin_events.php?sel=add">{$lang.events.add}</a>
    </li>*}
</ul>
{*/if*}
{*if $form.err}
{else}
{if $ajax eq '0'*}
		<div class="user_operation_line" style="height:4px;font-size:0px;">
{*			<div onclick="javascript: location.href='{$add_link}'" class="uol_item">
				<div class="uol_in_item">{$lang.events.add}</div>
			</div>
			<div onclick="add_cat_func();" class="uol_item">
				<div class="uol_in_item">{$lang.events.add_type}</div>
			</div>*}
		</div>
		<div class="cr"></div>
<br>
{*<table>
	<tr height="40">
		<td><a class="admin_button" href='{$back_link}'>{$lang.button.back}<span>&nbsp;</span></a></td>
		<td><a class="admin_button_major" href='{$add_link}'>{$lang.events.add_type}<span>&nbsp;</span></a></td>
	</tr>
</table>*}
{*/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="dest_div" style="margin-bottom: 25px;">
			<table width="100%">				
                <form method="POST" action="{$form.action}" name="eventform" id="eventform" enctype="multipart/form-data">
				<input type="hidden" name="sel" id="sel" value="">
				<input type="hidden" name="id_type" id="id_type" value="">
                {$form.hiddens}
				<tr bgcolor="#ffffff">
					<td align="right" class="main_header_text" width="1%" nowrap>{$lang.events.type}<font class=main_error_text>*</font>:&nbsp;</td>
					<td class="main_content_text" align="left" width="200px;"><input type="text" id="type_name" name="type_name" value="" size=30 style="width: 195"></td>
					<td width="99%">
						<a class="admin_button_major" onclick="Save('type_name', 'addtype', 'id_type');{*document.getElementById('eventform').sel.value='addtype';document.getElementById('eventform').submit();*}">{$lang.button.add}<span>&nbsp;</span></a>
					</td>
					</tr>
				</form>
			</table>
		</div>
		<div id="dest_div_ed" style="display:none;">
			<table width="100%">
                <form method="POST" action="{$form.action}" name="eventform" id="eventform" enctype="multipart/form-data">
				<input type="hidden" name="sel" id="sel" value="">
				<input type="hidden" name="id_type" id="id_type" value="">
                {$form.hiddens}
				<tr bgcolor="#ffffff">
					<td align="right" class="main_header_text" width="160px">{$lang.events.type}<font class=main_error_text>*</font>:&nbsp;</td>
					<td class="main_content_text" align="left"><input type="text" id="type_name_ed" name="type_name_ed" value="{$data.name}" size=30 style="width: 195"></td>
				</tr>
				<tr bgcolor="#ffffff"><td colspan="2">
				<table>
					<tr height="40">
					<td>
						<a class="admin_button_major" onclick="Save('type_name_ed', 'savetype', 'id_type');{*document.getElementById('eventform').sel.value='savetype';document.getElementById('eventform').submit()*}">{$lang.button.save}<span>&nbsp;</span></a>
						<a class="admin_button" style="float:right;" onclick="javascript:if(confirm('{$lang.events.confirm|escape:javascript}')){literal}{Save('type_name_ed', 'deltype', 'id_type');}{/literal}">{$lang.button.delete}<span>&nbsp;</span></a>
					</td>
					</tr>
				</table>
				</form>
			</table>
		</div>
{/if}
<div id="events_table_div">
<table border=0 cellspacing=0 cellpadding=0 width="100%">
	{*if $links}
	<tr bgcolor="#ffffff">
		<td height="20"  colspan=3 align="left"  class="main_content_text" >{$links}</td>
	</tr>
	{/if*}
	<tr class="table_header">
		<td  align="center" width="20">{$lang.events.number}</td>
		<td  align="left">{$lang.events.type}</td>
		<td  align="right" width="100">{$lang.button.action}</td>
	</tr>
	{if $types}
	{section name=spr loop=$types}
	<tr {if $smarty.section.spr.index is div by 2}class="odd"{else}class="even"{/if}>
		<td align="center">{$types[spr].number+$smarty.section.spr.index}</td>
		<td align="left">{*<a href="{$types[spr].editlink}">{$types[spr].name}</a>*}
                                    <div id="inform_div{$types[spr].id}" class="error_msg" style="display:none;float:right;"></div>
                                    <span id="link{$types[spr].id}">{$types[spr].name}</span>
									<input id="text_input{$types[spr].id}" type="text" value="{$types[spr].name}" style="display:none"/>
		</td>
		<td align="right">{*<a href="#" class="admin_button" onclick="javascript: if(confirm('{$lang.events.confirm|escape:javascript}')){literal}{{/literal}location.href='{$types[spr].deletelink}'{literal}}{/literal}">{$lang.button.delete}<span>&nbsp;</span></a>*}
{*							<div class="block_action fr" style="display: none;">
								<div class="action_del" style="display: block;cursor:pointer;">
									<img height="16" alt="" src="{$site_root}{$template_root}/images/photo_delete.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" onclick="javascript: if(confirm('{$lang.events.confirm|escape:javascript}')){literal}{{/literal}location.href='{$types[spr].deletelink}'{literal}}{/literal}">
								</div>
							</div>
							<div style="width:10px;float:right;" class="fl">&nbsp;</div>
							<div class="block_action fr" style="display: none;">
								<div class="action_edit" style="display: block;cursor:pointer;">				
									<img width="16" alt="" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.edit}');return false" src="{$site_root}{$template_root}/images/edit.png" onclick="Edit('{$types[spr].id}', '{$types[spr].name}');">
								</div>
							</div>		*}
                                    <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('{$lang.events.confirm|escape:javascript}')){literal}{{/literal}location.href='{$types[spr].deletelink}'{literal}}{/literal}" />&nbsp;&nbsp;
                                    </div>
		</td>
	</tr>
	{/section}
	{else}
	<tr height="40">
		<td class="main_error_text" align="left" colspan="3" bgcolor="#FFFFFF">{$lang.events.empty_types}</td>
	</tr>
	{/if}
	{*if $links
	<tr  class="table_header">
		<td height="20" colspan=4 align="left" >
		  {foreach item=item from=$links.pages}
		    <a class="page_link" href="{$item.link}" 
			{if $item.selected}style=" font-weight: bold; text-decoration: none;"{/if}>{$item.name}</a>
		  {/foreach}
		</td>
	</tr>
	{*/if*}
	<tr class="table_header">
                        <td colspan="9">
                            &nbsp;&nbsp;
                            {if $links}
                            {foreach item=item from=$links.pages}
                                &nbsp;<a onclick="PageList('event_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('events_table_div', '{$links.previous}');">< {$lang.content.previous} {$per_page}</a>
                            {/if}
                            {if $links.next}
                                <a onclick="PageList('events_table_div', '{$links.next}');">{$lang.content.next} {$per_page} ></a>
                            {/if}
                            </div>
                        </td>
                    </tr>
</table>
<script type="text/javascript">
{literal}
function PageList(id_div, par) {
        //ajaxLoadingImage(1, 'pays');
        $.post("admin_events.php", par, function(data){
            //ajaxLoadingImage(0, 'pays');
            $('#events_table_div').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=savetype&id_type='+id+'&type_name='+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 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>
{*/if*}
<script language="javascript" type="text/javascript">
{literal}
function add_cat_func(){
	$('#dest_div').css("display", "block");
	$('#dest_div_ed').css("display", "none");	
	$("input:hidden[name='sel']").val('addtype');
}
function Edit(id, name){
/*	$("#err"+id).html('');
	$("#"+id).hide();
	$("#edit_"+id).show();*/
	$("input:text[name='type_name_ed']").val(name);
	$("input:hidden[name='id_type']").val(id);
	$("input:hidden[name='sel']").val('savetype');
	$('#dest_div_ed').css("display", "block");	
	//$('#dest_div').css("display", "none");	
}
/*document.getElementById('eventform').sel.value='addtype';document.getElementById('eventform').submit()*/
function Save(name, par, id){
	var cat_name = document.getElementById(name).value;
	var cat_id = document.getElementById(id).value;
	$('#dest_div').css("display", "block");
	$('#dest_div_ed').css("display", "none");	
	if (cat_name!='')
	{	
		//$('#dest_div').css("display", "none");
		ajaxLoadingImage(1, 'events_table_div');
		$.post("admin_events.php", {type_name:cat_name, sel:par, id_type:cat_id, ajax:'1'}, function(data){
			ajaxLoadingImage(0, 'events_table_div');
			$('#events_table_div').html(data);
		});
	}else{
        $(".error_message").html("{/literal}{$lang.err.invalid_feilds}{literal}");
        $(".error_message").fadeIn(500);
        setTimeout('$(".error_message").fadeOut(500);', 5000);  
	}
	$('#'+name).val('');
}
{/literal}
</script>
{if $ajax eq '0'}
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}