window.onload = function() {
  var ajaxPatts = new Book(200, "Ajax Patterns", "Mahemoff");
  var guns = new Book(300, "Guns, Germs, and Steel", "Diamond");
  log(ajaxPatts.display());
  log(guns.display());
  log(ajaxPatts.constant("MAX_CHAPTERS"));
}

var Book = (function() {

  var amount = 0;
  function checkIsbn(isbn) { return (isbn>100); }

  var constants = {
    MAX_CHAPTERS: 100,
    MAX_VOLUMES: 10
  }
  return function(newIsbn, newTitle, newAuthor) {

    console.log(++amount);
    var isbn, title, author;

    this.constant  =function(id) { return constants[id]; }

    this.getIsbn = function() { return isbn; }
    this.setIsbn = function(newIsbn) {
      if (!checkIsbn(newIsbn)) console.log("error"); // throw new Error("invalid");
      isbn = newIsbn;
    }

    this.getTitle = function() { return title; }
    this.setTitle = function(newTitle) {
      title = newTitle || "no title specified";
    }

    this.getAuthor = function() { return author; }
    this.setAuthor = function(newAuthor) {
      author = newAuthor || "no author specified";
    }

    this.setIsbn(newIsbn);
    this.setTitle(newTitle);
    this.setAuthor(newAuthor);

  }

})();

Book.prototype = {
  display: function() {
    return this.title + " by " + this.author + " (" + this.getIsbn() + ")";
  }
}

function log(result) {
  $("results").innerHTML += "<p>" + result + "</p>";
}
