<!-- $Id: virtual_card_info.htm 7860 2007-04-03 11:04:59Z scottye $ -->
{include file="pageheader.htm"}

<script type="text/javascript" language="javascript" src="js/selectzone.js"></script>

<!-- 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="linkgoods-tab">{$lang.tab_linkgoods}</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();">
        <!-- 通用信息 -->
        <table width="90%" id="general-table">
          <tr>
            <td class="label">{$lang.lab_goods_name}</td>
            <td><input type="text" name="goods_name" value="{$goods.goods_name}" 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}" 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_shop_price}</td>
            <td><input type="text" name="shop_price" value="{$goods.shop_price}" size="20" onblur="priceSetted()"/>{$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" /></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}
                <img src="../{$goods.goods_img}" width="16" height="16" border="0" onmouseover="showImg('goods_img_layer', 'show')" onmouseout="showImg('goods_img_layer', 'hide')" />
                <div id="goods_img_layer" style="position:absolute; width:100px; height:100px; z-index:1; visibility:hidden" border="1">
                  <img src="../{$goods.goods_img}" border="0" />
                </div>
              {/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}
                <img src="../{$goods.goods_thumb}" width="16" height="16" border="0" onmouseover="showImg('goods_thumb_layer', 'show')" onmouseout="showImg('goods_thumb_layer', 'hide')" />
                <div id="goods_thumb_layer" style="position:absolute; width:100px; height:100px; z-index:1; visibility:hidden" border="1">
                  <img src="../{$goods.goods_thumb}" border="0" />
                </div>
              {/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">
          {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="10" disabled="disabled" /></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}" size="40" /></td>
          </tr>
          <tr>
            <td class="label">{$lang.lab_goods_brief}</td>
            <td><input type="text" name="goods_brief" value="{$goods.goods_brief}" size="50" /></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="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="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="sz2.addItem(false, 'add_goods_article', goodsId)">
              </select>
            </td>
            <td align="center">
              <p><input type="button" value=">>" onclick="sz2.addItem(true, 'add_goods_article', goodsId, this.form.elements['price2'].value)" class="button" /></p>
              <p><input type="button" value=">" onclick="sz2.addItem(false, 'add_goods_article', goodsId, this.form.elements['price2'].value)" class="button" /></p>
              <p><input type="button" value="<" onclick="sz2.dropItem(false, 'drop_goods_article', goodsId, elements['is_single'][0].checked)" class="button" /></p>
              <p><input type="button" value="<<" onclick="sz2.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="sz2.dropItem(false, 'drop_goods_article', goodsId)">
                {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 -->

<script language="JavaScript" src="js/validator.js"></script>
<script language="JavaScript" src="js/tab.js"></script>
<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(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();
  }

  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[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('properties-table');
      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('properties-table');

      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);
          }
      }
      sel.name = "other_cat[]";
      sel.onChange = function() {checkIsLeaf(this);};
      conObj.appendChild(sel);
  }

    /**
     * 显示隐藏图片
     * @param   id  div的id
     * @param   show | hide
     */
    function showImg(id, act)
    {
        if (act == 'show')
        {
            document.getElementById(id).style.visibility = 'visible';
        }
        else
        {
            document.getElementById(id).style.visibility = 'hidden';
        }
    }
  /* 关联商品函数 */
  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);

    sz2.loadOptions('get_article_list', filters);
  }
</script>
{/literal}
{include file="pagefooter.htm"}