{if $ajax eq 0}
{include file="$admingentemplates/admin_top.tpl"}
<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_users.php">{$lang.button.back}</a>
</div>
<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{$lang.groups.list}</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.groups_list}
    </div>
</div>
<ul class="tabs">
    <li>
        <a href="admin_users.php">{$lang.users.razdel_name}</a>
    </li>
    <li>
        <a class="current" href="#">{$lang.groups.razdel_name}</a>
    </li>
    <li>
        <a href="admin_users.php?sel=import">{$lang.admin_user.import.sub_header}</a>
    </li>
</ul>
<div class="panel">
    <div class="user_operation_line">
        <div class="uol_item" onclick="javascript: location.href='{$add_link}'">
            <div class="uol_in_item">{$lang.groups.add}</div>
        </div>        
        <div class="uol_item">
                    <div class="uol_in_item2" style="position:relative;width: 100%">
                        <div class="select_box_option" id="sub" style="text-align: center; border: 0;width:100%; position: relative;margin-left: -15px;">
                            {$lang.groups.membership_mode}
                            <div class="option_box" id="active_themes" style="position: absolute;width:100%; top:20px; left:0;">
        	                        <div class='option_box_item'>
                                        <div class='option_box_item_box' onclick="document.location.href='admin_groups.php?sel=member_mode&val=0'">
                                            <div style='width:90%;float:left;'>{$lang.groups.list_1}</div>
                                                <div class='theme_list' style='width:10%;float:left;{if $data.use_gender_membership eq 0}display:block{else}display:none{/if};'>
                                                    <img width="16" alt="" src="{$site_root}{$template_root}/images/success.png"> 
                                                </div>
                                            <div class="cr"></div>
                                        </div>
                                    </div>
                                    <div class='option_box_item'>
                                        <div class='option_box_item_box' onclick="document.location.href='admin_groups.php?sel=member_mode&val=1'">
                                            <div style='width:90%;float:left;'>{$lang.groups.list_2}</div>                                
                                            <div class='theme_list' style='width:10%;float:left;{if $data.use_gender_membership eq 1}display:block{else}display:none{/if};'>
                                                <img width="16" alt="" src="{$site_root}{$template_root}/images/success.png"> 
                                            </div>
                                            <div class="cr"></div>
                                        </div>
                                    </div>
        	                    <div id='bottom_corner' style='height:5px;'></div>
        	                </div>
                        </div>
                        
                    </div>
                </div>          
        <div class="uol_item" {literal}onclick="javascript: if (window.confirm('{/literal}{$lang.users.del_confirm|escape:javascript}{literal}'))  { DeleteList(); } else return false;"{/literal}>
            <div class="uol_in_item">{$lang.users.delete}</div>
        </div>
        <div class="uol_item" onclick="javascript: if (window.confirm('{$lang.groups.make_site_free_confirm|escape:javascript}')) document.location='{$del_groups_link}'; else return false;">
            <div class="uol_in_item">{$lang.groups.absolutely_free}</div>
        </div>
    </div>
	<div class="cr">&nbsp;</div>

    <div id="free_groups" style="width: 380px; float: left;">
    <table>
        <tr >
            <td align="left" nowrap width="auto" style="padding-left: 0px;">
                <input type="checkbox" style="margin-left: -1px;" id="use_freetrial_membership" name="use_freetrial_membership" value="1" {if $status eq 1} checked=""{/if} onchange="Func();"/>
                <b>{$lang.settings.use_freetrial_membership}:&nbsp;</b>
            </td>
            <td align="center" valign="middle">
                <table cellspacing=2 cellpadding=0>
                    <tr>                        
                        <td>
                            <input {if $status eq 1}onchange="Func();"{/if} type="text" id="freetrial_amount" name="freetrial_amount" size="4" maxlength="4" value="{$data.freetrial_amount}"  /></td>
                        <td>
                            <select {if $status eq 1}onchange="Func();"{/if} name="freetrial_period" id="freetrial_period" >
                            {foreach key=value item=name from=$data.freetrial_periods}
                            <option value="{$value}" {if $data.freetrial_period eq $value}selected{/if}>{$name}</option>
                            {/foreach}
                            </select>
                        </td>                                             
                    </tr>
                </table>
            </td>
        </tr>
    </table>   
    </div>      
                                
    <div class="user_status_line">
        <div class="cr"></div>
{/if}
        <div id="users_table_div">
