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

    $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;

    $Response->{Buffer} = 1;

	### Read Application Variables ###
	my $mySQL = $Application->Contents('Connection');
	my $MyConn = $Server->CreateObject("ADODB.Connection");
    $MyConn->Open($mySQL);

	my $ProductID = $Request->QueryString("ProductID")->Item(1);
	my $Page = $Request->QueryString("Page")->Item(1);
	my $Category = $Request->QueryString("Category")->Item(1);

	&ShowPics if ($ProductID > 0 && $Page > 0 && $Category > 0);

	$Response->Redirect("../");
	exit;


sub ShowPics {
	my $IntPicQTY;

	my $AddRS = $MyConn->Execute("SELECT ProductName FROM ProductsTable WHERE ProductID = $ProductID");
	my $ProductTitle = $AddRS->Fields("ProductName")->Value;
	$AddRS->Close;

	my $AddRS = $MyConn->Execute("SELECT PictureFile FROM AdditionalPics WHERE ProductID = $ProductID");

	#my $rsInt = $Server->CreateObject("ADODB.Recordset");
	#$rsInt->Open("SELECT * FROM InteriorPics WHERE RVID = $RVID", $MyConn, adOpenStatic, adLockOptimistic);

	&IMGHeader;
	$Response->Write("<title>$ProductTitle - Additional Pictures</title>\n");
%>
	<div align="center">
	  <center>
	  <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
	    <tr>
	      <td width="100%">
	        <div align="center">
<%
			$Response->Write("<br><center><h3>$ProductTitle - Additional Pictures</h3></center><br>\n");
%>
	          <table border="0" cellpadding="0" cellspacing="0" width="95%">

<%
	my $ColCount;
	my $PictureFile;

	$Response->Write("<tr>\n");
	while (!$AddRS->EOF) {
		$PictureFile = $AddRS->Fields("PictureFile")->Value;

		if ($ColCount eq 2) {
			#End the row and start fresh
			$Response->Write("</tr>\n");
			$Response->Write("<tr>\n");
			$ColCount = 0;
		}

		$Response->Write("<td width=\"50%\" align=\"center\">\n");
		#Write out the pic
		$Response->Write("<img src='../prodpics/$PictureFile' border='0'>\n");
		$Response->Write("</td>\n");

		$ColCount++;
		$AddRS->MoveNext;
	}

%>

	          </table>
		   <% if ($Category > 0 && $ProductID > 0) { %>
		   <form>
		   <input type="button" value="<< Return to Item" onClick="window.location.href='<%="store.asp?action=grabcat&page=$Page&category=$Category#$ProductID"%>'">
		   </form>
		   <% } %>
		   </div>
	      </td>
	    </tr>
	  </table>
	  </center>
	</div>


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


<% sub IMGHeader {

	# Does header file exist
	my $HeaderFile = $Application->Contents('IMGHeader');
	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 = "Shopping Cart";
	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>
<%
}

%>
