<!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='type519 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='SID519'> </span>&nbsp;&nbsp;&nbsp;编址:<span class='Addr519'> </span>&nbsp;&nbsp;&nbsp;数据端口:<span class='Port519'> </span></td></tr>
        <tr><td style='width: 200px;'>更新时间</td><td><span class='DateUpd519'> </span></td></tr>
        <tr><td style='width: 200px;'>监测项状态</td><td><span class='State519'> </span></td></tr>
		<tr>
			<td width='25%'>第1路:&nbsp;&nbsp;<span class='DO1519'></span></td>
			<td width='25%'>第2路:&nbsp;&nbsp;<span class='DO2519'></span></td>
		</tr>
		<tr>
			<td width='25%'>第3路:&nbsp;&nbsp;<span class='DO3519'></span></td>
			<td width='25%'>第4路:&nbsp;&nbsp;<span class='DO4519'></span></td>
		</tr>

    </table>
    <table width='100%' style='margin-top: 30px' class="ofBTN">
      <tr><td style='border: none'> <h1>单路控制</h1></td></tr>
      <tr><td style='width: 180px;'><span id='IFunc'>开关编号:</span> <select id="functions" style="width:80px" onchange="OnFuncChange()"></select></td>
				<td style='width: 25%;'> <a  href='javascript:SwRemoteCtrl(1)' id='SwRemoteCtrlon' class='gray'>打开</a></td>
				<td style='width: 25%;'><a href='javascript:SwRemoteCtrl(0)' id='SwRemoteCtrloff' class='gray'>关闭</a></td>
				
     	</tr>
    </table>
	<table width='100%' style='margin-top: 30px' class="ofBTN">
      <tr><td style='border: none'> <h1>总开关控制</h1></td></tr>
      <tr><td style='width: 25%;'> <a  href='javascript:SwRemoteCtrl(3)' id='SwRemoteCtrlon' class='gray'>全部打开</a></td>
		  <td style='width: 25%;'><a href='javascript:SwRemoteCtrl(2)' id='SwRemoteCtrloff' class='gray'>全部关闭</a></td>
				
     	</tr>
    </table>
    
    </td>
    </tr>
  </table>
    <a href='javascript:history.back()' class='back' style='color: #fff'>返回</a>
</div>
<script>
var itype=519;
var tescape= 5000,time;

<% db_Open("/NandFlash/tmp/dbDat0.db3"); %>
var sid=<% write(sid);%>;
var json=<% db_QryAdv("select * from tbElcSwLight 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="时控开关"+(n.Fld);
      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) {

      $(".SID519").html(n.SID);
      $(".Addr519").html(n.Addr);
      $(".Port519").html(n.Port % 256);
      $(".DateUpd519").html(n.DateUpd);
      //$(".State519").html(window.parent.parseState(n.State));
	  $(".State519").html(n.State?"正常":"告警");
      $(".DO1519").html(n.DO1?"开":"关");
      $(".DO2519").html(n.DO2?"开":"关");
      $(".DO3519").html(n.DO3?"开":"关");
      $(".DO4519").html(n.DO4?"开":"关");

    })
    $("span:contains('故障'),span:contains('告警'),span:contains('闭合'),span:contains('关闭')").addClass("red").removeClass("ger");
    $("span:contains('正常')").addClass("ger").removeClass("red");
  }
  
listFunctions();
function listFunctions()
{
	var stbl = "";

		for (var i=1; i<5; i++){
			stbl+=" <option value=\""+i+"\">"+i+"</option>";
		}
		$("#functions").html(stbl);
}
function OnFuncChange()
{
	var ifunc=$("#functions").val();//遥控命令号
}

function SwRemoteCtrl(state){
	var iReg=$("#functions").val();//开关编号
	
	if(state<=1)
	{
		//if(iReg>=1) iReg=iReg+2;//第一个开关地址为0x03
		if(iReg==1) iReg = 0x03;
		else if(iReg==2) iReg = 0x04;
		else if(iReg==3) iReg = 0x05;
		else if(iReg==4) iReg = 0x06;
			
	  var wParam = 0x060000 | (iReg & 0xffff); //[32:16]功能码，[15:0]寄存器地址
	  var lParam = (sid << 16) | (state & 0xFF);//[32:16]SID，[15:0]控制信息数据
	}
	else
	{
		if(state==2) //全关
		{
		  var wParam = 0x060000 | (0x01 & 0xffff); //[32:16]功能码，[15:0]寄存器地址
		  var lParam = (sid << 16) | (0x00 & 0xFF);//[32:16]SID，[15:0]控制信息数据
		}
		else if(state==3) //全开
		{
		  var wParam = 0x060000 | (0x02 & 0xffff); //[32:16]功能码，[15:0]寄存器地址
		  var lParam = (sid << 16) | (0x01 & 0xFF);//[32:16]SID，[15:0]控制信息数据
		}
	}
	
  $.ajax({
		type: "POST",
		url: "action/doctrl",
		data: "op="+wParam+"&value="+lParam+"",
		dataType: "json",
		success: function(msg){
			alert("ok!");
		}    
	});
    
    //alert("OK!!!");
}

</script>
</body>
</html>