<!--#include file="include/inicio.asp"-->
<%call titulo_box(titulo)%>
<p><font face=tahoma color=black style="font-size:8pt;">
<DIV align=right><A href="http://www.cidadedolivro.com.br/carrinho.asp?cod_site=0">Meu Carrinho</A> | <A 
href="http://www.cidadedolivro.com.br/cadastro_cli.asp?cod_site=0">Meu Cadastro</A> | <A 
href="http://www.cidadedolivro.com.br/conteudo.asp?cod_site=0&id_menu=8">Política de Privacidade</A> | <A 
href="http://www.cidadedolivro.com.br/conteudo.asp?cod_site=0&id_menu=23">Política de Trocas e 
Devoluções</A> </DIV>
<%
strsql = "select valor_sem_taxa_entrega from tbl_dados"
set consulta = conexao.execute(strsql)
if not consulta.eof then
	valor_sem_taxa_entrega = consulta("valor_sem_taxa_entrega")
end if
set consulta = nothing

modo = request("modo")

if len(session("cod_pedido_temp")) > 0 then
	if session("cod_pedido_temp") > 0 then
		strsql = "select cod_pedido_temp from tbl_pedidos_temp where cod_pedido_temp="&session("cod_pedido_temp")
		set consulta = conexao.execute(strsql)
		if consulta.eof then
		'limpar sessions
			session("cod_pedido_temp") = 0
			session("cod_local") = 0
			session("id_valor") = 0
		' limpar cookies
			response.cookies("loja_"&nome_empresa)("cod_pedido_temp") = 0
			response.cookies("loja_"&nome_empresa).expires = date() - 1
		end if
		set consulta = nothing
	end if
end if


if len(session("log_cli")) > 0 then
	strsql = "select cod_local from tbl_clientes where id_cliente="&session("log_cli")
	set consulta = conexao.execute(strsql)
	cod_local = consulta("cod_local")
	session("cod_local") = cod_local
	set consulta = nothing
	if cod_local = 0 then
		
		response.redirect("cadastro_cli.asp?cod_site="&cod_site&"&msg="&alerta(34)&"&modo=abre_cadastro&id_cliente="&session("log_cli"))
	end if
else
	cod_local = 0
	session("cod_local") = cod_local
end if

%>
<table width=100% align=center style="font-size:8pt;"><tr><td valign=top>
<%
if len(session("cod_pedido_temp")) = 0 then
	session("cod_pedido_temp") = 0
end if


'******* SE A SESSION ESTIVER VARIA, PROCURA NO COOKIE
if len(session("cod_pedido_temp")) = 0 or session("cod_pedido_temp") = 0 then
' pega o código de um cookie gravado no cliente, se houver
if request("loja_"&nome_empresa)<>"" then
 session("cod_pedido_temp") = request("loja_"&nome_empresa)("cod_pedido_temp")
end if
end if


%>

<%
'******* INCLUSÃO DE PRODUTOS NO CARRINHO DE COMPRAS
	quantidade = valida_num(request("quantidade"))
	aro_m = valida_a(valida_num(request("aro_m")))
	parametros = valida_nq(request("parametros"))
	cod_curso = valida_a(valida_num(request("cod_curso")))
	aro_f = valida_a(valida_num(request("aro_f")))
	gravacao_m = valida_nq(request("gravacao_m"))
	gravacao_f = valida_nq(request("gravacao_f"))

if modo = "incluir" then
'******* CRIA O CARRINHO PARA O CLIENTE

	if len(session("cod_pedido_temp")) = 0 or session("cod_pedido_temp") = 0  then

		strsql = "insert into tbl_pedidos_temp(ip,data,cod_valor)values('"&Request.ServerVariables("REMOTE_ADDR")&"',"&data_sistema&",0)"
		conexao.execute strsql
		strsql = "select max(cod_pedido_temp) as maximo from tbl_pedidos_temp"
		set consulta = conexao.execute(strsql)
		session("cod_pedido_temp") = consulta("maximo")
		' gravar cookie
		response.cookies("loja_"&nome_empresa)("data") = date()
		response.cookies("loja_"&nome_empresa)("cod_pedido_temp") = consulta("maximo")
		response.cookies("loja_"&nome_empresa).expires = date() + 5
		set consulta = nothing
	end if


