

function Validator(theForm)
{
/************************************************
* function verificaEmail
* Verifica se um email é válido
************************************************/

function verificaEmail(email) 
{
	var s = new String(email);
	// { } ( ) < > [ ] | \ /
	if ((s.indexOf("{")>=0) || (s.indexOf("}")>=0) || (s.indexOf("(")>=0) || (s.indexOf(")")>=0) || (s.indexOf("<")>=0) || (s.indexOf(">")>=0) || (s.indexOf("[")>=0) || (s.indexOf("]")>=0) || (s.indexOf("|")>=0) || (s.indexOf("\"")>=0) || (s.indexOf("/")>=0) )
		return false;
	if (vogalAcentuada(email))
		return false;
	// & * $ % ? ! ^ ~ ` ' "
	if ((s.indexOf("&")>=0) || (s.indexOf("*")>=0) || (s.indexOf("$")>=0) || (s.indexOf("%")>=0) || (s.indexOf("?")>=0) || (s.indexOf("!")>=0) || (s.indexOf("^")>=0) || (s.indexOf("~")>=0) || (s.indexOf("`")>=0) || (s.indexOf("'")>=0) )
		return false;
	// , ; : = #
	if ((s.indexOf(",")>=0) || (s.indexOf(";")>=0) || (s.indexOf(":")>=0) || (s.indexOf("=")>=0) || (s.indexOf("#")>=0) )
		return false;
	// procura se existe apenas um @
	if ( (s.indexOf("@") < 0) || (s.indexOf("@") != s.lastIndexOf("@")) )
		return false;
	// verifica se tem pelo menos um ponto após o @
	if (s.lastIndexOf(".") < s.indexOf("@"))
		return false;
	return true;
}	


// Verifica se uma string tem vogais acentuadas

function vogalAcentuada(s) {
	ls = s.toLowerCase();
	if ((ls.indexOf("á")>=0) || (ls.indexOf("à")>=0) || (ls.indexOf("ã")>=0) || (ls.indexOf("â")>=0) || (ls.indexOf("é")>=0) || (ls.indexOf("í")>=0) || (ls.indexOf("ó")>=0) || (ls.indexOf("õ")>=0) || (ls.indexOf("ô")>=0) || (ls.indexOf("ú")>=0) || (ls.indexOf("ü")>=0))
		return true;
}


/************************************************
* function ValidaData
* Verifica se a data foi digitada corretamente
* Input: Data a ser verificado
************************************************/
function ValidaData (data, AnoMin, AnoMax) 
{

var datacomposta = data;

//**************declaracao das variaveis***********************************
//*****variaveis que comporao dia/mes/ano*****
var dia="";
var mes="";
var ano="";

//***********variavel para testar caracters validos*********
var caractervalidos="1234567890/. ";

//*****contadores******************************
var c=0;
var i=0;
var p=0;
var cont=1;
var verifica=0;

//************variavel de validacao************
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);
 }


//***********************testa caracteres validos*****************************  
        for(c; c<datacomposta.length; c++){
                 //alert("esta e a data composta = " +datacomposta.charAt(c));
	   	 	if ( caractervalidos.indexOf(datacomposta.charAt(c)) == -1 ) {
   	 			   alert("Caracteres invalidos na Data.");
                    return (false);
			   	 } // end if
       		} // end for


//*******************testa a quantidade de verificadores " / " *****************

               
	for(c=0;c<datacomposta.length;c++){
    	if(datacomposta.charAt(c)=="/"){
        	verifica++;
			} // end if
        if (datacomposta.charAt(c)=="."){
            verifica++;
			} // end if
		} // end for
     if (verifica!=2){
	    	alert("Numero de separadores errados na Data.");
        	return (false);
		} // end if
                                        
//****************compoe variavel dia *************

   	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

