<%@ LANGUAGE = PerlScript %><%
    use Win32::ADO;
	use Win32::ASP qw(:strict);
	use Win32::ASP qw/SetCookie/;
	use strict;

	$Response->End();	
    $Response->{Buffer} = 1;

    use constant adCmdStoredProc => 0x0004;
    use constant adInteger => 3;
    use constant adVarChar => 200;
    use constant adParamOutput => 0x0002;
    use constant adParamInput => 0x0001;
	use constant adOpenForwardOnly => 0;
    use constant adOpenDynamic => 2;
	use constant adOpenStatic => 3;
    use constant adLockOptimistic => 3;

	my $RecurseLevel = 0;
    $Response->{Buffer} = 1;

	### Read Application Variables ###
	my $mySQL = $Application->Contents('Connection');
	my $COLORProductHeader 	= $Application->Contents('COLORProductHeader');
	my $COLORCategoryHeader = $Application->Contents('COLORCategoryHeader');

    my $MyConn = $Server->CreateObject("ADODB.Connection");
    $MyConn->Open($mySQL);

    ### Constants ###
	use constant COLS => 2;			### Number of category columns ###
    use constant PAGESIZE => 10;	### Number of items per page ###
    ###
    my $action = GetFormValue("action");
    my $key    = GetFormValue("key");

    &PullCat if ($action eq 'grabcat');
    &GetItem if ($key > 0);
    &ShowCats;
%>


