function addRegion()
{
    var sheng = $('#province').val();
    var shi = $('#city_id').val();
    var xian = $('#district').val();
    var areas  = document.getElementById("areas");
	var sheng_name = document.forms['myform'].elements['province'];
	var shi_name = document.forms['myform'].elements['city_id'];
	var xian_name = document.forms['myform'].elements['district'];
    if (xian > 0)
    {
        regionId = xian;
        regionName = xian_name.options[xian_name.selectedIndex].text;
    }
    else
    {
        if (shi > 0)
        {
            regionId = shi;
            regionName = shi_name.options[shi_name.selectedIndex].text;
        }
        else
        {
            if (sheng > 0)
            {
                regionId = sheng;
                regionName = sheng_name.options[sheng_name.selectedIndex].text;
            }
            else{return;}
        }
    }
    // 检查该地区是否已经存在
    exists = false;
    for (i = 0; i < document.forms['myform'].elements.length; i++)
    {
      if (document.forms['myform'].elements[i].type=="checkbox")
      {
        if (document.forms['myform'].elements[i].value == regionId)
        {
          exists = true;
		  $.showConfirm('选定的地区已经存在','','hc')
        }
      }
    }
    // 创建checkbox
    if (!exists)
    {
      areas.innerHTML += "<label class='checkbox-inline'><input type='checkbox' name='regions[]' value='" + regionId + "' checked='true' /> " + regionName + "</label>&nbsp;&nbsp;";
    }
}
function change(v){
	if(v==1){
		document.getElementById('type_s').className='hide_s';
		document.getElementById('type_s1').className='hide_s';
		document.getElementById('type_s2').className='hide_s';
		document.getElementById('type_z1').className='';
		document.getElementById('type_z2').className='';
		document.getElementById('type_z3').className='';
		document.getElementById('type_z4').className='';
	}else{
		document.getElementById('type_s').className='';
		document.getElementById('type_s1').className='';
		document.getElementById('type_s2').className='';
		document.getElementById('type_z1').className='hide_s';
		document.getElementById('type_z2').className='hide_s';
		document.getElementById('type_z3').className='hide_s';
		document.getElementById('type_z4').className='hide_s';
	}
}
/**
 * 切换编辑模式
 */
function model_change(type)
{
  //获取表单对象
  switch (type)
  {
    case '1': //代码模式
        document.getElementById('code_shipping_print').style.display = display_yes;
        document.getElementById('code_submit').style.display = display_yes;
        document.getElementById('visual').style.display = 'none';
    break;
    case '2': //所见即所得模式
        document.getElementById('code_shipping_print').style.display = 'none';
        document.getElementById('code_submit').style.display = 'none';
        document.getElementById('visual').style.display = display_yes;
    break;
  }
  return true;
}
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);
var display_yes = (Browser.isIE) ? 'block' : 'table-row-group';
/**
 * 保存
 */
function save()
{
  var the_form = this_obj("theForm");//获取表单对象
  if (typeof(the_form) == "undefined"){return false;} //程序错误  
  the_form.config_lable.value = call_flash('lable_Location_info', '');
  the_form.target = '_parent';
  the_form.act.value = 'do_edit_print_template';
  the_form.submit();
  return true;
}
/**
 * 与模板Flash编辑器通信
 */
function call_flash(type, currt_obj)
{
  var obj = this_obj("test");//获取flash对象
  switch (type)//执行操作
  {
    case 'lable_add': //插入标签
      if (typeof(currt_obj) != 'object'){return false;}
      if (currt_obj.value == '')
      {
		  $.showConfirm('没有选择要插入的标签','','hc');return false;
      }
      var result = obj.lable_add('t_' + currt_obj.value, currt_obj.options[currt_obj.selectedIndex].text, 150, 50, 20, 100, 'b_' + currt_obj.value);
      if (!result)
      {
		$.showConfirm('不能重复插入标签','','hc');return false;
      }
    break;
    case 'lable_del': //删除标签
      var result_del = obj.lable_del();
      if (result_del)
      {
		  return false;//alert("删除成功！");
      }
      else
      {
		  $.showConfirm('没有选择要删除的标签','','hc');return false;
      }
    break;
    case 'lable_Location_info': //获取标签位置信息
      var result_info = obj.lable_Location_info();
      return result_info;
    break;
  }return true;
}
/**
 * 获取页面Flash编辑器对象
 */
function this_obj(flash_name)
{
  var _obj;
  if (Browser.isIE)
  {
      _obj = window[flash_name];
  }
  else
  {
      _obj = document[flash_name];
  }
  if (typeof(_obj) == "undefined")
  {
    _obj = document[flash_name];
  }
  return _obj;
}
function addAdmin()
{
    var admin_id = $('#admin_id').val();
    var admin  = document.getElementById("admin");
    var admin_name = document.forms['myform'].elements['admin_id'];
    if (admin_id > 0)
    {
        adminId = admin_id;
        adminName = admin_name.options[admin_name.selectedIndex].text;
    }
    else
    {
        return;
    }
    // 检查该管理员是否已经存在
    exists = false;
    var admin =document.getElementById("admin");
    for (i = 0; i < admin.getElementsByTagName("input").length; i++)
    {
        if (admin.getElementsByTagName("input")[i].type=="checkbox")
        {
            if (admin.getElementsByTagName("input")[i].value == adminId)
            {
                exists = true;
                $.showConfirm('选定的管理员已经存在','','hc')
            }
        }
    }

    // 创建checkbox
    if (!exists)
    {
        admin.innerHTML += "<label class='checkbox-inline'><input type='checkbox' name='admin_id[]' value='" + adminId + "' checked='true' /> " + adminName + "</label>&nbsp;&nbsp;";
    }
}