// JScript source code for RSS feeds

// javascript by Ken Richardson
// for Emerald Isle Surf Shop, Emerald Isle, North Carolina
// questions/comments kenneth.r.richardson@gmail.com

/*-----------------------------------------------------------------------------
load and format RSS news feeds - Surfing, Standup Paddle Boarding, Bodyboarding
------------------------------------------------------------------------------*/


google.load("feeds", "1") //Load Google Ajax Feed API (version 1)
/*------------------------------------------------------------------------------
HOME PAGE SURF FEED LAYOUT
--------------------------------------------------------------------------------*/
function rssSurfdisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssSurfdisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}


rssSurfdisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput="<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<a href='news_surf.htm'>" + thefeeds[i].title + "</a>"
//var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""
var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>"
}
rssoutput += "<li><a href='news_surf.htm'>ASP Tour info, Rankings, News</a></li></ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

/*------------------------------------------------------------------------------
HOME PAGE SUP FEED LAYOUT
--------------------------------------------------------------------------------*/
function rssSUPdisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssSUPdisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}


rssSUPdisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput = "<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<a href='news_sup.htm'>" + thefeeds[i].title + "</a>"
//var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""
var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

/*------------------------------------------------------------------------------
HOME PAGE BODYBOARDING FEED LAYOUT
--------------------------------------------------------------------------------*/
function rssBodyboardingdisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssBodyboardingdisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}


rssBodyboardingdisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput = "<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<a href='news_bodyboarding.htm'>" + thefeeds[i].title + "</a>"
//var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""
var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

/*------------------------------------------------------------------------------
SURFING NEWS PAGE LAYOUT
--------------------------------------------------------------------------------*/
function rssSurfNewsPagedisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssSurfNewsPagedisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}

rssSurfNewsPagedisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput = "<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<H3>" + thefeeds[i].title + "</H3>"
var itemtitle="<a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""

var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li><br />"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

/*------------------------------------------------------------------------------
SUP NEWS PAGE LAYOUT
--------------------------------------------------------------------------------*/
function rssSUPNewsPagedisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssSUPNewsPagedisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}

rssSUPNewsPagedisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput = "<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<H3>" + thefeeds[i].title + "</H3>"
var itemtitle="<a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""

var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li><br />"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

/*------------------------------------------------------------------------------
BODYBOARDING NEWS PAGE LAYOUT
--------------------------------------------------------------------------------*/
function rssBodyboardingNewsPagedisplayer(divid, url, feedlimit, showoptions){
this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description")
var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API
feedpointer.setNumEntries(feedlimit) //set number of items to display
document.write('<div id="'+divid+'">Loading feed...</div>')
this.feedcontainer=document.getElementById(divid)
var displayer=this
feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed
}


rssBodyboardingNewsPagedisplayer.prototype.formatdate=function(datestr){

var itemdate=new Date(datestr)
var itemdateTime = itemdate.getTime();

var todaysDate = new Date();
var todaysTime = todaysDate.getTime();
var dayDiff = todaysDate - itemdate;
var timeDiff = (todaysTime - itemdateTime);
var timeDiffHour = Math.round((timeDiff / (60*60))/1000);
var timeDiffMinutes = Math.round((timeDiff / (60))/1000);
var timeDiffDays = Math.round(((todaysDate - itemdate) / (60*60*24)) / 1000);

if(timeDiffHour<1)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffMinutes + " minutes ago</i></span>"
}
else if (timeDiffHour>=1 && timeDiffHour<2)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hour ago</i></span>"
}
else if (timeDiffHour>=2 && timeDiffHour<24)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffHour + " hours ago</i></span>"
}
else if (timeDiffHour>=24 && timeDiffHour<35)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " day ago</i></span>"
}
else if (timeDiffHour>48)
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
else
{
    return "<span style='color:#7C99B5; font-size: 90%'>" + ' <i> - posted: ' + timeDiffDays + " days ago</i></span>"
}
}

rssBodyboardingNewsPagedisplayer.prototype.formatoutput=function(result){
if (!result.error){ //if RSS feed successfully fetched
var thefeeds=result.feed.entries //get all feed entries as a JSON array
var rssoutput = "<ul class='ul-style01'>"
for (var i=0; i<thefeeds.length; i++){ //loop through entries
var itemtitle="<H3>" + thefeeds[i].title + "</H3>"
var itemtitle="<a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a>"
var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : ""
var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+thefeeds[i].contentSnippet  : ""
rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li><br />"
}
rssoutput+="</ul>"
this.feedcontainer.innerHTML=rssoutput
}
else //else, output error
alert("Error fetching feeds: "+result.error.message)
}

//SYNTAX: new rssdisplayer("divid", "rssurl", numberofitems, "displayoptions")
