// Validacao
function v_email( campo )
{
	if( campo.length < 3 )
	{
		alert("O Campo E-mail deve ser preenchido");
		return false;
	}
	else if(  campo.indexOf('@') == -1 )
	{
		alert("E-mail invalido");
		return false;
	}
	else if( campo.indexOf('@') != campo.lastIndexOf('@') )
	{
		alert("E-mail invalido");
		return false;
	}
	else if( campo.indexOf('@') > campo.lastIndexOf('.') )
	{
		alert("E-mail invalido");
		return false;
	}
	else
	{
		return true;
	}
}	

// -----------------------------------------------------------------

function validarContato()
{
	with( document.getElementById('formContato') )
	{

		// nome
		if( nome.value.length == 0 )
		{
			alert("O campo 'Nome' deve ser preenchido");
			nome.focus();
			return false;	
		}
		if( isNaN( nome.value ) == false)
		{
			alert("O 'Nome' Não pode conter número");
			nome.focus();
			return false;
		}
		
		// assunto
		if( assunto.value.length == 0 )
		{
			alert("Determine o 'Assunto'");
			assunto.focus();
			return false;	
		}
				
		
		// email
		if( v_email( email.value ) == false )
		{
			email.focus();
			return false;	
		}
		
		// telefone
		if( telefone.value.length == 0 )
		{
			alert("O campo 'telefone' deve ser preenchido");
			telefone.focus();
			return false;	
		}

		// mensagem
		if( mensagem.value.length == 0 )
		{
			alert("O campo 'Mensagem' deve ser preenchido");
			mensagem.focus();
			return false;	
		}
	}
}


//------------------ EXIBIR OU OCULTAR O FORMULARIO --------------
function mostrarOcultar( idObj )
{
	var obj = document.getElementById( idObj );
	
	if( obj.style.display == 'none' )
	{
		obj.style.display = '';
	}
	else
	{
		obj.style.display = 'none';
	}
}

//---------------------------------------------------

function formataTexto( obj )
{
	var Max 	= 200;
	var nChar	= obj.value.length;	
	var txt 	= "<b>Caracteres: </b>"; 
				
	obj.value 	= obj.value.substr(0,Max); 
	
	if( nChar >= Max)
	{
		nChar = Max;
	}
	
	txt += nChar + " de " + Max;
	
	document.getElementById('txtMensagem').innerHTML = txt;
}

