HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/homefly/inc/inccart.asp
<%
'This code is copyright (c) Internet Business Solutions SL, all rights reserved.
'The contents of this file are protect under law as the intellectual property
'of Internet Business Solutions SL. Any use, reproduction, disclosure or copying
'of any kind without the express and written permission of Internet Business 
'Solutions SL is forbidden.
'Author: Vince Reid, vince@virtualred.net
Dim sSQL,rs,alldata,quantity,grandtotal,netnav,bExists,cartID,cartEmpty,cnn,index,index2,rowcounter,objItem,storeurl,useEuro,packtogether,hasOptions,stockManage,totShipOptions
cartEmpty=False
isInStock=true
tempOutOfStock=false
netnav = true
if instr(Request.ServerVariables("HTTP_USER_AGENT"), "compatible") > 0 OR instr(Request.ServerVariables("HTTP_USER_AGENT"), "Gecko") > 0 then netnav = false
function atb(size)
	if netnav then
		atb = CInt(size / 2 + 1)
	else
		atb = size
	end if
end function
Set rs = Server.CreateObject("ADODB.RecordSet")
Set rs2 = Server.CreateObject("ADODB.RecordSet")
Set cnn=Server.CreateObject("ADODB.Connection")
cnn.open sDSN
sSQL = "SELECT adminEmail,adminStoreURL,adminHandling,countryLCID,countryCurrency,adminUSZones,adminStockManage,adminSubCats,adminShipping FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID WHERE adminID=1"
rs.Open sSQL,cnn,0,1
splitUSZones = (Int(rs("adminUSZones"))=1)
if rs("countryLCID")<>0 then Session.LCID = rs("countryLCID")
countryCurrency = rs("countryCurrency")
if orcurrencyisosymbol<>"" then countryCurrency=orcurrencyisosymbol
useEuro = (countryCurrency="EUR")
storeurl = rs("adminStoreURL")
if (left(LCase(storeurl),7) <> "http://") AND (left(LCase(storeurl),8) <> "https://") then
	storeurl = "http://" & storeurl
end if
if Right(storeurl,1) <> "/" then storeurl = storeurl & "/"
stockManage = rs("adminStockManage")
subCats=(Int(rs("adminSubCats"))=1)
handling=cDbl(rs("adminHandling"))
shipType = Int(rs("adminShipping"))
rs.Close
saveLCID = Session.LCID
if stockManage<>0 then
	tdt = DateAdd("h",0-stockManage,now())
	sSQL = "DELETE FROM cart WHERE cartCompleted=0 AND cartOrderID=0 AND cartDateAdded<" & datedelim & DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt) & " " & DatePart("h",tdt) & ":" & DatePart("n",tdt) & ":" & DatePart("s",tdt) & datedelim
	cnn.Execute(sSQL)
end if
if request.form("mode")="update" then
	for each objItem In Request.Form
		if Left(objItem,5)="quant" then
			if Int(Request.form(objItem))=0 then
				sSQL="DELETE FROM cartOptions WHERE coCartID="&Right(objItem, Len(objItem)-5)
				cnn.Execute(sSQL)
				sSQL="DELETE FROM cart WHERE cartID="&Right(objItem, Len(objItem)-5)
				cnn.Execute(sSQL)
			else
				if stockManage<>0 then
					totQuant = 0
					sSQL="SELECT cartQuantity,pInStock,pID FROM cart INNER JOIN products ON cart.cartProdId=products.pID WHERE cartID="&Right(objItem, Len(objItem)-5)
					rs.Open sSQL,cnn,0,1
					if NOT rs.EOF then
						pID = rs("pID")
						pInStock = Int(rs("pInStock"))
						cartQuantity = Int(rs("cartQuantity"))
						rs.Close
						sSQL = "SELECT SUM(cartQuantity) AS cartQuant FROM cart WHERE cartCompleted=0 AND cartProdID='"&Trim(pID)&"'"
						rs.Open sSQL,cnn,0,1
						if NOT rs.EOF then
							if NOT IsNull(rs("cartQuant")) then totQuant = Int(rs("cartQuant"))
						end if
					end if
					rs.Close
					if (pInStock - totQuant + cartQuantity - Int(Request.form(objItem))) >= 0 then
						sSQL="UPDATE cart SET cartQuantity="&Request.form(objItem)&" WHERE cartID="&Right(objItem, Len(objItem)-5)
						cnn.Execute(sSQL)
					else
						isInStock = false
					end if
				else
					sSQL="UPDATE cart SET cartQuantity="&Request.form(objItem)&" WHERE cartID="&Right(objItem, Len(objItem)-5)
					cnn.Execute(sSQL)
				end if
			end if
		elseif Left(objItem,5)="delet" then
			sSQL="DELETE FROM cart WHERE cartID="&Right(objItem, Len(objItem)-5)
			cnn.Execute(sSQL)
			sSQL="DELETE FROM cartOptions WHERE coCartID="&Right(objItem, Len(objItem)-5)
			cnn.Execute(sSQL)
		end if
	next
end if
if request.form("mode")="add" then
	Session.LCID = 1033
	if Request.Form("quant")="" OR NOT IsNumeric(Request.Form("quant")) then
		quantity=1
	else
		quantity=Int(Request.Form("quant"))
	end if
	bExists=False
	sSQL = "SELECT cartID FROM cart WHERE cartCompleted=0 AND cartSessionID="&Session.SessionID&" AND cartProdID='"&Trim(Request.Form("id"))&"'"
	rs.Open sSQL,cnn,0,1
	do while (NOT rs.EOF) AND (NOT bExists)
		bExists=True
		cartID=rs("cartID")
		for each objForm in Request.Form ' We have the product. Check we have all the same options
			if Left(objForm,4)="optn" then
				if Trim(Request.Form("v"&objForm))<>"" then
					sSQL="SELECT coID FROM cartOptions WHERE coCartID="&cartID&" AND coOptID="&Request.Form(objForm)&" AND coCartOption='"&Request.Form("v"&objForm)&"'"
					rs2.Open sSQL,cnn,0,1
					if rs2.EOF then bExists=false
					rs2.Close
				else
					sSQL="SELECT coID FROM cartOptions WHERE coCartID="&cartID&" AND coOptID="&Request.Form(objForm)
					rs2.Open sSQL,cnn,0,1
					if rs2.EOF then bExists=false
					rs2.Close
				end if
			end if
			if NOT bExists then exit for
		next
		rs.MoveNext
	loop
	rs.Close
	sSQL = "SELECT pName,pPrice,pInStock FROM products WHERE pID='"&Request.Form("id")&"'"
	rs.Open sSQL,cnn,0,1
	alldata=rs.getrows
	rs.Close
	if stockManage<>0 then
		isInStock = ((alldata(2,0)-quantity) >= 0)
		if isInStock then ' Check cart
			totQuant = 0
			bestDate = DateAdd("m",2,now())
			sSQL = "SELECT cartQuantity,cartDateAdded,cartOrderID FROM cart WHERE cartCompleted=0 AND cartProdID='"&Trim(Request.Form("id"))&"'"
			rs.Open sSQL,cnn,0,1
			do while NOT rs.EOF
				totQuant=totQuant+rs("cartQuantity")
				if Int(rs("cartOrderID"))=0 AND rs("cartDateAdded") < bestDate then bestDate = rs("cartDateAdded")
				rs.MoveNext
			loop
			rs.Close
			if (alldata(2,0)-(totQuant+quantity)) < 0 then
				isInStock=false
				tempOutOfStock=true
			end if
		end if
	end if
	if isInStock then
		if bExists then
			sSQL = "UPDATE cart SET cartQuantity=cartQuantity+"&quantity&" WHERE cartID="&cartID
			cnn.Execute(sSQL)
		else
			rs.Open "cart",cnn,1,3,&H0002
			rs.AddNew
			rs.Fields("cartSessionID")		= Session.SessionID
			rs.Fields("cartProdID")			= trim(Request.Form("id"))
			rs.Fields("cartQuantity")		= quantity
			rs.Fields("cartCompleted")		= 0
			rs.Fields("cartProdName")		= alldata(0,0)
			rs.Fields("cartProdPrice")		= alldata(1,0)
			rs.Fields("cartDateAdded")		= Now()
			rs.Update
			cartID=rs.Fields("cartID")
			rs.Close
			hasOptions=false
			sProdOpts=""
			for each objForm in Request.Form
				if Left(objForm,4)="optn" then
					if Trim(Request.Form("v"&objForm))="" then
						sProdOpts = sProdOpts & addComma & Request.Form(objForm)
						addComma = ","
						hasOptions=true
					else
						sSQL="SELECT optID,OptGrpName,optName FROM options INNER JOIN optionGroup ON options.optGroup=optionGroup.optGrpID WHERE optID="&Request.Form(objForm)
						rs.Open sSQL,cnn,0,1
						sSQL = "INSERT INTO cartOptions (coCartID,coOptID,coOptGroup,coCartOption,coPriceDiff,coWeightDiff) VALUES ("&cartID&","&rs("optID")&",'"&Replace(rs("OptGrpName"),"'","''")&"','"&Replace(Request.Form("v"&objForm),"'","''")&"',0,0)"
						cnn.Execute(sSQL)
						rs.Close
					end if
				end if
			next
			if hasOptions then
				sSQL="SELECT optID,OptGrpName,optName,optPriceDiff,optWeightDiff,optType FROM options INNER JOIN optionGroup ON options.optGroup=optionGroup.optGrpID WHERE optID IN ("&sProdOpts&")"
				rs.Open sSQL,cnn,0,1
				prodoptions=rs.getrows
				rs.Close
				for index=0 to UBOUND(prodoptions,2)
					if abs(prodoptions(5,index))<> 3 then
						sSQL = "INSERT INTO cartOptions (coCartID,coOptID,coOptGroup,coCartOption,coPriceDiff,coWeightDiff) VALUES ("&cartID&","&prodoptions(0,index)&",'"&Replace(prodoptions(1,index),"'","''")&"','"&Replace(prodoptions(2,index),"'","''")&"',"&prodoptions(3,index)&","&prodoptions(4,index)&")"
					else
						sSQL = "INSERT INTO cartOptions (coCartID,coOptID,coOptGroup,coCartOption,coPriceDiff,coWeightDiff) VALUES ("&cartID&","&prodoptions(0,index)&",'"&Replace(prodoptions(1,index),"'","''")&"','',0,0)"
					end if
					cnn.Execute(sSQL)
				next
			end if
		end if
		response.write "<meta http-equiv=""Refresh"" content=""3; URL=cart.asp"">"
%>
      <table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
        <tr> 
          <td width="100%" align="center">
            <table width="<%=innertablewidth%>" border="0" cellspacing="<%=innertablespacing%>" cellpadding="<%=innertablepadding%>" bgcolor="<%=innertablebg%>">
			  <tr>
			    <td align="center"><p>&nbsp;</p>
				<p><%=quantity&" <b>"&alldata(0,0)&"</b> "&xxAddOrd%></p>
				<p><%=xxPlsWait%><a href="cart.asp"><b><%=xxClkHere%></b></a>.</p>
				<p>&nbsp;</p>
				<p>&nbsp;</p>
				</td>
			  </tr>
			</table>
		  </td>
        </tr>
      </table>
<%
	else
%>
      <table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
        <tr> 
          <td width="100%" align="center">
            <table width="<%=innertablewidth%>" border="0" cellspacing="<%=innertablespacing%>" cellpadding="<%=innertablepadding%>" bgcolor="<%=innertablebg%>">
			  <tr>
			    <td align="center"><p>&nbsp;</p>
				<% response.write "<p>" & xxSrryItm & " <b>" & alldata(0,0)&"</b> " & xxIsCntly
				if tempOutOfStock then response.write " " & xxTemprly
				response.write " " & xxOutStck & "</p>"
				if tempOutOfStock then
					response.write "<p>" & xxNotChOu & " "
					totMins = DateDiff("n",Now(),DateAdd("h",stockManage,bestDate))
					if totMins > 300 then
						response.write xxShrtWhl
					else
						if totMins >= 60 then response.write Int(totMins / 60) & " hour"
						if totMins >= 120 then response.write "s"
						totMins = totMins - (Int(totMins / 60) * 60)
						if totMins > 0 then response.write " " & totMins & " minute"
						if totMins > 1 then response.write "s"
					end if
					response.write xxChkBack & "</p>"
				end if %>
				<p><%=xxPlease%> <a href="javascript:history.go(-1)"><b><%=xxClkHere%></b></a> <%=xxToRetrn%></p>
				<p>&nbsp;</p>
				<p>&nbsp;</p>
				</td>
			  </tr>
			</table>
		  </td>
        </tr>
      </table>
<%
	end if
elseif Request.Form("mode")="checkout" then
	Dim ordName,ordAddress,ordCity,ordState,ordZip,ordCountry,ordEmail,ordPhone,ordShipName,ordShipAddress,ordShipCity,ordShipState,ordShipZip,ordShipCountry,ordAddInfo
	Dim remember,allstates,havestate,allcountries
	allstates=""
	allcountries=""
	remember=False
	if request.cookies("id1")<>"" AND request.cookies("id2")<>"" AND IsNumeric(request.cookies("id1")) AND IsNumeric(request.cookies("id2")) then
		sSQL = "SELECT ordName,ordAddress,ordCity,ordState,ordZip,ordCountry,ordEmail,ordPhone,ordShipName,ordShipAddress,ordShipCity,ordShipState,ordShipZip,ordShipCountry,ordPayProvider,ordComLoc,ordAddInfo FROM orders WHERE ordID="&request.cookies("id1")&" AND ordSessionID="&request.cookies("id2")
		rs.Open sSQL,cnn,1,3,&H0001
		if NOT rs.EOF then
			ordName = rs("ordName")
			ordAddress = rs("ordAddress")
			ordCity = rs("ordCity")
			ordState = rs("ordState")
			ordZip = rs("ordZip")
			ordCountry = rs("ordCountry")
			ordEmail = rs("ordEmail")
			ordPhone = rs("ordPhone")
			ordShipName = rs("ordShipName")
			ordShipAddress = rs("ordShipAddress")
			ordShipCity = rs("ordShipCity")
			ordShipState = rs("ordShipState")
			ordShipZip = rs("ordShipZip")
			ordShipCountry = rs("ordShipCountry")
			ordPayProvider = rs("ordPayProvider")
			ordComLoc = rs("ordComLoc")
			ordAddInfo = rs("ordAddInfo")
			remember=True
		end if
		rs.Close
	end if
