<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="GB2312">
  <title></title>
  <link href="css/style.css" title="style" rel="stylesheet" type="text/css" />
  <script src="js/jquery-1.6.3.min.js"></script>
</head>

<body style="background: #F3F3F3">
  <div>
    <div class="list2" style="margin: 10px;">
      <a class="you_p" href="#" style="color: #fff">网络设备</a>
    </div>
    <div class='list2' style='margin: 10px;'>
      <a id='anote' class='you_p' href='#' style='color: #fff'>网络IP设备编辑</a>&nbsp;&nbsp;<b><span id="anote2"></span></b>
    </div>
    <div class='setbase' style='border: #B0B7BF 1px solid'>
      <table width='100%'>
        <tr>
          <th width="15%"><span>监测项描述:</span></th>
          <th style='text-align: left'><input id="tname" value="" style="width:250px"></input></th>
          <th style='text-align: left'>如: xx视频(不能全为数字)</th>
        </tr>
        <tr style="display:none">
          <th><span>说 明:</span></th>
          <th style='text-align: left'><input id="tnote" value="" style="width:250px"></input></th>
          <th style='text-align: left'>帮助了解位置等</th>
        </tr>
        <tr>
          <th><span>IP地址:</span></th>
          <th style='text-align: left'><input id="tip" value="192.168.0.100" style="width:150px"></input></th>
          <th style='text-align: left'>设备IP地址</th>
        </tr>
        <tr>
          <th><span>端 口:</span></th>
          <th style='text-align: left'><input id="tport" value="" style="width:150px"></input></th>
          <th style='text-align: left'>设备端口</th>
        </tr>
        <tr>
          <th><span>登陆名:</span></th>
          <th style='text-align: left'><input id="tusr" value="" style="width:150px"></input></th>
          <th style='text-align: left'>设备登陆名(可选)</th>
        </tr>
        <tr>
          <th><span>密 码:</span></th>
          <th style='text-align: left'><input id="tpwd" value="" style="width:150px"></input></th>
          <th style='text-align: left'>同上</th>
        </tr>
        <tr style="display:none">
          <th><span>型 号:</span></th>
          <th style='text-align: left'><select id="lsType" style="width:350px"></select></th>
          <th style='text-align: left'>选择网络设备型号&nbsp;</h>
        </tr>
        <tr id="doorcontro" <!--style="display:none" -->><th><span>其 他:</span> </th>
          <th style='text-align: left'>串号:&nbsp;<input id="taddr" value="0"
              style="width:100px"></input>&nbsp;&nbsp;&nbsp;扩 展:&nbsp;<input id="text1" value="0"
              style="width:100px"></input>&nbsp;(扩展设置详见&nbsp;<a href="omdev-help.html"
              target="content">配置参考</a>)&nbsp;&nbsp;&nbsp;<input id="tdatam" type="checkbox" name="tdatam"
              value="1">采集数据</input></th>
          <th style='text-align: left'></th>
        </tr>
      </table>
    </div>
    <div id="setadv" style="display:none">
      <div class='list2' style='margin: 10px;'>
        <a class='you_p' href='#' style='color: #fff'>参数设置</a>
        <span>&nbsp;&nbsp;&nbsp;<input id="pdefault" type="checkbox" name="pdefault" value="1">保存为默认设置</input></span>
      </div>
      <div id='setparam' style='border: #B0B7BF 1px solid'>
        <table width='100%'>
          <tr>
            <th><span>温 度:</span></th>
            <th style='text-align: left'>
              <input value="20" style="width:100px"></input>&nbsp(最低允许温度)&nbsp;&nbsp;&nbsp;
              <input value="33" style="width:100px"></input>(最高允许温度)
            </th>
            <th>&nbsp;参考范围:20~33</th>
          </tr>
          <tr>
            <th><span>湿 度:</span></th>
            <th style='text-align: left'>
              <input value="20" style="width:100px"></input>&nbsp(最低允许湿度)&nbsp;&nbsp;&nbsp;
              <input value="33" style="width:100px"></input>(最高允许湿度)
            </th>
            <th>&nbsp;参考范围:46~80</th>
          </tr>
        </table>
      </div>
      <div class='list2' style='margin: 10px;'>
        <a class='you_p' href='#' style='color: #fff'>告警设置</a>
        <span>&nbsp;&nbsp;&nbsp;模板选择：
          <select id="lsAlm" style="width:150px" onchange="onAlmSel()">
            <option value="0">无(不告警)
            <option value="1">声光告警
            <option value="2">短信告警
            <option value="3">电话告警
            <option value="4">邮件告警
            <option value="5">声光+短信+电话告警
            <option value="6">自定义告警
          </select></span>
      </div>
      <div id='setalm' style='border: #B0B7BF 1px solid'>
        <table width='100%'>
          <tr>
            <th width="15%"><span>预警保持时间(s):</span></th>
            <th style='text-align: left'><input id="atimeon" value="5" style="width:100px"></input></th>
            <th style='text-align: left'>&nbsp;数值范围:0~9999</th>
          </tr>
          <tr>
            <th><span>重复告警间隔(s):</span></th>
            <th style='text-align: left'><input id="atimeredo" value="900" style="width:100px"></input></th>
            <th style='text-align: left'>&nbsp;数值范围:0~9999</th>
          </tr>
          <tr>
            <th><span>告警发送方式:</span></th>
            <th id="almonMode" style='text-align: left'>
              <input type="checkbox" name="almmask" value="1">声光</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="2">语音</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="4">短信</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="8">彩信</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="16">电话</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="32">邮件</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="256">联动1</input>&nbsp;&nbsp;
              <input type="checkbox" name="almmask" value="512">联动2</input>&nbsp;&nbsp;
            </th>
          </tr>
          <tr>
            <th><span>告警时段选择:</span></th>
            <th style='text-align: left'>
              <select id="lsAlmTime" style="width:150px">
                <option value="0">全时段
                <option value="1">工作时段
                <option value="2">周六周日
                <option value="3">自定义时段
              </select>
            </th>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <th><span>告警抓拍设置:</span></th>
            <th style='text-align: left'>
              <select id="lsAlmCam" style="width:250px">
                <option value="0">无
              </select>
            </th>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <th><span>告警短信内容:</span></th>
            <th style='text-align: left'>
              <textarea id="almsms" style='width: 400px'>短信内容</textarea>
            </th>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <th><span>告警电话内容:</span></th>
            <th style='text-align: left'>
              <textarea id="almtel" style='width: 400px'>电话内容</textarea>
            </th>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <th><span>告警解除方式:</span></th>
            <th id="almoffMode" style='text-align: left'>
              <input type="checkbox" name="offmask" value="1">声光</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="2">语音</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="4">短信</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="8">彩信</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="16">电话</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="32">邮件</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="256">联动1</input>&nbsp;&nbsp;
              <input type="checkbox" name="offmask" value="512">联动2</input>&nbsp;&nbsp;
            </th>
          </tr>
          <tr>
            <th><span>告警解除内容:</span></th>
            <th style='text-align: left'>
              <textarea id="almoff" style='width: 400px'>告警解除内容</textarea>
            </th>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <th><span>信息接收人:</span></th>
            <th id="lsRecv" style='text-align: left'>
              <input type="checkbox" name="arecv">管理员</input>&nbsp;&nbsp
              <input type="checkbox" name="arecv">用户1</input>&nbsp;&nbsp;
        </table>
      </div>
    </div>
  </div>
  <div>
    <table width='100%'>
      <tr>
        <th><a id='abtn' href='javascript:saveclick()' class='back' style='color: #fff;background: #ffa225'>保存</a></th>
        <th><a href='javascript:history.back()' class='back' style='color: #fff'>返回</a></th>
      </tr>
    </table>
  </div>

  <script>
    var isid =<% write(sid); %>;
    var itype =<% write(type); %>
