
<fieldset class="cbi-section">
	<table width="100%">
	  <tr><td width="100%" colspan="4">
	  	<p align="center" id="switch_mode">
	  		<%:Collecting data...%>
	  	</p>
	  </td></tr>
	</table>
</fieldset>

<script type="text/javascript">//<![CDATA[
	var switch_mode  = document.getElementById('switch_mode');
  XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "op_mode")%>', null, function(x, status) {
      	if ( x && x.status == 200 ) {
      	   if ( status.op_mode == "redir-host" ) {
      	      switch_mode.innerHTML = '<input type="button" class="cbi-button cbi-button-reset" value="<%:切换页面到 Fake-IP 模式%>" onclick="return switch_modes(this)"/>';
      	   }
      	   else {
      		    switch_mode.innerHTML = '<input type="button" class="cbi-button cbi-button-reset" value="<%:切换页面到 Redir-Host 模式%>" onclick="return switch_modes(this)"/>';
           }
        }
      });
    
  function switch_modes(btn)
  {
      btn.disabled = true;
      XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "switch_mode")%>', null, function(x, status) {
      	if ( x && x.status == 200 ) {
      	   if ( status.switch_mode == "redir-host" ) {
      	      alert('页面已切换为Fake-IP模式！')
      	      window.location.href='<%="http://'+window.location.hostname+'/cgi-bin/luci/admin/services/openclash/settings"%>';
      	   }
      	   else {
      		    alert('页面已切换为Redir-Host模式！')
      		    window.location.href='<%="http://'+window.location.hostname+'/cgi-bin/luci/admin/services/openclash/settings"%>';
           }
        }
      });
      btn.disabled = false;
      return false; 
  }

//]]></script>
      