function checkEmail(str)
{
	var at="@"; var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (lat<1 || lat==lstr)
	{
		return false;
	}	//no @ or a leading @ or @ at the end
	
	if ( ldot<1 ||  ldot==lstr)
	{
		return false;
	} //no . or a leading . or . at the end
	
	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false;
	}	//more than one @
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false;
	}
	
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false;
	}
	
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}	//no blank
return true;
}

function validarNewsletter()
{
	var form = document.forms["news"];
	
	if (form.Nome.value == "" || form.Nome.value == "Nome")
	{
		window.alert("Preencha o campo nome.");
		form.Nome.focus();
		return false;
	}
	
	if (!checkEmail(form.Email.value))
	{
		alert("Verifique o seu endereço de e-mail.");
		form.Email.focus();
		return false;
	}
	
	return true;
}

function validarIndique()
{
	var form = document.forms["indique"];
	
	if (form.Nome.value == "" || form.Nome.value == "Seu nome")
	{
		window.alert("Preencha o campo nome.");
		form.Nome.focus();
		return false;
	}
	
	if (!checkEmail(form.Email.value))
	{
		alert("Verifique o seu endereço de e-mail.");
		form.Email.focus();
		return false;
	}

	if (form.recipient.value == "" || form.recipient.value == "E-mail do amigo")
	{
		window.alert("Preencha o campo e-mail do amigo.");
		form.recipient.focus();
		return false;
	}
	
	return true;
}

function validarContato()
{
	var form = document.forms["contato"];
	
	if (form.Nome.value == "")
	{
		window.alert("Preencha o campo nome.");
		form.Nome.focus();
		return false;
	}
	
	if (!checkEmail(form.Email.value))
	{
		alert("Verifique o seu endereço de e-mail.");
		form.Email.focus();
		return false;
	}

	if (form.Sexo[0].checked == false && form.Sexo[1].checked == false)
	{
		window.alert("Selecione o seu sexo.");
		form.Sexo[0].focus();
		return false;
	}
	
	if (form.Estado.value == "")
	{
		window.alert("Selecione o seu estado.");
		form.Estado.focus();
		return false;
	}

	if (form.Cidade.value == "")
	{
		window.alert("Preencha o campo cidade.");
		form.Cidade.focus();
		return false;
	}

	if (form.DDD.value == "")
	{
		window.alert("Preencha o campo DDD.");
		form.DDD.focus();
		return false;
	}

	if (form.Telefone.value == "")
	{
		window.alert("Preencha o campo telefone.");
		form.Telefone.focus();
		return false;
	}

	if (form.Contato.value == "")
	{
		window.alert("Selecione o tipo de contato.");
		form.Contato.focus();
		return false;
	}

	if (form.Comentário.value == "")
	{
		window.alert("Preencha o campo comentários.");
		form.Comentário.focus();
		return false;
	}
	
	return true;
}

function contaCaracter(opt_boxcontado, opt_contarcorpo, opt_valormax)
{
	var boxcontado = opt_boxcontado ? opt_boxcontado : "contado";
	var contarcorpo = opt_contarcorpo ? opt_contarcorpo : "contador";
	var valormax = opt_valormax ? opt_valormax : 150;
	var field = document.getElementById(boxcontado);
	
	if (field && field.value.length >= valormax)
	{
		field.value = field.value.substring(0, valormax);
	}
	var txtField = document.getElementById(contarcorpo);
	
	if (txtField)
	{
		txtField.innerHTML = opt_valormax - field.value.length;
	}
}
 
function sem_letras()
{
	navegador = /msie/i.test(navigator.userAgent);
	
	if (navegador)
	{
		if ((window.event.keyCode < 48) | (window.event.keyCode > 57))
		{
			window.event.keyCode = 0
		}
	}
	else
	{
		if ((event.keyCode < 48) | (event.keyCode > 57))
		{
			event.keyCode = 0
		}
	}
}
 
function mascTel(id)
{
	if(document.getElementById(id).value.length == "4")
	{
		document.getElementById(id).value += "-";
	}
	
	if(document.getElementById(id).value.length == "9")
	{
		document.getElementById(id).value;
	}
}
