// JavaScript Document

function fnSubmit()
{
	
	var form=document.getElementById("form");
	
	var er_email = /^[a-z._\-]{2,50}@[a-z_\-]{2,50}\.[a-z]{2,3}[a-z.]{0,3}$/;
	
	var nome = document.getElementById("nome");
	var cidade = document.getElementById("cidade");
	var email = document.getElementById("email");
	var assunto = document.getElementById("assunto");
	var mensagem = document.getElementById("mensagem");
	
	if(0==trimAll(nome.value).length)
	{
		window.alert("Informe seu nome!");
		nome.focus();
	}
	else if(0==trimAll(cidade.value).length)
	{
		window.alert("Informe a cidade!");
		cidade.focus();
	}
	else if(!er_email.test(email.value))
	{
		window.alert("Informe um e-mail válido!");
		email.focus();
	}
	else if(0==trimAll(assunto.value).length)
	{
		window.alert("Informe o assunto!");
		assunto.focus();
	}
	else if(0==trimAll(mensagem.value).length)
	{
		window.alert("Informe a mensagem!");
		mensagem.focus();
	} 
	else 
	{		
		form.submit();
	}
}

//elimina espaços em branco no inicio e no final da string
function trimAll(sString){
	var sString = new String(sString);
	while (sString.substring(0,1) == " "){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == " "){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}