' INCLUI O PRODUTO
	cod_produto = valida_num(request("cod_produto"))
	quantidade = valida_num(request("quantidade"))
	parametros = valida_nq(request("parametros"))
	aro_m = valida_a(valida_num(request("aro_m")))
	cod_curso = valida_a(valida_num(request("cod_curso")))
	aro_f = valida_a(valida_num(request("aro_f")))
	gravacao_m = valida_nq(request("gravacao_m"))
	gravacao_f = valida_nq(request("gravacao_f"))

	if len(quantidade)=0 then
		quantidade = 1
		Session("quantidade") = 1
	else
		Session("quantidade") = valida_num(Session("quantidade")) + quantidade
	end if


	strsql = "insert into tbl_pedidos_produtos_temp(cod_pedido_temp,cod_produto,quantidade,aro_m,aro_f,gravacao_m,gravacao_f,cod_curso,obs_produto)values("&session("cod_pedido_temp")&","&cod_produto&","&quantidade&","&aro_m&","&aro_f&",'"&gravacao_m&"','"&gravacao_f&"',"&cod_curso&",'"&parametros&"')"
	'response.write strsql
	conexao.execute(strsql)
end if
%>

<%
'******* EXCLUSÃO DE PRODUTOS DO CARRINHO DE COMPRAS
if request("modo") = "excluir" then
	id_pedidos_temp = valida_num(request("id_pedidos_temp"))
	strsql = "delete tbl_pedidos_produtos_temp from tbl_pedidos_produtos_temp where id_pedidos_temp="&id_pedidos_temp& " and cod_pedido_temp="&session("cod_pedido_temp")
	conexao.execute(strsql)

	Session("quantidade") = Session("quantidade") - 1
end if
%>

<%
'******* EXCLUSÃO DO CARRINHO DE COMPRAS
if request("modo") = "limpar" then
	strsql = "delete tbl_pedidos_produtos_temp from tbl_pedidos_produtos_temp where cod_pedido_temp="&session("cod_pedido_temp")
	conexao.execute(strsql)
	Session("quantidade") = 0
end if

'******* RECALCULA 
if request("modo") = "recalcula" then
if len(request("tmpo"))>0 then
session("xpto") = 1
session("fical") = valida_a(request("fical"))
session("cpfxto") = valida_nq(request("cpfxto"))
end if
	pedidos = request("pedidos")
	if len(pedidos) > 0 then
		y= 1
		cat = trim(replace(pedidos," ",""))&","
		do while len(cat) <> 0
			y= instr(cat,",")
			categ_inclui=replace(mid(cat,1,y),",","")
			quantidade = valida_num(request("quantidade_"&categ_inclui))
			aro_m = valida_a(valida_num(request("aro_m_"&categ_inclui)))
			parametros = valida_nq(request("parametros_"&categ_inclui))
			cod_curso = valida_a(valida_num(request("cod_curso_"&categ_inclui)))
			aro_f = valida_a(valida_num(request("aro_f_"&categ_inclui)))
			gravacao_m = valida_nq(request("gravacao_m_"&categ_inclui))
			gravacao_f = valida_nq(request("gravacao_f_"&categ_inclui))	
			strsql = "update tbl_pedidos_produtos_temp set quantidade="&quantidade& ",aro_m="&aro_m&",aro_f="&aro_f&",gravacao_m='"&gravacao_m&"',gravacao_f='"&gravacao_f&"',cod_curso="&cod_curso&",obs_produto='"&parametros&"' where id_pedidos_temp="&categ_inclui
			conexao.execute(strsql)
			cat=mid(cat,y+1,len(pedidos))
		loop
	end if
end if
%>

<%
'******* MONTA CARRINHO
strsql = "select * from tbl_pedidos_temp as a,tbl_pedidos_produtos_temp as b where a.cod_pedido_temp=b.cod_pedido_temp and a.cod_pedido_temp="&session("cod_pedido_temp")& " order by b.id_pedidos_temp"

set consulta = conexao.execute(strsql)
if consulta.eof then
	response.write "<p><font face=tahoma style=""font-size: 8pt;""><b>Nenhum produto em seu carrinho até o momento</b><p><a href=loja.asp?cod_site="&cod_site&">Clique aqui para voltar à loja</a></font>"