%>
<script Language="JavaScript">
<!--
function checkform(frm)
{
if(frm.name.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxName%>\".");
	frm.name.focus();
	return (false);
}
if(frm.email.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxEmail%>\".");
	frm.email.focus();
	return (false);
}
if(frm.address.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxAddress%>\".");
	frm.address.focus();
	return (false);
}
if(frm.city.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxCity%>\".");
	frm.city.focus();
	return (false);
}
if(frm.country.options[frm.country.selectedIndex].value=='<%=replace(xxCntryTxt,"'","\'")%>'){
	if(frm.state.selectedIndex==0)
	{
		alert("<%=xxPlsSlct & " " & xxState%>.");
		frm.state.focus();
		return (false);
	}
}
else{
	if(frm.state2.value=="")
	{
		alert("<%=xxPlsEntr%> \"<%=Replace(xxNonState,"<br>"," ")%>\".");
		frm.state2.focus();
		return (false);
	}
}
if(frm.zip.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxZip%>\".");
	frm.zip.focus();
	return (false);
}
if(frm.phone.value=="")
{
	alert("<%=xxPlsEntr%> \"<%=xxPhone%>\".");
	frm.phone.focus();
	return (false);
}
<% if noshipaddress<>true then %>
if(frm.saddress.value!=""){
	if(frm.scity.value=="")
	{
		alert("<%=xxShpDtls%>\n\n<%=xxPlsEntr%> \"<%=xxCity%>\".");
		frm.scity.focus();
		return (false);
	}
	if(frm.scountry.options[frm.scountry.selectedIndex].value=='<%=replace(xxCntryTxt,"'","\'")%>'){
		if(frm.sstate.selectedIndex==0)
		{
			alert("<%=xxShpDtls%>\n\n<%=xxPlsSlct & " " & xxState%>.");
			frm.sstate.focus();
			return (false);
		}
	}
	else{
		if(frm.sstate2.value=="")
		{
			alert("<%=xxShpDtls%>\n\n<%=xxPlsEntr%> \"<%=Replace(xxNonState,"<br>"," ")%>\".");
			frm.sstate2.focus();
			return (false);
		}
	}
	if(frm.szip.value=="")
	{
		alert("<%=xxShpDtls%>\n\n<%=xxPlsEntr%> \"<%=xxZip%>\".");
		frm.szip.focus();
		return (false);
	}
}
<% end if %>
if(frm.remember.checked==false)
{
	if(confirm("<%=xxWntRem%>")){
		frm.remember.checked=true
	}
}
<% if termsandconditions=TRUE then %>
if(frm.license.checked==false)
{
	alert("<%=xxPlsProc%>");
	frm.license.focus();
	return (false);
}
<% end if %>
return (true);
}
<% if termsandconditions=TRUE then %>
function showtermsandconds(){
newwin=window.open("termsandconditions.asp","Terms","menubar=no, scrollbars=yes, width=420, height=380, directories=no,location=no,resizable=yes,status=no,toolbar=no");
}
<% end if %>
//-->
</script>
	  <table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
        <tr> 
          <td width="100%">
		    <form method="POST" action="cart.asp" onSubmit="return checkform(this)">
			  <input type="hidden" name="mode" value="go">
			  <input type="hidden" name="sessionid" value="<%=request.form("sessionid")%>">
			  <input type="hidden" name="PARTNER" value="<%=Request.Form("PARTNER")%>">
			  <table width="<%=innertablewidth%>" border="0" cellspacing="<%=innertablespacing%>" cellpadding="<%=innertablepadding%>" bgcolor="<%=innertablebg%>">
				<tr>
				  <td width="100%" align="center" colspan="4"><b><%=xxCstDtl%></b></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxName%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="name" size="<%=atb(20)%>" value="<%=ordName%>"></td>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxEmail%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="email" size="<%=atb(20)%>" value="<%=ordEmail%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxAddress%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="address" size="<%=atb(20)%>" value="<%=ordAddress%>"></td>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxCity%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="city" size="<%=atb(20)%>" value="<%=ordCity%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><%=xxState%>:</b></td>
				  <td width="25%" align="left"><select name="state" size="1">
<%
Function show_states(tstate)
	Dim foundmatch
	foundmatch=false
	if NOT IsArray(allstates) then
		sSQL = "SELECT stateName FROM states WHERE stateEnabled=1 ORDER BY stateName"
		rs.Open sSQL,cnn,0,1
		allstates=rs.getrows
		rs.Close
	end if
	response.write "<option value=''>"&xxOutState&"</option>"
	for rowcounter=0 to UBOUND(allstates,2)
		response.write "<option value='"&allstates(0,rowcounter)&"'"
		if tstate=allstates(0,rowcounter) then
			response.write " selected"
			foundmatch=true
		end if
		response.write ">"&allstates(0,rowcounter)&"</option>"&vbCrLf
	next
	show_states=foundmatch
End Function
havestate = show_states(ordState)
%>
					</select>
				  </td>
				  <td width="25%" align="right"><b><%=xxNonState%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="state2" size="<%=atb(20)%>" value="<% if not havestate then response.write ordState%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxCountry%>:</b></td>
				  <td width="25%" align="left"><select name="country" size="1">
<%
Sub show_countries(tcountry)
	if NOT IsArray(allcountries) then
		sSQL = "SELECT countryName FROM countries WHERE countryEnabled=1 ORDER BY countryOrder DESC, countryName"
		rs.Open sSQL,cnn,0,1
		allcountries=rs.getrows
		rs.Close
	end if
	for rowcounter=0 to UBOUND(allcountries,2)
		response.write "<option value='"&allcountries(0,rowcounter)&"'"
		if tcountry=allcountries(0,rowcounter) then
			response.write " selected"
		end if
		response.write ">"&allcountries(0,rowcounter)&"</option>"&vbCrLf
	next
End Sub
show_countries(ordCountry)
%>
					</select>
				  </td>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxZip%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="zip" size="<%=atb(10)%>" value="<%=ordZip%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><font color='#FF0000'>*</font><%=xxPhone%>:</b></td>
				  <td align="left" colspan="3"><input type="text" name="phone" size="<%=atb(20)%>" value="<%=ordPhone%>"></td>
				</tr>
			<%	if commercialloc=TRUE OR shipType=4 then %>
				<tr>
				  <td width="25%" align="right"><input type="checkbox" name="commercialloc" value="Y" <%if (ordComLoc AND 1)=1 then response.write "checked"%>></td>
				  <td align="left" colspan="3"><font size="1"><%=xxComLoc%></font></td>
				</tr>
			<%	end if
				if addshippinginsurance=2 then %>
				<tr>
				  <td width="25%" align="right"><input type="checkbox" name="wantinsurance" value="Y" <%if (ordComLoc AND 2)=2 then response.write "checked"%>></td>
				  <td align="left" colspan="3"><font size="1"><%=xxWantIns%></font></td>
				</tr>
			<%	end if
				if noshipaddress<>true then %>
				<tr>
				  <td width="100%" align="center" colspan="4"><b><%=xxShpDiff%></b></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><%=xxName%>:</b></td>
				  <td align="left" colspan="3"><input type="text" name="sname" size="<%=atb(20)%>" value="<%=ordShipName%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><%=xxAddress%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="saddress" size="<%=atb(20)%>" value="<%=Trim(ordShipAddress)%>"></td>
				  <td width="25%" align="right"><b><%=xxCity%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="scity" size="<%=atb(20)%>" value="<%=ordShipCity%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><%=xxState%>:</b></td>
				  <td width="25%" align="left"><select name="sstate" size="1">
<%
havestate = show_states(ordShipState)
%>
					</select>
				  </td>
				  <td width="25%" align="right"><b><%=xxNonState%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="sstate2" size="<%=atb(20)%>" value="<% if not havestate then response.write ordShipState%>"></td>
				</tr>
				<tr>
				  <td width="25%" align="right"><b><%=xxCountry%>:</b></td>
				  <td width="25%" align="left"><select name="scountry" size="1">
<%
show_countries(ordShipCountry)
%>
					</select>
				  </td>
				  <td width="25%" align="right"><b><%=xxZip%>:</b></td>
				  <td width="25%" align="left"><input type="text" name="szip" size="<%=atb(10)%>" value="<%=ordShipZip%>"></td>
				</tr>
			<%	end if ' noshipaddress %>
				<tr>
				  <td width="100%" align="center" colspan="4">
					<b><%=xxAddInf%>.</b><br>
					<textarea name="ordAddInfo" rows="3" wrap=virtual cols="<%=atb(44)%>"><%=ordAddInfo%></textarea> 
				  </td>
				</tr>
<% if termsandconditions=TRUE then %>
				<tr>
				  <td width="100%" align="center" colspan="4"><input type="checkbox" name="license" value="1">
					<%=xxTermsCo%>
				  </td>
				</tr>
<% end if %>
				<tr>
				  <td width="100%" align="center" colspan="4"><input type="checkbox" name="remember" value="1" <% if remember then response.write "checked"%>>
					<b><%=xxRemMe%></b><br>
					<font size="1"><%=xxOpCook%></font>
				  </td>
				</tr>
<%					if nogiftcertificate<>true then %>
				<tr>
				  <td align="right" colspan="2"><strong><%=xxGifNum%>:</strong></td><td colspan="2"><input type="text" name="cpncode" size="<%=atb(20)%>"></td>
				</tr>
				<tr>
				  <td align="center" colspan="4"><font size="1"><%=xxGifEnt%></font></td>
				</tr>
<%
					end if
					sSQL = "SELECT payProvID,PayProvShow FROM payprovider WHERE payProvEnabled=1 ORDER BY payProvOrder"
					rs.Open sSQL,cnn,0,1
					alldata=""
					if not rs.EOF then alldata=rs.getrows
					rs.Close
					if NOT IsArray(alldata) then
%>
				<tr>
				  <td colspan="4" align="center"><b><%=xxNoPay%></b></td>
				</tr>
<%
					elseif UBOUND(alldata,2)=0 then
%>
				<tr>
				  <td colspan="4" align="center"><input type="hidden" name="payprovider" value="<%=alldata(0,0)%>"><b><%=xxClkCmp%></b></td>
				</tr>
<%
					else
%>			    <tr>
				  <td colspan="4" align="center"><p><b><%=xxPlsChz%></b></p>
				    <p><select name="payprovider" size="1">
<%
						for rowcounter=0 to UBOUND(alldata,2)
							response.write "<option value='"&alldata(0,rowcounter)&"'"
							if ordPayProvider=alldata(0,rowcounter) then response.write " selected"
							response.write ">"&alldata(1,rowcounter)&"</option>"&vbCrLf
						next
%>
				    </select></p>
				  </td>
			    </tr>
<%
					end if
%>
				<tr>
				  <td width="50%" align="center" colspan="4"><input type="image" src="images/checkout.gif" border="0"></td>
				</tr>
			  </table>
			</form>
		  </td>
        </tr>
      </table>
