function inicia(){
      var pagina='validacao.php'
	  var my = new Ajax.Updater(
		    {success: 'retorno'},	// div de retorno
        		pagina,
		    {
			    method: 'post',
				parameters: $('cadastro').serialize(),
				encoding: 'iso-8859-1',
				onFailure: retiraCarr,
			    onCreate: mostraCarr,
			    onComplete: retiraCarr,
			    evalScripts: true
	  });
}
function mostraCarr() {
    car = document.createElement('div');
	car.id = 'carregando';
	car.innerHTML = 'Enviando email...';
	document.body.appendChild(car);
}

function retiraCarr() {
    if ($('carregando'))
	document.body.removeChild($('carregando'));
	$('teste').reset();
}
function validaForm(){
           if (document.getElementById("nome").value == ""){
                     alert("Você deve informar seu nome!");
                     document.getElementById("nome").focus();
                     return false;
           }
           if (document.getElementById("assunto").value == ""){
                     alert("Você deve informar o assunto!");
                     document.getElementById("assunto").focus();
                     return false;
           }		   
           if (document.getElementById("email").value == ""){
                     alert("Você deve informar seu email!");
                     document.getElementById("email").focus();
                     return false;
           }
		   parte1 = document.getElementById("email").value.indexOf("@");
			parte2 = document.getElementById("email").value.indexOf(".");
			parte3 = document.getElementById("email").value.length;
			if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
					alert ("O campo do email deve conter um endereço válido");
					document.getElementById("email").focus();
					return false;
			}
           if (document.getElementById("mensagem").value == ""){
                     alert("Você deve informar a mensagem!");
                     document.getElementById("mensagem").focus();
                     return false;
           }
	return true;
}
function contadorAtualiza(opt_boxcontado, opt_contarcorpo, opt_valormax) {
  var boxcontado = opt_boxcontado ? opt_boxcontado : "mensagem";
  var contarcorpo = opt_contarcorpo ? opt_contarcorpo : "cont";
  var valormax = opt_valormax ? opt_valormax : 300;

  var field = document.getElementById(boxcontado);
  if (field && field.value.length >= valormax) {
    field.value = field.value.substring(0, valormax);
  }
  var txtField = document.getElementById(contarcorpo);
  if (txtField) {
    txtField.innerHTML = field.value.length;
  }
}
