//-------------------------------
var foco = "DICAS";
var msgstatus = "";
var ImagemAtual = new Image();
//-------------------------------
// Muda a imagem com o Hover
function MudaImagem(MyImg, Imagem){
	ImagemAtual.src = Imagem;
   MyImg.src = ImagemAtual.src;
}
// Mensagem do tipo Alert
function aviso (campo, msg){
   alert(msg);
    campo.focus();
    return false;
}
// Verificar campo vazio
function isEmpty(s){
    return ((s == null) || (s.length == 0))
}
// Mensagem na barra de status (quando o campo está selecionado)
function hint (n,s){
   window.status = s;
   msgstatus = s;
   if ( n!='') foco = n;
}
// Não incluir caracter numérico
function ajustar_numero(input){
	if ((event.keyCode<48)||(event.keyCode>57))
		event.returnValue = false;
}
// Muda de campo quando atinge o seu tamanho
function VerficaTamanho(campo,tamanho,proximocampo){
 if (campo.value.length == tamanho)
 	proximocampo.focus();
}
// Verifica o E-mail no (onblur=verifica_email()) do campo
function verifica_email(){
	var f = document.form;

	if (!isEmpty(f.email.value)) {
	    if (!valida_mail(f.email.value)) {
   	  	  aviso(f.email,"Digite um E-mail válido!");
  		  return;
		}
	}
	if (isEmpty(f.email.value)) {
	return;
	}
}
// Valida o E-mail
function valida_mail(valor) {
	prim = valor.indexOf("@")
	if(prim < 2) return false;
	if(valor.indexOf("@",prim + 1) != -1) return false
	if(valor.indexOf(".") < 1) return false;
	if(valor.indexOf("zipmeil.com") > 0) return false;
	if(valor.indexOf("hotmeil.com") > 0) return false;
	if(valor.indexOf(".@") > 0) return false;
	if(valor.indexOf("@.") > 0) return false;
	if(valor.indexOf(".com.br.") > 0) return false;
	if(valor.indexOf("/") > 0) return false;
	if(valor.indexOf("[") > 0) return false;
	if(valor.indexOf("]") > 0) return false;
	if(valor.indexOf("(") > 0) return false;
	if(valor.indexOf(")") > 0) return false;
	if(valor.indexOf("..") > 0) return false;
	if(valor.indexOf(",") > 0) return false;
	if(valor.indexOf(".") == (valor.length - 1)) return false;
	return true;
}
// Função para colocar uma mensagem padrão na Barra de Status
window.status='MMIRio - Lutando pelas familias do Estado do Rio'

// Muda de Campo automaticamente quando atinge o tamanho máximo
// Telefone
var lentel = 0;
function MudaCampoTel(obj,dest)
{
	if (lentel > obj.value.length)
		dest.value = "";
	lentel = obj.value.length;
	if (obj.value.length == 13)
		dest.focus();
}

// Muda de Campo automaticamente quando atinge o tamanho máximo
// CEP
var lencep = 0;
function MudaCampoCep(obj,dest)
{
	if (lencep > obj.value.length)
		dest.value = "";
	lencep = obj.value.length;
	if (obj.value.length == 9)
		dest.focus();
}

//Formata número de telefone
var lineaux = "";
function formatLine(obj,e)
{
	if (navigator.userAgent.indexOf("IE") != -1)
	{
		var keypress = window.event.keyCode;
		if (keypress > 47 && keypress < 58 && obj.value.length < 13)
			{
			if (obj.value.length == 0) 
			   obj.value = "(" + obj.value;
			if (obj.value.length == 3) 
			   obj.value = obj.value + ")";
			if (obj.value.length == 8) 
			   obj.value = obj.value + "-";
			}
		else 
			event.returnValue = false;
	}
	else
	{
		lineaux = obj.value;
		var keypress = e.which;
		if (keypress == 8)
			return true;
		if ((keypress < 48 || keypress > 57) || obj.value.length >= 13)
			return false;
		if (lineaux.length == 0)
			lineaux = "(";
		if (lineaux.length == 3)
			lineaux = lineaux + ")";
		if (lineaux.length == 8)
			lineaux = lineaux + "-";
		lineaux = lineaux + (keypress - 48);
		obj.value = lineaux;
		return false;				
	}
	return true;
}

//Formata número do CEP
var lineaux = "";
function formatLineCep(obj,e)
{
	if (navigator.userAgent.indexOf("IE") != -1)
	{
		var keypress = window.event.keyCode;
		if (keypress > 47 && keypress < 58 && obj.value.length < 13)
			{
			if (obj.value.length == 5) 
			   obj.value = obj.value + "-";
			}
		else 
			event.returnValue = false;
	}
	else
	{
		lineaux = obj.value;
		var keypress = e.which;
		if (keypress == 8)
			return true;
		if ((keypress < 48 || keypress > 57) || obj.value.length >= 13)
			return false;
		if (lineaux.length == 5)
			lineaux = lineaux + "-";
		lineaux = lineaux + (keypress - 48);
		obj.value = lineaux;
		return false;				
	}
	return true;
}

function verifica_cep(obj) {	
	if ((obj.value.indexOf("-") != 5) || (obj.value.length != 9)  || (  !(cadeia_numerica(replace(obj.value,"-",""))))) { 
		return false;
	} else {
		return true;
	}
}