<div class="cbi-section-create cbi-tblsection-create">
  <br />
  <table class="cbi-section-table" style="width:1010px; margin-left:5px">
    <tr class="cbi-section-table-descr">
      <th class="cbi-section-table-cell"  style="width:200px"><%:Events%></th>
      <th class="cbi-section-table-cell"  style="width:200px"><%:Action%></th>
      <th class="cbi-section-table-cell" style="width:200px"><%:Mobile Number / VPN type%></th>
      <th class="cbi-section-table-cell" style="width:200px"><%:Text / VPN Name%></th>
      <th class="cbi-section-table-cell"></th>
    </tr>
    <tr class="cbi-section-table-row">
      <th class="cbi-section-table-cell" style="width:200px">
        <select onchange="xyz();" class="cbi-input-select" id="_new.event" name="_new.event">
          <option value="DI1_H">Digital Input # 1 has voltage</option>
          <option value="DI1_L">Digital Input # 1 is grounded</option>
          <option value="DI2_H">Digital Input # 2 has voltage</option>
          <option value="DI2_L">Digital Input # 2 is grounded</option>
          <!--  <option value="SIM_CHANGE">SIM_CHANGE</option>-->
        </select>
      </th>
      <th class="cbi-section-table-cell" style="width:200px" >
        <select onchange="abc();"  class="cbi-input-select" id="_new.action" name="_new.action">
          <option value="DO2_H" id="1" >Close digital Output # 2</option>
          <option value="DO2_L" id="2" >Open digital Output # 2</option>
          <option value="DO1_H" id="3" hidden="true">Close digital Output # 1</option>
          <option value="DO1_L" id="4" hidden="true">Open digital Output # 1</option>
                    <option value="VPN_ON">Start VPN</option>
                    <option value="VPN_OFF">Stop VPN</option>
          <option value="SMS">SMS</option>                                                                               
          <option value="REBOOT">REBOOT.(Use with caution. Will cause continuous reboot in case DI events are not properly configured. )</option>
          <option value="POWER_SAVEMODE_ON">POWER_SAVEMODE_ON</option>
          <option value="POWER_SAVEMODE_OFF">POWER_SAVEMODE_OFF</option>                                                                           
        </select>                                                                                                            
      </th>    

      <th class="cbi-section-table-cell" style="width:200px">
        <input type="text"  class="cbi-input-text"   id="_new.mobile"  disabled= "true" name="_new.mobile" placeholder="<%:+91xxxxxxxxxx %>" />
      </th>

      <th class="cbi-section-table-cell" style="width:200px">
        <input type="text" class="cbi-input-text" id="_new.msg" name="_new.msg" disabled="true"/>
      </th>

      <th class="cbi-section-table-cell">
        <input type="submit" class="cbi-button cbi-button-add" onClick="return empty();"   name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>"  value="<%:Add%>" />
      </th>

    </tr>                                                                                                                 
  </table>      

          <script type="text/javascript">//<![CDATA[                                                      

            var a = document.getElementsByName("var");
            a.value = true;
            function xyz()                                                                                            
            {                                                                                                         
              var op = document.getElementById('_new.event');
              var op1 = document.getElementById('1');
              var op2 = document.getElementById('2');
              var op3 = document.getElementById('3');
              var op4 = document.getElementById('4');
              var x = document.getElementById('_new.action');
              if (op.value == "DI2_L" || op.value == "DI2_H")
              {
                op1.hidden = true;
                op2.hidden = true; 
                op3.hidden = false;                                                      
                op4.hidden = false;
                    if (x.value!="SMS" && x.value!="REBOOT" && x.value!="VPN_OFF" && x.value!="VPN_ON")
                {
                  x.value=x.getElementsByTagName('option')[2].value;
                }
              }
              else if (op.value == "DI1_L" || op.value == "DI1_H")
              {
                op1.hidden = false;
                op2.hidden = false;
                op3.hidden = true;
                op4.hidden = true;
                    if (x.value!="SMS" && x.value!="REBOOT" && x.value!="VPN_OFF" && x.value!="VPN_ON")
                {
                  x.value=x.getElementsByTagName('option')[0].value;
                }
              }
              else
              {
                op1.hidden = false;                                                      
                op2.hidden = false;
                op3.hidden = false;                                                      
                op4.hidden = false;
              }
            }   

            function abc()
            {
              var x = document.getElementById('_new.action');
              var y = document.getElementById('_new.mobile');
              var z = document.getElementById('_new.msg'); 
                if (x.value == "SMS" || x.value == "VPN_ON" || x.value == "VPN_OFF")
                {
                    y.disabled = false;
                    z.disabled = false;
                }
                else
                {
                    y.disabled = true;
                    z.disabled = true;
                }

            }

            function empty()
            {
              var x = document.getElementById('_new.action');
              var n = document.getElementById('_new.mobile');
              var m = document.getElementById('_new.msg');
              n.disabled = false;
              m.disabled = false;

              if (x.value != "NA" && n.value != "" && m.value != ""  )
              {
                return true;
              }
              else 
              {

                    if (x.value == "SMS" || x.value == "VPN_ON" || x.value == "VPN_OFF")
                {
                  alert (" Some field are empty");
                  return false;
                }
                if (x.value == "NA" )
                {
                  alert("Some field are missing");
                  return false;
                }
                n.value = 0;
                m.value = 0;
                return true;

              }
            }
            cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
            //]]></script>                                                                                                                                 

          </div>
