function HabCampos() {
  if (document.getElementById('Orcamento').checked) {
	  
    document.getElementById('campos').style.display = "";
	document.getElementById('txtDtEvento').focus();
	
  }
  else {
    document.getElementById('campos').style.display = "none";
  }
}


function txtBoxFormat(objeto, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}
sValue = objeto.value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;
i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;
while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}
i++;
}
objeto.value = sCod;
if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}


function CheckEmail(email)
{
   var achou_ponto=false;
   var achou_arroba=false;
   var nao_achou_espaco=false;

   for (var i=0; i < email.length; i++)
   {
      if (email.charAt(i)=="@")
      { 
         if (email.charAt(i+1)==".") achou_arroba=false;
         else achou_arroba=true;
      }
      else if (email.charAt(i)==".") achou_ponto=true;
      else if (email.charAt(i)!=" ") nao_achou_espaco=true;
   }
   
   if(email.charAt(email.length-1)==".") achou_ponto=false;
   
   
   
   if (achou_ponto && achou_arroba && nao_achou_espaco) return true;
   else
   {      
      return false;  
   }
}

function verifica(){
	with(document.form1){
		if (txtNome.value == "") {
			alert('O Campo NOME é de preenchimento obrigatório.');
			txtNome.focus();
			return false;
		}
		
		/*if (txtTel.value != ""){
			if (!isTelefone(txtTel.value)) {
				alert('Número de telefone inválido.');
				txtTel.focus();
				return false;
			}		
		}*/
		
				
		if (txtEmail.value == "") {
			alert('O Campo E-MAIL é de preenchimento obrigatório.');
			txtEmail.focus();
			return false;
		}else{
			if (!(CheckEmail(txtEmail.value))){
				alert('E-mail inválido!');
				txtEmail.focus();
				return false;
			}
		}
		
		if (txtDtEvento.value != "") {
			if (!isData(txtDtEvento.value)) {
				alert('Data prevista do evento é inválida.');
				txtDtEvento.value == ""
				txtDtEvento.focus();
				return false;
			}
		}

		
		if (txtMensagem.value == "") {
			alert('O Campo MENSAGEM é de preenchimento obrigatório.');
			txtMensagem.focus();
			return false;
		}
			
	}

}

function isData(pVal)
{
	var reTipo = /^((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}$/;

	return reTipo.test(pVal);
}

function isNumerico(pVal)
{
	var reTipo = /^\d+$/;
	return reTipo.test(pVal);
}


function isTelefone(pVal)
{
	aux = pVal.replace("(","");
	aux2 = aux.replace(")","");
	aux3 = aux2.replace("-","");	
	var reTipo = /^\d+$/;
	return reTipo.test(aux3);
}


function FormataTel(tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	var fvr = '';
	// ao invés de recuperar valor do campo utilizadno o form, vou
	// pegar pelo evento<b></b>
	vr = event.srcElement.value;
	for(i=0;i<vr.length;i++){
		ch=vr.charAt(i);
		if((ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")||(ch=="0")){
			fvr=fvr+ch;
		}
		}
		vr=fvr;		
	tam = vr.length ;
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
			event.srcElement.value = "("+vr
		}
		if ( tam > pos+2 && tam <= tammax ){
			event.srcElement.value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );
			txt=event.srcElement.value
			event.srcElement.value = "("+txt.substr(0,2)+")"+txt.substr(2,tam)
			
		}
	}
}


function FormataTel2(tammax,pos,teclapres){
	var fvr = '';
	// ao invés de recuperar valor do campo utilizadno o form, vou
	// pegar pelo evento<b></b>
	vr = event.srcElement.value;
	for(i=0;i<vr.length;i++){
		ch=vr.charAt(i);
		if((ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")||(ch=="0")){
			fvr=fvr+ch;
		}
		}
		vr=fvr;
		
	tam = vr.length ;
		if ((tam>0)&&(tam<=2)){
			event.srcElement.value = "("+vr
		}
		if ( tam > pos+2 && tam <= tammax ){
			event.srcElement.value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );
			txt=event.srcElement.value
			event.srcElement.value = "("+txt.substr(0,2)+")"+txt.substr(2,tam)
			
		}
}
