/**
 * This function is the call-back function for the JSON scripts which 
 * executes a Google book search response.
 *
 * @param {JSON} booksInfo is the JSON object pulled from the Google Book Search service.
 */
function listEntries(booksInfo) {
  
  for (i in booksInfo) {
     var book = booksInfo[i];
     var olivro = document.getElementById(book.bib_key);
     olivro.style.visibility = "visible";     
     olivro.firstChild.setAttribute("href",book.info_url);
  }
}

/**
 *
 * @param {DOM object} query The form element containing the
 *                     input parameters "isbns"
 */
function search(query) {
  var scriptElement = document.createElement("script");
  scriptElement.setAttribute("id", "jsonScript");
  scriptElement.setAttribute("src",
      "http://books.google.com/books?bibkeys=" + 
      escape(query) + "&jscmd=viewapi&callback=listEntries");
  scriptElement.setAttribute("type", "text/javascript");
  document.documentElement.firstChild.appendChild(scriptElement);
  }

function listaISBNs() {
   var lista="";
   var l = new Array();
   var spans = document.getElementsByTagName ('span');
   for (var i=0; i<spans.length; i++) {
     // lista += spans[i].getAttribute("id")+",";      
      l.push( spans[i].getAttribute("id"));
   }
   lista = l.join(",");
   search(lista);
}

window.onload=function(){
 listaISBNs();
}

 
