/******************************************************************
	LISTA DE TRIPULANTES
******************************************************************/

function excluirTripulantes()
{
	var marcado = 0;
	var uThick  = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with (document.tripulantes)
	{
		for (i=0; i<elements.length; i++)
		{
			if (elements[i].type == "checkbox")
			{
				if (elements[i].checked == true)
				{
					marcado++;	
				}
			}
		}
		
		if (marcado > 0)
		{
			action = "send.acoes.php?acao=amigo_excluirsel";	
			submit();
		}
		else
		{
			//alert("Você não selecionou nenhum tripulante");
			tb_show(null, 'avisos.php?aviso=Você não selecionou nenhum tripulante.'+uThick, null);
		}
	}
}

function buscaTripulantes()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with (document.tripulantes)
	{
		if (isEmail(busca) || isDefValue(busca, "Nome:"))
		{
			//alert("Preencha o nome do tripulante que deseja buscar.");
			tb_show(null, 'avisos.php?aviso=Preencha o nome do tripulante que deseja buscar.'+uThick, null);
			busca.focus();
			return;
		}
		
		action = "/tripulantes/busca";	
		submit();
	}
}

function paginacaoTripulantes(p)
{
	document.tripulantes.action = "/tripulantes/busca/?p="+p;	
	document.tripulantes.submit();
}


/******************************************************************
	FILTRO DE BUSCA
******************************************************************/

function filtraNoticias(t)
{
	var url = "";
	var pag = "/principal";
	
	with (document.filtro)
	{
		if (t == null || t == 0)
		{	
			carregaClip('ultimas_noticias?pais='+pais.value+"&estado="+estado.value+"&cidade="+cidade.value);
		}
		else if (t == 1)
		{
			if (pais.value != "")
			{
				url += pais.value;	
			}
			
			if (estado.value != "")
			{
				url += "-"+estado.value;	
			}
			
			if (cidade.value != "")
			{
				url += "-"+cidade.value;	
			}
			
			location.href = pag+"/"+url;
		}
		else if (t == 2)
		{
			carregaClip('tripulante_noticias?id='+id.value+'&pais='+pais.value+"&estado="+estado.value+"&cidade="+cidade.value);
		}
	}
}


/******************************************************************
	VALIDA IMAGEM DE EXIBIÇÃO DO USUÁRIO
******************************************************************/

function validaImagemExibicao()
{
	with (document.exibicao)
	{
		if (isEmpty(imagem))
		{
			alert("Selecione a imagem.");
			imagem.focus();
			return;
		}
		
		if (!testFileType(imagem.value, ['gif', 'jpg', 'png', 'jpeg']))
		{
			alert("A extensão da imagem selecionada é inválida. Utilize somente JPG, GIF ou PNG.");
			imagem.focus();
			return;
		}
		
		$("#midia #btn_aguardar").show();
		$("#midia #btn_aguardar").width(94);
		$("#midia #btn_salvar").hide();
		$("#midia #btn_fechar").hide();
		
		submit();
	}
}

function validaCrop()
{
	with (document.exibicao)
	{
		if (isEmpty(w))
		{
			alert('Selecione a região da imagem que deseja cortar.');
			return;
		}
		
		submit();
	}
}



/******************************************************************
	VALIDA MÍDIA DA NOTÍCIA
******************************************************************/

function validaMidia()
{
	with (document.midia)
	{
		if (!tipo[0].checked && !tipo[1].checked && !tipo[2].checked)
		{
			alert("Selecione o tipo de mídia que deseja inserir.");
			return;
		}
		
		if (tipo[0].checked)
		{
			if (isEmpty(imagem))
			{
				alert("Selecione a imagem que deseja inserir.");
				imagem.focus();
				return;
			}
		}
		
		if (tipo[1].checked)
		{
			if (isEmpty(audio))
			{
				alert("Preencha o campo abaixo com a url do YouTube de seu áudio.");
				audio.focus();
				return;
			}
		}
		
		if (tipo[2].checked)
		{
			if (isEmpty(video))
			{
				alert("Preencha o campo abaixo com a url do YouTube de seu vídeo.");
				video.focus();
				return;
			}
		}
		
		$("#midia #btn_aguardar").show();
		$("#midia #btn_aguardar").width(94);
		$("#midia #btn_adicionar").hide();
		$("#midia #btn_fechar").hide();
		
		submit();
	}
}

