<!-- $Id: goods_info.htm 8388 2007-04-27 10:47:16Z wj $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,selectzone.js"}

{if $warning}
<ul style="padding:0; margin: 0; list-style-type:none; color: #CC0000;">
  <li style="border: 1px solid #CC0000; background: #FFFFCC; padding: 10px; margin-bottom: 5px;" >{$warning}</li>
</ul>
{/if}

<!-- start goods form -->
<div class="tab-div">
    <!-- tab bar -->
    <div id="tabbar-div">
      <p>
        <span class="tab-front" id="general-tab">{$lang.tab_general}</span><span
        class="tab-back" id="detail-tab">{$lang.tab_detail}</span><span
        class="tab-back" id="mix-tab">{$lang.tab_mix}</span>{if $goods_type_list}<span
        class="tab-back" id="properties-tab">{$lang.tab_properties}</span>{/if}<span
        class="tab-back" id="gallery-tab">{$lang.tab_gallery}</span><span
        class="tab-back" id="linkgoods-tab">{$lang.tab_linkgoods}</span><span
        class="tab-back" id="groupgoods-tab">{$lang.tab_groupgoods}</span><span
        class="tab-back" id="article-tab">{$lang.tab_article}</span>
      </p>
    </div>

    <!-- tab body -->
    <div id="tabbody-div">
      <form enctype="multipart/form-data" action="" method="post" name="theForm" onsubmit="return validate();">
        <!-- 最大文件限制 -->
        <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
        <!-- 通用信息 -->
        <table width="90%" id="general-table" align="center">
          <tr>
            <td class="label">{$lang.lab_goods_name}</td>
            <td><input type="text" name="goods_name" value="{$goods.goods_name|escape}" size="40" />{$lang.require_field}</td>
          </tr>
          <tr>
            <td class="label">
            <a href="javascript:showNotice('noticeGoodsSN');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a> {$lang.lab_goods_sn} </td>
            <td><input type="text" name="goods_sn" value="{$goods.goods_sn|escape}" size="20" /><br />
            <span class="notice-span" id="noticeGoodsSN">{$lang.notice_goods_sn}</span></td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_goods_cat}</td>
            <td><select name="cat_id" onchange="changeCat(this)"><option value="0">{$lang.select_please}</option>{$cat_list}</select>{$lang.require_field}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_other_cat}</td>
            <td>
              <input type="button" value="{$lang.add}" onclick="addOtherCat(this.parentNode)" class="button" />
              {foreach from=$goods.other_cat item=cat_id}
              <select name="other_cat[]" onchange="checkIsLeaf(this)"><option value="0">{$lang.select_please}</option>{$other_cat_list.$cat_id}</select>
              {/foreach}
            </td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_goods_brand}</td>
            <td><select name="brand_id"><option value="0">{$lang.select_please}</caption>{html_options options=$brand_list selected=$goods.brand_id}</select></td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_shop_price}</td>
            <td><input type="text" name="shop_price" value="{$goods.shop_price}" size="20" onblur="priceSetted()"/>
            <input type="button" value="{$lang.compute_by_mp}" onclick="marketPriceSetted()" />
            {$lang.require_field}</td>
          </tr>
          {if $user_rank_list}
          <tr>
            <td class="label">{$lang.lab_user_price}</td>
            <td>
              {foreach from=$user_rank_list item=user_rank}
              {$user_rank.rank_name} <input type="text" id="rank_{$user_rank.rank_id}" name="user_price[]" value="{$member_price_list[$user_rank.rank_id]}" size="8" />
              <input type="hidden" name="user_rank[]" value="{$user_rank.rank_id}" />
              {/foreach}
            </td>
          </tr>
          {/if}
          <tr>
            <td class="label">{$lang.lab_market_price}</td>
            <td><input type="text" name="market_price" value="{$goods.market_price}" size="20" />
              <input type="button" value="{$lang.integral_market_price}" onclick="integral_market_price()" />
            </td>
          </tr>
          <tr>
            <td class="label"><a href="javascript:showNotice('noticPoints');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a> {$lang.lab_integral}</td>
            <td><input type="text" name="integral" value="{$goods.integral}" size="20" />
              <br /><span class="notice-span" id="noticPoints">{$lang.notice_integral}</span>
            </td>
          </tr>
          <tr>
            <td class="label"><label for="is_promote"><input type="checkbox" id="is_promote" name="is_promote" value="1" {if $goods.is_promote}checked="checked"{/if} onclick="handlePromote(this.checked);" /> {$lang.lab_promote_price}</label></td>
            <td id="promote_3"><input type="text" id="promote_1" name="promote_price" value="{$goods.promote_price}" size="20" /></td>
          </tr>
          <tr id="promote_4">
            <td class="label" id="promote_5">{$lang.lab_promote_date}</td>
            <td id="promote_6">{html_select_date prefix="promote_start_" end_year="+1" month_format="%m" field_order="YMD" time=$goods.promote_start} - {html_select_date prefix="promote_end_" end_year="+1" month_format="%m" field_order="YMD" time=$goods.promote_end}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_picture}</td>
            <td>
              <input type="file" name="goods_img" size="35" />
              {if $goods.goods_img}
                <a href="goods.php?act=show_image&img_url={$goods.goods_img}" target="_blank"><img src="images/yes.gif" border="0" /></a>
              {else}
                <img src="images/no.gif" />
              {/if}
            </td>
          </tr>
          <tr id="auto_thumb_1">
            <td class="label"> {$lang.lab_thumb}</td>
            <td id="auto_thumb_3">
              <input type="file" name="goods_thumb" size="35" />
              {if $goods.goods_thumb}
                <a href="goods.php?act=show_image&img_url={$goods.goods_thumb}" target="_blank"><img src="images/yes.gif" border="0" /></a>
              {else}
                <img src="images/no.gif" />
              {/if}{if $gd > 0}
              <br /><label for="auto_thumb"><input type="checkbox" id="auto_thumb" name="auto_thumb" checked="true" value="1" onclick="handleAutoThumb(this.checked)" />{$lang.auto_thumb}</label>{/if}
            </td>
          </tr>
        </table>

        <!-- 详细描述 -->
        <table width="90%" id="detail-table" style="display:none">
          <tr>
            <td>{$FCKeditor}</td>
          </tr>
        </table>

        <!-- 其他信息 -->
        <table width="90%" id="mix-table" style="display:none" align="center">
          <tr>
            <td class="label">{$lang.lab_goods_weight}</td>
            <td><input type="text" name="goods_weight" value="{$goods.goods_weight/$weight_unit}" size="20" /> <select name="weight_unit">{html_options options=$unit_list selected=$weight_unit}</select></td>
          </tr>
          {if $cfg.use_storage}
          <tr>
            <td class="label">{$lang.lab_goods_number}</td>
            <td><input type="text" name="goods_number" value="{$goods.goods_number}" size="20" /></td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_warn_number}</td>
            <td><input type="text" name="warn_number" value="{$goods.warn_number}" size="20" /></td>
          </tr>
          {/if}
          <tr>
            <td class="label">{$lang.lab_intro}</td>
            <td><input type="checkbox" name="is_best" value="1" {if $goods.is_best}checked="checked"{/if} />{$lang.is_best} <input type="checkbox" name="is_new" value="1" {if $goods.is_new}checked="checked"{/if} />{$lang.is_new} <input type="checkbox" name="is_hot" value="1" {if $goods.is_hot}checked="checked"{/if} />{$lang.is_hot}</td>
          </tr>
          <tr id="alone_sale_1">
            <td class="label" id="alone_sale_2">{$lang.lab_is_on_sale}</td>
            <td id="alone_sale_3"><input type="checkbox" name="is_on_sale" value="1" {if $goods.is_on_sale}checked="checked"{/if} /> {$lang.on_sale_desc}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_is_alone_sale}</td>
            <td><input type="checkbox" name="is_alone_sale" value="1" {if $goods.is_alone_sale}checked="checked"{/if} /> {$lang.alone_sale}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_can_handsel}</td>
            <td><input type="checkbox" name="can_handsel" value="1" {if $goods.can_handsel}checked="checked"{/if} /> {$lang.can_handsel}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_keywords}</td>
            <td><input type="text" name="keywords" value="{$goods.keywords|escape}" size="40" /> {$lang.notice_keywords}</td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_goods_brief}</td>
            <td><textarea name="goods_brief" cols="40" rows="3">{$goods.goods_brief|escape}</textarea></td>
          </tr>
          <tr>
            <td class="label">
            <a href="javascript:showNotice('noticeSellerNote');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a> {$lang.lab_seller_note} </td>
            <td><textarea name="seller_note" cols="40" rows="3">{$goods.seller_note}</textarea><br />
            <span class="notice-span" id="noticeSellerNote">{$lang.notice_seller_note}</span></td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_cycle_img}</td>
            <td>
              <input type="file" name="cycle_img" size="35" />
                {if $goods.cycle_img}
                <a href="goods.php?act=show_image&img_url={$goods.cycle_img}" target="_blank"><img id="cycle_yes" src="images/yes.gif" border="0" /></a>
                <a id="cycle_img_link" href="javascript:;" onclick="dropCycleImg('{$goods.goods_id}')"><strong>[-]</strong></a>
                <img id="cycle_no" src="images/no.gif" style="display:none" />
                {else}
                <img src="images/no.gif" />
                {/if}
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="text" name="cycle_img_url" value="{$goods.cycle_img}" size="40" /></td>
          </tr>
        </table>

        <!-- 属性与规格 -->
        {if $goods_type_list}
        <table width="90%" id="properties-table" style="display:none" align="center">
          <tr>
              <td class="label">{$lang.goods_type}</td>
              <td>
                <select name="goods_type" onchange="getAttrList({$goods.goods_id})">
                  {$goods_type_list}
                </select>
              </td>
          </tr>
          <tr>
            <td id="tbody-goodsAttr" colspan="2" style="padding:0">{$goods_attr_html}</td>
          </tr>
        </table>
        {/if}

        <!-- 商品相册 -->
        <table width="90%" id="gallery-table" style="display:none" align="center">
          <!-- 图片列表 -->
          <tr>
            <td>
              {foreach from=$img_list item=img key=i}
              <div id="gallery_{$img.img_id}" style="float:left; text-align:center; border: 1px solid #DADADA; margin: 4px; padding:2px;">
                <a href="javascript:;" onclick="if (confirm('{$lang.drop_img_confirm}')) dropImg('{$img.img_id}')">[-]</a><br />
                <a href="goods.php?act=show_image&img_url={$img.img_url}" target="_blank">
                <img src="../{if $img.thumb_url}{$img.thumb_url}{else}{$img.img_url}{/if}" {if $thumb_width neq 0}width="{$thumb_width}"{/if} {if $thumb_height neq 0}height="{$thumb_height}"{/if} border="0" />
                </a><br />
                <input type="text" value="{$img.img_desc|escape}" size="15" name="old_img_desc[{$img.img_id}]" />
              </div>
              {/foreach}
            </td>
          </tr>
          <tr><td>&nbsp;</td></tr>
          <!-- 上传图片 -->
          <tr>
            <td>
              <a href="javascript:;" onclick="addImg(this)">[+]</a>
              {$lang.img_desc} <input type="text" name="img_desc[]" size="20" />
              {$lang.img_url} <input type="file" name="img_url[]" />
            </td>
          </tr>
        </table>

        <!-- 关联商品 -->
        <table width="90%" id="linkgoods-table" style="display:none" align="center">
          <!-- 商品搜索 -->
          <tr>
            <td colspan="3">
              <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
              <select name="cat_id1"><option value="0">{$lang.all_category}</caption>{$cat_list}</select>
              <select name="brand_id1"><option value="0">{$lang.all_brand}</caption>{html_options options=$brand_list}</select>
              <input type="text" name="keyword1" />
              <input type="button" value="{$lang.button_search}"  class="button"
                onclick="searchGoods(sz1, 'cat_id1','brand_id1','keyword1')" />
            </td>
          </tr>
          <!-- 商品列表 -->
          <tr>
            <th>{$lang.all_goods}</th>
            <th>{$lang.handler}</th>
            <th>{$lang.link_goods}</th>
          </tr>
          <tr>
            <td width="42%">
              <select name="source_select1" size="20" style="width:100%" ondblclick="sz1.addItem(false, 'add_link_goods', goodsId, this.form.elements['is_single'][0].checked)" multiple="true">
              </select>
            </td>
            <td align="center">
              <p><input name="is_single" type="radio" value="1" checked="checked" />{$lang.single}<br /><input name="is_single" type="radio" value="0" />{$lang.double}</p>
              <p><input type="button" value=">>" onclick="sz1.addItem(true, 'add_link_goods', goodsId, this.form.elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value=">" onclick="sz1.addItem(false, 'add_link_goods', goodsId, this.form.elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value="<" onclick="sz1.dropItem(false, 'drop_link_goods', goodsId, elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value="<<" onclick="sz1.dropItem(true, 'drop_link_goods', goodsId, elements['is_single'][0].checked)" class="button" /></p>
            </td>
            <td width="42%">
              <select name="target_select1" size="20" style="width:100%" multiple ondblclick="sz1.dropItem(false, 'drop_link_goods', goodsId, elements['is_single'][0].checked)">
                {foreach from=$link_goods_list item=link_goods}
                <option value="{$link_goods.goods_id}">{$link_goods.goods_name}</option>
                {/foreach}
              </select>
            </td>
          </tr>
        </table>

        <!-- 配件 -->
        <table width="90%" id="groupgoods-table" style="display:none" align="center">
          <!-- 商品搜索 -->
          <tr>
            <td colspan="3">
              <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
              <select name="cat_id2"><option value="0">{$lang.all_category}</caption>{$cat_list}</select>
              <select name="brand_id2"><option value="0">{$lang.all_brand}</caption>{html_options options=$brand_list}</select>
              <input type="text" name="keyword2" />
              <input type="button" value="{$lang.button_search}" onclick="searchGoods(sz2, 'cat_id2', 'brand_id2', 'keyword2')" class="button" />
            </td>
          </tr>
          <!-- 商品列表 -->
          <tr>
            <th>{$lang.all_goods}</th>
            <th>{$lang.handler}</th>
            <th>{$lang.group_goods}</th>
          </tr>
          <tr>
            <td width="42%">
              <select name="source_select2" size="20" style="width:100%" onchange="sz2.priceObj.value = this.options[this.selectedIndex].id" ondblclick="sz2.addItem(false, 'add_group_goods', goodsId, this.form.elements['price2'].value)">
              </select>
            </td>
            <td align="center">
              <p>{$lang.price}<br /><input name="price2" type="text" size="6" /></p>
              <p><input type="button" value=">" onclick="sz2.addItem(false, 'add_group_goods', goodsId, this.form.elements['price2'].value)" class="button" /></p>
              <p><input type="button" value="<" onclick="sz2.dropItem(false, 'drop_group_goods', goodsId, elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value="<<" onclick="sz2.dropItem(true, 'drop_group_goods', goodsId, elements['is_single'][0].checked)" class="button" /></p>
            </td>
            <td width="42%">
              <select name="target_select2" size="20" style="width:100%" multiple ondblclick="sz2.dropItem(false, 'drop_group_goods', goodsId, elements['is_single'][0].checked)">
                {foreach from=$group_goods_list item=group_goods}
                <option value="{$group_goods.goods_id}">{$group_goods.goods_name}</option>
                {/foreach}
              </select>
            </td>
          </tr>
        </table>

        <!-- 关联文章 -->
        <table width="90%" id="article-table" style="display:none" align="center">
          <!-- 文章搜索 -->
          <tr>
            <td colspan="3">
              <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
              {$lang.article_title} <input type="text" name="article_title" />
              <input type="button" value="{$lang.button_search}" onclick="searchArticle()" class="button" />
            </td>
          </tr>
          <!-- 文章列表 -->
          <tr>
            <th>{$lang.all_article}</th>
            <th>{$lang.handler}</th>
            <th>{$lang.goods_article}</th>
          </tr>
          <tr>
            <td width="45%">
              <select name="source_select3" size="20" style="width:100%" multiple ondblclick="sz3.addItem(false, 'add_goods_article', goodsId, this.form.elements['price2'].value)">
              </select>
            </td>
            <td align="center">
              <p><input type="button" value=">>" onclick="sz3.addItem(true, 'add_goods_article', goodsId, this.form.elements['price2'].value)" class="button" /></p>
              <p><input type="button" value=">" onclick="sz3.addItem(false, 'add_goods_article', goodsId, this.form.elements['price2'].value)" class="button" /></p>
              <p><input type="button" value="<" onclick="sz3.dropItem(false, 'drop_goods_article', goodsId, elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value="<<" onclick="sz3.dropItem(true, 'drop_goods_article', goodsId, elements['is_single'][0].checked)" class="button" /></p>
            </td>
            <td width="45%">
              <select name="target_select3" size="20" style="width:100%" multiple ondblclick="sz3.dropItem(false, 'drop_goods_article', goodsId, elements['is_single'][0].checked)">
                {foreach from=$goods_article_list item=goods_article}
                <option value="{$goods_article.article_id}">{$goods_article.title}</option>
                {/foreach}
              </select>
            </td>
          </tr>
        </table>

        <div class="button-div">
          <input type="hidden" name="goods_id" value="{$goods.goods_id}" />
          <input type="submit" value="{$lang.button_submit}" class="button" />
          <input type="reset" value="{$lang.button_reset}" class="button" />
        </div>
        <input type="hidden" name="act" value="{$form_act}" />
      </form>
    </div>
</div>
<!-- end goods form -->
{insert_scripts files="validator.js,tab.js"}

<script language="JavaScript">
  var goodsId = '{$goods.goods_id}';
  var elements = document.forms['theForm'].elements;
  var sz1 = new SelectZone(1, elements['source_select1'], elements['target_select1']);
  var sz2 = new SelectZone(2, elements['source_select2'], elements['target_select2'], elements['price2']);
  var sz3 = new SelectZone(1, elements['source_select3'], elements['target_select3']);
  var marketPriceRate = {$cfg.market_price_rate|default:1};
  var integralPercent = {$cfg.integral_percent};

  {literal}
  onload = function()
  {
      handlePromote(document.forms['theForm'].elements['is_promote'].checked);

      if (document.forms['theForm'].elements['auto_thumb'])
      {
          handleAutoThumb(document.forms['theForm'].elements['auto_thumb'].checked);
      }

      // 检查新订单
      startCheckOrder();

      document.forms['theForm'].reset();
  }

  function validate()
  {
      var validator = new Validator('theForm');
      validator.required('goods_name', goods_name_not_null);
      if (document.forms['theForm'].elements['cat_id'].value == 0)
      {
          validator.addErrorMsg(goods_cat_not_null);
      }
      validator.required('shop_price', shop_price_not_null);
      validator.isNumber('shop_price', shop_price_not_number, true);
      validator.isNumber('market_price', market_price_not_number, false);
      if (document.forms['theForm'].elements['goods_number'] != undefined)
      {
          validator.isInt('goods_number', goods_number_not_int, false);
          validator.isInt('warn_number', warn_number_not_int, false);
      }
      return validator.passed();
  }

  function changeCat(selObj)
  {
      // 检查是否底级
      checkIsLeaf(selObj);
  }

  /**
   * 检查是否底级
   */
  function checkIsLeaf(selObj)
  {
      if (selObj.options.selectedIndex > 0 && selObj.options[selObj.options.selectedIndex].className != 'leafCat')
      {
          alert(goods_cat_not_leaf);
          selObj.options.selectedIndex = 0;
      }
  }

  /**
   * 切换商品类型
   */
  function getAttrList(goodsId)
  {
      var selGoodsType = document.forms['theForm'].elements['goods_type'];

      if (selGoodsType != undefined)
      {
          var goodsType = selGoodsType.options[selGoodsType.selectedIndex].value;

          Ajax.call('goods.php?is_ajax=1&act=get_attr', 'goods_id=' + goodsId + "&goods_type=" + goodsType, setAttrList, "GET", "JSON");
      }
  }

  function setAttrList(result, text_result)
  {
    document.getElementById('tbody-goodsAttr').innerHTML = result.content;
  }

  /**
   * 按比例计算价格
   * @param   string  inputName   输入框名称
   * @param   float   rate        比例
   * @param   string  priceName   价格输入框名称（如果没有，取shop_price）
   */
  function computePrice(inputName, rate, priceName)
  {
      var shopPrice = priceName == undefined ? document.forms['theForm'].elements['shop_price'].value : document.forms['theForm'].elements[priceName].value;
      shopPrice = Utils.trim(shopPrice) != '' ? parseFloat(shopPrice)* rate : 0;
      shopPrice += "";

      n = shopPrice.lastIndexOf(".");
      if (n > -1)
      {
          shopPrice = shopPrice.substr(0, n + 3);
      }

      if (document.forms['theForm'].elements[inputName] != undefined)
      {
          document.forms['theForm'].elements[inputName].value = shopPrice;
      }
      else
      {
          document.getElementById(inputName).value = shopPrice;
      }
  }

  /**
   * 设置了一个商品价格，改变市场价格、积分以及会员价格
   */
  function priceSetted()
  {
    computePrice('market_price', marketPriceRate);
    computePrice('integral', integralPercent / 100);
    {/literal}
    {foreach from=$user_rank_list item=user_rank}
    computePrice('rank_{$user_rank.rank_id}', {$user_rank.discount/100|default:1})
    {/foreach}
    {literal}
  }

  /**
   * 根据市场价格，计算并改变商店价格、积分以及会员价格
   */
  function marketPriceSetted()
  {
    computePrice('shop_price', 1/marketPriceRate, 'market_price');
    computePrice('integral', integralPercent / 100);
    {/literal}
    {foreach from=$user_rank_list item=user_rank}
    computePrice('rank_{$user_rank.rank_id}', {$user_rank.discount/100|default:1})
    {/foreach}
    {literal}
  }

  /**
   * 新增一个规格
   */
  function addSpec(obj)
  {
      var src   = obj.parentNode.parentNode;
      var idx   = rowindex(src);
      var tbl   = document.getElementById('attrTable');
      var row   = tbl.insertRow(idx + 1);
      var cell1 = row.insertCell(-1);
      var cell2 = row.insertCell(-1);
      var regx  = /<a([^>]+)<\/a>/i;

      cell1.className = 'label';
      cell1.innerHTML = src.childNodes[0].innerHTML.replace(/(.*)(addSpec)(.*)(\[)(\+)/i, "$1removeSpec$3$4-");
      cell2.innerHTML = src.childNodes[1].innerHTML.replace(/readOnly([^\s|>]*)/i, '');
  }

  /**
   * 删除规格值
   */
  function removeSpec(obj)
  {
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('attrTable');

      tbl.deleteRow(row);
  }

  /**
   * 处理规格
   */
  function handleSpec()
  {
      var elementCount = document.forms['theForm'].elements.length;
      for (var i = 0; i < elementCount; i++)
      {
          var element = document.forms['theForm'].elements[i];
          if (element.id.substr(0, 5) == 'spec_')
          {
              var optCount = element.options.length;
              var value = new Array(optCount);
              for (var j = 0; j < optCount; j++)
              {
                  value[j] = element.options[j].value;
              }

              var hiddenSpec = document.getElementById('hidden_' + element.id);
              hiddenSpec.value = value.join(String.fromCharCode(13)); // 用回车键隔开每个规格
          }
      }
      return true;
  }

  function handlePromote(checked)
  {
      document.forms['theForm'].elements['promote_price'].disabled = !checked;
      document.forms['theForm'].elements['promote_start_Year'].disabled = !checked;
      document.forms['theForm'].elements['promote_start_Month'].disabled = !checked;
      document.forms['theForm'].elements['promote_start_Day'].disabled = !checked;
      document.forms['theForm'].elements['promote_end_Year'].disabled = !checked;
      document.forms['theForm'].elements['promote_end_Month'].disabled = !checked;
      document.forms['theForm'].elements['promote_end_Day'].disabled = !checked;
  }

  function handleAutoThumb(checked)
  {
      document.forms['theForm'].elements['goods_thumb'].disabled = checked;
  }

  /**
   * 添加扩展分类
   */
  function addOtherCat(conObj)
  {
      var sel = document.createElement("SELECT");
      var selCat = document.forms['theForm'].elements['cat_id'];

      for (i = 0; i < selCat.length; i++)
      {
          var opt = document.createElement("OPTION");
          opt.text = selCat.options[i].text;
          opt.value = selCat.options[i].value;
          if (Browser.isIE)
          {
              sel.add(opt);
          }
          else
          {
              sel.appendChild(opt);
          }
      }
      conObj.appendChild(sel);
      sel.name = "other_cat[]";
      sel.onChange = function() {checkIsLeaf(this);};
  }

  /* 关联商品函数 */
  function searchGoods(szObject, catId, brandId, keyword)
  {
      var filters = new Object;

      filters.cat_id = elements[catId].value;
      filters.brand_id = elements[brandId].value;
      filters.keyword = Utils.trim(elements[keyword].value);
      filters.exclude = document.forms['theForm'].elements['goods_id'].value;

      szObject.loadOptions('get_goods_list', filters);
  }

  /**
   * 关联文章函数
   */
  function searchArticle()
  {
    var filters = new Object;

    filters.title = Utils.trim(elements['article_title'].value);

    sz3.loadOptions('get_article_list', filters);
  }

  /**
   * 新增一个图片
   */
  function addImg(obj)
  {
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  }

  /**
   * 删除图片上传
   */
  function removeImg(obj)
  {
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');

      tbl.deleteRow(row);
  }

  /**
   * 删除图片
   */
  function dropImg(imgId)
  {
    Ajax.call('goods.php?is_ajax=1&act=drop_image', "img_id="+imgId, dropImgResponse, "GET", "JSON");
  }

  function dropImgResponse(result)
  {
      if (result.error == 0)
      {
          document.getElementById('gallery_' + result.content).style.display = 'none';
      }
  }

  /**
   * 将市场价格取整
   */
  function integral_market_price()
  {
    document.forms['theForm'].elements['market_price'].value = parseInt(document.forms['theForm'].elements['market_price'].value);
  }

  /**
   * 删除图片文件
   * @param: int goodsId 商品id
   */
  function dropCycleImg(goodsId)
  {
    {/literal}if (confirm("{$lang.drop_img_confirm}")){literal}
    {
      Ajax.call('goods.php?is_ajax=1&act=drop_cycle_img&goods_id=' + goodsId, '', dropCycleImgResponse, "GET", "JSON");
    }
  }

  function dropCycleImgResponse(result)
  {
    if (result.error == 0)
    {
      document.getElementById('cycle_yes').style.display = 'none';
      document.getElementById('cycle_img_link').style.display = 'none';
      document.forms['theForm'].elements['cycle_img_url'].value = '';
      document.getElementById('cycle_no').style.display = '';
    }

    if (result.message.length > 0)
    {
        alert(result.message);
    }
  }
  {/literal}
</script>
{include file="pagefooter.htm"}