<?
/* BibleChapter*/

include_once `../inc/BibleLinkArray.inc`;

$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`];
//echo ~BibleChapter psg=$psg<br>~;
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);
  $chpsav=$chpnum;
  $vrs=substr($psg,strpos($psg,`:`)+1);

  $psg=$buk.` `.$chpnum.`:`.$vrs;
  $chp=$buk.` `.$chpnum;

  $schp=strtolower(str_replace(` `,``,$chp));
  
}
else
{
        AlertCustom(~Error~,~No Scripture Reference Number~);
        die();
}

$idx=BookIdx($buk);

$chpnum=trim(substr($chp,strpos($chp,` `)));
$savchp=$chpnum;
$savbuk=$buk;

$bukp=$buk;
$bukn=$buk;

$chpnump=$chpnum-1;
if($chpnump==0)
   { 
      $bukp=$fol[PrevBook($idx)];   
      $chpnump=$kjvchp[Bookidx($bukp)];
   }
$prechp=$bukp.` `.$chpnump;

$chpnumn=$chpnum+1;
if($chpnumn>$kjvchp[$idx])
  {
     $bukn=$fol[NextBook($idx)];
     $chpnumn=1;
  }
$nxtchp=$bukn.` `.$chpnumn;

$_SESSION[`PM_B_Method`]=`CH`;

$prec=~../ProjectManagement/Help.php?tabname=BibleChapter&ref=~.$prechp.~:1&winnam=BibleChapter&exte=1&clean=1~;
$nxtc=~../ProjectManagement/Help.php?tabname=BibleChapter&ref=~.$nxtchp.~:1&winnam=BibleChapter&exte=1&clean=1~;
  
$prechpt=`<a href=~`.$prec.`~>`.$prechp.`</a>`;
$nxtchpt=`<a href=~`.$nxtc.`~>`.$nxtchp.`</a>`;

$chpful=$ful[$idx].substr($chp,strpos($chp,` `));

//echo ~biblechapter idx=$idx buk=$buk chp=$chp chpful=$chpful<br>~;

$ref=$chp;

$tbuk=~ <a href=`javascript: popitup(~.`~`.~../ProjectManagement/Help.php?tabname=BibleBook&ref=~.$ref.~&winnam=BibleBook&exte=1&clean=1~.`~`.~,100,200,575,700); window.close();` title=~.$ful[$idx].~><img src=../images/book.jpg 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`].`=~Show verses in SlideShow mode~>`;

$audfil=$_SESSION[`PM_BASE`].~/Bible/audio/$savbuk/$savbuk~.`_`.~$savchp.wav~;
//echo ~BibleChapter audfil=$audfil<br>~;
if (file_exists($audfil))
  $aud=`<input type=~image~ onclick=~BibAud(`.~`~.`../Bible/audio/`.$savbuk.`/`.$savbuk.`_`.$savchp.`.wav`.~`~.`); return false;~; src=../images/audio.png height=28 `.$_SESSION[`PM_AltTitle`].`=~Listen to `.$ful[$idx].` `.$chpsav.`~>`;
else
  $aud=``;

//echo ~<br>schp=$schp~;

$tstrg=`<a href=~http://www.godrules.net/library/kjvstrongs/kjvstrongs`.$schp.`.htm~ target=_BLANK `.$_SESSION[`PM_AltTitle`].`=~Strongs_Concordance~><img src=../images/strong.png width=28></a>`;

$lpre=`<img src=~../images/left.png~ width=20px title=~Previous chapter~ onclick=~GoToChp(`.~`~.$prechp.~:1`~.`);~>`;
$lnxt=`<img src=~../images/right.png~ width=20px title=~Next chapter~ onclick=~GoToChp(`.~`~.$nxtchp.~:1`~.`);~>`;

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

<center><table width=100% border=0><tr><td width=30%>`,$tbib,`  `,$ssl,`  `,$tbuk,` `,$aud,`  `,$tstrg.`</td><td width=60%><div id=CHcon name=CHcon>`,$lpre,` </font>    <font size=5> `, $chpful,` </font>`,$lnxt,` </div></td></tr></table></center>

<div id=CHtxt name=CHtxt style=~overflow-y:auto;
      padding: 5px; border: 2px solid;
height:480px; background:#088A68;~>`,
	BibleStr($chp,`CH`,$buk),
`</div>

<script language=javascript>

function BibAud(fil)
{
//    alert(~BibAud fil=~+fil);
    popitup(fil,75,250,575,800);   
}

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

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

echo `
<script language=javascript>

  window.opener.close();

  function CHswipe(el,d)
    {
//      alert(~you swiped on element with id ~+el+~ to ~+d+~ direction~);
        if      (d===~r~) {GoToChp(~`,$prechp,`:1~);}
        else if (d===~l~) {GoToChp(~`,$nxtchp,`:1~);}
        else if (d===~u~) {GoToChp(~`,$nxtchp,`:1~);}
        else if (d===~d~) {GoToVrs(~`,$prechp,`:1~);}
    }

   detectSwipe(~CHcon~,CHswipe,~h~);

</script>`;
?>