<?php
// before_document_onload.php
// RJM Programming
// November, 2024

$results="";


echo "<html>
<head>
<title>Before Document Onload - RJM Programming - November, 2024</title>
<scr" . "ipt type=text/javascript>
  var bigwo=null, topgetbig='';
  
  function getbig() {
    if (bigwo == null) {
      if (document.URL.indexOf('wo=') != -1) {
        if (window.opener) { bigwo=window.opener; return window.opener; }
        return window.self;
      }
    }
    return bigwo;
  }
  
  function setbig(inwo) {
    if (!inwo) {  topgetbig=''; } 
    bigwo=inwo;
  }
  
  function closebig() {
    if (bigwo) { bigwo.close(); }
    bigwo=null;
  }

  function xresfill(iois) {
  //alert('trying ' + iois.src);
  if (iois != null) {
  if (iois.src.indexOf('About_Us.htm') == -1) {
       var xaaconto = (iois.contentWindow || iois.contentDocument);
       if (xaaconto != null) {
    //if (xaaconto.window.opener != null) { alert('trying Yet more'); wotest=true; }
       if (xaaconto.document) { xaaconto = xaaconto.document; }
    //if (xaaconto.window.opener != null) { alert('Trying Yet more'); wotest=true; }
       if (xaaconto.body != null) {
         if (iois.src.indexOf('wo=') != -1) {
         topgetbig='x';
         }
       }
       }
    }
    if (document.getElementById('results').innerHTML.indexOf(' findings') != -1) {
       document.getElementById('results').innerHTML=document.getElementById('results').innerHTML.replace(' findings',' Findings');
    }
    if (iois.src.indexOf('About_Us.') == -1 || iois.src.indexOf('wo=') != -1 || topgetbig != '') {
  //alert('trying more');
    var errr=null;
    var wotest=false;
    if (iois.src.indexOf('wo=') != -1) {  wotest=true; }
    var clientstuff='<br><br><br>ClientSide findings:<br><br>';

    clientstuff+='document.referrer=\"' + ('' + document.referrer) + '\"; <br>';
    clientstuff+='document.URL=\"' + ('' + iois.src.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='location.href=\"' + ('' + iois.src.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='document.location.href=\"' + ('' + iois.src.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='location.search=\"' + ('' + (iois.src.indexOf('?') == -1 ? '' : '?' + iois.src.replace(/\%26/g, '&').replace(/\%3D/g, '=').split('?')[1])) + '\"; <br>';
    clientstuff+='location.hash=\"' + ('' + (iois.src.indexOf('#') == -1 ? '' : '#' + iois.src.replace(/\%26/g, '&').replace(/\%3D/g, '=').split('#')[1])) + '\"; <br>';
    
    if (iois.src.indexOf('wo=') != -1 && !wotest) {
      var huhwoo=null;
      try {
      huhwoo=window.opener.getElementById('results');
      if (huhwoo != null) {  wotest=true; clientstuff+='window.opener.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + window.opener.document.getElementById('results').id) + '\"; <br>';  }
      } catch(errr) {
      wotest=false;
      }
    }
    
    if (wotest) {
    window.opener.document.getElementById('results').innerHTML+=clientstuff;
    } else if (window.parent != window.self && !bigwo) {
    if (window.self.window.opener && iois.src.indexOf('About_Us.') == -1) {  
    clientstuff+='window.opener.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + window.self.window.opener.document.getElementById('results').id) + '\"; <br>';  
    top.document.getElementById('results').innerHTML+=clientstuff;
    } else {
    clientstuff+='parent.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + parent.document.getElementById('results').id) + '\"; <br>';  
    clientstuff+='top.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + top.document.getElementById('results').id) + '\"; <br>';  
    top.document.getElementById('results').innerHTML+=clientstuff;
    }
    } else if (document.getElementById('results').innerHTML.indexOf(' findings') == -1) {
    document.getElementById('results').innerHTML+=clientstuff;
    }
    
    }
    }
  }
  
  function windowopen(pone,ptwo) {
    //alert(pone.replace(/\%26/g, '&').replace(/\%3D/g, '='));
    //document.getElementById('ifres').src='/About_Us.html';
    //document.getElementById('ifres').style.display='block';
    var rect=top.document.getElementById('tdwo').getBoundingClientRect();
    //return window.open(pone.replace(/\%26/g, '&').replace(/\%3D/g, '='),ptwo);
    return window.open(pone.replace(/\%26/g, '&').replace(/\%3D/g, '='),'_blank','top=' + rect.top + ',left=' + rect.left + ',width=' + rect.width + ',height=' + rect.height);
  }

  function resfill(ifo) {
    var errr=null;
    var wotest=false;
    var clientstuff='<br><br><br>';
    if (window.opener || document.URL.indexOf('wo=') != -1) { 
    clientstuff='<br><br><br>ClientSide findings :<br><br>'; 
    window.opener.setbig(window.self); 
    //bigwo=window.self; 
    //alert('opener ' + document.URL);  
    wotest=true;  
    } else { 
    clientstuff='<br><br><br>Clientside findings:<br><br>';
    if (top.getbig() != null) { wotest=true; } 
    }
    
    if (('' + location.hash).replace(/^null/g,'').replace(/^undefined/g,'') != '') {
       document.getElementById('myformget').action+=('' + location.hash);
       if (document.getElementById('hashget').value != ('#' + decodeURIComponent('' + location.hash).substring(1))) {
       //alert(document.getElementById('hashget').value + ' becomes ' + ('#' + decodeURIComponent('' + location.hash).substring(1)));
       document.getElementById('hashget').value=('#' + decodeURIComponent('' + location.hash).substring(1));
       }
    }
    if (document.getElementById('tdpost').innerHTML == '') {
    document.getElementById('tdpost').innerHTML=document.getElementById('tdget').innerHTML.replace(/\"GET\"/g, '\"POST\"').replace('Address','Post').replace(/get/g, 'post').replace(/document\.post/g,'document.get').replace('tarpost','target');
    }
    if (document.getElementById('tdlh').innerHTML == '') {
    document.getElementById('tdlh').innerHTML=document.getElementById('tdget').innerHTML.replace(/get/g, 'lh').replace('tarlh','target').replace('Address','Iframe').replace('_top','ifres').replace(/document\.lh/g,'document.get').replace(/return\ true\;/g, \"  document.getElementById('ifres').src=document.getElementById('myformlh').action.replace('.php','.php?questionlh=' + encodeURIComponent(document.getElementById('questionlh').value + '&sandamperlh=' + encodeURIComponent(document.getElementById('sandamperlh').value)));  return false;\");
    }
    if (document.getElementById('tdwo').innerHTML == '') {
    document.getElementById('tdwo').innerHTML=document.getElementById('tdget').innerHTML.replace(/get/g, 'wo').replace('tarwo','target').replace('Address','Popup').replace('_top','ifres').replace(/document\.wo/g,'document.get').replace(/return\ true\;/g, 'return woos();');
    }
    
    if (document.URL.indexOf('wo=') != -1) {
    //alert(1);
    clientstuff+='docum' + 'ent.referrer=\"' + ('' + document.referrer.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    //alert(12);
    clientstuff+='docum' + 'ent.URL=\"' + ('' + document.URL.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    //alert(13);
    clientstuff+='loca' + 'tion.href=\"' + ('' + location.href.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    //alert(213);
    clientstuff+='docum' + 'ent.location.href=\"' + ('' + document.location.href.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    //alert(313);
    clientstuff+='locat' + 'ion.search=\"' + ('' + location.search.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    //alert(14);
    clientstuff+='locat' + 'ion.hash=\"' + ('' + location.hash) + '\"; <br>';
    //alert(15);
    clientstuff+='wind' + 'ow.opener.docu' + 'ment.getElementById(' + \"'results'\" + ').id=\"' + ('' + document.getElementById('results').id) + '\"; <br>'; 
    //alert(clientstuff);
    if (clientstuff.indexOf('ClientSide findings :') != -1) {
    window.opener.document.getElementById('results').innerHTML=clientstuff;
    } else {
    window.opener.document.getElementById('results').innerHTML+=clientstuff;
    }
    //alert(clientstuff);
    window.opener.closebig();
    return '';
   } else {
    //alert(11);
    clientstuff+='document.referrer=\"' + ('' + document.referrer.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='document.URL=\"' + ('' + document.URL.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='location.href=\"' + ('' + location.href.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='document.location.href=\"' + ('' + document.location.href.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='location.search=\"' + ('' + location.search.replace(/\%26/g, '&').replace(/\%3D/g, '=')) + '\"; <br>';
    clientstuff+='location.hash=\"' + ('' + location.hash) + '\"; <br>';
    }
    
    if (top.getbig() && !wotest) {
      var huhwoo=null;
      try {
      huhwoo=top.getbig().getElementById('results');
      if (huhwoo != null) {  wotest=true; clientstuff+='window.opener.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + top.getbig().document.getElementById('results').id) + '\"; <br>';  }
      } catch(errr) {
      wotest=false;
      }
    }
    
    if (wotest) {
    if (clientstuff.indexOf('ClientSide findings :') != -1) {
    window.opener.document.getElementById('results').innerHTML=clientstuff;
    } else {
    window.opener.document.getElementById('results').innerHTML+=clientstuff;
    }
    window.opener.closebig();
    } else if (window.parent != window.self && !bigwo) {
    clientstuff+='parent.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + parent.document.getElementById('results').id) + '\"; <br>';  
    clientstuff+='top.document.getElementById(' + \"'results'\" + ').id=\"' + ('' + top.document.getElementById('results').id) + '\"; <br>';  
    if (clientstuff.indexOf('ClientSide findings :') != -1) {
    top.document.getElementById('results').innerHTML=clientstuff;
    } else {
    top.document.getElementById('results').innerHTML+=clientstuff;
    }
    } else if (document.getElementById('results').innerHTML.indexOf(' findings') == -1) {
    if (clientstuff.indexOf('ClientSide findings :') != -1) {
    document.getElementById('results').innerHTML=clientstuff;
    } else {
    document.getElementById('results').innerHTML+=clientstuff;
    }
    }
    
    document.getElementById('myformwo').target='ifres';
    if (top.getbig()) {
      top.getbig().close();
      top.setbig(null);
      topgetbig='';
    }
  }
  
  function alltarg(ivalo) {
    var vl='', iis=[], jjs=0;
    if (ivalo.value != '') {
      if (ivalo.value.indexOf('#') != 0) { 
        vl='#' + encodeURIComponent(ivalo.value); 
        ivalo.value='#' + decodeURIComponent(vl.substring(1)); 
      } else {
        vl='#' + encodeURIComponent(ivalo.value.substring(1));
      }
      iis=document.getElementsByTagName('form');
      for (jjs=0; jjs<iis.length; jjs++) {
        iis[jjs].action=iis[jjs].action.split('#')[0] + vl;
      }
    } else {
      iis=document.getElementsByTagName('form');
      for (jjs=0; jjs<iis.length; jjs++) {
        iis[jjs].action=iis[jjs].action.split('#')[0];
      }
    }
  }
  
  function woos() {
   top.document.getElementById('results').innerHTML=''; 
   topgetbig='x';  
   var intowo=('' + document.getElementById('myformwo').action).replace('.php','.php?' + ('questionwo=' + encodeURIComponent(document.getElementById('questionwo').value) + '&sandamperwo=' + encodeURIComponent(document.getElementById('sandamperwo').value)).replace(/%26/g, '&amp;').replace(/%3D/g, '='));
   //alert('intowo=' + intowo);
   bigwo=windowopen(intowo, 'ifres'); //, 'top=50,left=50,width=600,height=600'); 
   return false;
  }

</scr" . "ipt>
</head>
<body onload='resfill(null);'>
<h1>Before Document Onload</h1>
<h3>RJM Programming - November, 2024</h3>
<br>
<div id='results'>" . $results . "</div>
<br><br>

<table style=width:98%; border=2>
<tr><th>Get</th><th>Post</th><th>location.href=</th><th>window.open</th></tr>
<tr><td id=tdget>
<form id=myformget onsubmit=\"  top.document.getElementById('results').innerHTML=''; return true;\" action='./before_document_onload.php' method=\"GET\" target=_top>
<input type=text placeholder=Hashtag value='' id=hashget onblur=\"alltarg(this);\"></input><br>
<input type=text name=questionget id=questionget value=questionget></input><br>
<input type=text name=sandamperget id=sandamperget value=sandamperget></input><br>
<input style=background-color:yellow; id=subget value=Address type=submit></input></form>
</td><td id=tdpost></td><td id=tdlh></td><td id=tdwo></td>

</tr></table>
<iframe name=ifres id=ifres style=display:none; onerror=xresfill(this); onload=xresfill(this); src=/About_Us.html></iframe>
</body>
</html>";
?>