{include file="$admingentemplates/admin_top.tpl"}
<link href="{$site_root}{$template_root}/css/alert.css" rel="stylesheet" type="text/css">
<div id="boxes">
    <div id="close" class="close" onclick="Close()"></div>
	<div id="dialog" class="window">
	</div>
</div>
<div id="mask"></div>
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_modules.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.admin_games.razdel_name}</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>{$help.admin_games_categories}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs">
    <li>
        <a class="current">{$lang.admin_market.sales_games}</a>
    </li>
    <li>
        <a {if $sel eq 'orders'}class="current"{else}href="admin_games.php?sel=orders"{/if}>{$lang.admin_games.orders_list}</a>
    </li>
	<li>
        <a {if $sel eq 'settings'}class="current"{else}href="admin_games.php?sel=settings"{/if}>{$lang.admin_menu.aff_settings}</a>
    </li>
</ul>
<div class="user_operation_line">
	<div onclick="javascript: document.location.href='{$file_name}?sel=edit_game'" class="uol_item">
		<div class="uol_in_item">{$lang.admin_games.games_add}</div>
	</div>
</div><br><br><br><br>
<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="games_category_table_div">
	<div style="float:left; width:55%;">
		<div style="padding-top: 0px;">
		<form action="{$file_name}" method="POST" name="form1">
		<input type="hidden" name="sel" value="add_category">
			<div style=" margin-top:7px; vertical-align: top;">
				<span style=" vertical-align: top;">
					{$lang.admin_games.add_category}:&nbsp;&nbsp;&nbsp;
					<input type="text" name="name" size="30">
				</span>
				&nbsp;&nbsp;&nbsp;
				<a class="admin_button_major" style="margin-top: -6px;" onclick="document.form1.submit();">{$lang.admin_games.games_category_add}<span>&nbsp;</span></a>
			</div>
		</form>
		</div>
{*	<div style="height:30px;">		
		<a class="admin_button" style="margin-top: 0;" onclick="javascript: document.location.href='{$file_name}?sel=edit_game'">{$lang.admin_games.games_add}<span>&nbsp;</span></a>
	</div>*}
	</div>
	<div style="padding-top:0px; width:45%; float:right;">
		<div>
		<form action="{$file_name}" method="POST" name="form2">
		<input type="hidden" name="sel" value="search_games">
			<div style=" margin-top:7px; vertical-align: top; float: right;">
				<span style=" vertical-align: top;">
					{$lang.admin_games.games_search}:&nbsp;&nbsp;&nbsp;
					<input type="text" name="name" size="20">
				</span>
				&nbsp;&nbsp;&nbsp;
				<a class="admin_button" style="margin-top: -6px;" onclick="document.form2.submit();">{$lang.admin_games.games_search_go}<span>&nbsp;</span></a>
			</div>
		</form>
	</div>
	</div>
	<div class="cr">&nbsp;</div>
	<div style="padding-top: 0px;">
	<table border=0 cellspacing=0 cellpadding=0 width="100%">
		<tr bgcolor="#ffffff">
			<td colspan=4 class="main_content_text">
				{if $links}
				<div style="margin-{$default_left}: 0px; padding-top: 15px;">
				{foreach item=item from=$links}
					<span style="padding-{$default_right}: 15px;"><a href="{$item.link}" {if $item.selected eq '1'} class="text_head"{/if}>{$item.name}</a></span>
				{/foreach}
				</div>
				{/if}
			</td>
		</tr>
		<tr class="table_header">
			<td class="main_header_text" align="left" width="40%">{$lang.admin_games.categories}</td>
			<td class="main_header_text" align="left" width="20%">{$lang.admin_games.games_count}</td>
			<td class="main_header_text" align="right" width="40%">{$lang.admin_games.actions}</td>
		</tr>
		{foreach item=item from=$games_category name=i}
		<tr {if $smarty.foreach.i.iteration mod 2 eq 1}class="table_row even"{else}class="table_row odd"{/if} style="height:32px;">
			<td class="main_content_text" align="left">
				<div id="{$item.id_category}"><a href="{$file_name}?sel=games_list&id_category={$item.id_category}">{$item.name}</a></div>
				<div style="display:none;" id="edit_{$item.id_category}">
					<div id="err{$item.id_category}" style="display:none;">
					</div>
					<div>
					<input type="text" name="name" id="edit_name_{$item.id_category}" value="{$item.name}" size="25">&nbsp;&nbsp;&nbsp;
{*					<input type="button" name="save" value="{$lang.button.save}" onclick="Save('{$item.id_category}');">*}
{*					<div class="block_action fr" style="display: none;">
						<div class="action_del" style="display: block;">				
							<img width="16" alt="" src="{$site_root}{$template_root}/images/success.png" onclick="Save('{$item.id_category}');">
						</div>
					</div>*}
{*					<a class="admin_button_major" name="save" onclick="Save('{$item.id_category}');">{$lang.button.save}<span>&nbsp;</span></a>*}
					</div>
				</div>
			</td>
			<td class="main_content_text" align="left">
				{$item.count_games}
			</td>
			<td class="main_content_text" align="right">
					<div class="block_action" >
						<img id="edit_button{$item.id_category}" 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="Edit('{$item.id_category}');" />&nbsp;
						<img id="save_button{$item.id_category}" 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="Save('{$item.id_category}');" />&nbsp;
						<img onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" alt="" height="13" style="cursor: pointer;" src="{$site_root}{$template_root}/images/photo_delete.png" onclick="Delete('{$item.id_category}')">&nbsp;
					</div>
{*					<div class="block_action fr" style="display: none;">
						<div class="action_del" style="display: block;">				
							<img width="16" alt="" src="{$site_root}{$template_root}/images/photo_delete.png" onclick="Delete('{$item.id_category}')'">
						</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;">
							<img width="16" alt="" src="{$site_root}{$template_root}/images/edit.png" onclick="Edit('{$item.id_category}');">
						</div>
					</div>*}
			</td>
		</tr>
		{/foreach}
	<tr class="table_header">
		<td colspan="4">	
			&nbsp;&nbsp;
			{if $links}
			{foreach item=item from=$links.pages}
				&nbsp;<a onclick="PageList('games_category_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('games_category_table_div', '{$links.previous}');">< {$lang.content.previous} {$per_page}</a>
			{/if}
			{if $links.next}
				<a onclick="PageList('games_category_table_div', '{$links.next}');">{$lang.content.next} {$per_page} ></a>
			{/if}
			</div>	
		</td>
	</tr>
	</table>
	</div>
