<?

$linkico=$_SESSION[`PM_B_Ico`];

$_REQUEST[`bgimage`]=`../images/gardentomb.jpg`;

$txtsiz=$_REQUEST[`txtsiz`];
if($txtsiz==``) $txtsiz=$_SESSION[`PM_B_Tsiz`];

echo `
<style>
  .BibTxt{
		font-family: Arial, Helvetica, sans-serif;
		font: `,$txtsiz,`pt Tahoma;
	 }
</style>
`;
  $psg=$_REQUEST[`ref`];
  if($psg>`0`)
    {
       $chp=substr($psg,0,strpos($psg,`:`));
       if(substr($psg,0,1)<`A`) 
            $buk=substr($psg,0,2).substr($psg,2,strpos(substr($psg,2),` `));
       else                  
            $buk=substr($psg,0,3);

       $chpnum=substr($chp,strrpos($chp,` `)+1);
       $vrs=substr($psg,strpos($psg,`:`)+1);

       $psg=$buk.` `.$chpnum.`:`.$vrs;
       $chp=$buk.` `.$chpnum;
       
//echo ~buk=$buk chpnum=$chpnum vrs=$vrs psg=$psg chp=$chp<br>~;
       if ($vrs==`1`) 
          {
            $line=ShowQueryResultScalar(~select line from Bible where book=`$buk` and chapter=`$chpnum` and verse=`$vrs` ~);
            $lin0=$line-1;
            $pbuk=ShowQueryResultScalar(~select book from Bible where line=`$lin0`~);             
            $pchp=ShowQueryResultScalar(~select chapter from Bible where line=`$lin0`~);             
            $pvrs=ShowQueryResultScalar(~select verse from Bible where line=`$lin0`~);             
            $prevrs=$pbuk.` `.$pchp.`:`.$pvrs;
//echo ~pbuk=$pbuk pchp=$pchp pvrs=$pvrs<br>~;
            $vrss=`1,2,3`;
            $nxtvrs=$chp.`:2`;
          }
       else 
          {
            $vrs0=$vrs-1;
            $prevrs=$chp.`:`.$vrs0;
            $vrs1=$vrs+1;
            $line=ShowQueryResultScalar(~select line from Bible where book=`$buk` and chapter=`$chpnum` and verse=`$vrs` ~);
//echo ~cur line=$line<br>~;
            $lin1=$line+1;
            $nchp=ShowQueryResultScalar(~select chapter from Bible where line=`$lin1` ~);
//echo ~nchp=$nchp chpnum=$chpnum<br>~;
            if($nchp!==$chpnum)
              {
                 $nbuk=ShowQueryResultScalar(~select book from Bible where line=`$lin1` ~);
//echo ~nbuk=$nbuk buk=$buk<br>~;
                 if($nbuk!==$buk)
                    {
                       $nxtvrs=$nbuk.` `.$nchp.`:1`;
                       $vrss=`1,2,3`;
                    }
                 else
                    {
                       $nxtvrs=$buk.` `.$nchp.`:1`;
                       $vrs2=$vrs-2;
                       $vrs1=$vrs-1;
                       $vrss=~$vrs2,$vrs1,$vrs~;
//echo ~vrss=$vrss<br>~;
                    }
              }
            else
              {
                 $nxtvrs=$chp.`:`.$vrs1;
                 $vrss=~$vrs0,$vrs,$vrs1~;
              }
          }
       $con=$chp.`:`.$vrss;

//echo ~nbuk=$nbuk nchp=$nchp nxtvrs=$nxtvrs<br>~;

//echo ~verse=$vrs verses=$vrss context=$con~;
    }
  else
    {
        AlertCustom(~Error~,~No Scripture Reference Number~);
        die();
    }

//echo `biblecontext con=`,$con,`<br>`;

$ref=$buk.` `.$chpnum.`:`.$vrs;

$conful=$ful[BookIdx($buk)].substr($con,strpos($con,` `));

$tchp=~ <a href=`javascript: popitup(~.`~`.~../ProjectManagement/Help.php?tabname=BibleChapter&ref=~.$ref.~&winnam=BibleChapter&exte=1&clean=1~.`~`.~,75,175,575,700); window.close();` title=Chapter><img src=../images/page.gif width=30px></a> ~;

$tbib=~ <a href=`javascript: window.close();` title=`Bible search`><img src=../images/close.png width=30px></a> ~;

  echo `<table border=0 width=100%><tr><td>`,$tbib,` `,$tchp,`</td><td width=60%><font size=5>`, $conful,`</font></td></tr></table>  

<div style=~overflow-y:auto;
      padding: 5px; border: 2px solid;
 background:#088A68~>`,
	BibleStr($con,~CO~,$buk),
`</div>
<script language=javascript>
var onam=window.opener.name;
//alert(~Opened by ~+onam);
if (onam != ~BibleContext~)
  {
     window.opener.close();
  }
</script>
`;

?>