var now  = new Date();
var data = now.getDate()+"/"+(now.getMonth() + 1)+"/"+now.getYear();
var h    = now.getHours();
var m    = now.getMinutes();
var hora = h + ":" + m

function verifica_datas(nCampo){ 
  dia = (nCampo.value.substring(0,2)); 
  mes = (nCampo.value.substring(3,5)); 
  ano = (nCampo.value.substring(6,10)); 
		
  situacao = ""; 
  // verifica data
  if (nCampo.value != "") {
	  if ((dia < 01 ) || (dia > 31) || (mes < 01) ||(mes > 12) || (ano < 1900) || (ano > now.getYear())){ 
		  situacao = "falsa"; 
	  } 
	   
	  if (situacao == "falsa") { 
		  alert("Data invalida!");
		  nCampo.focus(); 
		  document.getElementById('dt_inicio12').value = ''
		  return false;
	  } 
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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 abre(url, name)
{     
	var str = "left=100,screenX=0,top=0,screenY=0,status=1,scrollbars=1";

     if (window.screen) {
       var ah = screen.availHeight - 350;
       var aw = screen.availWidth - 450;
       str += ",height=" + ah;
       str += ",innerHeight=" + ah;
       str += ",width=" + aw;
       str += ",innerWidth=" + aw;
     } else {
       str += ",resizable"; // redimensiona a janela para o usuário
     }

	var janela = window.open(url, name, str);

	if (!janela)
	{
		alert("Por favor, desative seu anti-popup para usar o sistema.");
	}
}

function abre2(url, name,w,h)
{     
	var str = "left=100,screenX=0,top=100,screenY=0,status=0,scrollbars=0";

     if (window.screen) {
       var ah = screen.availHeight - 350;
       var aw = screen.availWidth - 450;
       //str += ",height=" + ah;
       //str += ",innerHeight=" + ah;
       //str += ",width=" + aw;
       //str += ",innerWidth=" + aw;
	   str += ",height=" + h;
       str += ",width=" + w;
     } else {
       str += ",resizable"; // redimensiona a janela para o usuário
     }

	var janela = window.open(url, name, str);

	if (!janela)
	{
		alert("Por favor, desative seu anti-popup para usar o sistema.");
	}
}

function validaLivro(){
if(document.getElementById('texto').value==''){
	alert("Campo Exigido!")
	document.getElementById('texto').focus();
	document.getElementById('texto').style.background='#FFFFE5';
	return false
	}
if(document.getElementById('nome').value==''){
	alert("Campo Exigido!")
	document.getElementById('nome').focus();
	document.getElementById('nome').style.background='#FFFFE5';
	return false
	}	
	else{
	retorna();
	}
}

function retorna(){
	var nome  = document.getElementById('nome').value;
	var texto = document.getElementById('texto').value;
	var icone = document.getElementById('icone').value;

	if(icone == ''){
		icone = 'teeth_smile.gif'
		}

	document.getElementById('GN').value = nome;
	document.getElementById('GT').value = texto;
	document.getElementById('GI').value = icone
	
	lform.submit();
}

function validaForm(){

email=document.form.email

	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	if(document.form.email.value==''){
		alert("Campo Exigido!")
		document.form.email.focus();
		document.form.email.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(email)==false){
	  return false     
	  }
	}
	if(document.form.assunto.value==''){
		alert("Campo Exigido!")
		document.form.assunto.focus();
		document.form.assunto.style.background='#FFFFE5';
		return false
	}

	if(document.form.mensagem.value==''){
		alert("Campo Exigido!")
		document.form.mensagem.focus();
		document.form.mensagem.style.background='#FFFFE5';
		return false
	}
} 	 

//FORM enviar por e-mail
function validaFormEmail(){
	remEmail=document.form.remEmail;
	destEmail=document.form.destEmail;

	if(document.form.remNome.value==''){
		alert("Campo Exigido!")
		document.form.remNome.focus();
		document.form.remNome.style.background='#FFFFE5';
		return false
	}
	if(document.form.remEmail.value==''){
		alert("Campo Exigido!")
		document.form.remEmail.focus();
		document.form.remEmail.style.background='#FFFFE5';
		return false		
	} else {
		if(checkEmail(remEmail)==false){
			return false     
		}
	}
	if(document.form.destNome.value==''){
		alert("Campo Exigido!")
		document.form.destNome.focus();
		document.form.destNome.style.background='#FFFFE5';
		return false
	}
	if(document.form.destEmail.value==''){
		alert("Campo Exigido!")
		document.form.destEmail.focus();
		document.form.destEmail.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(destEmail)==false){
	  return false     
	  }
	}
}

