<?php
/**
* @version 1.0.0
* @package RSFiles! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/

defined('_JEXEC') or die('Restricted access');
?>
<script language="javascript" type="text/javascript">
function selectAll(element) 
{
	for (var i=0; i<element.options.length; i++) 
	{
		var o = element.options[i];
		o.selected = true;
	}
}

function submitbutton(task)
{
	var form = document.adminForm;
	
	if(task == 'cancel')
	{
		submitform(task);
	}
	else  
	{
		ret = true;
		if(form.GroupName.value=='') { form.GroupName.className = 'jdError'; ret=false; } else { form.GroupName.className = '';  }			
		if((form.GroupAcl.value=='' && form.addusers.options.length == 0)) { form.GroupAcl.className = 'jdError'; form.addusers.className = 'jdError'; ret=false; } else { form.GroupAcl.className = ''; form.addusers.className = ''; }
		
		if(ret) 
		{
			selectAll($('addusers'));
			submitform(task);
		}
	}
	return false;
	 
}

function rsf_select_user(id,username,name)
{
	if (id == '') 
	{
		window.parent.document.getElementById('sbox-window').close();
		return; 
	}
	
	var values = $('addusers').options;
	var array = new Array();
	var j = 0;
	for ( i=0; i < values.length; i++ )
	{
		array[j] = values[i].value;
		j++;
	}
		
	if (array.contains(id))
	{	
		alert('<?php echo JText::_('RSFL_USER_ALREADY_EXISTS',true); ?>');
		return;
	}

	var option = new Option(name+ ' - '+username,id);
	$('addusers').add(option, null);
	
	window.parent.document.getElementById('sbox-window').close();
}

function rsf_remove()
{
	var select = $('addusers');
	
	var isselected = false;
	for(i=0;i<select.length;i++)
		if (select[i].selected)
			isselected = true;
	
	if (!isselected)
	{
		alert('<?php echo JText::_('RSFL_PLEASE_SELECT_USER',true); ?>');
		return;
	}
	
	for (i=select.length - 1; i >= 0; i--)
	{
		if ( select[i].selected )
			select[i].remove();
	}
}

</script>
<form action="index.php" method="post" name="adminForm" id="adminForm">
	<table cellspacing="0" cellpadding="0" border="0" width="100%">
		<tr>
			<td valign="top">
				<table  class="adminform">
					<tr>
						<td>
							<label for="groupName">
								<?php echo JText::_( 'RSFL_GROUP_NAME' ).':'; ?>
							</label>
						</td>
						<td>						
							<input type="text" name="GroupName" id="GroupName" size="40" value="<?php echo $this->data->GroupName; ?>" />
						</td>
					</tr>
					<tr>
						<td>
							<label for="joomlaGroups">
								<?php echo JText::_( 'RSFL_JOOMLA_GROUPS' ).':'; ?>
							</label>
						</td>
						<td>						
							<?php echo $this->lists['acls']; ?>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td valign="top">
				<table  class="adminform">
					<tr>
						<td colspan="3">						
							<?php echo JText::_( 'RSFL_USERS_GROUPS' ); ?>
						</td>
					</tr>
					<tr>
						<td width="15%">
							<?php echo $this->lists['usersadd']; ?>
						</td>
						<td>
							<a class="modal" rel="{handler:'iframe'}" href="index.php?option=com_rsfiles&task=users"><?php echo JText::_('RSFL_ADD_USERS'); ?></a> <br />
							<a href="javascript:void(0);" onclick="rsf_remove();"><?php echo JText::_('RSFL_REMOVE_USERS'); ?></a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table> 






<?php echo JHTML::_( 'form.token' ); ?>
<input type="hidden" name="option" value="com_rsfiles" />
<input type="hidden" name="cid" value="<?php echo $this->data->IdGroup; ?>" />
<input type="hidden" name="IdGroup" value="<?php echo $this->data->IdGroup; ?>" />
<input type="hidden" name="controller" value="groups" />
<input type="hidden" name="view" value="groups" />
<input type="hidden" name="task" value="save" />
</form>

<?php
//keep session alive while editing
JHTML::_('behavior.keepalive');
?>