<%
elseif Request.Form("mode")="go" then
%>
<!--#include file="uspsshipping.asp"-->
<%
	Dim demomode,data1,data2,success,errormsg,shipping,totalgoods,orderid,sXML,origZip,destZip,shipType,uspsUser,uspsPw,allzones,countryTax,stateTax,countryTaxRate,stateTaxRate,countryID,somethingToShip,taxfreegoods
	Dim iPounds,iOunces,iTotItems,international,origCountry,checkIntOptions,shipMethod,shipArr,shipcountry,intShipping(4,20),havematch,dHighest,dHighWeight,dTotalWeight,dTotalWeightOz,thePQuantity,thePWeight
	success=True
	checkIntOptions=False
	alldata = ""
	shipMethod = ""
	shipping = 0
	shipping2 = 0
	iTotItems = 0
	iWeight = 0
	countryTaxRate=0
	stateTaxRate=0
	countryTax=0
	stateTax=0
	stateAbbrev=""
	international = ""
	thePQuantity = 0
	thePWeight = 0
	iPounds = 0
	iOunces = 0
	runTotQuant = 0
	taxfreegoods = 0
	shipfreegoods = 0
	totalgoods = 0
	somethingToShip = false
	cpncode = Trim(replace(request.form("cpncode"),"'",""))
	cpnmessage = "<br>"
	gotcpncode=false
	totaldiscounts = 0
	isstandardship = false
	if Trim(request.form("saddress"))<>"" then
		shipcountry = trim(request.form("scountry"))
		shipstate = trim(request.form("sstate"))
		destZip = trim(request.form("szip"))
	else
		shipcountry = trim(request.form("country"))
		shipstate = trim(request.form("state"))
		destZip = trim(request.form("zip"))
	end if
	sSQL = "SELECT adminZipCode,adminPacking,adminShipping,adminUnits,adminUSPSUser,adminUSPSpw,adminUPSUser,adminUPSpw,adminUPSAccess,countryName,countryCode FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID"
	rs.Open sSQL,cnn,0,1
		packtogether=false
		if Int(rs("adminPacking"))=1 then packtogether=true
		origZip = rs("adminZipCode")
		shipType = Int(rs("adminShipping"))
		origCountry = rs("countryName")
		origCountryCode = rs("countryCode")
		uspsUser = rs("adminUSPSUser")
		uspsPw = rs("adminUSPSpw")
		upsUser = upsdecode(rs("adminUPSUser"))
		upsPw = upsdecode(rs("adminUPSpw"))
		upsAccess = rs("adminUPSAccess")
		if Int(rs("adminUnits"))=0 then adminUnits="KGS" else adminUnits="LBS"
	rs.Close
	sSQL = "SELECT countryID,countryName,countryTax,countryCode FROM countries WHERE countryName='"&trim(request.form("country"))&"'"
	rs.Open sSQL,cnn,0,1
		countryTaxRate = rs("countryTax")
		countryID = rs("countryID")
		countryCode = rs("countryCode")
	rs.Close
	if xxCntryTxt=trim(request.form("country")) then
		sSQL = "SELECT stateTax,stateAbbrev FROM states WHERE stateName='"&trim(request.form("state"))&"'"
		rs.Open sSQL,cnn,0,1
		if NOT rs.EOF then
			stateTaxRate=rs("stateTax")
			stateAbbrev=rs("stateAbbrev")
		end if
		rs.Close
	end if
	if shipcountry <> origCountry then international = "Intl"
	if shipType=2 OR shipType=5 then ' Weight / Price based shipping
		allzones=""
		useUSState=false
		if splitUSZones then
			if shipcountry=trim(xxCntryTxt) then useUSState=true
			if useUSState then
				sSQL = "SELECT stateZone,zcWeight,zcRate,zcRate2,pzMultiShipping FROM states INNER JOIN (zoneCharges INNER JOIN postalzones ON zoneCharges.zcZone=postalzones.pzID) ON states.stateZone=zoneCharges.zcZone WHERE stateName='"&shipstate&"' ORDER BY zcWeight"
				rs.Open sSQL,cnn,0,1
				if NOT (rs.EOF OR rs.BOF) then allzones=rs.getrows
				rs.Close
			end if
		end if
		if NOT useUSState then
			sSQL = "SELECT countryZone,zcWeight,zcRate,zcRate2,pzMultiShipping FROM countries INNER JOIN (zoneCharges INNER JOIN postalzones ON zoneCharges.zcZone=postalzones.pzID) ON countries.countryZone=zoneCharges.zcZone WHERE countryName='"&shipcountry&"' ORDER BY zcWeight"
			rs.Open sSQL,cnn,0,1
			if NOT (rs.EOF OR rs.BOF) then allzones=rs.getrows
			rs.Close
		end if
	elseif shipType=3 then ' USPS
		sSQL = "SELECT uspsMethod,uspsShowAs FROM uspsMethods WHERE uspsID<100 uspsUseMethod=1 AND uspsLocal="
		if international="" then sSQL=sSQL&"1" else sSQL=sSQL&"0"
		rs.Open sSQL,cnn,0,1
		if NOT rs.EOF then
			uspsmethods=rs.GetRows()
		else
			success=false
			errormsg = "USPS Admin Error: " & xxNoMeth
		end if
		rs.Close
	elseif shipType=4 then ' UPS
		sSQL = "SELECT uspsMethod FROM uspsMethods WHERE uspsID>100 AND uspsID<200 AND uspsUseMethod=1"
		rs.Open sSQL,cnn,0,1
		if NOT rs.EOF then
			uspsmethods=rs.GetRows()
		else
			success=false
			errormsg = "UPS Admin Error: " & xxNoMeth
		end if
		rs.Close
		sSQL = "SELECT countryCode FROM countries WHERE countryName='"&shipcountry&"'"
		rs.Open sSQL,cnn,0,1
		destCountryCode = rs("countryCode")
		rs.Close
	end if
	sSQL = "SELECT cartID,cartProdID,pName,pPrice,cartQuantity,pWeight,pShipping,pShipping2,pExemptions,pSection,topSection FROM cart INNER JOIN (products LEFT OUTER JOIN sections ON products.pSection=sections.sectionID) ON cart.cartProdID=products.pID WHERE cartCompleted=0 AND cartSessionID="&Request.form("sessionid")
	rs.Open sSQL,cnn,0,1
	if NOT (rs.EOF OR rs.BOF) then alldata=rs.getrows
	rs.Close
	if success AND IsArray(alldata) then
		if shipType=3 then
			sXML = "<"&international&"RateRequest USERID="""&uspsUser&""" PASSWORD="""&uspsPw&""">"
		elseif shipType=4 then
			sXML = "<?xml version=""1.0""?><AccessRequest xml:lang=""en-US""><AccessLicenseNumber>"&upsAccess&"</AccessLicenseNumber><UserId>"&upsUser&"</UserId><Password>"&upsPw&"</Password></AccessRequest><?xml version=""1.0""?>"
			sXML = sXML & "<RatingServiceSelectionRequest xml:lang=""en-US""><Request><TransactionReference><CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference>"
			sXML = sXML & "<RequestAction>Rate</RequestAction><RequestOption>shop</RequestOption></Request>"
			if upspickuptype<>"" then sXML = sXML & "<PickupType><Code>"&upspickuptype&"</Code></PickupType>"
			sXML = sXML & "<Shipment><Shipper><Address>"
			sXML = sXML & "<PostalCode>"&origZip&"</PostalCode>"
			sXML = sXML & "<CountryCode>"&origCountryCode&"</CountryCode>"
			sXML = sXML & "</Address></Shipper><ShipTo><Address>"
			sXML = sXML & "<PostalCode>"&destZip&"</PostalCode>"
			sXML = sXML & "<CountryCode>"&destCountryCode&"</CountryCode>"
			if Request.Form("commercialloc")<>"Y" then sXML = sXML & "<ResidentialAddress/>"
			sXML = sXML & "</Address></ShipTo>"
			'sXML = sXML & "<Service><Code>11</Code></Service>"
		end if
		rowcounter = 0
		For index=0 to UBOUND(alldata,2)
			sSQL = "SELECT SUM(coPriceDiff) AS coPrDff FROM cartOptions WHERE coCartID="&alldata(0,index)
			rs.Open sSQL,cnn,0,1
			if NOT rs.EOF then
				if NOT IsNull(rs("coPrDff")) then alldata(3,index)=cDbl(alldata(3,index))+cDbl(rs("coPrDff"))
			end if
			rs.Close
			sSQL = "SELECT SUM(coWeightDiff) AS coWghtDff FROM cartOptions WHERE coCartID="&alldata(0,index)
			rs.Open sSQL,cnn,0,1
			if NOT rs.EOF then
				if NOT IsNull(rs("coWghtDff")) then alldata(5,index)=cDbl(alldata(5,index))+cDbl(rs("coWghtDff"))
			end if
			rs.Close
			runTot=(alldata(3,index)*Int(alldata(4,index)))
			runTotQuant = runTotQuant + alldata(4,index)
			totalgoods=totalgoods+runTot
			thistopcat=0
			if NOT subCats then alldata(10,index)=0
			if alldata(8,index)=1 OR alldata(8,index)=3 then taxfreegoods = taxfreegoods + runTot
			if alldata(8,index)=2 OR alldata(8,index)=3 then shipfreegoods = shipfreegoods + runTot
			Session.LCID = 1033
			tdt = Date()
			sSQL = "SELECT cpnID,cpnWorkingName,cpnType,cpnNumber,cpnDiscount,cpnThreshold FROM coupons LEFT OUTER JOIN cpnAssign ON coupons.cpnID=cpnAssign.cpaCpnID WHERE (cpnSitewide=0 OR cpnSitewide=2) AND cpnNumAvail>0 AND cpnThreshold<="&runTot&" AND (cpnThresholdMax>"&runTot&" OR cpnThresholdMax=0) AND cpnQuantity<="&alldata(4,index)&" AND (cpnQuantityMax>"&alldata(4,index)&" OR cpnQuantityMax=0) AND cpnEndDate>="&datedelim&DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt)&datedelim&" AND (cpnIsCoupon=0 OR (cpnIsCoupon=1 AND cpnNumber='"&cpncode&"')) AND (cpnSitewide=2 OR (cpaType=0 AND cpaAssignment='"&alldata(10,index)&"') OR (cpaType=1 AND cpaAssignment='"&alldata(9,index)&"') OR (cpaType=2 AND cpaAssignment='"&alldata(1,index)&"'))"
			rs.Open sSQL,cnn,0,1
			do while NOT rs.EOF
				if rs("cpnType")=1 then ' Flat Rate Discount
					if cpncode<>"" AND LCase(Trim(rs("cpnNumber")))=LCase(cpncode) then gotcpncode=true
					if InStr(cpnmessage,"<br>" & rs("cpnWorkingName") & "<br>")=0 then cpnmessage = cpnmessage & rs("cpnWorkingName") & "<br>"
					if cDbl(rs("cpnDiscount")) > runTot then
						totaldiscounts = totaldiscounts + runTot
					else
						totaldiscounts = totaldiscounts + cDbl(rs("cpnDiscount"))
					end if
					if alldata(8,index)=1 OR alldata(8,index)=3 then taxfreegoods = taxfreegoods - cDbl(rs("cpnDiscount"))
					if alldata(8,index)=2 OR alldata(8,index)=3 then shipfreegoods = shipfreegoods - cDbl(rs("cpnDiscount"))
					cnn.Execute("UPDATE coupons SET cpnNumAvail=cpnNumAvail-1 WHERE cpnNumAvail>0 AND cpnNumAvail<30000000 AND cpnID=" & rs("cpnID"))
				elseif rs("cpnType")=2 then ' Percentage Discount
					if cpncode<>"" AND LCase(Trim(rs("cpnNumber")))=LCase(cpncode) then gotcpncode=true
					if InStr(cpnmessage,"<br>" & rs("cpnWorkingName") & "<br>")=0 then cpnmessage = cpnmessage & rs("cpnWorkingName") & "<br>"
					totaldiscounts = totaldiscounts + ((cDbl(rs("cpnDiscount")) * cDbl(runTot)) / 100.0)
					if alldata(8,index)=1 OR alldata(8,index)=3 then taxfreegoods = taxfreegoods - ((cDbl(rs("cpnDiscount")) * cDbl(runTot)) / 100.0)
					if alldata(8,index)=2 OR alldata(8,index)=3 then shipfreegoods = shipfreegoods - ((cDbl(rs("cpnDiscount")) * cDbl(runTot)) / 100.0)
					cnn.Execute("UPDATE coupons SET cpnNumAvail=cpnNumAvail-1 WHERE cpnNumAvail>0 AND cpnNumAvail<30000000 AND cpnID=" & rs("cpnID"))
				end if
				rs.MoveNext
			loop
			rs.Close
			Session.LCID = saveLCID
			if packtogether then
				iTotItems = 1
			else
				iTotItems = iTotItems + Int(alldata(4,index))
			end if
			shipThisProd=true
			if alldata(8,index)=2 OR alldata(8,index)=3 then ' No Shipping on this product
				if NOT packtogether then iTotItems = iTotItems - Int(alldata(4,index))
				shipThisProd=false
			end if
			if shipType=1 then ' Flat rate shipping
				if shipThisProd then shipping = shipping + alldata(6,index) + (alldata(7,index) * (alldata(4,index)-1))
			elseif (shipType=2 OR shipType=5) AND request.form("shipping")="" then ' Weight / Price based shipping
				havematch=false
				dHighest=0
				dHighest2=0
				if IsArray(allzones) then
					if shipThisProd then
						somethingToShip=true
						if packtogether then
							if shipType=2 then
								thePWeight = thePWeight + (cDbl(alldata(4,index))*cDbl(alldata(5,index)))
							else
								thePWeight = thePWeight + (cDbl(alldata(4,index))*cDbl(alldata(3,index)))
							end if
							thePQuantity = 1
						else
							if shipType=2 then
								thePWeight = cDbl(alldata(5,index))
							else
								thePWeight = cDbl(alldata(3,index))
							end if
							thePQuantity = cDbl(alldata(4,index))
						end if
					end if
					if ((NOT packtogether AND shipThisProd) OR (packtogether AND index=UBOUND(alldata,2))) AND somethingToShip then ' Only calculate pack together when we have the total
						for index2=0 to UBOUND(allzones,2)
							if allzones(1,index2)>=thePWeight then
								havematch=true
								shipping=shipping+(cDbl(allzones(2,index2))*thePQuantity)
								shipping2=shipping2+(cDbl(allzones(3,index2))*thePQuantity)
								exit for
							end if
							dHighWeight=allzones(1,index2)
							dHighest=allzones(2,index2)
							dHighest2=allzones(3,index2)
						next
						if NOT havematch then
							shipping = shipping + dHighest
							shipping2 = shipping2 + dHighest2
							if allzones(1,0) < 0 then
								dHighWeight = thePWeight - dHighWeight
								do while dHighWeight > 0
									shipping = shipping + (cDbl(allzones(2,0))*thePQuantity)
									shipping2 = shipping2 + (cDbl(allzones(3,0))*thePQuantity)
									dHighWeight = dHighWeight + allzones(1,0)
								loop
							end if
						end if
					end if
				end if
			elseif shipType=3 AND request.form("shipping")="" then ' USPS Shipping
				if packtogether then
					if shipThisProd then
						somethingToShip=true
						iPounds = iPounds + (Int(alldata(5,index)) * Int(alldata(4,index)))
						iOunces = iOunces + ((cInt((cDbl(alldata(5,index))-cDbl(Int(alldata(5,index))))*100)) * Int(alldata(4,index)))
					end if
					if index = UBOUND(alldata,2) AND somethingToShip then
						iPounds = iPounds + Int(cDbl(iOunces)/16.0)
						iOunces = iOunces - Int(Int(cDbl(iOunces)/16.0)*16)
						if international <> "" then
							sXML = sXML & addInternational(rowcounter,iPounds,iOunces,"Package",shipcountry)
						else
							sXML = sXML & addDomestic(rowcounter,"Parcel",origZip,destZip,iPounds,iOunces,"None","REGULAR","True")
						end if
						rowcounter = rowcounter + 1
					end if
				else
					if shipThisProd then
						somethingToShip=true
						iPounds=Int(alldata(5,index))
						iOunces=cInt((cDbl(alldata(5,index))-cDbl(iPounds))*100)
						iPounds = iPounds + Int(cDbl(iOunces)/16.0)
						iOunces = iOunces - Int(Int(cDbl(iOunces)/16.0)*16)
						For index2=0 to Int(alldata(4,index))-1
							if international <> "" then
								sXML = sXML & addInternational(rowcounter,iPounds,iOunces,"Package",shipcountry)
							else
								sXML = sXML & addDomestic(rowcounter,"Parcel",origZip,destZip,iPounds,iOunces,"None","REGULAR","True")
							end if
							rowcounter = rowcounter + 1
						Next
					end if
				end if
			elseif shipType=4 AND request.form("shipping")="" then ' UPS Shipping
				Session.LCID = 1033
				if upspacktype="" then upspacktype="02"
				if packtogether then
					if shipThisProd then
						somethingToShip=true
						iWeight = iWeight + (cDbl(alldata(5,index)) * Int(alldata(4,index)))
					end if
					if index = UBOUND(alldata,2) AND somethingToShip then
						sXML = sXML & addUPSInternational(iWeight,adminUnits,upspacktype,destCountryCode,totalgoods-shipfreegoods)
					end if
				else
					if shipThisProd then
						somethingToShip=true
						iWeight=alldata(5,index)
						For index2=0 to Int(alldata(4,index))-1
							sXML = sXML & addUPSInternational(iWeight,adminUnits,upspacktype,destCountryCode,alldata(3,index))
						Next
					end if
				end if
				Session.LCID = saveLCID
			end if
		Next
		if (shipType=2 OR shipType=5) AND somethingToShip then
			checkIntOptions = (request.form("shipping")="")
			if IsArray(allzones) then
				if allzones(4,0) = 0 then checkIntOptions = FALSE
			else
				checkIntOptions = FALSE
			end if
		elseif shipType=3 AND somethingToShip then
			checkIntOptions = (request.form("shipping")="")
			if request.form("shipping")="" then
				sXML = sXML & "</"&international&"RateRequest>"
				success = USPSCalculate(sXML,international,shipping, errormsg, intShipping)
				if success AND checkIntOptions then ' Look for a single valid shipping option
					totShipOptions = 0
					for index=0 to UBOUND(intShipping,2)
						if iTotItems=intShipping(3,index) then
							for index2=0 to UBOUND(uspsmethods,2)
								if Trim(intShipping(0,index)) = Trim(uspsmethods(0,index2)) then
									totShipOptions = totShipOptions + 1
									shipping = intShipping(2,index)
									shipMethod = Trim(uspsmethods(1,index2))
								end if
							next
						end if
					next
					if totShipOptions=1 then
						checkIntOptions=False
					elseif totShipOptions=0 then
						checkIntOptions=False
						success=False
						errormsg=xxNoMeth
					end if
				elseif NOT success then
					errormsg = "USPS error: " & errormsg
				end if
			end if
		elseif shipType=4 AND somethingToShip then
			checkIntOptions = (request.form("shipping")="")
			if request.form("shipping")="" then
				sXML = sXML & "<ShipmentServiceOptions/></Shipment></RatingServiceSelectionRequest>"
				' response.write Replace(Replace(sXML,"</","&lt;/"),"<","<br>&lt;")&"<BR><hr>"
				if Trim(upsUser)<>"" AND Trim(upsPw)<>"" then
					success = UPSCalculate(sXML,international,shipping, errormsg, intShipping)
				else
					success = false
					errormsg = "You must register with UPS by logging on to your online admin section and clicking the &quot;Register with UPS&quot; link before you can use the UPS OnLine&reg; Shipping Rates and Services Selection"
				end if
				if success then
					totShipOptions = 0
					for index=0 to UBOUND(intShipping,2)
						if intShipping(3,index)=true then
							totShipOptions = totShipOptions + 1
							shipping = intShipping(2,index)
							shipMethod = intShipping(1,index)
						end if
					next
					if totShipOptions=1 then
						checkIntOptions=False
					elseif totShipOptions=0 then
						checkIntOptions=False
						success=False
						errormsg=xxNoMeth
					end if
				end if
			end if
		elseif request.form("shipping")<>"" then
			shipArr = split(request.form("shipping"),"|")
			shipping = CDbl(shipArr(0))
			isstandardship = Int(shipArr(1))=0
			shipMethod = shipArr(2)
		end if
		if taxShipping=1 AND Trim(request.form("shipping"))="" then
			stateshippingtax = (cDbl(shipping)*cDbl(stateTaxRate))/100.0
			shipping = shipping + (cDbl(shipping)*cDbl(countryTaxRate))/100.0
			shipping = shipping + stateshippingtax
			stateshippingtax = (cDbl(shipping2)*cDbl(stateTaxRate))/100.0
			shipping2 = shipping2 + (cDbl(shipping2)*cDbl(countryTaxRate))/100.0
			shipping2 = shipping2 + stateshippingtax
		end if
		if NOT checkIntOptions then
			freeshipamnt = 0
			sSQL = "SELECT countryID FROM countries WHERE countryName='"&shipcountry&"' AND countryFreeShip=1"
			rs.Open sSQL,cnn,0,1
			freeshipapplies = (NOT rs.EOF)
			rs.Close
			Session.LCID = 1033
			tdt = Date()
			sSQL = "SELECT cpnID,cpnWorkingName,cpnType,cpnNumber,cpnDiscount,cpnThreshold,cpnCntry FROM coupons WHERE cpnSitewide=1 AND cpnNumAvail>0 AND cpnThreshold<="&totalgoods&" AND (cpnThresholdMax>"&totalgoods&" OR cpnThresholdMax=0) AND cpnQuantity<="&runTotQuant&" AND (cpnQuantityMax>"&runTotQuant&" OR cpnQuantityMax=0) AND cpnEndDate>="&datedelim&DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt)&datedelim&" AND (cpnIsCoupon=0 OR (cpnIsCoupon=1 AND cpnNumber='"&cpncode&"'))"
			rs.Open sSQL,cnn,0,1
			do while NOT rs.EOF
				cpnType=Int(rs("cpnType"))
				if cpnType=0 then ' Free Shipping
					if freeshipapplies OR Int(rs("cpnCntry"))=0 then
						if cpncode<>"" AND LCase(Trim(rs("cpnNumber")))=LCase(cpncode) then gotcpncode=true
						if request.form("shipping")="" OR isstandardship then
							if InStr(cpnmessage,"<br>" & rs("cpnWorkingName") & "<br>")=0 then cpnmessage = cpnmessage & rs("cpnWorkingName") & "<br>"
							freeshipamnt = shipping
							cnn.Execute("UPDATE coupons SET cpnNumAvail=cpnNumAvail-1 WHERE cpnNumAvail>0 AND cpnNumAvail<30000000 AND cpnID=" & rs("cpnID"))
						end if
					end if
				elseif cpnType=1 then ' Flat Rate Discount
					if cpncode<>"" AND LCase(Trim(rs("cpnNumber")))=LCase(cpncode) then gotcpncode=true
					if InStr(cpnmessage,"<br>" & rs("cpnWorkingName") & "<br>")=0 then cpnmessage = cpnmessage & rs("cpnWorkingName") & "<br>"
					totaldiscounts = totaldiscounts + cDbl(rs("cpnDiscount"))
					cnn.Execute("UPDATE coupons SET cpnNumAvail=cpnNumAvail-1 WHERE cpnNumAvail>0 AND cpnNumAvail<30000000 AND cpnID=" & rs("cpnID"))
				elseif cpnType=2 then ' Percentage Discount
					if cpncode<>"" AND LCase(Trim(rs("cpnNumber")))=LCase(cpncode) then gotcpncode=true
					if InStr(cpnmessage,"<br>" & rs("cpnWorkingName") & "<br>")=0 then cpnmessage = cpnmessage & rs("cpnWorkingName") & "<br>"
					totaldiscounts = totaldiscounts + ((cDbl(rs("cpnDiscount")) * cDbl(totalgoods)) / 100.0)
					cnn.Execute("UPDATE coupons SET cpnNumAvail=cpnNumAvail-1 WHERE cpnNumAvail>0 AND cpnNumAvail<30000000 AND cpnID=" & rs("cpnID"))
				end if
				rs.MoveNext
			loop
			rs.Close
			Session.LCID = saveLCID
			cpnmessage = Right(cpnmessage,Len(cpnmessage)-4)
			if totaldiscounts > totalgoods then totaldiscounts = totalgoods
			if freeshipamnt > shipping then freeshipamnt = shipping
			if totalgoods>0 then
				stateTax = ((cDbl(totalgoods)-cDbl(totaldiscounts))*cDbl(stateTaxRate)/100.0)-(((cDbl(totalgoods)-cDbl(totaldiscounts))*cDbl(stateTaxRate)/100.0)*(cDbl(taxfreegoods)/cDbl(totalgoods)))
				countryTax = ((cDbl(totalgoods)-cDbl(totaldiscounts))*cDbl(countryTaxRate)/100.0)-(((cDbl(totalgoods)-cDbl(totaldiscounts))*cDbl(countryTaxRate)/100.0)*(cDbl(taxfreegoods)/cDbl(totalgoods)))
			end if
			if taxShipping=2 AND (shipping - freeshipamnt > 0) then
				stateTax = stateTax + (cDbl(shipping)-cDbl(freeshipamnt))*(cDbl(stateTaxRate)/100.0)
				countryTax = countryTax + (cDbl(shipping)-cDbl(freeshipamnt))*(cDbl(countryTaxRate)/100.0)
			end if
			if stateTax < 0 then stateTax = 0
			if countryTax < 0 then countryTax = 0
			totaldiscounts = totaldiscounts + freeshipamnt
			grandtotal = (totalgoods + shipping + stateTax + countryTax + handling) - totaldiscounts
			if grandtotal < 0 then grandtotal = 0
			sSQL = "SELECT ordID FROM orders WHERE ordSessionID="&trim(request.form("sessionid"))&" AND ordAuthNumber=''"
			rs.Open sSQL,cnn,0,1
			if NOT rs.EOF then orderid=rs("ordID") else orderid=""
			rs.Close
			if orderid="" then
				rs.Open "orders",cnn,1,3,&H0002
				rs.AddNew
			else
				rs.Open "SELECT * FROM orders WHERE ordID="&orderid,cnn,1,3,&H0001
			end if
			rs.Fields("ordSessionID")	= trim(request.form("sessionid"))
			rs.Fields("ordName")		= trim(request.form("name"))
			rs.Fields("ordAddress")		= trim(request.form("address"))
			rs.Fields("ordCity")		= trim(request.form("city"))
			if trim(request.form("state"))<>"" then
				rs.Fields("ordState")		= trim(request.form("state"))
			else
				rs.Fields("ordState")		= trim(request.form("state2"))
			end if
			rs.Fields("ordZip")			= trim(request.form("zip"))
			rs.Fields("ordCountry")		= trim(request.form("country"))
			rs.Fields("ordEmail")		= trim(request.form("email"))
			rs.Fields("ordPhone")		= trim(request.form("phone"))
			rs.Fields("ordShipName")	= trim(request.form("sname"))
			rs.Fields("ordShipAddress")	= trim(request.form("saddress"))
			rs.Fields("ordShipCity")	= trim(request.form("scity"))
			if trim(request.form("sstate"))<>"" then
				rs.Fields("ordShipState")	= trim(request.form("sstate"))
			else
				rs.Fields("ordShipState")	= trim(request.form("sstate2"))
			end if
			rs.Fields("ordShipZip")		= trim(request.form("szip"))
			rs.Fields("ordShipCountry")	= trim(request.form("scountry"))
			rs.Fields("ordPayProvider") = trim(Request.Form("payprovider"))
			rs.Fields("ordAuthNumber")	= "" ' Not yet authorized
			rs.Fields("ordShipping")	= shipping
			rs.Fields("ordStateTax")	= stateTax
			rs.Fields("ordCountryTax")	= countryTax
			rs.Fields("ordHandling")	= handling
			rs.Fields("ordShipType")	= shipMethod
			rs.Fields("ordTotal")		= totalgoods
			rs.Fields("ordDate")		= Now()
			rs.Fields("ordIP")			= request.servervariables("REMOTE_HOST")
			ordComLoc=0
			if Trim(request.form("commercialloc"))="Y" then ordComLoc = 1
			if Trim(request.form("wantinsurance"))="Y" OR addshippinginsurance=1 then ordComLoc = ordComLoc + 2
			rs.Fields("ordComLoc") = ordComLoc
			if Trim(request.form("demo"))="Y" then
				rs.Fields("ordDemoMode")= 1
			end if
			rs.Fields("ordAffiliate")	= Trim(Request.Form("PARTNER"))
			rs.Fields("ordAddInfo")		= trim(Request.Form("ordAddInfo"))
			rs.Fields("ordDiscount")	= totaldiscounts
			rs.Fields("ordDiscountText")= Left(cpnmessage,255)
			rs.Update
			orderid  = rs.Fields("ordID")
			rs.Close
			sSQL="UPDATE cart SET cartOrderID="&orderid&" WHERE cartCompleted=0 AND cartSessionID="&trim(request.form("sessionid"))
			cnn.Execute(sSQL)
			descstr=""
			addComma = ""
			sSQL="SELECT cartQuantity,cartProdName FROM cart WHERE cartOrderID="&orderid&" AND cartCompleted=0"
			rs.Open sSQL,cnn,0,1
			do while NOT rs.EOF
				descstr=descstr&addComma&rs("cartQuantity")&" "&rs("cartProdName")
				addComma = ", "
				rs.MoveNext
			loop
			rs.Close
			descstr=Replace(descstr,"""","")
			if request.form("remember")="1" then
				response.write "<script src='vsadmin/savecookie.asp?id1="&orderid&"&id2="&trim(request.form("sessionid"))&"'></script>"
			end if
		end if
	else
		success=False
	end if
	if checkIntOptions AND success then
		success = False ' So not to print the order totals.
