# -*- Mode:Perl; -*-
# Time-stamp: <2001/05/24 (Thu) 20:38:29 m-hase@ceres.dti.ne.jp>
#

################################################################
#  $Head{dynamic} = qq(<meta http-equiv="Content-Style-Type" content="text/css">
#  <style type="text/css"><!--
#   span.isbn { color: gray; FONT-SIZE: 9pt; }
#   span.cd { color: gray; FONT-SIZE: 9pt; }
#  --></style>
#  );

################################################################
### Append AllowCommands
package HNS::Hnf::Command::New;
$AllowCommands = [ $HNS::Hnf::Command::New::AllowCommands,'ISBN','CD'];

package HNS::Hnf::Command::Sub;
$AllowCommands = [ $HNS::Hnf::Command::Sub::AllowCommands,'ISBN','CD'];

package HNS::Hnf::Command::LI;
$AllowCommands = [ $HNS::Hnf::Command::LI::AllowCommands,'ISBN','CD'];

################################################################
### ISBN
package HNS::Hnf::Command::ISBN;
use vars qw(@ISA $Template $EndTemplate $NumAttr $IsOneline $AllowCommands
	    $IsBeginSection $CountName $OmittableEnd 
	    $ContentTemplate $Separator @Stores );

@ISA = qw(HNS::Hnf::Command::Inline);
$AllowCommands = [$HNS::Hnf::Command::Entities{'Inline'}];
$NumAttr = 1;
$Template = qq(<strong>%content</strong><span class="isbn">[ISBN%code: %stores]</span>);
$EndTemplate = qq(<br>\n);
$ContentTemplate = qq(<a href="%url">%name</a>);
$Separator = "/";
@Stores = ({'name'=>'eS',
	    'url'=> qq(http://www.eshopping.ne.jp/bks.svl?CID=BKS504&amp;access_method=isbn_cd&amp;input_data=%code)},
	   {'name'=>'bk',
	    'url'=> qq(http://www.bk1.co.jp/cgi-bin/srch/srch_result_book.cgi?idx=3&amp;isbn=%code)},
	   {'name'=>'IS',
	    'url'=> qq(http://www.isize.com/book/cgi-bin/isbn.cgi?isbn=%code)},
	   {'name'=>'',
	    'url'=> qq(http://www.netdirect.co.jp/search/ISSSchDetail.asp?ISBN=%code_no_bar)},
	   {'name'=>'JB',
	    'url'=> qq(http://www.jbook.co.jp/product.asp?isbn=%code_no_bar)},
	   {'name'=>'BO',
	    'url' => qq(http://www.jp.bol.com/cec/cstage?ecaction=bcssearch&amp;query_type=BS_ISBN&amp;isbn=%code_no_bar)},
	   {'name'=>'I',
	    'url'=> qq(http://bookweb.kinokuniya.co.jp/guest/cgi-bin/wshosea.cgi?W-ISBN=%code_no_bar)},
	   {'name'=>'AM',
	    'url'=> qq(http://www.amazon.co.jp/exec/obidos/ASIN/%code_no_bar)},
	   {'name'=>'x',
	    'url'=> qq(http://www.fujisan.com/online/Jsearch?key=productcode&amp;value=%code_no_bar)},
	   {'name'=>'{',
	    'url'=> qq(http://www1.honyasan.co.jp/washo/book.cfm?PRODUCT_CD=%code)});

sub AsHTML($$$)
{
    my ($self, $start, $params) = @_;
    my $code = $self->{attr}->[1];
    my $code_no_bar = $code;
    $code_no_bar =~ s/\-//g;
    
    my $templ = new HNS::Template;
    my @contents;
    for (@Stores){
	my $name = $_->{'name'};
	my $url = $_->{'url'};
	my $tmp_params;
	$tmp_params->{url} = $templ->Expand($url, {'code'=>$code,
						   'code_no_bar'=>$code_no_bar});
	$tmp_params->{name} = $name;
	push(@contents, $templ->Expand($ContentTemplate, $tmp_params));
    }
    $params->{stores} = join($Separator, @contents);
    $params->{code} = $code;

    return $self->SUPER::AsHTML($start, $params);
}


################################################################
### CD
package HNS::Hnf::Command::CD;
use vars qw(@ISA $Template $EndTemplate $NumAttr $IsOneline $AllowCommands
	    $IsBeginSection $CountName $OmittableEnd 
	    $ContentTemplate $Separator @Stores );

@ISA = qw(HNS::Hnf::Command::Inline);
$AllowCommands = [$HNS::Hnf::Command::Entities{'Inline'}];
$NumAttr = 1;
$Template = qq(<strong>%content</strong><span class="cd">[%code: %stores]</span>);
$EndTemplate = qq(<br>\n);
$ContentTemplate = qq(<a href="%url">%name</a>);
$Separator = "/";
@Stores = ({'name'=>'hm',
	    'url'=> qq(http://www.hmv.co.jp/search/title.asp?category=CATALOGUENO&amp;keyword=%code)},
	   {'name'=>'To',
	    'url'=> qq(http://www.towerrecords.co.jp/tower/towercdj.nsf/SearchProductID/%code)},
	   {'name'=>'',
	    'url'=> qq(http://www.netdirect.co.jp/search/ISSSchDetail.asp?ISBN=%code_no_bar)},
	   {'name'=>'JB',
	    'url'=> qq(http://sea.jbook.co.jp/search97cgi/s97_cgi.exe?Action=Search&ResultTemplate=search_result_40.hts&QueryText=%28%28+%code+%29%3cIN%3etext_area%29+and+sale_status_asc_all)},
	   {'name'=>'V',
	    'url'=> qq(https://cd2.shinseido.co.jp/cgi-bin/ehsql_select/ec/slist10.ehtml?eh-dbase=ecdb&amp;eh-table=product&amp;eh-key-attribute=pro_no&amp;pro_recno=%code)} );


sub AsHTML($$$)
{
    my ($self, $start, $params) = @_;
    my $code = $self->{attr}->[1];
    my $code_no_bar = $code;
    $code_no_bar =~ s/\-//g;
    
    my $templ = new HNS::Template;
    my @contents;
    for (@Stores){
	my $name = $_->{'name'};
	my $url = $_->{'url'};
	my $tmp_params;
	$tmp_params->{url} = $templ->Expand($url, {'code'=>$code,
						   'code_no_bar'=>$code_no_bar});
	$tmp_params->{name} = $name;
	push(@contents, $templ->Expand($ContentTemplate, $tmp_params));
    }
    $params->{stores} = join($Separator, @contents);
    $params->{code} = $code;

    return $self->SUPER::AsHTML($start, $params);
}