<div id="tooltip" onclick="hideToolTip()" style="text-align:center; background-color: #FFFFFF; border: 1px dotted; width:auto; 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">
                <tbody>
                    <tr class="table_header">
                        <td width="29" align="center">
                            <input type="checkbox" name="select_all" id="select_all" onclick="PutAll()" />
                        </td>
                        <td width="280" align="left">
                            {$lang.groups.name}
                        </td>
                        <td width="120" align="center">
                            {$lang.groups.users_a_in_group}
                        </td>
                        <td width="170" align="left">
                            {$lang.groups.membership_cost}
                        </td>
                        <td align="center">
                            {$lang.groups.access_permissions}
                        </td>
                    </tr>
                   
                    {section name=g loop=$group_arr}
                    <tr height="20px;" {if $smarty.section.g.index mod 2 eq 1}class="even"{else}class="odd"{/if}>
                        <td align="center" valign="top"><input type="checkbox" name="delete" value="{$group_arr[g].id}" {if $group_arr[g].id eq 2 || $group_arr[g].id eq 6 || $group_arr[g].type eq 'd' || $group_arr[g].default eq 1}disabled{/if}></td>
                        <td valign="top">{$group_arr[g].name}</td>
                        <td align="center" valign="top">{$group_arr[g].user_count}</td>
                        <td align="left" valign="top">                            
                                <div id="price_{$smarty.section.g.index}" style="float:left;">
                                    {section name=i loop=$group_arr[g].price}  
                                        <div id="price" style="float: left; height: 20px; width: 100%">                                
                                            <div  style="float: left; margin-right: 5px;">
                                                {$group_arr[g].price[i].count}&nbsp;{$group_arr[g].price[i].period}-{$group_arr[g].price[i].cost}&nbsp;{$form.costunits}
                                            </div>
                                            <div style="float:left; display: none; padding-top: 2px;" id="del">
                                                <img src="{$site_root}{$template_root}/images/photo_delete.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" alt="{$lang.button.delete}" height="13" style="cursor: pointer;" onclick="Delete({$group_arr[g].price[i].id})" />
                                            </div> 
                                        </div>                               
                                        </br>
                                    {/section}
                                </div>                            
                        </td>
                        <td align="center" valign="top">
                            <div class="block_action" style=" padding-top: 2px; margin-left: 130px; position: relative;">
                                <div id="qwerty" value=1; style="float: left;">
                                    <a href="admin_groups.php?sel=perm&id={$group_arr[g].id}" >{$group_arr[g].permission.count}</a>&nbsp;&nbsp;
                                    
                                    {*<div id="permission" class="permissions" style="display: none; padding-left: 20px; float: left;background-color:white;">
                                            {$group_arr[g].permission.modulestr}                                  
                                    </div>*}
                                
                                </div>
                                <div style="float: left;">                               
                                    <img 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="document.location.href='admin_groups.php?sel=edit&id='+{$group_arr[g].id}" />&nbsp;&nbsp;
                                    {if $group_arr[g].type != 'g' && $group_arr[g].type != 't' && $group_arr[g].type != 'd' && $group_arr[g].default != '1'}
                                        <img src="{$site_root}{$template_root}/images/photo_delete.png" onmouseout="javascript:hideToolTip();" onmouseover="javascript: showToolTip(event,'{$lang.button.delete}');return false" alt="" height="13" style="cursor: pointer;" onclick="DelGroup({$group_arr[g].id})" />&nbsp;&nbsp;
                                    {/if}
                                </div>
                            </div>
                        </td>
                    </tr>
			{sectionelse}

			<tr height="40">
				<td class="main_error_text" align="left" colspan="5" bgcolor="#FFFFFF">{$lang.groups.empty}</td>
			</tr>
                    {/section}
					<tr class="table_header"><td colspan="5">&nbsp;</td></tr>
                </tbody>
             </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 - 80;
			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 $ajax eq 0}
    </div>
    
</div>
<!--<div id="permission" class="permissions">                                
</div>-->

{*
<font class=red_header>{$lang.groups.razdel_name}</font><font class=red_sub_header>&nbsp;|&nbsp;{$lang.groups.list}</font>
<div class="help_text">
    <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.groups_list}
    </div>
