<!--
function MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
function MM_preloadImages() { var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
function MM_findObj(n, d) { var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && document.getElementById) x=document.getElementById(n); return x;}
function MM_swapImage() { var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}
//-->

function SomenteNumero(e){
if (document.all) // Internet Explorer
var tecla = event.keyCode;
else if(document.layers) // Nestcape
var tecla = e.which;
if (tecla > 47 && tecla < 58) // numeros de 0 a 9
return true;
else{
if (tecla != 8) // backspace
event.keyCode = 0;
else
return true;
}
}

function SomenteNumeroMoeda(e){
 if (document.all) // Internet Explorer
  var tecla = event.keyCode;
 else if(document.layers) // Nestcape
  var tecla = e.which;
 if(tecla == 44  || tecla == 46){return true;}
 if (tecla > 47 && tecla < 58) // numeros de 0 a 9
  return true;
 else{
  if (tecla != 8) // backspace
   event.keyCode = 0;
	//return false;
  else
   return true;
 }
}

function IsNumeric(sText){
 var ValidChars = "0123456789";
 var IsNumber=true;
 var Char;
 for (i = 0; i < sText.length && IsNumber == true; i++){ 
  Char = sText.charAt(i); 
  if (ValidChars.indexOf(Char) == -1){
   IsNumber = false;
  }
 }
 return IsNumber;
}


function VerificaVazio(vCampo){
 if(vCampo.value==''){
  vCampo.focus();
  return false;
 }
 return true;
}

/// VALIDA O CAMPO E-MAIL ///
function ValidaEmail(vEmail){
//return true;
 var email = vEmail.value;
 var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
 var GoodChars = "@."; 
 var posarroba = email.indexOf ("@",0);
 if (email.length < 6){ // o email é menor que 6 caracteres
  return (false);
 }
 for (var i = 0; i < email.length; i++){
  if (BadChars.indexOf(email.charAt(i)) != -1){ // Contém caracteres inválidos, badchars
	return (false);
  }
 }
 for (var i = 0; i < GoodChars.length; i++){
  if (email.indexOf(GoodChars.charAt(i)) == -1){ // não tem goodchars
	return (false);
  }
  if (email.indexOf(GoodChars.charAt(i),0) == 0){ // começou com goodchars (. ou @)
   return (false);
  }
  if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3){ //existe menos de 2 caracteres depois do ultimo goodchar
   return (false);
  }
 }
 if (email.indexOf ("@.",0) != -1 || email.indexOf (".@",0) != -1){ // . e @ colados
  return (false);
 }
 if (email.indexOf ("@",posarroba+1) != -1){ // Contém mais de um " @ " 
  return (false);
 }
 return (true);
}

function ValidaDataForm(vDia,vMes,vAno){
 if (vDia < 1 || vDia > 31){return false;}
 if (vMes < 1 || vMes > 12){return false;}
 if (vAno < 1900 || vAno > 2010){return false;}
 if (vMes == 2 && vDia > 29){return false;}
 return true;
}

//Mostra os caracteres restantes no textarea
//Entrada: txtArea: Campo TextArea
//			  vTotal: Máximo de Caracteres
function MontaCharTextArea(txtArea, vTotal){
 total = vTotal;
 tam = txtArea.value.length;
 str="";
 str=str+tam;
 Digitado.innerHTML = str;
 Restante.innerHTML = total - str;
 if (tam > total){
  aux = txtArea.value;
  txtArea.value = aux.substring(0,total);
  Digitado.innerHTML = total
  Restante.innerHTML = 0
 } 
}

function NewWin(url,name,xpos,ypos,width,height){
 var x = parseInt((screen.width-width)/2);
 var y = parseInt((screen.height-height)/2);
 newWin=window.open(url, name, "screenX="+xpos+",screenY="+ypos+",WIDTH="+width+",HEIGHT="+height+ 
        ",location=0,resizable=1,status=0,titlebar=0,directories=0,toolbar=0,menubar=0,scrollbars=0,status=0");
 newWin.focus();
newWin.moveTo(x,y);
}
function NewWinScroll(url,name,xpos,ypos,width,height){
 var x = parseInt((screen.width-width)/2);
 var y = parseInt((screen.height-height)/2);
 newWin=window.open(url, name, "screenX="+xpos+",screenY="+ypos+",WIDTH="+width+",HEIGHT="+height+",location=0,resizable=0,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=0");
 newWin.focus();
 newWin.moveTo(x,y);
}
function PopupPic(sPicURL){ window.open( "popup.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");} 
function MostraCategoria(vID){window.location.href='lista_anuncio.asp?cat='+vID;}

