//Variaveis para validacao de Data
var reDate4 = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
var reDate = reDate4;

//Data dd/mm/aaaa
function doDate(pStr, pFmt, pObj)
{
	if(pObj.value != '')
	{		
		eval("reDate = reDate" + pFmt);
		if(reDate.test(pStr) != true) {
			alert(pStr + " NÃO é uma data válida.\nPor gentileza preencha o campo com uma data válida.");
			pObj.focus();
			return false;
		}
	}
}

//Data mm/aaaa
function doDate2(pStr, pFmt, pObj)
{
	if(pObj.value != '')
	{
		eval("reDate = reDate" + pFmt);
		if(reDate.test(pStr) != true) {
			alert(pStr + " NÃO é uma data válida.\nPor gentileza preencha o campo com uma data válida.");
			pObj.focus();
			return false;
		}
	}
}

//Endereço home
function Validar_Endereco_Home()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.cboEstado.value == "")
	{
		alert(msgPadrao + "Estado");
		document.frm.cboEstado.focus();
		return false;
	}
	else if(document.frm.txtTelefone.value == "")
	{
		alert(msgPadrao + "Telefone");
		document.frm.txtTelefone.focus();
		return false;
	}
	else if(document.frm.txtEndereco.value == "")
	{
		alert(msgPadrao + "Endereço");
		document.frm.txtEndereco.focus();
		return false;
	}
}

//Assinantes
function Validar_Assinante()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtNome.value == "")
	{
		alert(msgPadrao + "Nome");
		document.frm.txtNome.focus();
		return false;
	}
	else if(document.frm.txtEmail.value == "")
	{
		alert(msgPadrao + "E-mail");
		document.frm.txtEmail.focus();
		return false;
	}
}

//Cliente
function Validar_Cliente()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtCliente.value == "")
	{
		alert(msgPadrao + "Cliente");
		document.frm.txtCliente.focus();
		return false;
	}
}

