// @ According to Copyright and Warranty Notice that can be found at
// @ http://w.moreover.com/wizard/wizard_copyright.html (you can also find this
// @ notice in the readme.txt file distributed along with these modifications),
// @ this code may be freely modified and re-distributed. Please see the
// @ Moreover.com copyright notice at the end of this code. It and other code
// @ has been preserved in accordance with Moreover's copyright agreement.

// @ All modifications performed on the following code are Copyright
// @ Gemineye.biz 2002. By using these modifications, you agree to abide by the
// @ Moreover.com Copyright and Warranty Notice, and you agree to include this
// @ paragraph, the previous one, and any comments added to the code by myself.
// @ You can easily spot my comments and modifications, as they will be marked
// @ using the following syntax: "// @". In addition to the code enhancements
// @ performed, I have taken steps to beautify the existing code to make it
// @ easier to read and manage.

// @ Modification Name: Gemineye.biz Headline Wizard
// @ Modification Author: Corey Taylor (corey.taylor@gemineye.biz)
// @ Distributor: http://Gemineye.biz
// @ Last Modified: November 21, 2002
// @ File Name: HeadlineWizardJS.js
// @ Version: 1.0

// @ The following code is a JavaScript class which allows developers to
// @ easily create variations (in the form of objects) of the Moreover news
// @ headline wizard code. This class is not meant to work on its own. You must
// @ use some sort of wrapper class written in a scripting language which
// @ supports dynamic opening of URLs. Lucky for you I have written and
// @ included such a class written in PHP. Please refer to the file
// @ HeadlineWizardPHP.inc for more information.

// @ The following functions are the method definitions.

function set_table_width( tableWidth )
{
    this.tableWidth = tableWidth;
}

function set_table_row_bg_color( tableRowBgColor )
{
    this.tableRowBgColor = tableRowBgColor;
}

function begin_display_headlines()
{
  function load_wizard()
  {
      var newwin = window.open("","clone","resizable,scrollbars");
      document.forms.moreover_clone.submit();
      return true;
  }
}