function selecioneMidia(t)
{
	if (t == 0)
	{
		document.getElementById("imagem").style.display = "block";
		document.getElementById("audio").style.display  = "none";
		document.getElementById("video").style.display  = "none";
	}
	
	if (t == 1)
	{
		document.getElementById("imagem").style.display = "none";
		document.getElementById("audio").style.display  = "block";
		document.getElementById("video").style.display  = "none";
	}
	
	if (t == 2)
	{
		document.getElementById("imagem").style.display = "none";
		document.getElementById("audio").style.display  = "none";
		document.getElementById("video").style.display  = "block";
	}
}


/******************************************************************
	VALIDA NOTÍCIA
******************************************************************/

function validaNoticia()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with (document.noticia)
	{
		if (isEmpty(titulo))
		{
			//alert("Preencha o título da notícia.");
			tb_show(null, 'avisos.php?aviso=Preencha o título da notícia.'+uThick, null);
			titulo.focus();
			return;
		}
		
		if (isEmpty(historyline))
		{
			//alert("Preencha o historyline da notícia.");
			tb_show(null, 'avisos.php?aviso=Preencha o storyline da notícia.'+uThick, null);
			historyline.focus();
			return;
		}
		
		if (isEmpty(descricao))
		{
			//alert("Preencha o texto da notícia.");
			tb_show(null, 'avisos.php?aviso=Preencha o texto da notícia.'+uThick, null);
			descricao.focus();
			return;
		}
		
		if (isEmpty(tags))
		{
			//alert("Preencha as tags da notícia.");
			tb_show(null, 'avisos.php?aviso=Preencha as tags da notícia.'+uThick, null);
			tags.focus();
			return;
		}
		
		if (isEmpty(captcha))
		{
			//alert("Preencha o código de validação.");
			tb_show(null, 'avisos.php?aviso=Preencha o código de validação.'+uThick, null);
			captcha.focus();
			return;
		}
		
		if (captchaok.value == 0)
		{
			//alert("Aguarde a confirmação do código de validação e em seguida clique novamente para postar sua notícia.");
			tb_show(null, 'avisos.php?aviso=Aguarde a confirmação do código de validação e em seguida clique novamente para publicar sua notícia.'+uThick, null);
			return;
		}
		
		if (captchaok.value == 1)
		{
			var an = (anonimo.checked == true) ? 1 : 0;
			tb_show(null, 'publicacao.php?anonimo='+an+uThick, null);
			//$("#noticia #btn_aguardar").show();
			//$("#noticia #btn_aguardar").width(94);
			//$("#noticia #btn_publicar").hide();
			
			//submit();
		}
	}
}


/******************************************************************
	VALIDA CONFIGURAÇÕES DO USUÁRIO
******************************************************************/

function validaConfig()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.formulario)
	{
		if (isNotEqual(twitter_url, ""))
		{
			if (isEmpty(twitter_user))
			{
				//alert("Preencha seu usuário de acesso do Twitter.");
				tb_show(null, 'avisos.php?aviso=Preencha seu usuário de acesso do Twitter.'+uThick, null);
				twitter_user.focus();
				return;
			}
			
			if (isEmpty(twitter_pass))
			{
				//alert("Preencha sua senha de acesso do Twitter.");
				tb_show(null, 'avisos.php?aviso=Preencha sua senha de acesso do Twitter.'+uThick, null);
				twitter_user.focus();
				return;
			}
			
			if (twitterok.value == "0")
			{
				//alert("Preencha sua senha de acesso do Twitter.");
				tb_show(null, 'avisos.php?aviso=Você deve validar seu login no Twitter para salvar suas configurações.'+uThick, null);
				return;
			}
		}
		
		$("#formulario #btn_aguardar").show();
		$("#formulario #btn_aguardar").width(94);
		$("#formulario #btn_salvar").hide();
		
		submit();
	}
}


/******************************************************************
	VALIDA POST NO DIÁRIO
******************************************************************/

function validaPost(rel)
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with (document.diario)
	{
		if (isEmpty(postagem))
		{
			//alert("Preencha a postagem.");
			tb_show(null, 'avisos.php?aviso=Preencha a postagem.'+uThick, null);
			postagem.focus();
			return;
		}
		
		if (postagem.value.length < 10)
		{
			//alert("Seu post deve ter no mínimo 10 caracteres.");
			tb_show(null, 'avisos.php?aviso=Seu post deve ter no mínimo 10 caracteres.'+uThick, null);
			postagem.focus();
			return;
		}
		
		if (postagem.value.length > 140)
		{
			//alert("Seu post excedeu o limite de 140 caracteres.");
			tb_show(null, 'avisos.php?aviso=Seu post excedeu o limite de 140 caracteres.'+uThick, null);
			postagem.focus();
			return;
		}
		
		$("#diario #btn_aguardar").show();
		$("#diario #btn_aguardar").width(94);
		$("#diario #btn_publicar").hide();
		
		enviaDiario("#diario #postagem", "#diario #twitter", rel);
	}
}