</div>
<br>
<font class=red_sub_header>{$lang.groups.list_1}</font>
<div class="help_text"><span class="help_title">{$lang.help}:</span>{$lang.admin_help.groups_list_1}</div>
<div>
	<table class="main_table" id="main_groups_div_1">
		{if $links}
		<tr bgcolor="#ffffff">
			<td height="20"  colspan=5 align="left" class="main_content_text" >{$links}</td>
		</tr>
		{/if}
        <tr>
            <td class="main_header_table" width="5%">{$lang.groups.number}</td>
            <td class="main_header_table" width="60%" >{$lang.groups.name}</td>
            <td class="main_header_table" width="15%">{$lang.groups.type}</td>
            <td class="main_header_table" width="10%" >&nbsp;</td>
            <td class="main_header_table" width="10%" >&nbsp;</td>
        </tr>
		{if $group_arr}
		{assign var="foo" value=0}
	  	{foreach item=item from=$group_arr}
	  	{if $item.is_gender_group ne '1'}
	  	{assign var="foo" value=$foo+1}
        <tr>
            <td class="main_content_table" width="5%">{$foo}</td>
            <td class="main_content_table" width="60%"><a {if $form.use_gender_membership ne 1} href="{$item.editlink}" {else} href="#" onclick="return false;" {/if}>{$item.name}</a></td>
            <td class="main_content_table" width="15%">{$item.type_name}</td>
            <td class="main_content_table" width="10%">{if $item.type ne 'm'}<input type="button" value="{$lang.groups.permission}" class="button" {if $form.use_gender_membership ne 1} onclick="javascript: location.href='{$item.editlink}'"  {else}onclick="return false;"{/if}>{/if}</td>
            <td class="main_content_table" width="10%">{if $item.type ne 'm'}<input type="button" value="{$lang.groups.user_list}" class="button" {if $form.use_gender_membership ne 1} onclick="javascript: location.href='{$item.userlink}'"  {else}onclick="return false;"{/if}>{/if}</td>
        </tr>
        {/if}
		{/foreach}
		{else}
        <tr height="40">
            <td class="main_error_text" align="left" colspan="5" bgcolor="#FFFFFF">{$lang.groups.empty}</td>
        </tr>
		{/if}
		{if $links}
		<tr bgcolor="#ffffff">
			<td height="20"  colspan=5 align="left"  class="main_content_text" >{$links}</td>
		</tr>
		{/if}
	</table>
	<table id="main_groups_div_2">
		<tr height="40">
			<td><input type="button" value="{$lang.groups.add}" class="button" {if $form.use_gender_membership ne 1}onclick="javascript: location.href='{$add_link}'"  {else}onclick="return false;"{/if}></td>
		</tr>
	</table>
</div>
<br>
<font class=red_sub_header>{$lang.groups.list_2}</font>
<div class="help_text"><span class="help_title">{$lang.help}:</span>{$lang.admin_help.groups_list_2}</div>
<div>
	<table class="main_table" id="gender_groups_div">
	<tr>
        <td class="main_header_table" width="5%">{$lang.groups.number}</td>
        <td class="main_header_table" width="60%" >{$lang.groups.name}</td>
        <td class="main_header_table" width="15%" >{$lang.groups.type}</td>
        <td class="main_header_table" width="10%" >&nbsp;</td>
        <td class="main_header_table" width="10%" >&nbsp;</td>
    </tr>
    {if $group_arr}
    {assign var="foo" value=0}
  	{foreach item=item from=$group_arr}
	{if $item.is_gender_group eq '1' || $item.type eq 'r' || $item.type eq 'd' || $item.type eq 'g' || $item.type eq 'm' || $item.type eq 't'}
  	{assign var="foo" value=$foo+1}
    <tr>
        <td class="main_content_table" width="5%">{$foo}</td>
        <td class="main_content_table" width="60%"><a {if $form.use_gender_membership eq 1} href="{$item.editlink}" {else} href="#" onclick="return false;" {/if}>{$item.name}</a></td>
        <td class="main_content_table" width="15%">{$item.type_name}</td>
        <td class="main_content_table" width="10%">{if $item.type ne 'm'}<input type="button" value="{$lang.groups.permission}" class="button" {if $form.use_gender_membership eq 1} onclick="javascript: location.href='{$item.editlink}'"  {else}onclick="return false;"{/if}>{/if}</td>
        <td class="main_content_table" width="10%">{if $item.type ne 'm'}<input type="button" value="{$lang.groups.user_list}" class="button" {if $form.use_gender_membership eq 1} onclick="javascript: location.href='{$item.userlink}'"  {else}onclick="return false;"{/if}>{/if}</td>
    </tr>
    {/if}
	{/foreach}
	{else}
    <tr height="40">
        <td class="main_error_text" align="left" colspan="5" bgcolor="#FFFFFF">{$lang.groups.empty}</td>
    </tr>
	{/if}
	</table>