%>
	<br>
	<form method="post" action="cart.asp">
	  <%
		for each objItem in request.form
			response.write "<input type='hidden' name='"&objItem&"' value="""&Replace(request.Form(objItem),"""","&quot;")&""">"&vbCrLf
		next
	  %>
      <table border="0" cellspacing="0" cellpadding="0" width="<%=maintablewidth%>" bgcolor="#B1B1B1" align="center">
        <tr> 
          <td width="100%">
            <table width="100%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">
			  <tr>
			    <td height="34" align="center" bgcolor="#EBEBEB"><b><%=xxShpOpt%></b></td>
			  </tr>
			  <tr>
				<td height="34" align="center" bgcolor="#FFFFFF">
				  <table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF">
					<tr>
					  <td height="74" align="right" width="50%" bgcolor="#FFFFFF"><% if shipType=4 then response.write "<img src='images/LOGO_S.gif'>&nbsp;&nbsp;" else response.write "&nbsp;" %></td>
					  <td height="74" align="center" bgcolor="#FFFFFF"><%
						response.write "<select name='shipping' size='1'>"
						if shipType=2 OR shipType=5 then
							response.write "<option value='"&shipping&"|0|" & standardship & "'>"
							response.write standardship & " " & FormatEuroCurrency(shipping) & "</option>"
							response.write "<option value='"&shipping2&"|1|"& expressship &"'>"
							response.write expressship & " " & FormatEuroCurrency(shipping2) & "</option>"
						else
							for index2=0 to UBOUND(intShipping,2)
								intShipping(2,index2) = cDbl(intShipping(2,index2))
								for index=1 to UBOUND(intShipping,2)
									if cDbl(intShipping(2,index))<cDbl(intShipping(2,index-1)) then
										tt0 = intShipping(0,index)
										tt1 = intShipping(1,index)
										tt2 = intShipping(2,index)
										tt3 = intShipping(3,index)
										intShipping(0,index) = intShipping(0,index-1)
										intShipping(1,index) = intShipping(1,index-1)
										intShipping(2,index) = intShipping(2,index-1)
										intShipping(3,index) = intShipping(3,index-1)
										intShipping(0,index-1) = tt0
										intShipping(1,index-1) = tt1
										intShipping(2,index-1) = tt2
										intShipping(3,index-1) = tt3
									end if
								next
							next
							firstitem=0
							for index=0 to UBOUND(intShipping,2)
								if shipType=3 then
									' if InStr(intShipping(0,index),"Parcel Post")<>0 AND iTotItems=intShipping(3,index) then
									if iTotItems=intShipping(3,index) then
										for index2=0 to UBOUND(uspsmethods,2)
											if Trim(intShipping(0,index)) = Trim(uspsmethods(0,index2)) then
												response.write "<option value='"&intShipping(2,index)&"|"&firstitem&"|"&uspsmethods(1,index2)&"'>"
												response.write uspsmethods(1,index2)
												response.write " ("&intShipping(1,index)&") "
												response.write FormatEuroCurrency(intShipping(2,index))
												response.write "</option>"
												firstitem=1
												exit for
											end if
										next
									end if
								elseif shipType=4 then
									if intShipping(3,index) then
										response.write "<option value='"&intShipping(2,index)&"|"&firstitem&"|"&intShipping(0,index)&"'>"&intShipping(0,index)&" "
										if Trim(intShipping(1,index))<>"" then response.write "(Guaranteed "&intShipping(1,index)&") "
										response.write FormatEuroCurrency(intShipping(2,index))
										response.write "</option>"
										firstitem=1
									end if
								end if
							next
						end if
						response.write "</select>"
					%></td>
					  <td height="74" align="left" width="50%" bgcolor="#FFFFFF">&nbsp;</td>
					</tr>
				  </table>
				</td>
			  </tr>
			  <tr>
			    <td height="34" align="center" bgcolor="#FFFFFF"><table width="100%" cellspacing="0" cellpadding="0" border="0">
				    <tr>
					  <td bgcolor="#FFFFFF" width="16" height="26" align="right" valign="bottom">&nbsp;</td>
					  <td bgcolor="#FFFFFF" width="100%" align="center"><input type="image" value="Checkout" border="0" src="images/checkout.gif"></td>
					  <td bgcolor="#FFFFFF" width="16" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
					</tr>
				  </table>
				</td>
			  </tr>
			</table>
		  </td>
        </tr>
		<% if shipType=4 then %>
		  <tr>
			<td height="34" align="center" bgcolor="#FFFFFF"><p>&nbsp;<br><font size="1">UPS&reg;, UPS & Shield Design&reg; and UNITED PARCEL SERVICE&reg; 
			  are<br>registered trademarks of United Parcel Service of America, Inc.</font></p></td>
		  </tr>
		<% end if %>
      </table>
	</form>
<%
	elseif NOT success then
%>
      <table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
        <tr> 
          <td width="100%">
            <table width="<%=innertablewidth%>" border="0" cellspacing="<%=innertablespacing%>" cellpadding="<%=innertablepadding%>" bgcolor="<%=innertablebg%>">
			  <tr>
			    <td align="center"><p>&nbsp;</p><p><b><%=xxSryErr%></b></p><p><b><%="<BR>"&errormsg%></b></p><p>&nbsp;</p></td>
			  </tr>
			</table>
		  </td>
        </tr>
      </table>
<%
	elseif Trim(Request.Form("payprovider"))<>"" then
		sSQL = "SELECT payProvDemo,payProvData1,payProvData2,payProvMethod FROM payprovider WHERE payProvID=" & Request.Form("payprovider")
		rs.Open sSQL,cnn,0,1
		demomode=(Int(rs("payProvDemo"))=1)
		data1=rs("payProvData1")
		data2=rs("payProvData2")
		ppmethod=Int(rs("payProvMethod"))
		rs.Close
		if grandtotal > 0 AND Request.Form("payprovider")="1" then ' PayPal
%>
	<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
	  <INPUT TYPE="hidden" NAME="cmd" VALUE="_ext-enter">
	  <INPUT TYPE="hidden" NAME="redirect_cmd" VALUE="_xclick">
	  <INPUT TYPE="hidden" NAME="business" VALUE="<%=data1%>">
	  <INPUT TYPE="hidden" NAME="return" VALUE="<%=storeurl%>thanks.asp">
	  <INPUT TYPE="hidden" NAME="notify_url" VALUE="<%=storeurl%>vsadmin/ppconfirm.asp">
	  <INPUT TYPE="hidden" NAME="item_name" VALUE="<%=Left(descstr,127)%>">
	  <INPUT TYPE="hidden" NAME="custom" VALUE="<%=orderid%>">
	  <%	Session.LCID = 1033 %>
	  <INPUT TYPE="hidden" NAME="amount" VALUE="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
	  <%	Session.LCID = saveLCID %>
	  <INPUT TYPE="hidden" name="currency_code" value="<%=countryCurrency%>">
	  <input type="hidden" name="bn" value="ecommercetemplates.asp.ecommplus">
<%			thename = Trim(Request.form("name"))
			if thename<>"" then
				if InStr(thename," ") > 0 then
					namearr = Split(thename," ",2)
					response.write "<INPUT TYPE='HIDDEN' NAME='first_name' value='"&namearr(0)&"'>"&vbCrLf
					response.write "<INPUT TYPE='HIDDEN' NAME='last_name' value='"&namearr(1)&"'>"&vbCrLf
				else
					response.write "<INPUT TYPE='HIDDEN' NAME='last_name' value='"&thename&"'>"&vbCrLf
				end if
			end if
%>
	  <input type="hidden" name="address1" value="<%=Request.form("address")%>">
	  <input type="hidden" name="city" value="<%=Request.form("city")%>">
	  <input type="hidden" name="state" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
	  <input type="hidden" name="email" value="<%=Request.form("email")%>">
	  <input type="hidden" name="zip" value="<%=Request.form("zip")%>">
	  <INPUT TYPE="hidden" NAME="cancel_return" VALUE="<%=storeurl%>sorry.asp">
<%
		elseif grandtotal > 0 AND Request.Form("payprovider")="2" then ' 2Checkout
%>
	<form method="POST" action="https://www.2checkout.com/cgi-bin/sbuyers/cartpurchase.2c">
	  <input type="hidden" name="cart_order_id" value="<%=orderid%>">
	  <input type="hidden" name="sid" value="<%=data1%>">
	  <input type="hidden" name="total" value="<%=grandtotal%>">
	  <input type="hidden" name="card_holder_name" value="<%=Request.form("name")%>">
	  <input type="hidden" name="street_address" value="<%=Request.form("address")%>">
	  <input type="hidden" name="city" value="<%=Request.form("city")%>">
	  <input type="hidden" name="state" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
	  <input type="hidden" name="zip" value="<%=Request.form("zip")%>">
	  <input type="hidden" name="country" value="<%=Request.form("country")%>">
	  <input type="hidden" name="email" value="<%=Request.form("email")%>">
	  <input type="hidden" name="phone" value="<%=Request.form("phone")%>">
	  <%	if trim(Request.form("sname")) <> "" OR trim(Request.form("saddress")) <> "" then %>
	  <input type="hidden" name="ship_name" value="<%=Request.form("sname")%>">
	  <input type="hidden" name="ship_street_address" value="<%=Request.form("saddress")%>">
	  <input type="hidden" name="ship_city" value="<%=Request.form("scity")%>">
	  <input type="hidden" name="ship_state" value="<%if Trim(Request.form("sstate"))<>"" then response.write Trim(Request.form("sstate")) else response.write Trim(Request.form("sstate2"))%>">
	  <input type="hidden" name="ship_zip" value="<%=Request.form("szip")%>">
	  <input type="hidden" name="ship_country" value="<%=Request.form("scountry")%>">
	  <%	end if
			if demomode then Response.write "<input type='hidden' name='demo' value='Y'>"
		elseif grandtotal > 0 AND Request.Form("payprovider")="3" then ' Authorize.net SIM
%>
	<FORM METHOD=POST ACTION="https://secure.authorize.net/gateway/transact.dll">
	  <input type="hidden" name="x_Version" VALUE="3.0">
	  <input type="hidden" name="x_Login" VALUE="<%=data1%>">
	  <input type="hidden" name="x_Show_Form" VALUE="PAYMENT_FORM">
	  <%	if ppmethod=1 then %>
	  <input type="hidden" name="x_type" VALUE="AUTH_ONLY">
	  <%	end if %>
<!--#include file="md5.asp"-->
<SCRIPT LANGUAGE=JScript RUNAT=SERVER>
function binl2byt(binarray){
var hex_tab = "0123456789abcdef";
var  bytarray = new Array(binarray.length * 4);
var str = "";
for(var i = 0; i < binarray.length * 4; i++){
bytarray[i] = (binarray[i>>2] >> ((i%4)*8+4) & 0xF) << 4 | binarray[i>>2] >> ((i%4)*8) & 0xF;
}
return bytarray;
}
function bytarray2word (barray){
var blks = new Array(barray.length / 4);
for(var i = 0; i < blks.length; i++) blks[i] = 0
for(var i = 0; i < barray.length; i++)
blks[i>>2] |= (barray[i] & 0xFF) << ((i%4) * 8)
//blks[i>>2] |= 0x80 << ((i%4) * 8)
//blks[nblk*16-2] = barray.length * 8
return blks
}
function bytarray2binl (barray){
var nblk = ((barray.length + 8) >> 6) + 1 // number of 16-word blocks
var blks = new Array(nblk * 16)
for(var i = 0; i < nblk * 16; i++) blks[i] = 0
for(var i = 0; i < barray.length; i++)
blks[i>>2] |= (barray[i] & 0xFF) << ((i%4) * 8)
blks[i>>2] |= 0x80 << ((i%4) * 8)
blks[nblk*16-2] = barray.length * 8
return blks
}
function b_calcMD5(barray) { return coreMD5(bytarray2binl(barray)) }
function HMAC(key, text){
var hkey,idata,odata;
var ipad= new Array(64);
var opad= new Array (64);
idata = new Array (64 + text.length);
odata = new Array (64 + 16);
if (key.length > 64){
	hkey = calcMD5(key);
}
else
	hkey = key;
for (i=0;i<64;i++){
	idata[i] = ipad[i] = 0x36;
	odata[i] = opad[i] = 0x5C;
}
for(i=0;i<hkey.length; i++){
	ipad[i] ^= hkey.charCodeAt(i);
	opad[i] ^= hkey.charCodeAt(i);
	idata[i]= ipad[i] & 0xFF;
	odata[i] = opad[i] & 0xFF;
}
for (i=0;i<text.length;i++) {
	idata[64+i] = text.charCodeAt(i) & 0xFF;
}
var innerhashout = binl2byt(b_calcMD5(idata));
for (i=0;i<16;i++) {
odata[64+i] = innerhashout[i];
}
return binl2hex(b_calcMD5(odata));
}
function GetSecondsSince1970(){
var d = new Date();
var secs= Math.floor(d.getTime() / 1000);
return (secs);
}
</SCRIPT>
<%			thename = Trim(Request.form("name"))
			if thename<>"" then
				if InStr(thename," ") > 0 then
					namearr = Split(thename," ",2)
					response.write "<INPUT TYPE='HIDDEN' NAME='x_First_Name' value='"&namearr(0)&"'>"&vbCrLf
					response.write "<INPUT TYPE='HIDDEN' NAME='x_Last_Name' value='"&namearr(1)&"'>"&vbCrLf
				else
					response.write "<INPUT TYPE='HIDDEN' NAME='x_Last_Name' value='"&thename&"'>"&vbCrLf
				end if
			end if
			Randomize
			sequence = Int(1000 * Rnd)
			tstamp = GetSecondsSince1970()
			fingerprint = HMAC(data2, data1 & "^" & sequence & "^" & tstamp & "^" & FormatNumber(grandtotal,2,-1,0,0) & "^")
%>
	  <input type="hidden" name="x_fp_sequence" value="<%=sequence%>">
	  <input type="hidden" name="x_fp_timestamp" value="<%=tstamp%>">
	  <input type="hidden" name="x_fp_hash" value="<%=fingerprint%>">
	  <input type="hidden" name="x_address" VALUE="<%=Request.form("address")%>">
	  <input type="hidden" name="x_city" value="<%=Request.form("city")%>">
	  <input type="hidden" name="x_country" value="<%=Request.form("country")%>">
	  <input type="hidden" name="x_phone" value="<%=Request.form("phone")%>">
	  <input type="hidden" name="x_state" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
	  <input type="hidden" name="x_zip" value="<%=Request.form("zip")%>">
	  <input type="hidden" name="x_cust_id" value="<%=orderid%>">
	  <input type="hidden" name="x_Invoice_Num" value="<%=orderid%>">
	  <input type="hidden" name="x_Description" value="<%=Left(descstr,255)%>">
	  <input type="hidden" name="x_email" value="<%=Request.form("email")%>">
	  <%	if trim(Request.form("sname")) <> "" OR trim(Request.form("saddress")) <> "" then
				thename = Trim(Request.form("sname"))
				if thename<>"" then
					if InStr(thename," ") > 0 then
						namearr = Split(thename," ",2)
						response.write "<INPUT TYPE='HIDDEN' NAME='x_Ship_To_First_Name' value='"&namearr(0)&"'>"&vbCrLf
						response.write "<INPUT TYPE='HIDDEN' NAME='x_Ship_To_Last_Name' value='"&namearr(1)&"'>"&vbCrLf
					else
						response.write "<INPUT TYPE='HIDDEN' NAME='x_Ship_To_Last_Name' value='"&thename&"'>"&vbCrLf
					end if
				end if %>
	  <input type="hidden" name="x_ship_to_address" value="<%=Request.form("saddress")%>">
	  <input type="hidden" name="x_ship_to_city" value="<%=Request.form("scity")%>">
	  <input type="hidden" name="x_ship_to_country" value="<%=Request.form("scountry")%>">
	  <input type="hidden" name="x_ship_to_state" value="<%if Trim(Request.form("sstate"))<>"" then response.write Trim(Request.form("sstate")) else response.write Trim(Request.form("sstate2"))%>">
	  <input type="hidden" name="x_ship_to_zip" value="<%=Request.form("szip")%>">
	  <%	end if %>
	  <input type="hidden" name="x_Amount" VALUE="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
	  <input type="hidden" name="x_Relay_Response" VALUE="True">
	  <input type="hidden" name="x_Relay_URL" VALUE="<%=storeurl%>vsadmin/wpconfirm.asp">
<%
			if demomode then %>
	  <input type="hidden" name="x_Test_Request" VALUE="TRUE">
<%			end if
		elseif grandtotal = 0 OR Request.Form("payprovider")="4" then ' Email
%>
	<form method="POST" action="<%=storeurl%>thanks.asp">
	  <input type="hidden" name="emailorder" value="<%=orderid%>">
<%		elseif grandtotal > 0 AND Request.Form("payprovider")="5" then ' WorldPay %>
	<form method="post" action="https://select.worldpay.com/wcc/purchase">
	  <INPUT TYPE="hidden" NAME="instId" VALUE="<%=data1%>">
	  <INPUT TYPE="hidden" NAME="cartId" VALUE="<%=orderid%>">
	  <%	Session.LCID = 1033 %>
	  <INPUT TYPE="hidden" NAME="amount" VALUE="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
	  <%	Session.LCID = saveLCID %>
	  <INPUT TYPE="hidden" NAME="currency" VALUE="<%=countryCurrency%>">
	  <INPUT TYPE="hidden" NAME="desc" VALUE="<%=Left(descstr,255)%>">
	  <INPUT TYPE="hidden" NAME="name" VALUE="<%=Request.form("name")%>">
	  <INPUT TYPE="hidden" NAME="address" VALUE="<%=Request.form("address")%>&#10;<%=Request.form("city")%>&#10;<%
			if trim(request.form("state"))<>"" then
				response.write Request.form("state")
			else
				response.write Request.form("state2")
			end if%>">
	  <INPUT TYPE="hidden" NAME="postcode" VALUE="<%=Request.form("zip")%>">
	  <INPUT TYPE="hidden" NAME="country" VALUE="<%=countryCode%>">
	  <INPUT TYPE="hidden" NAME="tel" VALUE="<%=Request.form("phone")%>">
	  <INPUT TYPE="hidden" NAME="email" VALUE="<%=Request.form("email")%>">
	  <%	if demomode then %>
	  <INPUT TYPE="hidden" NAME="testMode" VALUE="100">
	  <%	end if
		elseif grandtotal > 0 AND Request.Form("payprovider")="6" then ' NOCHEX %>
	<form method="post" action="https://www.nochex.com/nochex.dll/checkout">
	  <INPUT TYPE="hidden" NAME="email" VALUE="<%=data1%>">
	  <INPUT TYPE="hidden" NAME="returnurl" VALUE="<%=storeurl%>">
	  <INPUT TYPE="hidden" NAME="description" VALUE="<%=Left(descstr,255)%>">
	  <INPUT TYPE="hidden" NAME="ordernumber" VALUE="<%=orderid%>">
	  <INPUT TYPE="hidden" NAME="amount" VALUE="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
<%		elseif grandtotal > 0 AND Request.Form("payprovider")="7" then ' VeriSign Payflow Pro %>
	<form method="post" action="cart.asp">
	  <INPUT TYPE="hidden" NAME="mode" VALUE="authorize">
	  <INPUT TYPE="hidden" NAME="method" VALUE="payflowpro">
	  <INPUT TYPE="hidden" NAME="ordernumber" VALUE="<%=orderid%>">
<%		elseif grandtotal > 0 AND Request.Form("payprovider")="8" then ' Payflow Link %>
	<form method="POST" action="https://payflowlink.verisign.com/payflowlink.cfm">
		<input type="hidden" name="LOGIN" value="<%=data1%>">
		<input type="hidden" name="PARTNER" value="<%=data2%>">
		<input type="hidden" name="CUSTID" VALUE="<%=orderid%>">
		<input type="hidden" name="AMOUNT" value="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
		<input type="hidden" name="TYPE" value="S">
		<input type="hidden" name="DESCRIPTION" value="<%=Left(descstr,255)%>">
		<input type="hidden" name="NAME" value="<%=Request.form("name")%>">
		<input type="hidden" name="ADDRESS" value="<%=Request.form("address")%>">
		<input type="hidden" name="CITY" value="<%=Request.form("city")%>">
		<input type="hidden" name="STATE" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
		<input type="hidden" name="ZIP" value="<%=Request.form("zip")%>">
		<input type="hidden" name="COUNTRY" value="<%=Request.form("country")%>">
		<input type="hidden" name="EMAIL" value="<%=Request.form("email")%>">
		<input type="hidden" name="PHONE" value="<%=Request.form("phone")%>">
		<input type="hidden" name="METHOD" value="CC">
		<input type="hidden" name="ORDERFORM" value="TRUE">
		<input type="hidden" name="SHOWCONFIRM" value="FALSE">
		<%	if trim(Request.form("sname")) <> "" OR trim(Request.form("saddress")) <> "" then %>
		<input type="hidden" name="NAMETOSHIP" value="<%=Request.form("sname")%>">
		<input type="hidden" name="ADDRESSTOSHIP" value="<%=Request.form("saddress")%>">
		<input type="hidden" name="CITYTOSHIP" value="<%=Request.form("scity")%>">
		<input type="hidden" name="STATETOSHIP" value="<%if Trim(Request.form("sstate"))<>"" then response.write Trim(Request.form("sstate")) else response.write Trim(Request.form("sstate2"))%>">
		<input type="hidden" name="ZIPTOSHIP" value="<%=Request.form("szip")%>">
		<input type="hidden" name="COUNTRYTOSHIP" value="<%=Request.form("scountry")%>">
		<%	end if
		elseif grandtotal > 0 AND Request.Form("payprovider")="9" then ' Secpay %>
	<form method="POST" action="https://www.secpay.com/java-bin/ValCard">
		<input type="hidden" name="merchant" value="<%=data1%>">
		<input type="hidden" name="trans_id" value="<%=orderid%>">
		<input type="hidden" name="amount" value="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
		<input type="hidden" name="callback" value="<%=storeurl%>vsadmin/wpconfirm.asp">
		<input type="hidden" name="currency" value="<%=countryCurrency%>">
		<input type="hidden" name="cb_post" value="true">
		<input type="hidden" name="bill_name" value="<%=Request.form("name")%>">
		<input type="hidden" name="bill_addr_1" value="<%=Request.form("address")%>">
		<input type="hidden" name="bill_city" value="<%=Request.form("city")%>">
		<input type="hidden" name="bill_state" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
		<input type="hidden" name="bill_post_code" value="<%=Request.form("zip")%>">
		<input type="hidden" name="bill_country" value="<%=Request.form("country")%>">
		<input type="hidden" name="bill_email" value="<%=Request.form("email")%>">
		<input type="hidden" name="bill_tel" value="<%=Request.form("phone")%>">
		<%	if trim(Request.form("sname")) <> "" OR trim(Request.form("saddress")) <> "" then %>
		<input type="hidden" name="ship_name" value="<%=Request.form("sname")%>">
		<input type="hidden" name="ship_addr_1" value="<%=Request.form("saddress")%>">
		<input type="hidden" name="ship_city" value="<%=Request.form("scity")%>">
		<input type="hidden" name="ship_state" value="<%if Trim(Request.form("sstate"))<>"" then response.write Trim(Request.form("sstate")) else response.write Trim(Request.form("sstate2"))%>">
		<input type="hidden" name="ship_post_code" value="<%=Request.form("szip")%>">
		<input type="hidden" name="ship_country" value="<%=Request.form("scountry")%>">
		<%	end if
			if demomode then %>
		<input type="hidden" name="test_status" value="true">
		<%	end if
		elseif grandtotal > 0 AND Request.Form("payprovider")="10" then ' Capture Card %>
	<form method="post" action="thanks.asp" onSubmit="return isvalidcard(this)">
	  <INPUT TYPE="hidden" NAME="docapture" VALUE="vsprods">
	  <INPUT TYPE="hidden" NAME="ordernumber" VALUE="<%=orderid%>">
<%		elseif grandtotal > 0 AND (Request.Form("payprovider")="11" OR Request.Form("payprovider")="12") then ' PSiGate %>
	<form method="POST" action="https://order.psigate.com/psigate.asp" <% if Request.Form("payprovider")="12" then response.write "onSubmit=""return isvalidcard(this)""" %>>
		<input type="hidden" name="MerchantID" value="<%=data1%>">
		<input type="hidden" name="Oid" value="<%=orderid%>">
		<input type="hidden" name="FullTotal" value="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
		<input type="hidden" name="ThanksURL" value="<%=storeurl%>thanks.asp">
		<input type="hidden" name="NoThanksURL" value="<%=storeurl%>thanks.asp">
		<input type="hidden" name="Chargetype" value="<% if ppmethod=1 then response.write "1" else response.write "0" %>">
		<input type="hidden" name="Bname" value="<%=Request.form("name")%>">
		<input type="hidden" name="Baddr1" value="<%=Request.form("address")%>">
		<input type="hidden" name="Bcity" value="<%=Request.form("city")%>">
		<input type="hidden" name="IP" value="<%=request.servervariables("REMOTE_HOST")%>">
		<% if countryID=1 AND stateAbbrev<>"" then %>
		<input type="hidden" name="Bstate" value="<%=stateAbbrev%>">
		<% else %>
		<input type="hidden" name="Bstate" value="<%if Trim(Request.form("state"))<>"" then response.write Trim(Request.form("state")) else response.write Trim(Request.form("state2"))%>">
		<% end if %>
		<input type="hidden" name="Bzip" value="<%=Request.form("zip")%>">
		<input type="hidden" name="Bcountry" value="<%=countryCode%>">
		<input type="hidden" name="Email" value="<%=Request.form("email")%>">
		<input type="hidden" name="Phone" value="<%=Request.form("phone")%>">
		<% if trim(Request.form("sname")) <> "" OR trim(Request.form("saddress")) <> "" then %>
		<input type="hidden" name="Sname" value="<%=Request.form("sname")%>">
		<input type="hidden" name="Saddr1" value="<%=Request.form("saddress")%>">
		<input type="hidden" name="Scity" value="<%=Request.form("scity")%>">
		<input type="hidden" name="Sstate" value="<%if Trim(Request.form("sstate"))<>"" then response.write Trim(Request.form("sstate")) else response.write Trim(Request.form("sstate2"))%>">
		<input type="hidden" name="Szip" value="<%=Request.form("szip")%>">
		<input type="hidden" name="Scountry" value="<%=Request.form("scountry")%>">
		<% end if
		   if demomode then %>
		<input type="hidden" name="Result" value="1">
	  <%   end if
		elseif grandtotal > 0 AND Request.Form("payprovider")="13" then ' Authorize.net AIM %>
	<form method="post" action="cart.asp" onSubmit="return isvalidcard(this)">
	  <INPUT TYPE="hidden" NAME="mode" VALUE="authorize">
	  <INPUT TYPE="hidden" NAME="method" VALUE="authnetaim">
	  <INPUT TYPE="hidden" NAME="ordernumber" VALUE="<%=orderid%>">
<%		elseif grandtotal > 0 AND Request.Form("payprovider")="14" then ' Custom Pay Provider %>
<!--#include file="customppsend.asp"-->
<%		elseif grandtotal > 0 AND Request.Form("payprovider")="15" then ' Netbanx %>
	<form method="POST" action="https://www.netbanx.com/cgi-bin/payment/<%=data1%>">
	  <input type="hidden" name="order_id" VALUE="<%=orderid%>">
	  <input type="hidden" name="payment_amount" value="<%=FormatNumber(grandtotal,2,-1,0,0)%>">
	  <input type="hidden" name="currency_code" value="<%=countryCurrency%>">
	  <input type="hidden" name="cardholder_name" value="<%=Request.form("name")%>">
	  <input type="hidden" name="email" value="<%=Request.form("email")%>">
	  <input type="hidden" name="postcode" value="<%=Request.form("zip")%>">
<%		end if
	end if
	if success then
%>
	  <br>
      <table border="0" cellspacing="0" cellpadding="0" width="<%=maintablewidth%>" bgcolor="#B1B1B1" align="center">
        <tr> 
          <td width="100%">
            <table width="100%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" colspan="2" align="center"><b><%=xxChkCmp%></b></td>
			  </tr>
<% if cpncode<>"" AND NOT gotcpncode then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxGifCer%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><font size="1"><%
							if request.form("shipping")="" then jumpback=1 else jumpback=2
							response.write Replace(Replace(xxNoGfCr,"%s",cpncode,1,1),"%s",jumpback,1,1)%></font></td>
			  </tr>
<% end if
   if cpnmessage<>"" then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxAppDs%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=cpnmessage%></td>
			  </tr>
<% end if %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxTotGds%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(totalgoods)%></td>
			  </tr>
<% if shipType<>0 then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxShippg%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(shipping)%></td>
			  </tr>
<% end if
   if handling<>0 then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxHndlg%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(handling)%></td>
			  </tr>
<% end if
   if totaldiscounts<>0 then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxTotDs%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><font color="#FF0000"><%=FormatEuroCurrency(totaldiscounts)%></font></td>
			  </tr>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxSubTot%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency((totalgoods+shipping+handling)-totaldiscounts)%></td>
			  </tr>
<% end if
   if stateTax<>0.0 then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxStaTax%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(stateTax)%></td>
			  </tr>
<% end if
   if countryTax<>0.0 then %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxCntTax%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(countryTax)%></td>
			  </tr>
<% end if %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" align="right" width="50%"><b><%=xxGndTot%>:</b></td>
				<td bgcolor="#FFFFFF" height="30" align="left" width="50%"><%=FormatEuroCurrency(grandtotal)%></td>
			  </tr>
<% if Request.Form("payprovider")="7" OR Request.Form("payprovider")="10" OR Request.Form("payprovider")="12" OR Request.Form("payprovider")="13" then ' VeriSign Payflow Pro OR Capture Card OR PSiGate SSL OR Auth.NET AIM
		if Request.Form("payprovider")="7" OR Request.Form("payprovider")="12" OR Request.Form("payprovider")="13" then data1 = "XXXXXXXXXXXXXXXXXXXXXXXXX"
		isPSiGate = (Request.Form("payprovider")="12")
%>
<script Language="JavaScript">
<!--
function isCreditCard(st){
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul = mul - 1;
  }
  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

}
function isVisa(cc){ // 4111 1111 1111 1111
  if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}