function validaFormCadastro(){
	email=document.form.email

	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	if(document.form.email.value==''){
		alert("Campo Exigido!")
		document.form.email.focus();
		document.form.email.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(email)==false){
	  return false     
	  }
	}
	if(document.form.empresa.value==''){
		alert("Campo Exigido!")
		document.form.empresa.focus();
		document.form.empresa.style.background='#FFFFE5';
		return false		
	}
	if(document.form.ramo.value==''){
		alert("Campo Exigido!")
		document.form.ramo.focus();
		document.form.ramo.style.background='#FFFFE5';
		return false		
	}
	if(document.form.cidade.value==''){
		alert("Campo Exigido!")
		document.form.cidade.focus();
		document.form.cidade.style.background='#FFFFE5';
		return false		
	}
	if(document.form.estado.value==''){
		alert("Campo Exigido!")
		document.form.estado.focus();
		document.form.estado.style.background='#FFFFE5';
		return false		
	}
} 

function checkEmail(campo)
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo.value))
 {
   return (true)
 } if(campo.value!=""){
   alert("O e-mail informado nao e valido.")
   campo.focus();
   campo.style.background='#FFFFE5';
   return (false)
 }
}

function segundo_checkEmail(email){
	var str=email;
	var filter=/^.+@.+\..{2,3}$/;
	if (filter.test(str))
		testresults=true;
	else{
		alert("Por Favor insira um email válido!");
		testresults=false;
	}
	return testresults;
}

function valida (nForm) {
	if(nForm.newsNome.value == "") {
		alert("Campo obrigatorio!");
		nForm.newsNome.focus();
		return false;
	}
	
	if(nForm.newsEmail.value == "") {
		alert("Campo obrigatorio!");
		nForm.newsEmail.focus();
		return false;
	}
	
	abre('/cadastro/envia.asp?nm='+nForm.newsNome.value+'&em='+nForm.newsEmail.value);
}

function validaFormInstrutores(){

email=document.form.email

	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	if(document.form.email.value==''){
		alert("Campo Exigido!")
		document.form.email.focus();
		document.form.email.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(email)==false){
	  return false     
	  }
	}
	if(document.form.area.value==''){
		alert("Campo Exigido!")
		document.form.area.focus();
		document.form.area.style.background='#FFFFE5';
		return false
	}
	if(document.form.areas.value==''){
		alert("Campo Exigido!")
		document.form.areas.focus();
		document.form.areas.style.background='#FFFFE5';
		return false
	}
	if(document.form.cpf.value==''){
		alert("Campo Exigido!")
		document.form.cpf.focus();
		document.form.cpf.style.background='#FFFFE5';
		return false
	}
	if(document.form.rg.value==''){
		alert("Campo Exigido!")
		document.form.rg.focus();
		document.form.rg.style.background='#FFFFE5';
		return false
	}

}

function validaFormCurso(){

email=document.form.email

	if(document.form.curso.value==''){
		alert("Campo Exigido!")
		return false
	}
	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	if(document.form.email.value==''){
		alert("Campo Exigido!")
		document.form.email.focus();
		document.form.email.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(email)==false){
	  return false     
	  }
	}
	if(document.form.cooperativa.value==''){
		alert("Campo Exigido!")
		document.form.cooperativa.focus();
		document.form.cooperativa.style.background='#FFFFE5';
		return false
	}
	if(document.form.cnpj.value==''){
		alert("Campo Exigido!")
		document.form.cnpj.focus();
		document.form.cnpj.style.background='#FFFFE5';
		return false
	}
	if(document.form.turma.value==''){
		alert("Campo Exigido!")
		document.form.turma.focus();
		document.form.turma.style.background='#FFFFE5';
		return false
	}

}