<% sub PullCat {
    ##########################################################
    ### Display List of Categories within current Category ###
    ##########################################################

    my ($catid, $page) = (GetFormValue('category'), GetFormValue('page'));
    my ($catPath, $catPage, $catLinks, @subcatList);
	my $ReturnID = $catid;

    if (($catid < 1) || ($page < 1)) {
        &ShowCats;
        exit;
    }

    ### Load Product List Recordset ###
    my $Rset = $Server->CreateObject("ADODB.Recordset");
    $Rset->{'CursorLocation'} = 3;  ### Client-side Cursor ###
    $Rset->Open("SELECT ProductsTable.* FROM Categories INNER JOIN (ProductsTable INNER JOIN ProductCategories ON ProductsTable.ProductID = ProductCategories.ProductID) ON Categories.CategoryID = ProductCategories.CategoryID WHERE Categories.CategoryID = $catid ORDER BY ProductCategories.Position, ProductsTable.ProductName ", $MyConn, 3, 1);
    $Rset->{'PageSize'} = PAGESIZE;
    $Rset->{'AbsolutePage'} = $page;
    my $Rstart = $Rset->{'AbsolutePosition'};
    my $Rstop = $Rset->{'AbsolutePosition'} + ($Rset->{'PageSize'} - 1);
    my $Rtotal = $Rset->{RecordCount};
    if ($Rstop > $Rtotal) { $Rstop = $Rtotal; }

    ### Find originating record to search path ###
    my $RS = $MyConn->Execute("SELECT * FROM Categories WHERE CategoryID = $catid");

    if (!$RS) {
        $RS->Close;
        &ShowCats;
        exit;
    }

    my ($mainDescript, $mainPic, $mainCode, $mainLink) = ($RS->Fields("Description")->value, $RS->Fields("PictureFile")->value, $RS->Fields("HTMLCode")->value, $RS->Fields("DescriptionLink")->value );
    my ($mainID) = $catid;
    undef($mainLink) if (length($mainLink) < 1);
    $mainDescript =~ s/\b(\w)/\U$1/g;
    $catid = $RS->Fields("ParentCategory")->value;

    $catPath = " : $mainDescript";

    my $infLoop = 0;
    my $companyName = $mainDescript;
    while ($catid > 0) {
        $RS->Close;
        $RS = $MyConn->Execute("SELECT * FROM Categories WHERE CategoryID = $catid");
        if ($RS) {
            my ($descript, $parent) = ($RS->Fields("Description")->value, $RS->Fields("ParentCategory")->value );
            $descript =~ s/\b(\w)/\U$1/g;
            my $tlink = sprintf("action=grabcat&page=1&category=%d", $Server->URLEncode($catid));
            $catPath = sprintf(" : <A HREF=\"store.asp?%s\">%s</A>%s", $tlink, $descript, $catPath);
            $companyName = $descript;  ### Keeps last description which should be company name
            if ($catid == $parent) {
                $catid = 0;
            } else {
                $catid = $parent;
            }
        } else {
            $catid = 0;
        }
        if ($infLoop++ > 50) { $catid = 0; } ### Break from infinite loops
    }

    $RS->Close;
    $catPath = "<A HREF=\"store.asp\">All Categories</A>" . $catPath;

    ### Compile a list of available sub-categories ###
        $RS = $MyConn->Execute("SELECT * FROM Categories WHERE ParentCategory = $mainID ORDER BY Description");
    while(!$RS->EOF) {
        my ($catid, $descript) = ( $RS->Fields("CategoryID")->value, $RS->Fields("Description")->value );
        $descript =~ s/\b(\w)/\U$1/g;
        if (($catid > 0) && (length($descript) > 0)) {
            push(@subcatList, sprintf("<LI><A HREF=\"store.asp?action=grabcat&page=1&category=%d\">%s</A>", $catid, $descript));
        }
        $RS->MoveNext;
    }
    $RS->Close;

    if ($mainDescript eq $companyName) {
        &HTMLHeader(sprintf("%s: All Categories - Page %d", $mainDescript, $page));
    } else {
        &HTMLHeader(sprintf("%s: %s - Page %d", $companyName, $mainDescript, $page));
    }
%>
<script language="JavaScript">
	function OrderItem(ProductID) {
		var d = 1;
		var p, f;
		var descript = '';
		var sData = '';
		f = eval("document.P" + ProductID);
		if (f) {
			p = eval("f.D" + d);
			while (p) {
				sData = p[p.selectedIndex].value;
				if (sData == 'R1') {
					alert('Required entry is missing!');
					return;
				}
				if (sData != 'R0') descript += p[p.selectedIndex].value;
				d++;
				p = eval("document.P" + ProductID + ".D" + d);
				if ((p) && (sData != 'R0')) descript += ', ';
			}
		}
		self.location.href='cart.asp?action=add&qty=1&product=' + ProductID + '&category=' + <%= $mainID %> + '&extra=' + escape(descript);
	}
</script>
<FONT FACE="arial">
<table border=0 width=98% align=center>
<tr><td>
<%
    print "<CENTER>\n";

    #<!--Picture provided with category-->#
	if (length($mainPic) > 1) {
    print "<table border=0 width=100% >\n";
	print "<tr><td><center>\n";
	print "<img src=\"/prodpics/$mainPic\" border=0>\n";
	print "</center></td></tr>\n";
	print "<tr><td><center><font size=4 color=\"$COLORCategoryHeader\">$mainDescript</font></center></td>\n";
	print "</tr></table>\n";
	print "<HR WIDTH=\"90%\" SIZE=1 ALIGN=CENTER NOSHADE>\n<BR>\n";
	}
	else {
	print "<font size=4 color=\"$COLORCategoryHeader\">$mainDescript</font>\n";
	print "<HR WIDTH=\"90%\" SIZE=1 ALIGN=CENTER NOSHADE>\n<BR>\n";
	}
%>

</CENTER>
<%
    if (length($mainCode) > 1) {
        ### A long description was provided, print it ###
        print "<BLOCKQUOTE><DIV ALIGN=CENTER>\n";
        if ($mainLink) { print "<a href='$mainLink'>"; }
        $mainCode =~ s/ +/ /g;
        print ($mainCode);
        if ($mainLink) { print "</a>"; }
        print "</DIV></BLOCKQUOTE>\n";
    	print "<HR WIDTH=\"90%\" SIZE=1 ALIGN=CENTER NOSHADE>\n<BR>\n";
    }
    print "<FONT SIZE=+1><B>$catPath</B></FONT>\n";
    print "<P>\n";

    ### List sub-categories if they exist ###
    if ($#subcatList >= 0) {
        print "<CENTER>\n";
        print "<TABLE BORDER=0 CELLPADDING=6>\n";
        print "<TR><TD ALIGN=LEFT VALIGN=TOP>\n";
        print "<FONT FACE=\"arial\"><UL TYPE=SQUARE>\n";
        for (my $ii = 0; $ii <= (int($#subcatList / 2)); $ii++) {
            print $subcatList[$ii] . "\n";
        }
        print "</UL></FONT></TD>\n";
        print "<TD ALIGN=LEFT VALIGN=TOP>\n";
        print "<FONT FACE=\"arial\"><UL TYPE=SQUARE>\n";
        for (my $ii = (int($#subcatList / 2)+1); $ii <= $#subcatList; $ii++) {
            print $subcatList[$ii] . "\n";
        }
        print "</UL></FONT></TD>\n";
        print "</TR></TABLE>\n";
        print "</CENTER><P>\n";
    }

    ### Construct page selection line ###
    $catPage = '';
    if ($page < 2) {
        $catPage .= '<TD ALIGN=CENTER WIDTH="20%">&nbsp;&nbsp;</TD>';
    } else {
        $catPage .= sprintf("<TD ALIGN=CENTER WIDTH=\"20%%\">&lt;&lt;&nbsp;<A HREF=\"store.asp?action=grabcat&page=%d&category=%d\"><FONT COLOR=\"#0000FF\">PREVIOUS</FONT></A></TD>\n",
            ($page - 1), $mainID);
    }
    my $totpages = int((($page * PAGESIZE) + ($Rtotal - $Rstop)) / PAGESIZE);
    $totpages++ if (($Rtotal - $Rstop) > 0);
    $catPage .= sprintf("<TH ALIGN=CENTER WIDTH=\"20%%\"><FONT FACE=\"arial\">Page&nbsp;%d&nbsp;of&nbsp;%d</FONT></TH>", $page, $totpages);
    if ($Rstop < $Rtotal) {
        $catPage .= sprintf("<TD ALIGN=CENTER WIDTH=\"20%%\"><A HREF=\"store.asp?action=grabcat&page=%d&category=%d\"><FONT COLOR=\"#0000FF\">NEXT</FONT></A>&nbsp;&gt;&gt;</TD>\n",
            ($page + 1), $mainID);
    } else {
        $catPage .= '<TD ALIGN=CENTER WIDTH="20%">&nbsp;&nbsp;</TD>';
    }
    ### Construct Quick Page line ###
    if (($Rtotal / PAGESIZE) > 3) {
        $catLinks = '';
        for (my $ii = 1; $ii <= (int($Rtotal / PAGESIZE)+1); $ii++) {
            if ($ii == $page) {
                $catLinks .= "$ii ";
                next;
            }
            $catLinks .= sprintf("<A HREF=\"store.asp?action=grabcat&page=%d&category=%d\"><FONT COLOR=\"#0000FF\">%d</FONT></A> ",
                $ii, $mainID, $ii);
        }
        $catLinks = '- ' . $catLinks . ' -';
    }

    ### List products on page X ###
    if (($Rstart < 0) && ($Rstop < 1)) {
        if ($#subcatList < 0) {
            print "<CENTER><B><FONT SIZE=+2>No products listed.<BR>Come back soon.</FONT></B></CENTER>\n";
        }
    } else {

	 #Get X number of products for this page#
	 for (my $ii = $Rstart; $ii <= $Rstop; $ii++) {

	   my ($ProductID, $ProductCode, $ProductName, $PictureFile, $UnitPrice, $MSRP, $Orientation, $Notes) = (
            $Rset->Fields('ProductID')->value,      $Rset->Fields('ProductCode')->value,
            $Rset->Fields('ProductName')->value,    $Rset->Fields('PictureFile')->value,
            $Rset->Fields('UnitPrice')->value,      $Rset->Fields('MSRP')->value,
            $Rset->Fields('Orientation')->value,		$Rset->Fields('Notes')->value );

	   $Orientation =~ s/ +$//g;
	   if (length($Orientation) < 1) {
	   	$Orientation = 'T';
		$Orientation =~ s/ +$//g;
	   }

	   #Select Additional Pics#
	   my $AddLink;
	   my $AddRS = $MyConn->Execute("SELECT * FROM AdditionalPics WHERE ProductID = $ProductID");
		if (!$AddRS->EOF) {
			$AddLink = "images.asp?ProductID=$ProductID&page=$page&Category=$ReturnID";
		}
		else {
		undef($AddLink);
		}
	   $AddRS->Close();

	  	print "<a name=\"$ProductID\"></a>\n";
        ##Determine Orientation##
	   if ($Orientation eq 'T') {

	   	#Orientation is TOP#

		%>
		<table border=0 width=100%>
		<tr><td>
		<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);
		%>
		</td></tr>
		<tr><td>
	   	<%
	   	print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
		if (length($Notes) > 1) {
			$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</TD></TR>

		</TABLE>

		<%
	    } #End TOP Orientation#

   	   if ($Orientation eq 'L') {
	   	#Orientation is Left#

		%>
		<table border=0>
		<tr><td width=50% align=center valign=middle>
		<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);

		%>
		</td>
		<td width=50% align=left valign=middle>
	   	<%
	    	print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
				if (length($Notes) > 1) {
				$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</TD</TR></TABLE>
		<%

	    } #End LEFT Orientation#

	  if ($Orientation eq 'R') {
	   	#Orientation is Right#

		%>
		<table border=0>
		<tr><td width=50% align=left valign=middle>
		<%
		print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
			if (length($Notes) > 1) {
			$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</td>
		<td width=50% align=center valign=middle>
	   	<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);
		%>
		</TD</TR></TABLE>
		<%


	    } #End RIGHT Orientation#

        ### Check for Drop Downs ###
        my $rsDrops = $MyConn->Execute("SELECT * FROM DropDowns WHERE ProductID = $ProductID ORDER BY DropPriority");
        if (!$rsDrops->EOF) {
          my $dNum = 1;
          print "<form name='P$ProductID'>\n";
          while (!$rsDrops->EOF) {
        		my ($DropID,$Descript,$SD) = ($rsDrops->Fields('DropID')->value, $rsDrops->Fields('Description')->value, $rsDrops->Fields('SelectionRequired')->value);
        		print "<SELECT NAME='D$dNum'>\n";
        		print "\t<OPTION VALUE='R$SD' SELECTED> $Descript\n";
			my $rsDetail = $MyConn->Execute("SELECT * FROM DropDetail WHERE DropID = $DropID ORDER BY DetailPriority, DetailText");

			while (!$rsDetail->EOF) {
				my ($DetailText) = ($rsDetail->Fields('DetailText')->value);
				$DetailText =~ s/\"/&quot;/g;
				print "\t<OPTION VALUE=\"$DetailText\"> $DetailText\n";
				$rsDetail->MoveNext;
			}
			print "</SELECT>\n";
			$dNum++;
			$rsDrops->MoveNext;
		}
		print "<br><br><To order, please call 865-579-0737>";
		print "</form>";
	}
	elsif ($rsDrops->EOF) {
		  print "<To order this item, please call 865-579-0737>\n";
	}
        print "<P><HR WIDTH=\"80%\" SIZE=1 ALIGN=CENTER NOSHADE><P>\n";
        $Rset->MoveNext;
      }
    }
    $Rset->Close;

%>
<P>
<CENTER>
    <TABLE BORDER=0 CELLPADDING=4 WIDTH="60%" BGCOLOR="#000000">
    <TR>
    <TD ALIGN=CENTER>
    		<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=5 BGCOLOR="#FFFFFF">
		<TR><%= $catPage %></TR>
		<%= ($catLinks) ? "<TR>\n<TD COLSPAN=3 ALIGN=CENTER>$catLinks</TD></TR>\n" : '' %>
   		 </TABLE>
	</TD></TR>
	</TABLE>
</CENTER>
<P>
</td></tr>
</table>
<%
	&HTMLFooter;
    $MyConn->Close;
    $Response->End;
    exit;
} %>




<% sub ShowCats {
    ######################################
    ### Display List of Top Categories ###
    ######################################
    my $ii = 0;
    my $RS = $MyConn->Execute("SELECT DISTINCT Categories.CategoryID, Categories.Description FROM Categories WHERE Categories.ParentCategory < 1 AND Len(Description) > 1 ORDER BY Categories.Description");

    if(!$RS) {
        my $Errors = $MyConn->Errors();
        print "Errors:\n";
        foreach my $error (keys %$Errors) {
            $Response->write($error->{Description}."\n");
        }
        die;
    }

    &HTMLHeader();
%>
<FONT FACE="trebuchet MS">
<CENTER>
<BR>
<H2>Product Categories</h2>

<P>
<TABLE BORDER=0 CELLPADDING=8>
<%
    while(!$RS->EOF) {
        my($catid,$descript) = ( $RS->Fields('CategoryID')->value, $RS->Fields('Description')->value );
        $descript =~ s/\b(\w)/\U$1/g;
        if (!($ii % COLS)) {
            $Response->write("<TR>\n");
        }
        my $tlink = sprintf("action=grabcat&page=1&category=%d", $Server->URLEncode($catid));
        $Response->write(sprintf("    <TH ALIGN=CENTER><FONT FACE=\"arial\"><A HREF=\"store.asp?%s\">%s</A></FONT></TH>\n", $tlink, $descript));
        $ii++;
        if (!($ii % COLS)) {
            $Response->write("</TR>");
        }
        $RS->MoveNext;
    }
    if (($ii % COLS)) {
        $Response->write("\n    </TR>");
    }
    $RS->Close;
%>
</TABLE>
</CENTER>

<BR><BR><BR><BR><BR>
</FONT>

<%
	&HTMLFooter;
	$MyConn->Close;
    $Response->End;
    exit;
}

sub HTMLHeader {

	# Does header file exist
	my $HeaderFile = $Application->Contents('HTMLHeader');
	my $FullPath = $Application->Contents('FullPath');
	my $HeaderPath = "$FullPath\\$HeaderFile";
	my $FSYS = $Server->CreateObject("Scripting.FileSystemObject");

	if ($FSYS->FileExists($HeaderPath)) {
		my $HTMLFile = $FSYS->OpenTextFile($HeaderPath);
		my $AllFile = $HTMLFile->ReadAll();
		$Response->Write("$AllFile\n");
		$FSYS->Close();
	}
	else {

	my $subtitle = shift;
	my $title = $Application->{'SiteTitle'};
	if (length($subtitle) > 0) {
		$title .= ": $subtitle";
	}
%>
<HTML>
<HEAD>
<TITLE><%= $title %></TITLE>
</HEAD>
<BODY background="pics/wlbackground.jpg">


<%
	} #<!--End else-->#

}


sub HTMLFooter {

	# Does Footer file exist
	my $FooterFile = $Application->Contents('HTMLFooter');
	my $FullPath = $Application->Contents('FullPath');
	my $FooterPath = "$FullPath\\$FooterFile";
	my $FSYS = $Server->CreateObject("Scripting.FileSystemObject");

	if ($FSYS->FileExists($FooterPath)) {
		my $HTMLFile = $FSYS->OpenTextFile($FooterPath);
		my $AllFile = $HTMLFile->ReadAll();
		$Response->Write("$AllFile\n");
		$FSYS->Close();
	}
	else {
%>
        </td>
</tr>
</table>
<%  } %>
		<CENTER>
            <HR WIDTH=90% ALIGN=CENTER SIZE=1 NOSHADE>
            <P><font size=+1 face="arial">
            <a href="../">HOME</a><br><br></font>
                <FONT FACE="arial">
                <strong>E-Mail:</strong> <A HREF="mailto:<%=$Application->Contents('Email')%>"><%=$Application->Contents('Email')%></A>
                <P>
                <FONT SIZE=-1><I><B>
                <%=$Application->Contents('Copyright')%><BR>
                Produced by <A HREF="http://www.1stresource.com/" target=_top>1st Internet Resources</A></B></I></FONT>
                </FONT>
            <P>
        </CENTER>

</BODY>
</HTML>
<%
}

%>

<% sub GetItem {

	&HTMLHeader;
	%>
	<TABLE BORDER=0 WIDTH=98%>
	<TR><TD>
	<%
	my $Rset = $Server->CreateObject("ADODB.Recordset");
	$Rset->{'CursorLocation'} = 3;  ### Client-side Cursor ###
    $Rset->Open("SELECT ProductsTable.* FROM ProductsTable WHERE ProductsTable.ProductID = $key ORDER BY ProductsTable.WebOrdering, ProductsTable.ProductName, ProductsTable.ProductCode", $MyConn, 3, 1);

	  my ($ProductID, $ProductCode, $ProductName, $PictureFile, $UnitPrice, $MSRP, $Orientation, $Notes) = (
            $Rset->Fields('ProductID')->value,      $Rset->Fields('ProductCode')->value,
            $Rset->Fields('ProductName')->value,    $Rset->Fields('PictureFile')->value,
            $Rset->Fields('UnitPrice')->value,      $Rset->Fields('MSRP')->value,
            $Rset->Fields('Orientation')->value,		$Rset->Fields('Notes')->value );

	   $Orientation =~ s/ +$//g;
	   if (length($Orientation) < 1) {
	   	$Orientation = 'T';
		$Orientation =~ s/ +$//g;
	   }

	   #Select Additional Pics#
	   my $AddLink;
	   my $AddRS = $MyConn->Execute("SELECT * FROM AdditionalPics WHERE ProductID = $ProductID");
		if (!$AddRS->EOF) {
			$AddLink = "images.asp?ProductID=$ProductID";
		}
		else {
		undef($AddLink);
		}
	   $AddRS->Close();

	  	print "<a name=\"$ProductID\"></a>\n";
        ##Determine Orientation##
	   if ($Orientation eq 'T') {
	   	#Orientation is TOP#

		%>
		<table border=0 width=100%>
		<tr><td>
		<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);


		%>
		</td></tr>
		<tr><td>
	   	<%
	   	print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
			if (length($Notes) > 1) {
			$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</TD></TR>

		</TABLE>

		<%
	    } #End TOP Orientation#

   	   if ($Orientation eq 'L') {
	   	#Orientation is Left#

		%>
		<table border=0>
		<tr><td width=50% align=center valign=middle>
		<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);

		%>
		</td>
		<td width=50% align=left valign=middle>
	   	<%
	    	print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
			if (length($Notes) > 1) {
			$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</TD</TR></TABLE>
		<%

	    } #End LEFT Orientation#

	  if ($Orientation eq 'R') {
	   	#Orientation is Right#

		%>
		<table border=0>
		<tr><td width=50% align=left valign=middle>
		<%
		print "<FONT SIZE=+1 COLOR=\"$COLORProductHeader\"><B>$ProductName</B></FONT><BR>\n";
		print "<KBD>\U$ProductCode</KBD><BR>\n";
		$Response->Write(sprintf("<B>Our Price:</B> \$%1.2f", $UnitPrice));
		if ($MSRP > 0.01) {
		$Response->Write(sprintf("\n<BR><FONT SIZE=-2>Sugg. Retail Price: \$%1.2f</FONT><P>", $MSRP));
		} else {
			$Response->Write("<P>\n");
		}
		# Print out a description if available #
				if (length($Notes) > 1) {
				$Response->Write("<table border=0 width=300><tr><td>$Notes\n</td></tr></table>");
		}
		%>
		</td>
		<td width=50% align=center valign=middle>
	   	<%
		#Write out Picture if it exists#
		#Determine if Additional pics exist#

		$Response->Write("<A HREF=\"$AddLink\"> ") if ($AddLink);
		if (length($PictureFile) > 1) {
			$Response->Write("<IMG SRC=\"/prodpics/$PictureFile\" border=0>\n");
		}
		else {
			$Response->Write("Click here for Picture(s)\n") if ($AddLink);
		}
		$Response->Write("</A>\n") if ($AddLink);
		%>
		</TD</TR></TABLE>
		<%


	    } #End RIGHT Orientation#

        ### Check for Drop Downs ###
        my $rsDrops = $MyConn->Execute("SELECT * FROM DropDowns WHERE ProductID = $ProductID ORDER BY DropPriority");
        if (!$rsDrops->EOF) {
          my $dNum = 1;
          print "<form name='P$ProductID'>\n";
          while (!$rsDrops->EOF) {
        		my ($DropID,$Descript,$SD) = ($rsDrops->Fields('DropID')->value, $rsDrops->Fields('Description')->value, $rsDrops->Fields('SelectionRequired')->value);
        		print "<SELECT NAME='D$dNum'>\n";
        		print "\t<OPTION VALUE='R$SD' SELECTED> $Descript\n";
			my $rsDetail = $MyConn->Execute("SELECT * FROM DropDetail WHERE DropID = $DropID ORDER BY DetailPriority, DetailText");

			while (!$rsDetail->EOF) {
				my ($DetailText) = ($rsDetail->Fields('DetailText')->value);
				$DetailText =~ s/\"/&quot;/g;
				print "\t<OPTION VALUE=\"$DetailText\"> $DetailText\n";
				$rsDetail->MoveNext;
			}
			print "</SELECT>\n";
			$dNum++;
			$rsDrops->MoveNext;
		}
		print "<br><br><To order, please call 865-579-0737>";
		print "</form>";
	}
	elsif ($rsDrops->EOF) {
		  print "<To order, please call 865-579-0737>\n";
	}
        print "<P><HR WIDTH=\"80%\" SIZE=1 ALIGN=CENTER NOSHADE><P>\n";

    $Rset->Close;
	%>
	</TD></TR>
	</TABLE>
	<%
	&HTMLFooter;

	$Response->End;
	exit;

}
%>

