
<!--/span-->				<div class="span12"><script type="text/javascript">
	function newCategory(){
		d = document.category;
		d.cid.value = "";
		d.cname.value = "";
		d.corder.value = "";
		d.cparent.value = "";
		d.cdesc.value = "";
		//d.cprice.value = "0";
		d.action.value ="new";
		d.submitCat.value ="New Category";
		document.getElementById("form-tab").innerHTML ="New Category";
		show("formCat");
		location.href = "#formCat";
		$('form#category').attr('action', 'categories/add');
	}	
	function editCategory(cid, corder,cparent,cprice){
		d = document.category;
		d.cid.value = cid;
		d.cname.value = document.getElementById('name-'+cid).innerHTML;
		d.corder.value = corder;
		d.cparent.value = cparent;
		d.cdesc.value = document.getElementById('desc-'+cid).innerHTML;//cdesc;
		//d.cprice.value = cprice;
		d.action.value ="edit";
		d.submitCat.value ="Edit Category";
		document.getElementById("form-tab").innerHTML ="Edit Category";
		show("formCat");
		location.href = "#formCat";
		$('form#category').attr('action', 'categories/add');
	}	
	function deleteCategory(category){
		if (confirm('Delete Category "'+document.getElementById('name-'+category).innerHTML+'"?'))
		window.location = "categories/delete/"+category;
	}
</script>

<div class="page-header">
	<h1>Categories</h1>
	<button class="btn btn-primary pull-right" onclick="newCategory();return false;">
		<i class="icon-pencil icon-white"></i>
		New Category	</button>		
</div>

Manage your website categories 
<form  class="well form-inline" action="" method="get" >
<select name="cid" id="cid"><option value=0>All</option>
<?php foreach($parent_categories as $category){?>
<option  value="<?php echo $category->id;?>" <?php  if($selected_cat && $category->id==$selected_cat) echo 'selected="selected"';?>><?php echo $category->name;?></option>
<?php } ?>
	</select><input type="hidden" name="action" value="filter" /><input type="submit" class="btn" value="Filter" /></form>

<div id="formCat" style="display:none;">
	<h2 id="form-tab"></h2>
	<form class="well" name="category" id="category" action="categories/edit" method="post" onsubmit="return checkForm(this);">
		<fieldset>
			<p>
				<label>Category name</label>
				<input class="span4" name="cname" type="text" class="text-long" lang="false" onblur="validateText(this);" xml:lang="false" />
			</p>                          
			<p>
            	<label>Order</label>
                <input class="span1" name="corder" type="text" class="text-small" lang="false"  onblur="validateNumber(this);" onkeypress="return isNumberKey(event);" value="" maxlength="5" xml:lang="false" />
			</p>
			<p>
            	<label>Parent</label>
                <select name="cparent" id="cparent"><option value=0>Top Level</option>
	 <?php foreach($parent_categories as $category){?>
<option  value='<?php echo $category->id;?>'><?php echo $category->name;?></option>
<?php } ?></select>        	</p>
			<p>
            	<label>Description</label>
                <textarea class="span4" rows="10" name="cdesc" ></textarea>
        	</p>
		
			<input id="submitCat" type="submit" value="" class="btn btn-primary" />
			<input type="submit" value="Cancel" class="btn" onclick="hide('formCat');return false;" />
			<input type="hidden" name="cid" value="" />
			<input type="hidden" name="action" value="" />
		</fieldset>
	</form>
</div>


<table class="table table-bordered">
	<thead>
		<tr>
			<th>Categories</th>
			<th>Order</th>
			<th>Parent</th>
			
			<th>&nbsp;</th>
		</tr>
	</thead>
	<?php foreach($categories as $category){?>
		<?php 
			if($category->parent_id > 0){
				$p_category=$this->categories_model->getCategory($category->parent_id);
				$parent_category=$p_category->name;
			}else{
				$parent_category='Parent';
			}

		?>
		<tr>      
		<td><?php echo $category->name;?></td>
		<td><?php echo $category->order;?></td>
		<td><?php echo $parent_category;?></td>
		
		<td>
			<button  class="btn btn-primary" onclick="editCategory('<?php echo $category->id;?>', '<?php echo $category->order;?>','<?php echo $category->parent_id;?>','0');return false;">
				<i class="icon-edit icon-white"></i>
			</button> 
			
			<button class="btn btn-danger" onclick="deleteCategory('<?php echo $category->id;?>');return false;" >
				<i class="icon-trash icon-white"></i>
			</button>
			
		<div style="display:none;" id="name-<?php echo $category->id;?>"><?php echo $category->name;?></div>
		<div style="display:none;" id="desc-<?php echo $category->id;?>"><?php echo $category->description;?></div>
		</td>
	</tr>
	<?php } ?>
		
	</table>


</div><!--/span--> 
