<!DOCTYPE html>
<% language=javascript %>
<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 class='type517 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-elecsw.png" style="width: 80%;text-align: center;"></td>
    <td>
    <table width='100%'>
        <tr><td style='border: none'> <h1>配电开关监测</h1></td></tr>
        <tr><td style='width: 200px;'>基本信息</td><td>SID:<span class='SID517'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr517'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port517'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd517'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State517'> </span></td></tr>
	</table>
	
    <table width='100%' class='kttable'>
        <tr><td style='border: none'> <h1>监测量</h1></td></tr>
		<tr><td style='width: 20%;' id='adi1'>继电器1</td><td style='width: 80px;'><span class='DO1517'> </span></td>
            <td style='width: 20px;'><a  href='javascript:ktKaiguan(0,1)' id='kgkai1' ztop='1' zt='1'  class='gray' name="kgkai">闭合</a></td>
            <td ><a  href='javascript:ktKaiguan(0,0)' id='kgguan1' ztop='1' zt='0'  class='gray' name="kgguan">断开</a></td></tr>
		<tr><td style='width: 20%;' id='adi2'>继电器2</td><td style='width: 80px;'><span class='DO2517'> </span></td>
            <td style='width: 20px;'><a  href='javascript:ktKaiguan(1,1)' id='kgkai2' ztop='1' zt='1'  class='gray' name="kgkai">闭合</a></td>
            <td ><a  href='javascript:ktKaiguan(1,0)' id='kgguan2' ztop='1' zt='0'  class='gray' name="kgguan">断开</a></td></tr>
		<tr><td style='width: 20%;' id='adi3'>继电器3</td><td style='width: 80px;'><span class='DO3517'> </span></td>
            <td style='width: 20px;'><a  href='javascript:ktKaiguan(2,1)' id='kgkai3' ztop='1' zt='1'  class='gray' name="kgkai">闭合</a></td>
            <td ><a  href='javascript:ktKaiguan(2,0)' id='kgguan3' ztop='1' zt='0'  class='gray' name="kgguan">断开</a></td></tr>
		<tr><td style='width: 20%;' id='adi4'>继电器4</td><td style='width: 80px;'><span class='DO4517'> </span></td>
            <td style='width: 20px;'><a  href='javascript:ktKaiguan(3,1)' id='kgkai4' ztop='1' zt='1'  class='gray' name="kgkai">闭合</a></td>
            <td ><a  href='javascript:ktKaiguan(3,0)' id='kgguan4' ztop='1' zt='0'  class='gray' name="kgguan">断开</a></td></tr>
    </table>
    <table width='100%' class='kttable'>
        <tr><td style='border: none'> <h1>1键控制</h1></td></tr>
		<tr><td style='width: 20%;' id='adi1'>1键控制</td><td style='width: 80px;'></td>
            <td style='width: 20px;'><a  href='javascript:ktKaiguana(0,1)' id='kgkaia' ztop='1' zt='1'  class='gray' name="kgkai">1键闭合</a></td>
            <td ><a  href='javascript:ktKaiguana(0,0)' id='kgguana' ztop='1' zt='0'  class='gray' name="kgguan">1键断开</a></td></tr>
	</table>
    </td>
    </tr>
  </table>
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
</div>
<script>
var itype=517;
var tescape= 5000,time;

<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json=<% db_QryAdv("select * from tbElcSwRelay where SID="+sid,0); %>;
var jdefv=<% db_QryAdv("select Fld,ANote from tbSMDefVal where SID="+sid,0); %>;
<% db_Close(); %>
	
