<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view(TPL_FOLDER."header");?>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" >
  <tr>
    <td width="3%" align="left" ><img src="{tpl_path}images/forward.jpg" /></td>
    <td width="97%" align="left" >您现在的位置：热门分类</td>
  </tr>
</table>
<div class="blockdiv" style="text-align:center">添加分类到当前热门分类 --> 拖动排序 --> 提交保存</div>
<form method="post" action="<?php echo site_url(CTL_FOLDER.'hot_cats/save_hot_cats');?>">
  <fieldset>
  <legend>当前热门分类(双击可从当前分类中删除，拖动可对分类进行排序)</legend>
  <div class="nav_box">
    <ul id="cnav">
      <?php foreach($hot_cats as $v){?>
      <li><?php echo $v['cat_name'];?>
        <input type="hidden" name="hot_cats[]" value="<?php echo $v['cat_name'].'|'.$v['cid'];?>" />
      </li>
      <?php }?>
    </ul>
  </div>
  <div class="clear"></div>
  <div style="text-align:center">
    <input type="button" onclick="submit_nav(this.form,this)" class="button-style" value="提交保存" />
  </div>
  </fieldset>
</form>
<fieldset>
<legend>添加热门分类</legend>
<form name="addForm">
<table width="100%"  border="0" cellpadding="3" cellspacing="0" >
  <tr>
    <td width="173"><font color="#FF0000">*</font>行业分类：</td>
    <td width="540"><select name="cid" dataType="Require" msg="该项必选">
        <?php foreach($catalog as $row) {?>
        <option value="<?php echo $row->cid;?>"><?php echo $row->cat_name;?>( <?php echo $row->cid;?> )</option>
        <?php }?>
      </select></td>
  </tr>
  <tr>
    <td width="173"><font color="#FF0000">*</font>分类：<br />不超过4个字</td>
    <td width="540"><input Name="cat_name" type="text" size="4" maxlength="4" dataType="Require" msg="该项必须填写"></td>
  </tr>
  <tr>
    <td width="173">&nbsp;</td>
    <td width="540"><input type="button" name="sbmit" onclick="submit_add_form()" value="添加到当前分类" class="button-style" style="width:100px" /></td>
  </tr>
</table>
</form>
</fieldset>
<fieldset>
<legend>出现在前台页面的位置</legend>
<img src="{tpl_path}images/help_hot_cats.jpg" width="650"  />
</fieldset>
<script language="javascript">
$(document).ready(function(){
	$("#cnav").sortable();
	$("#cnav li").dblclick(function(){
		$(this).remove();
	});
}); 

function submit_add_form()
{
	var theform = document.addForm;
	if( ! Validator.Validate(theform,3)) return ;
	var cat_name = theform.cat_name.value;
	cat_name = cat_name.replace(/\|/g,'');
	var cid = theform.cid.value;
	var str = cat_name+'|'+cid;
	if( ! checkr(str))
	{
		$('<li>'+cat_name+'<input type="hidden" name="hot_cats[]" value="'+str+'" /></li>').appendTo('#cnav');
	}
	else
	{
		alert('该分类已经存在，请勿重复添加');
	}
}

function submit_nav(f,e)
{
	if($("#cnav li").length == 0)
	{
		alert('至少添加一个热门分类');
	}
	else
	{
		if(confirm('确定要修改吗'))
		{
			e.value = '数据处理中..';
			e.disabled = true;
			f.submit();
		}
	}
}
function checkr(v)
{
	var f = false;
	$('#cnav input').each(function(){
		if($(this).val() == v)
		{
			f = true;
		}
	});
	return f;
}
</script>
<?php $this->load->view(TPL_FOLDER."footer");?>