function isMasterCard(cc){ // 5500 0000 0000 0004
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

}
function isAmericanExpress(cc){ // 340000000000009
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

}
function isDinersClub(cc){ // 30000000000004
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 14) && (firstdig == 3) &&
      ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
    return isCreditCard(cc);
  return false;
}
function isDiscover(cc){ // 6011000000000004
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

}
function isEnRoute(cc){ // 201400000000009
  first4digs = cc.substring(0,4);
  if ((cc.length == 15) && ((first4digs == "2014") || (first4digs == "2149")))
    return isCreditCard(cc);
  return false;
}
function isJCB(cc){
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && ((first4digs == "3088") || (first4digs == "3096") || (first4digs == "3112") || (first4digs == "3158") || (first4digs == "3337") || (first4digs == "3528")))
    return isCreditCard(cc);
  return false;

}
function isvalidcard(theForm){
  cc = theForm.<% if isPSiGate then response.write "CardNumber" else response.write "ACCT"%>.value;
  newcode = "";
  l = cc.length;
  for(i=0;i<l;i++){
	digit = cc.substring(i,i+1);
	digit = parseInt(digit ,10);
	if(!isNaN(digit)) newcode += digit;
  }
  cc=newcode;
  if (true <% 
		if Mid(data1,1,1)="X" then response.write "&& !isVisa(cc) "
		if Mid(data1,2,1)="X" then response.write "&& !isMasterCard(cc) "
		if Mid(data1,3,1)="X" then response.write "&& !isAmericanExpress(cc) "
		if Mid(data1,4,1)="X" then response.write "&& !isDinersClub(cc) "
		if Mid(data1,5,1)="X" then response.write "&& !isDiscover(cc) "
		if Mid(data1,6,1)="X" then response.write "&& !isEnRoute(cc) "
		if Mid(data1,7,1)="X" then response.write "&& !isJCB(cc)" %>){
	alert("<%=xxValCC%>");
	theForm.<% if isPSiGate then response.write "CardNumber" else response.write "ACCT"%>.focus();
    return false;
  }
  if(theForm.<% if isPSiGate then response.write "ExpMonth" else response.write "EXMON"%>.selectedIndex==0){
    alert("<%=xxCCMon%>");
	theForm.<% if isPSiGate then response.write "ExpMonth" else response.write "EXMON"%>.focus();
    return false;
  }
  if(theForm.<% if isPSiGate then response.write "ExpYear" else response.write "EXYEAR"%>.selectedIndex==0){
    alert("<%=xxCCYear%>");
	theForm.<% if isPSiGate then response.write "ExpYear" else response.write "EXYEAR"%>.focus();
    return false;
  }
  return true;
}
//-->
</script>
<% if request.servervariables("HTTPS")<>"on" AND nochecksslserver<>true then %>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="center" colspan="2"><b><font color="#FF0000">This site may not be secure. Do not enter real Credit Card numbers.</font></b></td>
			  </tr>
