<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div class="module goods_list" id="goods_tags">
  <div class="caption"><span>{$lang.goods_tag}</span></div>
  <p class="top"><span></span></p>
  <div class="content">
    <form name="tagForm" action="javascript:;" onSubmit="return submitTag(this)" id="tagForm">
        <p id="ECS_TAGS" style="margin-bottom:5px; padding:0 10px;">
          <!-- 标记{foreach from=$tags item=tag}-->
          <a href="search.php?keywords={$tag.tag_words|escape:url}">{$tag.tag_words|escape:html}[{$tag.tag_count}]</a>
          <!-- 结束标记{/foreach} -->
        </p>
        <p style="margin-bottom:10px; padding:0 10px;">
          <input type="text" class="input_1" style="margin:0px; width:300px;" name="tag" id="tag" size="35" />
          <input type="submit" value="Append" class="button_2" style="border:none; position:relative; top:-0px!important;" />
          <input type="hidden" name="goods_id" value="{$goods.goods_id}"  />
        </p>
        <script type="text/javascript">
                //<![CDATA[
                {literal}
                /**
                 * 用户添加标记的处理函数
                 */
                function submitTag(frm)
                {
                  try
                  {
                    var tag = frm.elements['tag'].value;
                    var idx = frm.elements['goods_id'].value;

                    if (tag.length > 0 && parseInt(idx) > 0)
                    {
                      Ajax.call('user.php?act=add_tag', "id=" + idx + "&tag=" + tag, submitTagResponse, "POST", "JSON");
                    }
                  }
                  catch (e) { alert(e); }

                  return false;
                }

                function submitTagResponse(result)
                {
                  var div = document.getElementById('ECS_TAGS');

                  if (result.error > 0)
                  {
                    alert(result.message);
                  }
                  else
                  {
                    try
                    {
                      div.innerHTML = '';
                      var tags = result.content;

                      for (i = 0; i < tags.length; i++)
                      {
                        div.innerHTML += '<a href="search.php?keywords='+tags[i].word+'">' +tags[i].word + '[' + tags[i].count + ']<\/a>&nbsp;&nbsp; ';
                      }
                    }
                    catch (e) { alert(e); }
                  }
                }
                {/literal}
                //]]>
                </script>
      </form>
  </div>
  <p class="bottom"><span></span></p>
</div>