// Arquivos html que são os templates dos forms de alerta
var templates=new Object;
templates['preco']="./FormularioProduto/FormAlertaPreco.php?produto=1&55601";
templates['avisa']="./FormularioProduto/FormAvisar.php?produto=1&55579";
templates['indica']="./FormularioProduto/FormIndica.php?produto=1&9568";
templates['ampliar']="./FormularioProduto/FormAmpliarImagem.php?produto=1&35";
templates['btus']="./FormularioProduto/FormBtus.html?55612";
templates['garantiamais']="./FormularioProduto/FormSobreGarantia.php?55570";
templates['termos']="./FormularioProduto/FormTermosTc.php?55579";
templates['opina']="./FormularioProduto/FormOpinar.php?produto=1&5595";
templates['brinde']="./FormularioProduto/FormBrinde.php?produto=1&5575";
templates['SobreCupom']="./FormularioProduto/FormSobreCupomDesconto.php?produto=5582";
templates['Filiais']="./FormularioProduto/FormFilial.php?produto=1&5590";
templates['RSS']="./FormularioProduto/FormRSS.php?produto=1&5581";
templates['CartaoCredito']="./FormularioProduto/FormCartao.php?produto=1&5584";
templates['TrocoPremiado']="./FormularioProduto/FormSobreTrocoPremiado.php?55571";
templates['Marca']="./FormularioProduto/FormMarca.php?5572&pt=.";
templates['Marca2']="../FormularioProduto/FormMarca.php?55650&pt=..";
// aloco aqui o código html de cada template acima
var templates_html=new Object;
// tentativas de baixar o template. Caso exceda, não será baixado novamente
var tentativas=new Object;
for (var i in templates)
{
tentativas[i]=0;
}
var maximo_tentativas=10;
var posCmpBusca=0;
// --------------------------------------------
// FUNÇÃO DE EXIBIÇÃO DA TELA
// --------------------------------------------
function showLayer(layer, x, y, prod_id, prod_nome, grupo_id, tipo_id)
{
if (layer!="preco" && layer!="avisa" && layer!="indica" && layer!="ampliar" && layer!="btus" && layer!="garantiamais" && layer!="opina" && layer!="termos" && layer!="brinde" && layer!="SobreCupom" && layer!="Filiais" && layer!="RSS" && layer!="CartaoCredito" && layer!="TrocoPremiado" && layer!="Marca" && layer!="Marca2")
{
alert("Valor recebido para variável layer não esperado: " + layer)
return;
}
if (!templates_html[layer])
{
setTimeout("showLayer('" + layer + "', '" + x + "', '" + y + "', '" + prod_id + "', '" + prod_nome + "', '" + grupo_id + "', '" + tipo_id + "')",1000);
return;
}
var template_lines=templates_html[layer];
template_lines=template_lines.replace(/%%PROD_ID/g, prod_id);
template_lines=template_lines.replace(/%%PROD_NOME/g, prod_nome);
template_lines=template_lines.replace(/%%GRUPO_ID/g, grupo_id);
template_lines=template_lines.replace(/%%TIPO_ID/g, tipo_id);
document.getElementById("layer_alerta").style.position='absolute';
document.getElementById('layer_alerta').innerHTML=template_lines;
if (y)
{
document.getElementById("layer_alerta").style.top=y + "px";
}
if (x)
{
document.getElementById("layer_alerta").style.left=x + "px";
}
document.getElementById('layer_alerta').style.visibility="visible";
}
// ------------------------------------------------------------
// LOADA DAS TELAS
// ------------------------------------------------------------
function preLoadLayers(layer)
{
if (layer)
{
if (!templates_html[layer]){
var myConn = new XHConn();
var fnWhenDone = function (oXML)
{
evaljavascript(oXML.responseText);
templates_html[layer]=oXML.responseText;
}
myConn.connect("./" + templates[layer], "GET", "", fnWhenDone);
}
}
else
{
for (var i in templates) // for (var i in object) is equivalent to Perl foreach $key (keys %hash)
{
if (!templates_html[i])
{
tentativas[i]++;
if (tentativas[i]>=maximo_tentativas)
{
alert("Falha baixando template " + templates[i]);
return;
}
var myConn = new XHConn();
var fnWhenDone = function (oXML)
{
evaljavascript(oXML.responseText);
templates_html[i]=oXML.responseText;
}
myConn.connect("./" + templates[i], "GET", "", fnWhenDone);
setTimeout("preLoadLayers()",3000);
return;
}
}
}
}
// ------------------------------------------------------------
// VALIDAÇÃO DOS DADOS DO FORMULÁRIO
// ------------------------------------------------------------
function validaFormPreco()
{
var msg='';
//validando a grana $$
var grana=document.getElementById('ALE_PARAM').value;
grana = grana.replace(/,/g,"");
grana = grana.replace(objRegExp = /\./g,"");
grana=grana+0;
if (parseFloat(grana) <= 0)
{
msg=msg+'É necessário informar o valor máximo do produto\n'
}
if (document.getElementById('ALE_NOMECLI').value.length<3)
{
msg=msg+'Favor escreva seu nome e sobrenome.\n';
}
if (!document.getElementById('ALE_EMAILCLI').value || !ValidaEmail(document.getElementById('ALE_EMAILCLI').value))
{
msg=msg+'Seu email não foi escrito corretamente.\n';
}
if (document.getElementById('ALE_DATAVALIDADE').selectedIndex==0)
{
msg=msg+'Selecione o prazo máximo para ser avisado por email.\n';
}
if (msg != "")
{
alert(msg);
return;
}
document.getElementById('ALE_PEDIDO').value=document.frmLoja.pedido.value;
document.getElementById('ALE_LISTA').value=document.frmLoja.lista.value;
//ANTES
//document.getElementById('formAviseMePreco').submit();
//NOVA ESPECIFICAÇÃO:
// A nova especificação mencionada anteriormente é sobre aparecer uma lista dos produtos que tem o valor
//menor que o valor que o cliente pediu para ser avisado. Caso exista um produto com o valor menor que o
//solicitado pelo cliente é exibido na tela alertando-o
var queryString="";
for (i=0;i 70) // assumo que não é só um alert de javascript
if (strRetorno != 'ALERTA') // assumo que não é só um alert de javascript
{
var body= window.document.getElementsByTagName('body')[0];
var tela = document.createElement("div");
tela.id='telaCinza';
var xWithScroll,yWithScroll;
if (window.innerHeight && window.scrollMaxY) {// Firefox
yWithScroll = window.innerHeight + window.scrollMaxY;
xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
yWithScroll = document.body.scrollHeight;
xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
yWithScroll = document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
tela.style.width=xWithScroll;
tela.style.height=yWithScroll;
tela.style.background='#E6E5E4';
tela.style.opacity='0.8';
tela.style.filter="alpha(opacity=80)";
tela.style.position='absolute';
tela.style.top=0;
tela.style.left=0;
tela.style.zIndex = 30;
tela.style.visibility='visible';
body.appendChild(tela);
var telaAlerta = document.createElement("div");
telaAlerta.id='layer_alerta';
telaAlerta.style.position='absolute';
if (window.innerHeight && window.scrollMaxY) {
topo=document.body.scrollTop;
xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){
topo=document.body.scrollTop;
xWithScroll = document.body.scrollWidth;
} else {
topo=document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
var dif = xWithScroll - 410;
esquerda = parseInt(dif/2);
//topo += parseInt(y);
telaAlerta.style.margin='0 auto';
telaAlerta.style.zIndex = 30;
telaAlerta.style.visibility='visible';
body.appendChild(telaAlerta);
if (document.getElementById('BTF'))
{
document.getElementById('BTF').style.visibility='hidden';
}
// esquerda=esquerda/2;
document.getElementById("layer_alerta").style.position='absolute';
document.getElementById('layer_alerta').innerHTML=oXML.responseText;
document.getElementById("layer_alerta").style.top="20px";
document.getElementById("layer_alerta").style.left=esquerda + "px";
document.getElementById('layer_alerta').style.visibility="visible";
telaAlerta.innerHTML=document.getElementById("layer_alerta").innerHTML;
}
}
myConn.connect("./FormularioProduto/FormMandaGravar.php", "GET", queryString, fnWhenDone);
}
// ------------------------------------------------------------
// VALIDAÇÃO DOS DADOS DO FORMULÁRIO DE ALERTA OPINIÃO SOBRE PRODUTO
// ------------------------------------------------------------
function validaFormOpina()
{
var msg='';
if (document.getElementById('SEUNOME_O').value.length<3)
{
msg=msg+'Favor escreva seu nome.\n';
}
if (!document.getElementById('SEUEMAIL_O').value || !ValidaEmail(document.getElementById('SEUEMAIL_O').value))
{
msg=msg+'Seu e-mail foi escrito de forma incorretamente.\n';
}
if (document.getElementById('POSSUI_O').selectedIndex==0)
{
msg=msg+'Favor responda se você possui ou não este produto.\n';
}
if (document.getElementById('RECOMENDA_O').selectedIndex==0)
{
msg=msg+'Favor responda se você recomenda ou não este produto.\n';
}
if (document.getElementById('PRAT_O').selectedIndex==0)
{
msg=msg+'Favor responda o que vocês achou sobre a Praticidade deste produto.\n';
}
if (document.getElementById('DURA_O').selectedIndex==0)
{
msg=msg+'Favor responda o que vocês achou sobre a Durabilidade deste produto.\n';
}
if (document.getElementById('CUST_O').selectedIndex==0)
{
msg=msg+'Favor responda o que vocês achou sobre o Custo Beneficio deste produto.\n';
}
if (document.getElementById('DESI_O').selectedIndex==0)
{
msg=msg+'Favor responda o que vocês achou sobre o Designer deste produto.\n';
}
if (document.getElementById('COMENTARIO_O').value.length<3)
{
msg=msg+'Favor escreva o comentário.\n';
}
if (document.getElementById('NEWSL_O').selectedIndex==0)
{
msg=msg+'Favor responda se você deseja receber ofertas promocionais pelo e-mail.\n';
}
if (msg != "")
{
alert(msg);
return;
}else { alert("Opinião Recebida com Sucesso!"); }
//document.getElementById('formOpina').submit();
var queryString="";
for (i=0;i| Grupo: | ' + combo_grupos + ' |
';
break
case 2:
document.getElementById('div_dinamico1').innerHTML='| Grupo: | ' + combo_grupos + ' |
';
break
case 3:
if (codigo_grupo)
{
valor=codigo_grupo;
}
else
{
valor='';
}
document.getElementById('div_dinamico1').innerHTML='';
document.getElementById('div_dinamico2').innerHTML='';
break
default:
alert("Erro de programa")
}
if (document.getElementById('prod_grupo'))
{
for (i=0;i document.body.offsetHeight){ // all but Explorer Mac
yWithScroll = document.body.scrollHeight;
xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
yWithScroll = document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
tela.style.width=xWithScroll;
tela.style.height=yWithScroll;
tela.style.background='#000000';
tela.style.opacity='0.7';
tela.style.filter="alpha(opacity=70)";
tela.style.position='absolute';
tela.style.top=0;
tela.style.left=0;
tela.style.zIndex = 30;
tela.style.visibility='visible';
body.appendChild(tela);
var telaAlerta = document.createElement("div");
telaAlerta.id='layer_alerta';
telaAlerta.style.position='absolute';
var topo=0;
if (window.innerHeight && window.scrollMaxY) {
topo=document.body.scrollTop;
xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){
topo=document.body.scrollTop;
xWithScroll = document.body.scrollWidth;
} else {
//topo=document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
var dif = xWithScroll - x;
esquerda = parseInt(dif/2);
topo += parseInt(y);
telaAlerta.style.margin='0 auto';
telaAlerta.style.zIndex = 30;
telaAlerta.style.visibility='visible';
body.appendChild(telaAlerta);
if (document.getElementById('BTF'))
{
document.getElementById('BTF').style.visibility='hidden';
}
preLoadLayers(layer);
showLayer(layer, esquerda, topo, prod_id, prod_nome, grupo_id, tipo_id);
}
function apagarDivs(){
var tela1 = document.getElementById("layer_alerta");
var tela2 = document.getElementById("telaCinza");
var body= document.getElementsByTagName('body')[0];
body.removeChild(tela1);
body.removeChild(tela2);
}
function XHConn()
{
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone)
{
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET")
{
xmlhttp.open(sMethod, sURL+"?"+sVars, true);
sVars = "";
}
else
{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && !bComplete)
{
bComplete = true;
fnDone(xmlhttp);
//return xmlhttp.responseText;
}};
xmlhttp.send(sVars);
}
catch(z) { return false; }
return true;
}; return this;
}