</div>
<script language="JavaScript" type="text/javascript">
{literal}
function Close(){
    $('#mask').fadeOut(500);
    $('#close').fadeOut(500)
    $('#dialog').fadeOut(500)	
}
		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';
		}
function Edit(id) {
	$("#err"+id).html('');
	$("#"+id).hide();
	$("#edit_button"+id).hide();
	$("#edit_"+id).show();
	$("#save_button"+id).show();
}
function Save(id) {
	if ($("#edit_name_"+id).val() == '') {
	} else {
		ajaxLoadingImage(1, 'err'+id);
		$("#err"+id).show(100);
		name = $("#edit_name_"+id).val();
		$.post("{/literal}{$file_name}{literal}",{sel:'add_category', id_category:id,name:name}, 
			function(data){
				if (data == '1') {
					ShowAjaxError("{/literal}{$lang.admin_games.category_edit_err_exist}{literal}", '', 'error');
					//error_display("{/literal}{$lang.admin_games.category_edit_err_exist}{literal}");
				} else {
					ShowAjaxError(data, '', 'success');
					//error_display(data);
					$("#"+id+" a").text(name);
					$("#edit_"+id).delay(4000).hide(100);
					$("#"+id).delay(4000).show(10);
				}
				ajaxLoadingImage(0, 'err'+id);							
			}
		);
		$("#save_button"+id).hide();
		$("#edit_button"+id).show();
	}
}
function error_display(text){
	var parent = document.getElementById('right_panel');
	var newDiv = document.createElement('div');
	newDiv.id = 'error_message';
	newDiv.style.border = '1px solid #D82B2B';
	newDiv.style.background = 'none repeat scroll 0 0 #FFFFAA';
	newDiv.style.color = '#000';
	newDiv.style.fontSize = '13px';
	newDiv.style.fontWeight = 'bold';
	newDiv.style.padding = '20px';
	newDiv.style.position = 'fixed';
	newDiv.style.top = '2px';
	newDiv.style.left = '600px';
	var text_dis = text;
	var textNode = document.createTextNode(text_dis);
	newDiv.appendChild(textNode);
	parent.appendChild(newDiv);
	setTimeout("document.getElementById('error_message').style.display = 'none';", 5000);  
}
function SavePaid() {
	var paid_value;
	var price = 0;
	var period_day = 0;
	if ($('#use_paid_service').is(':checked')) {
			paid_value = 1;
			price = $('#price').val();
			period_day = $('#period_day').val();
	} else {
			paid_value = 0;
	}
	ajaxLoadingImage(1, 'info');
	$('#info').show();
	$.post('admin_games.php',{sel:'use_paid',value:paid_value,price:price,period_day:period_day,ajax:'1'},
		function(data){
			ajaxLoadingImage(0, 'info'),
			ShowAjaxError(data, '');
			//$('#info').html('<font class="error_msg">'+data+'</font>').fadeIn(500).delay(2000).fadeOut(500)
		}
	);
}
$(document).ready(function() {	
	//if close button is clicked
	$('.window .close').live("click",function (e) {
		//Cancel the link behavior
		$('#mask, .window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	$('#use_paid_service').click(function(){
		var paid_value;
		if ($('#use_paid_service').is(':checked')) {
			paid_value = 1;
			$('#period').show();
		} else {
			paid_value = 0;
			$('#period').hide();
		}
		}
	);
});
//select all the a tag with name equal to modal
function Delete(id) {
		str_html = "<div align=\"right\"><a href=\"#\"class=\"close\" ><img border=\"0\" src=\"{/literal}{$site_root}{$admin_theme_path}{literal}/images/window-close.png\"></a></div>";
		str_html = str_html+"<div id=\"answ\" style=\"padding:20px;\">";
		str_html = str_html+"<div align=\"left\">{/literal}{$lang.admin_games.category_delete}{literal}</div>";
		str_html = str_html+"<div style=\"padding-top:40px;\"><div align=\"center\" style=\"width:100%;\"><a class=\"admin_button_major\" href=\"{/literal}{$file_name}{literal}?sel=delete_category&id_category="+id+"&page={/literal}{$page}{literal}\">{/literal}{$lang.admin_games.games_delete_yes}{literal}<span>&nbsp;</span></a></div>";
		str_html = str_html+"<div align=\"left\" style=\"padding-left:50px;\"><a href=\"#\"class=\"close\">{/literal}{$lang.admin_games.games_delete_no}{literal}</a></div>";
		str_html = str_html+"</div></div>";
	
		$("#dialog").html(str_html);
		$("#dialog").css("height","230px"),
		$("#dialog").css("width","410px"),
		$("#dialog").css("padding","20px"),
		ShowPopup();
}
function ShowPopup() {
	//e.preventDefault();
	//Get the A tag
	var id = '#dialog';
	
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();
	
	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
		
	//transition effect		
	$('#mask').fadeIn(500);	
	$('#mask').fadeTo("fast",0.8);	
	
	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
              
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2);
	$(id).css('left', winW/2-$(id).width()/2);
	
        $('#close').css('top',  winH/2-$('#dialog').height()/2+11);
		$('#close').css('left', winW/2+$('#dialog').width()/2+5);
	//transition effect
	$(id).fadeIn(500); 
	$('#close').fadeIn(500); 
}
{/literal}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}