title: Unable to get property 'document' of undefined or null reference
body: <p>I'm trying to get this code to work, I'm not brilliant at JS but I cant see anything that could be causing this.</p>
  
  <p>This is my code</p>
  
  <p>javascript:</p>
  
  <pre><code>function end(){
      c='798|209';
      var d = document;
  
      if (window.frames.length &gt; 0)
          d = window.main.document;
  
      url = d.URL;
  
      if (url.indexOf('screen=place') == -1)
          alert('This script needs to be run from the rally point');
  
      a = c.match(/(\d+\|\d+)/g);
      b = a[Math.round(Math.random()*(a.length-1))].split("|");
      d.forms[0].x.value = b[0];
      d.forms[0].y.value = b[1];
      d.forms[0].spear.value = 0;
      d.forms[0].sword.value = 0;
      d.forms[0].axe.value = 0;
      d.forms[0].spy.value = 0;
      d.forms[0].light.value = 529;
      d.forms[0].heavy.value = 0;
      d.forms[0].ram.value = 1;
      d.forms[0].catapult.value = 0;
      d.forms[0].snob.value = 0;
      d.forms[0].archer.value = 0;
      d.forms[0].marcher.value = 100;
      d.forms[0].knight.value = 0;
  }
  
  end();
  </code></pre>