function isBlank(element, display_message){
	if(element.value.length == 0){
		element.focus();
		element.select();
		alert(display_message);
		return true;
	}
	return false;
}

function selectIsBlank(element, display_message){
	if(element.selectedIndex == 0){
		element.focus();
		//element.select();
		alert(display_message);
		return true;
	}
	return false;
}


function isEMail(element, display_message){
//--- verifica se foi inserido o simbolo "@" de email
	var sourceStr = element.value;
   var n; //indice de @ na string
	var dominio;  //String resultante da "@" para a frente
	var i; //interador da string dominio
	var contaPtos=0; //conta pontos na string dominio
	var indexPto //indice do ponto na string dominio
	
	
	n = sourceStr.search("@");
	if( n < 1 ){
		element.focus();
		element.select();
		alert(display_message);
		return false;
	}
	
	dominio=sourceStr.slice(n+1,sourceStr.length);
	
	for(i=0;i<=dominio.length;i++){
		if(dominio.charCodeAt(i)==46){
			contaPtos++;
			indexPto=i;
			}
		}	
	if(indexPto==dominio.length-1 || contaPtos==0 || dominio.charCodeAt(0)==46){
		element.focus();
		element.select();
		alert(display_message);
		return false;
	}
		   
	return true
}

function IsNotNum(element, display_message)
{
	valor=element.value;
	if(isNaN(valor)){
		element.focus();
		element.select();
		alert(display_message);
		return true;
	}
	else
		return false;
}




function valida(){
	var c=document.contacto
	if (isBlank(c.nome, "O campo 'Nome' é de preenchimento obrigatório."))
		return false
	
	if (isBlank(c.telefone, "O campo 'Telefone' é de preenchimento obrigatório."))
		return false
	
	if (isBlank(c.email, "O campo 'E-mail' é de preenchimento obrigatório."))
		return false
		
	if(c.email.value.length!=0){
		if(!isEMail(c.email, "O E-mail inserido não tem um formato válido"))
			return false
		}
	
	if (isBlank(c.assunto, "O campo 'Assunto' é de preenchimento obrigatório."))
		return false
		
	if (isBlank(c.mensagem, "O campo 'Mensagem' é de preenchimento obrigatório."))
		return false				
		
	return true
}