else
%>
<form method=post action=carrinho.asp?cod_site=<%=cod_site%>&modo=recalcula name=carrinho>
<p class="style11"><font style="font-size:8pt;"><b><%call alerta(35)%></b></font>
<p>
<table width="90%" cellspacing="1" cellpadding="2" align="center" style="font-size:8pt;font-family: tahoma;"><tr bgcolor="#137EBF"><td colspan=2><font color=white><b><%call alerta(123)%></b></font></td><td><font color=white><b><%call alerta(124)%></b></font></td><td><font color=white><b><%call alerta(128)%></b></font></td><TD></td></tr>
<td><font color=white><b><%call alerta(126)%></b></font></td><td><font color=white><b><%call alerta(127)%></b></font></td><td><font color=white><b><%call alerta(128)%></b></font></td></tr>
<tr><td colspan=4 height=5></tr>
<%
total_peso = 0
total_prod = 0
cor = "#F0FFF8"
do while not consulta.eof
set consulta2 = conexao.execute("select id_produto,nome,figura_pq,preco,desconto,desconto,peso,codigo,formato from tbl_produtos where id_produto="&consulta("cod_produto"))
	if cor = "#F0FFF8" then
		cor = "white"
	else
		cor = "#F0FFF8"
	end if
%>
<tr bgcolor="<%=cor%>">
<td width=50><img src="imagens/<%=consulta2("figura_pq")%>" alt="Ampliar" border=0 style="border-color: gray;" width=50></td>
<td width=300><A href="produtos.asp?cod_site=<%=cod_site%>&id_produto=<%=consulta2("id_produto")%>"><b><%=consulta2("nome")%></b></a><BR>Cód: <%=consulta2("codigo")%>
<input type=hidden name="parametros_<%=consulta("id_pedidos_temp")%>" value="<%=consulta("obs_produto")%>" size=1 class=campo>
<input type=hidden name="cod_curso_<%=consulta("id_pedidos_temp")%>" value="<%=consulta("cod_curso")%>" size=1 class=campo>
<%
if consulta("cod_curso") <> 0 then
	strsql = "select nome from tbl_produtos_cursos where id_curso="&consulta("cod_curso")
	set consulta4 = conexao.execute(strsql)
	if not consulta4.eof then
		response.write "<BR><b>"&consulta4("nome")&"</b>"
	end if
	set consulta4 = nothing
end if
%>
</td>
<td>
<input type=text name="quantidade_<%=consulta("id_pedidos_temp")%>" value="<%=consulta("quantidade")%>" size=1 class=campo>
</td>
<input type=hidden name="pedidos" value="<%=consulta("id_pedidos_temp")%>" size=1 class=campo>
<td align=right>R$ <%response.write formatnumber(consulta2("desconto")*consulta("quantidade"),2)%></td>
<td align=center><a href="carrinho.asp?cod_site=<%=cod_site%>&modo=excluir&id_pedidos_temp=<%=consulta("id_pedidos_temp")%>"><img src="img/comum/bot_exclui_carrinho.gif" alt="Excluir" border=0></a></td>
</tr>
<%
total_prod = total_prod + (consulta2("desconto")*consulta("quantidade"))
total_peso = total_peso + (consulta2("peso")*consulta("quantidade"))
set consulta2 = nothing
consulta.movenext
loop
set consulta = nothing

'DESCONTO NO FRETE PARA O CASO DE O VALOR TOTAL DE PRODUTOS FOR MAIOR DO QUE O VALOR ESTIPULADO

if total_prod > valor_sem_taxa_entrega then
	
	total_peso = 0
else
	
end if

if total_prod>=90 then
	frete_gratis2 = true
else
	frete_gratis2 = false
end if


session("total_peso") = total_peso
%>
<input type=hidden name=cod_pedido_temp value="<%=session("cod_pedido_temp")%>">
<input type=hidden name=total_peso value="<%=session("total_peso")%>">
<%
if len(session("id_valor")) = 0 then
	session("id_valor") = 0
end if

if valida_num(request("total_peso")) <> valida_num(session("total_peso")) then
	session("id_valor") = 0
else
	session("id_valor") = valida_num(request("id_valor"))
	if len(session("id_valor")) = 0 then
		session("id_valor") = 0
	end if
end if
	
strsql = "select valor as loc_valor,regiao from tbl_locaisXvalores,tbl_locais where cod_local = id_local and id_valor="&session("id_valor")
set consulta = conexao.execute(strsql)
if consulta.eof then
%>

<tr bgcolor="#FFFFCC"><Td colspan=3><b><%call alerta(119)%></b></td><td colspan=1 align=right> R$ <%=formatnumber(total_prod,2)%></td><Td></td></tr>

