{include file="$admingentemplates/admin_top.tpl"}
<link type="text/css" href="{$site_root}{$template_root}/css/jquery.css" rel="stylesheet" />
<script language="JavaScript" type="text/javascript" src="{$site_root}{$template_root}/js/jquery-ui.js"></script>
{if $form}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_marketing.php">{$lang.button.back}</a>
</div>
{/if}
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.admin_market.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>{$help.admin_market}
    </div>
</div>
<div class="cr">&nbsp;</div>
<div>
	<table class="table_main" cellspacing="1" cellpadding="5" border="0" width="100%" style="background-color:white;">
		<tr>
			<td width="50%" valign="top">
				<form name="add_market" action="{$file_name}" method="POST">
				{$hiddens}
				<div style="width:100%;overflow:hidden;"><font class="section_header">{if $form.name_market} {$lang.admin_market.edit_campaign} {else} {$lang.admin_market.add_campaign} {/if}</font></div>
				<div class="sep"></div>
				<div id="market_name" style="float:left;">{$lang.admin_market.name}:&nbsp;</div><input type="text" name="name_market" value="{$form.name_market}" size="35">
				<div class="sep"></div>
				{$lang.admin_market.url}:<br><div id="url" style="float:left;">{$server}/</div><input type="text" name="url" size="35" value="{$form.url}">
				<div class="sep"></div>
				{$lang.admin_market.url_leads}:&nbsp;
				<input type="radio" id="reg" name="leads" value="1" {if $form.leads eq '1'}checked{/if}>
				<label for="reg">registration.php</label>
				<input type="radio" id="ind" name="leads" value="0" {if $form.leads eq '0'}checked{/if}>
				<label for="ind">index.php</label>
				<div class="sep"></div>
				{$lang.admin_market.dates}:
				<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;">				
				<input type="checkbox" name="no_ending" value="1" {if $form.no_ending}checked{/if}>
				{$lang.admin_market.no_ending_date}
				<div class="sep"></div>
				<div align="left">
					<a href="#" class="admin_button_major" onclick="javascript:document.add_market.submit();">{$lang.button.save}<span>&nbsp;</span></a>
				</div>
				</form>
			</td>
			<td valign="top">
			<div style="padding-left:15px;">
				<div style="width:100%;overflow:hidden;"><font class="section_header">{$lang.admin_market.calculator}</font></div>
				<div class="sep"></div>
				<div id="calculator_select_campaign" style="float:left;">{$lang.admin_market.calculator_select_campaign}:&nbsp;</div>
					<select name="campaign" id="campaign" onchange="GetSum();" style="width:104px;">
						<option  value="" selected>{$lang.index.please_select}</option>
						{foreach item=item from=$data}
						<option  value="{$item.id}">{$item.name}</option>
						{/foreach}
					</select>
				<div class="sep"></div>
				<div id="calculator_spent" style="float:left;">{$lang.admin_market.calculator_spent}:&nbsp;</div><input type="text" name="spent" id="spent" size="15" value="0">&nbsp;{$site_unit_costunit}
				<div class="sep"></div>
				
				<div id="calculator_got" style="float:left;">{$lang.admin_market.calculator_got}:&nbsp;</div>
					<select name="got" id="got" onchange="GetSum();" style="width:104px;">
						<option  value="" selected>{$lang.index.please_select}</option>
						<option  value="total">{$lang.admin_market.calculator_total}</option>
						<option  value="membership">{$lang.admin_market.calculator_membership}</option>
						<option  value="servises">{$lang.admin_market.calculator_servises}</option>
					</select>
				<span id="sum">
				</span>
				<div class="sep"></div>
					<div style="float:left;">
						<a href="#" class="admin_button" onclick="Calculate();">{$lang.admin_market.calculate}<span>&nbsp;</span></a>
					</div>
					<div style="float:left;">
						&nbsp;&nbsp;&nbsp;
						<a href="#" class="admin_button" onclick="Reset();">{$lang.admin_market.reset}<span>&nbsp;</span></a>
					</div>
					<div style="float:left;">
						&nbsp;&nbsp;&nbsp;
						<a href="#" class="admin_button" onclick="javascript: document.location.href='{$file_name}?sel=stat'">{$lang.admin_market.general_statistic}<span>&nbsp;</span></a>
					</div>
				<div class="sep" style="clear:both;"></div>
				<div id="info">
					<div id="error_box" class="error_box_blue" style="margin-left:0px; padding-left:0px;">&nbsp;*&nbsp;{$lang.admin_market.calculate_err}</div>
				</div>
			</div>
			</td>
		</tr>
	</table>