<% end if %>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxCrdNum%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><input type="text" name="<% if isPSiGate then response.write "CardNumber" else response.write "ACCT"%>" size="<%=atb(21)%>" AUTOCOMPLETE="off"></td>
			  </tr>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxExpEnd%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%">
				  <select name="<% if isPSiGate then response.write "ExpMonth" else response.write "EXMON"%>" size="1">
					<option value=""><%=xxMonth%></option>
					<%	for index=1 to 12
							if index < 10 then themonth = "0" & index else themonth = index
							response.write "<option value='"&themonth&"'>"&themonth&"</option>"&vbCrLf
						next %>
				  </select> / <select name="<% if isPSiGate then response.write "ExpYear" else response.write "EXYEAR"%>" size="1">
					<option value=""><%=xxYear%></option>
					<%	thisyear=DatePart("yyyy", Date())
						for index=thisyear to thisyear+10
							response.write "<option value='"&index&"'>"&index&"</option>"&vbCrLf
						next %>
				  </select>
				</td>
			  </tr>
			<% if NOT isPSiGate then %>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xx34code%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><input type="text" name="CVV2" size="<%=atb(4)%>" AUTOCOMPLETE="off"> <b><%=xxIfPres%></b></td>
			  </tr>
			<% end if %>
<% end if %>
			  <tr>
			    <td bgcolor="#EBEBEB" height="30" colspan="2" align="center"><b><%=xxMstClk%></b></td>
			  </tr>
			  <tr>
				<td bgcolor="#FFFFFF" colspan="2" align="center"><table width="100%" cellspacing="0" cellpadding="0" border="0">
				    <tr>
					  <td bgcolor="#FFFFFF" width="16" height="26" align="right" valign="bottom">&nbsp;</td>
					  <td bgcolor="#FFFFFF" width="100%" align="center"><input type="image" src="images/checkout.gif" border="0"></td>
					  <td bgcolor="#FFFFFF" width="16" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
					</tr>
				  </table></td>
			  </tr>
			</table>
		  </td>
        </tr>
      </table>
	</form>