function end_display_headlines()
{
  // load global_article array with articles from category
  if (article != null && (article.length > 0))
  {
      this.early_exit = false;

      for (var article_counter = 1; article_counter < article.length; article_counter++)
      {
          this.global_article[this.global_article_counter] = article[article_counter];
          this.global_article[this.global_article_counter].url += "&w=2143116";
          this.global_article[this.global_article_counter].url += "' TARGET='_blank";
          this.global_article[this.global_article_counter].document_url += "' TARGET='_blank";
          this.global_article_counter++;
      }
  }

  if (this.global_article.length == 0)
  {
      if (this.early_exit)
      {
          document.write("<center>Please reload this page to view the headlines</center>");
      }
      else
      {
          document.write("<center>Sorry, no articles matched your search criteria</center>");
          this.early_exit = true;
      }
  }

  // @ The following begins construction of the table that the headlines will
  // @ reside in.
  document.write(" <table cellpadding='0' cellspacing='0' border='0' width='" + this.tableWidth + "'>");
  document.write("  <tr bgcolor='" + this.tableRowBgColor + "'>");
  document.write("   <td>");

  if (!this.early_exit)
  {
        var wizard_brand        = "moreover";
        var webfeed_heading     = "";
        var width               = this.tableWidth;
        var numberofarticles    = this.global_article.length;
        var cluster_border      = "0";
        var time_display        = "Yes";
        var cell_spacing        = "0";
        var cell_padding        = "1";
        var time                = new Array(this.global_article.length);

        // Start loop for articles
        for (var counter=0; counter < numberofarticles; counter++)
        {
            if (this.global_article[counter].source.indexOf("Ad -") == -1) {
                if ((counter == (this.global_article.length - 1)) && this.moreover_text == 1)
                {
                    time_display = "No";
                }
    
                // Print out the headline
                document.write("<a href='"+this.global_article[counter].url+"' class='morehl'>");
                document.write(this.global_article[counter].headline_text+"...</a><br />");
    
                // Print out the source
                if ((counter != (this.global_article.length - 1)) || this.moreover_text != 1)
                {
                    document.write("<a href='"+this.global_article[counter].document_url+"' + class='moresrc'>");
                    document.write(this.global_article[counter].source+"</A>");
                }
    
                // Print out reg/sub/prem if appropriate
                if (this.global_article[counter].access_status == "sub" || this.global_article[counter].access_status == "reg" || this.global_article[counter].access_status == "prem")
                {
                    document.write("<span class='moreti'>&nbsp;</span><a href='"+this.global_article[counter].access_registration+"' class='moresrc'>");
                    document.write(this.global_article[counter].access_status+"</A>");
                }
    
                // Print out the harvest time
                if (time_display == "Yes")
                {
                    // Make a new date object
                    time[counter] = new Date(this.global_article[counter].harvest_time);
                    time[counter].setHours(time[counter].getHours() - (time[counter].getTimezoneOffset() / 60 ));
                    document.write("<span class='moreti'> &nbsp;"+time[counter].toString()+"<br />&nbsp;<br /></span>");
                }
                else
                {
                    document.write("<br />&nbsp;<br />");
                }
            }
        } // End of article loop

    // Start of clone button code //
    // NOTE: DO NOT REMOVE any of the code in this section //
    document.write("<form method='post' action='http://www.moreover.com/cgi-local/wizard_welcome.pl' target='clone' name='moreover_clone'>");

    document.write("<input type='hidden' name='parent_code' value='2143116'>");
    document.write("<input type='hidden' name='clone_system' value='c'>");
    document.write("<input type='hidden' name='system' value='c'>");
    document.write("<input type='hidden' name='heading_font_size' value=''><input type='hidden' name='headline_bgcolor' value='1A4E94'>")
    document.write("<input type='hidden' name='webfeed_heading' value=''><input type='hidden' name='cluster_width' value='200'>")
    document.write("<input type='hidden' name='cluster_name' value='query=" + this.keyword + "%20&o=js'><input type='hidden' name='source_time_underline' value='false'>")
    document.write("<input type='hidden' name='time_display' value='Yes'><input type='hidden' name='heading_display' value='Yes'>")
    document.write("<input type='hidden' name='headline_fgcolor' value='ffffff'><input type='hidden' name='cluster_cellspacing' value='0'>")
    document.write("<input type='hidden' name='number_of_headlines' value='10'><input type='hidden' name='source_time_fgcolor' value='cccccc'>")
    document.write("<input type='hidden' name='headline_font_size' value='10'><input type='hidden' name='search_keywords' value='" + this.keyword + "'>")
    document.write("<input type='hidden' name='source_time_font_size' value='10'><input type='hidden' name='headline_italic' value='false'>")
    document.write("<input type='hidden' name='headline_font' value='Arial, geneva, sans-serif'><input type='hidden' name='source_time_italic' value='false'>")
    document.write("<input type='hidden' name='source_time_font' value='Arial, geneva, sans-serif'><input type='hidden' name='wizard_brand' value='moreover'>")
    document.write("<input type='hidden' name='cluster_cellpadding' value='1'><input type='hidden' name='headline_bold' value='false'>")
    document.write("<input type='hidden' name='cluster_border' value='0'><input type='hidden' name='source_time_bold' value='false'>")
    document.write("<input type='hidden' name='headline_underline' value='true'><input type='hidden' name='cluster_layout' value='<br />'>")

    document.write("</form>");

    // End of clone button code //

    // ************************************************************************************
    // This code is subject to the copyright and warranty restrictions detailed at
    // http://www.moreover.com/wizard_copyright.html
    // Copyright 2000 Moreover.com Inc. All rights reserved.
    // *************************************************************************************

    }

    //document.write('<script language="JavaScript" src="http://p.moreover.com/dr/wizard/wizard_text.js"></script>');

    document.write('   </td>');
    document.write('  </tr>');
    document.write(' </table>');

}

// @ The following function is the constructor for this class.

function HeadlineWizard( keyword, articlesDesired, tableWidth )
{
    // @ I modified the following fields to be initialized once an object
    // @ is instantiated.
    // the array global_article is used to allow multiple categories
    this.global_article = new Array();
    this.global_article_counter = 0;
    this.article = null;
    this.early_exit = true;
    this.moreover_text = 0;

    // @ Initialize the object's properties/variables

    this.keyword = keyword; // @ The keyword for the headline topics.
    this.articlesDesired = articlesDesired; // @ The ammount of articles to
                                            // @ get. Defaults to 10.

    this.tableWidth = tableWidth; // @ This field controls the width of the
                                  // @ table which surrounds the headlines.
                                  // @ Defaults to 200.
    this.tableRowBgColor = ""; // @ This field controls the bgcolor
                               // @ of the table row which contains
                               // @ the headlines. Defaults to nada.

    // @ Define the methods to be used on this object.

    this.setTableWidth = set_table_width;
    this.setTableRowBgColor = set_table_row_bg_color;
    this.beginDisplayHeadlines = begin_display_headlines;
    this.endDisplayHeadlines = end_display_headlines;
}
