function checkform(form){
    var text=document.forms[form];
    if(text.nome.value==""){
        alert("Nome e uma campo obrigatorio.");
        text.nome.focus();
		return false;
    }
    if (text.email.value=="") {
        alert("Email é um campo obrigatorio.");
        text.email.focus();
		return false;
	}
    if (isEmail(text.email.value)==false) {
        alert("verifique a sintaxe do email.");
		return false;
	}
    /*
    if (text.num_ordem.value=="") {
        alert("Número e uma campo obrigatorio.");
        text.num_ordem.focus();
		return false;
	}
    if (text.bi_num.value=="") {
        alert("Numero de BI é uma campo obrigatorio.");
        text.bi_num.focus();
		return false;
	}
    if (text.nacionalidade.value=="") {
        alert("Nacionalidade é um campo obrigatorio.");
        text.nacionalidade.focus();
		return false;
	}
    if (text.naturalidade.value=="") {
        alert("Naturalidade e campo obrigatorio.");
        text.naturalidade.focus();
		return false;
	}
    if (text.nascimento.value=="") {
        alert("Data de Nascimento e um campo obrigatorio.");
        text.nascimento.focus();
		return false;
	}
    if (text.emissao.value=="") {
        alert("Data de Emissao e um campo obrigatorio.");
        text.emissao.focus();
		return false;
	}
    if (text.empresa.value=="") {
        alert("Empresa e um campo obrigatorio.");
        text.empresa.focus();
		return false;
	}
    if (text.morada.value=="") {
        alert("Morada e um campo obrigatorio.");
        text.morada.focus();
		return false;
	}
    if (text.contribuinte.value=="") {
        alert("Contribuinte e um campo obrigatorio.");
        text.contribuinte.focus();
		return false;
	}
    if (text.cod_postal.value=="") {
        alert("Codigo Postal e um campo obrigatorio.");
        text.cod_postal.focus();
		return false;
	}
    if (text.concelho.value=="") {
        alert("Concelho e um campo obrigatorio.");
        text.concelho.focus();
		return false;
	}
    if (text.telefone.value=="" && text.telemovel.value=="") {
        alert("Deve preencher um dos campos: (Telefone/Telemovel).");
        text.telefone.focus();
		return false;
	}
    */

    text.submit();
}
// Email address must be of form a@b.c
function isEmail (s){
	if (isEmpty(s)){return true;}
    	// is s whitespace?
    	if (isWhitespace(s)){return true;}

    	// there must be >= 1 character before @, so we
    	// start looking at character position 1
    	// (i.e. second character)
    	var i = 1;
    	var sLength = s.length;

    	// look for @
    	while ((i < sLength) && (s.charAt(i) != "@"))
    	{ i++
    	}

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
// fim da funcao isEmail

function isWhitespace (s)
{
    var whitespace = " \t\n\r";
    var i;

    // Is s empty?
    if (isEmpty(s)){return true;}

    // Search through characters one by one
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
} // fim da funcao Whitespace

// Check whether string s is empty.
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
