<!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>
    <style>
        i{font-style:normal}
        .kaiguanTD td{text-align: center;}
    </style>

</head>
<body style="background: #F3F3F3">
<div class='type2312 empty' style=' margin: 10px;'>
  <table width="100%">
    <tr>
    <td width="300px" style="text-align: center;"><img src="img/ico-dio.png" style="width: 100%;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='SID2312'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr2312'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port2312'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd2312'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State2312'> </span></td></tr>
    </table>

    <h1 style='margin:10px 10px 10px 10px;'>输入状态</h1>
    <table width='100%' class="kaiguanTD">
        <tr> <td><h1>S0</h1></td> <td><h1>S1</h1></td> <td><h1>S2</h1></td> <td><h1>S3</h1></td> <td><h1>S4</h1></td> <td><h1>S5</h1></td> <td><h1>S6</h1></td> <td><h1>S7</h1></td></tr>
        <tr> <td><i class="D012312"></i></td> <td><i class="D022312"></i></td> <td><i class="D032312"></i></td>  <td><i class="D042312"></i></td> <td><i class="D052312"></i></td> <td><i class="D062312"></i></td> <td><i class="D072312"></i></td> <td><i class="D082312"></i></td></tr>
    </table>
<!--
    <h1 style='margin:10px 10px 10px 10px;'>继电器状态</h1>
    <table width='100%' class="kaiguanTD">
        <tr> <td><h1>继电器0</h1></td> <td><h1>继电器1</h1></td> <td><h1>继电器2</h1></td> <td><h1>继电器3</h1></td></tr>
        <tr> <td><i class="D092312"></i></td> <td><i class="D102312"></i></td> <td><i class="D112312"></i></td>  <td><i class="D122312"></i></td></tr>
    </table>
-->
    <table width="100%" class="ofBTN">
        <tbody>
			<tr><td style='border: none'> <h1>继电器控制</h1></td></tr>
			<tr><td style="width: 200px;">继电器0:</td> <td><a  href='javascript:void(0)' zt="1" op="jdc0Btn"  class='gray'>开</a> <a  style="margin-left: 10px;" href='javascript:void(0)' zt="0" op="jdc0Btn" class='gray'>关</a></td></tr>
			<tr><td style="width: 200px;">继电器1:</td> <td><a  href='javascript:void(0)' zt="1" op="jdc1Btn"  class='gray'>开</a> <a  style="margin-left: 10px;" href='javascript:void(0)' zt="0" op="jdc1Btn" class='gray'>关</a></td></tr>
			<tr><td style="width: 200px;">继电器2:</td> <td><a  href='javascript:void(0)' zt="1" op="jdc2Btn"  class='gray'>开</a> <a  style="margin-left: 10px;" href='javascript:void(0)' zt="0" op="jdc2Btn" class='gray'>关</a></td></tr>
			<!--<tr><td style="width: 200px;">继电器3:</td> <td><a  href='javascript:void(0)' zt="1" op="jdc3Btn"  class='gray'>开</a> <a  style="margin-left: 10px;" href='javascript:void(0)' zt="0" op="jdc3Btn" class='gray'>关</a></td></tr> -->
		</tbody>
	</table>
    </td>
    </tr>
  </table>
	
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
    </div>
<script>
var itype=2312;
var tescape=5000,time;

<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json=<% db_QryAdv("select * from tbDio where SID="+sid,0); %>;
<% db_Close(); %>
	
    $(function(){
        if (tescape>0)
        {
			RelayCtrlFunc();
            time=setInterval(ajax,tescape);
        }
    });
    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){
            $(".SID2312").html(n.SID);
            $(".Addr2312").html(n.Addr);
            $(".Port2312").html(n.Port%256);
            $(".DateUpd2312").html(n.DateUpd);
            $(".State2312").html(window.parent.parseState(n.State));

            $(".D012312").html(n.D01);
            $(".D022312").html(n.D02);
            $(".D032312").html(n.D03);
            $(".D042312").html(n.D04);
            $(".D052312").html(n.D05);
            $(".D062312").html(n.D06);
            $(".D072312").html(n.D07);
            $(".D082312").html(n.D08);
            //$(".D092312").html(n.D09);
            //$(".D102312").html(n.D10);
            //$(".D112312").html(n.D11);
            //$(".D122312").html(n.D12);
            //$(".D132312").html(n.D13);
            //$(".D142312").html(n.D14);
            //$(".D152312").html(n.D15);
            //$(".D162312").html(n.D16);

        });
        $("i:contains('1')").addClass("red").removeClass("ger");
        $("i:contains('0')").addClass("ger").removeClass("red");
        $("span:contains('故障'),span:contains('告警'),span:contains('闭合')").addClass("red").removeClass("ger");
        $("span:contains('正常')").addClass("ger").removeClass("red");
    }
	
	//继电器输出控制
	function RelayCtrlFunc()
	{    
		var arr=["green","redd"];
		//继电器0
		$("a[op=jdc0Btn]").live("click",function(){
			var i=$("a[op=jdc0Btn]").index(this);
			$("a[op=jdc0Btn]:eq("+i+")").attr("class",arr[i]).siblings().attr("class","gray");
			var q=$(this).attr("zt");
			ajaxBtnof(0,q)
		});
		//继电器1
		$("a[op=jdc1Btn]").live("click",function(){
			var i=$("a[op=jdc1Btn]").index(this);
			$("a[op=jdc1Btn]:eq("+i+")").attr("class",arr[i]).siblings().attr("class","gray");
			var q=$(this).attr("zt");
			ajaxBtnof(1,q)
		});
		//继电器2
		$("a[op=jdc2Btn]").live("click",function(){
			var i=$("a[op=jdc2Btn]").index(this);
			$("a[op=jdc2Btn]:eq("+i+")").attr("class",arr[i]).siblings().attr("class","gray");
			var q=$(this).attr("zt");
			ajaxBtnof(2,q)
		});
		//继电器3
		/*$("a[op=jdc3Btn]").live("click",function(){
			var i=$("a[op=jdc3Btn]").index(this);
			$("a[op=jdc3Btn]:eq("+i+")").attr("class",arr[i]).siblings().attr("class","gray");
			var q=$(this).attr("zt");
			ajaxBtnof(3,q)
		});*/
	}
	
	//继电器控制ajax请求函数
	//reg: 寄存器地址  
	//value: 设置的值
	function ajaxBtnof(wParam,lParam)
	{
		//wParam = 0x050000 | (wParam & 0xFFFF);
		lParam = (itype << 16) | (lParam & 0xFFFF)
		$.ajax({
			type: "POST",
			url: "action/doctrl",
			data: "op="+wParam+"&value="+lParam+"",
			dataType: "json",
			success: function(msg){
				alert("ok!");
			}
		});
	}
</script>
</body>
</html>