#!/usr/bin/perl

MAIN:
{

	$server = $ENV{'SERVER_NAME'};
	$query  = $ENV{'QUERY_STRING'};
	$query0 = $query;
	$query0 =~ s/\&price\_range\=.*//g;

	$domain = $server;
	if   ( $domain =~ m/sex\-superstore/i ) { $domain = '.sex-superstore.com' }
	else                                    { $domain = '' }

	#affiliate flag
	if (    !( $server =~ m/pexxx/i )
		and !( $server =~ m/privateentertainment/i )
		and !( $server =~ m/myadultwarehouse/i ) )
	{
		$aff_flag = 1;
	}
	if (   $server =~ /shop\.sex\-superstore\.com/i
		or $server =~ /store\.sex\-superstore\.com/i
		or $server =~ /store\.dev\.sex\-superstore\.com/i
		or $server =~ /shop\.dev\.sex\-superstore\.com/i )
	{
		$aff_super = 1;
	}

	$status = 'date';

	#niche specific
	if ( $server =~ /hetero/i ) {
		@asso00 = ( 'hotdeal', 'hetero', 'allgirl' );
		@asso0 = (
			'hetero',      'Hetero',
			'allgirl',     'All Girl',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0 = @asso0;
		@races = ( 'black', 'white', 'asian', 'interracial', 'latin' );
		$init_def = 'hetero';    #default initial category
		$query_def = "(initial='hetero' or initial='allgirl')";   #query default
		$query_def1 = $query_def;    #query modifier only for niches
		$niche1     = 'Hetero';      #for top20
	}
	elsif ( $server =~ /allmale/i ) {
		@asso00 = ( 'hotdeal', 'allmale', 'bisex' );
		@asso0 = (
			'allmale',     'AllMale',
			'bisex',       'BiSexual',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0      = @asso0;
		@races      = ( 'black', 'white', 'asian', 'interracial', 'latin' );
		$init_def   = 'allmale';
		$query_def  = "(initial='allmale' or initial='bisex')";
		$query_def1 = $query_def;
		$niche1     = 'Allmale';
	}
	elsif ( $server =~ /transsexual/i ) {
		@asso00 = ( 'hotdeal', 'trans', 'bisex' );
		@asso0 = (
			'trans',       'Transsexual',
			'bisex',       'BiSexual',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0      = @asso0;
		@races      = ( 'black', 'white', 'asian', 'interracial', 'latin' );
		$init_def   = 'trans';
		$query_def  = "(initial='trans' or initial='bisex')";
		$query_def1 = $query_def;
		$niche1     = 'Transsexual';
	}
	elsif ( $server =~ /fetish/i ) {
		@asso00 = ( 'hotdeal', 'fetish', 'bondage' );
		@asso0 = (
			'fetish',      'Fetish',
			'bondage',     'Bondage',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0      = @asso0;
		@races      = ( 'black', 'white', 'asian', 'interracial', 'latin' );
		$init_def   = 'fetish';
		$query_def  = "(initial='fetish' or initial='bondage')";
		$query_def1 = $query_def;
		$niche1     = 'Fetish';
	}
	elsif ( $server =~ /interracial/i ) {
		@asso00 = (
			'hotdeal', 'hetero',  'fetish', 'bondage',
			'allgirl', 'allmale', 'bisex',  'trans'
		);
		@asso0 = (
			'hetero',      'Hetero',
			'fetish',      'Fetish',
			'bondage',     'Bondage',
			'allgirl',     'All Girl',
			'allmale',     'All Male',
			'bisex',       'BiSexual',
			'trans',       'Transsexual',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0    = @asso0;
		@races    = ( 'black', 'interracial', 'asian', 'latin' );
		$init_def = 'hetero';
		$query_def =
"(initial='hetero' or initial='fetish' or initial='bondage' or initial='allgirl')";
		$query_add =
		  "and (sub='black' or sub='interracial' or sub='asian' or sub='latin')"
		  ;    #additional query modifier
		$query_def1 = $query_def;
		$niche1     = 'Interracial';
	}
	else {     #SuperStore
		@asso00 = (
			'hotdeal', 'hetero',  'fetish', 'bondage',
			'allgirl', 'allmale', 'bisex',  'trans'
		);
		@asso0 = (
			'hetero',      'Hetero',
			'fetish',      'Fetish',
			'bondage',     'Bondage',
			'allgirl',     'All Girl',
			'allmale',     'All Male',
			'bisex',       'BiSexual',
			'trans',       'Transsexual',
			'voldiscount', 'Volume Discount',
			'hotdeal',     'Hot Deals!',
			'top20',       'Top 20',
			'all',         'New Releases'
		);
		%asso0 = @asso0;
		@races = (
			'black', 'white',   'asian', 'interracial',
			'latin', 'allgirl', 'bondage'
		);
		$init_def = 'hetero';
		$query_def =
"(initial='hetero' or initial='fetish' or initial='bondage' or initial='allgirl' or initial='bisex' or initial='trans')";
		$niche1 = 'Superstore';
	}

	if   ($query_def1) { $query_def2 = "and $query_def1" }
	else               { $query_def2 = '' }

	use CGI;
	$foo = new CGI;

	#DATE
	local ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
	  localtime(time);
	$year = 1900 + $year;
	local (@month) = (
		'January',   'February', 'March',    'April',
		'May',       'June',     'July',     'August',
		'September', 'October',  'November', 'December'
	);
	local ($mo) = $month[$mon];

	&ReadParse;
	(
		$ecode,      $text, $type,       $criteria, $last_list,
		$first_list, $fam,  $hotdeal,    $discount, $bestseller,
		$top20,      $init, $dozen_list, $letter,   $search,
		$init1,      $race, $affiliate,  $price_range
	  )
	  = (
		$in{'ecode'},      $in{'text'},      $in{'type'},
		$in{'criteria'},   $in{'last_list'}, $in{'first_list'},
		$in{'fam'},        $in{'hotdeal'},   $in{'discount'},
		$in{'bestseller'}, $in{'top20'},     $in{'init'},
		$in{'dozen_list'}, $in{'letter'},    $in{'search'},
		$in{'init1'},      $in{'race'},      $in{'af'},
		$in{'price_range'}
	  );
	  
	# INSERTED 2/9/2010 BY SCOTT TO PREVENT SQL INJECTION
	if (length($ecode) > 10) {
		die('Invalid Parameter');
	}
	  
	if ( $text eq 'hotdeal' or $init eq 'hotdeal' ) { $hotdeal = 'Yes' }
	if ( $init eq 'top20' ) { $top20 = 'Yes' }

	if ( $criteria eq 'voldiscount' or $init eq 'voldiscount' ) {
		$discount = 'Yes';
		$init     = 'voldiscount';
	}
	if ( $criteria eq 'init' ) { $init = $text }
	if ( !$init and !$criteria ) { $init = 'all' }

	&get_cookie;
	$stock = $cookie{'stock'};
	$stock = substr( $stock, 0, 1 );
	if (
		!$stock
		or (    $stock ne 'N'
			and $stock ne 'T'
			and $stock ne 'A'
			and $stock ne 'P'
			and $stock ne 'O'
			and $stock ne 'F'
			and $stock ne 'D' )
	  )
	{
		$stock = 'N';
	}
	if ( $stock ne 'N' ) { $inv_mod = " and inventory.available='$stock'"; }
	else {
		$inv_mod = " and (inventory.available='T' or inventory.available='P')";
	}
	$res_field = 'results';
	if ( $stock eq 'T' ) { $sel_T = 'selected'; $res_field = 'res_T' }
	if ( $stock eq 'A' ) {
		$sel_A     = 'selected';
		$inv_mod   = '';
		$res_field = 'res_A';
	}
	if ( $stock eq 'P' ) { $sel_P = 'selected'; $res_field = 'res_P' }
	if ( $stock eq 'O' ) { $sel_O = 'selected'; $res_field = 'res_O' }
	if ( $stock eq 'F' ) { $sel_F = 'selected'; $res_field = 'res_F'; }
	if ( $stock eq 'D' ) { $sel_D = 'selected'; $res_field = 'res_D'; }

	if ( !( $affiliate =~ /^\d/ ) ) {
		$affiliate = $cookie{'affiliate'};
	}
	$affiliate =~ s/\D.*//s;
	if ( !( $affiliate =~ /^\d/ ) ) { $affiliate = 0 }

	if ($fam) {
		foreach $rc (@races) {
			if ( $fam eq $rc ) { $race = $fam }
		}
	}

	if ( !$dozen )      { $dozen      = 1 }
	if ( !$dozen_list ) { $dozen_list = 1 }
	$dozen0      = $dozen - 1;
	$dozen1      = $dozen + 1;
	$dozen_list0 = $dozen_list - 1;
	$dozen_list1 = $dozen_list + 1;
	$first_list0 = $first_list;
	$last_list0  = $last_list;

	if ( !$init1 and ( $discount eq 'Yes' ) ) { $init1 = $init_def }

	$type  = 'dvd';
	$type3 = $type;

	$text3 = $foo->escape($text);

	if ($price_range) { $price_app = "&price_range=$price_range" }

	require("../inc/dbc.dat");

	#product DB retrieve
	$table  = 'date_' . $type;
	$table1 = 'aph_' . $type;

	$sql = $dbh->prepare(
" SELECT product_name,saleprice,price,manufacturer,pimage,voldiscount,synopsis,stars,prod_year,run_time,available,DATE_FORMAT(date_mod, '%M %e, %Y'),bigkey,initial,sub,family1,family2,show_front,show_back
     FROM $table,inventory
     WHERE $table.item='$ecode' and inventory.item='$ecode'
     "
	);
	$sql->execute();
	
	#Block for e-Codes not existing under selected category - ThomasW
    	if ($sql->rows eq 0) {
		die "Error: This product can not be found under the selected category.\n"
	}
	
	(
		$name,      $saleprice, $price,      $manufacturer, $image,
		$onsale,    $synopsis,  $star,       $prodyear,     $runtime,
		$available, $dateav,    $key,        $init0,        $sub,
		$family1,   $family2,   $show_front, $show_back
	) = $sql->fetchrow_array;
	$sql->finish();

	#get rating
	$sql = $dbh->prepare(
		" SELECT reviews,rating_ave
     FROM rating
     WHERE item='$ecode'
     LIMIT 1
     "
	);

	$sql->execute();
	( $reviews, $rating_ave ) = $sql->fetchrow_array;
	$sql->finish();

	$init = $init0;
	$rating1 = sprintf "%.0f", $rating_ave;

###CATEGORY & family SELECT

	if ( $criteria eq 'init' ) { $init = $text }
	$text_type = $type;

	open( FILEHANDLE, "< store.txt" ) or print 'Cannot open file';
	while (<FILEHANDLE>) { chop $_; $code .= $_ }
	close(FILEHANDLE);
	eval($code);
	%assa3 = @asso3;
	%assa1 = @asso1;
	%assa0 = @asso0;

	$fam_number = ( $#asso1 + 1 ) / 2;

	$initial = $assa0{$init};
	if ( !$text ) { $text = $initial }

	$family = $assa1{$fam};

	if ( $criteria eq 'init' ) {
		$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&type=$type&text=$text3&criteria=init' class='text1large'>$assa3{$text}</a>";
	}
	if ($fam) {
		$fam1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&fam=$fam' class='text1large'>$family</a>";
	}
	if ($init1) {
		$fam1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init1=$init1&criteria=$criteria&text=$text3' class='text1large'>$asso0{$init1}</a>";
	}
	if ($init1) {
		$fam1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init1=$init1&criteria=$criteria&text=$text3' class='text1large'>$asso0{$init1}</a>";
	}
	if ($race) {
		$race1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&race=$race' class='text1large'>$assa1{$race}</a>";
		if ( $race eq $fam ) { $fam1 = '' }
		else { $add_race = "&nbsp;&nbsp;&nbsp;$assa1{$race}<br>" }
		$and_race = "AND sub='$race'";
	}

	#show stream
	$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&text=$text3&criteria=$criteria' class='text1large'>$text</a>";
	if ( $hotdeal eq 'Yes' ) {
		$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init=hotdeal' class='text1large'>Hot Deals!</a>";
		$addition = '&hotdeal=Yes';
	}
	if ( $discount eq 'Yes' ) {
		$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&discount=Yes' class='text1large'>Volume Discounts</a>";
		$addition = '&discount=Yes';
	}
	if ( $bestseller eq 'Yes' ) {
		$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&bestseller=Yes' class='text1large'>Bestsellers</a>";
		$addition = '&bestseller=Yes';
		$pth      = 'pimage';
	}
	if ( $top20 eq 'Yes' ) {
		$text1 =
" &GT; <a href='/cgi-bin/dvd.cgi?af=$affiliate&init=top20' class='text1large'>Top 20</a>";
	}
	$type1 =
"<a href='/cgi-bin/dvd.cgi?af=$affiliate' class='text1large'>Adult DVD</a>";

	@split_star = split( /,/, $star );

	if ( $available eq 'T' ) {
		$available1 = '1 to 2 business days';
		$available2 = 'IN STOCK';
	}
	if ( $available eq 'F' ) {
		$available1 = '10 to 15 business days';
		$available2 = 'SPECIAL ORDER';
	}
	if ( $available eq 'P' ) {
		$available1 = 'upon release';
		$available2 = 'PRE-ORDER';
	}
	if ( $available eq 'O' ) {
		$available1 = '10 to 15 business days';
		$available2 = 'ON ORDER';
	}
	if ( $available eq 'D' ) {
		$available1 = 'not available';
		$available2 = 'NOT AVAILABLE';
	}

	$onsale1 = $onsale;
	$sale    = '';
	if ( $onsale eq 'T' ) {
		$onsale1 = 1;
		$sale =
'<img src="/ahtml/images/sale.gif" align=absmiddle width=35 height=16 border=0 alt="Volume Discounts">';
	}
	if ( $onsale eq 'C' ) {
		$sale =
'<img src="/ahtml/images/salec.gif" align=absmiddle width=35 height=16 border=0 alt="Volume Discounts">';
	}
	if ( $onsale eq 'F' ) { $onsale1 = 0; }

	#check VHS

	#$name2 = $dbh->quote($name);

	# $sqlD =
	#     $dbh->prepare( " SELECT video.item
	#     FROM video,inventory
	#     WHERE video.product_name=$name2 and video.item=inventory.item $inv_mod
	#     ");

	#    $sqlD->execute();

	#    ($ecode_vhs)=$sqlD->fetchrow_array;

	#    $sqlD->finish();

#if($ecode_vhs){$vhs = "
#             <tr>
#              <td class='blackbold' height=22>Also available on <a href=/cgi-bin/video2.cgi?af=$affiliate&ecode=$ecode_vhs&init=$init>VHS</a></td>
#             </tr>"}
#else{$vhs = ''}

	#alphabetic list

	if ( $init and $init ne 'all' ) {
		$where_list = "WHERE initial='$init'";
	}
	else {
		$where_list = "WHERE $query_def";
	}

	if ( $criteria eq 'title' )        { $crt = 'product_name' }
	if ( $criteria eq 'manufacturer' ) { $crt = 'manufacturer' }
	if ( $criteria eq 'star' )         { $crt = 'stars' }
	if ( $criteria eq 'ecode' )        { $crt = 'inventory.item' }
	if ( $criteria eq 'init' )         { $crt = 'initial' }
	if   ( $text ne 'all' ) { $textE = "%" . $text . "%"; }
	else                    { $textE = "%" . "%"; }
	$textE = $dbh->quote($textE);

	if ( $criteria or $init1 ) {
		$where_list = "WHERE $crt LIKE $textE $query_def2";
		if ($init1) { $where_list = $where_list . " and initial='$init1'"; }
	}

	if ($fam) {
		if ( $fam =~ m/\d\-\d/ ) {
			( $time1, $time2 ) = split /-/, $fam;
			$where_list =
			  $where_list . " and run_time>=$time1 and run_time<=$time2";
		}
		else {
			$where1 = "or sub='$fam'";
			$where_list =
			  $where_list . " and (family1='$fam' or family2='$fam' $where1)";
		}
	}
	if ($race) {
		$where_list = $where_list . " and sub='$race'";
		$sql        = $dbh->prepare(
			" SELECT family_list
                 FROM races_dvd
                 WHERE initial='$init' AND race='$race'
                 LIMIT 1
                 "
		);

		$sql->execute();
		$fam_list = $sql->fetchrow_array;
		$sql->finish();
		@family_list = split /,/, $fam_list;
		@family_list = ( @races, @family_list );
		$fam_number = 1 + $#family_list;
	}

	if ( $hotdeal eq 'Yes' ) {
		$where      = "WHERE hotdeals='T'";
		$where_list = "WHERE hotdeals='T'";
		if ($fam) {
			if ( $fam =~ m/\d\-\d/ ) {
				( $time1, $time2 ) = split /-/, $fam;
				$where_list =
				  $wher_list . " and run_time>=$time1 and run_time<=$time2";
			}
			else {
				$where1     = "or sub='$fam'";
				$where_list = $where_list
				  . " and (initial='$fam' or family1='$fam' or family2='$fam' $where1)";
			}
		}
	}

	if ( $discount eq 'Yes' ) {
		$where_list = "WHERE voldiscount='T'";
		if ($init1) { $where_list = $where_list . " and initial='$init1'"; }
	}

	if ( $top20 eq 'Yes' ) {
		$table      = 'aph_' . $type;
		$table1     = $table;
		$top20table = 'top_20,';
		$where_list =
		  "WHERE top_20.type = '$type' AND top_20.niche = '$niche1'";
		$order_list = ',top_20.rank';
		$tmptable   = 'top_20';
		$tmp20mod   = " and aph_$type.item=inventory.item";
	}
	else {
		$tmptable = 'inventory';
	}
	$where_list0 = $where_list;
	if ($last_list) { $where_list = $where_list . " and bigkey>'$last_list'" }
	if ($first_list) {
		$where_list = $where_list . " and bigkey<'$first_list'";
		$order_list = 'DESC';
	}
	if ($letter) {
		$where_list  = $where_list . " and product_name LIKE '$letter%'";
		$where_list0 = $where_list0 . " and product_name LIKE '$letter%'";
	}

	#price range/match
	if ($price_range) {

		#field for price
		if (   ( $aff_flag and !( $server =~ m/shop/ ) )
			or ( $server =~ m/myadultwarehouse/ ) )
		{
			$price_field = 'price';
		}
		else { $price_field = 'saleprice' }

		if ( $price_range !~ /\-/ ) {    #exact match
			$price_match = $price_range;
			if ( $price_match =~ /^\d+$/ or $price_match =~ /^\d+\.\d+$/ ) {
				$price_mod = "$price_field=$price_match";
				$price2    = "\$$price_match";
			}
		}
		else {                           #range
			( $price_min, $price_max ) = split /-/, $price_range;
			if ( $price_min =~ /^\d+$/ or $price_min =~ /^\d+\.\d+$/ ) {
				$price_mod_min = "$price_field>$price_min";
			}
			if ( $price_max =~ /^\d+$/ or $price_max =~ /^\d+\.\d+$/ ) {
				$price_mod_max = "$price_field<$price_max";
			}
			if ( $price_mod_min and $price_mod_max ) {
				$price_mod = "$price_mod_min and $price_mod_max";
				$price2    = "\$$price_min - \$$price_max";
			}
			elsif ($price_mod_min) {
				$price_mod = $price_mod_min;
				$price2    = "more than \$$price_min";
			}
			elsif ($price_mod_max) {
				$price_mod = $price_mod_max;
				$price2    = "less than \$$price_max";
			}
		}

	}

	if ($price_mod) {
		if   ($where_list) { $where_list = "$where_list and $price_mod"; }
		else               { $where_list = "WHERE $price_mod"; }
	}

	$sql = $dbh->prepare(
		" SELECT $table1.item,$table1.product_name,$table1.bigkey
     FROM $table1, $top20table inventory
     $where_list and $table1.item=$tmptable.item $tmp20mod $inv_mod
     ORDER by bigkey $order_list 
     LIMIT 50
     "
	);
	$sql->execute();
	$j = 0;
	while ( @record1 = $sql->fetchrow_array ) {
		( $list_ecode[$j], $list[$j], $bigkey_list[$j] ) = @record1;
		$j++;
	}
	$sql->finish();

	#number of search results
	if ( $letter or ( $criteria and ( $criteria ne 'init' ) ) ) {
		$phrase = $dbh->quote($text);
		$sql    = $dbh->prepare(
			" SELECT $res_field,inits
     FROM search
     WHERE phrase=$phrase and type='$type' and criteria='$criteria' and site='Superstore'
     LIMIT 1
     "
		);

		$sql->execute();
		( $jj, $inits ) = $sql->fetchrow_array;
		$sql->finish();

		@inits = split /,/, $inits;
		foreach $init_dd (@inits) { $init_present{$init_dd} = 'Yes' }

	}

	if ($first_list) {
		@list_ecode  = reverse @list_ecode;
		@list        = reverse @list;
		@bigkey_list = reverse @bigkey_list;
	}

	$first_list = $bigkey_list[0];
	$last_list  = $bigkey_list[ $j - 1 ];
	$l0         = $#list;

	#FILTER FOR NAMES IN LIST
	$l = $#list + 1;
	local ($lil) = 0;
	local ($il)  = 0;
	while ( $lil + $il <= 100 && $il <= $l - 1 ) {
		local ($lilo) = 0;
		local ($prev) = 0;
		for ( $i = 0 ; $i <= ( length( $list[$il] ) - 1 ) ; $i++ ) {
			if (   ( substr( $list[$il], $i, 1 ) eq ' ' )
				&& ( ( $i - $prev ) > 25 )
				&& substr( $list[$il], $i + 1, 1 ) )
			{
				$prev = $i + $prev;
				$lilo++;
				substr( $list[$il], $i, 1 ) = '*';
			}
		}
		$lil = $lil + $lilo;
		while ( $list[$il] =~ m/\*/ ) {
			$list[$il] =~
s/\*/<\/a><br>&nbsp;&nbsp;&nbsp;<a href='\/cgi-bin\/dvd2.cgi?af=$affiliate&ecode=$list_ecode[$il]&fam=$fam&init=$init&letter=$letter&last_list=$last_list0&first_list=$first_list0&dozen_list=$dozen_list&text=$text3&criteria=$criteria&init1=$init1&race=$race$price_app' class='text1'>/;
		}
		$il++;
	}
	for ( $i = $0 ; $i < $il ; $i++ ) { $list[ $i + $il ] = $list[ $i + $l ] }
	$lold     = $l;
	$l        = $il;
	$list_key = $list[ 2 * $l - 1 ];

	require("/export/home0/vhost218/cgi-serverwide/colors.pl");

	#page layout

	print &PrintHeader;
	print <<EOT;
<html>
<head>
<title>Adult DVD: $name</title>
<META HTTP-EQUIV="Expires" CONTENT="0">

<script language="JavaScript">
<!--

self.status='';

function repl(value){
var url='/cgi-bin/dvd.cgi?af=$affiliate&fam='+value+'&init=$init&race=$race'
window.location = url;
}

function replC(value){
var url='/cgi-bin/dvd.cgi?af=$affiliate&init1='+value+'&criteria=$criteria&text=$text3&race=$race'
window.location = url;
}

function replP(value){
  if(value){window.location='http://$ENV{"HTTP_HOST"}/cgi-bin/$type.cgi?$query0&price_range='+value;}
  else{window.location='http://$ENV{"HTTP_HOST"}/cgi-bin/$type.cgi?$query0';}
}

var caution = false
today=new Date();
quarterlater=new Date();
quarterlater.setTime(today.getTime()+7776000000);
yearslater=new Date();
yearslater.setTime(today.getTime()+315360000000);


function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		 "; path=/" +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie
}

function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		"; path=/" +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}

function fixDate(date) {
	var base = new Date(0)
	var skew = base.getTime()
	if (skew > 0)
		date.setTime(date.getTime() - skew)
}


function setCart(key,onsale,last_price){

var keyss = getCookie("keysCookie")		
var onsales = getCookie("onsalesCookie")		

if ( keyss ) {keyss = keyss+key+'\$' }
else {keyss = key+'\$' }
if ( onsales ) {onsales = onsales+onsale+'\$' }
else {onsales = onsale+'\$' }

var total = getCookie("total");
var tot_qty = getCookie("tot_qty");
if(eval(total)>0){total = eval(total)+eval(last_price);} else{total = eval(last_price)}
if(eval(tot_qty)){tot_qty = eval(tot_qty)+1} else{tot_qty = 1}

setCookie ("keysCookie",keyss,quarterlater)
setCookie ("onsalesCookie",onsales,quarterlater)
setCookie ("total",total,quarterlater);
setCookie ("tot_qty",tot_qty,quarterlater);
document.location.reload();
}

function Start(page) {
OpenWin1 = this.open(page,"Sale","toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=320,height=335");
}

function send_link() {
this.open('/cgi-share/send_link.cgi?af=$affiliate&ecode=$ecode&type=$type',"SendLink","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=340,height=258");
}

function bookmark()
{
bookmarkurl="http://$server/cgi-bin/product.cgi?af=$affiliate&criteria=ecode&text=$ecode&type=$type"
bookmarktitle="$name"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserVer >= 3) version = "n3";
else if (browserName == "Netscape" && browserVer <= 2) version = "n2";
else version = "ie"
function MakeHelpLogin(url) {
	if (version == "ie" || version == "n2") { alert('Netscape 3.0 and above or Internet Explorer 4.0 and above are required to use the Help Windows.'); }
	if (version == "n3") {
		HelpWindow=window.open(url,"HelpWindow","toolbar=no,width=300,height=400,scrollbars=auto,directories=no,status=no,menubar=no");
		HelpWindow.focus();
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
$style_sheet
</head>
<body bgcolor="$bgcolor" text="#000000" link="#0000FF" vlink="#0000FF" alink="$hover" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
EOT

	require("/export/home0/vhost218/cgi-serverwide/header.pl");

	print <<EOT;
<table border="0" cellspacing="0" cellpadding="0" width=100%>
 <tr>
  <td width="5%" bgcolor="$bgcolor2" valign="top">
EOT

	require("/export/home0/vhost218/cgi-serverwide/menu_new.pl");

	if ( $image !~ /\.gif$/i ) {

		# if ($show_back eq "T") {
		$image_back =
qq(<img src="/images/pimage/dvdback/$image" align="top" border=0 alt="$name Back" width=210 height=300><br>DVD Back Cover);

# } else {
# $image_back = qq(<img src="/images/pimage/dvdback/toohot.jpg" align="top" border=0 alt="$name Back" width=210 height=300><br>DVD Back Cover);
# }
	}
	else {
		$image_back = "&nbsp;";
	}

	# if ($show_front eq "F") {
	#  $image = "toohot.jpg";
	# }

	print <<EOT;
  </td>
  <td valign=top>
   <table bgcolor="$bgcolor" border=0 cellspacing=0 cellpadding=0 width="100%" valign=top align=center>
    <tr>
     <td width="75%" valign=top>
	<table border=0 cellspacing=6 cellpadding=0 width="100%" valign=top align=center>
       <tr>
        <td width="100%" align=center valign=top>
         <table bgcolor="$bgcolor" cellspacing=0 cellpadding=0 border=0 width="100%" valign=top align=center>
	    <tr>
	     <td valign=middle width=75% class="text1large">&nbsp;&nbsp;$type1$text1$race1$fam1</td>
           <td valign=middle align=right width=25%><a href="javascript:bookmark();" class="text1">Bookmark this item</a></td>
          </tr>
         </table>
        </td>
       </tr>
       <tr>
        <td bgcolor="$bgcolor3" width="100%" align=center valign=top>
         <table cellpadding=0 cellspacing=0 border=0 height=10 width=100%>
          <tr>
           <td valign=top height=19 width=3%><img src="/ahtml/images/spacer.gif" height=19 width=35 vspace=0 hspace=0></td>
           <td align=center height=19 class="text3large">$name</td>
           <td align=right valign=top height=19 width=3%><img src="/ahtml/images/dvd.gif" height=19 width=35 vspace=0 hspace=0></td>
          </tr>
         </table>
        </td>
       </tr>
       <tr>
        <td bgcolor="#FFFFFF" width="100%" align=center valign=top>
         <table width=100% cellspacing=2 cellpadding=2 valign=top border=0>
          <tr>
           <td width=192 valign=top align=center class="black"><img src="/images/pimage/dvd/$image" align="top" border=0 alt="$name Front" width=210 height=300><br>
            DVD Front Cover<br>
            <img src="/ahtml/images/spacer.gif" height=6 width=5><br>
            $image_back</td>
           <td valign=top>
           <form name="RatingForm" METHOD=get action=/cgi-share/1review.cgi>
           <input type=hidden name=mode value=submit>
           <input type=hidden name=ecode value='$ecode'>
           <input type=hidden name=type value='$type'> 
           <input type=hidden name=af value='$affiliate'>                      
            <table width=100% cellspacing=0 cellpadding=2 border=0>
             <tr>
              <td class="black" valign=top><span class="blackbold">Description:</span>&nbsp;$synopsis</td>
             </tr>
             <tr>
              <td class="black" valign=top><span class="blackbold">Starring:</span>&nbsp;

EOT

	$split_manuf = $foo->escape($manufacturer);
	if ( $runtime == 0 ) { $runtime = 'Not Specified'; $mins = ''; }
	if ( $runtime != 0 ) { $mins = 'mins.'; }
	$count_star = $#split_star + 1;
	$count      = 1;
	foreach $split_star (@split_star) {
		if ( $count == $count_star ) { $comma = ''; }
		if ( $count != $count_star ) { $comma = ','; $count++; }
		$show_star = $split_star;
		$split_star =~ s/^ //;
		$split_star = $foo->escape($split_star);
		print
"<a href='/cgi-bin/dvd.cgi?af=$affiliate&text=$split_star&criteria=star'>$show_star</a>$comma ";
	}

	#change plan A->B
	if (   ( $aff_flag and !( $server =~ m/shop/ ) )
		or ( $server =~ m/myadultwarehouse/ ) )
	{
		$saleprice = $price;
	}
	else {
		$you_save = sprintf "%.2f", ( $price - $saleprice );
		$reg_line =
qq(Regular Price:&nbsp;<span class="blackbold"><s>\$$price</s></span>&nbsp;&nbsp;&nbsp;<span class="blackbold">You Save:&nbsp;\$$you_save</span>);
	}

	#-change

	$saleprice = sprintf "%.2f", $saleprice;

	#if (length($name)>30){$name=substr($name,0,30).'...';}
	while ( $name =~ m/\'/ ) {
		$name =~ s/\'/\`/;
	}
	$name =~ s/"//g;
	$keystatus = $key . $status . $ecode;

	if ($race) { $race3 = qq( $assa1{$race}) }

	print <<E_O_T;
              </td>
             </tr>
             <tr>
              <td height=22 class="black"><span class="blackbold">Studio:</span>&nbsp;<a href='/cgi-bin/dvd.cgi?af=$affiliate&text=$split_manuf&criteria=manufacturer'>$manufacturer</a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Status:</span>&nbsp;<a href="javascript:MakeHelpLogin('/ahtml/help/menu_status.html')" onMouseover="self.status='Open A Help Window'; return true;" onMouseout="self.status=''; return true;" class="redbold">$available2</a></td>
             </tr>
             <tr>
	        <td height=22 class="black" nowrap><span class="blackbold">Our Price:</span>&nbsp;<span class="redlarge">\$$saleprice</span>&nbsp;&nbsp;&nbsp;<a href="javascript:MakeHelpLogin('/ahtml/help/menu_discounts.html')" onMouseover="self.status='Open A Help Window'; return true;" onMouseout="self.status=''; return true;")">$sale</a><br>
               $reg_line</td>
             </tr>
E_O_T

	if ( $available ne 'D' ) {
		print <<EOT;
             <tr>
	        <td height=30 valign=middle><a href="javascript:setCart('$keystatus', '$onsale1',$saleprice)"><img src="/ahtml/images/add_cart.gif" width=173 height=22 border=0 alt="Add to Cart"></a></td>
             </tr>
             <tr>
              <td height=30 valign=middle><a href=/cgi-share/1wishlist.cgi?af=$affiliate&add=$ecode><img src="/ahtml/images/add_wishlist.gif" width=173 height=22 border=0 alt="Add to Wish List"></a></td>
             </tr>
             <tr>
              <td height=30 valign=middle><a href=/cgi-share/1giftreg.cgi?af=$affiliate&ecode=$ecode&add=Yes><img src="/ahtml/images/add_giftreg.gif" width=173 height=22 border=0 alt="Add to Gift Registry"></a></td>
             </tr>

EOT
	}
	else {
		print <<EOT;
             <tr>
              <td height=24 valign=middle class="redbold" nowrap>NOT AVAILABLE</td>
             </tr>
EOT
	}

	print <<EOT;
             <tr>
              <td height=30 valign=middle><a href=/cgi-share/1order.cgi?af=$affiliate><img src="/ahtml/images/checkout.gif" width=173 height=22 border=0 alt="Checkout"></a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Ships:</span>&nbsp;$available1</td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">e-Code:</span>&nbsp;$ecode</td>
             </tr>
             <tr>
              <td height=22 class="black"><span class="blackbold">Approx. Running Time:</span>&nbsp;$runtime $mins</td>
             </tr>
             <tr>
              <td height=22 class="black"><span class="blackbold">Production Year:</span>&nbsp;$prodyear</td>
             </tr>
             <tr>
              <td height=22 class="black"><span class="blackbold">Date Available:</span>&nbsp;$dateav</td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Format:</span>&nbsp;DVD VIDEO</td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Initial Genre:</span>&nbsp;<a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init'>$initial</a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Category 1:</span>&nbsp;<a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&fam=$sub'>$assa1{$sub}</a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Category 2:</span>&nbsp;<a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&fam=$family1'>$assa1{$family1}</a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><span class="blackbold">Category 3:</span>&nbsp;<a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&fam=$family2'>$assa1{$family2}</a></td>
             </tr>
EOT

	if ( $reviews > 0 ) {
		print <<E_O_T;
             <tr> 
              <td height=22 class="black"><span class="blackbold">Customer Rating:</span>&nbsp;<img src="/ahtml/images/stars-$rating1-0.gif" width="100" height="18" align="absmiddle"><br><img src="/ahtml/images/spacer.gif" height="6" width="100">based on $reviews ratings or <a href="#rating">reviews</a></td>
             </tr>
E_O_T
	}

	print <<EOT;
             <tr> 
              <td>
               <table width="240" border="0" cellspacing="0" cellpadding="2">
                <tr> 
                 <td width="95" class="blackbold">Rate this DVD:</td>
                 <td class="blackbold" width="75" valign="middle"> 
                  <select name="rating">
                   <option value="5" selected>5 Stars</option>
                   <option value="4">4 Stars</option>
                   <option value="3">3 Stars</option>
                   <option value="2">2 Stars</option>
                   <option value="1">1 Star</option>
                  </select>&nbsp;
                 </td>
                 <td class="blackbold" width="70" valign="middle">
                  <input type="submit" value="Submit">
                 </td>
                </tr>
               </table>
              </td>
             </tr>
             <tr> 
              <td height=22 class="black"><a href="/cgi-share/1review.cgi?af=$affiliate&type=$type&ecode=$ecode">Write 
               an online review</a></td>
             </tr>
             <tr> 
              <td height=22 class="black"><a href="/cgi-share/1review.cgi?af=$affiliate&mode=edit&type=$type&ecode=$ecode">Edit your reviews</a></td>
             </tr>
             <tr>    
              <td height=22 class="black"><a href="javascript:send_link();">Email a friend about this item</a>&nbsp;<img src="/ahtml/images/envelope.gif" width=39 height=15 align=absmiddle border=0></td>
             </tr>
            </table>
           </form>
           </td>
	    </tr>
         </table>
        </td>
       </tr>
       <tr> 
        <td align=center bgcolor="$bgcolor3" class="text3large">We recommend these similar$race3 Adult DVD titles:</td>
       </tr>
       <tr> 
        <td bgcolor="#FFFFFF"> 
         <table width=100% border="0" cellspacing="0" cellpadding="2">
          <tr valign=top align=center> 

EOT

	#thumbs to other products

	foreach $fm ( ( $family1, $family2 ) ) {

		if ( $fm eq $family2 ) {
			$and_filter =
			  "and (date_dvd.item != '$item1' and date_dvd.item != '$item2')";
		}

		$sql = $dbh->prepare(
" SELECT date_dvd.item,date_dvd.product_name,date_dvd.pthumbs,date_dvd.show_front
          FROM date_dvd,inventory
          WHERE (family1='$fm' or family2='$fm') AND initial='$init' AND date_dvd.item !='$ecode' $and_race $and_filter and date_dvd.item=inventory.item  and inventory.available='T'
          ORDER by RAND()
          LIMIT 2
          "
		);

		$sql->execute();

		$it_cnt = 0;
		while ( @record = $sql->fetchrow_array ) {
			( $item_th, $name_th, $thumb_th, $show_front ) = @record;
			$it_cnt++;
			if ( $fm eq $family1 ) {
				if ( $it_cnt eq 1 ) { $item1 = $item_th }
				if ( $it_cnt eq 2 ) { $item2 = $item_th }
			}

			if ( $show_front ne "T" ) {

				#  $thumb_th = "toohot.jpg";
			}
			print
qq(<td width=25% class="black">CATEGORY:<br><a href='/cgi-bin/dvd.cgi?af=$affiliate&init=$init&fam=$fm' class="redbold">$assa1{$fm}</a><br><a href="/cgi-bin/dvd2.cgi?af=$affiliate&ecode=$item_th&init=$init&fam=$fm&race=$race"><img src="/images/pthumbs/dvd/$thumb_th" width="98" height="140" border="1"><br>$name_th</a></td>);
		}
		$sql->finish();
	}

	print <<E_O_T;
		                        
         </tr>
         </table>
        </td>
       </tr>
       <tr> 
        <td align=center bgcolor="$bgcolor3" class="text3large"><a name="rating">Customer Ratings and Reviews:</a></td>
       </tr>
       <tr> 
        <td bgcolor="#FFFFFF">
         <table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr> 
           <td class="blacklarge">DVD: $name</td>
          </tr>
E_O_T

	if ( $reviews > 0 ) {
		print <<E_O_T;
          <tr> 
           <td height=22 class="black"><span class="blackbold">Customer Rating:</span>&nbsp;<img src="/ahtml/images/stars-$rating1-0.gif" width="100" height="18" align="absmiddle">&nbsp;based on $reviews ratings or reviews</td>
          </tr>
E_O_T

		#get reviews
		$sql = $dbh->prepare(
" SELECT title,review,rating,reviewer_nickname,reviewer_location,DATE_FORMAT(date, '%M %e, %Y')
     FROM reviews
     WHERE item='$ecode' AND title IS NOT NULL
     ORDER by date DESC
     LIMIT 10
     "
		);

		$aa = $sql->execute();

		#show reviews
		if ( $aa > 0 ) {
			print <<E_O_T;
          <tr> 
           <td> 
            <hr noshade color="$bgcolor3">
           </td>
          </tr>
          <tr> 
           <td class="blackbold">Customer Ratings and Reviews:</td>
          </tr>
E_O_T

			while (
				(
					$review_title,      $review,
					$review_rating,     $reviewer_nickname,
					$reviewer_location, $review_date
				)
				= $sql->fetchrow_array
			  )
			{
				if ($reviewer_location) {
					$from_rev = "from $reviewer_location";
				}
				print <<EOT;
          <tr> 
           <td> 
            <table width="100%" border="0" cellspacing="2" cellpadding="0">
             <tr> 
              <td class="black"><img src="/ahtml/images/stars-$review_rating-0.gif" width="100" height="18" align="absmiddle">&nbsp;<span class="blackbold">$review_title</span>, $review_date </td>
             </tr>
             <tr> 
              <td class="black">Reviewer:&nbsp;$reviewer_nickname $from_rev</td>
             </tr>
             <tr> 
              <td class="black">
              $review
              </td>
             </tr>
             <tr> 
              <td class="black"><a href="/cgi-share/1review.cgi?af=$affiliate&mode=edit&type=$type&ecode=$ecode">Edit this review</a></td>
             </tr>
             <tr> 
              <td> 
               <hr noshade color="$bgcolor3">
              </td>
             </tr>
            </table>
           </td>
          </tr>

EOT
			}    #end of reviews loop
		}    #end of show reviews

		$sql->finish();
	}    ###reviews exist
	else {
		print <<E_O_T;
          <tr> 
           <td class="black">There are no reviews for this DVD.<br>
            <a href="/cgi-share/1review.cgi?af=$affiliate&type=$type&ecode=$ecode">Click Here</a> to be the first to review this DVD.</td>
          </tr>
          <tr> 
           <td>
            <form name="RatingForm" METHOD=post action=/cgi-share/1review.cgi>
            <input type=hidden name=mode value=submit>
            <input type=hidden name=ecode value='$ecode'>
            <input type=hidden name=type value='$type'>
            <input type=hidden name=af value='$affiliate'>                                 
            <table width="240" border="0" cellspacing="0" cellpadding="2">
             <tr> 
              <td width="95" class="blackbold">Rate this DVD:</td>
              <td class="blackbold" width="75" valign="middle"> 
               <select name="rating">
                <option value="5" selected>5 Stars</option>
                <option value="4">4 Stars</option>
                <option value="3">3 Stars</option>
                <option value="2">2 Stars</option>
                <option value="1">1 Star</option>
               </select>&nbsp;
              </td>
              <td class="blackbold" width="70" valign="middle">
               <input type="submit" value="Submit">
              </td>
             </tr>
            </table>
            </form>
           </td>
          </tr>
E_O_T
	}

	print <<E_O_T;
          <tr> 
           <td height="22" class="blackbold"><a href="/cgi-share/1review.cgi?af=$affiliate&type=$type&ecode=$ecode">Write 
            your own online review</a> of $name</td>
          </tr>
         </table>
        </td>
       </tr>
	</table>
     </td>
     <td align="center" valign="top" width="25%">
     <form name="InventoryForm2" METHOD=get>
      <table valign="top" border="0">
                         
E_O_T

	require("/export/home0/vhost218/cgi-serverwide/cart.pl");
	require("/export/home0/vhost218/cgi-serverwide/promo_inc.pl");

	$initial1 = $initial;
	if ( $criteria and ( $criteria ne 'init' ) ) {
		$criteria1 = ucfirst $criteria;
		if ( $criteria1 eq 'Manufacturer' ) { $criteria1 = 'Studio' }
		$initial1 = "$criteria1 : $text";
	}
	if ( $criteria eq 'voldiscount' or $discount eq 'Yes' ) {
		$initial1 = 'Volume Discounts';
	}

	print <<E_O_T;
		<tr>
			<td class="text1large" height="20">&nbsp;&nbsp;&nbsp;Alphabetically Sorted List</td>
		</tr>
		<tr>
			<td class="text1large">&nbsp;&nbsp;&nbsp;$initial1</td>
		</tr>
E_O_T

	if (    ( $top20 ne 'Yes' )
		and !( $criteria and ( $criteria ne 'init' ) )
		and ( $discount ne 'Yes' ) )
	{
		print <<E_O_T;
       <tr>
        <td valign="top">
         <select id="InventoryComboBox1" name="fam" onChange="repl(this.options[this.selectedIndex].value)">
          <option value="category" SELECTED>-- Select a Category --</option>
E_O_T
		for ( $ji = 0 ; $ji <= $fam_number - 1 ; $ji++ ) {
			$fam_this = $asso1[ 2 * $ji ];
			if ($race) { $fam_this = $family_list[$ji] }
			local ($show) = $assa1{$fam_this};
			$show =~ s/&#8482/(TM)/;
			if ( $show =~ /hours/i and $hotdeal eq 'Yes' ) { next }
			if ( !$show ) { next }
			print '<option value="', $fam_this, '">', $show, '</option>';
		}
		print "</select>";
	}

	if ( ( $criteria and ( $criteria ne 'init' ) ) or $discount eq 'Yes' ) {
		print <<E_O_T;
       <tr>
        <td valign="top">
         <select id="InventoryComboBox1" name="fam" onChange="replC(this.options[this.selectedIndex].value)">
          <option value="category" SELECTED>-- Select a Category --</option>
E_O_T
		for ( $ji = 0 ; $ji <= $#asso00 ; $ji++ ) {
			$ini = $asso00[$ji];
			if ( $ini eq 'hotdeal' or $ini eq 'top20' or $ini eq 'voldiscount' )
			{
				next;
			}
			if ( $init_present{$ini} eq 'Yes' or $criteria eq 'voldiscount' ) {
				print '<option value="', $ini, '">', $asso0{$ini}, '</option>';
			}
		}
		print <<E_O_T;
         </select>
        </td>
       </tr>
E_O_T
	}

	&RightDefault;
	print <<E_O_T;
        </td>
       </tr>
       <tr>
        <td align=center valign=middle>
E_O_T

	# DOZENS CONTROL for list (NEXT -- PREVIOUS)
	if ( $dozen_list > 1 ) {
		print
"<a href='/cgi-bin/dvd2.cgi?af=$affiliate&ecode=$ecode&first_list=$first_list&init=$init&fam=$fam&dozen_list=$dozen_list0&letter=$letter&criteria=$criteria&text=$text3&init1=$init1&race=$race$price_app' class='text1bold'><img src='/ahtml/images/arrowback.gif' HEIGHT=10 WIDTH=30 align=absmiddle border=0>BACK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>";
	}
	if ( $l0 eq 49 ) {
		print
"<a href='/cgi-bin/dvd2.cgi?af=$affiliate&ecode=$ecode&last_list=$last_list&init=$init&fam=$fam&dozen_list=$dozen_list1&letter=$letter&criteria=$criteria&text=$text3&init1=$init1&race=$race$price_app' class='text1bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NEXT<img src='/ahtml/images/arrownext.gif' HEIGHT=10 WIDTH=30 align=absmiddle border=0></a>";
	}

	if ( $server =~ /^store/i or $server =~ /myadultwarehouse/i ) {

		#options for higher price
		$price_range_options = qq(
      <option value="">All Prices</option>
      <option value="-15">less than \$15</option>
      <option value="15-20">\$15-\$20</option>
      <option value="20-25">\$20-\$25</option>
      <option value="25-30">\$25-\$30</option>
      <option value="30-35">\$30-\$35</option>      
      <option value="35-">more than \$35</option>);
	}
	else {    #options for lower price
		$price_range_options = qq(
      <option value="">All Prices</option>
      <option value="-10">less than \$10</option>
      <option value="10-15">\$10-\$15</option>
      <option value="15-20">\$15-\$20</option>
      <option value="20-25">\$20-\$25</option>
      <option value="25-30">\$25-\$30</option>
      <option value="30-35">\$30-\$35</option>      
      <option value="35-">more than \$35</option>);
	}

	print <<E_O_T;
        </td>
       </tr> 
       <tr>
        <td align=center>
         <br>
         <select name="price_rng" onChange="replP(this.options[this.selectedIndex].value)">
         <option value="" SELECTED>-- Price Range --</option>                        
          $price_range_options      
         </select>
        </td>
       </tr>                           
       <tr>
        <td align=center> 
         <br>                
E_O_T
	$br         = '';
	$alph_count = 1;
	@alphabet   = (
		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
		'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
	);

	print <<E_O_T;
         <table cellspacing=0 cellpadding=2 border=1 bgcolor='$bgcolor3' bordercolor='$bgcolor3'>
          <tr>
           <td align=center class="text3large">Alphabetical
E_O_T
	$initial_category = $foo->escape($initial_category);
	print <<E_O_T;
           </td>
          </tr>
          <tr>
           <td align=center bgcolor=#FFFFFF class="black">
E_O_T
	foreach $alphabet (@alphabet) {
		if   ( $init ne 'top20' ) { $init2 = $init; $fam2 = $fam }
		else                      { $init2 = '';    $fam2 = '' }
		print <<E_O_T;
<a href=/cgi-bin/dvd.cgi?af=$affiliate&init=$init2&fam=$fam2&letter=$alphabet$price_app>$alphabet</a>
$br
E_O_T
		$br = '';
		$alph_count++;
		if ( $alph_count == 13 or $alph_count == 26 ) { $br = '<br>'; }
	}
	print <<E_O_T;
           </td>
	    </tr>
	   </table>
        </td>
       </tr>
      </table>
     </form>
     </td>
    </tr>           
   </table>
  </td>
 </tr>           
</table>

E_O_T

	#FOOTER

	require("/export/home0/vhost218/cgi-serverwide/footer.pl");

	print <<E_O_T;

</body>
</html> 
E_O_T
	$sql->finish();
	$dbh->disconnect();

	exit;
}

############################################################################################################################################

#RIGHTDEFAULT
sub RightDefault {

	if ( $criteria and ( $criteria ne 'init' ) ) { $initial = $text; }
	if ( !$family ) {
		$family = 'All Categories';
		if ($price_range) { $family = $price2 }
	}
	if ($letter) { $letter1 = "<br>&nbsp;&nbsp;&nbsp;$letter" }
	if ( $letter or ( $criteria and ( $criteria ne 'init' ) ) ) {
		$family = "$jj titles found$letter1";
	}
	if ($init1) { $family = $asso0{$init1} }
	print <<E_O_T;

    <tr>
     <td valign=top nowrap class="text1large">$add_race&nbsp;&nbsp;&nbsp;$family<br></td>
    </tr>
    <tr valign=top>
     <td valign=top nowrap class='text1'>

E_O_T

	for ( $j = 0 ; $j <= ( $il - 1 ) ; $j++ ) {
		print
"&#8226;&nbsp;<a href='/cgi-bin/dvd2.cgi?af=$affiliate&ecode=$list_ecode[$j]&letter=$letter&fam=$fam&init=$init&last_list=$last_list0&first_list=$first_list0&dozen_list=$dozen_list&text=$text3&criteria=$criteria&init1=$init1&race=$race$price_app' class='text1'>$list[$j]</a><br>
";
	}
	print "<br>";
	1;
}

#############################################################################################################################################

sub PrintHeader {
	return "Content-type: text/html\n\n";
}

sub Flag {
	local ($input) = @_;
	local ($flag)  = 1;
	$flag = 0
	  if ( $input / 2 eq int( $input / 2 ) );  # $flag=0 if even, and =1 if odd;
	return $flag;
}

sub get_cookie {
	local ( $chip, $val );
	foreach ( split( /; /, $ENV{'HTTP_COOKIE'} ) ) {

   # split cookie at each ; (cookie format is name=value; name=value; etc...)
   # Convert plus to space (in case of encoding (not necessary, but recommended)
		s/\+/ /g;                              # Split into key and value.
		( $chip, $val ) = split( /=/, $_, 2 ); # splits on the first =.
		        # Convert %XX from hex numbers to alphanumeric
		$chip =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;
		$val  =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge;

		# Associate key and value
		next if ( defined( $cookie{$chip} ) );
		$cookie{$chip} .= $val;
	}
}

sub ReadParse {
	local (*in) = @_ if @_;
	local ( $i, $key, $val );

	# Read in text
	if (&MethGet) {
		$in = $ENV{'QUERY_STRING'};
	}
	elsif (&MethPost) {
		read( STDIN, $in, $ENV{'CONTENT_LENGTH'} );
	}

	@in = split( /[&;]/, $in );

	foreach $i ( 0 .. $#in ) {

		# Convert plus's to spaces
		$in[$i] =~ s/\+/ /g;

		# Split into key and value.
		( $key, $val ) = split( /=/, $in[$i], 2 );    # splits on the first =.

		# Convert %XX from hex numbers to alphanumeric
		$key =~ s/%(..)/pack("c",hex($1))/ge;
		$val =~ s/%(..)/pack("c",hex($1))/ge;

		# Associate key and value
		$in{$key} .= "\0"
		  if ( defined( $in{$key} ) );    # \0 is the multiple separator
		$in{$key} .= $val;

	}

	return scalar(@in);
}

sub MethGet {
	return ( $ENV{'REQUEST_METHOD'} eq "GET" );
}

# MethPost
# Return true if this cgi call was using the POST request, false otherwise

sub MethPost {
	return ( $ENV{'REQUEST_METHOD'} eq "POST" );
}