/******************************************************************
	VALIDA COMENTÁRIOS DA NOTÍCIA
******************************************************************/

function validaComent()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.comentar)
	{
		if (isEmpty(texto))
		{
			//alert("É necessário descrever seu comentário.");
			tb_show(null, 'avisos.php?aviso=É necessário descrever seu comentário.'+uThick, null);
			texto.focus();
			return;
		}
		
		if (texto.value.length < 10)
		{
			//alert("Seu comentário deve ter no mínimo 10 caracteres.");
			tb_show(null, 'avisos.php?aviso=Seu comentário deve ter no mínimo 10 caracteres.'+uThick, null);
			texto.focus();
			return;
		}
		
		if (texto.value.length > 200)
		{
			//alert("Seu comentário não pode ultrapassar o limite de 200 caracteres.");
			tb_show(null, 'avisos.php?aviso=Seu comentário não pode ultrapassar o limite de 200 caracteres.'+uThick, null);
			texto.focus();
			return;
		}
		
		$("#comentar #btn_comentar").prev().show();
		$("#comentar #btn_comentar").prev().width(94);
		$("#comentar #btn_comentar").hide();
		
		//submit();
		enviaComentario(texto.value, id.value, reply.value);
	}
}



/******************************************************************
	VALIDA BUSCA POR NOTÍCIAS
******************************************************************/

function validaBusca()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.busca)
	{
		if (isEmpty(palavra) || isDefValue(palavra, "Palavra-chave"))
		{
			//alert("Preencha a palavra-chave que deseja buscar.");
			tb_show(null, 'avisos.php?aviso=Preencha a palavra-chave que deseja buscar.'+uThick, null);
			palavra.focus();
			return;
		}
		
		action = "/principal/busca/"+palavra.value;
		submit();
	}
}


/******************************************************************
	VALIDA BUSCA POR NOTÍCIAS DE QUEM NÃO ESTA LOGADO
******************************************************************/

function validaBuscaHome()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.busca)
	{
		if (isEmpty(palavra) || isDefValue(palavra, "Palavra-chave"))
		{
			//alert("Preencha a palavra-chave que deseja buscar.");
			tb_show(null, 'avisos.php?aviso=Preencha a palavra-chave que deseja buscar.'+uThick, null);
			palavra.focus();
			return;
		}
		
		submit();
	}
}


/******************************************************************
	ESQUECI MINHA SENHA
******************************************************************/

function validaLogin()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.formulario)
	{
		if (isEmpty(email) || isDefValue(email, "E-mail:"))
		{
			//alert("Preencha seu e-mail.");
			tb_show(null, 'avisos.php?aviso=Preencha se e-mail.'+uThick, null);
			email.focus();
			return;
		}
		
		if (!isEmail(email))
		{
			//alert("O e-mail digitado é inválido.");
			tb_show(null, 'avisos.php?aviso=O e-mail digitado é inválido.'+uThick, null);
			email.focus();
			return;
		}
		
		if (isEmpty(senha) || isDefValue(senha, "Senha:"))
		{
			//alert("Preencha sua senha de acesso.");
			tb_show(null, 'avisos.php?aviso=Preencha sua senha de acesso.'+uThick, null);
			senha.focus();
			return;
		}
		
		$("#formulario #btn_aguardar").show();
		$("#formulario #btn_aguardar").width(85);
		$("#formulario #btn_entrar").hide();
		
		verificaLogin("#email", "#senha", "#salvar");
	}
}


/******************************************************************
	ESQUECI MINHA SENHA
******************************************************************/

function validaEsqueciSenha()
{
	var uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
	
	with(document.formulario)
	{
		if (isEmpty(email) || isDefValue(email, "E-mail:"))
		{
			//alert("Preencha se e-mail.");
			tb_show(null, 'avisos.php?aviso=Preencha se e-mail.'+uThick, null);
			email.focus();
			return;
		}
		
		if (!isEmail(email))
		{
			//alert("O e-mail digitado é inválido.");
			tb_show(null, 'avisos.php?aviso=O e-mail digitado é inválido.'+uThick, null);
			email.focus();
			return;
		}
		
		verificaSenha("#email");
	}
}


