
function soNumeros(evt) {
      if (document.all) { // IE
	  	var key = event.keyCode;
	  } else { // Firefox
	  	var key = evt.charCode;
	  }
	  //var chr = String.fromCharCode(evt); // pegando a tecla digitada
	  // Se o código for menor que 20 é porque deve ser caracteres de controle
      // ex.: <ENTER>, <TAB>, <BACKSPACE> portanto devemos permitir
      // as teclas numéricas vão de 48 a 57
      if ((key<20 ) || ((key >47) && (key<58))) {
	    tecla=key;
	  	return true;
	  }
      
	  return false;
}

function mascaraData(campo) {
		if (tecla>=20) {
			if (campo.value.length==2) {
				campo.value = campo.value + "/";
			}
			if (campo.value.length==5) {
				campo.value = campo.value + "/";
			}
		}
}


$(document).ready(function(){	
	// chamada ajax do formulário
	// seta todos os links com chamadas ajax
	
	function submitForm(){
	      var inputs = [];
	      
	      var ok = true;

	      $(":input", $(this)).each(function() {
              if (($(this).attr("alt")=="obrigatorio")) {
			    if (($(this).attr("value")=="") || ($(this).attr("value")==null)) {
	    			alert("Preencha o campo obrigatório.");
		 			$(this).focus();
		 			ok = false;
		 			return false;
				}
				if ($(this).attr("value").length<10) {
	    			alert("Preencha a data no formato: XX/XX/XXXX");
		 			ok = false;
		 			return false;
				}
		      }
	      });
	      
	      if (!ok)
	      	return false;
	      	
	      ok = true;	
	      $(".campoemail").each(function(){
	      	var email = $(this).attr("value");
			
			if ((email!=null)) {
				if(!((email.indexOf("@") > -1) && (email.substring(email.indexOf("@")+1).indexOf(".") > -1))){
				    alert("O formato de email não é válido."); 
				    $(this).focus();
				 	ok = false;
				 	return false;
				}
			}
	      });
	      if (!ok)
	      	return false;
	}
	
	$("#form").submit(submitForm);

	$.datepicker.setDefaults({showOn: 'button', 
	                          buttonImageOnly: true,
	                          yearRange: '1900:2100',
	                          buttonImage: 'lib/js/datepicker/calendar.gif',
	                          buttonText: 'Calendário',
	                          dateFormat: 'dd/mm/yy'});
	$(".campodt").datepicker();
});

	