// JavaScript Document
//if (document.all)
//document.onselectstart =
//function () { return false; };

//function click() {
//if (event.button==2||event.button==3) {
// oncontextmenu='return false';
//  }
//}
//document.onmousedown=click
//document.oncontextmenu = new Function("return false;")

function janela(pagina,nome,larg,alt,scl)
{
	str_ng = 'toolbar=no,width=' + larg+ ',height=' + alt+ ',maximize=no,scrollbars=' + scl+ ',resizable=no resize=no';
	abre = window.open(pagina, nome, str_ng)
}

//Testa campos formulario contato/orçamento - anuncio
function testacampos()
 {
 aux=0;
 xnome=document.cv.nome.value;
 if (aux==0) {
 if (xnome==""){
 aux=1;
 alert("Preencha o campo Seu Nome");
 document.cv.nome.focus();
 return false;
 }
 }
 xemail=document.cv.email.value;
 if (aux==0) {
 if (xemail==""){
 aux=1;
 alert("Preencha o campo Seu E-mail");
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf("@") < 0){
 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br")
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf(".") < 0){

 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br");
 document.cv.email.focus();
 return false;
 }
 }
 xmsg=document.cv.mensagem.value;
 if (aux==0) {
 if (xmsg==""){
 aux=1;
 alert("Preencha o campo Sua Mensagem");
 document.cv.mensagem.focus();
 return false;
 }
 }
 element1 = document.getElementById('formulario_contato').style;
 element2 = document.getElementById('contato_enviado').style;
 element1.display='none';
 element2.display='block';
}

//Testa campos formulario comentario - noticia
function testacampos_comentario()
 {
 aux=0;
 xnome=document.cv.nome.value;
 if (aux==0) {
 if (xnome==""){
 aux=1;
 alert("Preencha o campo Seu Nome");
 document.cv.nome.focus();
 return false;
 }
 }
 xemail=document.cv.email.value;
 if (aux==0) {
 if (xemail==""){
 aux=1;
 alert("Preencha o campo Seu E-mail");
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf("@") < 0){
 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br")
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf(".") < 0){

 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br");
 document.cv.email.focus();
 return false;
 }
 }
 xmsg=document.cv.mensagem.value;
 if (aux==0) {
 if (xmsg==""){
 aux=1;
 alert("Preencha o campo Sua Mensagem");
 document.cv.mensagem.focus();
 return false;
 }
 }
 element1 = document.getElementById('formulario_comentario').style;
 element2 = document.getElementById('comentario_enviado').style;
 element1.display='none';
 element2.display='block';
}

//INICIO TESTA FORM CADASTRO
function testacampos_cadastro()
 {
 aux=0;
 xtitulo=document.cv.titulo.value;
 if (aux==0) {
 if (xtitulo==""){
 aux=1;
 alert("Preencha o campo Nome da Empresa");
 document.cv.titulo.focus();
 return false;
 }
 }
 xidcat=document.cv.id_categoria.value;
 if (aux==0) {
 if (xidcat<=0){
 aux=1;
 alert("Selecione uma categoria para sua empresa");
 document.cv.id_categoria.focus();
 return false;
 }
 }
 xnome=document.cv.nome.value;
 if (aux==0) {
 if (xnome==""){
 aux=1;
 alert("Preencha o campo Seu Nome");
 document.cv.nome.focus();
 return false;
 }
 }
 xemail=document.cv.email.value;
 if (aux==0) {
 if (xemail==""){
 aux=1;
 alert("Preencha o campo Seu E-mail");
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf("@") < 0){
 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br")
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf(".") < 0){

 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br");
 document.cv.email.focus();
 return false;
 }
 }
 xcpf=document.cv.cpf.value;
 if (aux==0) {
 if (xcpf==""){
 aux=1;
 alert("Preencha o campo CPF/CNPJ");
 document.cv.cpf.focus();
 return false;
 }
 }
 xddd=document.cv.ddd1.value;
 if (aux==0) {
 if (xddd==""){
 aux=1;
 alert("Preencha o campo DDD");
 document.cv.ddd1.focus();
 return false;
 }
 }
 xfone=document.cv.telefone1.value;
 if (aux==0) {
 if (xfone==""){
 aux=1;
 alert("Preencha o campo TELEFONE");
 document.cv.telefone1.focus();
 return false;
 }
 }
 xend=document.cv.endereco.value;
 if (aux==0) {
 if (xend==""){
 aux=1;
 alert("Preencha o campo ENDEREÇO");
 document.cv.endereco.focus();
 return false;
 }
 }
 xnume=document.cv.numero.value;
 if (aux==0) {
 if (xnume==""){
 aux=1;
 alert("Preencha o campo NÚMERO");
 document.cv.numero.focus();
 return false;
 }
 }
 xbairro=document.cv.bairro.value;
 if (aux==0) {
 if (xbairro==""){
 aux=1;
 alert("Preencha o campo BAIRRO");
 document.cv.bairro.focus();
 return false;
 }
 }
 xcep1=document.cv.cep1.value;
 if (aux==0) {
 if ((xcep1=="")||(xcep1.length!=5)){
 aux=1;
 alert("Preencha corretamente o campo CEP! (00000-000)");
 document.cv.cep1.focus();
 return false;
 }
 }
 xcep2=document.cv.cep2.value;
 if (aux==0) {
 if ((xcep2=="")||(xcep2.length!=3)){
 aux=1;
 alert("Preencha corretamente o campo CEP! (00000-000)");
 document.cv.cep2.focus();
 return false;
 }
 }
 xcidade=document.cv.cidade.value;
 if (aux==0) {
 if (xcidade==""){
 aux=1;
 alert("Preencha o campo CIDADE");
 document.cv.cidade.focus();
 return false;
 }
 }
 xmsg=document.cv.mensagem.value;
 if (aux==0) {
 if (xmsg==""){
 aux=1;
 alert("Preencha o campo DESCRIÇÃO DA EMPRESA");
 document.cv.mensagem.focus();
 return false;
 }
 }
 element1 = document.getElementById('formulario_cadastro').style;
 element2 = document.getElementById('cadastro_enviado').style;
 element1.display='none';
 element2.display='block';
}