function validaFormProgramacao(){

emailTre=document.form.emailTre

	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	if(document.form.telTre.value==''){
	alert("Campo Exigido!")
	document.form.telTre.focus();
	document.form.telTre.style.background='#FFFFE5';
	return false		
	}
	if(document.form.emailTre.value==''){
		alert("Campo Exigido!")
		document.form.emailTre.focus();
		document.form.emailTre.style.background='#FFFFE5';
		return false		
	}
	else{
	 if(checkEmail(emailTre)==false){
	  return false     
	  }
	}
	if(document.form.cooperativa.value==''){
		alert("Campo Exigido!")
		document.form.cooperativa.focus();
		document.form.cooperativa.style.background='#FFFFE5';
		return false
	}
}

function valida_CPF(s)	{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

//Limpa String

function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";

	for (var i=0; i<S.length; i++)	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)	{
			temp=temp+digito	}
	} //for

	return temp
}

function MascaraCPF(val)
{
   	var pass = val.value;
	var expr = /[0123456789]/;
		
	for(i=0; i<pass.length; i++){
		// charAt -> retorna o caractere posicionado no índice especificado
		var lchar = val.value.charAt(i);
		var nchar = val.value.charAt(i+1);
	
		if(i==0){
		   // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
		   // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
		   // instStr.search(expReg);
		   if ((lchar.search(expr) != 0)){
			  val.value = "";
		   }

		}else if(i<2){
		   if (lchar.search(expr) != 0){
			  val.value = val.value.substring(0,(i));
		   }

		}else if(i==2){
			   
			   if(lchar.search(expr) != 0){
				  // substring(indice1,indice2)
				  // indice1, indice2 -> será usado para delimitar a string
				  var tst1 = val.value.substring(0,(i));
				  val.value = tst1;				
 				  continue;			
			   }
			   
			   if ((nchar != '.') && (nchar != '')){
				 	var tst1 = val.value.substring(0,(i)+1);
				
					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '.' + tst2;
			   }
		 
		 }else if(i>3 && i<6){
				if (lchar.search(expr) != 0){
				  val.value = val.value.substring(0,(i));
			   }			 
		 }else if(i==6){
			
				if(lchar.search(expr) != 0){
					var tst1 = val.value.substring(0,(i));
					val.value = tst1;
					continue;			
				}
		
				if	((nchar != '.') && (nchar != '')){
					var tst1 = val.value.substring(0,(i)+1);

					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '.' + tst2;
				}
   		  }else if(i>7 && i<10){
				if (lchar.search(expr) != 0){
				  val.value = val.value.substring(0, i);
			   }
		  }else if(i==10){
			   
			   if(lchar.search(expr) != 0){
				  // substring(indice1,indice2)
				  // indice1, indice2 -> será usado para delimitar a string
				  var tst1 = val.value.substring(0,(i));
				  val.value = tst1;				
 				  continue;			
			   }
			   
			   if ((nchar != '-') && (nchar != '')){
				 	var tst1 = val.value.substring(0,(i)+1);
				
					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '-' + tst2;
			   }
		  }else if(i>11){
			  if(lchar.search(expr) != 0) {
					var tst1 = val.value.substring(0,(i));
					val.value = tst1;			
			  }
		  }
	 }
	
     if(pass.length>14)
		val.value = val.value.substring(0, 14);
	 	return true;
}

function formataDataDMA(data) {   // data deve ser um Date
	var dia, ano, mes
	dia = data.getDate();
	mes = (data.getMonth()+1);
	ano = data.getFullYear();
	if (dia < 10){
		dia = ('0'+dia);
	}
	if (mes < 10){
		mes = ('0'+mes);
	}
	return dia+"/"+mes+"/"+ano; // retorna no formato data MDA
}