</table>

<div align=right><font color=red><%=alerta(152)%></font></div>
<hr noshade size=1 color=silver><font style="font-size:8pt;">
<%
strsql = "select * from tbl_locaisXtipos where ativo=1 and cod_site="&cod_site&" order by nome"
'SÓ SEDEX
set consulta2 = conexao.execute(strsql)
if not consulta2.eof then
if cod_local <> 0 and len(cod_local) > 0 then
%>
<%call alerta(36)%>
 <BR>
<%
end if
do while not consulta2.eof
	strsql = "select top 1 id_valor,valor,tbl_locaisXtipos.nome as tipo from tbl_locaisXvalores,tbl_locaisXtipos,tbl_locais where tbl_locais.cod_site="&cod_site&" and id_tipo = cod_tipo and cod_local="&cod_local&" and cod_tipo="&consulta2("id_tipo")&" and peso_ate >="&total_peso&" order by peso_ate"
	set consulta3 = conexao.execute(strsql)
	if not consulta3.eof then
	set frt = conexao.execute("select frete_gratis from tbl_clientes where id_cliente = "&session("log_cli"))
	if not frt.eof then
	frete_gratis = frt("frete_gratis")
	end if
	set frt = nothing
	
	
	if frete_gratis = 1 or frete_gratis2 then
	%>
	<input type="radio" name="id_valor" value="19749" onclick="javascript:document.carrinho.submit();"> <b>Frete Gratis: </b> R$ <%=formatnumber(0,2)%>&nbsp; <br>
	<%
	
	else%>
	<input type="radio" name="id_valor" value="<%=consulta3("id_valor")%>" onclick="javascript:document.carrinho.submit();"> <b><%=consulta3("tipo")%>: </b> R$ <%=formatnumber(consulta3("valor"),2)%>&nbsp; <br>
	<%
	end if
	end if
	set consulta3 = nothing
consulta2.movenext
loop
end if
set consulta2 = nothing
	%>
<div align=right>
<hr noshade size=1 color=silver>
<!--<input type=submit name=recalcular value="<%call alerta(130)%>" class=botao>-->
<a href="loja.asp?cod_site=<%=cod_site%>"><img src="img/bot_loja.gif" alt="" border="0"></a>
<a href="javascript:document.carrinho.submit();"><img src="img/bot_recalcular.gif" alt="" border="0"></a>
</div>
</form>
<%if len(session("log_cli")) = 0 then%>
	<hr noshade size=1 color=silver>
<b><%call alerta(37)%> <a href="cadastro_cli.asp?cod_site=<%=cod_site%>&modo=novo_cliente&carrinho=sim" class="style11"><font color="blue"><u><%call alerta(132)%></u></font></a></b>
<form method=post action=cadastro_cli.asp?cod_site=<%=cod_site%>&modo=loga&carrinho=sim>
<p><table>
<tr>
	<td><font face=tahoma style="font-size: 8pt;">E-mail:</font> </td>
	<td><input type="text" name="login_cli" size="20" class=campo></td>
</tr>
<tr>
	<td><font face=tahoma style="font-size: 8pt;">Senha:</font> </td>
	<td><input type="password" name="senha" size="30" class=campo></td>
</tr>
</table>
<input type="submit" name="Continuar" value="<%call alerta(131)%>" class=botao>

<font face=tahoma style="font-size: 8pt;">
<BR><Br><b>: :</b> <a href="cadastro_cli.asp?cod_site=<%=cod_site%>&modo=novo_cliente&carrinho=sim"><font color="#000000"><%call alerta(129)%></font></a>
<Br><b>: :</b> <a href="cadastro_cli.asp?cod_site=<%=cod_site%>&modo=lembra_senha"><font color="#000000"><%call alerta(100)%></font></a></font>
</form>
<%end if%>
<%else
total = total_prod + consulta("loc_valor")
%>
<tr bgcolor="#FFFFCC"><Td colspan=4><b><%call alerta(119)%></b></td><td colspan=3 align=right> R$ <%=formatnumber(total_prod,2)%></td><Td></td></tr>
<%
desconto_frete = 0
strsql = "select valor_pedido from tbl_desconto_frete where regiao='"&consulta("regiao")&"' and ativo = 1"
set consulta5 = conexao.execute(strsql)
if not consulta5.eof then
if total_prod >= consulta5("valor_pedido") then
	desconto_frete = consulta("loc_valor")