//INICIO TESTA FORM CONTATO
function testacampos_contato()
 {
 aux=0;
 xnome=document.cv.nome.value;
 if (aux==0) {
 if (xnome==""){
 aux=1;
 alert("Preencha o campo Seu Nome");
 document.cv.nome.focus();
 return false;
 }
 }
 xtitulo=document.cv.titulo.value;
 if (aux==0) {
 if (xtitulo==""){
 aux=1;
 alert("Preencha o campo Nome da Empresa");
 document.cv.titulo.focus();
 return false;
 }
 }
 xemail=document.cv.email.value;
 if (aux==0) {
 if (xemail==""){
 aux=1;
 alert("Preencha o campo Seu E-mail");
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf("@") < 0){
 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br")
 document.cv.email.focus();
 return false;
 }
 }
 if (aux==0) {
 if (document.cv.email.value.indexOf(".") < 0){

 aux=1;
 alert("Preencha o campo Seu E-mail no formato seu@email.com.br");
 document.cv.email.focus();
 return false;
 }
 }
 xddd=document.cv.ddd1.value;
 if (aux==0) {
 if (xddd==""){
 aux=1;
 alert("Preencha o campo DDD");
 document.cv.ddd1.focus();
 return false;
 }
 }
 xfone=document.cv.telefone1.value;
 if (aux==0) {
 if (xfone==""){
 aux=1;
 alert("Preencha o campo TELEFONE");
 document.cv.telefone1.focus();
 return false;
 }
 }
 xmsg=document.cv.mensagem.value;
 if (aux==0) {
 if (xmsg==""){
 aux=1;
 alert("Preencha o campo MENSAGEM");
 document.cv.mensagem.focus();
 return false;
 }
 }
 element1 = document.getElementById('formulario_contato').style;
 element2 = document.getElementById('contato_enviado').style;
 element1.display='none';
 element2.display='block';
}
//FIM TESTA FORM CONTATO

function exibir_telefone(){
	element1 = document.getElementById('mostra_telefone').style;
	element2 = document.getElementById('show_telefone').style;
	element1.display='none';
	element2.display='block';
}
function exibir_site(){
	element1 = document.getElementById('mostra_site').style;
	element2 = document.getElementById('show_site').style;
	element1.display='none';
	element2.display='block';
}
function conta_click(codigo,tipo){
	abre = window.open('staticlicks.asp?id='+codigo+'&tipo='+tipo, 'iframe_contador')
}
function troca_foto(foto,texto,idf,autf){
	//alert("Entrou na função");
	if(autf==1){
	fecha_produto();
	}
	document.foto_grande.src = "images/anuncios/blank.gif";
	document.foto_grande.src = "images/anuncios/" + foto;
	document.getElementById('texto_legenda_foto').innerHTML = texto;
	element1 = document.getElementById('foto_ampliada').style;
	element1.display='block';
	abre = window.open('staticlicks_anuncio_fotos.asp?id='+idf, 'iframe_contador')
}
function fecha_foto(){
 	element1 = document.getElementById('foto_ampliada').style;
	element1.display='none';
	document.foto_grande.src = "images/anuncios/blank.gif";
}
function mudacor1() {
	element1 = document.getElementById('mensagem_contato').style;
	element1.background='#FFFF00';
}