<%
	end if ' success
elseif Request.Form("mode")="authorize" then
	if Request.Form("method")="payflowpro" then
		sSQL = "SELECT payProvData1,payProvDemo FROM payprovider WHERE payProvID=7"
		rs.Open sSQL,cnn,0,1
		vsdetails = rs("payProvData1")
		demomode=(Int(rs("payProvDemo"))=1)
		rs.Close
		if IsNull(vsdetails) then vsdetails=""
		vsdetails = Split(vsdetails, "&")
		if UBOUND(vsdetails) > 0 then
			vs1=vsdetails(0)
			vs2=vsdetails(1)
			vs3=vsdetails(2)
			vs4=vsdetails(3)
		end if
		sSQL = "SELECT ordZip,ordShipping,ordStateTax,ordCountryTax,ordTotal,ordDiscount,ordAddress,ordAuthNumber FROM orders WHERE ordID="&Request.Form("ordernumber")
		rs.Open sSQL,cnn,0,1
		vsAUTHCODE = rs("ordAuthNumber")
		if IsNull("ordAuthNumber") then vsAUTHCODE=""
		parmList = "TRXTYPE=S&TENDER=C"
		parmList = parmList & "&ZIP["&Len(rs("ordZip"))&"]="&rs("ordZip")
		parmList = parmList & "&STREET["&Len(rs("ordAddress"))&"]="&rs("ordAddress")
		parmList = parmList & "&COMMENT1="&Request.Form("ordernumber")
		parmList = parmList & "&ACCT=" & request.form("ACCT")
		parmList = parmList & "&PWD=" & vs4
		parmList = parmList & "&USER=" & vs1
		parmList = parmList & "&VENDOR=" & vs2
		parmList = parmList & "&PARTNER=" & vs3
		parmList = parmList & "&EXPDATE=" & request.form("EXMON") & Right(request.form("EXYEAR"),2)
		parmList = parmList & "&AMT=" & FormatNumber((rs("ordShipping")+rs("ordStateTax")+rs("ordCountryTax")+rs("ordTotal"))-rs("ordDiscount"),2,-1,0,0)
		rs.Close
		if vsAUTHCODE="" then
			Set client = Server.CreateObject("PFProCOMControl.PFProCOMControl.1")
			' response.write parmList & "<BR>"
			if demomode then
				Ctx1 = client.CreateContext("test-payflow.verisign.com", 443, 30, "", 0, "", "")
			else
				Ctx1 = client.CreateContext("payflow.verisign.com", 443, 30, "", 0, "", "")
			end if
			curString = client.SubmitTransaction(Ctx1, parmList, Len(parmList))
			client.DestroyContext (Ctx1)
			Do while Len(curString) <> 0
				'get the next name value pair
				if InStr(curString,"&") Then
					varString = Left(curString, InStr(curString , "&" ) -1)
				else
					varString = curString
				end if
				'get the name part of the name/value pair
				name = Left(varString, InStr(varString, "=" ) -1)
				value = Right(varString, Len(varString) - (Len(name)+1))
				if name="RESULT" then
					vsRESULT=value
				elseif name="PNREF" then
					vsPNREF=value
				elseif name="RESPMSG" then
					vsRESPMSG=value
				elseif name="AUTHCODE" then
					vsAUTHCODE=value
				elseif name="AVSADDR" then
					vsAVSADDR=value
				elseif name="AVSZIP" then
					vsAVSZIP=value
				elseif name="IAVS" then
					vsIAVS=value
				end if
				'skip over the &
				if Len(curString) <> Len(varString) Then
					curString = Right(curString, Len(curString) - (Len(varString)+1))
				else
					curString = ""
				end if
			Loop
			if vsRESULT="0" then
				do_stock_management(Request.Form("ordernumber"))
				sSQL="UPDATE cart SET cartCompleted=1 WHERE cartOrderID="&Request.Form("ordernumber")
				cnn.Execute(sSQL)
				sSQL="UPDATE orders SET ordAuthNumber='"&vsAVSADDR&vsAVSZIP&"-"&vsAUTHCODE&"' WHERE ordID="&Request.Form("ordernumber")
				cnn.Execute(sSQL)
			end if
		else
			vsRESULT="0"
			vsRESPMSG="Approved"
			if InStr(vsAUTHCODE,"-") > 0 then vsAUTHCODE = Right(vsAUTHCODE,Len(vsAUTHCODE)-InStr(vsAUTHCODE,"-"))
		end if
	elseif Request.Form("method")="authnetaim" then
		sSQL = "SELECT payProvData1,payProvData2,payProvDemo,payProvMethod FROM payprovider WHERE payProvID=13"
		rs.Open sSQL,cnn,0,1
		login = rs("payProvData1")
		trankey = rs("payProvData2")
		demomode=(Int(rs("payProvDemo"))=1)
		ppmethod=Int(rs("payProvMethod"))
		rs.Close
		sSQL = "SELECT ordID,ordName,ordCity,ordState,ordCountry,ordPhone,ordZip,ordEmail,ordShipping,ordStateTax,ordCountryTax,ordTotal,ordDiscount,ordAddress,ordIP,ordAuthNumber FROM orders WHERE ordID="&Request.Form("ordernumber")
		rs.Open sSQL,cnn,0,1
		vsAUTHCODE = rs("ordAuthNumber")
		if IsNull("ordAuthNumber") then vsAUTHCODE=""
		parmList = "x_version=3.1&x_delim_data=True&x_relay_response=False&x_delim_char=|"
		parmList = parmList & "&x_login="&login
		parmList = parmList & "&x_tran_key="&trankey
		parmList = parmList & "&x_cust_id="&rs("ordID")
		parmList = parmList & "&x_amount=" & FormatNumber((rs("ordShipping")+rs("ordStateTax")+rs("ordCountryTax")+rs("ordTotal"))-rs("ordDiscount"),2,-1,0,0)
		parmList = parmList & "&x_currency_code=" & countryCurrency
		parmList = parmList & "&x_card_num=" & request.form("ACCT")
		parmList = parmList & "&x_exp_date=" & request.form("EXMON") & Right(request.form("EXYEAR"),2)
		if Trim(request.form("CVV2"))<>"" then parmList = parmList & "&x_card_code=" & Trim(request.form("CVV2"))
		if ppmethod=1 then parmList = parmList & "&x_type=AUTH_ONLY" else parmList = parmList & "&x_type=AUTH_CAPTURE"
		thename = Trim(rs("ordName"))
		if thename<>"" then
			if InStr(thename," ") > 0 then
				namearr = Split(thename," ",2)
				parmList = parmList & "&x_first_name=" & namearr(0)
				parmList = parmList & "&x_last_name=" & namearr(1)
			else
				parmList = parmList & "&x_last_name=" & thename
			end if
		end if
		parmList = parmList & "&x_address="&rs("ordAddress")
		parmList = parmList & "&x_city="&rs("ordCity")
		parmList = parmList & "&x_state="&rs("ordState")
		parmList = parmList & "&x_zip="&rs("ordZip")
		parmList = parmList & "&x_country="&rs("ordCountry")
		parmList = parmList & "&x_phone="&rs("ordPhone")
		parmList = parmList & "&x_email="&rs("ordEmail")
		if Trim(rs("ordIP"))<>"" then parmList = parmList & "&x_customer_ip="&Trim(rs("ordIP"))
		if demomode then parmList = parmList & "&x_test_request=TRUE"
		rs.Close
		if vsAUTHCODE="" then
			set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
			objHttp.open "POST", "https://secure.authorize.net/gateway/transact.dll", false
			objHttp.Send parmList
			If err.number <> 0 OR objHttp.status <> 200 Then
				errormsg = "Error, couldn't connect to Authorize.net server"
			Else
				varString = Split(objHttp.responseText, "|")
				vsRESULT=varString(0)
				vsRESPMSG=varString(3)
				vsAUTHCODE=varString(4)
				vsAVSADDR=varString(5)
				vsCVV2=varString(38)
				if Int(vsRESULT)=1 then
					vsRESULT="0" ' Keep in sync with Payflow Pro
					do_stock_management(Request.Form("ordernumber"))
					sSQL="UPDATE cart SET cartCompleted=1 WHERE cartOrderID="&Request.Form("ordernumber")
					cnn.Execute(sSQL)
					sSQL="UPDATE orders SET ordAuthNumber='"&vsAVSADDR&vsCVV2&"-"&vsAUTHCODE&"' WHERE ordID="&Request.Form("ordernumber")
					cnn.Execute(sSQL)
				end if
			End If
		else
			vsRESULT="0"
			vsRESPMSG="This transaction has been approved."
			if InStr(vsAUTHCODE,"-") > 0 then vsAUTHCODE = Right(vsAUTHCODE,Len(vsAUTHCODE)-InStr(vsAUTHCODE,"-"))
		end if
	end if
