<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Wait.aspx.cs" Inherits="MyTunes.Admin.Wait" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
<!--
  var pollInterval = 1000;
  var nextPageUrl = "ScanResults.aspx";
  var checkStatusUrl = "ScanStatus.aspx";
  var lastStatus = "Update Pending...";
  var req;
  
  // Setup interval for status checks
  window.setInterval("checkStatus()", pollInterval);
  
  // Animates the page, not critical
  window.setInterval("drawStatus()", pollInterval);
  
  function drawStatus()
  {
      var status = document.getElementById("status");
      if(status)
        status.innerText = lastStatus;
  }
  
  function checkStatus()
  {
    createRequester();
    
    if(req != null)
    {
      req.onreadystatechange = process;
      req.open("GET", checkStatusUrl, true);
      req.send(null);
    }
  }
  function process()
  {
    if(req.readyState == 4)
    {
      if(req.status == 200)
      {
        var currStatus = req.responseText.substr(0,1);
        
        // "1" means scan completed, so redirect
        if(currStatus == "1")
        {
          document.location.replace(nextPageUrl);
        }
        else
        {
          lastStatus = req.responseText.substr(2);
        }
      }
    }
  }
  
  // Create an XmlHttpRequest object (varies depending on browser)
  function createRequester()
  {
    try
    {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(oc)
      {
        req = null;
      }
    }
    
    if( !req && typeof XMLHttpRequest != "undefined")
    {
      req = new XMLHttpRequest();
    }
    
    return req;
}
//-->
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p>
        Latest Status</p>
    <p>
        &nbsp;<span id="status" 
            style="margin: 3px; font-family: 'Times New Roman', Times, serif; font-size: large; background-color: #00FF00; border-color: #C0C0C0; border-style: groove; padding: 3px"></span></p>
        <script type="text/javascript">
        <!--
            drawStatus();
        //-->
        </script>
</asp:Content>
