// JavaScript Document
function emailValido (email){
	invalidChars = " /:,;";
	if (email == "") return false;
	for (i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1) return false;
	}
   atPos = email.indexOf("@",1);
	if ((atPos == -1) || (email.indexOf("@",atPos+1) != -1)) return false;
	periodPos = email.indexOf(".",atPos);
	if ((periodPos == -1) || (periodPos+3 > email.length)) return false;
	return true;
}
function enviar_ok(f){

	var cor = "FFFFFF";
	f.Nome.style.background = cor;
	f.Idade.style.background = cor;
	f.Cidade.style.background = cor;
	f.Texto_opinao.style.background = cor;
	f.email.style.background = cor;
	
	cor = "F3F3F3";
	
	if(f.Nome.value == ""){
		alerta("Ops!","Digite seu nome!");
		f.Nome.style.background = cor;
		f.Nome.focus();
		return false;
	}
	if(f.Idade.value == ""){
		alerta("Ops!","Digite sua Idade!");
		f.Idade.style.background = cor;
		f.Idade.focus();
		return false;
	}
	if(f.Cidade.value == "" || f.UF.value == ""){
		alerta("Ops!","Digite a Cidade e o Estado");
		if(form_sendtofriend.Cidade.value == ""){
			f.Cidade.style.background = cor;
			f.Cidade.focus();
		}else{
			f.UF.style.background = cor;
			f.UF.focus();
		}
		return false;
	}
	
	if (emailValido(f.email.value)==false){
		alerta("Ops!","Digite um e-mail válido!");
		f.email.style.background = cor;
		f.email.focus();
		return false;
	}
	
	if(f.Texto_opinao.value == "" || f.Texto_opinao.value == " "){
		alerta("Ops!","Digite sua mensagem!");
		f.Texto_opinao.style.background = cor;
		f.Texto_opinao.focus();
		return false;
	}

	var text_opin = '';
	text_opin = '|||' + f.Nome.value;
	text_opin += '|||' + f.Idade.value;
	text_opin += '|||' + f.Cidade.value + '/' + f.UF.value;
	text_opin += '|||' + f.Texto_opinao.value;
	cookies.criar('opine',text_opin,0);
	return true;
}
function mascara(o,f){
	v_obj=o;
	v_fun=f;
	setTimeout("execmascara()",1);
}
function execmascara(){
	v_obj.value=v_fun(v_obj.value);
}
function numero(v){
	v=v.replace(/\D/g,"");
	v=v.replace(/^(\d\d)(\d)/g,"($1) $2");
	v=v.replace(/(\d{4})(\d)/,"$1-$2");
	return v;
}