/******************************************************************
	CADASTRO
******************************************************************/

function validaCadastroRapido(b, tp)
{
	with(document.formulario)
	{
		prNome = nome.value.split(" ");
		utNome = sobrenome.value.split(" ");
		uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
		
		if (isEmpty(nome) || isInvalidFormat(nome))
		{
			$("#aviso").empty().html("Preencha seu nome.");
			nome.focus();
			return;
		}
		
		if (isEmpty(sobrenome) || isInvalidFormat(sobrenome))
		{
			$("#aviso").empty().html("Preencha seu sobrenome.");
			sobrenome.focus();
			return;
		}
		
		if (isEmpty(email))
		{
			$("#aviso").empty().html("Preencha seu e-mail.");
			email.focus();
			return;
		}
		
		if (!isEmail(email))
		{
			$("#aviso").empty().html("O e-mail digitado é inválido.");
			email.focus();
			return;
		}
		
		if (!isEqual(email, emailok))
		{
			$("#aviso").empty().html("O e-mail não confere.");
			emailok.focus();
			return;
		}
		
		if (isEmpty(senha) || senha.length < 6)
		{
			$("#aviso").empty().html("Preencha uma senha de acesso. (Mínimo 6 caracteres)");
			senha.focus();
			return;
		}
		
		if (isInvalidFormat(senha))
		{
			$("#aviso").empty().html("Não é permitido a utilização de caracteres especiais na senha.");
			senha.focus();
			return;
		}
		
		if (!isEqual(senha, senhaok))
		{
			$("#aviso").empty().html("A senha não confere.");
			senhaok.focus();
			return;
		}
		
		if (termos.checked == false)
		{
			$("#aviso").empty().html("Você deve concordar com o regulamento para poder prosseguir com seu cadastro.");
			return;	
		}
				
		if (captchaok.value == 0)
		{
			if (isEmpty(captcha))
			{
				$("#aviso").empty().html("Preencha o código de validação ao lado.");
				captcha.focus();
				return;	
			}
		}
		
		if (captchaok.value == 0)
		{
			$("#aviso").empty().html("Aguarde a confirmação do código de validação e em seguida clique novamente para finalizar seu cadastro.");
			return;
		}
		
		if (captchaok.value == 1)
		{
			$("aviso").empty();
			$("#formulario #btn_aguardar").show();
			$("#formulario #btn_aguardar").width(94);
			$("#formulario #"+b).hide();
			
			submit();
		}
	}	
}