//Noticia Arquivo
function Validar_Noticia_Arquivo()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtTitulo.value == "")
	{
		alert(msgPadrao + "Titulo");
		document.frm.txtTitulo.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Noticia
function Validar_Noticia()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtTitulo.value == "")
	{
		alert(msgPadrao + "Titulo");
		document.frm.txtTitulo.focus();
		return false;
	}
	else if(document.frm.txtTexto.value == "")
	{
		alert(msgPadrao + "Texto");
		document.frm.txtTexto.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Link
function Validar_Link()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtTitulo.value == "")
	{
		alert(msgPadrao + "Titulo");
		document.frm.txtTitulo.focus();
		return false;
	}
	else if(document.frm.txtLink.value == "")
	{
		alert(msgPadrao + "Link");
		document.frm.txtLink.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar")
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Evento
function Validar_Evento()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtEvento.value == "")
	{
		alert(msgPadrao + "Evento");
		document.frm.txtEvento.focus();
		return false;
	}
	else if(document.frm.txtDescricao.value == "")
	{
		alert(msgPadrao + "Descrição");
		document.frm.txtDescricao.focus();
		return false;
	}
	else if(document.frm.txtDtInicio.value == "")
	{
		alert(msgPadrao + "Data Inicio");
		document.frm.txtDtInicio.focus();
		return false;
	}
	else if(document.frm.txtDtTermino.value == "")
	{
		alert(msgPadrao + "Data Termino");
		document.frm.txtDtTermino.focus();
		return false;
	}
	else if(document.frm.txtEstado.value == "")
	{
		alert(msgPadrao + "Estado");
		document.frm.txtEstado.focus();
		return false;
	}
	else if(document.frm.txtCidade.value == "")
	{
		alert(msgPadrao + "Cidade");
		document.frm.txtCidade.focus();
		return false;
	}
	else if(document.frm.txtBairro.value == "")
	{
		alert(msgPadrao + "Bairro");
		document.frm.txtBairro.focus();
		return false;
	}
	else if(document.frm.txtCep.value == "")
	{
		alert(msgPadrao + "CEP");
		document.frm.txtCep.focus();
		return false;
	}
	else if(document.frm.txtEndereco.value == "")
	{
		alert(msgPadrao + "Endereço");
		document.frm.txtEndereco.focus();
		return false;
	}
	else if(document.frm.txtNumero.value == "")
	{
		alert(msgPadrao + "Nº");
		document.frm.txtNumero.focus();
		return false;
	}
	else if(document.frm.txtTel.value == "")
	{
		alert(msgPadrao + "Tel");
		document.frm.txtTel.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Email
function Validar_Email()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtArea.value == "")
	{
		alert(msgPadrao + "Área");
		document.frm.txtArea.focus();
		return false;
	}
	else if(document.frm.txtEmail.value == "")
	{
		alert(msgPadrao + "E-mail");
		document.frm.txtEmail.focus();
		return false;
	}
	else if(document.frm.txtEmail.length < 5)
	{
		alert("Preencha corretamente o campo E-mail");
		document.frm.txtEmail.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Endereço
function Validar_Endereco()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.cboEstado.value == "")
	{
		alert(msgPadrao + "Estado");
		document.frm.cboEstado.focus();
		return false;
	}
	else if(document.frm.txtCidade.value == "")
	{
		alert(msgPadrao + "Cidade");
		document.frm.txtCidade.focus();
		return false;
	}
	else if(document.frm.txtBairro.value == "")
	{
		alert(msgPadrao + "Bairro");
		document.frm.txtBairro.focus();
		return false;
	}
	else if(document.frm.txtCep.value == "")
	{
		alert(msgPadrao + "CEP");
		document.frm.txtCep.focus();
		return false;
	}
	else if(document.frm.txtCep.length < 9)
	{
		alert("Preencha corretamente o campo CEP");
		document.frm.txtCep.focus();
		return false;
	}
	else if(document.frm.txtEndereco.value == "")
	{
		alert(msgPadrao + "Endereço");
		document.frm.txtEndereco.focus();
		return false;
	}
	else if(document.frm.txtNumero.value == "")
	{
		alert(msgPadrao + "Nº");
		document.frm.txtNumero.focus();
		return false;
	}
	else if(document.frm.txtTel.value == "")
	{
		alert(msgPadrao + "Tel");
		document.frm.txtTel.focus();
		return false;
	}
	else if(document.frm.txtTel.length < 9)
	{
		alert("Preencha corretamente o campo Tel")
		document.frm.txtTel.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Solução
function Validar_Solucao()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtTitulo.value == "")
	{
		alert(msgPadrao + "Titulo");
		document.frm.txtTitulo.focus();
		return false;
	}
	else if(document.frm.txtTexto.value == "")
	{
		alert(msgPadrao + "Texto");
		document.frm.txtTexto.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Usuarios
function Validar_Usuario()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtNome.value == "")
	{
		alert(msgPadrao + "Nome");
		document.frm.txtNome.focus();
		return false;
	}
	else if(document.frm.txtLogin.value == "")
	{
		alert(msgPadrao + "Login");
		document.frm.txtLogin.focus();
		return false;
	}
	else if(document.frm.txtSenha.value == "")
	{
		alert(msgPadrao + "Senha");
		document.frm.txtSenha.focus();
		return false;
	}
	else if(document.frm.txtEmail.value == "")
	{
		alert(msgPadrao + "E-mail");
		document.frm.txtEmail.focus();
		return false;
	}
	else if(document.frm.cboStatus.value == "")
	{
		alert(msgPadrao + "Status");
		document.frm.cboStatus.focus();
		return false;
	}else if(document.frm.cboNivel.value == "")
	{
		alert(msgPadrao + "Nível");
		document.frm.cboNivel.focus();
		return false;
	}
}