%>
<tr bgcolor="#FFFFCC"><Td colspan=4><b><%call alerta(800)%></b></td><td colspan=3 align=right><font color=red><b> - R$ <%=formatnumber(desconto_frete,2)%></b></font></td><Td></td></tr>
<%
end if
end if 
set consulta5 = nothing
%>
<tr bgcolor="#FFFFCC"><Td colspan=4><b><%call alerta(120)%></b></td><td colspan=3 align=right> R$ <%=formatnumber(consulta("loc_valor"),2)%></td><Td></td></tr>

<tr bgcolor="#FFCECE"><Td colspan=4><b><%call alerta(121)%></b></td><td colspan=3 align=right> <big>R$ <b><%=formatnumber(total - desconto_frete,2)%></b></big></td><Td></td></tr>
</table>

<div align=right><font color=red><%=alerta(152)%></font></div>
<hr noshade size=1 color=silver>
<font style="font-size:8pt;">
<%call alerta(38)%>
<BR>
<%
strsql = "select * from tbl_locaisXtipos where ativo=1 and cod_site="&cod_site&" order by nome"
'SÓ SEDEX
set consulta2 = conexao.execute(strsql)
do while not consulta2.eof
	strsql = "select top 1 id_valor,valor,tbl_locaisXtipos.nome as tipo from tbl_locaisXvalores,tbl_locaisXtipos,tbl_locais where tbl_locais.cod_site="&cod_site&" and id_tipo = cod_tipo and cod_local="&cod_local&" and cod_tipo="&consulta2("id_tipo")&" and peso_ate >="&total_peso&" order by peso_ate"
	set consulta3 = conexao.execute(strsql)
	if not consulta3.eof then
	
	
	if not session("id_valor") = 19749 then%>
	<input type="radio" name="id_valor" value="<%=consulta3("id_valor")%>" onclick="javascript:document.carrinho.submit();" <%if valida_num(consulta3("id_valor"))=valida_num(session("id_valor")) then response.write "checked" end if%>> <b><%=consulta3("tipo")%>: </b> R$ <%=formatnumber(consulta3("valor"),2)%> &nbsp; <BR>
	<%
	else
	%>
	<input type="radio" name="id_valor" value="19749" onclick="javascript:document.carrinho.submit();" checked> <b>Frete Gratis: </b> R$ <%=formatnumber(0,2)%> &nbsp; <BR>
	<%
	end if
	end if
	set consulta3 = nothing
consulta2.movenext
loop
set consulta2 = nothing
%>
<hr noshade size=1 color=silver>
<table align=right><tr>
<TD><a href="loja.asp?cod_site=<%=cod_site%>"><img src="img/bot_loja.gif" alt="" border="0"></a></td>
<td valign="baseline">
<!--<input type=submit name=recalcular value="<%call alerta(130)%>" class=botao>-->
<a href="javascript:document.carrinho.submit();"><img src="img/bot_recalcular.gif" alt="" border="0"></a>
</td><td>
<!--<input type=button name=continuar value="Continuar" class=botao onclick="window.location='<%=endereco_seguro%>passo1.asp?cod_site=<%=cod_site%>&id_valor=<%=session("id_valor")%>&cod_local=<%=session("cod_local")%>&cod_pedido_temp=<%=session("cod_pedido_temp")%>&log_cli=<%=session("log_cli")%>';">-->

<%if session("xpto") = 1 then%>
<a href="javascript:window.location='<%=endereco_seguro%>passo1.asp?cod_site=<%=cod_site%>&id_valor=<%=session("id_valor")%>&cod_local=<%=session("cod_local")%>&cod_pedido_temp=<%=session("cod_pedido_temp")%>&log_cli=<%=session("log_cli")%>&fical=<%=session("fical")%>&cpfxto=<%=session("cpfxto")%>';">
<%else%>
<script>
function abrirxto(){
document.getElementById("fundopri1").style.visibility = "visible";
document.getElementById("fundopri2").style.visibility = "visible";
}
</script>
<a href="javascript:abrirxto()">
<%end if%>
<img src="img/bot_continuar.gif" alt="" border="0"></a>
</td></tr></table>
</form>
<%
end if
end if
set consulta = nothing
%>
</td></tr></table>
<!--#include file="include/fim.asp"-->