{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<script language="JavaScript" type="text/javascript" src="{$site_root}{$index_theme_path}/js/jquery.form.js"></script>

<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_menu.affiliate}</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>{$top_help}
    </div>
</div>
<div class="cr">&nbsp;</div>
<ul class="tabs" style="width: 100.5%;">
    <li>
        <a {if $ref eq '1'}class="current"{else}href="admin_affilate.php?ref=1"{/if}>{$lang.admin_menu.aff_summary}</a>
    </li>
    <li>
        <a {if $ref eq '5'}class="current"{else}href="admin_affilate.php?ref=5"{/if}>{$lang.admin_menu.aff_sales}</a>
    </li>
    <li style="padding-right:0px;">
        <a {if $ref eq '6'}class="current"{else}href="admin_affilate.php?ref=6"{/if}>{$lang.admin_menu.aff_affiliate}</a>
    </li>
    <li style="padding-right:0px;">
        <a {if $ref eq '8'}class="current"{else}href="admin_affilate.php?ref=8"{/if}>{$lang.admin_menu.aff_ads}</a>
    </li>
    <li style="padding-right:0px;">
        <a {if $ref eq '3'}class="current"{else}href="admin_affilate.php?ref=3"{/if}>{$lang.admin_menu.aff_statistics}</a>
    </li>
    <li style="padding-right:0px;">
        <a {if $ref eq '14'}class="current"{else}href="admin_affilate.php?ref=14"{/if}>{$lang.admin_menu.aff_settings}</a>
    </li>
</ul>
<div class="panel" style="width:100.2%;">
    <div class="user_status_line" style="margin-top:0px;">
            <div id="ref_block" class="fl" style="{*width:45%;*}width:100%;float:left;">
{/if}
{include file="$admingentemplates/$filename"}
{if $ajax eq 0}
            </div>
{*            <div class="fl" id="options" style="width:50%;margin:10px;">
                &nbsp;
            </div>*}
    </div>
</div>
<script type="text/javascript">
var ref = {$ref};
{literal}
var REF_OLD = "";
var REF_OPEN_OPTION = "";
function Refresh() {
	file_name = '{/literal}{$form.action}{literal}';
	var s='';
	i = 0;
	while(document.getElementById(i)) {
		if (document.getElementById(i).checked == true) {
			if (s != '') {
				s=s+','+document.getElementById(i).value;
			} else {
				s=document.getElementById(i).value;
			}
		}
		i++;
	}
	tmp_text = 'Saving...';
	ShowAjaxError(tmp_text, '', 'success');
	//$('#refresh').html(tmp_text);
	$.post(file_name , {sel:'refresh', end:i, val:s}, function(data){
		CloseAjaxError(1);
		$('#refresh').html(data);
	});
}
$(document).ready(function() {
    $("tr .table_row .action_edit").click(
        function(){
            var ref_id = $("tr .select_tr").find('input[type="hidden"]').val();
            REF_OLD = $('#ref_'+ref_id).text();
            str = '<input type="text" name="ref_new" id="ref_new_'+ref_id+'" value="'+REF_OLD+'" size="20">';
            $('#ref_'+ref_id).html(str);
            $('tr .select_tr').find('div .action_edit, .action_del').css('display', 'none');
            $('tr .select_tr').find('div .action_save').css('display', 'block');
        }
    );
    $("tr .table_row .action_save").click(
        function(){
            var ref_id = $("tr .select_tr").find('input[type="hidden"]').val();
            var ref_new = $('#ref_new_'+ref_id).val();
            if (ref_new == '') return;
            ajaxIndicator(1, 'ref_'+ref_id);
            $.post('admin_reference.php', {sel:'change',ref:ref, id:ref_id,name:ref_new},
                function(data){
                    ajaxIndicator(0, 'ref_'+ref_id);
                    if (data=="")
                        $('#ref_'+ref_id).html(REF_OLD);
                    else 
                        $('#ref_'+ref_id).html(data);
                    REF_OLD = "";
                }
            );
            $('tr .select_tr').find('div .action_edit, .action_del').css('display', 'block');
            $('tr .select_tr').find('div .action_save').css('display', 'none');
        }
    );
    $("tr .table_row .action_del").click(
        function(){
            var ref_id = $("tr .select_tr").find('input[type="hidden"]').val();
            ajaxIndicator(1, 'ref_'+ref_id);
            $.post('admin_reference.php', {sel:'del',ref:ref, id:ref_id},
                function(data){
                    ajaxIndicator(0, 'ref_'+ref_id);
                    if (data == 'deleted'){
                        if (ref_id == REF_OPEN_OPTION)
                            $("#options").html('');
                        //$("#tr_"+ref_id).remove();
                        ShowReference('')
                    }
                }
            );
        }
    );
    $("#ref_add").click(
        function(){
            var name_ref_add = $("#name_ref").val();
            if (name_ref_add == "") return;
            document.types_form.submit();
        }
    );
});
function ShowOption(par, open_ref) {
    REF_OPEN_OPTION = open_ref;
    ajaxLoadingImage(1, 'options');
    $.post(par,'',function(data){
        ajaxLoadingImage(0, 'options');
        $('#options').html(data);
    });
}
function ShowReference(par) {
    ajaxLoadingImage(1, 'ref_block');
    if(par == '')
        $.post('admin_reference.php',{ref:ref,ajax:'1'},function(data){
            ajaxLoadingImage(0, 'ref_block');
            $('#ref_block').html(data);
        });
    else
        $.post(par,'',function(data){
            ajaxLoadingImage(0, 'ref_block');
            $('#ref_block').html(data);
        });
}
function PageList(id_div, par) {
    ShowReference(par);
}
{/literal}
</script>

{include file="$admingentemplates/admin_bottom.tpl"}
{/if}