#!/usr/bin/perl -w

use strict;

my $google_search = q!
<a href="#"><span class="sidelink" onClick="getElementById('google_search').style.display = 'block';">Search</span></a>
<div id="google_search" style="width: 500px; position: absolute; top: 100px; left: 100px; border: 1px solid DarkRed; background: White; z-index: 100; display: none">
<div id="close_X" style="float: right; margin: 5px; padding: 5px; border: 1px solid Gray" onClick="getElementById('google_search').style.display = 'none';"><a href="#" style="text-decoration: none; color: black; font-family: Arial">X</a></div>
<script>
  (function() {
    var cx = '016081325033090261488:uhmmwk_9eck';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
!;

my $file; 
my $filecontents;

for($file=0;$file<=$#ARGV;$file++)
  {
  warn "Opening $ARGV[$file] for reading...\n";
  if(!open(FH,$ARGV[$file]))
    {
    warn "Couldn't open $ARGV[$file] for reading\n";
    next;
    }
  while(<FH>)
    {
    $filecontents = $filecontents.$_;
    }
  close(FH);

  print "Evaluating sub....\n";
  $filecontents =~ s/\<A.HREF\=\"http\:\/\/www\.picosearch\.com\/cgi-bin\/ts0\.pl\?index\=140395\"\>\<SPAN.CLASS\=\"sidelink\"\>Search\<\/SPAN\>\<\/A\>/$google_search/gs;

  warn "Opening $ARGV[$file] for writing...\n";
  if(!open(OFH,">$ARGV[$file]"))
    {
    warn "Couldn't open $ARGV[$file] for writing\n";
    next;
    }
  print OFH $filecontents;
  close(OFH);
  $filecontents = "";
  }

#EOF
