<?xml version="1.0"?>
  <?xml-stylesheet 
    href="chrome://global/skin/" 
    type="text/css"
  ?>
  <window 
    id="MySecondWindow" 
    title="eXe" 
    onload="return ol()" onclose="return ex()" 
    width="600" height="300" screenX="200" screenY="300"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    xmlns:html="http://www.w3.org/1999/xhtml"
  >
    <spacer height="30"/>
    <description>
      <html:center>
        <html:img src="exe_logo.png"/>
      </html:center>
    </description>
    <spacer height="20"/>

    <row>
    <spacer width="20"/>
    <groupbox>
      <caption label="" /> 
      <row>
        <description><html:b></html:b> LOADING_FILE_NAME</description>
        <spacer width="5"/>
        <description id="loadPercent"></description>
      </row>
      <row>
        <progressmeter id="pm" mode="undetermined" value="" width="520"/>
      </row>
    </groupbox>
    <spacer width="20"/>
    </row>
    <script type="text/javascript" >
      closeCount=0
      allowClose = 0
      var interval = 0

      function ol() { loopMe() }
      function olEnd() { window.close(); }


      function ex()
      { 
        closeCount+=1
        if(closeCount==0 || allowClose) { return true } 
        else 
        {
          alert("PLEASE_WAIT_LOAD");
          return false 
        }
      }

      function loopMe()
      { interval = setInterval('urlGet("splash.dat")',1000) }

      function urlGet(URL)
      {
        var req = false;
        var self = this;
        if (window.XMLHttpRequest) { self.req = new XMLHttpRequest() }
        self.req.open('POST', URL, true)
        self.req.setRequestHeader('Content-Type', 'text/plain')
        self.req.onreadystatechange = function()
        { if (self.req.readyState == 4) { updatepage(self.req.responseText) } }
        self.req.send("")
      }

      function olOpenWin()
      {
          window.open(openUrl, "eXe");
          allowClose = 1
      }

      openUrl = ""
      function updatepage(str)
      {
        var results = str.split(";")
        if(results[2])
        {
          clearInterval(interval)
          var pl = document.getElementById("loadPercent");
          pl.value = "(" + results[2] + ")"
          alert(results[2])
          window.open(results[1], "eXe");
          allowClose = 1
          setTimeout('olEnd()', 3000)
        }
        else
        {
          if(results[0])
          {
            setProgress(results[0]) //set bar to whatever is in splash.dat
          }

          if(results[1])
          {
            clearInterval(interval)
            setProgress(1000) //set bar to 100
            openUrl = results[1]
            setTimeout('olOpenWin()', 500);
            setTimeout('olEnd()', 3000);
          }
        }
      }

      function setProgress(progressValue)
      {
        progressValue =  progressValue/10
        var mpm = document.getElementById("pm");
        var pl = document.getElementById("loadPercent");
        pl.value = "(" + progressValue.toPrecision(3) + "%)"
        mpm.mode = "determined"
        mpm.value = progressValue;
      }
    </script>

  </window>
