{include file="$admingentemplates/admin_top.tpl"}
<link type="text/css" href="{$site_root}{$template_root}/css/jquery.css" rel="stylesheet" />
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.admin_menu.admin_promo_codes}</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.admin_promo_codes}
    </div>
</div>

	{if $err}
	<div>
		<font class="error_msg">{literal}<script>ShowAjaxError('', '{/literal}{$err|escape:javascript}{literal}');</script>{/literal}</font>
	</div>
	{/if}
	<div>
		<form name="add_campaign" action="{$file_name}?sel=add_campaign" method="post" >
			<table cellpadding="0" cellspacing="0" >
			<tr>
				<td colspan="2" class="section_header">{$lang.admin_promo_codes.add_campaign_header}</td>
			</tr>
			<tr>
				<td  style="padding-bottom: 5px;" width="30%">{$lang.admin_promo_codes.campaign_name} :</td>
				<td style="padding-bottom: 5px;"><input type="text" name="name" id="promo_name" style="width:199px;"/></td>
			</tr>
			<tr>
				<td style="padding-bottom: 5px;" width="30%">{$lang.admin_promo_codes.campaign_type} :</td>
				<td style="padding-bottom: 5px;">
					<select id="type_val" name="type" onchange="switchType();" style="width:199px;">
						{foreach from=$types key=key item=item}
							<option value="{$key}">{$item}</option>
						{/foreach}
					</select>
				</td>
			</tr>
			<tr>
				<td style="padding-bottom: 5px;" width="30%">{$lang.admin_promo_codes.type_value} :</td>
				<td style="padding-bottom: 5px;">
					<select id="type_group" name="type_value" style="width:199px;">
						{foreach from=$groups item=item}
						<option value="{$item.id}">{$item.info_str}</option>
						{/foreach}
					</select>
					<input id="type_curr" type="text" name="type_value" value="" />
					<script type="text/javascript">
					{literal}
					function switchType(){
						var val = $("#type_val").val();
						switch (val){
							case 'group': 
								$("#type_curr").attr('disabled','disabled');
								$("#type_group").removeAttr('disabled');
								$("#type_curr").hide();
								$("#type_group").show();
							break;	
							case 'curr': 
								$("#type_curr").removeAttr('disabled');
								$("#type_group").attr('disabled','disabled');
								$("#type_curr").show();
								$("#type_group").hide();
							break;	
						}
					}
					switchType();
					
					{/literal}
					</script>
				</td>
			</tr>
			<tr>
				<td style="padding-bottom: 5px;" width="30%">{$lang.admin_promo_codes.code_count} :</td>
				<td style="padding-bottom: 5px;">
					<input type="text" name="count" id="promo_count" value="{$data.count}" size="22" />
				</td>
			</tr>
			<tr>
				<td style="padding-bottom: 5px;" width="30%">{$lang.admin_promo_codes.campaign_dates} :</td>
				<td style="padding-bottom: 5px;">
					<input type="text" value="{$form.start}" id="date_start" name="date_start" onmousedown="{literal}$('#date_start').datepicker('show');{/literal}" readonly style="margin-right: 5px;">
					&nbsp;-&nbsp;
					<input type="text" value="{$form.end}" id="date_end" name="date_end" onmousedown="{literal}$('#date_end').datepicker('show');{/literal}" readonly style="margin-right: 5px;">				
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<a class="admin_button_major" onclick="addCampaign(this);" name="search_submit">{$lang.button.add}<span>&nbsp;</span></a>
				</td>
			</tr>
			</table>
		</form>
		<table border=0 cellspacing=0 cellpadding=0 width="100%" style="margin-top:20px;">