%>
	<br>
	<form method="POST" action="<%=storeurl%>thanks.asp" name="checkoutform">
	<input type="hidden" name="xxpreauth" value="<%=Request.Form("ordernumber")%>">
      <table border="0" cellspacing="0" cellpadding="0" width="<%=maintablewidth%>" bgcolor="#B1B1B1" align="center">
        <tr> 
          <td width="100%">
            <table width="100%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">
<%		if vsRESULT="0" then %>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="center" colspan="2"><b><%=xxTnxOrd%></b></td>
			  </tr>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxTrnRes%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><b><%=vsRESPMSG%></b></td>
			  </tr>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxOrdNum%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><b><%=Request.Form("ordernumber")%></b></td>
			  </tr>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxAutCod%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><b><%=vsAUTHCODE%></b></td>
			  </tr>
			  <tr height="30">
				<td bgcolor="#FFFFFF" colspan="2">
				  <table width="100%" cellspacing="0" cellpadding="0" border="0">
				    <tr>
					  <td width="16" height="26" align="right" valign="bottom">&nbsp;</td>
					  <td bgcolor="#FFFFFF" width="100%" align="center">&nbsp;<br>
					  <input type="submit" value="Print Receipt"><br>&nbsp;
					  </td>
					  <td width="16" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
					</tr>
				  </table>
				</td>
			  </tr>
<%		else %>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="center" colspan="2"><b><%=xxSorTrn%></b></td>
			  </tr>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" align="right" width="50%"><b><%=xxTrnRes%>:</b></td>
				<td bgcolor="#FFFFFF" width="50%"><b><%=vsRESPMSG%></b></td>
			  </tr>
			  <tr height="30">
				<td bgcolor="#FFFFFF" colspan="2">
				  <table width="100%" cellspacing="0" cellpadding="0" border="0">
				    <tr>
					  <td width="16" height="26" align="right" valign="bottom">&nbsp;</td>
					  <td bgcolor="#FFFFFF" width="100%" align="center">&nbsp;<br>
					  <input type="button" value="<%=xxGoBack%>" onClick="javascript:history.go(-1)"><br>&nbsp;
					  </td>
					  <td width="16" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
					</tr>
				  </table>
				</td>
			  </tr>
<%		end if %>
			</table>
		  </td>
        </tr>
      </table>
	</form>
<%
else
	alldata=""
	sSQL = "SELECT cartID,cartProdID,pName,pPrice,cartQuantity,pSection,topSection FROM " & _
			"cart INNER JOIN (products LEFT OUTER JOIN sections ON products.pSection=sections.sectionID) ON cart.cartProdID=products.pID WHERE cartCompleted=0 AND cartSessionID="&Session.SessionID
	rs.Open sSQL,cnn,0,1
	if NOT (rs.EOF OR rs.BOF) then alldata=rs.getrows
	rs.Close
%>
	<br>
	<form method="POST" action="cart.asp" name="checkoutform">
	<input type="hidden" name="mode" value="update">
      <table border="0" cellspacing="0" cellpadding="0" width="<%=maintablewidth%>" bgcolor="#B1B1B1" align="center">
        <tr> 
          <td width="100%">
            <table width="100%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">
<%
	if IsArray(alldata) then
		if NOT isInStock then
%>
			  <tr height="30">
			    <td bgcolor="#FFFFFF" colspan="6" align="center"><font color="#FF0000"><b><%=xxNoStok%></b></font></td>
			  </tr>
<%
		end if
%>
			  <tr height="30">
			    <td bgcolor="#EBEBEB" width="15%"><b><%=xxCODets%></b></td>
			    <td bgcolor="#EBEBEB" width="33%"><b><%=xxCOName%></b></td>
				<td bgcolor="#EBEBEB" width="14%" align="center"><b><%=xxCOUPri%></b></td>
				<td bgcolor="#EBEBEB" width="14%" align="center"><b><%=xxQuant%></b></td>
				<td bgcolor="#EBEBEB" width="14%" align="center"><b><%=xxTotal%></b></td>
				<td bgcolor="#EBEBEB" width="10%" align="center"><b><%=xxCOSel%></b></td>
			  </tr>
<%		grandtotal=0.0
		totaldiscounts = 0
		totquant = 0
		For index=0 to UBOUND(alldata,2) %>
              <tr height="30">
			    <td bgcolor="#EBEBEB"><b><%=alldata(1,index)%></b></td>
			    <td bgcolor="#FFFFFF"><% Response.write alldata(2,index) %></td>
				<td bgcolor="#FFFFFF" align="right"><%=FormatEuroCurrency(alldata(3,index))%></td>
				<td bgcolor="#FFFFFF" align="center"><input type="text" name="quant<%=alldata(0,index)%>" value="<%=alldata(4,index)%>" size="2"></td>
				<td bgcolor="#FFFFFF" align="right"><%=FormatEuroCurrency(alldata(3,index)*alldata(4,index))%></td>
				<td bgcolor="#FFFFFF" align="center"><input type="checkbox" name="delet<%=alldata(0,index)%>"></td>
			  </tr>
<%			sSQL = "SELECT coOptGroup,coCartOption,coPriceDiff FROM cartOptions WHERE coCartID="&alldata(0,index)
			rs.Open sSQL,cnn,0,1
			optPriceDiff=0
			do while NOT rs.EOF %>
              <tr height="25">
				<td bgcolor="#EBEBEB" align="right"><font size="1"><b><%=rs("coOptGroup")%>:</b></font></td>
				<td bgcolor="#FFFFFF"><font size="1"><%="&nbsp;- "&rs("coCartOption")%></font></td>
				<td bgcolor="#FFFFFF" align="right"><font size="1"><%if rs("coPriceDiff")=0 then response.write "- " else response.write FormatEuroCurrency(rs("coPriceDiff"))%></font></td>
				<td bgcolor="#FFFFFF" align="right">&nbsp;</td>
				<td bgcolor="#FFFFFF" align="right"><font size="1"><%if rs("coPriceDiff")=0 then response.write "- " else response.write FormatEuroCurrency(rs("coPriceDiff")*alldata(4,index))%></font></td>
				<td bgcolor="#FFFFFF" align="center">&nbsp;</td>
			  </tr>
<%				optPriceDiff=optPriceDiff+rs("coPriceDiff")
				rs.MoveNext
			loop
			rs.Close
			subtot = ((alldata(3,index)+optPriceDiff)*Int(alldata(4,index)))
			totquant = totquant + Int(alldata(4,index))
			grandtotal=grandtotal+subtot
			Session.LCID = 1033
			tdt = Date()
			sSQL = "SELECT cpnDiscount,cpnType FROM coupons LEFT OUTER JOIN cpnAssign ON coupons.cpnID=cpnAssign.cpaCpnID WHERE cpnNumAvail>0 AND cpnEndDate>="&datedelim&DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt)&datedelim&" AND cpnIsCoupon=0 AND cpnThreshold<="&subtot&" AND (cpnThresholdMax>"&subtot&" OR cpnThresholdMax=0) AND cpnQuantity<="&alldata(4,index)&" AND (cpnQuantityMax>"&alldata(4,index)&" OR cpnQuantityMax=0) AND (cpnSitewide=0 OR cpnSitewide=2) AND "
			sSQL = sSQL & "(cpnSitewide=2 OR (cpaType=2 AND cpaAssignment='"&alldata(1,index)&"') "
			sSQL = sSQL & "OR (cpaType=1 AND cpaAssignment='"&alldata(5,index)&"') "
			if subCats then sSQL = sSQL & "OR (cpaType=0 AND cpaAssignment='"&alldata(6,index)&"')"
			sSQL = sSQL & ")"
			rs2.Open sSQL,cnn,0,1
			do while NOT rs2.EOF
				if rs2("cpnType")=1 then ' Flat Rate Discount
					if subtot > cDbl(rs2("cpnDiscount")) then
						totaldiscounts = totaldiscounts + cDbl(rs2("cpnDiscount"))
					else
						totaldiscounts = totaldiscounts + subtot
					end if
				elseif rs2("cpnType")=2 then ' Percentage Discount
					totaldiscounts = totaldiscounts + ((cDbl(rs2("cpnDiscount")) * cDbl(subtot)) / 100.0)
				end if
				rs2.MoveNext
			loop
			rs2.Close
			Session.LCID = saveLCID
		Next
		Session.LCID = 1033
		tdt = Date()
		sSQL = "SELECT cpnType,cpnDiscount FROM coupons WHERE cpnNumAvail>0 AND cpnEndDate>="&datedelim&DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt)&datedelim&" AND cpnIsCoupon=0 AND cpnThreshold<="&grandtotal&" AND (cpnThresholdMax>"&grandtotal&" OR cpnThresholdMax=0) AND cpnQuantity<="&totquant&" AND (cpnQuantityMax>"&totquant&" OR cpnQuantityMax=0) AND cpnSitewide=1"
		rs2.Open sSQL,cnn,0,1
		do while NOT rs2.EOF
			if rs2("cpnType")=1 then ' Flat Rate Discount
				totaldiscounts = totaldiscounts + cDbl(rs2("cpnDiscount"))
			elseif rs2("cpnType")=2 then ' Percentage Discount
				totaldiscounts = totaldiscounts + ((cDbl(rs2("cpnDiscount")) * cDbl(grandtotal)) / 100.0)
			end if
			rs2.MoveNext
		loop
		rs2.Close
		Session.LCID = saveLCID
		if totaldiscounts>0 then
			if totaldiscounts > grandtotal then totaldiscounts = grandtotal
%>
              <tr height="30">
				<td bgcolor="#EBEBEB" rowspan="4">&nbsp;</td>
				<td bgcolor="#FFFFFF" align="right" colspan="3"><strong><%=xxSubTot%>:</strong></td>
				<td bgcolor="#FFFFFF" align="right"><%=FormatEuroCurrency(grandtotal)%></td>
				<td bgcolor="#FFFFFF" align="center">&nbsp;</td>
			  </tr>
			  <tr height="30">
				<td bgcolor="#FFFFFF" align="right" colspan="3"><font color="#FF0000"><strong><%=xxDsApp%></strong></font></td>
				<td bgcolor="#FFFFFF" align="right"><font color="#FF0000"><%=FormatEuroCurrency(totaldiscounts)%></font></td>
				<td bgcolor="#FFFFFF" align="center">&nbsp;</td>
			  </tr>
<%
		end if
%>
              <tr height="30">
				<% if totaldiscounts=0 then %>
				<td bgcolor="#EBEBEB" rowspan="2">&nbsp;</td>
				<% end if %>
				<td bgcolor="#FFFFFF" align="right" colspan="3"><b><%=xxGndTot%>:</b></td>
				<td bgcolor="#FFFFFF" align="right"><%=FormatEuroCurrency(grandtotal-totaldiscounts)%></td>
				<td bgcolor="#FFFFFF" align="center"><a href="javascript:document.checkoutform.submit()"><b><%=xxDelete%></b></a></td>
			  </tr>
			  <tr height="30">
				<td bgcolor="#FFFFFF" colspan="5">
				  <table width="100%" cellspacing="0" cellpadding="0" border="0">
				    <tr>
					  <td bgcolor="#FFFFFF" width="50%" align="center"><a href="<%=xxHomeURL%>"><b><%=xxCntShp%></b></a></td>
					  <td bgcolor="#FFFFFF" width="50%" align="center"><a href="javascript:document.checkoutform.submit()"><b><%=xxUpdTot%></b></a></td>
					  <td width="16" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
					</tr>
				  </table>
				</td>
			  </tr>
<%
	else
		cartEmpty=True
%>
              <tr>
			    <td bgcolor="#FFFFFF" colspan="6" align="center">
				  <p>&nbsp;</p>
				  <p><%=xxSryEmp%></p>
				  <p>&nbsp;</p>
				  <p><a href="<%=xxHomeURL%>"><b><%=xxCntShp%></b></a></p>
				  <p>&nbsp;</p>
				</td>
			  </tr>
<%
	end if
%>
			</table>
		  </td>
        </tr>
      </table>
	</form>
<%
end if

if request.form("mode")<>"go" AND request.form("mode")<>"checkout" AND request.form("mode")<>"add" AND request.form("mode")<>"authorize" AND NOT cartEmpty then
	requiressl = false
	sSQL = "SELECT payProvID FROM payprovider WHERE payProvEnabled=1 AND payProvID IN (7,10,12,13)" ' All the ones that require SSL
	rs.Open sSQL,cnn,0,1
	if NOT rs.EOF then requiressl = true
	rs.Close
	if requiressl then
		if pathtossl<>"" then
			if Right(pathtossl,1) <> "/" then pathtossl = pathtossl & "/"
			cartpath = pathtossl & "cart.asp"
		else
			cartpath = Replace(storeurl,"http:","https:") & "cart.asp"
		end if
	else
		cartpath="cart.asp"
	end if
%>
	  <table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
        <tr> 
          <td width="100%">
		    <form method="POST" action="<%=cartpath%>">
			  <input type="hidden" name="mode" value="checkout">
			  <input type="hidden" name="sessionid" value="<%=Session.SessionID%>">
			  <input type="hidden" name="PARTNER" value="<%=Trim(request.cookies("PARTNER"))%>">
			  <table width="<%=innertablewidth%>" border="0" cellspacing="<%=innertablespacing%>" cellpadding="<%=innertablepadding%>" bgcolor="<%=innertablebg%>">
				<tr>
				  <td width="100%" align="center" colspan="2"><b><%=xxPrsChk%></b></td>
				</tr>
				<tr>
				  <td width="50%" align="center" colspan="2"><input type="image" src="images/checkout.gif" border="0"></td>
				</tr>
			  </table>
			</form>
		  </td>
        </tr>
      </table>
<%
end if
cnn.Close
%>