//Produtos
function Validar_Produtos()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtProduto.value == "")
	{
		alert(msgPadrao + "Produto");
		document.frm.txtProduto.focus();
		return false;
	}
	else if(document.frm.txtTexto.value == "")
	{
		alert(msgPadrao + "Texto");
		document.frm.txtTexto.focus();
		return false;
	}
	else if(document.frm.cboOrdem.value == "")
	{
		alert(msgPadrao + "Ordem");
		document.frm.cboOrdem.focus();
		return false;
	}
	else if(document.frm.cboPublicar.value == "")
	{
		alert(msgPadrao + "Publicar");
		document.frm.cboPublicar.focus();
		return false;
	}
}

//Recados
function Validar_Recados()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtAssuntoRecado.value == "")
	{
		alert(msgPadrao + "Assunto");
		document.frm.txtAssuntoRecado.focus();
		return false;
	}
	else if(document.frm.cboPara.value == "")
	{
		alert(msgPadrao + "Para:");
		document.frm.cboPara.focus();
		return false;
	}
	else if(document.frm.txtMensagemRecado.value == "")
	{
		alert(msgPadrao + "Recado");
		document.frm.txtMensagemRecado.focus();
		return false;
	}
}

//Agenda
function Validar_Agenda()
{
	var msgPadrao = "Por gentileza preencha o campo ";
	if(document.frm.txtAssuntoAgenda.value == "")
	{
		alert(msgPadrao + "Assunto");
		document.frm.txtAssuntoAgenda.focus();
		return false;
	}
	else if(document.frm.txtLembrarDia.value == "")
	{
		alert(msgPadrao + "Lembrar dia");
		document.frm.txtLembrarDia.focus();
		return false;
	}
	else if(document.frm.txtLembrete.value == "")
	{
		alert(msgPadrao + "Lembrete");
		document.frm.txtLembrete.focus();
		return false;
	}
}

//Formata Data
function FormataData(campo)	
{	
	if(campo.value.length == 2 && event.keyCode != 10)
	{
		campo.value = campo.value + "/";
	}
	if(campo.value.length == 5 && event.keycode != 10)
	{
		campo.value = campo.value + "/";
	}
}

//Formata Data2 (mes/ano apenas)
function FormataData2(campo)	
{	
	if(campo.value.length == 2 && event.keyCode != 7)
	{
		campo.value = campo.value + "/";
	}
}


//Formata CEP
function FormataCep(campo)
{	
	if(campo.value.length == 5 && event.keyCode != 8)
	{
		campo.value = campo.value + "-";
	}
}

//Formata Telefone e Fax
function FormataTel(campo)
{	
	if(campo.value.length == 2 && event.keyCode != 8)
	{
		campo.value = campo.value + " | ";
	}
	if(campo.value.length == 9 && event.keycode != 8)
	{
		campo.value = campo.value + "-";
	}
}
function Formata_Tel(campo)	
{	
	if(campo.value.length == 0 && event.keyCode != 15)
	{
		campo.value = campo.value + "(";
	}
	if(campo.value.length == 3 && event.keyCode != 15)
	{
		campo.value = campo.value + ")";
	}
	if(campo.value.length == 8 && event.keyCode != 15)
	{
		campo.value = campo.value + "-";
	}
}
//===============================================================================================================================
// Adicionadas


function isNum( caractere )   
{ 
 		var strValidos = "0123456789-()";
 		if ( strValidos.indexOf( caractere ) == -1 ) 
 			return false; 
 		return true;   
} 

function isString( caractere )   
{ 
 		var strValidos = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWYãÃõÕ";
 		if ( strValidos.indexOf( caractere ) == -1 ) 
 			return false; 
 		return true;   
} 

// Validação de Teclas
function validaTeclaString(campo, event) 
{ 
	var BACKSPACE= 8;
	var key;
	var tecla;
	CheckTAB=true;
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla= event.which;
	else
		tecla= event.keyCode;
	key = String.fromCharCode( tecla);
	if ( tecla == 13 )
		return false;
	if ( tecla == BACKSPACE )
		return true;
	return ( isString(key));
}
 