//****************compoe variavel mes, testa e valida numero de dias  ************
    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

	// Valida os meses e dias
		
     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!=4){
	    	alert("Ano invalido na Data. Formato de ANO com 4 dígitos");
	        return (false);
		} // 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);
				
}                

  if (theForm.razaosocial.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Razão Social!");
    theForm.razaosocial.focus();
    return (false);
  }

  if (theForm.endereco.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Endereço!");
    theForm.endereco.focus();
    return (false);
  }
  
  if (theForm.numero.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Número!");
    theForm.numero.focus();
    return (false);
  }

  if (theForm.cep.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo CEP!");
    theForm.cep.focus();
    return (false);
  }  

  if (theForm.cidade.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Cidade!");
    theForm.cidade.focus();
    return (false);
  }      

  if (theForm.estado.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Estado!");
    theForm.estado.focus();
    return (false);
  }      
  

  if (theForm.pais.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo País!");
    theForm.pais.focus();
    return (false);
  }     
  
   if ((! theForm.categoria[0].checked ) && (! theForm.categoria[1].checked )) {
	    alert("Você esqueceu de selecionar a Categoria!");
	    return (false);
	}			  			    


  if (theForm.nro_func.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Numero de Funcionarios!");
    theForm.nro_func.focus();
    return (false);
  } 


  if (theForm.nomecontato.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome Contato!");
    theForm.nomecontato.focus();
    return (false);
  }      



  if (theForm.telefonecontato.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Telefone Contato!");
    theForm.telefonecontato.focus();
    return (false);
  }      
  
  // Tel
  var expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.telefonecontato.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Telefone Contato é inválido!");
     theForm.telefonecontato.focus();
     return (false);		
  }

	
  if (theForm.emailcontato.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo E-mail Contato!");
    theForm.emailcontato.focus();
    return (false);
  }      	
  
  // E-mail
  expReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;  	
  if (!(theForm.emailcontato.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo E-mail Contato é inválido!");
     theForm.emailcontato.focus();
     return (false);		
  }	
  
  if (theForm.celularcontato.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Celular Contato!");
    theForm.celularcontato.focus();
    return (false);
  }      					  
    
  // Cel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.celularcontato.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Celular Contato é inválido!");
     theForm.celularcontato.focus();
     return (false);		
  } 

  if (theForm.nomecontato2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome Contato!");
    theForm.nomecontato2.focus();
    return (false);
  }      

  if (theForm.telefonecontato2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Telefone Contato!");
    theForm.telefonecontato2.focus();
    return (false);
  }   
  
  // Tel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.telefonecontato2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Telefone Contato é inválido!");
     theForm.telefonecontato2.focus();
     return (false);		
  }   
  
  if (theForm.emailcontato2.value.length == 0)
  {
    alert("Você esqueceu de preencher o campo E-mail Contato!");
    theForm.emailcontato2.focus();
    return (false);
  }     
  
  // E-mail	
  expReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;  	
  if (!(theForm.emailcontato2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo E-mail Contato é inválido!");
     theForm.emailcontato2.focus();
     return (false);		
  }	 					  

  if (theForm.celularcontato2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Cel Contato!");
    theForm.celularcontato2.focus();
    return (false);
  }   
  
  // Cel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.celularcontato2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Telefone Contato é inválido!");
     theForm.celularcontato2.focus();
     return (false);		
  }   					  


  if (theForm.nomecontatotec.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome Contato Técnico!");
    theForm.nomecontatotec.focus();
    return (false);
  }      

  
  if (theForm.telefonecontatotec.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Telefone Contato Técnico!");
    theForm.telefonecontatotec.focus();
    return (false);
  }        
  
  // Tel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.telefonecontatotec.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Telefone Contato Técnico é inválido!");
     theForm.telefonecontatotec.focus();
     return (false);		
  }   

  if (theForm.emailcontatotec.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo E-mail Contato Técnico!");
    theForm.emailcontatotec.focus();
    return (false);
  }      
  
  // E-mail	
  expReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;  	
  if (!(theForm.emailcontatotec.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo E-mail Contato Técnico é inválido!");
     theForm.emailcontatotec.focus();
     return (false);		
  }	  

  if (theForm.celularcontatotec.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Cel Contato Técnico!");
    theForm.celularcontatotec.focus();
    return (false);
  }        
  
  // Cel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.celularcontatotec.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Cel Contato Técnico é inválido!");
     theForm.celularcontatotec.focus();
     return (false);		
  } 

  if (theForm.nomecontatotec2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome Contato Técnico!");
    theForm.nomecontatotec2.focus();
    return (false);
  }      

  
  if (theForm.telefonecontatotec2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Telefone Contato Técnico!");
    theForm.telefonecontatotec2.focus();
    return (false);
  }        
  
  // Tel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.telefonecontatotec2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Telefone Contato Técnico é inválido!");
     theForm.telefonecontatotec2.focus();
     return (false);		
  }   

  if (theForm.emailcontatotec2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo E-mail Contato Técnico!");
    theForm.emailcontatotec2.focus();
    return (false);
  }      
  
  // E-mail	
  expReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;  	
  if (!(theForm.emailcontatotec2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo E-mail Contato Técnico é inválido!");
     theForm.emailcontatotec2.focus();
     return (false);		
  }	  

  if (theForm.celularcontatotec2.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Cel Contato Técnico!");
    theForm.celularcontatotec2.focus();
    return (false);
  }        
  
  // Cel
  expReg = /\(..\)[0-9]{4}-[0-9]{4}/;  	
  if (!(theForm.celularcontatotec2.value.match(expReg))) // se a expressao tiver erro
  {    
     alert("O campo Cel Contato Técnico é inválido!");
     theForm.celularcontatotec2.focus();
     return (false);		
  } 
  
  if (theForm.nomecomercial.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome Comercial!");
    theForm.nomecomercial.focus();
    return (false);
  }      

  if (theForm.serie.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Série!");
    theForm.serie.focus();
    return (false);
  }        

  if (theForm.modelo.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Modelo!");
    theForm.modelo.focus();
    return (false);
  }        


   if ((! theForm.origemequipamento[0].checked ) && (! theForm.origemequipamento[1].checked ) && (! theForm.origemequipamento[2].checked ) && (! theForm.origemequipamento[3].checked )) {
	    alert("Você esqueceu de selecionar a Origem!");
	    return (false);
	}			  			    
  

  if (theForm.aplicacao.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Aplicação!");
    theForm.aplicacao.focus();
    return (false);
  }        


    if ((! theForm.origemprojeto[0].checked ) && (! theForm.origemprojeto[1].checked ) && (! theForm.origemprojeto[2].checked ) && (! theForm.origemprojeto[3].checked ) && (! theForm.origemprojeto[4].checked )) {
	    alert("Você esqueceu de selecionar a Origem do Projeto!");
	    return (false);
	}			  			     
  
    if ((! theForm.equipamento[0].checked ) && (! theForm.equipamento[1].checked )) {
	    alert("Você esqueceu de selecionar se o produto foi ensaiado/estado!");
	    return (false);
	}		
	
	if ((! theForm.outrasedicoes[0].checked ) && (! theForm.outrasedicoes[1].checked )) {
	    alert("Você esqueceu de selecionar se o produto já concorreu nesta categoria!");
	    return (false);
	}
	
		  			     


// Data
  if (theForm.datalancamento.value.length == 0)
  {
    alert("Você esqueceu de preencher o campo Data de Lançamento!");
    theForm.datalancamento.focus();
    return (false);
  }   

  if (!ValidaData(theForm.datalancamento.value, 1901, 2100))
  {
    alert("Formato incorreto de Data!");
    theForm.datalancamento.focus();
    return (false);
  }        

  
  if (theForm.mercadointerno.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Mercado Interno!");
    theForm.mercadointerno.focus();
    return (false);
  }          


  if (theForm.norte.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.norte.focus();
    return (false);
  }          

  if (theForm.nordeste.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.nordeste.focus();
    return (false);
  }            

  if (theForm.centrooeste.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.centrooeste.focus();
    return (false);
  }            

  if (theForm.sudeste.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.sudeste.focus();
    return (false);
  }            

  if (theForm.sul.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.sul.focus();
    return (false);
  }                         

  if (theForm.mercadoexterno.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Mercado Externo!");
    theForm.mercadoexterno.focus();
    return (false);
  }                         

  if (theForm.mercosul.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo!");
    theForm.mercosul.focus();
    return (false);
  }                         


  if (theForm.numerounidadedesdelancamento.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Número de unidades produzidas/comercializadas desde o lançamento!");
    theForm.numerounidadedesdelancamento.focus();
    return (false);
  }     
  

  if (theForm.numerounidadeateestadata.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Número de unidades do produto inscrito fabricado/comercializado até esta data!");
    theForm.numerounidadeateestadata.focus();
    return (false);
  }                         


  if (theForm.local.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Local!");
    theForm.local.focus();
    return (false);
  }                         

 // Data
  if (theForm.data.value.length == 0)
  {
    alert("Você esqueceu de preencher a Data!");
    theForm.data.focus();
    return (false);
  } 

  if (!ValidaData(theForm.data.value, 1901, 2100))
  {
    alert("Formato incorreto de Data!");
    theForm.data.focus();
    return (false);
  }                           

  if (theForm.nomeresponsavel.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Nome do responsável!");
    theForm.nomeresponsavel.focus();
    return (false);
  }        
  
  if (theForm.numerounidadedesdelancamento.value.length == 0) 
  {
    alert("Você esqueceu de preencher o campo Numero de Unidades!");
    theForm.numerounidadedesdelancamento.focus();
    return (false);
  }  
                     
}	
//-->

function MM_swapImgRestore() { //v3.0
  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() { //v3.0
  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) { //v4.0
  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() { //v3.0
  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 abreinscricao(pUrl,pTit,pLX,pAY)
{
	var xx=10;
	var yy=10;
	document.form_destaque.target=pTit;
	document.form_destaque.action=pUrl;
	window.open(pUrl,pTit,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+pLX+',height='+pAY+',top='+yy+',left='+xx+',screenX='+xx+',screenY='+yy);
	document.form_destaque.submit();
}

function FormSubmit(){
	document.form_destaque.target='_self'
	document.form_destaque.action='edicao2009-form_envia_email_destaque.asp'
}

function ValidaFone(obj,prox) {
	switch (obj.value.length) {
	    case 1:
	        obj.value = "(" + obj.value;
	        break;
	    case 3:
	        obj.value = obj.value + ")";
	        break;    
	    case 8:
	        obj.value = obj.value + "-";
	        break;    
	    case 13:
	        prox.focus();
	        break;
		}
}