//Funcoes Header
function MostraLinksGeral(){NewWin(_url+'links.htm','LINKS',250,130,700,600);}
function MostraTermoUso(){NewWinScroll(_url+'termos.htm','Termos',250,130,530,400);}
function MostraAviso(){NewWin(_url+'popup_aviso.asp','AVISO',250,130,400,300);}
function MostraRecomendacao(vID, vTipo, vTitulo){NewWin(_url+'pop_recomendacao.asp?id='+vID+'&tipo='+vTipo+'&anuncio='+vTitulo,'RECOMENDACAO',200,180,615,450);}
function Denunciar(vID, vTipo, vTitulo){NewWin(_url+'pop_denuncia_anuncio.asp?id='+vID+'&tipo='+vTipo+'&anuncio='+vTitulo,'RECOMENDACAO',200,180,615,450);}

function ValidaBusca(){
if(document.frmBusca.txtBusca.value==''){alert('Digite o que deseja buscar.');document.frmBusca.txtBusca.focus();return false;}
var _txt = document.frmBusca.txtBusca.value;
//_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");_txt = _txt.replace(" ","_");
_txt = retirarAcentos(_txt);
document.frmBusca.action=_url+'busca/' + _txt;
document.frmBusca.submit();
}
function retirarAcentos(valor) {
var texto = valor;
var acento = ' áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ,:;?^<>.';
var semacento = '-aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC--------';
var nova='';
for (i = 0; i < texto.length; i++) {
if (acento.search(texto.substr(i, 1)) >= 0) {
nova += semacento.substr(acento.search(texto.substr(i, 1)), 1);
}
else {
nova += texto.substr(i, 1);
}
}
return nova;
}
//Listagem
function Listagem(){
document.frmPesquisa.view.value = 'L';
ValidaFiltroListagem();
}
function Galeria(){
document.frmPesquisa.view.value = 'G';
ValidaFiltroListagem();
}
function ValidaFiltroListagem(){
_ords = document.frmPesquisa.cmbOrdem.value;
var _view = document.frmPesquisa.view.value;
var _cat = document.frmPesquisa.cat.value;
var _uf = document.frmPesquisa.cmbUF.value;
var _tp = document.frmPesquisa.cmbTipo.value;
document.frmPesquisa.action=_url+'lista_anuncio.asp?cmbOrdem='+_ords+'&txtBusca='+_txt+'&cmbTipo='+_tp+'&cmbUF='+_uf+'&cat='+_cat+'&view='+_view+'&pagina='+_pag;
document.frmPesquisa.submit();
}
function ValidaRecomendacao(){
 if(!VerificaVazio(document.frmRecomendacao.txtNome)){alert('Digite seu Nome.');document.frmRecomendacao.txtNome.focus();return false;}
 if(!VerificaVazio(document.frmRecomendacao.txtEmail)){alert('Digite seu E-mail.');document.frmRecomendacao.txtEmail.focus();return false;}
 if(!ValidaEmail(document.frmRecomendacao.txtEmail)){alert('O seu E-mail não é válido.');document.frmRecomendacao.txtEmail.focus();return false;}
 if(!VerificaVazio(document.frmRecomendacao.txtNomeDestinatario)){alert('Digite o Nome do seu Amigo.');document.frmRecomendacao.txtNomeDestinatario.focus();return false;}
 if(!VerificaVazio(document.frmRecomendacao.txtEmailDestinatario)){alert('Digite o E-mail do seu Amigo.');document.frmRecomendacao.txtEmailDestinatario.focus();return false;}
 if(!ValidaEmail(document.frmRecomendacao.txtEmailDestinatario)){alert('O E-mail do seu Amigo não é válido.');document.frmRecomendacao.txtEmailDestinatario.focus();return false;}
 return true;
}

function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
str = str.replace( /\s*tab-stops:[^"]*/gi, "" ) ;
str = str.replace( /\s*face="[^"]*"/gi, "" ) ;
str = str.replace( /\s*face=[^ >]*/gi, "" ) ;
str = str.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
str = str.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
str = str.replace( /\s*style="\s*"/gi, '' ) ; 
str = str.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ; 
str = str.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ; 
str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ; 
str = str.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ; 
str = str.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;
str = str.replace(/<\\?\?xml[^>]*>/gi, "") ; 
str = str.replace(/<\/?\w+:[^>]*>/gi, "") ; 
str = str.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
str = str.replace( /<H1([^>]*)>/gi, '' ) ;
str = str.replace( /<H2([^>]*)>/gi, '' ) ;
str = str.replace( /<H3([^>]*)>/gi, '' ) ;
str = str.replace( /<H4([^>]*)>/gi, '' ) ;
str = str.replace( /<H5([^>]*)>/gi, '' ) ;
str = str.replace( /<H6([^>]*)>/gi, '' ) ;
str = str.replace( /<\/H\d>/gi, '<br>' ) ; //remove this to take out breaks where Heading tags were 
str = str.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;
str = str.replace( /<(B|b)>&nbsp;<\/\b|B>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
//some RegEx code for the picky browsers
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;
str = str.replace( re, "<div$2</div>" ) ;
var re2 = new RegExp("(<font|<FONT)([^*>]*>.*?)(<\/FONT>|<\/font>)","gi") ; 
str = str.replace( re2, "<div$2</div>") ;
str = str.replace( /size|SIZE = ([\d]{1})/g, '' ) ;
return str ;
}
