String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function verificar_campos_Adesao(theForm)
{
	var strTemp;

	strTemp = new String(theForm.nome.value);
	if (strTemp.trim().length == 0)
	{
		alert("Por favor introduza o seu Nome.");
		theForm.nome.focus();
		return false;
	}
	
	strTemp = new String(theForm.empresa.value);
	if (strTemp.trim().length == 0)
	{
		alert("Por favor introduza a Empresa a que pertence.");
		theForm.nome.focus();
		return false;
	}
	
	strTemp = new String(theForm.eMail.value);
	if (strTemp.trim().length == 0)
	{
		alert("Por favor introduza o seu Email.");
		theForm.nome.focus();
		return false;
	}

	if (checkemail(theForm) == false)
	{
		theForm.eMail.focus();
		return false;
	}

}

function verificar_campos_form5(theForm)
{
	
	var strTemp, strTemp1;
	
	strTemp = new String(theForm.empresa.value);
	//alert (strTemp);
	if (strTemp.trim().length == 0)
	{
		alert("Por favor introduza o nome da Empresa.");
		theForm.empresa.focus();
		return false;
	}
	
	strTemp = new String(theForm.telefone.value);
	strTemp1 = new String(theForm.email.value);

	if ((strTemp.trim().length == 0) && (strTemp1.trim().length == 0))
	{
		alert ("Por favor introduza o número de Telefone ou o e-mail.");
		theForm.telefone.focus();
		return false;
	}
	else if (strTemp1.trim().length != 0)
	{
		if (checkemail(theForm) == false)
		{	
			theForm.email.focus();
			return false;
		}
	}
	
	//alert ("strTemp");
	/*if (strTemp.trim().length == 0)
	{
		alert ("Por favor introduza o número de Telefone.");
		theForm.telefone.focus();
		return false;
	}

		strTemp = new String(theForm.email.value);
	if (strTemp.trim().length != 0)
	{
		if (checkemail(theForm) == false)
		{	
			theForm.email.focus();
			return false;
		}
	}
	*/
	strTemp = new String(theForm.nomeresp.value);
	if (strTemp.trim().length == 0)
	{
		alert ("Por favor introduza o Nome do Responsável.");
		theForm.nomeresp.focus();
		return false;
	}
	if (isNaN(strTemp) == false)
	{
		alert ("O campo Nome do Responsável não é válido.");
		theForm.nomeresp.focus();
		return false;
	}

	strTemp = new String(theForm.cp1.value);
	if (isNaN(strTemp) == true)
	{
		alert ("O primeiro campo do código de postal não é válido.");
		theForm.cp1.focus();
		return false;
	}

	strTemp = new String(theForm.cp2.value);
	if (isNaN(strTemp) == true)
	{
		alert ("O segundo campo do código de postal não é válido.");
		theForm.cp2.focus();
		return false;
	}


}

var testresults

function checkemail(theForm)
{
	var str = theForm.email.value
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str))
		testresults=true
	else
	{
		
		alert("Por favor, preencha correctamente o campo de e-mail")
		testresults=false
		theForm.email.focus();
	}
	return testresults;
}

function ValidateSearch(frmSearch)
{
	var strTemp;

	strTemp = new String(frmSearch.search.value);
	if (strTemp.trim().length <= 2) {
		alert("Por favor, introduza uma palavra com mais de 2 letras.");
		return(false);
	}
	else {
		return(true);
	}
}
