// ===== Biblioteca de funções do site www.veteranbahia.com.br ================================
// ===== Desenvolvido e adaptado por Rubem Sena ===============================================
// ===== Contato: rubemsena@yahoo.com.br ================== 71.8802-1324 ======================


// Endereço do site fixado na barra de status ================================================

	window.defaultStatus = "Veteran Car Club do Brasil - Bahia"



// Funções para pop-ups ======================================================================

	function opnWindow (url, w, h) // sem scroll
	{
	janela = window.open (url, 'foto', "titlebar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,width=" + w + ",height="+ h)
	}

	function classificados (url, w, h) // com scroll
	{
	janela = window.open (url, 'popup', "titlebar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,width=" + w + ",height="+ h)
	}

	function Windowopn (url, w, h) // com scroll
	{
	janela = window.open (url, 'popup', "titlebar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,width=" + w + ",height="+ h)
	}

	function abreWindow (url, w, h) // com scroll
	{
	janela = window.open (url, 'pop', "titlebar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,width=" + w + ",height="+ h)
	}

	function fullscreen (url)
	{
	janela = window.open (url,'Apostilas','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,fullscreen=yes')
	}

	function modelesswin(url,mwidth,mheight)
	{
	if (document.all&&window.print) //if ie5
		eval('window.showModelessDialog(url,"","help:0; resizable:0; titlebar:1; toolbar:0; location:0; directories:0; scroll:0; status:0; dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
	else
		eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=0")')
	}


// Confirmação de exclusão ===================================================================

	function confirmaExclusao(aURL)
	{
		if(confirm("Você tem certeza que deseja excluir o registro?"))
		{
		location.href = aURL;
		}
	}



// Centraliza página =========================================================================

	function centraliza(x,y)
	{
	window.moveTo((screen.width-x)/2, (screen.height-y-40)/2);
	}



// Função para formatar os campos (cpf,telefone,data) ========================================

function formatar(src, mask)
	{
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
		{
		src.value += texto.substring(0,1);
		}
	}



// Manipulação dos DIV´s =====================================================================

	var i=0;
	function Load()
		{
		if (i==null) i=0;
		eval("document.all.Tip1.style.display=''");
		}
	var ant=1;
	function exibir(i)
		{
		eval("document.all.Tip"+ant+".style.display='none'");
		eval("document.all.Tip"+i+".style.display=''");
		ant = i
		}



// Faz o banner cair na tela =================================================================

var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var bouncelimit=32 //(must be divisible by 8)
var direction="up"
var crossobj=""

function initbox()
	{
	if (!dom&&!ie&&!ns4)
	return
	crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
	scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
	crossobj.top=scroll_top-250
	crossobj.visibility=(dom||ie)? "visible" : "show"
	dropstart=setInterval("dropin()",50)
	}
function dropin()
	{
	scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
	if (parseInt(crossobj.top)<10+scroll_top)
	crossobj.top=parseInt(crossobj.top)+40
	else
	{
	clearInterval(dropstart)
	bouncestart=setInterval("bouncein()",50)
	}
	}
function bouncein()
	{
	crossobj.top=parseInt(crossobj.top)-bouncelimit
	if (bouncelimit<0)
	bouncelimit+=8
	bouncelimit=bouncelimit*-1
	if (bouncelimit==0){
	clearInterval(bouncestart)
	}
	}
function dismissbox()
	{
	if (window.bouncestart) clearInterval(bouncestart)
	crossobj.visibility="hidden"
	}
function get_cookie(Name)
	{
	var search = Name + "="
	var returnvalue = ""
	if (document.cookie.length > 0) {
	offset = document.cookie.indexOf(search)
	if (offset != -1) {
	offset += search.length
	end = document.cookie.indexOf(";", offset)
	if (end == -1)
	end = document.cookie.length;
	returnvalue=unescape(document.cookie.substring(offset, end))
	}
	}
	return returnvalue;
	}
function dropornot()
	{
	if (get_cookie("droppedin")=="")
	{
	window.onload=initbox
	document.cookie="droppedin=yes"
	}
	}
	dropornot()
function redo()
	{
	bouncelimit=32
	direction="up"
	initbox()
	}
	window.onload=initbox



//=============================================================================================
// PALAVRÃO ===================================================================================
//=============================================================================================

		function valida_palavrao()
		{
			var palavra = document.palavrao.palavra.value;

		// PALAVRÃO
			if (palavra == "") { alert("Digite uma palavra que deseja bloquar no site!");  document.palavrao.palavra.focus(); return false}
			if (document.palavrao.palavra.value.length < 2) { alert("Você não pode bloquear um caracter!"); document.palavrao.palavra.focus(); return false }
		}



//=============================================================================================
// INSCRIÇÃO PARA O 4º ENCONTRO ===============================================================
//=============================================================================================

function encontronordeste()
{
	var letras = "abcdefghijlmnopqrstuvxzkywABCDEFGHIJLMNOPQRSTUVXZKYWçÇ´[~,;`{^<>:?\|!@#$%¨&*()_+}=]'"; 

	var tipoinsc=document.inscricao.tipoinsc.value;
	var tipo=document.inscricao.tipo.value;
	var nome=document.inscricao.nome.value;
	var cracha=document.inscricao.cracha.value;
	var acompanhante=document.inscricao.acompanhante.value;
	var cracha_acompanhante=document.inscricao.cracha_acompanhante.value;
	var endereco=document.inscricao.endereco.value;
	var bairro=document.inscricao.bairro.value;
	var cep=document.inscricao.cep.value;
	var cidade=document.inscricao.cidade.value;
	var estado=document.inscricao.estado.value;
	var email=document.inscricao.email.value;

	// TELEFONES ------------------------------
	var telres=document.inscricao.telres.value;
	var telcom=document.inscricao.telcom.value;
	var telcel=document.inscricao.telcel.value;
	
	// CARRO ----------------------------------
	var marca=document.inscricao.marca1.value;
	var modelo=document.inscricao.modelo1.value;
	var ano=document.inscricao.ano1.value;
	var placa=document.inscricao.placa1.value;
	var cor=document.inscricao.cor1.value;

	// Tipo
	if (tipoinsc == "") { alert("Selecione a cetegoria de sua inscrição!"); document.inscricao.nome.focus(); return false}

	// Nome
	if (nome == "") { alert("Digite seu nome!");  document.inscricao.nome.focus(); return false}

	// Crachá
	if (cracha == "") { alert("Informe o nome para seu crachá!");  document.inscricao.cracha.focus(); return false}

	// Acompanhante
	if (tipo =="C")
	{
		if (acompanhante == "") { alert("Informe o nome do acompanhante!");  document.inscricao.acompanhante.focus(); return false}
		if (cracha_acompanhante == "") { alert("Informe o nome no cracha do seu acompanhante!");  document.inscricao.cracha_acompanhante.focus(); return false}
	}

	// Endereço
	if (endereco == "") { alert("Informe seu endereço!");  document.inscricao.endereco.focus(); return false}

	// Bairro
	if (bairro == "") { alert("Informe seu bairro!");  document.inscricao.bairro.focus(); return false}

	// CEP
	if (cep == "CEP") { alert("Informe o cep!");  document.inscricao.cep.focus(); return false}
	var cep_numero = "1234567890.-";
	var cepinvalido = true;
	for (i = 0;  i < cep.length;  i++)
		{
		ch = cep.charAt(i);
		for (j = 0;  j < cep_numero.length;  j++)
		if (ch == cep_numero.charAt(j))
			break;
		if (j == cep_numero.length)
			{
			cepinvalido = false;
			break;
			}
		}
	if (!cepinvalido)
		{
		alert("O campo CEP deve conter apenas números!");
		document.inscricao.cep.focus();
		return (false);
		}
	if (document.inscricao.cep.value.length < 10)
		{
		alert("O campo CEP foi preenchido incorretamente. Verifique!");
		document.inscricao.cep.focus();
		return (false);
		}

	// Cidade
	if (cidade == "") { alert("Informe sua cidade!");  document.inscricao.cidade.focus(); return false}

	// Estado
	if (estado == "") { alert("Informe seu estado!");  document.inscricao.estado.focus(); return false}

	// Email
	if (email == "") { alert("Informe seu email !!!"); document.inscricao.email.focus(); return false}
	if (document.inscricao.email.value.indexOf('@', 0) == -1 || document.inscricao.email.value.indexOf('.', 0) == -1) { alert("Email invalido!"); document.inscricao.email.focus(); return false}

	// Telefone residencial
	if (telres != "(XX) XXXX-XXXX")
		{
		var res_numero = "1234567890()- ";
		var resinvalido = true;
		for (i = 0;  i < telres.length;  i++)
			{
			ch = telres.charAt(i);
			for (j = 0;  j < res_numero.length;  j++)
			if (ch == res_numero.charAt(j))
				break;
			if (j == res_numero.length)
				{
				resinvalido = false;
				break;
				}
			}
		if (!resinvalido)
			{
			alert("O campo Telefone residencial deve conter apenas números !!!");
			document.inscricao.telres.focus();
			return (false);
			}
		if (document.inscricao.telres.value.length < 12)
			{
			alert("O campo Telefone residencial não foi preenchido corretamente!");
			document.inscricao.telres.focus();
			return (false);
			}
		}

	// Telefone comercial
	if (telcom != "(XX) XXXX-XXXX")
		{
		var com_numero = "1234567890()- ";
		var cominvalido = true;
		for (i = 0;  i < telcom.length;  i++)
			{
			ch = telcom.charAt(i);
			for (j = 0;  j < com_numero.length;  j++)
			if (ch == com_numero.charAt(j))
				break;
			if (j == com_numero.length)
				{
				cominvalido = false;
				break;
				}
			}
		if (!cominvalido)
			{
			alert("O campo Telefone comercial deve conter apenas números !!!");
			document.inscricao.telcom.focus();
			return (false);
			}
		if (document.inscricao.telcom.value.length < 12)
			{
			alert("O campo Telefone comercial não foi preenchido corretamente!");
			document.inscricao.telcom.focus();
			return (false);
			}
		}

	// Telefone celular
	if (telcel != "(XX) XXXX-XXXX")
		{
		var cel_numero = "1234567890()- ";
		var celinvalido = true;
		for (i = 0;  i < telcel.length;  i++)
			{
			ch = telcel.charAt(i);
			for (j = 0;  j < cel_numero.length;  j++)
			if (ch == cel_numero.charAt(j))
				break;
			if (j == cel_numero.length)
				{
				celinvalido = false;
				break;
				}
			}
		if (!celinvalido)
			{
			alert("O campo Telefone celular deve conter apenas números !!!");
			document.inscricao.telcel.focus();
			return (false);
			}
		if (document.inscricao.telcel.value.length < 12)
			{
			alert("O campo Telefone celular não foi preenchido corretamente!");
			document.inscricao.telcel.focus();
			return (false);
			}
		}

}



//=============================================================================================
// CARROS PARA O 4º ENCONTRO (MANUTENÇÃO) =====================================================
//=============================================================================================

function encontrocarros()
{
	if ( document.inscricao.marca.value == "" || document.inscricao.modelo.value == "" || document.inscricao.ano.value == "" || document.inscricao.placa.value == "" || document.inscricao.cor.value == "" )
		{
		alert("PREENCHA CORRETAMENTE O FORMULÁRIO!");
		document.inscricao.marca.focus();
		return (false);
		}
}