</div>
<br><br>
<font class=red_sub_header>{if $form.free_site eq '1'}{$lang.groups.site_free_header}{else}{$lang.groups.make_site_free_header}{/if}</font><br><br>
		<table border=0 class="table_main" cellspacing=1 cellpadding=5 width="75%">
            <tr bgcolor="#FFFFFF">
                <td class="main_content_text">
				{if $form.free_site eq '1'}
					{$lang.groups.site_free_text}
				{else}
					{$lang.groups.make_site_free_text}
					{if $form.payed_count}<br>{$lang.groups.make_site_free_note}{/if}
				{/if}
				</td>
            </tr>
		{if $form.free_site neq '1'}
            <tr bgcolor="#FFFFFF">
                <td><input type="button" value="{$lang.groups.delete_groups}" class="button" onclick="javascript: if (window.confirm('{$lang.groups.make_site_free_confirm|escape:javascript}')) document.location='{$del_groups_link}'; else return false;"></td>
            </tr>
		{/if}
		</table>
*}
{literal}
<script type="text/javascript">
$(document).ready(function(){
     $("#qwerty").live("mouseover mouseout", function() {
     var height = document.getElementById('users_table_div').offsetHeight;
     var top = document.getElementById('users_table_div').offsetTop;
     var width = document.getElementById('qwerty').offsetWidth;
     /*$("#permission").css('height', height)
     $("#permission").css('top', 0)
     $("#permission").css('left', 0)
     $("#permission").toggle();*/
     $(this).children("#permission").css('height', height-25)
     $(this).children("#permission").css('top', 0)
     $(this).children("#permission").toggle()
	   });
       
       
     $('#bottom_corner').corner("bottom 3px");
     $('.select_box_option').live('click',function(){
        $("#active_themes").toggle();
        });
        $(".option_box_item_box").hover(
        function(){
            $(this).addClass('option_box_item_box_hover');
            },
        function(){
            $(this).removeClass('option_box_item_box_hover');
            }
        ); 		
})

function Delete(price){
    var par = "sel=delprice&id="+price+'&ajax=1'
    $.ajax({
        type: "POST",
        url: 'admin_groups.php',
        data: (par),
		success: function(data){
		  $('#users_table_div').html(data);
		}
    })
}

function DelGroup(id){
    //document.location.href='admin_groups.php?sel=del&id='+{$group_arr[g].id}
    $.ajax({
        type: "POST",
        data: 'sel=del&id='+id+'&ajax=1',
        url: "admin_groups.php",
        success: function(data){
            $('#users_table_div').html(data)
        }
    })
}

function DeleteList(){
    $('input[name=delete]:checked').each(function(){
         DelGroup($(this).val())
    })
}

/*function Membership_mode(val){
    
}*/

function HighLight(section, state) {
	if (document.getElementById(section)) {
		if (state == 1) {
			setElementOpacity(section, 0.4);
		} else {
			setElementOpacity(section, 1.0);
		}
	}
	return;
}


function PutAll() {
         var o=document.getElementsByName('select_all')	
         var i
         if (o[0].checked){                    
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                if (!o[i].disabled)
                    o[i].checked = true
            }            
         }
         else{
            o=document.getElementsByName('delete')
            for (i=0; i<o.length; i++){                
                o[i].checked = false
            }            
         }             
}

function Func(){
    var p = document.getElementById('use_freetrial_membership')
    var freetrial_amount = $("#freetrial_amount").val();
    var freetrial_period = $("#freetrial_period").val();
    var status;
    if (p.checked)
        status = 1;
                //document.free.submit()
    else
        status = 0;
    
    ajaxLoadingImage(1, 'free_groups');    
    $.ajax({
        type: "POST",
        data: 'sel=free_real&status='+status+'&ajax=1&freetrial_period='+freetrial_period+'&freetrial_amount='+freetrial_amount,
        url: "admin_groups.php",
        success: function(data){
            //$('#users_table_div').html(data)
            ajaxLoadingImage(0, 'free_groups');
            ShowAjaxError("", '{/literal}{$lang.button.save}{literal}', 'success');   
        }
    })
	return false;
}


function setElementOpacity(sElemId, nOpacity)
{

  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);

  if (!elem || !opacityProp) return; // error

  if (opacityProp=="filter")  // Internet Explorer 5.5+
  {
    nOpacity *= 100;

    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
  }
  else {
  	elem.style[opacityProp] = nOpacity;
  }
  return;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') { // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9, IE7)
    return 'opacity';
  } else if (typeof document.body.style.MozOpacity == 'string') {// Mozilla 1.6 � ������, Firefox 0.8
    return 'MozOpacity';
  } else if (typeof document.body.style.KhtmlOpacity == 'string') {// Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  } else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) {// Internet Explorer 5.5+
    return 'filter'
  } else {
  	return false;
  }
}
</script>
{/literal}
<script type="text/javascript">
{if $form.use_gender_membership eq 1}
HighLight('main_groups_div_1', 1);
HighLight('main_groups_div_2', 1);
{else}
HighLight('gender_groups_div', 1);
{/if}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}
{/if}