<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php $this->load->view(TPL_FOLDER."header");?>
<script type="text/javascript" src="{root_path}js/jquery/jquery.colorPicker-1.0.1.js"></script>
<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_keyword/save_hot_keyword');?>">
  <fieldset>
  <legend>当前热门关键词(双击可从当前关键词中删除，拖动可对关键词进行排序)</legend>
  <div class="nav_box">
    <ul id="cnav">
      <?php foreach($hot_keyword as $v){?>
      <li><?php echo $v['title'];?>
        <input type="hidden" name="hot_keyword[]" value="<?php echo $v['title'].'|'.$v['title_color'].'|'.$v['sword'].'|'.$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 str_repeat("&nbsp;&nbsp;&nbsp;",$row->deep_id).$row->cat_name;?>( <?php echo $row->cid;?> )</option>
        <?php }?>
      </select></td>
  </tr>
  <tr>
    <td width="173"><font color="#FF0000">*</font>关键词：</td>
    <td width="540"><input Name="title" type="text" size="15" dataType="Require" msg="该项必须填写" maxlength="50">
      &nbsp;
      <input type="hidden" name="title_color" id="title_color" />
      <img style="cursor:pointer" src="{tpl_path}images/color.gif"  align="absmiddle" onclick="$(this).colorPicker({ setValue:'input[name=title_color]' ,setBackground:true })" alt="关键词颜色" /> </td>
  </tr>
  <tr>
    <td width="173"><font color="#FF0000">*</font>搜索关键词：<br />
      用于搜索匹配 不会显示出来</td>
    <td width="540"><input type="text" name="sword" maxlength="50" size="15" 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_keyword.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 title = theform.title.value;
	title = title.replace(/\|/g,'');
	var title_color = theform.title_color.value;
	var sword = theform.sword.value;
	sword = sword.replace(/\|/g,'');
	var cid = theform.cid.value;
	var str = title+'|'+title_color+'|'+sword+'|'+cid;
	if( ! checkr(str))
	{
		$('<li>'+title+'<input type="hidden" name="hot_keyword[]" 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");?>
