var LibPage=1;
var infoHTML= "";
var BooksHTML= "";
var StatsHTML= "";
var FriendReqHTML="";

detectBrowser();


function detectBrowser(){

if(navigator.appName== "Microsoft Internet Explorer" && navigator.appVersion.search('MSIE 8')==-1){

window.location = "http://www.bookbump.com/ie/"

}
}


function BuildTitleArray(){
s= title_source;
if(s.search("</e>")>0){
do{
n= s.search("</e>");
title_array.push(s.substr(3,n-3));
s= s.substr(n+4, 10000);
}
while (n>0)
}
BuildISBNArray();
if(document.getElementById("BBSearchBar")!=null){
document.getElementById("BBSearchBar").disabled=false;
}
}

function BuildISBNArray(){
s= isbn_source;
if(s.search("</e>")>0){
do{
n= s.search("</e>");
isbn_array.push(s.substr(3,n-3));
s= s.substr(n+4, 10000);
}
while (n>0)
}
BuildFriendArray();
}

function BuildFriendArray(){
friend_array.length=0;
friendid_array.length=0;
s= friend_source;
if(s.search("</f>")>0){
do{	
m = s.search("</e>");
friendid_array.push(s.substr(3,m-3));
s= s.substr(m+4, 10000);
n= s.search("</f>");
friend_array.push(s.substr(3,n-3));
s= s.substr(n+4, 10000);
}
while (n>0)
}
}

function NewSearch(){
var g= document.getElementById("BBSearchBar").value.toUpperCase();
document.getElementById("Results").innerHTML="";
document.getElementById("Results").style.display="none";
if(g!=""){
document.getElementById("Results").style.display="block";
var i= title_array.length;	
var count=0;
for(n=0; n<i; n++){
if(count==10){break;}
if(title_array[n].toUpperCase().search(g)>-1){
if(count==0){
s=document.getElementById("Results").innerHTML;
document.getElementById("Results").innerHTML= s+"<a><li onClick='window.location = "+'"'+"http://www.bookbump.com/library.php?username="+user_name+"'><b>Books</b></li></a>";
}
count++;
s=document.getElementById("Results").innerHTML;
document.getElementById("Results").innerHTML= s+"<a><li onClick='window.location = "+'"'+"http://www.bookbump.com/book.php?isbn="+isbn_array[n]+'"'+"'>"+title_array[n].substr(0,title_array[n].toUpperCase().search(g))+"<span style='background-color: #D8DFEA; font-weight:bold'>"+title_array[n].substr(title_array[n].toUpperCase().search(g), g.length)+"</span>"+title_array[n].substr(title_array[n].toUpperCase().search(g)+g.length, title_array[n].length)+"</li></a>";
}
}
var i= friend_array.length;
var count2=0;
for(n=0; n<i; n++){
if(count2==10){break;}
if(friend_array[n].toUpperCase().search(g)>-1){
if(count2==0){
s=document.getElementById("Results").innerHTML;
document.getElementById("Results").innerHTML= s+"<a><li onClick='window.location = "+'"'+"http://www.bookbump.com/friends.php?username="+user_name+"'><b>Friends</b></li></a>";
}
count2++;
s=document.getElementById("Results").innerHTML;
document.getElementById("Results").innerHTML= s+"<a><li onClick='window.location = "+'"'+"http://www.bookbump.com/profile.php?username="+friendid_array[n]+'"'+"'>"+friend_array[n].substr(0,friend_array[n].toUpperCase().search(g))+"<span style='background-color: #D8DFEA; font-weight:bold'>"+friend_array[n].substr(friend_array[n].toUpperCase().search(g), g.length)+"</span>"+friend_array[n].substr(friend_array[n].toUpperCase().search(g)+g.length, friend_array[n].length)+"</li></a>";
}
}				
if(count+count2==0){document.getElementById("Results").style.display="none";}
}	
}

function checkCover(img, size){
if (img.width==size && img.height==size) {
img.src= "http://www.bookbump.com/styles/images/HardCover_small.jpg";
}		
if(img.width> size){
img.width= size;
}
}

function friendPictureCheck(img){ 
img.src= "http://www.bookbump.com/styles/images/NoPicture.png";
}

function ActionClicked(){ 
if(document.getElementById("ActionButton").src== "http://www.bookbump.com/styles/images/Action.png"){
document.getElementById("ActionButton").src= "http://www.bookbump.com/styles/images/ActionSel.png";
document.getElementById("ActionMenu").style.display= "block";
}else{
document.getElementById("ActionButton").src= "http://www.bookbump.com/styles/images/Action.png";
document.getElementById("ActionMenu").style.display= "none";
}
}

function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}

function reloadCaptcha(){
document.getElementById("captcha_img").src = 
document.getElementById("captcha_img").src + 
'?' + (new Date()).getTime();
}