<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php JHTML::_('behavior.modal'); ?>
<?php  JHTML::_('behavior.tooltip');  ?>
<?php
	$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
	$edit=JRequest::getVar( 'edit', true );
	JArrayHelper::toInteger($cid, array(0));

	$text = ( $edit ? JText::_( 'Edit' ) : JText::_( 'New' ) );

	JToolBarHelper::title(  JText::_( 'Filter' ).' : <small><small>[ ' .$text.' ]</small></small>', 'kip.png'  );
	JToolBarHelper::save('save');
	JToolBarHelper::apply('apply');
	JToolBarHelper::cancel( 'cancel', $edit ? 'Close' : 'Cancel' );
	
	$editor =& JFactory::getEditor('none');
	JFilterOutput::objectHTMLSafe( $this->item);
?>

<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		// do field validation
		var regex=/^\s*[0-9]{1,3}(\.[0-9]{1,3}){3}((-[0-9]{1,3}(\.[0-9]{1,3}){3})|(\/[0-9]{1,2})|(\/[0-9a-f]{8})|(\/[0-9]{1,3}(\.[0-9]{1,3}){3})|)\s*$/;
		if (!regex.test(form.iprange_txt.value)) {
			alert( "<?php echo JText::_( 'Incorrect IP address/range ', true ); ?>" );
		}else{
			if(document.getElementById('client_id').value!=2)
				document.getElementById('userid').value=0;
			submitform( pressbutton );
		}
	}
	
	function jSelectUser(id, title) {
		document.getElementById('userid').value = id;
		document.getElementById('username').value = title;
		document.getElementById('sbox-window').close();
	}
	
</script>
<form action="index.php" method="post" name="adminForm">
<div class="col100">
	<fieldset class="adminform">
	<legend><?php echo JText::_('Details') ?></legend>
	<table class="admintable">
		<tr>
			<td style="width:100px" class="key">
				<label for="title">
					<?php echo JText::_( 'IP address/range' ); ?>:
				</label>
			</td>
			<td>
				<input class="inputbox" type="text" name="iprange_txt" id="iprange_txt" size="96" value="<?php echo $this->item->iprange_txt; ?>" />
			</td>
			<td>
				&nbsp;&nbsp;<span class="editlinktip hasTip" title="<?php echo JText::_('FIELD_IP_TIP_TITLE').'::'.JText::_('FIELD_IP_TIP_TEXT')?>">
					<?php echo JHTML::_('image.administrator',  'help.png', '/components/com_kip/assets/images/' ); ?>
				</span>
			</td>
		</tr>
		<tr>
			<td class="key">
				<label for="title">
					<?php echo JText::_( 'Type' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->lists['client_id']; ?>
			</td>
		</tr>
		<tr id="user_outer" <?php echo $this->item->client_id!=2 ? 'style="display:none"' : ''?>>
			<td class="key">
				<?php echo JText::_('User') ?>
			</td>
			<td >
				<div style="float: left;">
					<input size="40" style="background: #ffffff;" type="text" id="username" value="<?php echo $this->item->username; ?>" disabled="disabled" />
				</div>
				<div class="button-1">
					<div>
						<a class="modal" title="<?php echo JText::_('Select User') ?>"  href="index.php?option=<?php echo $this->option ?>&view=users&tmpl=component" rel="{handler: 'iframe', size: {x: 800, y: 400}}"><?php echo JText::_('Select') ?></a>
					</div>
				</div>
				
				<input class="inputbox" type="hidden" name="userid" id="userid"  value="<?php echo $this->item->userid; ?>" />
			</td>
		</tr>
	
		<tr>
			<td class="key">
				<label for="title">
					<?php echo JText::_( 'State' ); ?>:
				</label>
			</td>
			<td>
				<?php echo $this->lists['published']; ?>
			</td>
		</tr>
		<tr>
			<td class="key">
				<label for="description">
					<?php echo JText::_( 'Notes' ); ?>:
				</label>
			</td>
			<td>
				<?php
				echo $editor->display( 'description',  $this->item->description, '400', '60', '60', '20', false ) ;
				?>
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<div class="clr"></div>

	<input type="hidden" name="task" value="" />
	<input type="hidden" name="option" value="<?php echo $this->option ?>" />
	<input type="hidden" name="view" value="<?php echo $this->view ?>" />
	<input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
	<input type="hidden" name="cid[]" value="<?php echo $this->item->id; ?>" />
	<input type="hidden" name="textfieldcheck" value="<?php echo $n; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>