//Função que faz a submissão de um formulário
function sendForm(frm)        {
  frm.submit();
}

//Função que faz a validação dos campos obrigatórios do formulário 
function checkForm(theForm)
{
	var regexp = /\@(.*)\./
	if (!regexp.test(theForm.txtEmail.value))
	{
		alert('O campo E-mail não foi correctamente intoduzido.');
		theForm.txtEmail.focus();
		return (false);
	}

	if (theForm.txtPass1.value.length == 0 || theForm.txtPass2.value.length == 0 )
	{
		alert("Os campos não podem ficar a vazios...");
		theForm.txtPass1.focus();
		return (false);
	}

	if (theForm.txtPass1.value != theForm.txtPass2.value)
	{
		alert("As passwords não são iguais...");
		theForm.txtPass1.focus();
		return (false);
	}

	if (theForm.txtNome.value == "")
	{
		alert("O campo \"Nome\" é obrigatório..");
		theForm.txtNome.focus();
		return (false);
	}
	
	if (theForm.txtMorada.value == "")
	{
		alert("O campo \"Morada\" é obrigatório..");
		theForm.txtMorada.focus();
		return (false);
	}
	
	var regexp = /[1-9]\d\d\d\-\d\d\d/
	if (!regexp.test(theForm.txtCodPostal.value))
	{
		alert('O campo Codigo Postal não foi correctamente intoduzido.');
		theForm.txtCodPostal.focus();
		return (false);
	}
	
	if (theForm.txtLocal.value == "")
	{
		alert("O campo \"Morada\" é obrigatório..");
		theForm.txtMorada.focus();
		return (false);
	}
	
	  if (theForm.txtTelefone.value != "")
	  {
		  var checkOK = "0123456789";
		  var checkStr = theForm.txtTelefone.value;
		  var allValid = true;
		  var decPoints = 0;
		  var allNum = "";
		  for (i = 0;  i < checkStr.length;  i++)
		  {
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
			  if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
			  allValid = false;
			  break;
			}
			allNum += ch;
		  }	
	 }

//O formulário foi correctamente validado
 	return (true);
}
