function BlogPreview(container) {
  this.container_ = container;
}

BlogPreview.prototype.show = function(url, opt_noTitle) {
  var feed = new google.feeds.Feed(url);
  var preview = this;
  feed.load(function(result) {
    preview.render_(result, opt_noTitle);
  });
}

BlogPreview.prototype.render_ = function(result, opt_noTitle) {
  if (!result.feed || !result.feed.entries) return;
  while (this.container_.firstChild) {
    this.container_.removeChild(this.container_.firstChild);
  }

 // var newsFeed = this.createDiv_(this.container_, "newsFeed");
  var newsFeed = this.createElement_("ul", this.container_, "");
  if (!opt_noTitle) {
    var header = this.createElement_("p", newsFeed, "BBC Sport News Feed");
   // this.createLink_(header, result.feed.link, result.feed.title);
  }
  for (var i = 0; i < result.feed.entries.length; i++) {
    var entry = result.feed.entries[i];
   // var div = this.createDiv_(newsFeed, "entry");
    var linkDiv = this.createElement_("li", newsFeed, "");
	
    this.createLink_(linkDiv, entry.link, entry.title);
    if (entry.author) {
      this.createDiv_(div, "author", "Posted by " + entry.author);
    }
  //  this.createDiv_(div, "body", entry.contentSnippet);
  }
}

BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
  return this.createElement_("div", parent, className, opt_text);
}

BlogPreview.prototype.createLink_ = function(parent, href, text) {
  var link = this.createElement_("a", parent, "", text);
  link.href = href;
  return link;
}

BlogPreview.prototype.createElement_ = function(tagName, parent, className,
                                                opt_text) {
  var div = document.createElement(tagName);
  div.className = className;
  parent.appendChild(div);
  if (opt_text) {
    div.appendChild(document.createTextNode(opt_text));
  }
  return div;
}

google.load("feeds", "1");

function initialize() {
  var newsFeed = new BlogPreview(document.getElementById("newsFeed"));
  newsFeed.show("http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/front_page/rss.xml");
}
google.setOnLoadCallback(initialize);





//
function setVisitorID(randomvisitornumber) {
	var expirydate = new Date()
	//var randomvisitornumber=Math.floor(Math.random()*100000001) ;
	//alert(randomvisitornumber) ;
	expirydate.setTime(expirydate.getTime() + (180*24*60*60*1000));
	if (isNaN(readCookie('visitor_id')) || readCookie('visitor_id') == 1 || !readCookie('visitor_id')) {
		//var randomvisitornumber=Math.floor(Math.random()*100000001) ;
		//document.cookie = "visitor_id=" + escape(randomvisitornumber) + "; expires=" + expirydate.toGMTString() + ";";
	}
	document.cookie = "visitor_id=" + escape(randomvisitornumber) + "; expires=" + expirydate.toGMTString() + ";";
}

// This is called by clicking to add product to notepad - stores the product index key in $_POST field then submits notepad form
function addNotepad(idx_key) {
	//setcookies() ;
	document.forms.notepad.notepad_add_products_index_key.value = idx_key ;
	document.forms.notepad.submit() ;
}

// This is called by clicking to remove product from notepad - stores the product index key in $_POST field then submits notepad form
function removeNotepad(idx_key) {
	//setcookies() ;
	document.forms.notepad.notepad_remove_products_index_key.value = idx_key ;
	document.forms.notepad.submit() ;
}

// This is called by clicking the main notepad link - sets the form field to Y then submits the form
function viewNotepad(doviewnotepad) {
	// If going to view notepad, remove the search settings (Y), but retain them if going back to browing (N)
	if (doviewnotepad == 'Y') {
		document.forms.searchform.categories0_index_key.value = 'all' ;
		document.forms.searchform.categories1_index_key.value = 'all' ;
		document.forms.searchform.manufacturers_index_key.value = 'all' ;
		document.forms.searchform.brands_index_key.value = 'all' ;
		document.forms.searchform.keywords.value = '' ;
		document.forms.searchform.minprice.value = '' ;
		document.forms.searchform.maxprice.value = '' ;
		document.forms.searchform.searchoffers.value = '0' ;
	}
	// When this cookie is set to Y, only products within the notepad (and meeting search conditions) are displayed
	document.forms.searchform.view_notepad.value = doviewnotepad ;
	searchformsubmit() ;
}

// This function stores all the cookies
function setcookies() {
	var expirydate = new Date()
	expirydate.setTime(expirydate.getTime() + (180*24*60*60*1000));
	document.cookie = "categories0_index_key=" + escape(document.forms.searchform.categories0_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "categories1_index_key=" + escape(document.forms.searchform.categories1_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "manufacturers_index_key=" + escape(document.forms.searchform.manufacturers_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "brands_index_key=" + escape(document.forms.searchform.brands_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "keywords=" + escape(document.forms.searchform.keywords.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "minprice=" + escape(document.forms.searchform.minprice.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "maxprice=" + escape(document.forms.searchform.maxprice.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "searchoffers=" + escape(document.forms.searchform.searchoffers.checked) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "products_per_page=" + escape(document.forms.searchform.products_per_page.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "reference_seq=" + escape(document.forms.searchform.reference_seq.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "price_seq=" + escape(document.forms.searchform.price_seq.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "sort_field=" + escape(document.forms.searchform.sort_field.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "view_notepad=" + escape(document.forms.searchform.view_notepad.value) + "; expires=" + expirydate.toGMTString() + ";";
}

   //function preventBack(){window.history.forward();} 

  //  setTimeout("preventBack()", 0); 

//    window.onunload=function(){null}; 

