{include file="pageheader.htm"}
<div class="main-div">
  <form action="attribute.php"  method="post" name="theForm" onsubmit="return validate();">
  <table width="100%" id="general-table">
      <tr>
        <td class="label">{$lang.label_attr_name}</td>
        <td>
          <input type='text' name='attr_name' value="{$attr.attr_name}" size='30' />
          {$lang.require_field}
        </td>
      </tr>
      <tr>
        <td class="label">{$lang.label_cat_id}</td>
        <td>
          <select name="cat_id" onchange="onChangeGoodsType(this.value)">
          <option value="0">{$lang.select_please}</option>
            {$goods_type_list}
          </select> {$lang.require_field}
        </td>
      </tr>
      <tr id="attrGroups" style="display:none">
        <td class="label">{$lang.label_attr_group}</td>
        <td>
          <select name="attr_group">
          {if $attr_groups}
          {html_options options=$attr_groups selected=$attr.attr_group}
          {/if}
          </select>
        </td>
      </tr>
      <tr>
        <td class="label"><a href="javascript:showNotice('noticeAttrType');" title="{$lang.form_notice}"><img src="images/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}"></a>{$lang.label_attr_type}</td>
        <td>
          <input type="radio" name="attr_type" value="1" {if $attr.attr_type eq 1} checked="true" {/if} /> {$lang.attr_type_values[1]}
          <input type="radio" name="attr_type" value="2" {if $attr.attr_type eq 2} checked="true" {/if} /> {$lang.attr_type_values[2]}
          <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="noticeAttrType">{$lang.note_attr_type}</span>
        </td>
      </tr>
      <tr>
        <td class="label">{$lang.label_attr_input_type}</td>
        <td>
          <input type="radio" name="attr_input_type" value="0" {if $attr.attr_input_type eq 0} checked="true" {/if} onclick="radioClicked(0)"/>
          {$lang.text}
          <input type="radio" name="attr_input_type" value="1" {if $attr.attr_input_type eq 1} checked="true" {/if} onclick="radioClicked(1)"/>
          {$lang.select}
          <input type="radio" name="attr_input_type" value="2" {if $attr.attr_input_type eq 2} checked="true" {/if} onclick="radioClicked(0)"/>
          {$lang.text_area}
        </td>
      </tr>
      <tr>
        <td class="label">{$lang.label_attr_values}</td>
        <td>
          <textarea name="attr_values" cols="30" rows="5">{$attr.attr_values}</textarea>
        </td>
      </tr>
      <tr>
        <td colspan="2">
        <div class="button-div">
          <input type="submit" value="{$lang.button_submit}" class="button"/>
          <input type="reset" value="{$lang.button_reset}" class="button" />
        </div>
        </td>
      </tr>
      </table>
    <input type="hidden" name="act" value="{$form_act}" />
    <input type="hidden" name="attr_id" value="{$attr.attr_id}" />
  </form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="JavaScript">
<!--
onload = function()
{
{/literal}
  radioClicked({$attr.attr_input_type});
  onChangeGoodsType({$attr.cat_id});
  // 开始检查订单
  startCheckOrder();
{literal}
}

/**
 * 检查表单输入的数据
 */
function validate()
{
  var ele = document.forms['theForm'].elements;
  var msg = '';

  if (Utils.trim(ele['attr_name'].value) == '')
  {
    msg += name_not_null + '\n';
  }

  if (ele['cat_id'].value == 0)
  {
    msg += cat_id_not_null + '\n';
  }

  if (ele['attr_input_type'][1].checked && Utils.trim(ele['attr_values'].value) == '')
  {
    msg += values_not_null + '\n';
  }

  if (msg.length > 0)
  {
    alert(msg);
    return false;
  }
  else
  {
    return true;
  }
}

/**
 * 点击类型按钮时切换选项的禁用状态
 */
function radioClicked(n)
{
  document.forms['theForm'].elements["attr_values"].disabled = n > 0 ? false : true;
}

/**
 * 改变商品类型的处理函数
 */
function onChangeGoodsType(catId)
{
  Ajax.call('attribute.php?act=get_attr_groups&cat_id=' + catId, '', changeGoodsTypeResponse, 'GET', 'JSON');
}

function changeGoodsTypeResponse(res)
{
  if (res.error == 0)
  {
    var row = document.getElementById('attrGroups');
    if (res.content.length == 0) {
      row.style.display = 'none';
    } else {
      row.style.display = document.all ? 'block' : 'table-row';

      var sel = document.forms['theForm'].elements['attr_group'];

      sel.length = 0;

      for (var i = 0; i < res.content.length; i++)
      {
        var opt = document.createElement('OPTION');
        opt.value = i;
        opt.text = res.content[i];
        sel.options.add(opt);
        if (i == '{$attr.attr_group}')
        {
          opt.selected=true;
        }
      }
    }
  }

  if (res.message)
  {
    alert(res.message);
  }
}

//-->
</script>
{/literal}
{include file="pagefooter.htm"}
