// JavaScript Document

function verificaemail(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function ConfereCadastro(pagina)
{
if (!verificaemail(document.formcadastro.email.value))
	{
		alert("EMAIL inválido.");
		document.formcadastro.email.focus();
		return;
	}

	
	// senha
	if (document.formcadastro.senha.value.length < 6)
	{
    	alert('A SENHA deve ter entre 6 e 12 caracteres.');
	    document.formcadastro.senha.focus()
   		return;
	}
	if (document.formcadastro.senha2.value.length = 0)
	{
    	alert('Digite a confirmação da SENHA.');
	    document.formcadastro.senha2.focus()
   		return;
	}
	if (document.formcadastro.senha2.value != document.formcadastro.senha.value)
	{
    	alert('A confirmação da SENHA está incorreta.');
	    document.formcadastro.senha2.value='';
	    document.formcadastro.senha2.focus()
   		return;
	}
	
	// nome
	if (document.formcadastro.nome.value.length < 3)
	{
    	alert('O NOME é obrigatório.');
	    document.formcadastro.nome.focus()
   		return;
	}
	
	// empresa
	if (document.formcadastro.empresa.value.length < 3)
	{
    	alert('A EMPRESA é obrigatório.');
	    document.formcadastro.empresa.focus()
   		return;
	}

	// DIA NASCIMENTO
	if (document.formcadastro.dia_nascimento.value.length < 2)
	{
    	alert('DIA DE NASCIMENTO é obrigatório.');
	    document.formcadastro.dia_nascimento.focus()
   		return;
	}
	// MES NASCIMENTO
	if (document.formcadastro.mes_nascimento.value.length < 2)
	{
    	alert('MES DE NASCIMENTO é obrigatório.');
	    document.formcadastro.mes_nascimento.focus()
   		return;
	}
	// ANO NASCIMENTO
	if (document.formcadastro.ano_nascimento.value.length < 4)
	{
    	alert('ANO DE NASCIMENTO é obrigatório.');
	    document.formcadastro.ano_nascimento.focus()
   		return;
	}
	// TELEFONE FIXO
	if (document.formcadastro.fone_fixo.value.length < 11)
	{
    	alert('TELEFONE FIXO É OBRIGATÓRIO DIGITE-O DA SEGUINTE FORMA 45-5555-3333');
	    document.formcadastro.fone_fixo.focus()
   		return;
	}
		// TELEFONE celular
	if (document.formcadastro.celular.value.length < 11)
	{
    	alert('CELULAR É OBRIGATÓRIO DIGITE-O DA SEGUINTE FORMA 45-9999-3333');
	    document.formcadastro.celular.focus()
   		return;
	}

	// endereço
	if (document.formcadastro.endereco.value.length < 3)
	{
    	alert('Digite o ENDEREÇO corretamente.');
	    document.formcadastro.endereco.focus()
   		return;
	}
	
	// numero 
	if (document.formcadastro.numero.value.length < 1)
	{
    	alert('Digite o NÚMERO corretamente.');
	    document.formcadastro.numero.focus()
   		return;
	}
	// bairro 
	if (document.formcadastro.bairro.value.length < 5)
	{
    	alert('Digite o BAIRRO corretamente.');
	    document.formcadastro.bairro.focus()
   		return;
	}
	// CIDADE 
	if (document.formcadastro.cidade.value.length < 5)
	{
    	alert('Digite o CIDADE corretamente.');
	    document.formcadastro.cidade.focus()
   		return;
	}
	// ESTADO 
	if (document.formcadastro.estado.value =="x")
	{
    	alert('SELECIONE O ESTADO ESTADO.');
	    document.formcadastro.estado.focus()
   		return;
	}
	// PAIS 
	if (document.formcadastro.pais.value.length < 5)
	{
    	alert('Digite o PAÍS.');
	    document.formcadastro.pais.focus()
   		return;
	}
	

	// email
	if (document.formcadastro.email.value.length < 7)
	{
    	alert('Digite corretamente seu EMAIL.');
	    document.formcadastro.email.focus()
   		return;
	}

	document.formcadastro.action=pagina;
	document.formcadastro.submit();
}


//#################################################################################################################
//LIST CATEGORIAS E SUB CATEGORIAS
//#################################################################################################################
function ajaxInit() {

  var xmlhttp;

  try {
     xmlhttp = new XMLHttpRequest();
  } catch(ee) {
     try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch(e) {
        try {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(E) {
           xmlhttp = false;
        }
     }
  }

  return xmlhttp;
	}
function getCidades() {

  sEstado = document.getElementById("estado").value;
  ajax = ajaxInit();
  
  if (ajax) {
     ajax.open("GET", "categorias.php?cat=" + sEstado, true);
     ajax.onreadystatechange = function () {
        if (ajax.readyState == 4) {
           if (ajax.status == 200) {
              document.getElementById('cidades').innerHTML = ajax.responseText;
           } else {
              alert(ajax.statusText);
           }
        }
     }
     ajax.send(null);
  }
  
}


function getSubcategorias() {

  sEstado = document.getElementById("estado").value;
  ajax = ajaxInit();
  
  if (ajax) {
     ajax.open("GET", "subcategorias.php?cat=" + sEstado, true);
     ajax.onreadystatechange = function () {
        if (ajax.readyState == 4) {
           if (ajax.status == 200) {
              document.getElementById('cidades').innerHTML = ajax.responseText;
           } else {
              alert(ajax.statusText);
           }
        }
     }
     ajax.send(null);
  }
  
}


//########################################
//VALIDA PESQUISA DETALHADA HOME
//########################################
function validaPESQUISATOPO() {
var estado=document.formpesquisatopo.estado.value; // CATEGORIA PRINCIPAL
var procurado=document.formpesquisatopo.procurado.value; // NOME DO PRODUTO

if (estado=="x") {
window.alert("SELECIONE UMA CATEGORIA E POISTERIOR UMA SUBCATEGORIA");
document.formpesquisatopo.estado.focus();
return false;
}

if (procurado=="") {
window.alert("DIGITE O NOME DO PRODUTO QUE ESTA BUSCANDO");
document.formpesquisatopo.procurado.focus();
return false;
} 

return true;
document.formpesquisatopo.submit();
}

//########################################################
//VALIDA FORM DE CONTATO
//########################################################


function ConfereContato(pagina)
{
if (!verificaemail(document.formcontato.email.value))
	{
		alert("EMAIL inválido.");
		document.formcontato.email.focus();
		return;
	}

		
	// nome
	if (document.formcontato.nome.value.length < 3)
	{
    	alert('O NOME é obrigatório.');
	    document.formcontato.nome.focus()
   		return;
	}
		
	// email
	if (document.formcontato.email.value.length < 7)
	{
    	alert('Digite corretamente seu EMAIL.');
	    document.formcontato.email.focus()
   		return;
	}
	
	//mensagem	
	if (document.formcontato.mensagem.value.length < 10)
	{
    	alert('O MENSAGEM é obrigatório OU contem menos que 10 caracteres.');
	    document.formcontato.mensagem.focus()
   		return;
	}

	document.formcontato.action=pagina;
	document.formcontato.submit();
}

//#########################################################################
//AUMENTA FONTE
//#########################################################################

function sizeFont (elem, acao){    
// tamanho inicial da fonte (em px)    
var tamInic = 13;    
// Tamanho mínimo da [b]fonte (em px)    
var tamMin = 10;    
// Tamanho máximo da fonte (em px)    
var tamMax = 20;    
// Pega o tamanho da fonte. Se não foi setada ainda (primeira vez que a função é executada) terá como tamanho padrão 'tamInic'.   
 if (document.getElementById(elem).style.fontSize == "") { 
 	var tamFonte = tamInic;    
	} else {
	var tamFonte = parseInt(document.getElementById(elem).style.fontSize);      
	} switch (acao){  
	// Aumenta o tamanho, enquanto foi menor que 'tamMax'                
	case '+':   
		 if (tamFonte < tamMax) 
		 	document.getElementById(elem).style.fontSize = (tamFonte + 2) + "px";
			break;               
	// Diminui o tamanbo, enquanto for maior que 'tamMin'               
	 case '-':  
	     if (tamFonte > tamMin)
		 	document.getElementById(elem).style.fontSize = (tamFonte - 2) + "px";   
			break; 
	}
}