// Armazena o innerHTML anterior da célula ctn_val gaSpaImvOldCtnVal = new Array("",""); // Armazena dados sobre o conteúdo exibido antes da pesquisa gaSpaImvOldConteudo = new Array(null,null); // Para armazenamento dos objetos que serão removidos durante a pesquisa e reenseridos após ela goSpaImvSaveFrmPesq = null; // Último scroll offset obtido com spaImvCumulativeScrollOffset ao exibir os detalhes gnSpaImvCurScrollOffset = 0; // Caminho para clientes gcSpaPathCli = "http://www.spaicnet.com.br/clientes"; function spaImvExibeDetDtq(oObj) { eval(oObj.attributes["onclick_code"].nodeValue); } function spaImvAtivaEstado(cPath,nLateral) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; oTipo = document.getElementById("spa-imv-tipv" + cSufAv); oEstado = document.getElementById("spa-imv-estado" + cSufAv); cTipo = spaImvPegaTipo(nLateral); if (oEstado.tagName == "INPUT") { spaImvBuscarCidades(oEstado,cPath,nLateral); } else { oAjax = spaImvCriaAjax(); if (oAjax) { cURL = cPath + "spa_query.php?tp=3&tc=" + cTipo + "&sr=" + gcSpaSrImv; oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); spaImvTrataAjax(oEstado,cPath,nLateral); // Assim dá pra passar parâmetros } oEstado.disabled = false; } oCodigoImv = document.getElementById("spa-imv-cod-i" + cSufAv); if (oCodigoImv) { oCodigoImv.disabled = false; } spaImvControlaCamposValor(cTipo,nLateral); } function spaImvCriaAjax() { var xmlhttp; try { xmlhttp = new XMLHttpRequest(); } catch (ie1) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (ie2) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; } } } return xmlhttp; } function spaImvControlaCamposValor(cTipo,nLateral) { if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; oCidade = document.getElementById("spa-imv-cidade" + cSufAv); lUsaPar = (oCidade.tagName == "INPUT"); lDisabled = (lUsaPar ? false : (oCidade.selectedIndex == 0)); oCtnVal = document.getElementById("spa-imv-ctn_val" + cSufAv); if (cTipo == "V") { if (gaSpaImvOldCtnVal[nLateral].length != 0) { oCtnVal.innerHTML = gaSpaImvOldCtnVal[nLateral]; } document.getElementById("spa-imv-valor" + cSufAv).disabled = lDisabled; } else if (cTipo == "L") { if (gaSpaImvOldCtnVal[nLateral].length == 0) { gaSpaImvOldCtnVal[nLateral] = oCtnVal.innerHTML; } if (nLateral == 0) { oCtnVal.innerHTML = '' + ' a ' + '
(Digite apenas números. Ex.: 400 a 1200)'; } else { oCtnVal.innerHTML = '' + ' a ' + '
(Digite apenas números)'; } document.getElementById("spa-imv-vali" + cSufAv).onkeydown = spaImvValidaValor; document.getElementById("spa-imv-valf" + cSufAv).onkeydown = spaImvValidaValor; document.getElementById("spa-imv-vali" + cSufAv).disabled = lDisabled; document.getElementById("spa-imv-valf" + cSufAv).disabled = lDisabled; } } function spaImvValidaValor(e) { e = e ? e : window.event; lRet = false; nChar = !isNaN(e.charCode) && e.charCode != 0 ? e.charCode: !isNaN(e.keyCode) && e.keyCode != 0 ? e.keyCode: e.which; if ((nChar >= 96 && nChar <= 105) || (nChar >= 48 && nChar <= 57)) { lRet = true; } else if (nChar == 8 || nChar == 9 || nChar == 13 || nChar == 16 || nChar == 35 || nChar == 36 || nChar == 37 || nChar == 39 || nChar == 46) { lRet = true; } return lRet; } function spaImvBuscarCidades(oObj,cPath,nLateral) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; oCidade = document.getElementById("spa-imv-cidade" + cSufAv); if (oObj.tagName == "SELECT") { oAjax = spaImvCriaAjax(); if (oAjax) { cTipo = spaImvPegaTipo(nLateral); cURL = cPath + "spa_query.php?tp=4&tc=" + cTipo + "&uf=" + oObj.options[oObj.selectedIndex].text + "<=" + nLateral + "&sr=" + gcSpaSrImv; oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); spaImvTrataAjax(oCidade,cPath,nLateral); // Assim dá pra passar parâmetros oCidade.disabled = (oObj.selectedIndex == 0); } } spaImvBuscarRegioes(oCidade,cPath,nLateral); } function spaImvTrataAjax(oObj,cPath,nLateral,oDadosJson) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; if (oAjax.readyState == 4) { if (oAjax.status == 200) { // Estou usando json oJson = eval("(" + oAjax.responseText + ")"); if (oAjax.responseText.indexOf("opcoes") != -1) { spaImvRemoveFilhos(oObj); spaImvPopulaSelect(oObj,oJson); /* * Se tiver estado e cidade preenchidos, trazer como padrão * setTimeout é importante para resolver problemas com o IE */ if (oObj.id == "spa-imv-estado" + cSufAv) { if (oJson.uf.length > 0) { for (i = 0; i < oObj.childNodes.length; i++) { if (oObj.childNodes[i].getAttribute("value") == oJson.uf) { oObj.childNodes[i].setAttribute("selected",true); break; } } window.setTimeout('spaImvBuscarCidades(document.getElementById("spa-imv-estado' + cSufAv + '"),"' + cPath + '",' + nLateral + ')',50); } } else if (oObj.id == "spa-imv-cidade" + cSufAv) { if (oJson.cid.length > 0) { for (i = 0; i < oObj.childNodes.length; i++) { if (oObj.childNodes[i].getAttribute("value") == oJson.cid) { oObj.childNodes[i].setAttribute("selected",true); break; } } window.setTimeout('spaImvBuscarRegioes(document.getElementById("spa-imv-cidade' + cSufAv + '"),"' + cPath + '",' + nLateral + ')',50); } } } else if (oAjax.responseText.indexOf("mini") != -1) { spaImvAtuMini(oObj,oJson); } } } } /* * Remove todos os objetos filhos de um objeto */ function spaImvRemoveFilhos(oObj) { while (oObj.firstChild) { oObj.removeChild(oObj.firstChild); } } /* * Popula um select */ function spaImvPopulaSelect(oSelect,oJson) { for (i = 0; i < oJson.opcoes.length; i++) { oOption = document.createElement("option"); oOption.setAttribute("value",oJson.opcoes[i].codigo); // 04/11/2011 - Agora recebemos entidades HTML do PHP e usando createTextNode() elas não eram convertidas //oOption.appendChild(document.createTextNode(oJson.opcoes[i].descr)); oOption.innerHTML = oJson.opcoes[i].descr; oSelect.appendChild(oOption); } } function spaImvExibeDetalhe(oObj, cPath, cTipC, cSerie, lPopup, cArqCSS) { if (cPath == null) { cPath = ""; } if (cTipC == null) { cTipC = ""; } if (cSerie == null) { cSerie = ""; } if (lPopup == null) { lPopup = false; } if (cArqCSS == null) { cArqCSS = ""; } // 08/08/2011 - Usado somente na Jerusalém por enquanto // 10/08/2011 - Será o padrão para acesso pelos links if (lPopup) { /* * O Firefox só obedece width e height. A janela traz barra de endereço, statusbar e permite redimensionamento. * Só é possível mudar este comportamento em about:config. */ if (cTipC.length != 0) { // Imóveis em destaque // oObj recebe o código do imóvel cURL = gcSpaPathCli + "/servicosnet/imoveis/detalhe2.php?sr=" + cSerie + "&tc=" + cTipC + "&id=" + oObj; } else { cTipo = spaImvPegaCampoPesq("p_tc").value; cID = oObj.id; cItem = cID.substring(cID.indexOf("_") + 1); cURL = gcSpaPathCli + "/servicosnet/imoveis/detalhe2.php?sr=" + cSerie + "&tc=" + cTipo + "&id=" + document.getElementById("spa-imv-chave_" + cItem).value; } cURL += "&depup=1" + "&stl=" + (cArqCSS.indexOf("%") != -1 ? cArqCSS : escape(cArqCSS)); window.open(cURL, "", "WIDTH=810,HEIGHT=530"); } else { if (cTipC.length != 0) { // Imóveis em destaque // oObj recebe o código do imóvel cURL = cPath + "spa_query.php?tp=14&id=" + oObj + "&tc=" + cTipC + "&sr=" + cSerie; } else { cTipo = spaImvPegaCampoPesq("p_tc").value; cID = oObj.id; cItem = cID.substring(cID.indexOf("_") + 1); cURL = cPath + "spa_query.php?tp=14&id=" + document.getElementById("spa-imv-chave_" + cItem).value + "&tc=" + cTipo + "&sr=" + cSerie; } oAjax = spaImvCriaAjax(); if (oAjax) { oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); if (oAjax.readyState == 4) { if (oAjax.status == 200) { oDivDet = document.createElement("div"); if (oDivDet) { oDivDet.id = "spa-imv-div_det"; oDivDet.innerHTML = oAjax.responseText; cNav = navigator.userAgent; lMSIE = (cNav.indexOf("MSIE") != -1); if (lMSIE) { //gnSpaImvCurScrollOffset = spaImvCumulativeScrollOffset(document.getElementById("wrapper")); //gnSpaImvCurScrollOffset = spaImvCumulativeScrollOffset(document.getElementById(gcSpaIDCtnBase)); oCtnBase = document.getElementById(gcSpaIDCtnBase); gnSpaImvCurScrollOffset = (oCtnBase) ? spaImvCumulativeScrollOffset(oCtnBase) : 0; oDivDet.style.top = gnSpaImvCurScrollOffset + 35; // Esconde selects, objects e embeds. No IE estes objetos ficam por cima dos detalhes $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' }); // Evita que o Lightbox tente esconder/exibir estes objetos enquanto os detalhes estão visíveis LightboxOptions.hideUndesirable = false; } oBody = document.body; oBody.appendChild(oDivDet); } } } } } } function spaImvFechaDetalhe() { if (parent.document.getElementById("spa-imv-div_mail")) { spaImvFechaEMail(); } cNav = navigator.userAgent; lMSIE = (cNav.indexOf("MSIE") != -1); cIDDet = "spa-imv-div_det"; oDivDet = document.getElementById(cIDDet); document.body.removeChild(oDivDet); gnSpaImvCurScrollOffset = 0; if (lMSIE) { $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' }); LightboxOptions.hideUndesirable = false; } } function spaImvLinkOver(oObj,nLateral,lSempre) { if (nLateral == null) { nLateral = 0; } if (lSempre == null) { lSempre = false; } cSufAv = (nLateral == 0) ? "_av" : ""; oBtnPesq = document.getElementById("spa-imv-btn_pesq" + cSufAv); if ((lSempre ? true : (oBtnPesq ? !oBtnPesq.disabled : true))) { oObj.style.cursor = "hand"; /* * Um "hack" maluco necessário para o Firefox. Seria um bug ou uma feature? * Curioso é que no IE, com ou sem esta linha, tudo funciona perfeitamente. */ oObj.style.cursor = "pointer"; } } function spaImvLinkOut(oObj,nLateral,lSempre) { if (nLateral == null) { nLateral = 0; } if (lSempre == null) { lSempre = false; } oBtnPesq = document.getElementById("spa-imv-btn_pesq" + cSufAv); if ((lSempre ? true : (oBtnPesq ? !oBtnPesq.disabled : true))) { oObj.style.cursor = "pointer"; } } function spaImvImgOver(oObj,lSempre) { if (lSempre == null) { lSempre = false; } oBtn = document.getElementById("spa-imv-btn_pesq"); if ((lSempre ? true : (oBtn ? !oBtn.disabled : true))) { oObj.style.cursor = "hand"; oObj.style.cursor = "pointer"; } } function spaImvImgOut(oObj,lSempre) { if (lSempre == null) { lSempre = false; } oBtn = document.getElementById("spa-imv-btn_pesq"); if ((lSempre ? true : (oBtn ? !oBtn.disabled : true))) { oObj.style.cursor = "pointer"; } } /* * Pega o tipo selecionado: Venda ou Locação */ function spaImvPegaTipo(nLateral) { if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; cRet = ""; oTipV = spaImvPegaCampoPesq("spa-imv-tipv" + cSufAv); if (oTipV.type.toUpperCase() == "RADIO") { oTipL = spaImvPegaCampoPesq("spa-imv-tipl" + cSufAv); if (oTipV.checked) { cRet = oTipV.value; } else { cRet = oTipL.value; } } else { cRet = oTipV.value; } return cRet; } function spaImvBuscarRegioes(oObj,cPath,nLateral) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; oAjax = spaImvCriaAjax(); if (oAjax) { lUsaPar = (oObj.tagName == "INPUT"); oRegiao = document.createElement("select"); oOpcao = document.createElement("option"); oOpcao.nodeValue = "0"; oRegiao.appendChild(oOpcao); spaImvBuscarBairros(oObj,oRegiao,cPath,nLateral); lDisabled = (lUsaPar ? (parseInt(oObj.value) == 0) : (oObj.selectedIndex == 0)); oRegiao.disabled = lDisabled; document.getElementById("spa-imv-bairro" + cSufAv).disabled = lDisabled; document.getElementById("spa-imv-tipo_imov" + cSufAv).disabled = lDisabled; spaImvControlaCamposValor(cTipo,nLateral); document.getElementById("spa-imv-dormit" + cSufAv).disabled = lDisabled; document.getElementById("spa-imv-vagas" + cSufAv).disabled = lDisabled; document.getElementById("spa-imv-btn_pesq" + cSufAv).disabled = lDisabled; } } function spaImvBuscarBairros(oObj,oSelect,cPath,nLateral) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; oAjax = spaImvCriaAjax(); if (oAjax) { cTipo = spaImvPegaTipo(nLateral); lUsaPar = (oObj.tagName == "INPUT"); cURL = cPath + "spa_query.php?tp=5&tc=" + cTipo + "&cid=" + (lUsaPar ? oObj.value : oObj.options[oObj.selectedIndex].value) + "®=" + oSelect.options[oSelect.selectedIndex].value + "<=" + nLateral + "&sr=" + gcSpaSrImv; oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); oBairro = document.getElementById("spa-imv-bairro" + cSufAv); spaImvTrataAjax(oBairro,cPath,nLateral); // Assim dá pra passar parâmetros oBairro.disabled = (lUsaPar ? (parseInt(oObj.value) == 0) : (oObj.selectedIndex == 0)); } } function spaImvExecutaPesquisa(nPag, cPath, nLateral, nDePup, cArqCSS) { if (cPath == null) { cPath = ""; } if (nLateral == null) { nLateral = 0; } if (nDePup == null) { nDePup = 0; } if (cArqCSS == null) { cArqCSS = ""; } cSufAv = (nLateral == 0) ? "_av" : ""; if (!nPag) { nPag = 1; } cTipo = (cPath == "n") ? document.getElementById("p_tc").value : spaImvPegaTipo(nLateral); if (cTipo == "V") { cValor = document.getElementById((cPath == "n") ? "p_val" : "spa-imv-valor" + cSufAv).value; } else { oValI = spaImvPegaCampoPesq((cPath == "n") ? "p_vli" : "spa-imv-vali" + cSufAv); cValI = oValI.value; oValF = spaImvPegaCampoPesq((cPath == "n") ? "p_vlf" : "spa-imv-valf" + cSufAv); cValF = oValF.value; if (parseInt(cValI) > parseInt(cValF)) { window.alert("O valor inicial não pode ser maior que o valor final."); oValI.select(); oValI.focus(); return false; } } // Pesquisa por código oCodImv = document.getElementById("spa-imv-cod-i" + cSufAv); if (oCodImv) { if (oCodImv.value.length > 0) { //cTipo = (document.getElementById("spa-imv-tipv").checked) ? "V" : "L"; cURL = "spa_query.php?tp=14&id=" + oCodImv.value + "&tc=" + cTipo + "&sr=" + gcSpaSrImv; oAjax = criaAjax(); if (oAjax) { oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); if (oAjax.readyState == 4) { if (oAjax.status == 200) { if (oAjax.responseText.indexOf("*NE*") != -1) { window.alert("Imóvel não encontrado."); } else { //exibeDetImv(cTipC, oReferencia.value); spaImvExibeDetalhe(oCodImv.value, cPath, cTipo, gcSpaSrImv, (nDePup != 0), cArqCSS) // Limpa o código digitado e altera o estado do botão "Pesquisar" oCodImv.value = ""; spaImvAtivaBtnPesq(oCodImv); } } } } return true; } } // oEstado = spaImvPegaCampoPesq((cPath == "n") ? "p_uf" : "spa-imv-estado" + cSufAv); lUsaPar = (oEstado.tagName == "INPUT"); cUF = ((lUsaPar || cPath == "n") ? oEstado.value : oEstado.options[oEstado.selectedIndex].text); oCidade = spaImvPegaCampoPesq((cPath == "n") ? "p_cid" : "spa-imv-cidade" + cSufAv); cCodCid = ((lUsaPar || cPath == "n") ? oCidade.value : oCidade.options[oCidade.selectedIndex].value); cCodReg = "0"; oBairro = spaImvPegaCampoPesq((cPath == "n") ? "p_bai" : "spa-imv-bairro" + cSufAv); cCodBai = (cPath == "n") ? oBairro.value : oBairro.options[oBairro.selectedIndex].value; oTipImov = spaImvPegaCampoPesq((cPath == "n") ? "p_tim" : "spa-imv-tipo_imov" + cSufAv); cCodTipI = (cPath == "n") ? oTipImov.value : oTipImov.options[oTipImov.selectedIndex].value; cDormit = spaImvPegaCampoPesq((cPath == "n") ? "p_dor" : "spa-imv-dormit" + cSufAv).value; cVagas = spaImvPegaCampoPesq((cPath == "n") ? "p_vag" : "spa-imv-vagas" + cSufAv).value; oPesqAv = spaImvPegaCampoPesq((cPath == "n") ? "p_pa" : "spa-imv-pesq_av" + cSufAv); cPesqAv = oPesqAv.value; cPesqAvTxt = ""; if (cPath == "n") { cPesqAvTxt = spaImvPegaCampoPesq("p_tpa").value; } else if (cPesqAv == 1) { oElements = (document.forms["spa-imv-frmPesq" + cSufAv]) ? document.forms["spa-imv-frmPesq" + cSufAv].elements : null; if (!oElements) { oElements = goSpaImvSaveFrmPesq.elements; } for (i = 0; i < oElements.length; i++) { if (oElements[i].id.indexOf("spa-imv-chk") != -1) { if (oElements[i].checked) { if (cPesqAvTxt.length > 0) { cPesqAvTxt += ";"; } cPesqAvTxt += oElements[i].value; } } } } cVal = (cTipo == "V" ? "val=" + cValor : "vli=" + cValI + "&vlf=" + cValF); /** cDadCnt = ""; cPC2 = ""; //(cPath == "n") ? document.getElementById("p_c2").value : ""; if (cPC2.length == 0) { //nLateral == 1 && cPath != "n") { // ** cDadCnt = "c1=&c2=" + escape(oIFrCnt.attributes["src"].nodeValue) + "&c3=&c4=" + oIFrCnt.height; cDadCnt = "c1=&c2=&c3=&c4="; } else { cPC1 = escape(document.getElementById("p_c1").value); cPC2 = escape(cPC2); cPC3 = escape(document.getElementById("p_c3").value); cPC4 = document.getElementById("p_c4").value cDadCnt = "c1=" + cPC1 + "&c2=" + cPC2 + "&c3=" + cPC3 + "&c4=" + cPC4; } **/ cURL = "spa_query.php?tp=6" + "&tc=" + cTipo + "&uf=" + cUF + "&cid=" + cCodCid + "®=" + cCodReg + "&bai=" + cCodBai + "&tim=" + cCodTipI + "&" + cVal + "&dor=" + cDormit + "&vag=" + cVagas + "&pa=" + cPesqAv + "&tpa=" + cPesqAvTxt + "&pg=" + nPag + "<=" + nLateral + "&sr=" + gcSpaSrImv + "&depup=" + nDePup + "&stl=" + (cArqCSS.indexOf("%") != -1 ? cArqCSS : escape(cArqCSS)); oAjax = spaImvCriaAjax(); if (oAjax) { oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); if (oAjax.readyState == 4) { if (oAjax.status == 200) { oDiv = document.getElementById(gcSpaIDCtn); if (cPath != "n") { gaSpaImvOldConteudo[nLateral] = {'innerHTML':oDiv.innerHTML,'width':oDiv.style.width,'height':oDiv.style.height}; } oDiv.innerHTML = oAjax.responseText; // Código definido pelo usuário para ser executado na pesquisa lateral if (cPath != "n" && nLateral == 1 && gcSpaImvExPesqLat.length > 0) { eval(gcSpaImvExPesqLat); } } } } } /* * Para forçar o navegador a voltar para o topo da pesquisa */ function spaImvIrTopoPesq() { oPesq = document.getElementById("spa-imv-pesquisa_av"); oTopo = document.getElementById("spa-imv-topo_pesq"); if (oPesq) { oPesq.style.visibility = "visible"; } if (oTopo) { oTopo.style.visibility = "visible"; oTopo.focus(); oTopo.style.visibility = "hidden"; } if (oPesq) { oPesq.style.visibility = "hidden"; } } function spaImvVoltaPesquisa(nLateral) { if (nLateral == null) { nLateral = 0; } oDiv = document.getElementById(gcSpaIDCtn); oDiv.innerHTML = gaSpaImvOldConteudo[nLateral].innerHTML; oDiv.style.width = gaSpaImvOldConteudo[nLateral].width; oDiv.style.height = gaSpaImvOldConteudo[nLateral].height; gaSpaImvOldConteudo[nLateral] = null; // Código definido pelo usuário para ser executado na pesquisa lateral if (nLateral == 1 && gcSpaImvFePesqLat.length > 0) { eval(gcSpaImvFePesqLat); } } function spaImvExibeFoto(oObj) { //document.getElementById("detq").src = oObj.src; } function spaImvAtivaPesqAv(oObj,nLateral) { if (nLateral == null) { nLateral = 0; } cSufAv = (nLateral == 0) ? "_av" : ""; if (!document.getElementById("spa-imv-btn_pesq" + cSufAv).disabled) { oCtnAvanc = document.getElementById("spa-imv-ctn_avanc" + cSufAv); oAvancada = document.getElementById("spa-imv-avancada" + cSufAv); oPesqAv = document.getElementById("spa-imv-pesq_av" + cSufAv); if (oAvancada.style.visibility == "hidden") { oAvancada.style.display = "inline"; oAvancada.style.height = null; oAvancada.style.visibility = "visible"; //oCtnAvanc.style.border = "solid 1px #999999"; oPesqAv.value = "1"; oObj.innerHTML = "Pesquisa avançada <<"; } else { oAvancada.style.display = "none"; oAvancada.style.height = "0px"; oAvancada.style.visibility = "hidden"; oCtnAvanc.style.border = ""; oPesqAv.value = "0"; oObj.innerHTML = "Pesquisa avançada >>"; } } } function spaImvExibeFormMail(oObj, lPopup) { if (lPopup == null) { lPopup = false; } oAjax = spaImvCriaAjax(); if (oAjax) { cURL = ""; if (lPopup) { cURL = gcSpaPathCli + "/"; } cURL += "spa_query.php?tp=15&id=" + document.getElementById("spa-imv-chave_det").value + "&sr=" + gcSpaSrImv + "&tc=" + document.getElementById("spa-imv-tipc").value; if (lPopup) { cURL += "&depup=1"; } oAjax.open('GET',cURL,false); // false = síncrona oAjax.send(null); if (oAjax.readyState == 4) { if (oAjax.status == 200) { oDivMail = document.createElement("div"); if (oDivMail) { oDivMail.id = "spa-imv-div_det_mail"; oDivMail.innerHTML = oAjax.responseText; cNav = navigator.userAgent; lMSIE = (cNav.indexOf("MSIE") != -1); if (lMSIE) { //gnSpaImvCurScrollOffset = spaImvCumulativeScrollOffset(document.getElementById("wrapper")); //gnSpaImvCurScrollOffset = spaImvCumulativeScrollOffset(document.getElementById(gcSpaIDCtnBase)); oCtnBase = document.getElementById(gcSpaIDCtnBase); gnSpaImvCurScrollOffset = (oCtnBase) ? spaImvCumulativeScrollOffset(oCtnBase) : 0; oDivMail.style.top = gnSpaImvCurScrollOffset + 65; } oBody = document.body; oBody.appendChild(oDivMail); document.getElementById("spa-imv-nome").focus(); if (lMSIE) { document.getElementById("spa-imv-nome").focus(); } } } } } } function spaImvEnviaEMail(lPopup) { if (lPopup == null) { lPopup = false; } oID = document.getElementById("spa-imv-cod"); oNome = document.getElementById("spa-imv-nome"); oEMail = document.getElementById("spa-imv-email"); oDDDFone = document.getElementById("spa-imv-ddd_fone"); oNumFone = document.getElementById("spa-imv-num_fone"); oDDDCel = document.getElementById("spa-imv-ddd_cel"); oNumCel = document.getElementById("spa-imv-num_cel"); oObs = document.getElementById("spa-imv-obs"); oTipC = document.getElementById("spa-imv-tipc"); /* * Expressões regulares para validação dos campos */ oERNome = /\D{3,}/; oEREMail = /.+@{1}.+\.+.+/; oERDDDFone = /\d{2,}/; oERNumFone = /\d{2,4}-{0,1}\d{4}.*/; if (!oNome.value.match(oERNome)) { window.alert("Informe seu nome por favor."); oNome.select(); oNome.focus(); return; } if (oDDDFone.value.length > 0) { if (!oDDDFone.value.match(oERDDDFone)) { window.alert("O DDD deve conter apenas dígitos (pelo menos 2)."); oDDDFone.select(); oDDDFone.focus(); return; } } if (oNumFone.value.length > 0) { if (!oNumFone.value.match(oERNumFone)) { window.alert("O número do telefone informado não é válido."); oNumFone.select(); oNumFone.focus(); return; } } if (oDDDCel.value.length > 0) { if (!oDDDCel.value.match(oERDDDFone)) { window.alert("O DDD deve conter apenas dígitos (pelo menos 2)."); oDDDCel.select(); oDDDCel.focus(); return; } } if (oNumCel.value.length > 0) { if (!oNumCel.value.match(oERNumFone)) { window.alert("O número do celular informado não é válido."); oNumCel.select(); oNumCel.focus(); return; } } if (oEMail.value.length > 0) { if (!oEMail.value.match(oEREMail)) { window.alert("O e-mail informado não é válido."); oEMail.select(); oEMail.focus(); return; } } if (oEMail.value.length == 0 && oNumFone.value.length == 0 && oNumCel.value.length == 0) { window.alert("Preencha pelo menos uma forma de contato (e-mail ou telefone)."); return; } oAjax = spaImvCriaAjax(); if (oAjax) { cURL = ""; if (lPopup) { cURL = gcSpaPathCli + "/"; } cURL += "spa_query.php?tp=16" + "&id=" + oID.firstChild.nodeValue + "&nm=" + escape(oNome.value) + "&em=" + escape(oEMail.value) + "&df=" + escape(oDDDFone.value) + "&nf=" + escape(oNumFone.value) + "&dc=" + escape(oDDDCel.value) + "&nc=" + escape(oNumCel.value) + "&obs=" + escape(oObs.value) + "&sr=" + gcSpaSrImv + "&tc=" + oTipC.value; oAjax.open('GET',cURL,false); oAjax.send(null); if (oAjax.readyState == 4 && oAjax.status == 200) { //if (oAjax.responseText == "OK") { if (oAjax.responseText.indexOf("*OK*") != -1) { window.alert("Mensagem enviada com sucesso."); //window.close(); spaImvFechaEMail(); } else { window.alert("Não foi possível enviar sua mensagem. Entre em contato conosco, por favor." + String.fromCharCode(10, 10) + oAjax.responseText); } /* else { // Descomentar para teste window.alert(oAjax.responseText); } */ } } } function spaImvFechaEMail() { cIDMail = "spa-imv-div_det_mail"; oDivMail = document.getElementById(cIDMail); document.body.removeChild(oDivMail); } function spaImvRolOver(oObj) { oRolSt = document.getElementById("rol_st"); aStatus = oRolSt.value.split(","); if (oObj.id == "mini_v") { if (aStatus[1] == 1) { oObj.style.cursor = "hand"; oObj.style.cursor = "pointer"; oObj.src = "imagens/volta_o.gif"; } } else { if (aStatus[2] == 1) { oObj.style.cursor = "hand"; oObj.style.cursor = "pointer"; oObj.src = "imagens/avanca_o.gif"; } } } function spaImvRolOut(oObj) { oRolSt = document.getElementById("rol_st"); aStatus = oRolSt.value.split(","); if (oObj.id == "mini_v") { if (aStatus[1] == 1) { oObj.style.cursor = "pointer"; oObj.src = "imagens/volta.gif"; } } else { if (aStatus[2] == 1) { oObj.style.cursor = "pointer"; oObj.src = "imagens/avanca.gif"; } } } function voltaImg(oObj) { oRolSt = document.getElementById("rol_st"); aStatus = oRolSt.value.split(","); oAjax = spaImvCriaAjax(); if (oAjax) { cURL = "img_mini.php?id=" + aStatus[3] + "&in=" + aStatus[0] + "&di=v&tc=" + aStatus[4]; oAjax.open('GET',cURL,false); oAjax.send(null); spaImvTrataAjax(document.getElementById("img_mini")); } } function spaImvAvancaImg(oObj) { oRolSt = document.getElementById("rol_st"); aStatus = oRolSt.value.split(","); oAjax = spaImvCriaAjax(); if (oAjax) { cURL = "img_mini.php?id=" + aStatus[3] + "&in=" + aStatus[0] + "&di=a&tc=" + aStatus[4]; oAjax.open('GET',cURL,false); oAjax.send(null); spaImvTrataAjax(document.getElementById("img_mini")); } } function spaImvAtuMini(oObj,oJson) { cMini = ""; nCnt = 0; for (i = 0; i < oJson.mini.length; i++) { if (cMini.length > 0) { cMini += " "; } cMini += ""; nCnt ++; } /* * Se tiver menos que 5 imagens complementa com nada.jpg */ if (nCnt < 5) { for (i = (nCnt + 1); i <= 5; i++) { cMini += ""; } } cMini = " " + cMini + " " + ""; oObj.innerHTML = cMini; } function spaImvPegaCampoPesq(cCampo) { oCampo = document.getElementById(cCampo); if (!oCampo) { if (goSpaImvSaveFrmPesq) { oCampo = goSpaImvSaveFrmPesq.elements[cCampo]; } if (!oCampo) { //window.alert(cCampo); oCampo = window.frames[0].document.getElementById(cCampo); //.contentDocument.getElementById(cCampo); } } return oCampo; } /* * Original retirada de prototype.js */ function spaImvCumulativeScrollOffset(element) { var valueT = 0, valueL = 0; do { valueT += element.scrollTop || 0; valueL += element.scrollLeft || 0; element = element.parentNode; } while (element); return valueT; } function spaImvAtivaBtnPesq(oObj) { cSufAv = (oObj.id.indexOf("_av") != -1) ? "_av" : ""; oBtnPesq = document.getElementById("spa-imv-btn_pesq" + cSufAv); if (oObj.value.length > 0) { oBtnPesq.disabled = false; } else { oCidade = document.getElementById("spa-imv-cidade" + cSufAv); lUsaPar = (oCidade.tagName == "INPUT"); lDisabled = (lUsaPar ? (parseInt(oCidade.value) == 0) : (oCidade.selectedIndex == 0)); oBtnPesq.disabled = lDisabled; } } /* * 03/11/2011 - Como o método replace estava falhando com uma variável, criei esta função para substituí-lo * Está neste arquivo por conveniência. O ideal é criar um arquivo de rotinas genéricas */ function spaReplace(cStr, cSearch, cReplace) { //nPos = 0; while ((nPos = cStr.indexOf(cSearch)) != -1) { //if (nPos != -1) { cStr = cStr.substring(0, nPos) + cReplace + cStr.substr(nPos + cReplace.length); } return cStr; } /* * Corrige entidades HTML que foram convertidas para maiúsculas */ function spaCorrigeEntidades(cStr) { cStr = spaReplace(cStr, "ACUTE;", "acute;"); cStr = spaReplace(cStr, "CIRC;", "circ;"); cStr = spaReplace(cStr, "GRAVE;", "grave;"); cStr = spaReplace(cStr, "TILDE;", "tilde;"); cStr = spaReplace(cStr, "CEDIL;", "cedil;"); return cStr; } /* * Executa a pesquisa por código após pressionar Enter */ function spaImvPesqEnter(evt) { evt = (evt) ? evt : ((window.event) ? window.event : ""); if (evt) { nChar = !isNaN(evt.charCode) && evt.charCode != 0 ? evt.charCode: !isNaN(evt.keyCode) && evt.keyCode != 0 ? evt.keyCode: evt.which; if (nChar == 13) { oObj = evt.target ? evt.target : evt.srcElement; if (oObj.value.length > 0) { cSufAv = (oObj.id.indexOf("_av") != -1) ? "_av" : ""; oBtnPesq = document.getElementById("spa-imv-btn_pesq" + cSufAv); if (oBtnPesq) { oBtnPesq.onclick(); } } } } }