<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-nested" prefix="nested" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>

<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="dwr/interface/serverElectricPower.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>

<html:form action="measurementGroupElectricPower" target="info">

<table class="data">
 <thead>
  <tr class="thead">
   <td id="itemName"><bean:message key="text.itemName"/></td>
   <td id="setupValue"><bean:message key="text.setupValue"/></td>
  </tr>
 </thead>
 <tbody>
  <tr class="row1">
   <td nowrap>
     <bean:message key="text.period"/>
     <bean:message key="text.scope.range" arg0="5" arg1="24" />
   </td>
   <td nowrap>
    <span id="periodHour_input">
     <html:select name="SupportElectricPowerForm" property="periodHour" onchange="changeTest(this)">
      <html:option value="00">00</html:option>
      <html:option value="01">01</html:option>
      <html:option value="02">02</html:option>
      <html:option value="03">03</html:option>
      <html:option value="04">04</html:option>
      <html:option value="05">05</html:option>
      <html:option value="06">06</html:option>
      <html:option value="07">07</html:option>
      <html:option value="08">08</html:option>
      <html:option value="09">09</html:option>
      <html:option value="10">10</html:option>
      <html:option value="11">11</html:option>
      <html:option value="12">12</html:option>
      <html:option value="13">13</html:option>
      <html:option value="14">14</html:option>
      <html:option value="15">15</html:option>
      <html:option value="16">16</html:option>
      <html:option value="17">17</html:option>
      <html:option value="18">18</html:option>
      <html:option value="19">19</html:option>
      <html:option value="20">20</html:option>
      <html:option value="21">21</html:option>
      <html:option value="22">22</html:option>
      <html:option value="23">23</html:option>
      <html:option value="24">24</html:option>
     </html:select>
     <bean:message key="text.hour"/>
    </span>
     
    <span id="periodMinute_input">
     <html:select name="SupportElectricPowerForm" property="periodMinute">
      <html:option value="00">00</html:option>
      <html:option value="01">01</html:option>
      <html:option value="02">02</html:option>
      <html:option value="03">03</html:option>
      <html:option value="04">04</html:option>
      <html:option value="05">05</html:option>
      <html:option value="06">06</html:option>
      <html:option value="07">07</html:option>
      <html:option value="08">08</html:option>
      <html:option value="09">09</html:option>
      <html:option value="10">10</html:option>
      <html:option value="11">11</html:option>
      <html:option value="12">12</html:option>
      <html:option value="13">13</html:option>
      <html:option value="14">14</html:option>
      <html:option value="15">15</html:option>
      <html:option value="16">16</html:option>
      <html:option value="17">17</html:option>
      <html:option value="18">18</html:option>
      <html:option value="19">19</html:option>
      <html:option value="20">20</html:option>
      <html:option value="21">21</html:option>
      <html:option value="22">22</html:option>
      <html:option value="23">23</html:option>
      <html:option value="24">24</html:option>
      <html:option value="25">25</html:option>
      <html:option value="26">26</html:option>
      <html:option value="27">27</html:option>
      <html:option value="28">28</html:option>
      <html:option value="29">29</html:option>
      <html:option value="30">30</html:option>
      <html:option value="31">31</html:option>
      <html:option value="32">32</html:option>
      <html:option value="33">33</html:option>
      <html:option value="34">34</html:option>
      <html:option value="35">35</html:option>
      <html:option value="36">36</html:option>
      <html:option value="37">37</html:option>
      <html:option value="38">38</html:option>
      <html:option value="39">39</html:option>
      <html:option value="40">40</html:option>
      <html:option value="41">41</html:option>
      <html:option value="42">42</html:option>
      <html:option value="43">43</html:option>
      <html:option value="44">44</html:option>
      <html:option value="45">45</html:option>
      <html:option value="46">46</html:option>
      <html:option value="47">47</html:option>
      <html:option value="48">48</html:option>
      <html:option value="49">49</html:option>
      <html:option value="50">50</html:option>
      <html:option value="51">51</html:option>
      <html:option value="52">52</html:option>
      <html:option value="53">53</html:option>
      <html:option value="54">54</html:option>
      <html:option value="55">55</html:option>
      <html:option value="56">56</html:option>
      <html:option value="57">57</html:option>
      <html:option value="58">58</html:option>
      <html:option value="59">59</html:option>
     </html:select>
    </span>
    <bean:message key="text.minute"/>
   </td>
  </tr>
  <tr class="row2">
   <td nowrap>
     <bean:message key="text.measurementInterval"/>
     <bean:message key="text.seconds.range" arg0="5" arg1="60" />
   </td>
   <td nowrap>
    <span id="interval_input">
     <html:select name="SupportElectricPowerForm" property="interval">
      <html:option value="05">05</html:option>
      <html:option value="06">06</html:option>
      <html:option value="07">07</html:option>
      <html:option value="08">08</html:option>
      <html:option value="09">09</html:option>
      <html:option value="10">10</html:option>
      <html:option value="11">11</html:option>
      <html:option value="12">12</html:option>
      <html:option value="13">13</html:option>
      <html:option value="14">14</html:option>
      <html:option value="15">15</html:option>
      <html:option value="16">16</html:option>
      <html:option value="17">17</html:option>
      <html:option value="18">18</html:option>
      <html:option value="19">19</html:option>
      <html:option value="20">20</html:option>
      <html:option value="21">21</html:option>
      <html:option value="22">22</html:option>
      <html:option value="23">23</html:option>
      <html:option value="24">24</html:option>
      <html:option value="25">25</html:option>
      <html:option value="26">26</html:option>
      <html:option value="27">27</html:option>
      <html:option value="28">28</html:option>
      <html:option value="29">29</html:option>
      <html:option value="30">30</html:option>
      <html:option value="31">31</html:option>
      <html:option value="32">32</html:option>
      <html:option value="33">33</html:option>
      <html:option value="34">34</html:option>
      <html:option value="35">35</html:option>
      <html:option value="36">36</html:option>
      <html:option value="37">37</html:option>
      <html:option value="38">38</html:option>
      <html:option value="39">39</html:option>
      <html:option value="40">40</html:option>
      <html:option value="41">41</html:option>
      <html:option value="42">42</html:option>
      <html:option value="43">43</html:option>
      <html:option value="44">44</html:option>
      <html:option value="45">45</html:option>
      <html:option value="46">46</html:option>
      <html:option value="47">47</html:option>
      <html:option value="48">48</html:option>
      <html:option value="49">49</html:option>
      <html:option value="50">50</html:option>
      <html:option value="51">51</html:option>
      <html:option value="52">52</html:option>
      <html:option value="53">53</html:option>
      <html:option value="54">54</html:option>
      <html:option value="55">55</html:option>
      <html:option value="56">56</html:option>
      <html:option value="57">57</html:option>
      <html:option value="58">58</html:option>
      <html:option value="59">59</html:option>
      <html:option value="60">60</html:option>
     </html:select>
    </span>
    <bean:message key="text.second"/>
   </td>
  </tr>
  <tr class="row1">
   <td nowrap><bean:message key="text.resultCheck"/></td>
   <td nowrap>
    <span id="check_input">
     <html:radio name="SupportElectricPowerForm" property="check" value="false" styleId="check_false"/>
      <label for="check_false">
       <bean:message key="text.new"/>
      </label>
     <html:radio name="SupportElectricPowerForm" property="check" value="true" styleId="check_true"/>
      <label for="check_true">
       <bean:message key="text.succeed"/>
      </label>
    </span>
   </td>
  </tr>
 </tbody>