var itag1 =<% write(tag1); %>

<% db_Open("/NandFlash/dbCfg.db3"); %>
var jtype =<% db_QryAdv("select Type,t.Kind,t.Name,t.Note,Tag1,Port,ASubSys,ExtDi,ExtSer,k.Name as KName from tbSMType t left join tbSMKind k on k.Kind=t.Kind where Port=6 order by Type,Tag1", 0); %>;
    var jsid =<% db_QryAdv("select * from tbSM where SID=" + sid, 0); %>;
    var jdef =<% db_QryAdv("select s.*,v.vmode as Dvmode,v.vref as Dvref,v.vref2 as Dvref2 from tbSMDef s left join tbSMDefVal v on (v.Type=s.Type and v.Fld=s.Fld and v.SID=" + sid + ") where s.Type=" + type + " and s.vmode>=0 order by FldDept,Fld", 0); %>;
    var idefv =<% write(db_QryInt("select count(*) from tbSMDefVal where Type=" + type + " and SID=" + sid, 1)); %>;
    var jcam =<% db_QryAdv("select s.SID,s.Name,t.Name as TName from tbSM s left join tbSMType t on t.Type=s.Type and t.Tag1=s.Tag1 where s.Type=3072 or s.Type=3073", 0); %>;
    var jalm =<% db_QryAdv("select * from tbAlm where AID<16", 0); %>;
    var jalmType =<% db_QryAdv("select * from tbAlm where AID=" + type, 0); %>;
    var jalmSid =<% db_QryAdv("select * from tbAlm where AID=" + (sid + 4096), 0); %>;
    var jrecv =<% db_QryAdv("select Name,Recv from tbUser where State=0 and Recv>0", 0); %>;
    var jalmTime =<% db_QryAdv("select TID, Note from tbAlmTime", 0); %>;
    var jDOInfo = <% db_QryAdv("select * from tbPort where Type=2",0); %>