<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();

    $.datepicker.setDefaults($.extend({showMonthAfterYear: false}));
    $("#date_start").datepicker({changeMonth: true, changeYear: true, showOn: 'button', buttonImage: '{/literal}{$site_root}{$template_root}{literal}/images/calendar.gif', buttonImageOnly: true});
    $("#date_end").datepicker({changeMonth: true, changeYear: true, showOn: 'button', buttonImage: '{/literal}{$site_root}{$template_root}{literal}/images/calendar.gif', buttonImageOnly: true});
});
</script>
{/literal}
		<tr class="table_header">
			<td width="15%">{$lang.admin_promo_codes.campaign_name}</td>
			<td width="15%" align="center">{$lang.admin_promo_codes.campaign_type}</td>
			<td width="15%" align="center">{$lang.admin_promo_codes.type_value}</td>
			<td width="12%" align="center">{$lang.admin_promo_codes.codes_link}</td>
			<td width="18%" align="center">{$lang.admin_promo_codes.statistic}</td>
			<td width="17%" align="center">{$lang.admin_promo_codes.campaign_dates}</td>
			<td width="8%" align="right">{$lang.users.actions}</th>
		</tr>
		{foreach from=$items key=key item=item}
		<tr id="id_{$item.id}" {if $key mod 2 eq 1}class="even"{else}class="odd"{/if}>
			<td class="main_content_text">{$item.campaign_name}</td>
			<td class="main_content_text" align="center">{$lang.admin_promo_codes.types[$item.type]}</td>
			<td class="main_content_text" align="center">{$item.type_value}</td>
			<td class="main_content_text" align="center">{if $item.codes_link}<a href="{$item.codes_link}">{$lang.admin_promo_codes.codes_link}</a>{/if}</td>
			<td class="main_content_text" align="center">{$lang.admin_promo_codes.used_codes}:{$item.count_used_codes}/{$lang.admin_promo_codes.unused_codes}:{$item.count_unused_codes}</td>
			<td class="main_content_text" align="center">{if $item.date_begin != '0000-00-00'}{$item.date_begin}{else}&infin;{/if} - {if $item.date_end != '0000-00-00'}{$item.date_end}{else}&infin;{/if}</td>
			<td class="main_content_text">
                <div class="block_action" style="float: right; margin-right: 20px;">                
                    <img  src="{$site_root}{$template_root}/images/photo_delete.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" height="15px" width="15px" alt="" align="right" onclick="if (confirm('{$lang.admin_promo_codes.confirm_delete|escape:javascript}'))delItem({$item.id});" style="cursor: pointer; float: right;" />                                       
                </div>                
            </td>
		</tr>
		{foreachelse}
		<tr height="40">
			<td class="main_error_text" align="left" colspan="7" bgcolor="#FFFFFF">{$lang.admin_promo_codes.no_campaigns}</td>
		</tr>
		{/foreach}
            <tr class="table_header">
				<td colspan="11">
					&nbsp;&nbsp;
					{if $links}
					{foreach item=item from=$links.pages}
						&nbsp;<a onclick="PageList('bad_words', '{$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('bad_words', '{$links.previous}');">< {$lang.content.previous} {$per_page}</a>
					{/if}
					{if $links.next}
						<a onclick="PageList('bad_words', '{$links.next}');">{$lang.content.next} {$per_page} ></a>
					{/if}
					</div>
				</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>
	<div class="cr">&nbsp;</div>

	<script type="text/javascript">
		var page={$page};
		var file_name='{$file_name}';
		{literal}
		function delItem(id){
			data = 'ajax=1&sel=delcampaign&id_item='+id;
			$.post(file_name,data,function(data){
				$("#id_"+id).fadeOut("fast", function(){
					if (!$(".item_str:visible").css("display")){
						location.href = (page > 1) ? file_name+'?page='+(page-1) : file_name;
					}
				});
			});
		}
		function switchToDates(checked){
			if (checked){
				$("select[@jq_id=to_dates]").attr("disabled", "disabled");
				$("select[@jq_id=to_dates]").hide();
			}else{
				$("select[@jq_id=to_dates]").show();
				$("select[@jq_id=to_dates]").removeAttr("disabled");
			}
		}
		function addCampaign(){
			name = $("#promo_name").val();
			count = parseInt($("#promo_count").val());
			if(name == ''){
				alert("{/literal}{$lang.admin_promo_codes.err.addCampaign_emty_name|escape:javascript}{literal}");
				return false;
			}
			if(isNaN(count)){
				alert("{/literal}{$lang.admin_promo_codes.err.generateCodes_zero_count|escape:javascript}{literal}");
				return false;
			}
			$("form:first").submit();
		}
		
		{/literal}
	</script>
	
	{if $go_to_url}
		<script>
			var go_to_url = "{$go_to_url}";
			{literal}
			$(document).ready(function(){
				setTimeout(function(){location.href=go_to_url;}, 1000); //for IE
			});
			{/literal}
		</script>
	{/if}
	
{include file="$admingentemplates/admin_bottom.tpl"}
	