<?
/* BiblePassage*/

$linkico=$_SESSION[`PM_B_Ico`];

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

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

echo `
<style>
  .BibTxt{
	    font-size:`,$txtsiz,`pt;
	 }
</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 ~<br>buk=$buk chpnum=$chpnum vrs=$vrs psg=$psg chp=$chp~;
       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();
    }

  $_SESSION[`PM_B_Method`]=`PA`;
 
//echo ~biblepassage psg=$psg chp=$chp buk=$buk con=$con<br>~;

$psgful=$ful[BookIdx($buk)].` `.$chpnum.`:`.$vrs;

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

//$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> ~;

//$ssl=`<input type=~image~ return onclick=~BibSS(); return false;~; src=../images/slideshow.jpg width=25 `.$_SESSION[`PM_AltTitle`].`=~SlideShow mode~>`;
$ssl=``;

$lpre=`<img src=~../images/left.png~ width=20px title=~Previous verse~ onclick=~GoToVrs(`.~`~.$prevrs.~`~.`);~>`;
$lnxt=`<img src=~../images/right.png~ width=20px title=~Next verse~ onclick=~GoToVrs(`.~`~.$nxtvrs.~`~.`);~>`;

  echo `
<input type=~hidden~ id=~ref~ name=~ref~ value=~`,$ref,`~> 

<center><table width=100% border=0><tr><td width=20%>`,$tbib,`  `,$ssl,`  `,$tchp,`</td><td><div id=PAcon name=PAcon>`,$lpre,`  <font size=5> `, $psgful,` </font>`,$lnxt,` </div></td></tr></table></center>

<div id=~PAtxt~ name=~PAtxt~   style=~overflow-y:auto;
      padding: 5px; border: 2px solid;
 background:#088A68;~>`,

BibleStr(~$psg~,`PA`,~$buk~),`

</div>
<script language=javascript>

//alert(~In BiblePassage~);

var onam=window.opener.name;
//alert(~Opened by ~+onam);

if (onam==~BiblePassage~) {}
else if (onam.substring(0,5)==~Bible~) {window.opener.close();}

//if (onam.substring(0,5)==~Bible~) {window.opener.close();}

function BibSS()
{
//alert(~BibSS started~);
   purl=~../inc/slideshow.php?name=1&controls=1&height=500&txtsize=200&fun=BibleStr(`,~`~,$psg,~`,`PA`,`~,$buk,~`~,`)&winnam=BibleSS&exte=1&ttl=`,$ref,`~;
   popitup(purl,75,250,575,800);
}
function GoToVrs(vrs)
{
//alert(~GoToVrs vrs=~+vrs);
   document.getElementById(~ref~).value=vrs;
   document.Help.submit();    
}
</script>
`;

include_once `../inc/swipe.js`;

echo `
<script language=javascript>

  function PAswipe(el,d)
    {
//      alert(~you swiped on element with id ~+el+~ to ~+d+~ direction~);
        if      (d===~r~) {GoToVrs(~`,$prevrs,`~);}
        else if (d===~l~) {GoToVrs(~`,$nxtvrs,`~);}
        else if (d===~u~) {GoToVrs(~`,$nxtvrs,`~);}
        else if (d===~d~) {GoToVrs(~`,$prevrs,`~);}
    }

   detectSwipe(~PAcon~,PAswipe,~b~);

</script>`;
?>