function validaTecla(campo, event) 
{ 
	var BACKSPACE= 8;
	var key;
	var tecla;
	CheckTAB=true;
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla= event.which;
	else
		tecla= event.keyCode;
	key = String.fromCharCode( tecla);
	if ( tecla == 13 )
		return false;
	if ( tecla == BACKSPACE )
		return true;
	return ( isNum(key));
}

// Validação numerica
function validaNum(campo, event)
{
	var caract = new RegExp(/^[0-9a-zA-Z]+$/i);
	var caract = caract.test(String.fromCharCode(event.keyCode));
	if(!caract){
	   event.keyCode=0;
	   return;
	}
}

//Formata RG
function FormataRG(campo)
{	
	if(campo.value.length == 2 && event.keyCode != 12)
	{
		campo.value = campo.value + ".";
	}
	
	if(campo.value.length == 6 && event.keyCode != 12)
	{
		campo.value = campo.value + ".";
	}
	
	if(campo.value.length == 10 && event.keyCode != 12)
	{
		campo.value = campo.value + "-";
	}
}

//Formata RG

function FormataCPF(campo)
{	
	if(campo.value.length == 3 && event.keyCode != 12)
	{
		campo.value = campo.value + ".";
	}
	
	if(campo.value.length == 7 && event.keyCode != 12)
	{
		campo.value = campo.value + ".";
	}
	
	if(campo.value.length == 11 && event.keyCode != 12)
	{
		campo.value = campo.value + "-";
	}
}

/******************MENU*************************************/

