// JavaScript Document
<!--
 
/**
 * Lists blog entries from the specified JSON feed
 * by creating a new 'ul' element in the DOM.  Each
 * bullet is the title of one blog entry, and contains
 * a hyperlink to that entry's URL.
 *
 * @param {JSON} json is the JSON object pulled from the Blogger service.
 */
function listEntries(json) {
  // Clear any information displayed under the "data" div.
  removeOldResults();
  var div_content = document.createElement('div');
 
  for (var i = 0; i < json.feed.entry.length; i++) {
    var entry = json.feed.entry[i];
    var alturl;
 
    for (var k = 0; k < entry.link.length; k++) {
      if (entry.link[k].rel == 'alternate') {
        alturl = entry.link[k].href;
        break;
      }
    }
		
		
 
 
    var h2 = document.createElement('h2');
    var em = document.createElement('em');
    var div_p = document.createElement('div');
		div_p.className = "blog_content";

    var a = document.createElement('a');
    a.href = alturl;
    a.target = '_blank';


		var title = document.createTextNode(entry.title.$t);
		h2.appendChild(title);
		
		var date1 = entry.updated.$t.substr(0,10);

		var author = document.createTextNode("by " + entry.author[0].name.$t + " on " + date1);
		em.appendChild(author);

		div_p.innerHTML = (entry.content.$t);

 		div_content.appendChild(h2);
 		div_content.appendChild(em);
		div_content.appendChild(div_p);



		/*
 		div_content.appendChild(em);
 		div_content.appendChild(p);
		
		
 
    var txt = document.createTextNode(entry.title.$t);
    a.appendChild(txt);
    li.appendChild(a);
 
    //div_content.appendChild(li);
		*/
  }
 
  // Install the bullet list of blog posts.
  document.getElementById('blognews').appendChild(div_content);
 
  // Re-enable the search button.
 // var search_button = document.getElementById('search_button');
 // search_button.removeAttribute('disabled');
}
 
/**
 * Called when the user clicks the 'Search' button to
 * retrieve a blog's JSON feed.  Creates a new script
 * element in the DOM whose source is the JSON feed
 * 'query'.blogspot.com, and specifies that the callback
 * function is 'listEntries' (above).
 *
 * @param {String} query is the blog to be retrieved, specified
 *     as a prefix of ".blogspot.com".
 */
function viewBlogPreview(items) {
  // Delete any previous JSON script nodes.
  removeOldJSONScriptNodes();
  // Clear any old data to prepare to display the Loading... message.
  removeOldResults();
 
  // Show a "Loading..." indicator.
  var div = document.getElementById('blognews');
  var p = document.createElement('p');
  p.appendChild(document.createTextNode('Loading...'));
  div.appendChild(p);
 
  // Disable the search button.
  //var search_button = document.getElementById('search_button');
 // search_button.disabled = 'true';
 
  // Retrieve the JSON feed.
  var script = document.createElement('script');
  script.setAttribute('src', 'http://blog.visrez.com/feeds/posts/default?alt=json-in-script&callback=listEntries&max-results='+items);
											
											//published-min=2008-03-16T00:00:00&published-max=2009-03-24T23:59:59
  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  document.documentElement.firstChild.appendChild(script);
}
 

/**
 * Deletes any old script elements which have been created by previous calls
 * to search().
 */
function removeOldJSONScriptNodes() {
  var jsonScript = document.getElementById('jsonScript');
  if (jsonScript) {
    jsonScript.parentNode.removeChild(jsonScript);
  }
}
 
/**
 * Deletes pre-existing children of the data div from the page. The data div 
 * may contain a "Loading..." message, or the results of a previous query. 
 * This old data should be removed before displaying new data.
 */
function removeOldResults() {
  var div = document.getElementById('blognews');
  if (div.firstChild) {
    div.removeChild(div.firstChild);
  }
}




// INIT

//google.load("gdata", "1");
//window.onload = init; 

//--> 