function validaCadastro(b, tp)
{
	with(document.formulario)
	{
		prNome = nome.value.split(" ");
		utNome = sobrenome.value.split(" ");
		uThick = "&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=490&modal=true";
		
		if (isEmpty(nome) || isInvalidFormat(nome))
		{
			tb_show(null, 'avisos.php?aviso=Preencha seu nome.'+uThick, null);
			nome.focus();
			return;
		}
		
		/*if (prNome.length > 1)
		{
			tb_show(null, 'avisos.php?aviso=O nome deve conter no máximo uma palavra.'+uThick, null);
			nome.focus();
			return;
		}
		
		if (utNome.length > 4)
		{
			tb_show(null, 'avisos.php?aviso=O sobrenome deve conter no máximo três palavra.'+uThick, null);
			sobrenome.focus();
			return;
		}*/
		
		if (isEmpty(sobrenome) || isInvalidFormat(sobrenome))
		{
			tb_show(null, 'avisos.php?aviso=Preencha seu sobrenome.'+uThick, null);
			sobrenome.focus();
			return;
		}
		
		if (tp == "novo")
		{
			if (isEmpty(cpf))
			{
				tb_show(null, 'avisos.php?aviso=Preencha seu cpf.'+uThick, null);
				cpf.focus();
				return;
			}
			
			if (!isCpf(cpf.value))
			{
				tb_show(null, 'avisos.php?aviso=O CPF digitado é inválido.'+uThick, null);
				cpf.focus();
				return;
			}
		}
		
		/*if (isEmpty(rg) || isInvalidFormat(rg) || rg.length < 5)
		{
			//alert("Preencha seu rg. (Somente números)");
			tb_show(null, 'avisos.php?aviso=Preencha seu rg.'+uThick, null);
			rg.focus();
			return;
		}*/
		
		if (isEmpty(nascimento))
		{
			tb_show(null, 'avisos.php?aviso=Preencha sua data de nascimento.'+uThick, null);
			nascimento.focus();
			return;
		}
		
		if (!isDate(nascimento))
		{
			tb_show(null, 'avisos.php?aviso=Preencha uma data de nascimento válida.'+uThick, null);
			nascimento.focus();
			return;
		}
		
		var meuDia = nascimento.value.split("/")[0];
		var meuMes = nascimento.value.split("/")[1]; 
		var meuAno = nascimento.value.split("/")[2];
		var strIda = calculaIdade(meuDia, meuMes, meuAno);
		
		if (strIda < 18)
		{
			tb_show(null, 'avisos.php?aviso=Você deve ser maior de 18 anos para participar do Responde Brasil.'+uThick, null);
			nascimento.focus();
			return;	
		}
		
		if (isEmpty(email))
		{
			tb_show(null, 'avisos.php?aviso=Preencha seu e-mail.'+uThick, null);
			email.focus();
			return;
		}
		
		if (!isEmail(email))
		{
			tb_show(null, 'avisos.php?aviso=O e-mail digitado é inválido.'+uThick, null);
			email.focus();
			return;
		}
		
		if (!isEqual(email, emailok))
		{
			tb_show(null, 'avisos.php?aviso=O e-mail não confere.'+uThick, null);
			emailok.focus();
			return;
		}
		
		if (isEmpty(senha) || senha.length < 6)
		{
			tb_show(null, 'avisos.php?aviso=Preencha uma senha de acesso. (Mínimo 6 caracteres)'+uThick, null);
			senha.focus();
			return;
		}
		
		if (isInvalidFormat(senha))
		{
			tb_show(null, 'avisos.php?aviso=Não é permitido a utilização de caracteres especiais na senha. (Ex.: @!#$%&*+=?|-)'+uThick, null);
			senha.focus();
			return;
		}
		
		if (!isEqual(senha, senhaok))
		{
			tb_show(null, 'avisos.php?aviso=A senha não confere.'+uThick, null);
			senhaok.focus();
			return;
		}
		
		if (isEmpty(sexo))
		{
			tb_show(null, 'avisos.php?aviso=Selecione seu gênero.'+uThick, null);
			sexo.focus();
			return;
		}
		
		if (isEmpty(profissao))
		{
			tb_show(null, 'avisos.php?aviso=Selecione sua profissão.'+uThick, null);
			profissao.focus();
			return;
		}
		
		if (isEmpty(pais))
		{
			tb_show(null, 'avisos.php?aviso=Selecione o país onde reside.'+uThick, null);
			pais.focus();
			return;
		}
		
		if (isEmpty(estado) || isInvalidFormat(estado))
		{
			tb_show(null, 'avisos.php?aviso=Selecione/Preencha o estado onde reside.'+uThick, null);
			estado.focus();
			return;
		}
		
		if (isEmpty(cidade) || isInvalidFormat(cidade))
		{
			tb_show(null, 'avisos.php?aviso=Selecione/Preencha a cidade onde reside.'+uThick, null);
			cidade.focus();
			return;
		}
		
		if (captchaok.value == 0)
		{
			if (isEmpty(captcha))
			{
				tb_show(null, 'avisos.php?aviso=Preencha o código de validação ao lado.'+uThick, null);
				captcha.focus();
				return;	
			}
		}
		
		if (termos[0].checked == false)
		{
			tb_show(null, 'avisos.php?aviso=Você deve concordar com o regulamento para poder prosseguir com seu cadastro.'+uThick, null);
			return;	
		}
		
		if (captchaok.value == 0)
		{
			tb_show(null, 'avisos.php?aviso=Aguarde a confirmação do código de validação e em seguida clique novamente para finalizar seu cadastro.'+uThick, null);
			return;
		}
		
		if (captchaok.value == 1)
		{
			$("#formulario #btn_aguardar").show();
			$("#formulario #btn_aguardar").width(94);
			$("#formulario #"+b).hide();
			
			submit();
		}
	}	
}


/******************************************************************
	ALERTAS
******************************************************************/

function mostraAlerta(a, w, h)
{
	var wd = (w=="" || w==null) ? 490 : w;
	var ht = (h=="" || h==null) ? 200 : h;
	
	tb_show(null, 'avisos.php?aviso='+a+'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height='+ht+'&width='+wd+'&modal=true', null);
}