// colocar no evento onKeyUp passando o objeto como parametro
function formata(val)
{
   	var pass = val.value;
	var expr = /[0123456789]/;
		
	for(i=0; i<pass.length; i++){
		// charAt -> retorna o caractere posicionado no índice especificado
		var lchar = val.value.charAt(i);
		var nchar = val.value.charAt(i+1);
	
		if(i==0){
		   // search -> retorna um valor inteiro, indicando a posição do inicio da primeira
		   // ocorrência de expReg dentro de instStr. Se nenhuma ocorrencia for encontrada o método retornara -1
		   // instStr.search(expReg);
		   if ((lchar.search(expr) != 0) || (lchar>3)){
			  val.value = "";
		   }
		   
		}else if(i==1){
			   
			   if(lchar.search(expr) != 0){
				  // substring(indice1,indice2)
				  // indice1, indice2 -> será usado para delimitar a string
				  var tst1 = val.value.substring(0,(i));
				  val.value = tst1;				
 				  continue;			
			   }
			   
			   if ((nchar != '/') && (nchar != '')){
				 	var tst1 = val.value.substring(0, (i)+1);
				
					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
			   }

		 }else if(i==4){
			
				if(lchar.search(expr) != 0){
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;
					continue;			
				}
		
				if	((nchar != '/') && (nchar != '')){
					var tst1 = val.value.substring(0, (i)+1);

					if(nchar.search(expr) != 0) 
						var tst2 = val.value.substring(i+2, pass.length);
					else
						var tst2 = val.value.substring(i+1, pass.length);
	
					val.value = tst1 + '/' + tst2;
				}
   		  }
		
		  if(i>=6){
			  if(lchar.search(expr) != 0) {
					var tst1 = val.value.substring(0, (i));
					val.value = tst1;			
			  }
		  }
	 }
	
     if(pass.length>10)
		val.value = val.value.substring(0, 10);
	 	return true;
}

function MascaraCEP (Form1ato, keypress, objeto)
{
campo = eval (objeto);
if (Form1ato=='CEP')
	{
	caracteres = '01234567890';
	separacoes = 1;
	separacao1 = '-';
	conjuntos = 2;
	conjunto1 = 5;
	conjunto2 = 3;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
	(conjunto1 + conjunto2 + 1))
		{
		if (campo.value.length == conjunto1) 
		   campo.value = campo.value + separacao1;
		}
	else 
		event.returnValue = false;
	}
}

// Adiciona Máscara de numeros inteiros 
function mascaraInteiro(){
    if (event.keyCode < 48 || event.keyCode > 57){
        event.returnValue = false;
        return false;
    }
    return true;
}

//adiciona mascara ao telefone
function MascaraTelefone(tel){    
    if(mascaraInteiro(tel)==false){
        event.returnValue = false;
    }    
    return formataCampo(tel, '(000) 0000-0000', event);
}

/* Formataçao de Campos */
function formataCampo(campo, Mascara, evento) { 
    var boleanoMascara; 
    
    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" ); 
   
    var posicaoCampo = 0;     
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;; 
    
    if (Digitato != 8) { // backspace 
        for(i=0; i<= TamanhoMascara; i++) { 
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/")) 
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
            if (boleanoMascara) { 
                NovoValorCampo += Mascara.charAt(i); 
                  TamanhoMascara++;
            }else { 
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
                posicaoCampo++; 
              }            
          }     
        campo.value = NovoValorCampo;
          return true; 
    }else { 
        return true; 
    }
}


/* Masscara */
function RetornaTecla(e)
{
	if (document.all)
	{
		var tecla = event.keyCode;
	}
	else if(document.layers)
	{
		var tecla = e.which;
	}
	
	return tecla;
}

