function valemail(str){
var notvalid="``*}{[]$%&/|\«»,<>^;:?!£#=¨ºª\"\'()\\";
var arrobindex = str.indexOf("@");

var str1=str.substring(0, arrobindex);
var str23=str.substring(arrobindex+1, str.length);

var pontoindex = str23.lastIndexOf(".");

var str2=str23.substring(0, pontoindex);
var str3=str23.substring(pontoindex+1, str23.length);

var ok = "yes";
var temp;

if (str!='') {
for (var i=0; i<str.length; i++) {
	temp = "" + str.substring(i, i+1);
	if (notvalid.indexOf(temp) != "-1") ok = "no";
	}
if ((arrobindex=="-1") || (str1=="") || (pontoindex=="-1") || (str3.length<2) || (str3.length>3) || (ok == "no")) {
	alert("Preencha um Email Válido!");
	return false;   }
else return true;
}
else return true;
}

function testa(campo){
	fcampo=eval("document.fcontactos." + campo)
	fimagem=eval("document.ast_" + campo)
	if (fcampo.value=="") {
		resposta+=campo + "\n";
		fimagem.src="images/ast_vermelho.gif";
		return false;
	} else { 
		fimagem.src="images/ast_cinza.gif";
		return true;
	}
}



function obrigatorios(){
	sfalse=0;
	resposta="Os campos sequintes são obrigatórios:\n";
	
	if (testa("empresa")==false) {sfalse=1;}
	if (testa("nome")==false) {sfalse=1;}
	if (testa("email")==false) {sfalse=1;}
	if (valemail(document.fcontactos.email.value)==false) {sfalse=1;}
	if (testa("assunto")==false) {sfalse=1;}
	if ((document.fcontactos.telefone.value=="") && (document.fcontactos.telemovel.value=="")) {
		sfalse=1;
		resposta+="\n\nDeve preencher o telefone ou o telemóvel.\r\n";
		//alert("Deve preencher o telefone ou o telemóvel.");
	}
	if (sfalse) {alert(resposta);return false;}
	return true;
}

