lastHash = "";

function makeShareURL(bid) {
	if (typeof(hash.chapter) != 'undefined') {
		var chapterTemp = hash.chapter;
	} else {
		var chapterTemp = '1';
	}

	return '/bkmod/bkmod_share.php?book='+bid+'&chapter='+chapterTemp;
}

checkHash = function() {
	if (typeof(hash) != "undefined") lastHash = hash;

	hash = window.location.hash;
	hash = hash.substring(1);
	hash = hash.replace(/\;/g, '&');
	hash = hash.replace(/\:/g, '=');
	hash = hash.parseQuery();

	if (typeof(hash.chapter) != "undefined" && hash.chapter != lastHash.chapter) {

		var loadContent = document.getElementById('loadContent');

		var callBack = {
			success: function(o) {
				loadContent.innerHTML = o.responseText;
				document.getElementById('chapterTitle').innerHTML = document.getElementById('chapter').innerHTML
				document.getElementById('pageDisplay').innerHTML = document.getElementById('pages').innerHTML;
				document.getElementById('chapterNav1').innerHTML = document.getElementById('prevNext').innerHTML;
				document.getElementById('chapterNav2').innerHTML = document.getElementById('prevNext').innerHTML;
				document.getElementById('displayBookViews').innerHTML = document.getElementById('bookViews').innerHTML;
				document.getElementById('displayChapterViews').innerHTML = document.getElementById('chapterViews').innerHTML;
				document.getElementById('loadingInfo').className = "ready";
				document.getElementById('loadingInfo').innerHTML = "";


			},
			failure: function(o) {
				document.getElementById('loadingInfo').className = "ready";
				document.getElementById('loadingInfo').innerHTML = "<div class=\"loadingError\">Connection failed.</div>";

			}
		}

		document.getElementById('loadingInfo').className = "loading";
		document.getElementById('loadingInfo').innerHTML = "<div class=\"loadingSpacer\"></div>";

		var conn = YAHOO.util.Connect.asyncRequest("GET", "/bkmod/bkmod_display.php?bid=" + document.getElementById('bid').innerHTML + "&pages=" + hash.chapter, callBack);

	}

}
setInterval(checkHash,200);

/* Ajax file for download counter */

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



function update_download_counter(bid)
{
	var url="http://www.tauheed-sunnat.com/bkmod/bkmod_download_counter.php?book_id=" + bid +"&action=download_counter";
	xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);

}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4  || xmlHttp.readyState==0)
	{ 
	  con_val=xmlHttp.responseText;
	  con_array=con_val.split("|");
	  document.getElementById('down-count-'+con_array[0]).innerHTML = con_array[1];
	   
	}
}