<% db_Close(); %>

var aidSIDx = 0;



listAlmOnMode(jDOInfo);
function listAlmOnMode(data){
  var s="";
  var valtmp=256;
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"1\">声光</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"2\">语音</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"4\">短信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"8\">彩信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"16\">电话</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"almmask\" value=\"32\">邮件</input>&nbsp;&nbsp;\n";
   
   for(var i=1;i < data.reccnt;i++)
   {
   	if(i>1)
   		valtmp = valtmp * 2;
   	s+="  <input type=\"checkbox\" name=\"almmask\" value=\"";
   	s+=valtmp;
   	s+="\">联动";
   	s+=i;
   	s+="</input>&nbsp;&nbsp;\n";
   }
   s+="</th></tr>\n";
  
  $("#almonMode").html(s);
  console.log("almonMode="+s);
}

listAlmOffMode(jDOInfo);
function listAlmOffMode(data){
  var s="";
  var valtmp=256;
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"1\">声光</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"2\">语音</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"4\">短信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"8\">彩信</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"16\">电话</input>&nbsp;&nbsp;\n";
   s+="  <input type=\"checkbox\" name=\"offmask\" value=\"32\">邮件</input>&nbsp;&nbsp;\n";
   
   valtmp=256
   for(var i=1;i < data.reccnt;i++)
   {
   	if(i>1)
   		valtmp = valtmp * 2;
   	s+="<input type=\"checkbox\" name=\"offmask\" value=\"";
   	s+=valtmp;
   	s+="\">联动";
   	s+=i;
   	s+="</input>&nbsp;&nbsp;\n";
   }
   s+="</th></tr>\n";  
  $("#almoffMode").html(s);
  console.log("AlmOffMode="+s);
}


    listAlmTime();
    function listAlmTime() {
      if (jalmTime.reccnt == 0) return;
      var s = "";
      $.each(jalmTime.recs, function (i, n) {
        s += "<option value='" + n.TID + "'>" + n.Note;
      });
      $("#lsAlmTime").html(s);
    }

    listT();
    function listT() {
      if (jtype.reccnt == 0) return;
      var s = "";
      $.each(jtype.recs, function (i, n) {
        s += "<option value='" + n.Type + "'>" + n.KName + " (" + n.Name + ")&nbsp;&nbsp;&nbsp;" + n.Note;
      });
      $("#lsType").html(s);
      $("#lsType").val(itype);
    }

    listCam();
    function listCam() {
      if (jcam.reccnt == 0) return;
      var s = "<option value='0'>无";
      $.each(jcam.recs, function (i, n) {
        s += "<option value='" + n.SID;
        s += "'>" + n.Name + " (" + n.TName + ")</input>&nbsp;&nbsp;";
      });
      $("#lsAlmCam").html(s);
    }

    listRecv();
    function listRecv() {
      if (jrecv.reccnt == 0) return;
      var s = "";
      $.each(jrecv.recs, function (i, n) {
        s += "<input type='checkbox' name='arecv' value='" + n.Recv + "'>" + n.Name + "</input>&nbsp;&nbsp;";
      });
      $("#lsRecv").html(s);
    }

    listAlm();
    function listAlm() {
      if (jalm.reccnt == 0) return;
      var s = "";
      $.each(jalm.recs, function (i, n) {
        s += "<option value='" + n.AID + "'>" + n.Note;
        if (n.Note.indexOf("按类型") >= 0) aidType = n.AID;
        if (n.Note.indexOf("自定义") >= 0) aidSIDx = n.AID;
      });
      $("#lsAlm").html(s);
      if (jsid.reccnt > 0) {
        if (jsid.recs[0].AID < 16)
          $("#lsAlm").val(jsid.recs[0].AID);
        else {
          if (jsid.recs[0].AID == jsid.recs[0].Type)
            $("#lsAlm").val(aidType);
          else
            $("#lsAlm").val(aidSIDx);
        }
        onAlmSel();
      }
    }

    $(function () {
      if (isid == 0) {
        $("#anote").html("网络IP设备增加");
        $("#abtn").html("增加");
      }
      else if (jsid.reccnt > 0) {
        $("#anote2").html(jsid.recs[0].Name + " SID:" + isid + " 编址:" + jsid.recs[0].SerAddr);
        $("#tname").val(jsid.recs[0].Name);
        $("#tnote").val(jsid.recs[0].Note);
        $("#lsType").attr("disabled", "disabled");
        var strs;
        strs = jsid.recs[0].SerDef.split(":");
        if (strs.length > 0) $("#tip").val(strs[0]);
        if (strs.length > 1) $("#tport").val(strs[1]);
        if (strs.length > 2) $("#tusr").val(strs[2]);
        if (strs.length > 3) $("#tpwd").val(strs[3]);
        $("#taddr").val(jsid.recs[0].SerAddr);
        $("#text1").val(jsid.recs[0].Ext1);
        $("#tdatam").attr("value", jsid.recs[0].DataMode);
        if (jsid.recs[0].DataMode)
          $("#tdatam").prop("checked", true);
        else
          $("#tdatam").prop("checked", false);
        listParam();
      }
    });

    function isNumber(obj) {
      return typeof obj === 'number' && !isNaN(obj)
    }
    function listParam() {
      if (jdef.reccnt == 0) {
        $("#setparam").html("&nbsp;");
        //$("#setdetail").hide();
        return;
      }
      $("#setadv").show();
      $("#doorcontro").show();

      if (idefv == 0)
        $("#pdefault").prop("checked", true);
      else
        $("#pdefault").prop("checked", false);
      var stbl = "<table width='100%'>";
      var ichks = 0;
      //$.each(jdef.recs,function(i,n){
      for (var i = 0; i < jdef.reccnt; i++) {
        var n = jdef.recs[i];
        if (isNumber(n.Dvmode))
          n.vmode = n.Dvmode;
        if (isNumber(n.Dvref))
          n.vref = n.Dvref;
        if (isNumber(n.Dvref2))
          n.vref2 = n.Dvref2;
        var ivmode = n.vmode;
        if (n.Fld == 0) {
          if (ichks == 1) stbl += "</th></tr>";
          stbl += "<tr><th style='padding: 10px;background:#E5E9EC'>&nbsp</th><th style='padding: 10px;background:#E5E9EC'>" + n.Note + "</th><th style='padding: 10px;background:#E5E9EC'>&nbsp;</th></tr>";
          ichks = n.vkind;
          if (ichks == 1)
            stbl += "<tr><th>" + n.Note + "告警选择</th><th>";
        }
        else if (n.Note != '' && ivmode >= 0) {
          if (ichks == 1) {
            stbl += "<input id='pmode" + n.Fld + "' type='checkbox'";
            if (ivmode) stbl += " checked='true'";
            stbl += "/>" + n.Note + "&nbsp;&nbsp;&nbsp";
          }
          else {
            stbl += "<tr><th>" + n.Note + "</th><th style='text-align: left'>";
            stbl += "<select style='width:100px' id='pmode" + n.Fld + "'>"
            if (ivmode < 10) {
              stbl += "<option value='0'>不检测<option value='1'";
              if (ivmode == 1) stbl += " selected='true'"
              stbl += ">等于<option value='2'";
              if (ivmode == 2) stbl += " selected='true'"
              stbl += ">不等于<option value='3'";
              if (ivmode == 3) stbl += " selected='true'"
              stbl += ">大于<option value='4'";
              if (ivmode == 4) stbl += " selected='true'"
              stbl += ">小于";
            }
            else {
              stbl += "<option value='10'>不检测<option value='11'";
              if (ivmode == 11) stbl += " selected='true'"
              stbl += ">范围内<option value='12'";
              if (ivmode == 12) stbl += " selected='true'"
              stbl += ">范围外";
            }
            stbl += "</select>&nbsp;&nbsp;&nbsp;";
            if (ivmode < 10) {
              stbl += "<input id='pref" + n.Fld + "' value='" + (n.vref / n.vfactor) + "' style='width:100px'/>&nbsp;" + n.vtip;
            }
            else {
              stbl += "<input id='pref" + n.Fld + "' value='" + (n.vref / n.vfactor) + "' style='width:100px'/>&nbsp;~&nbsp;&nbsp;&nbsp;";
              stbl += "<input id='prefb" + n.Fld + "' value='" + (n.vref2 / n.vfactor) + "' style='width:100px'/>&nbsp;&nbsp;&nbsp;&nbsp;" + n.vtip;
            }
            stbl += "</th><th style ='text-align:left'>" + n.vtip2 + "</th></tr>";
          }
        }
      }
      //})
      if (ichks == 1) stbl += "</th><th></th></tr>";
      stbl += "</table>";
      $("#setparam").html(stbl);
    }

    function saveParam() {
      if (jdef.reccnt == 0) return;
      var idefault = 0;
      if ($("#pdefault").attr("checked") == "checked")
        idefault = 1;
      else {
        $.ajax({
          type: "POST",
          url: "omdev/smdef.asp",
          data: "op=chkx&type=" + itype + "&sid=" + isid,
          async: false,
          dataType: "json",
          success: function (msg) {
            if (msg.op != "ok")
              alert("准备自定义参数失败!");
          }
        });
      }
      var ichks = 0;
      var pmode;
      $.each(jdef.recs, function (i, n) {
        if (n.Fld == 0) {
          ichks = n.vkind;
        }
        else if (n.Note != '' && n.vmode >= 0) {
          pmode = $("#pmode" + n.Fld);
          var imode = pmode.val();
          var iref = 0;
          var iref2 = 0;
          if (ichks == 1) {
            if (pmode.prop("checked")) imode = 1; else imode = 0;
            iref = n.vref;
            iref2 = n.vref2;
          }
          else
            iref = parseInt(parseFloat($("#pref" + n.Fld).attr("value")) * n.vfactor);
          if (imode >= 10)
            iref2 = parseInt(parseFloat($("#prefb" + n.Fld).attr("value")) * n.vfactor);
          if (imode != n.vmode || iref != n.vref || iref2 != n.vref2) {
            var sop = "updd";
            var spost = "";
            spost += "&sid=" + isid;
            if (idefault) {
              spost += "&setval=vmode=" + imode;
              if (ichks == 0) {
                spost += ",vref=" + iref;
                spost += ",vref2=" + iref2;
              }
            }
            else {
              sop = "updx";
              spost += "&setval=" + itype + "," + isid + "," + n.Fld + "," + imode;
              if (ichks == 0)
                spost += "," + iref + "," + iref2;
              else
                spost += ",'',''";
              spost += ",0,''";
            }
            $.ajax({
              type: "POST",
              url: "omdev/smdef.asp",
              data: "op=" + sop + "&type=" + itype + "&fld=" + n.Fld + spost,
              async: false,
              dataType: "json",
              success: function (msg) {
                if (msg.op != "ok")
                  alert("保存 " + n.Note + " 失败!");
              }
            });
          }
        }
      });
    }

    function onAlmSel() {
      var idx = $('#lsAlm').prop('selectedIndex');
      var alm = jalm.recs[idx];
      if (alm.AID == aidType) {
        if (jalmType.reccnt > 0) showAlm(jalmType.recs[0]);
      }
      else if (alm.AID == aidSIDx) {
        if (jalmSid.reccnt > 0) showAlm(jalmSid.recs[0]);
      }
      else
        showAlm(alm);
    }

    function showAlm(alm) {
      $("#atimeon").val(alm.TimeOn);
      $("#atimeredo").val(alm.TimeRedo);
      showAlmMask(alm.AlmMask);
      $("#lsAlmTime").val(alm.AlmTid);
      $("#lsAlmCam").val(alm.AlmCam);
      $("#almsms").val(alm.AlmSms);
      $("#almtel").val(alm.AlmTel);
      showOffMask(alm.AlmOffMask);
      $("#almoff").val(alm.AlmOff);
      showRecv(alm.AlmRecv);
    }
    function showAlmMask(imask) {
      $("input[name='almmask']").each(function () {
        var iv = parseInt(this.value);
        if (iv & imask)
          $(this).attr("checked", true);
        else
          $(this).attr("checked", false);
      });
    }
    function showOffMask(imask) {
      $("input[name='offmask']").each(function () {
        var iv = parseInt(this.value);
        if (iv & imask)
          $(this).attr("checked", true);
        else
          $(this).attr("checked", false);
      });
    }
    function showRecv(irecv) {
      $("input[name='arecv']").each(function () {
        var iv = parseInt(this.value);
        if (irecv & (1 << (iv - 1)))
          $(this).attr("checked", true);
        else
          $(this).attr("checked", false);
      });
    }

    function saveAlm() {
      var spost = "&setval=";
      spost += "TimeOn=" + $("#atimeon").attr("value");
      spost += ",TimeRedo=" + $("#atimeredo").attr("value");
      spost += ",AlmMask=" + getAlmMask();
      spost += ",AlmTid=" + $("#lsAlmTime").val();
      spost += ",AlmCam=" + $("#lsAlmCam").val();
      spost += ",AlmSms='" + $("#almsms").attr("value");
      spost += "',AlmTel='" + $("#almtel").attr("value");
      spost += "',AlmOffMask=" + getOffMask();
      spost += ",AlmOff='" + $("#almoff").attr("value");
      spost += "',AlmRecv=" + getRecv();
      var idx = $('#lsAlm').prop('selectedIndex');
      var alm = jalm.recs[idx];
      var iaid = alm.AID;
      if (alm.AID == aidSIDx) {
        iaid = isid + 0x1000;
        spost += ",Note='" + $("#tname").attr("value") + " 告警'";
      }
      else if (alm.AID == aidType) {
        iaid = itype;
        idx = $('#lsType').prop('selectedIndex');
        spost += ",Note='" + jtype.recs[idx].KName + " 告警'";
      }

      $.ajax({
        type: "POST",
        url: "omdev/almx.asp",
        data: "op=upd&aid=" + iaid + "&sid=" + isid + spost,
        dataType: "json",
        success: function (msg) {
          if (msg.op == "ok")
            history.go(-1);
        }
      });
    }
    function getAlmMask() {
      var iv = 0;
      $("input[name='almmask']:checked").each(function () {
        iv += parseInt(this.value);
      });
      return iv;
    }
    function getOffMask() {
      var iv = 0;
      $("input[name='offmask']:checked").each(function () {
        iv += parseInt(this.value);
      });
      return iv;
    }
    function getRecv() {
      var iv = 0;
      $("input[name='arecv']:checked").each(function () {
        iv |= (1 << (parseInt(this.value) - 1));
      });
      return iv;
    }

    function saveclick() {

      var sname = "";
      sname = $("#tname").attr("value");
      if (!isNaN(sname)) {
        alert("错误: 监测项描述不能全为数字,请重新输入!");
        return;
      }
      var sip = "";
      sip = $("#tip").attr("value");
      var sport = "";
      sport = $("#tport").attr("value");
      if (sname == "" || sip == "" || sport == "") {
        alert("错误: 输入不完整,请重新输入!");
        return;
      }
      saveParam();

      var susr = ":";
      susr += $("#tusr").attr("value") + ":" + $("#tpwd").attr("value");
      if (susr == "::") susr = "";
      var spost = "";
      if (isid == 0) {
        var idx = $('#lsType').prop('selectedIndex');
        var sv = $("#taddr").attr("value");
        if (sv == "") sv = "0";
        var smtype = jtype.recs[idx];
        //null,kind,type,'name','',0,tag1,0,1,'',serK,serT,serD,serA,0,0,0,ASubSys,0,0,ext1,0
        var iv = parseInt($("#lsType").val());
        spost += "&insval=null," + (iv - (iv % 256));
        spost += "," + iv;
        spost += ",'" + sname;
        spost += "','" + $("#tnote").attr("value");
        spost += "',0," + itag1 + ",0,";
        if ($("#tdatam").attr("checked") == "checked")
          spost += "1";
        else
          spost += "0";
        spost += ",''," + 0x200000;
        spost += "," + (0x200000 + parseInt(sport));
        spost += ",'" + sip + ":" + sport + susr;
        spost += "'," + sv;
        spost += ",0,0,0," + smtype.ASubSys + ",0,0,0,0";
        $.ajax({
          type: "POST",
          url: "omdev/smx.asp",
          data: "op=ins&sid=0&addr=0&type=" + iv + "&name=" + sname + spost,
          dataType: "json",
          success: function (msg) {
            if (msg.op == "ok")
            location.href='C0-6.asp'
            
          }
        });
        return;
      }
      spost += "&sid=" + isid;
      //spost+="&name="+$("#tname").attr("value");
      //spost+="&note="+$("#tnote").attr("value");
      //spost+="&ser="+ser;
      //spost+="&type="+$("#lsType").val();
      spost += "&name=";
      var idx = $('#lsType').prop('selectedIndex');
      var smtype = jtype.recs[idx];
      if (smtype.ExtDi > 0 || smtype.ExtSer > 0 && sname != jsid.recs[0].Name)
        spost += sname;
      spost += "&setval=Name='" + sname;
      spost += "',Note='" + $("#tnote").attr("value");
      spost += "',SerDef='" + sip + ":" + sport + susr;
      spost += "',SerType=" + (0x200000 + parseInt(sport));
      var sv = $("#taddr").attr("value");
      if (sv == "") sv = "0";
      spost += ",SerAddr=" + sv;
      spost += ",Type=" + $("#lsType").val();
      sv = $("#text1").attr("value");
      if (sv == "") sv = "0";
      spost += ",Ext1=" + sv;
      iv = $("#tdatam").attr("value");
      sv = $("#tdatam").attr("checked");
      if (iv == 1 && sv != "checked")
        spost += ",DataMode=0";
      if (iv == 0 && sv == "checked")
        spost += ",DataMode=1";
      $.ajax({
        type: "POST",
        url: "omdev/smx.asp",
        data: "op=upd" + spost,
        dataType: "json",
        success: function (msg) {
          if (msg.op == "ok")
            saveAlm(); //history.back();
          else
            alert("保存数据 编号" + itype + "-" + itag + " 失败!");
        }
      });
    }
  </script>
</body>

</html>