//
// This file and the code in this file are CopyRighted (c) 2004
//
//           to EasyByte Software Corporation Ltd
//
// Only once you have purchased a NewsFeed license from us are 
// you allowed to make any changes to this file beyond the general
// config parameters.
//
// www.easybyte.com/buy/ 
//
//
// You may try the NewsFeeds out on your website for upto one week
// for free, beyond that you will have to pay for them.
// 


// BEGIN general config parameters   
   var nArticlesToDisplay = 5;
   var webfeedHeading = "";
   var shouldDisplayHeading = true;
   var shouldDisplayTime    = false;
   var erfDisplaySource     = true;
   var openNewWindow        = false;
   
   var scrollVertical = false;
   var scrollHorizontal = false;  
// END   general config parameters


if (scrollVertical && scrollHorizontal)
{
 scrollVertical = scrollHorizontal = false;
}

// BEGIN marquee parameters
//
var marqueeScrollAmount = 2;
var marqueeScrollDelay = 60;

var displayVertical = true; // by default, the news are displayed vertically.
var marqueeWidth="300px";
var marqueeHeight="120";

if (scrollHorizontal == true)
{
 displayVertical = false;
 marqueeWidth="480px";
 marqueeHeight="20px";
}

// END marquee parameters

// BEGIN news items separarators
//  ________ Article ________
// /                          \   <--- articleSeparator
// Headline Source Access Time
//         ^      ^      ^    ^
//         |      |      |    |
//         |      |      |    timeSeparator(*)
//         |      |      accessSeparator
//         |      sourceSeparator
//         headlineSeparator
//
var headlineSeparator="\n";
var sourceSeparator="\n";
var accessSeparator="\n";
var timeSeparatorIfDisplayTime="";
var timeSeparatorIfNotDisplayTime="";
var articleSeparator="<tr><td class='headline-spacing'></td></tr>";

if (!displayVertical) 
{
 headlineSeparator=" : ";
 sourceSeparator=" ";
 accessSeparator=";";
 timeSeparatorIfDisplayTime=".";
 timeSeparatorIfNotDisplayTime="";
 articleSeparator="¦¦"; // or perhaps an image
}
// END   news items separators


function beginMarquee()
{
 if (scrollVertical == scrollHorizontal)
 {
  return;
 }

 theDirection = "up";

 if (scrollHorizontal == true)
 {
  theDirection = "left";
 }

 document.writeln("<marquee class='heading' behavior='scroll' direction='"+theDirection+"' width='"+marqueeWidth+"' height='"+marqueeHeight+"' scrollamount='"+marqueeScrollAmount+"' scrolldelay='"+marqueeScrollDelay+"' onmouseout='this.start()'>");
}

function endMarquee()
{
 if (scrollVertical == scrollHorizontal)
 {
  return;
 }

 document.writeln("</marquee>");
}

function beginItem()
{
 if (displayVertical) 
 {
  document.writeln("<tr><td>");
 }
}

function endItem()
{
 if (displayVertical) 
 {
  document.writeln("</td></tr>");
 }
}

// This function is called from writeArticle
//
function writeLink(formattingClass, theUrl, displayText, theTail)
{
 document.write("<A class='"+formattingClass+"' HREF='"+theUrl+"' >" + displayText + "</A>" + theTail);
}

// Write the News Feed heading in, if one has been defined and the config
// setting set to true
//
function writeHeading()
{
 if (shouldDisplayHeading == true)
 {
  beginItem();
  document.writeln("<span class='heading'>" + webfeedHeading + "</span>");
  endItem();
 }
}


// If it is set to write the time in, make it relative to local time
// for the person viewing that pages.
//
function writeTime(harvestTime, displayTime)
{
 if (displayTime == true)
 {
  time = new Date(harvestTime);
  time.setHours(time.getHours() - (time.getTimezoneOffset() / 60 ));
  document.writeln("<span class='time'>" + time.toString() + "</span>");
  document.writeln(timeSeparatorIfDisplayTime);
 } 
 else 
 {
  document.writeln(timeSeparatorIfNotDisplayTime);
 }
}


// This function writes each headline into the webpage using the config
// settings that are defined at the top of this file
//
function writeArticle(theArticle, theHeadlineClass, displayTime)
{
 beginItem();

 document.writeln("<span class='headline'>");
 writeLink(theHeadlineClass, theArticle.url, theArticle.headline_text + "...", headlineSeparator);
    
 if (erfDisplaySource == true)
 {
  writeLink("source", theArticle.document_url, theArticle.source, sourceSeparator);
 }
    
 if (theArticle.access_status == "sub" || theArticle.access_status == "reg")
 {
  writeLink("access", theArticle.access_registration, theArticle.access_status, accessSeparator);
 }

 writeTime(theArticle.harvest_time, displayTime);
 document.writeln("</span>");
 endItem();
 document.writeln(articleSeparator);
}


//
// The code that powers the feed follows from here
//
if (article == null)
{
 article = new Array();
}

// Check to make sure we have the news feed file ok
//	
if (article.length == 0)
{
 document.writeln("<center>Please reload this page to view the News/Information</center>");
}
else
{
 // Make changes as required to define whether or not clicking on the
 // headlines will make them open up in a new window.
 //
 for (var i = 0; i < article.length; i++)
 {
  var theTarget="_top";

  if (openNewWindow == true)
  {
   theTarget="_blank";
  }

  article[i].url += "' TARGET='" + theTarget;
  article[i].document_url += "' TARGET='" + theTarget;
 }    

  // Work out how many articles to display
  //
  if (nArticlesToDisplay > article.length)
  {
   nArticlesToDisplay = article.length;
  }

  var articleERF = new sa("http://www.easybyte.com/products/addjs.html", "News by ERF - add some to your website", "Powered by ERF", "text", " ", " ",	"http://www.easybyte.com/products/addjs.html", article[0].harvest_time, " ", " ");

  beginMarquee();  

  // Write in the start of the table structure into the web page
  //
  if (displayVertical)
  {
   document.writeln("<table class='layout'>");
   document.writeln("<tr><td align='center'> </td></tr>")
   document.writeln("<tr><td align='center'>");
   document.writeln("<table class='headlines'>");
  }
  
  // Write the News Feed heading into the web page, if it is set so in
  // config section at the top of the page
  //
  writeHeading();

  // We have the News Feed file ok and config settings switched so now
  // we loop through it and display the headlines in the webpage, using
  // the config options that are set at the top of this file.
  //
  for (var i=0; i < nArticlesToDisplay; i++)
  {
   writeArticle(article[i], 'headline', shouldDisplayTime);
  }
  
  // You are not allowed to remove or edit this line until you have
  // purchased the rights to use the feed on your site.
  //
  // The order forms are located at:
  //
  //      www.easybyte.com/buy/
  // 
  //
  //  writeArticle(articleERF, 'headline', false);

  // Finish the table structure off
  //
  if (displayVertical)
  {
   document.writeln("</table></td></tr></table>");
  }
  
  endMarquee();  
}