function insere_orcamento(produto){
	texto_atual = document.cv.mensagem.value;
	aux = texto_atual.indexOf("Gostaria");
	if (aux<0) {
		document.cv.mensagem.value = texto_atual+'Gostaria de um orçamento de 01 unidade do produto '+produto;
		}
		else {
			document.cv.mensagem.value = texto_atual+' + 01 unidade do produto '+produto;
	}
	mudacor1();
}

function troca_produto(foto,texto,idf,autf){
	//alert("Entrou na função");
	if(autf==1){
	fecha_foto();
	}
	document.produto_grande.src = "images/anuncios/blank.gif";
	document.produto_grande.src = "images/produtos/" + foto;
	document.getElementById('texto_legenda_produto').innerHTML = texto;
	element1 = document.getElementById('produto_ampliado').style;
	element1.display='block';
	//abre = window.open('staticlicks_anuncio_produtos.asp?id='+idf, 'iframe_contador')
}
function fecha_produto(){
 	element1 = document.getElementById('produto_ampliado').style;
	element1.display='none';
	document.produto_grande.src = "images/anuncios/blank.gif";
}
//Postar Comentarios, limite de caracteres.
function textCounterDec(aux_campo,aux_label){
	texto = aux_campo.value;
	total = texto.length;
	aux = 1000-total;
	document.getElementById(aux_label).innerHTML = aux;
	if (aux < 0) {
		aux_campo.value = texto.substring(0,1000);
		aux = 0;
		document.getElementById(aux_label).innerHTML = aux;
		//alert("Novo Texto: "+ntext);
	}
}
function CampoNumero(campo)
{
 var lngTecla = window.event.keyCode;
 var strTemp = campo.value;

 if ((strTemp == "") && (lngTecla == 44)) { return false; }
 if ((strTemp != "") && (lngTecla == 46)) { lngTecla=44; window.event.keyCode=44; }
 return ((lngTecla >= 48 && lngTecla <= 57 || lngTecla == 13));
}
tipoDocumento = '';
 function checaDocumento(texto){
 	texto = texto.replace(".", "");
	texto = texto.replace(".", "");
	texto = texto.replace(".", "");
	texto = texto.replace("-", "");
	texto = texto.replace("/", "");
	if(texto.length == 11){
		var cpf = document.cv.cpf;
		if(valida_cpf(texto)){
			cpf.value = texto.substr(0,3)+'.'+texto.substr(3,3)+'.'+texto.substr(6,3)+'-'+texto.substr(9,2);
			var rg = document.cv.rg;
			rg.focus();
			tipoDocumento = 'cpf';
		} else {
			alert('Por favor informe um CPF/CNPJ válido, digite apenas os números.');
			cpf.value = '';
			cpf.focus();
		}
	} else {
		if((texto.length == 14) || (texto.length == 15)){
			var cnpj = document.getElementById('cpf');
			if(valida_cnpj(texto)){
				if(texto.length == 14){
					cnpj.value = texto.substr(0,2)+'.'+texto.substr(2,3)+'.'+texto.substr(5,3)+'/'+texto.substr(8,4)+'-'+texto.substr(12,2);
				} else {
					cnpj.value = texto.substr(0,3)+'.'+texto.substr(3,3)+'.'+texto.substr(6,3)+'/'+texto.substr(9,4)+'-'+texto.substr(13,2);
				}
				var rg = document.getElementById('rg');
				rg.focus();
				tipoDocumento = 'cnpj';
			} else {
				alert('Por favor informe um CPF/CNPJ válido, digite apenas os números.');
				//cpf.value = '';
				document.cv.cpf.value = '';
				//cpf.focus();
				document.cv.cpf.focus();
			}
		} else {
			if(texto!=''){
				alert('Por favor informe um CPF/CNPJ válido, digite apenas os números.');
				//cpf.value = '';
				document.cv.cpf.value = '';
				//cpf.focus();
				document.cv.cpf.focus();
			}
		}
	}
 }
 function valida_cpf(cpf)
 {
	 var numeros, digitos, soma, i, resultado, digitos_iguais;
	 digitos_iguais = 1;
	 if (cpf.length < 11) 
		return false;
	 for (i = 0; i < cpf.length - 1; i++)
		if (cpf.charAt(i) != cpf.charAt(i + 1))
			  {
			  digitos_iguais = 0;
			  break;
			  }
	 if (!digitos_iguais)
		{
		numeros = cpf.substring(0,9);
		digitos = cpf.substring(9);
		soma = 0;
		for (i = 10; i > 1; i--)
			  soma += numeros.charAt(10 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(0))
			  return false;
		numeros = cpf.substring(0,10);
		soma = 0;
		for (i = 11; i > 1; i--)
			  soma += numeros.charAt(11 - i) * i;
		resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
		if (resultado != digitos.charAt(1))
			  return false;
		return true;
		}
	 else
		return false;
 }
 function valida_cnpj(cnpj)
 {
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
 }