# Copyright (C) 2005 Bart van Kuik <bart@vankuik.nl>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
#    Free Software Foundation, Inc.
#    59 Temple Place, Suite 330
#    Boston, MA 02111-1307 USA

$ModulesDescription .= '<p>A module to easily include Google Adsense ads</p>';

use vars qw($AdSensePageName $AdSensePlace);

$AdSensePageName = "AdSense";
$AdSensePlace = "top";         # Can either be top or bottom

#
# You shouldn't need to modify anything below this line
#

if ($AdSensePlace eq 'top') {
    *OldGetHtmlHeader = *GetHtmlHeader;
    *GetHtmlHeader = *NewGetHtmlHeader;
} else {
    *OldPrintFooter = *PrintFooter;
    *PrintFooter = *NewPrintFooter;
}

sub NewPrintFooter {
    OldPrintFooter(@_);
    my ($title, $id) = @_;
    print GetAdSense();
}

sub NewGetHtmlHeader {
  my $result .= OldGetHtmlHeader(@_);
  $result .= GetAdSense();
  return $result;
}

sub GetAdSense {
  my $result = "";
  $curr_action = GetParam('action', 'browse');
  if ($curr_action eq 'browse') {
    $result = GetPageContent($AdSensePageName);
  }
  return $result;
}

