function isNumeric(tamanho,valor){
  var digits="0123456789"
  var temp
  for (var i=0;i<tamanho;i++){
	  temp=valor.substring(i,i+1)
	  if (digits.indexOf(temp)==-1){
		  return false;
	  }
  }		  			  
  return true;
}



/************************************************
* function ValidaRadioBox
* Verifica se foi selecionado a Filial
* Input: O campo do formulário, mensagem
************************************************/
function ValidaRadio(btRadio,NomeBotao){
	var contBt = btRadio.length-1;
	var i =0;
	var btChecado = false;
	while (i<=contBt && !btChecado) {
		if (btRadio[i].checked)
			btChecado = true
		i++;
	}
	if (!btChecado)
		alert('Selecione ' + NomeBotao)
	return btChecado;
}

// #############################
// ##### VALIDAÇÃO DE DATA #####
// #############################
var diasMes = new Array(12);
diasMes[1] = 31;
diasMes[2] = 29;
diasMes[3] = 31;
diasMes[4] = 30;
diasMes[5] = 31;
diasMes[6] = 30;
diasMes[7] = 31;
diasMes[8] = 31;
diasMes[9] = 30;
diasMes[10] = 31;
diasMes[11] = 30;
diasMes[12] = 31;

function diasFevereiro (ano) {  
    return ( ((ano % 4 == 0) && ( (!(ano % 100 == 0)) || (ano % 400 == 0) ) ) ? 29 : 28 );
}

function dataValida(data) {
  var i;  
  if ((barra1 = data.value.indexOf('/')) < 1) {
	data.focus();
	alert('Data inválida');
  	return false;
  }
  if ((barra2 = data.value.substring(barra1+1, data.value.length).indexOf('/')) < 1) {
	data.focus();
	alert('Data inválida');
  	return false;
  }
  if (barra2+barra1+1 != data.value.lastIndexOf('/')) {
	data.focus();
	alert('Data inválida');
  	return false;
  }
  dia = data.value.substring(0,barra1);
  mes = data.value.substring(barra1+1, barra2+barra1+1);
  ano = data.value.substring(barra2+barra1+2, data.value.length);
  var dataTemp = dia + mes + ano;
  for (i = 0; i < dataTemp.length; i++) {   
        var ch = dataTemp.charAt(i);
        if ((ch < "0" || ch > "9")) {
			data.focus();
			alert('Data inválida');
		  	return false;
		}
  }
  if ((mes == 2) && (dia > diasFevereiro(ano))) {
	data.focus();
	alert('Data inválida');
  	return false;
  }
  if ((dia>diasMes[parseFloat(mes)]) || (dia<1) || (mes<1) || (mes>12) || (ano<1900) || (ano>2078)) {
	data.focus();
	alert('Data inválida');
  	return false;
  }
  return true;
}