$(function(){
  time=setInterval(ajax,tescape)
  if(jdefv.reccnt>0){
    var snote="";
    $.each(jdefv.recs, function(i, n) {
		snote="";
      if(n.ANote!="")
	  { 
		  snote+=n.ANote;
		  $("#adi"+n.Fld).html(snote);
	  }

    });
  }
});

  function ajax() {
    $.ajax({
      type: "POST",
      url: "omdev/smdat0.asp",
      data: "itype=" + itype + "&sid=" + sid,
      dataType: "json",
      success: function(msg) {
        list3(msg);
      }
    });
  }
  list3(json);

  function list3(data) {
    $.each(data.recs, function(i, n) {
	$(".SID517").html(n.SID);
	$(".Addr517").html(n.Addr);
	$(".Port517").html(n.Port % 256);
	$(".DateUpd517").html(n.DateUpd);
	$(".State517").html(window.parent.parseState(n.State));
	$(".DO1517").html(n.DO1 ? "闭合" : "断开");
	$(".DO2517").html(n.DO2 ? "闭合" : "断开");
	$(".DO3517").html(n.DO3 ? "闭合" : "断开");
	$(".DO4517").html(n.DO4 ? "闭合" : "断开");
	if (n.DO1)
	{
		$("#kgkai1").attr("class","green");
		$("#kgguan1").attr("class","gray");
	}
	else{
		$("#kgkai1").attr("class","gray");
		$("#kgguan1").attr("class","redd");
	}
	if (n.DO2)
	{
		$("#kgkai2").attr("class","green");
		$("#kgguan2").attr("class","gray");
	}
	else{
		$("#kgkai2").attr("class","gray");
		$("#kgguan2").attr("class","redd");
	}
	if (n.DO3)
	{
		$("#kgkai3").attr("class","green");
		$("#kgguan3").attr("class","gray");
	}
	else{
		$("#kgkai3").attr("class","gray");
		$("#kgguan3").attr("class","redd");
	}
	if (n.DO4)
	{
		$("#kgkai4").attr("class","green");
		$("#kgguan4").attr("class","gray");
	}
	else{
		$("#kgkai4").attr("class","gray");
		$("#kgguan4").attr("class","redd");
	}
    })
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('已接入')").addClass("red").removeClass("ger");
    $("span:contains('正常'),span:contains('断开'),span:contains('未接入')").addClass("ger").removeClass("red");
  }
function ktKaiguan(idx, iv){
	if (iv){
		$("#kgkai"+(idx+1)).attr("class","green");
		$("#kgguan"+(idx+1)).attr("class","gray");
		iv = 0xff00;
	}
	else{
		$("#kgkai"+(idx+1)).attr("class","gray");
		$("#kgguan"+(idx+1)).attr("class","redd");
		iv = 0x0000;
    }
	ajaxBtnof(0x05, sid, idx, iv)
}

function ktKaiguana(idx, iv){
	if (iv){
		$("#kgkai1").attr("class","green");
		$("#kgguan1").attr("class","gray");
		$("#kgkai2").attr("class","green");
		$("#kgguan2").attr("class","gray");
		$("#kgkai3").attr("class","green");
		$("#kgguan3").attr("class","gray");
		$("#kgkai4").attr("class","green");
		$("#kgguan4").attr("class","gray");
		iv = 0x00ff;
	}
	else{
		$("#kgkai1").attr("class","gray");
		$("#kgguan1").attr("class","redd");
		$("#kgkai2").attr("class","gray");
		$("#kgguan2").attr("class","redd");
		$("#kgkai3").attr("class","gray");
		$("#kgguan3").attr("class","redd");
		$("#kgkai4").attr("class","gray");
		$("#kgguan4").attr("class","redd");
		iv = 0x0000;
    }
	ajaxBtnof(0x0f, sid, idx, iv)
}
function ajaxBtnof(ifunc, isid, wParam, lParam){
	wParam = (ifunc << 16) | (wParam & 0xFFFF);
	lParam = (isid << 16) | (lParam & 0xFFFF);
    $.ajax({
        type: "POST",
        url: "action/doctrl",
        data: "op="+wParam+"&value="+lParam+"",
        dataType: "json",
        success: function(msg){
            alert("消息发送成功!");
        },
		complete: function(msg){
            alert("消息发送成功!");
		}
    });
}
</script>
</body>
</html>