<!-- $Id: shipping_area_info.htm 13551 2007-11-12 02:41:12Z arlicle $ -->
{include file="pageheader.htm"}
{insert_scripts files="validator.js,../js/transport.js,../js/region.js"}
<div class="main-div">
<form method="post" action="shipping_area.php" name="theForm" onsubmit="return validate()" style="background:#FFF">
<fieldset style="border:1px solid #DDEEF2">
  <table >
    <tr>
      <td class="label">{$lang.shipping_area_name}:</td>
<td><input type="text" name="shipping_area_name" maxlength="60" size="30" value="{$shipping_area.shipping_area_name}" />{$lang.require_field}</td>
    </tr>
{if $shipping_area.shipping_id != 3}
    {foreach from=$fields item=field}
    <tr>
      <td class="label">{$field.label}</td>
      <td><input type="text" name="{$field.name}" maxlength="60" size="20" value="{$field.value}" />{$lang.require_field}</td>
    </tr>
    {/foreach}
{/if}
  </table>
</fieldset>

<fieldset style="border:1px solid #DDEEF2">
  <legend style="background:#FFF">{$lang.shipping_area_regions}:</legend>
  <table style="width:600px" align="center">
  <tr>
    <td id="regionCell">
      {foreach from=$regions item=region key=id}
      <input type="checkbox" name="regions[]" value="{$id}" checked="true" /> {$region}&nbsp;&nbsp;
      {/foreach}
    </td>
  </tr>
  <tr>
    <td>
        <span  style="vertical-align: top">{$lang.label_country} </span>
        <select name="country" id="selCountries" onchange="region.changed(this, 1, 'selProvinces')" size="10" style="width:80px">
          {foreach from=$countries item=country}
          <option value="{$country.region_id}">{$country.region_name|escape:html}</option>
          {/foreach}
        </select>
        <span  style="vertical-align: top">{$lang.label_province} </span>
        <select name="province" id="selProvinces" onchange="region.changed(this, 2, 'selCities')" size="10" style="width:80px">
          <option value=''>{$lang.select_please}</option>
        </select>
        <span  style="vertical-align: top">{$lang.label_city} </span>
        <select name="city" id="selCities" onchange="region.changed(this, 3, 'selDistricts')" size="10" style="width:80px">
          <option value=''>{$lang.select_please}</option>
        </select>
        <span  style="vertical-align: top">{$lang.label_district}</span>
        <select name="district" id="selDistricts" size="10" style="width:130px">
          <option value=''>{$lang.select_please}</option>
        </select>
        <span  style="vertical-align: top"><input type="button" value="+" class="button" onclick="addRegion()" /></span>
    </td>
  </tr>
  </table >
</fieldset>

  <table >
  <tr>
    <td colspan="2" align="center">
      <input type="submit" value="{$lang.button_submit}" class="button" />
      <input type="reset" value="{$lang.button_reset}" class="button" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$shipping_area.shipping_area_id}" />
      <input type="hidden" name="shipping" value="{$shipping_area.shipping_id}" />
    </td>
  </tr>
</table>

</form>
</div>
<script language="JavaScript">
<!--
{literal}
region.isAdmin = true;
onload = function()
{
    document.forms['theForm'].elements['shipping_area_name'].focus();

    var selCountry = document.forms['theForm'].elements['country'];
    if (selCountry.selectedIndex <= 0)
    {
      selCountry.selectedIndex = 0;
    }
    
    region.loadProvinces(selCountry.options[selCountry.selectedIndex].value);

    // 开始检查订单
    startCheckOrder();
}

/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");

    validator.required('shipping_area_name', no_area_name);
    validator.isInt('free_money', invalid_free_mondy, true);
    return validator.passed();
}

/**
 * 添加一个区域
 */
function addRegion()
{
    var selCountry  = document.forms['theForm'].elements['country'];
    var selProvince = document.forms['theForm'].elements['province'];
    var selCity     = document.forms['theForm'].elements['city'];
    var selDistrict = document.forms['theForm'].elements['district'];
    var regionCell  = document.getElementById("regionCell");

    if (selDistrict.selectedIndex > 0)
    {
        regionId = selDistrict.options[selDistrict.selectedIndex].value;
        regionName = selDistrict.options[selDistrict.selectedIndex].text;
    }
    else
    {
        if (selCity.selectedIndex > 0)
        {
            regionId = selCity.options[selCity.selectedIndex].value;
            regionName = selCity.options[selCity.selectedIndex].text;
        }
        else
        {
            if (selProvince.selectedIndex > 0)
            {
                regionId = selProvince.options[selProvince.selectedIndex].value;
                regionName = selProvince.options[selProvince.selectedIndex].text;
            }
            else
            {
                if (selCountry.selectedIndex >= 0)
                {
                    regionId = selCountry.options[selCountry.selectedIndex].value;
                    regionName = selCountry.options[selCountry.selectedIndex].text;
                }
                else
                {
                    return;
                }
            }
        }
    }

    // 检查该地区是否已经存在
    exists = false;
    for (i = 0; i < document.forms['theForm'].elements.length; i++)
    {
      if (document.forms['theForm'].elements[i].type=="checkbox")
      {
        if (document.forms['theForm'].elements[i].value == regionId)
        {
          exists = true;
          alert(region_exists);
        }
      }
    }
    // 创建checkbox
    if (!exists)
    {
      regionCell.innerHTML += "<input type='checkbox' name='regions[]' value='" + regionId + "' checked='true' /> " + regionName + "&nbsp;&nbsp;";
    }
}
//-->
{/literal}
</script>
{include file="pagefooter.htm"}