/******************************************************************
	FOCUS E BLUR
******************************************************************/

function onFocus(campo, valor)
{
	if (campo.value == valor)
	{
		campo.value = "";
	}
}

function onBlur(campo, valor)
{
	if (campo.value == "")
	{
		campo.value = valor;
	}
}


/******************************************************************
	VALIDAÇÕES PADRÃO
******************************************************************/

function isEmpty(str)
{
	if (str.value == "" || str.value.length == 0)
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function isDefValue(str, def)
{
	if (str.value == def)
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function isInvalidFormat(str)
{
	var er = new RegExp(/[@!#$%&*+=?|-]/);
	
	if (typeof(str.value) == "string")
	{
        if (er.test(str.value))
		{ 
			return true; 
		}
    }
	else if (typeof(str) == "object")
	{
        if (er.test(str))
		{
           return true;
        }
    }
	else
	{
        return false;
    }
}

function isEqual(str1, str2)
{
	if (str2.value == str1.value)
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function isNotEqual(str, val)
{
	if (str.value != val)
	{
		return true;	
	}
	else
	{
		return false;
	}
}

function isDate(str) 
{
	var dia = str.value.substr(0,2);
	var mes = str.value.substr(3,2);
	var ano = str.value.substr(6,4);
	
	var data = new Date();
	var intDia;
	var intMes;
	var intAno;

	data.setFullYear(ano, mes-1, dia);

	intDia = (data.getDate() == dia);
	intMes = (data.getMonth() == mes-1);
	intAno = (data.getFullYear() == ano);

	if (intDia && intMes && intAno)
	{
		return true;
	}
	else
	{
		return false;	
	}
}

function isEmail(str)
{
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
   
    if (typeof(str.value) == "string")
	{
        if (er.test(str.value))
		{ 
			return true; 
		}
    }
	else if (typeof(str) == "object")
	{
        if (er.test(str))
		{
           return true;
        }
    }
	else
	{
        return false;
    }
}

function isImage(str)
{
    var er = new RegExp(/[\w]+\.(gif|jpg|bmp|png|jpeg)$/gi);
   
    if (typeof(str.value) == "string")
	{
        if (er.test(str.value))
		{ 
			return true; 
		}
    }
	else if (typeof(str) == "object")
	{
        if (er.test(str))
		{
           return true;
        }
    }
	else
	{
        return false;
    }
}

function isDDD(str)
{
	var ddd = str.value.substr(1,2);
	
	if (ddd == "00" || str.length == 0 || str == "")
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function isPhoneNumber(str)
{
	var fone   = str.value.substr(5,9);
	var digito = str.value.substr(5,1);
	var numero = fone.replace(".", "");	
	
	if (numero == "00000000" || numero == "11111111" || numero == "22222222" || numero == "33333333" || numero == "44444444" || numero == "55555555" || numero == "66666666" || numero == "77777777" || numero == "88888888" || numero == "99999999" || str.value.length < 14 || str.value == "" || digito == 0 || digito == 8 || digito == 9)
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function isCelularNumber(str)
{
	var fone   = str.value.substr(5,9);
	var digito = str.value.substr(5,1);
	var numero = fone.replace(".", "");
	
	if (numero == "00000000" || numero == "11111111" || numero == "22222222" || numero == "33333333" || numero == "44444444" || numero == "55555555" || numero == "66666666" || numero == "77777777" || numero == "88888888" || numero == "99999999" || str.value.length < 14 || str.value == "" || digito < 8)
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function isInteger(str)
{
	var er = new RegExp(/^[0-9]+$/);
	
	if (er.test(str.value)) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
}

function testFileType(fileName, fileTypes)
{
	if (!fileName) return;
	
	dots = fileName.split(".");
	
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	
	return (fileTypes.join(".").indexOf(fileType) != -1) ? true : false;
}

function calculaIdade(d, m, y)
{
	var dia = parseInt(d);
	var mes = parseInt(m)-1;
	var ano = parseInt(y);
	
	var age;
	var now = new Date();
	
	diaAtual = now.getDate();
	mesAtual = now.getMonth();
	anoAtual = now.getFullYear();
	
	if ((mesAtual > mes)||(mesAtual == mes & diaAtual >= dia))
	{
		age = ano;
	}
	else
	{
		age = ano+1;
	}
	
	return anoAtual-age;
}