/**************************TRATIVAS*************************/
/*Valida CPF*/
	  function ValidaCPF() {
      var i, senha; 
      s = document.Cadastro.txtCPF.value; 
      var c = s.substr(0,9); 
      var dv = s.substr(9,2); 
      var d1 = 0;
	  if( isNaN( s ) )
	  {
	    alert( "Digite somente números" );
		document.Cadastro.txtCPF.focus();
		document.Cadastro.txtCPF.style.background="#cccccc";
		return false;
	  }
	   
      for (i = 0; i < 9; i++) 
      { 
        d1 += c.charAt(i)*(10-i); 
      } 
      if (d1 == 0)
	  { 
        alert("CPF Invalido")
		document.Cadastro.txtCPF.focus();
		document.Cadastro.txtCPF.style.background="#cccccc"; 
        return false; 
      } 
      d1 = 11 - (d1 % 11); 
      if (d1 > 9) d1 = 0; 
      if (dv.charAt(0) != d1) 
      { 
        alert("CPF Invalido") 
		document.Cadastro.txtCPF.focus();
		document.Cadastro.txtCPF.style.background="#cccccc"; 
        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) 
      { 
        alert("CPF Invalido");
		document.Cadastro.txtCPF.focus();
		document.Cadastro.txtCPF.style.background="#cccccc"; 
        return false; 
      } 
	  
	  senha = document.ConfirmaCPF.txtSenha.value;
	  if( senha.length == 0 )
	  {
	    alert( "Informe a senha" );
		document.Cadastro.txtCPF.focus();
		document.Cadastro.txtCPF.style.background="#cccccc";
		return false;
	  }
	  
	  //alert("OK");
	  return true;
	  }
	  /*Fim Função*/
	  
	  function Verificar()
      {
        var Nome, Email, Telefone, RG, Cpf, Area, DtNasc, Escolaridade, Curriculum, Senha, Senha2;
        
		Nome = document.Cadastro.txtNome.value;
		if( Nome.length == 0 )
		{
		  alert( "Favor digite seu nome" );
		  document.Cadastro.txtNome.focus();
		  document.Cadastro.txtNome.style.background = "#cccccc";
		  return false;
		}
		
		Email = document.Cadastro.txtEmail.value;
		if( Email.length == 0 )
		{
		  alert( "Informe o Email" );
		  document.Cadastro.txtEmail.focus();
		  document.Cadastro.txtEmail.style.background = "#cccccc";
		  return false;
		}  
		if( Email.indexOf("@") == -1 )
		{
		  alert( "Email inválido" );
	      document.Cadastro.txtEmail.focus();
		  document.Cadastro.txtEmail.style.background = "#cccccc";
		  return false;
		}
		
		Telefone = document.Cadastro.txtTel.value;
		if( Telefone.length == 0 )
		{
		  alert( "Informe seu telefone" );
		  document.Cadastro.txtTel.focus();
		  document.Cadastro.txtTel.style.background = "#cccccc";
		  return false;
		}
		
		RG = document.Cadastro.txtRG.value;
	    if( RG.length == 0 )
	    {
	      alert( "Informe seu RG" );
		  document.Cadastro.txtRG.focus();
		  document.Cadastro.txtRG.style.background = "#cccccc";
		  return false;
	    }
		
		Cpf = document.Cadastro.txtCPF.value;
		if( Cpf.length == 0 )
		{
		  alert( "Informe seu CPF" );
		  document.Cadastro.txtCPF.focus();
		  document.Cadastro.txtCPF.style.background = "#cccccc";
		  return false;
		}
		
		DtNasc = document.Cadastro.txtDtNascimento.value;
		if( DtNasc.length == 0 )
		{
		  alert( "Informe sua Data de Nascimento" );
		  document.Cadastro.txtDtNascimento.focus();
		  document.Cadastro.txtDtNascimento.style.background = "#cccccc";
		  return false;
		}
		
		Area = document.Cadastro.txtAreaPretendida.value;
		if( Area == "Área de Interesse" )
		{
		  alert( "Informe a área de seu interesse" );
		  document.Cadastro.txtAreaPretendida.focus();
		  return false;
		}
		
		Escolaridade = document.Cadastro.txtEscolaridade.value;
		if( Escolaridade == "" )
		{
		  alert( "Informa sua escolaridade" );
		  document.Cadastro.txtEscolaridade.focus();
		  return false;
		}
		
		/*Curriculum = document.Cadastro.txtConhecimentos.value;
		if( Curriclulum == "" )
		{
		  alert( "Preencha seu mini curriculum" );
		  document.Cadastro.txtConhecimentos.focus();
		  return false;
		}*/
		
		Senha = document.Cadastro.txtSenha.value;
		if( Senha.length == 0 )
		{
		  alert( "Informe uma senha" );
		  document.Cadastro.txtSenha.focus();
		  document.Cadastro.txtSenha.style.background = "#cccccc";
		  return false;
		}
		Senha2 = document.Cadastro.txtSenha2.value;
		if( Senha2.length == 0 )
		{
		  alert( "Informe a confirmação da senha" );
		  document.Cadastro.txtSenha.focus();
		  document.Cadastro.txtSenha.style.background = "#cccccc";
		  return false;	
		}
				
        //alert( 'Dados enviados com sucesso' );
		document.Cadastro.submit();
		//window.close();
      }
	  
	  /*Verifica Senha*/
	  function VerificaSenha()
	  {
	    var Senha, ConfirmaSenha;
		Senha = document.Cadastro.txtSenha.value;
		ConfirmaSenha = document.Cadastro.txtSenha2.value;
		
		//alert( "Senha " + Senha + " Confirma " + ConfirmaSenha );
		if( Senha != ConfirmaSenha )
		{
		  alert( 'A senha está diferente da confirmação' );
          document.Cadastro.txtSenha.value = "";
		  document.Cadastro.txtSenha2.value = "";
		  document.Cadastro.txtSenha.focus();
		  document.Cadastro.txtSenha.style.background = "#cccccc";
		  document.Cadastro.txtSenha2.style.background = "#cccccc";
		  return false;
		}
		else
		{
		  return true;
		}
	  }
	  /*Fim*/