/************************************************
* function ValidaData
* Verifica se a data foi digitada corretamente
* Input: Data a ser verificado
************************************************/
function ValidaData (data, AnoMin, AnoMax){
	var datacomposta = data;
	var dia="";
	var mes="";
	var ano="";
	var caractervalidos="1234567890/. ";
	var c=0;
	var i=0;
	var p=0;
	var cont=1;
	var verifica=0;
	var validadata=true;
	var checkOK = "0123456789/";
	var checkStr = datacomposta;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
   		for (j = 0;  j < checkOK.length;  j++)
     		if (ch == checkOK.charAt(j))
       			break;
   		if (j == checkOK.length){
			allValid = false;
     		break;
		}
		allNum += ch;
	}
	if(!allValid){
		alert("Por favor entre com a data no formato DD/MM/AAAA .");
		return (false);
	}
	for(c; c<datacomposta.length; c++){
		if ( caractervalidos.indexOf(datacomposta.charAt(c)) == -1 ) {
   			alert("Caracteres invalidos na Data.");
    		return (false);
		} 
	}
	for(c=0;c<datacomposta.length;c++){
    	if(datacomposta.charAt(c)=="/"){
        	verifica++;
		}
        if (datacomposta.charAt(c)=="."){
        	verifica++;
		}
	}
	if (verifica!=2){
		alert("Numero de separadores errados na Data.");
        return (false);
	}
	for (i=0;i< datacomposta.length;i++){
    	if ((datacomposta.charAt(i)=="/")||(datacomposta.charAt(i)==".")){
        	break;
		}else {   
			dia=dia+datacomposta.charAt(i);
        } // end if
	} // end for
	i++;
    for (i;i< datacomposta.length;i++){
    	if ((datacomposta.charAt(i)=="/")||(datacomposta.charAt(i)==".")){
        	break;
		} else {        
        	mes=mes+datacomposta.charAt(i);
		} // end if
	} // end for

	if((mes<=0)||(mes>12)){
		alert("Mes invalido na Data.");
    	return (false);
	} // end if 
	if (mes==1){
    	if (dia>31){
			alert("Dia invalido na Data.");
	        return (false);
		} // end if
	} // end if
    if (mes==2){
    	if (dia>29){
			alert("Dia invalido na Data.");
	        return (false);
		} // end if
	} // end if
    if (mes==3){
    	if (dia>31){
			alert("Dia invalido na Data.");
	        return (false);
		} // end if
			} // end if
                        
        if (mes==4){
            if (dia>30){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if
                        
        if (mes==5){
            if (dia>31){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if
                        
        if (mes==6){
            if (dia>30){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

                                
        if (mes==7){
            if (dia>31){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

            
        if (mes==8){
            if (dia>31){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

                                
        if (mes==9){
        	if (dia>30){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

                        
        if (mes==10){
        	if (dia>31){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

                                                                        
        if (mes==11){
        	if (dia>30){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

                        
        if (mes==12){
        	if (dia>31){
		    	alert("Dia invalido na Data.");
	            return (false);
				} // end if
			} // end if

//******************compoe variavel ano**********************************               
        i++;
        for(i;i<datacomposta.length;i++){
        	if(datacomposta==""){
            	break;
			}
			else {
            	ano=ano+datacomposta.charAt(i);
			} // end if
		} // end for

//****************testa validade da variavel ano*************************                                                       
        if ((ano.length!=2)&(ano.length!=4)){
	    	alert("Ano invalido na Data.");
	        return (false);
		} // end if
			            
        if (ano.length==2){
        	if (ano == 0) {
				ano = 2000;
			} else {
				ano = 19 + ano ;
			} // end if
		} // end if

			            
       	if (ano<AnoMin){
	    	alert("Aceita apenas Data acima de " + AnoMin);
	        return (false);
		}
       	if (ano>AnoMax){
	    	alert("Aceita apenas Data abaixo de " + AnoMax);
	        return (false);
		}

//*********************** retorno padrao **************                         

return (true);
				
}           

function VerificaEmail(mail) {
    //declaracao das variaveis
	var user="";
	var dominio="";
	var i=0;
	var testa="+)(*&%$#!+;='\/`~?<>"; 
	var c=0;
	var checkmail=true;
	var ponto=0;
	var j=0;
	var arroba=0;
	

	//***********testa caracteres invalidos na variavel mail**********
	for(c;c<mail.length;c++){
		for (j=0; j<testa.length;j++){
			if (testa.charAt(j)==mail.charAt(c)){
				checkmail=false;
				alert ("Caracteres invalidos no e-mail");
				return (false);
				}
			}
		}		
	//************ cria variavel user******************************* 
	if (checkmail!=false){
			for (i=0;i< mail.length;i++){
				if (mail.charAt(i)=="@"){
					break;}
				else{	
					user=user+mail.charAt(i);
					}
				}
	
			//************cria variavel dominio**************************
			for (i;i<mail.length;i++){
				if (mail.charAt(i)==""){
					break;}
				else{	
					dominio=dominio+mail.charAt(i);
					}
				}
					
				//***********testa validade da variavel dominio********************		
				for(c=0;c<dominio.length;c++){
					if (dominio.charAt(c)=="@"){
						arroba++;}
					if (dominio.charAt(c)=="."){
						ponto++;}}
					if ((ponto<1)||(ponto>4)){
						alert("Erro no dominio do e-mail");
						return (false);
						}
					if (arroba != 1.0){
						alert("Erro no dominio do e-mail");
						return (false);
						};
				}			
	return (true);		
}

     
function ValidaObrigatorio(campo,nome_campo,tamanho,minimo) {
if (campo.value.length == 0){
	alert("Informe o campo  " + nome_campo);
	campo.focus();
	campo.select();
	return false;
	}
else if(tamanho>0){
		if(campo.value.length < tamanho){
	//	alert (minimo);
			if (minimo>0){
			//alert ("OK1");
				alert("O campo " + nome_campo + " deve ter pelo menos "+tamanho+" caracteres");
			}
			else{
			//alert ("OK2");
				alert("O campo " + nome_campo + " deve ter "+tamanho+" caracteres");
			campo.focus();
			campo.select();
			return false;
			}
		}
		else return true;
	}
	else return true;
}

function ValidaObrigatorioEsp(campo,nome_campo,tamanho,minimo) {
if (campo.value.length == 0){
	alert("Hencha el  " + nome_campo);
	campo.focus();
	campo.select();
	return false;
	}
else if(tamanho>0){
		if(campo.value.length < tamanho){
	//	alert (minimo);
			if (minimo>0){
			//alert ("OK1");
				alert("El " + nome_campo + " deve ter pelo menos "+tamanho+" caracteres");
			}
			else{
			//alert ("OK2");
				alert("El " + nome_campo + " deve ter "+tamanho+" caracteres");
			campo.focus();
			campo.select();
			return false;
			}
		}
		else return true;
	}
	else return true;
}


function TrocaAction(theForm){
	//alert("TrocaAction");
	if (theForm.sistema.value != ''){
		if (theForm.sistema.value.substr(3,3) == 'cad'){
			//alert("incinclusao");
			theForm.action = "include/incinclusao.asp";
		}
		else if (theForm.sistema.value.substr(3,3) == 'upl'){
			//alert("incalteracao");
			theForm.action = "include/incuplarquivo.asp";
		}
		else if (theForm.sistema.value.substr(3,3) == 'edt'){
			//alert("incalteracao");
			theForm.action = "include/incalteracao.asp";
		}
		else if (theForm.sistema.value.substr(3,3) == 'log'){
			//alert("verificalogin");
			if (theForm.tipo.value == 'adm') {
				theForm.action = "include/verificalogin.asp?tipo=adm";
			}
			else if (theForm.tipo.value == 'con') {
				theForm.action = "include/verificalogin.asp?tipo=con";
			}
		}
	}
}

//FALE CONOSCO
function ValidaFConosco(theForm){
//   if  (theForm.tema[theForm.tema.selectedIndex].value == "0") {
//		alert("Selecione um Assunto.");
//		theForm.tema.focus();
//		return false;	
//	}		
	if  (theForm.idAssunto.value == "0") {
 		alert("Selecione um Assunto.");
		theForm.idAssunto.focus();
		return false;	
	}

	if (!ValidaObrigatorio(theForm.nome,"Nome","4","250")){
	  	theForm.nome.focus();
	    return false;	  
	  }

	if (!ValidaObrigatorio(theForm.email,"E-mail","4","70")){
	  	theForm.email.focus();
	    return false;	  
	  }	  
	  
	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	}
	
	if (!ValidaObrigatorio(theForm.endereco,"Endereco","4","250")){
	  	theForm.endereco.focus();
	    return false;	  
	  }
	  if (!ValidaObrigatorio(theForm.bairro,"Bairro","4","250")){
	  	theForm.bairro.focus();
	    return false;	  
	  }
	  if (!ValidaObrigatorio(theForm.cidade,"Cidade","2","250")){
	  	theForm.cidade.focus();
	    return false;	  
	  }

	if (!ValidaObrigatorio(theForm.telefone,"Telefone","4","250")){
	  	theForm.telefone.focus();
	    return false;	  
	}
	
	if (!ValidaObrigatorio(theForm.fale,"Mensagem","0","200")){
	  	theForm.fale.focus();
	    return false;	  
	}
	  
	/*if (!ValidaObrigatorio(theForm.Pais,"País","4","250")){
	  	theForm.Pais.focus();
	    return false;	  
	}*/

	desabilitaBotao("btnEnviar", "Aguarde");
	return true;

}

//FALE CONOSCO ESPANHOL
function ValidaFConoscoEsp(theForm){

   if  ( (theForm.tema[theForm.tema.selectedIndex].value == "0") ||
   		 (theForm.tema[theForm.tema.selectedIndex].value == "") ){
		alert("Seleccione el Tema.");
		theForm.tema.focus();
		return false;	
	}		

	if (!ValidaObrigatorioEsp(theForm.nome,"Nombre","4","250")){
	  	theForm.nome.focus();
	    return false;	  
	  }
/*
	if (!ValidaObrigatorioEsp(theForm.email,"E-mail","4","70")){
	  	theForm.email.focus();
	    return false;	  
	  }	  
	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	}
	
	if (!ValidaObrigatorioEsp(theForm.fale,"Fale","0","200")){
	  	theForm.fale.focus();
	    return false;	  
	  }	  	  
*/	  
	if (!ValidaObrigatorioEsp(theForm.endereco,"Dirección","4","250")){
	  	theForm.endereco.focus();
	    return false;	  
	  }
	  if (!ValidaObrigatorioEsp(theForm.bairro,"Barrio","4","250")){
	  	theForm.bairro.focus();
	    return false;	  
	  }
	  if (!ValidaObrigatorioEsp(theForm.cidade,"Ciudad","2","250")){
	  	theForm.cidade.focus();
	    return false;	  
	  }
/*
	 if  (theForm.tema[theForm.estado.selectedIndex].value == "0") {
		alert("Selecione um Estado.");
		theForm.estado.focus();
		return false;	
	} 
*/
	if (!ValidaObrigatorioEsp(theForm.telefone,"Teléfono","4","250")){
	  	theForm.telefone.focus();
	    return false;	  
	  }
	  if (!ValidaObrigatorioEsp(theForm.Pais,"País","4","250")){
	  	theForm.Pais.focus();
	    return false;	  
	  }	  
}


//CATEGORIA
function ValidaCategoria(theForm)
	{
	if (!ValidaObrigatorio(theForm.categoria,"Categoria","3","50"))
	{
		theForm.categoria.focus();
		return (false);
	}
		TrocaAction(theForm);
}

function ValidaEdicao(theForm){
	if (ValidaObrigatorio(theForm.edicao,"Edição","1","50")){
		if (!isNumeric(5,theForm.edicao.value)) {
			alert("Campo Edição não pode conter letras.");
			theForm.edicao.focus();
			return (false);
		}
	}
	else{
		theForm.edicao.focus();
		return (false);
	}
	TrocaAction(theForm);
}


//LOGIN
function ValidaLogin(theForm){

	if (!ValidaObrigatorio(theForm.login,"Login","4","0")){
		theForm.login.focus();
		return false;
	}
	if (!ValidaObrigatorio(theForm.senha,"Senha","4","4")){
		theForm.senha.focus();
		return false;
	}
 	TrocaAction(theForm);	
}

//NOTICIA
function ValidaNoticia(theForm){
	if (!ValidaObrigatorio(theForm.titulo,"Título","10","250")){
	  	theForm.titulo.focus();
	    return false;	  
	  }

	if (!ValidaObrigatorio(theForm.resumo,"Resumo","10","500"))	{
	  	theForm.resumo.focus();
		return false;
	  }		
		  
	if (!ValidaObrigatorio(theForm.texto,"Texto","10","0"))	{
	  	theForm.texto.focus();
		return false;
	  }		
		  
    TrocaAction(theForm);
}


//COMMODITY
function ValidaCommodity(theForm){

	if (!ValidaObrigatorio(theForm.titulo,"Título","10","250")){
	  	theForm.titulo.focus();
	    return false;	  
	  }

    if (!ValidaData(theForm.data.value, 1901, 2100)) {
		theForm.data.focus();
		return false;
	  } 	
		  
	if (!ValidaObrigatorio(theForm.texto,"Texto","10","0"))	{
	  	theForm.texto.focus();
		return false;
	  }		
    TrocaAction(theForm);
}

// REPRESENTANTE
function ValidaRepresentante(theForm){
	 if (!ValidaObrigatorio(theForm.representante,"Representante","5","250")){
	  	theForm.representante.focus();
	    return false;	  
	  }
	 if (!ValidaObrigatorio(theForm.descritivo,"Descritivo","10","200")){
	  	theForm.descritivo.focus();
	    return false;	  
	  }
	 if (!ValidaObrigatorio(theForm.endereco,"Endereço","10","250")){
	  	theForm.endereco.focus();
	    return false;	  
	  }
 	 if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	 }	
	 if (!ValidaObrigatorio(theForm.fone,"Fone","7","15")){
	  	theForm.fone.focus();
	    return false;	  
	  }
	 if (!ValidaObrigatorio(theForm.cep,"Cep","8","10")){
	  	theForm.cep.focus();
	    return false;	  
	  }
	TrocaAction(theForm);	
}

// RELEASE
function ValidaRelease(theForm){
	  if (!ValidaObrigatorio(theForm.resumo,"Resumo","10","10000")){
	  	theForm.resumo.focus();
	    return false;	  
	  }
	  /*if(theForm.resumo.value.length > 1000){
		alert('Campo Resumo não pode ter mais de 1000 caracteres.');
		theForm.resumo.focus();
	    return false;	  
	  
	  }*/
	 if (!ValidaObrigatorio(theForm.titulo,"Título","10","250")){
	  	theForm.titulo.focus();
	    return false;	  
	  }
	 
	 if (!ValidaData(theForm.data.value, 1901, 2100)) {
		theForm.data.focus();
		return false;
	  } 	
	 
	TrocaAction(theForm);
}

// CAMPOABERTO  jaka
function ValidaCampoAberto(theForm){
	if (!ValidaObrigatorio(theForm.titulo,"Título","2","250")){
		theForm.titulo.focus();
		return false;	  
	}
	if (!ValidaObrigatorio(theForm.resumo,"Resumo","10","1000")){
		theForm.resumo.focus();
		return false;
	}
	if (!ValidaObrigatorio(theForm.texto,"Texto","10","5000")){
		theForm.texto.focus();
		return false;	  
	}
	if ((theForm.idAssunto.value == 0) && (theForm.outroassunto.value.length == 0)){
		alert("Escolha um Assunto entre os assuntos cadastrados ou preencha um novo assunto no campo Outro Assunto.");
		theForm.outroassunto.focus();
		return false;
	}
	/*
	if (!ValidaObrigatorio(theForm.descimagem,"DescImagem","10","1000")){
		theForm.descimagem.focus();
		return false;	  
	}
	*/
	TrocaAction(theForm);	
}


// PEÇAS
function ValidaPecas(theForm)
{
	 if (!ValidaObrigatorio(theForm.nome,"Nome","5","30")){
	  	theForm.nome.focus();
	    return false;	  
	  }
	 if (!ValidaObrigatorio(theForm.descritivo,"Descritivo","10","250")){
	  	theForm.descritivo.focus();
	    return false;	  
	  }
	/*
	 if (!ValidaObrigatorio(theForm.preco,"Preco","3","9")){
	  	theForm.preco.focus();
	    return false;	  
	  }
	 */

	TrocaAction(theForm);	
}

function ValidaCadastro(theForm){

	if(!ValidaObrigatorio(theForm.nome,"Nome","","60")){
		theForm.nome.focus();
		return false;		
	}
	
	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	
	}
	if (!ValidaData(theForm.dtnascimento.value, 1901, 2100)) {
		  	theForm.dtnascimento.focus();
			return (false);
	} 
		  
	if(!ValidaObrigatorio(theForm.logradouro,"Logradouro","","5")){
		theForm.logradouro.focus();
		return false;		
	}

	if(!ValidaObrigatorio(theForm.numero,"Número","","1")){
		theForm.numero.focus();
		return false;		
	}

//	if(!ValidaObrigatorio(theForm.complemento,"Complemento","","5")){
//		theForm.complemento.focus();
//		return false;		
//	}

	if(!ValidaObrigatorio(theForm.cidade,"Cidade","","3")){
		theForm.cidade.focus();
		return false;		
	}

    if  (theForm.estado[theForm.estado.selectedIndex].value == "") {
		alert("Selecione um Estado.");
		theForm.estado.focus();
		return false;	
	}		

    if  (theForm.atividade[theForm.atividade.selectedIndex].value == "0") {
		alert("Selecione uma Atividade.");
		theForm.atividade.focus();
		return false;	
	}		
    
	if (theForm.status.value == "c") { 
  	   if  (theForm.fazenda[0].checked == false && theForm.fazenda[1].checked == false) {
		   alert("Selecione Sim se você possui uma fazenda, ou Não se não possui.");
		   theForm.fazenda[1].checked=true;
		   return false;
	   }
	}

	TrocaAction(theForm);	
	return true;
}


//UPLOAD Simples
function ValidaUplSimples(theForm){
	if ((theForm.tbsistema.value != "servico") || (theForm.tbsistema.value != "noticia") || (theForm.tbsistema.value != "oferta") ) {
		if (!ValidaObrigatorio(theForm.arquivoupl,"Arquivo","3","300")){
			theForm.arquivoupl.focus();
			return (false);
		}
	}
 TrocaAction(theForm);
}


//Valida Usuário
function ValidaUsuario(theForm){
	if(!ValidaObrigatorio(theForm.nome,"Nome","5","50")){
		theForm.nome.focus();
		return false;		
		}

	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
		}

	if(!ValidaObrigatorio(theForm.login,"Login","4","10")){
		theForm.login.focus();
		return false;		
		}

	if(!ValidaObrigatorio(theForm.senha,"Senha","4","8")){
		theForm.senha.focus();
		return false;		
		}
	if(!ValidaObrigatorio(theForm.senhac,"Confirmação de Senha","4","8")){
		theForm.senhac.focus();
		return false;		
	}	
	if(theForm.senha.value != theForm.senhac.value)
	{
		alert("As senha digitadas não conferem!")
		theForm.senhac.focus();
		return(false);
	}			
	
	 TrocaAction(theForm);
}

//UPLOAD Multipla
function ValidaUplMultipla(theForm){
	if (theForm.tipoacao.value != "e" ) {
		if (!ValidaObrigatorio(theForm.arquivoupl1,"Arquivo","3","300")){
			theForm.arquivoupl1.focus();
			return (false);
		}
 	 }

	if (theForm.tipoacao.value == "e" ) {
		if ((theForm.arquivoupl1.value.length == 0) && (theForm.arquivoupl2.value.length == 0)  && (theForm.arquivoupl3.value.length == 0) && (theForm.arquivoupl4.value.length == 0) )
		  {
			alert("Preencha o campo foto!");
			return (false);
		}
 	 }

 TrocaAction(theForm);
}



function ValidaPropriedade(theForm){
	TrocaAction(theForm);	
	return true;
}

function ValidaAreaInteresse(theForm){
	TrocaAction(theForm);	
	return true;
}

// VALIDA CIDADE

function ValidaCidade(theForm){

if (!ValidaObrigatorio(theForm.cidade,"Cidade","","","40")){
		theForm.cidade.focus();
		return false;	
	}
if  (theForm.estado[theForm.estado.selectedIndex].value == "0") {
		alert("Escolha um Estado");
		theForm.estado.focus();
		return false;
	}	
	TrocaAction(theForm);	
	return true;
}


//Produtos
function ValidaProduto(theForm){

	if (!ValidaObrigatorio(theForm.modelo,"Modelo","5","70")){
	  	theForm.modelo.focus();
	    return false;	  
	  }
    TrocaAction(theForm);
}


// RELEASE
function ValidaVersao(theForm){

	 if (!ValidaObrigatorio(theForm.versao,"Versão","3","50")){
	  	theForm.versao.focus();
	    return false;	  
	  }
	TrocaAction(theForm);	
}

// VALIDA EVENTO
function ValidaEvento(theForm){
   
    if (theForm.descritivo.value==0){
		alert ("O campo descrição deve ser preenchido");
		theForm.descritivo.focus();
		return false;
	}
	
    if (theForm.descritivo.value.length > 300){
		alert ("O campo descrição deve ser menor que 300 caracteres!");
		theForm.descritivo.focus();
		return false;
	}
	
//	if (!ValidaObrigatorio(theForm.descritivo, "Descritivo", "10", "200")) {
//	  } 	
		
	if (!ValidaData(theForm.datainicial.value,1900,2100)){
		    theForm.datainicial.select();
			return false;
	}
	
	if (theForm.datafinal.length != 0)
	{
		/* Data final*/
			dtfinal = theForm.datafinal.value.split("/");
			datafinal = new Date (dtfinal[1] + "/" + dtfinal[0] + "/" + dtfinal[2]);
	
		/* Data Inicial*/
			dtinicial = theForm.datainicial.value.split("/");
			datainicial = new Date (dtinicial[1] + "/" + dtinicial[0] + "/" + dtinicial[2]);
			
		if (!ValidaData(theForm.datafinal.value,1900,2100)){
		    theForm.datafinal.select();
			return false;
		}		
		
		if (datainicial > datafinal){
		   alert("A data final do evento não pode ser anterior a " +  theForm.datainicial.value + ", a data final do evento. ");
		   theForm.datafinal.select();
		   return(false);
		}
	}
	
	if (!ValidaObrigatorio(theForm.nome,"Nome do Evento","","200")){
		theForm.nome.focus();
		return false;	
	}
	TrocaAction(theForm);	
}



//Inclusao de servicos (concessionarias)
function ValidaServico(theForm){
	 if (!ValidaObrigatorio(theForm.nome,"Nome","5","100")){
	  	theForm.nome.focus();
	    return false;	  
	  }
	 if (!ValidaObrigatorio(theForm.descritivo, "Descritivo", "10", "200")) {
		theForm.descritivo.focus();
		return false;
	  } 	
	TrocaAction(theForm);	
}

//Inclusao de contato (concessionarias)
function ValidaContato(theForm){
	if (!ValidaObrigatorio(theForm.depto,"Departamento","5","50")){
		theForm.depto.focus();
		return false;	  
	}
	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	}
	TrocaAction(theForm);	
}

function confereData(data){
	var dia, mes, ano
	var valorData = data.value;
	if(valorData.length < 10){
		alert("A data deve ser no formato dd/mm/aaaa.");
		data.focus();
		return false;
	}else{
		dia = parseInt(valorData.substring(0,2));
		mes = valorData.substring(3,5)-1;
		ano = parseInt(valorData.substring(6));
		var objData = new Date(ano, mes, dia);
		if(objData.getMonth() != mes){
			alert("Esta data não é válida.");
			data.focus();			
			return false;
		}
	}
	return true;
}

//Inclusao de aniversariante
function ValidaAniversario(theForm){
	if (theForm.nome.value.length == 0){
		alert("Entre com o nome do aniversariante.");
		theForm.nome.focus();
		return false;	  
	}
	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
	}
	if(!confereData(theForm.dtNascimento))
		return false;
}

function ValidaImportacao(theForm){
	var extensao
	if (theForm.lista.value.length == 0){
		alert("Você deve selecionar o arquivo com a lista de aniversariantes.");
		theForm.lista.focus();
		return false;
	}else{
		extensao = theForm.lista.value;
		extensao = extensao.substring(extensao.lastIndexOf(".")+1).toUpperCase();
		if(extensao != "TXT" && extensao != "CSV"){
			alert("A lista deve estar no formato TXT ou CSV.");
			theForm.lista.focus();
			return false;
		}
	}
}


//Inclusao de servicos (concessionarias)
function ValidaLink(theForm){
	 if (!ValidaObrigatorio(theForm.descritivo, "Descrição", "5", "60")) {
		theForm.descritivo.focus();
		return false;
	  } 
	 if (!ValidaObrigatorio(theForm.linke,"Link","5","50")){
	  	theForm.linke.focus();
	    return false;	  
	  }
	
	TrocaAction(theForm);	
}

//Inclusao de ofertas (concessionarias)
function Validaoferta(theForm){
	 if (!ValidaObrigatorio(theForm.nome, "Nome", "5", "30")) {
		theForm.nome.focus();
		return false;
	  } 

	 if (!ValidaObrigatorio(theForm.descritivo, "Descrição", "5", "200")) {
		theForm.descritivo.focus();
		return false;
	  } 
	  /*
	 if (!ValidaObrigatorio(theForm.preco,"Preço","4","9")){
	  	theForm.preco.focus();
	    return false;	  
	  }
	  */
	
	TrocaAction(theForm);	
}

//Inclusao de Categoria de produtos
function ValidaTipoProduto(theForm){
	 if (!ValidaObrigatorio(theForm.tipopor, "Tipo", "5", "30")) {
		theForm.tipopor.focus();
		return false;
	  } 

	 if (!ValidaObrigatorio(theForm.textopor,"Texto","5","80000")){
	  	theForm.textopor.focus();
	    return false;	  
	  }
	
	TrocaAction(theForm);	
}


//Inclusao de empresas (Massey)
function ValidaEmpresa1(theForm){
	
	 if (!ValidaObrigatorio(theForm.idmassey,"Código massey","1","20")){
	  	theForm.idmassey.focus();
	    return false;	  
	  }
	  
	 if (!ValidaObrigatorio(theForm.nome,"Nome","5","200")){
	  	theForm.nome.focus();
	    return false;	  
	  }

	 if (!ValidaObrigatorio(theForm.nomefantasia,"Nome Fantasia","5","200")){
	  	theForm.nomefantasia.focus();
	    return false;	  
	  }

	if (!ValidaObrigatorio(theForm.email,"Email","5","40")){
	  	theForm.email.focus();
	    return false;	  
	  }

	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
		}	
	 if (!ValidaObrigatorio(theForm.endereco,"Endereço","5","50")){
	  	theForm.endereco.focus();
	    return false;	  
	  }

	// if (!ValidaObrigatorio(theForm.cep,"Cep","8","10")){
	//  	theForm.cep.focus();
	//    return false;	  
	//  }
	// if (!ValidaObrigatorio(theForm.bairro,"Bairro","4","40")){
	//  	theForm.bairro.focus();
	//    return false;	  
	//  }
	//  if (!ValidaObrigatorio(theForm.fone1,"Fone1","7","300")){
	//  	theForm.fone1.focus();
	//    return false;	  
	//  }
	
	
	TrocaAction(theForm);	
}



//Inclusao de empresas (concessionarias)
function ValidaEmpresa(theForm){
	
		 if (theForm.senha.value != theForm.senhac.value)
		 {
			alert("As senha digitadas não conferem!")	
			theForm.senha.focus();
			return false;
		  } 

	
	if (!ValidaObrigatorio(theForm.email,"Email","5","40")){
	  	theForm.email.focus();
	    return false;	  
	  }

	if(!VerificaEmail(theForm.email.value)){
		theForm.email.focus();
		return false;
		}	
	  
	 if (!ValidaObrigatorio(theForm.nome,"Nome","5","200")){
	  	theForm.nome.focus();
	    return false;	  
	  }

	 if (!ValidaObrigatorio(theForm.nomefantasia,"Nome Fantasia","5","200")){
	  	theForm.nomefantasia.focus();
	    return false;	  
	  }
	
	 if (!ValidaObrigatorio(theForm.endereco,"Endereço","5","50")){
	  	theForm.endereco.focus();
	    return false;	  
	  }
	
	 if (!ValidaObrigatorio(theForm.nomefantasia,"Nome Fantasia","5","200")){
	  	theForm.nomefantasia.focus();
	    return false;	  
	  }

	 if (!ValidaObrigatorio(theForm.texto,"Texto","5","1000")){
		  	theForm.texto.focus();
		    return false;	  
		  }

	// if (!ValidaObrigatorio(theForm.cep,"Cep","8","10")){
	//  	theForm.cep.focus();
	//    return false;	  
	//  }
	
	// if (!ValidaObrigatorio(theForm.bairro,"Bairro","4","40")){
	//  	theForm.bairro.focus();
	//    return false;	  
	//  }
	
	//  if (!ValidaObrigatorio(theForm.fone1,"Fone1","7","300")){
	//  	theForm.fone1.focus();
	//    return false;	  
	//  }

	  if (!ValidaObrigatorio(theForm.login,"Login","2","10")){
		  	theForm.login.focus();
		    return false;	  
	  }
	  if (!ValidaObrigatorio(theForm.senha,"Senha","2","8")){
		  	theForm.senha.focus();
		    return false;	  
		  }	
	  	  	  	  
	TrocaAction(theForm);	
}

function FormataValor(tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form.preco.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.form.preco.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form.preco.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form.preco.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form.preco.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.form.preco.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form.preco.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}


function ValidaDicasTerra(theForm){
	if(!ValidaObrigatorio(theForm.titulo,"Título","5","60")){
		theForm.titulo.focus();
		return false;		
		}
		
	if (theForm.titulo.value.length >60 ) {
		alert("Campo Título não pode conter mais de 60 caracteres.");
		theForm.titulo.focus();
		return false;	
	}
	


	if(!ValidaObrigatorio(theForm.resumo,"Resumo","4","300")){
		theForm.resumo.focus();
		return false;		
		}
		
    if (theForm.resumo.value.length >300 ) {
		alert("Campo Resumo não pode conter mais de 300 caracteres.");
		theForm.resumo.focus();
		return false;	
	}		

	if(!ValidaObrigatorio(theForm.texto,"Texto","4","800")){
		theForm.texto.focus();
		return false;		
		}	
    if (theForm.texto.value.length >800 ) {
		alert("Campo Texto não pode conter mais de 800 caracteres.");
		theForm.texto.focus();
		return false;	
	}			
	theForm.action = "../../includes/incinclusao.asp";
}

function testaCheck(campo, mensagem){
	var conta = 0;
	if (typeof(campo.length)!="undefined"){
		for (var i=0; i<campo.length; i++) {
			if (campo[i].checked) {
				if (campo[i].value != '') {conta++}
			}
		}
	}else{
		if (campo.checked) {conta++;}
	}
	if (conta == 0) {
		alert(mensagem);
		return false;		
	} else {
		return true;
	}
}
  
  
function desabilitaBotao(botao, aviso) {
	document.getElementById(botao).style.display = 'none';
	document.getElementById(aviso).style.display = '';
	document.getElementById(aviso).innerText = 'Aguarde      ';
	setInterval('textoBotao(\'' + aviso + '\')',(500));
}

function textoBotao(objetvo) {
	var obj;
	obj = document.getElementById(objetvo);
	if (obj.innerText == 'Aguarde      ') {
		obj.innerText = 'Aguarde .    ';
	} else if (obj.innerText == 'Aguarde .    ') {
		obj.innerText = 'Aguarde . .  ';
	} else if (obj.innerText == 'Aguarde . .  ') {
		obj.innerText = 'Aguarde . . .';
	} else {
		obj.innerText = 'Aguarde      ';
	}
}

/*
 * Função inserida por Marcelo Pinheiro em 18/01/2006
 * Descrição: serve para limitar o conteúdo de campos texto
 */
function limitaCampoTexto(prmTextbox, prmLabelContador, prmLimiteCaracteres) {
	if (prmTextbox.value.length > prmLimiteCaracteres) {
		prmTextbox.value = prmTextbox.value.substring(0, prmLimiteCaracteres);
	} else {
		prmLabelContador.value = prmLimiteCaracteres - prmTextbox.value.length;
	}
}
