function showPage(){
 var cat = window.document.all.Category.options[window.document.all.Category.selectedIndex].text;
 var alpha = window.document.all.Alpha.options[window.document.all.Alpha.selectedIndex].text;
 var url = "stock/" + cat + "-" + alpha + ".html";
 window.frames['ContentFrame'].location.href = url;
};

function addBook(title,author,isbn) {
  makeCookie(title,author,isbn);
  if (isbn == null) {
    isbn = " ";
  }
  alert(title + " by " + author + " (ISBN:" + isbn + ") added to basket");
};

function pageCheck() {
}
function makeCookie(title,author,isbn) {
//Find out if they've already selected a book
  var totBooks = getCookieData("bookQty=");
  if ( totBooks == " " ) {
     books = 0;
  }
  books = (totBooks - 0);
//Now add one more and write it back
  document.cookie = "bookQty=" + (books + 1) +"; path=/ " ;
//Now we know how many books they have requested we can make a note of which books they are
  if ( books == 0 ) {
    document.cookie = "bookTitles=" + title +"; path=/ " ;
    document.cookie = "bookAuthors=" + author +"; path=/ " ;
    document.cookie = "bookISBNs=" + isbn +"; path=/ " ;
  } else {
    var bookTitles = getCookieData("bookTitles=");
    document.cookie = "bookTitles=" + bookTitles + "~" + title +"; path=/ " ;
    var bookAuthors = getCookieData("bookAuthors=");
    document.cookie = "bookAuthors=" + bookAuthors + "~" + author +"; path=/ " ;
    var bookISBNs = getCookieData("bookISBNs=");
    document.cookie = "bookISBNs=" + bookISBNs + "~" + isbn +"; path=/ " ;
 }
};

function checkout() {
//check to see if there are any books in the basket
  var totBooks = getCookieData("bookQty=");
  if ( totBooks == " " ) {
    alert("You currently have no books selected");
    return false;
  }
  window.parent.document.location = "../basket.html"
}

function readCookie() {
//Get the cookie values
  var bookTitles = getCookieData("bookTitles=");
  var bookAuthors = getCookieData("bookAuthors=");
  var bookISBNs = getCookieData("bookISBNs=");
//Load them into an array
  var titleArray = bookTitles.split("~");
  var authorArray = bookAuthors.split("~");
  var isbnArray = bookISBNs.split("~");
  var bookReport;
//Now re-organise in the individual entries 
  for (var i=0; i<titleArray.length; i++) {
    if (i==0) {
        bookReport = titleArray[i] + " by " + authorArray[i] + " (ISBN:" + isbnArray[i] +")\n"
    } else {
        bookReport = bookReport + titleArray[i] + " by " + authorArray[i] + " (ISBN:" + isbnArray[i] +")\n"
    }
  }
  document.forms[0].bookList.value = bookReport
//  alert( "You have selected:\n" + bookReport);
}

function getCookieData(label) {
  var labelLen = label.length;
  var cLen = document.cookie.length;
  var i = 0;
  var cEnd;
  while (i < cLen) {
     var j = i + labelLen
     if (document.cookie.substring(i,j) == label) {
        cEnd = document.cookie.indexOf( ";" , j )
        if (cEnd == -1) {
           cEnd = document.cookie.length
        }
        return unescape(document.cookie.substring(j,cEnd))
     }
     i++
  }
  return " "
};