function SomenteNumeros(e)
{
	tecla = RetornaTecla(e);
	
	// tratamento das teclas
	if ( (tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && (tecla < 37 || tecla > 40) && (tecla != 17) && (tecla != 18) && (tecla != 8) && (tecla != 9) && (tecla != 32) && (tecla != 46) && (tecla != 35) && (tecla != 36) && (tecla != 13))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function validaFicha(){
	email=document.form.email

	if(document.form.nome.value==''){
		alert("Campo Exigido!")
		document.form.nome.focus();
		document.form.nome.style.background='#FFFFE5';
		return false
	}
	var controle = 0;
	for (i=0;i<document.form.elements.length;i++){
		if (document.form.elements[i].type == "radio"){
			if (document.form.elements[i].name == "sexo"){
				if (document.form.elements[i].checked == true){
					controle++;
				}
			}
		}
	}
	if (controle <= 0){
		alert("Selecione uma das alternativas para o campo sexo.");
		document.form.nome.focus();
		return false;
	}
	if(document.form.cpf.value==''){
		alert("Campo Exigido!")
		document.form.cpf.focus();
		document.form.cpf.style.background='#FFFFE5';
		return false		
	}else{
		if(!valida_CPF(document.form.cpf.value)){
			alert("CPF invalido!")
			document.form.cpf.focus();
			document.form.cpf.style.background='#FFFFE5';
			return false		
		}
	}
	if(document.form.rg.value==''){
		alert("Campo Exigido!")
		document.form.rg.focus();
		document.form.rg.style.background='#FFFFE5';
		return false
	}
	if(document.form.rg_orgao.value==''){
		alert("Campo Exigido!")
		document.form.rg_orgao.focus();
		document.form.rg_orgao.style.background='#FFFFE5';
		return false
	}
	if(document.form.rg_emissao.value==''){
		alert("Campo Exigido!")
		document.form.rg_emissao.focus();
		document.form.rg_emissao.style.background='#FFFFE5';
		return false
	}
	if(document.form.nascimento.value==''){
		alert("Campo Exigido!")
		document.form.nascimento.focus();
		document.form.nascimento.style.background='#FFFFE5';
		return false
	}
	if(document.form.naturalidade.value==''){
		alert("Campo Exigido!")
		document.form.naturalidade.focus();
		document.form.naturalidade.style.background='#FFFFE5';
		return false
	}
	if(document.form.escolaridade.value==''){
		alert("Campo Exigido!")
		document.form.escolaridade.focus();
		document.form.escolaridade.style.background='#FFFFE5';
		return false
	}
	if(document.form.endereco.value==''){
		alert("Campo Exigido!")
		document.form.endereco.focus();
		document.form.endereco.style.background='#FFFFE5';
		return false
	}
	if(document.form.numero.value==''){
		alert("Campo Exigido!")
		document.form.numero.focus();
		document.form.numero.style.background='#FFFFE5';
		return false
	}
	if(document.form.bairro.value==''){
		alert("Campo Exigido!")
		document.form.bairro.focus();
		document.form.bairro.style.background='#FFFFE5';
		return false
	}
	if(document.form.cidade.value==''){
		alert("Campo Exigido!")
		document.form.cidade.focus();
		document.form.cidade.style.background='#FFFFE5';
		return false
	}
	if(document.form.uf.value==''){
		alert("Campo Exigido!")
		document.form.uf.focus();
		document.form.uf.style.background='#FFFFE5';
		return false
	}
	if(document.form.cep.value==''){
		alert("Campo Exigido!")
		document.form.cep.focus();
		document.form.cep.style.background='#FFFFE5';
		return false
	}
	if(!ValidaCep(document.form.cep)){
		document.form.cep.focus();
		document.form.cep.style.background='#FFFFE5';
		return false
	}
	if(document.form.email.value==''){
		alert("Campo Exigido!")
		document.form.email.focus();
		document.form.email.style.background='#FFFFE5';
		return false
	}
    if(checkEmail(document.form.email)==false){
	  return false     
	  }
	if(document.form.fone.value==''){
		alert("Campo Exigido!")
		document.form.fone.focus();
		document.form.fone.style.background='#FFFFE5';
		return false		
	}
	if(!ValidaTelefone(document.form.fone)){
		document.form.fone.focus();
		document.form.fone.style.background='#FFFFE5';
		return false		
	}
	var controle = 0;
	for (i=0;i<document.form.elements.length;i++){
		if (document.form.elements[i].type == "radio"){
			if (document.form.elements[i].name == "deficiencia"){
				if (document.form.elements[i].checked == true){
					controle++;
				}
			}
		}
	}
	if (controle <= 0){
		alert("Selecione uma das alternativas para o campo deficiência.");
		document.form.empresa.focus();
		return false;
	}
	if(document.form.empresa.value==''){
		alert("Campo Exigido!")
		document.form.empresa.focus();
		document.form.empresa.style.background='#FFFFE5';
		return false		
	}
	if(document.form.fantasia.value==''){
		alert("Campo Exigido!")
		document.form.fantasia.focus();
		document.form.fantasia.style.background='#FFFFE5';
		return false		
	}
	if(document.form.cnpj.value==''){
		alert("Campo Exigido!")
		document.form.cnpj.focus();
		document.form.cnpj.style.background='#FFFFE5';
		return false		
	}else{
		if(!ValidarCNPJ(document.form.cnpj)){
			document.form.cnpj.focus();
			document.form.cnpj.style.background='#FFFFE5';
			return false		
		}
	}
	if(document.form.endEmp.value==''){
		alert("Campo Exigido!")
		document.form.endEmp.focus();
		document.form.endEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.numEmp.value==''){
		alert("Campo Exigido!")
		document.form.numEmp.focus();
		document.form.numEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.BaiEmp.value==''){
		alert("Campo Exigido!")
		document.form.BaiEmp.focus();
		document.form.BaiEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.cidEmp.value==''){
		alert("Campo Exigido!")
		document.form.cidEmp.focus();
		document.form.cidEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.ufEmp.value==''){
		alert("Campo Exigido!")
		document.form.ufEmp.focus();
		document.form.ufEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.cepEmp.value==''){
		alert("Campo Exigido!")
		document.form.cepEmp.focus();
		document.form.cepEmp.style.background='#FFFFE5';
		return false
	}
	if(!ValidaCep(document.form.cepEmp)){
		document.form.cepEmp.focus();
		document.form.cepEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.foneEmp.value==''){
		alert("Campo Exigido!")
		document.form.foneEmp.focus();
		document.form.foneEmp.style.background='#FFFFE5';
		return false
	}
	if(!ValidaTelefone(document.form.foneEmp)){
		document.form.foneEmp.focus();
		document.form.foneEmp.style.background='#FFFFE5';
		return false
	}
	if(document.form.respNome.value==''){
		alert("Campo Exigido!")
		document.form.respNome.focus();
		document.form.respNome.style.background='#FFFFE5';
		return false
	}
	if(document.form.respFuncao.value==''){
		alert("Campo Exigido!")
		document.form.respFuncao.focus();
		document.form.respFuncao.style.background='#FFFFE5';
		return false
	}
	if(document.form.respCPF.value==''){
		alert("Campo Exigido!")
		document.form.respCPF.focus();
		document.form.respCPF.style.background='#FFFFE5';
		return false		
	}else{
		if(!valida_CPF(document.form.respCPF.value)){
			alert("CPF invalido!")
			document.form.respCPF.focus();
			document.form.respCPF.style.background='#FFFFE5';
			return false		
		}
	}
	if(document.form.respFone.value==''){
		alert("Campo Exigido!")
		document.form.respFone.focus();
		document.form.respFone.style.background='#FFFFE5';
		return false
	}
	if(!ValidaTelefone(document.form.respFone)){
		document.form.respFone.focus();
		document.form.respFone.style.background='#FFFFE5';
		return false
	}
} 

function FormataCnpj(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
					if (tam == 10)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
					if (tam == 15)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
				}
			}

//valida CEP
function ValidaCep(cep){
	exp = /\d{5}\-\d{3}/        
	if(!exp.test(cep.value)){          
		alert('Numero de Cep Invalido!');               
		return false;
	}else{
		return true;
	}
}

//valida telefone
function ValidaTelefone(tel){
	exp = /\(\d{3}\)\ \d{4}\-\d{4}/        
	if(!exp.test(tel.value)){
		alert('Numero de Telefone Invalido!');
		return false;
	}else{
		return true;
	}
}
//valida o CNPJ digitado
function ValidarCNPJ(ObjCnpj){
	var cnpj = ObjCnpj.value;
	var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
	var dig1= new Number;
	var dig2= new Number;
	exp = /\.|\-|\//g
	cnpj = cnpj.toString().replace( exp, "" );
	var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
	for(i = 0; i<valida.length; i++){
		dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);
		dig2 += cnpj.charAt(i)*valida[i];
	}
	dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
	dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
	if(((dig1*10)+dig2) != digito){
		alert('CNPJ Invalido!');                
		return false;
	}else{
		return true;
	}
}