</div>
<div class="sep"></div>
<div>
<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 width="100%" cellspacing="0" cellpadding="0" border="0">
	<tr class="table_header">
		<td width="10%" align="left">
			{$lang.admin_market.name}
		</td>
		<td width="40%" align="center">
			{$lang.admin_market.special_link_url}
		</td>
		<td width="40%" align="center">
			{$lang.admin_market.dates}
		</td>
		<td width="10%" align="right">
			{$lang.admin_market.actions}
		</td>
	</tr>
	{foreach item=item from=$data name=stat}
	<tr {if $smarty.foreach.stat.iteration mod 2 eq 1}class="table_row even"{else}class="table_row odd"{/if}>
		<td width="10%" style="padding-left: 5px;">
			{$item.name}
		</td>
		<td width="40%">
			{$item.url}
		</td>
		<td width="40%" align="center">
			{$item.date_start}&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;{$item.date_end}
		</td>
		<td width="10%" align="center">
					<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" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" onclick="document.location.href='{$file_name}?sel=del&id={$item.id}'">
						</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" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.edit}');return false" onclick="document.location.href='{$file_name}?sel=edit&id={$item.id}'">
						</div>
					</div>
		{if $item.no_start ne '1'}
					<div style="width:10px;float:right;" class="fl">&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/icon_ss.gif" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.statistic}');return false" onclick="document.location.href='{$file_name}?sel=stat&id_market={$item.id}'">
						</div>
					</div>
		{/if}
		</td>
	</tr>
	{foreachelse}
	<tr height="40">
		<td class="main_error_text" align="left" colspan="4" bgcolor="#FFFFFF">{$lang.interests_spr.empty}</td>
	</tr>
	{/foreach}
	<tr class="table_header"><td colspan="4">&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>
<div class="cr">&nbsp;</div>
<script type="text/javascript">
{literal}
TOTAL = 0;
function Calculate() {
	got = $("#got option:selected").val();
	campaign = $("#campaign option:selected").val();
	spent = $("#spent").val();
	if (got == '' || campaign == '') {
		$("#error_box").show();
	} else {
		profit = TOTAL - spent;
		if (profit < 0) {
			$("#info").html('<div style="display:table;width:100%;padding-top:10px;"><b>{/literal}{$lang.admin_market.calculate_profit}{literal}:</b> '+profit+'&nbsp;{/literal}{$site_unit_costunit}&nbsp;(<font style="color:red;">{$lang.admin_market.lost}</font>){literal}</div>');
		} else {
			$("#info").html('<div style="display:table;width:100%;padding-top:10px;"><b>{/literal}{$lang.admin_market.calculate_profit}{literal}:</b> '+profit+'&nbsp;{/literal}{$site_unit_costunit}&nbsp;(<font style="color:green;">{$lang.admin_market.earned}</font>){literal}</div>');
		}
		
	}
}

function GetSum() {
	par = $("#got option:selected").val();
	campaign = $("#campaign option:selected").val();
	if (par == '') {
		$("#sum").html('');
	} else if (campaign == '') {
		$("#sum").html('<font class="error_msg">&nbsp;*&nbsp;{/literal}{$lang.admin_market.calculator_select_campaign}{literal}</font>');
	} else {
		$.post("{/literal}{$file_name}{literal}",{sel:'get_calc_stat',got:par,id_market:campaign},
			function(data){
				$("#sum").html('<b>'+data+'&nbsp;{/literal}{$site_unit_costunit}{literal}');
				TOTAL = data;
			}
		);
	}
	$("#info").html('');
}

function Reset() {
	$("#info").html('');
	$("#sum").html('');
	$("#spent").val('0');
	$("select option[value='']").attr("selected","selected");
}

$(function() {
	$.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});
	$('#market_name').width($('#url').width());
	$('#calculator_spent').width($('#calculator_select_campaign').width());
	$('#calculator_got').width($('#calculator_select_campaign').width());
});
{/literal}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}