</table>
 <logic:equal name="CurrentUserInfo" property="electricPowerMonitoring" value="1">
  <table width="0" border="0" align="center">
   <tr>
    <td colspan="2" nowrap>
      <html:submit property="action.batchRun" onclick="return doRun(this.form)">
       <bean:message key="button.startMeasurement"/>
      </html:submit>
      <html:submit property="action.batchStop" onclick="return doStop(this.form)">
       <bean:message key="button.stopMeasurement"/>
      </html:submit>
      <html:submit property="action.graph" onclick="return openReadingGraph(this.form);">
       <bean:message key="button.graphMeasurement"/>
      </html:submit>
    </td>
   </tr>
  </table>
  <html:hidden name="SupportElectricPowerForm" property="serverIdList"/>
 </logic:equal>
</html:form>

<script language="JavaScript" type="text/javascript">
<!--
  function changeTest(choose) {
    var selectedHour = choose.options[choose.selectedIndex].value;
    var minute = choose.form.elements["periodMinute"];
    var time = minute.value;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    
    // 分の要素を一旦、全て削除する
    while(minute.options.length) {
      minute.remove(0);
    }

    if(selectedHour == 24) {
      // 24時間が選択された場合、分を00のみに設定する
      opt =  document.createElement("option");
      opt.text = "00";
      opt.value = "00";
      minute.add(opt, where);

    } else if(selectedHour == 00) {
      // 00時間が選択された場合、分を05から59の範囲に設定する
      for(i = 5; i <= 59; i++) {
        opt =  document.createElement("option");
        if(i < 10) {
          opt.text = "0" + i;
          opt.value = "0" + i;
        } else {
          opt.text = i;
          opt.value = i;
        }
        minute.add(opt, where);
      }
      if (Number(time) > 4) {
        minute.value = time;
      }

    } else {
      // 01から23時間が選択された場合、分を00から59の範囲に設定する
      for(i = 0; i <= 59; i++) {
        opt =  document.createElement("option");
        if(i < 10) {
          opt.text = "0" + i;
          opt.value = "0" + i;
        } else {
          opt.text = i;
          opt.value = i;
        }
        minute.add(opt, where);
      }
      minute.value = time;
    }
  }

  //測定ボタン押下時動作
  function doRun(form) {
    var ids = parent.tree.getServerIdList();
    document.getElementsByName("serverIdList")[0].value = ids;
    var msg = "<bean:message key="message.information.electricPowerStartButton"/>";
    form.action = '<html:rewrite forward="measurementGroupElectricPower"/>';
    form.target = 'info';

    confirmFlg = confirm(msg);
    return confirmFlg;
  }
  
  //キャンセルボタン押下時動作
  function doStop(form) {
    var ids = parent.tree.getServerIdList();
    document.getElementsByName("serverIdList")[0].value = ids;
    var msg = "<bean:message key="message.information.electricPowerCancelButton"/>";
    form.action = '<html:rewrite forward="measurementGroupElectricPower"/>';
    form.target = 'info';

    confirmFlg = confirm(msg);
    return confirmFlg;
  }

  //ボタンの無効化処理
  function checkDisalbedButton(isRunButton, isCancelButton, isGraphButton) {
      runButtonObj = document.getElementsByName("action.batchRun")[0];
      cancelButtonObj = document.getElementsByName("action.batchStop")[0];
      graphButtonObj = document.getElementsByName("action.graph")[0];
      runButtonObj.disabled = isRunButton;
      cancelButtonObj.disabled = isCancelButton;
      graphButtonObj.disabled = isGraphButton;
  }

  //測定値グラフ生成
  function openReadingGraph(form) {
      parent.tree.readingWindow = window.open('', 'readingWindow', 'width=840, height=320, menubar=no, toolbar=no, scrollbars=no, resizable=no, location=no, status=no');
      parent.tree.readingWindow.focus();
      form.action = '<html:rewrite forward="graphElectricPower"/>';
      form.serverIdList.value = parent.tree.getServerIdList();
      form.target = 'readingWindow';
      form.submit();
      return false;
  }

// -->
</script>

