function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function desativarSom()
{
	window.open("semSom.php","som");
}

function dadosCidades(valor)
{
	//verifica se o browser tem suporte a ajax
	try
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	
	catch(e)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		
		catch(ex)
		{
			try
			{
				ajax = new XMLHttpRequest();
			}
			
			catch(exc)
			{
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	
	//se tiver suporte ajax
	if(ajax)
	{
		//deixa apenas o elemento 1 no option, os outros são excluídos
		document.getElementById("cidades").options.length = 1;
		
		idOpcao = document.getElementById("opcoes");
		
		ajax.open("POST", "inc/cidades.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		ajax.onreadystatechange = function()
		{
			//enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1)
			{
				idOpcao.innerHTML = "Carregando...!";
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 )
			{
				if(ajax.responseXML)
				{
					processXML(ajax.responseXML);
				}
				else
				{
					//caso não seja um arquivo XML emite a mensagem abaixo
					idOpcao.innerHTML = "Selecione o estado";
				}
			}
		}
		
		//passa o código da seção escolhida
		var params = "uf="+valor;
		ajax.send(params);
	}
}
   
function processXML(obj)
{
	//pega a tag cidade
	var dataArray = obj.getElementsByTagName("cidade");
	
	//total de elementos contidos na tag cidade
	if(dataArray.length > 0)
	{
		//percorre o arquivo XML paara extrair os dados
		for(var i = 0 ; i < dataArray.length ; i++)
		{
			var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var nome =  item.getElementsByTagName("nome")[0].firstChild.nodeValue;
			
			idOpcao.innerHTML = "Selecione uma das cidades abaixo";
			
			//cria um novo option dinamicamente
			var novo = document.createElement("option");
			
			//atribui um ID a esse elemento
			novo.setAttribute("id", "opcoes");
			
			//atribui um valor
			novo.value = codigo;
			//atribui um texto
			novo.text  = nome;
			//finalmente adiciona o novo elemento
			document.getElementById("cidades").options.add(novo);
		}
	}
	else
	{
		//caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Nenhuma cidade disponível";
	}
}



//função para checar Login
function checarLogin(frmLogin)
{
	form = document.getElementById('frmLogin');
	
	if (form.document.getElementById('login').value == "")
	{
		alert("O campo login está vazio!!!");
		form.document.getElementById('login').focus();
		return (false);
	}
	
	if (form.document.getElementById('senha').value == "")
	{
		alert("Por favor preencha o campo senha!!!");
		form.document.getElementById('senha').focus();
		return (false);
	}
	return (true);
}

//função para checar Fale
function checarFale(frmFale){
form = document.getElementById('frmFale');
if (form.document.getElementById('Nome').value == ""){
alert("O campo nome está vazio!!!");
form.document.getElementById('Nome').focus();
return (false);
}
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.document.getElementById('Email').value))){ 
alert("Por favor informe um e-mail válido.")
form.document.getElementById('Email').focus() 
return (false);
}
if (form.document.getElementById('Mensagem').value == ""){
alert("Por favor preencha o campo Mensagem!!!");
form.document.getElementById('Mensagem').focus();
return (false);
}
return (true);
}


//função para checar Viagem
function checarViagem(frmViagem){
form = document.getElementById('frmViagem');
if (form.document.getElementById('motociclista').value == ""){
alert("O campo motociclista está vazio!!!");
form.document.getElementById('motociclista').focus();
return (false);
}
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.document.getElementById('email').value))){ 
alert("Por favor informe um e-mail válido.")
form.document.getElementById('email').focus() 
return (false);
}
if (form.document.getElementById('local').value == ""){
alert("O campo local de saída está vazio!!!");
form.document.getElementById('local').focus();
return (false);
}
if (form.document.getElementById('data').value == ""){
alert("O campo data está vazio!!!");
form.document.getElementById('data').focus();
return (false);
}
if (form.document.getElementById('destino').value == ""){
alert("O campo destino está vazio!!!");
form.document.getElementById('destino').focus();
return (false);
}
return (true);
}


//função para checarContatoVC
function checarContatoVC(frmContatoVC)
{
	form = document.getElementById('frmContatoVC');
	
	if (form.document.getElementById('nome').value == "")
	{
		alert("Por favor preencha o seu nome!!!");
		form.document.getElementById('nome').focus();
		return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.document.getElementById('email').value)))
	{
		alert("Por favor informe um e-mail válido.")
		form.document.getElementById('email').focus();
		return (false);
	}
	if (form.document.getElementById('endereco').value == "")
	{
		alert("O campo endereço está vazio!!!");
		form.document.getElementById('endereco').focus();
		return (false);
	}
	if (form.document.getElementById('bairro').value == "")
	{
		alert("O campo bairro está vazio!!!");
		form.document.getElementById('bairro').focus();
		return (false);
	}
	if (form.document.getElementById('cidade').value == "")
	{
		alert("O campo cidade está vazio!!!");
		form.document.getElementById('cidade').focus();
		return (false);
	}
	if (form.document.getElementById('telefones').value == "")
	{
		alert("Preencha o campo telefone corretamente.");
		form.document.getElementById('telefones').focus();
		return (false);
	}
	return (true);
}


//função para checar TrocaSenha
function checarTrocaSenha(frmTrocaSenha)
{
	form = document.getElementById('frmTrocaSenha');
	if (form.document.getElementById('login').value == "")
	{
		alert("O campo login está vazio!!!");
		form.document.getElementById('login').focus();
		return (false);
	}
	if (form.document.getElementById('senha').value == "")
	{
		alert("Por favor preencha o campo senha!!!");
		form.document.getElementById('senha').focus();
		return (false);
	}
	if (form.document.getElementById('novaSenha').value == "")
	{
		alert("Por favor preencha o campo senha!!!");
		form.document.getElementById('novaSenha').focus();
		return (false);
	}
	return (true);
}


//função para checar EsqueceuSenha
function checarEsqueceuSenha(frmEsqueceuSenha)
{
	form = document.getElementById('frmEsqueceuSenha');
	if (form.document.getElementById('login').value == "")
	{
		alert("O campo login está vazio!!!");
		form.document.getElementById('login').focus();
		return (false);
	}
	if (form.document.getElementById('email').value == "")
	{
		alert("Por favor preencha o campo e-mail!!!");
		form.document.getElementById('email').focus();
		return (false);
	}
	return (true);
}


//função para checar AltAnuncio
function checarAltAnuncio(frmAltAnuncio)
{
	form = document.getElementById('frmAltAnuncio');
	if (form.document.getElementById('titulo').value == "")
	{
		alert("O campo título está vazio!!!");
		form.document.getElementById('titulo').focus();
		return (false);
	}
	if (form.document.getElementById('anuncio').value == "")
	{
		alert("Por favor preencha o campo anúncio!!!");
		form.document.getElementById('anuncio').focus();
		return (false);
	}
	if (form.document.getElementById('dataExpira').value == "")
	{
		alert("Por favor preencha o campo data de expiração!!!");
		form.document.getElementById('dataExpira').focus();
		return (false);
	}
	return (true);
}


//função para checar CadAnuncio
function checarCadAnuncio(frmCadAnuncio)
{
	form = document.getElementById('frmCadAnuncio');
	if (form.document.getElementById('titulo').value == "")
	{
		alert("O campo título está vazio!!!");
		form.document.getElementById('titulo').focus();
		return (false);
	}
	if (form.document.getElementById('anuncio').value == "")
	{
		alert("Por favor preencha o campo anúncio!!!");
		form.document.getElementById('anuncio').focus();
		return (false);
	}
	return (true);
}


//função para mostrarDiv
function showDiv(ativar,id1)
{
	var A = document.getElementById(id1);
	
	if(ativar == 'sim')
	{
		A.style.display = 'block';
	}
	else
	{
		A.style.display = 'none';
	}
}


//função para desabilitarCampos
function desabilitarCampos(frm)
{
	var form = document.getElementById(frm);
	var indice = form.document.getElementById('pais').selectedIndex;
		
	if (form.document.getElementById('pais').options[indice].text != "Brasil")
	{
		form.document.getElementById('uf').disabled = true;
		form.document.getElementById('cidades').disabled = true;
		showDiv('nao','snr1');
		showDiv('sim','snr2');
	}
	else
	{
		form.document.getElementById('uf').disabled = false;
		form.document.getElementById('cidades').disabled = false;		
		showDiv('nao','snr2');
		showDiv('sim','snr1');
	}
}


//função para checarCadDados
function checarCadDados(frmCadDados)
{
	var form = document.getElementById('frmCadDados');
	
	if (form.document.getElementById('nome').value == "")
	{
		alert("Por favor preencha o seu nome!!!");
		form.document.getElementById('nome').focus();
		return (false);
	}
	if (form.document.getElementById('dataNasc').value == "")
	{
		alert("Por favor preencha a sua data de nascimento!!!");
		form.document.getElementById('dataNasc').focus();
		return (false);
	}
	else
	{
		if(!(/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/.test(form.document.getElementById('dataNasc').value)))
		{
			alert("Favor informar uma data válida.");
			return (false);
		}
	}
	if (form.document.getElementById('tipoSanguineo').value == "")
	{
		alert("Por favor preencha o seu tipo sanguíneo!!!");
		form.document.getElementById('tipoSanguineo').focus();
		return (false);
	}
	if (form.document.getElementById('profissao').value == "")
	{
		alert("Por favor preencha a sua profissão!!!");
		form.document.getElementById('profissao').focus();
		return (false);
	}
	if (form.document.getElementById('endereco').value == "")
	{
		alert("Por favor preencha o seu endereço!!!");
		form.document.getElementById('endereco').focus();
		return (false);
	}
	if (form.document.getElementById('bairro').value == "")
	{
		alert("Por favor preencha o seu bairro!!!");
		form.document.getElementById('bairro').focus();
		return (false);
	}

	var indice = form.document.getElementById('pais').selectedIndex;

	if (form.document.getElementById('pais').options[indice].text == "Brasil")
	{
		if (form.document.getElementById('uf').value == "")
		{
			alert("Por favor selecione o seu estado!!!");
			form.document.getElementById('uf').focus();
			return (false);
		}

		if (form.document.getElementById('cidades').value == "")
		{
			alert("Por favor preencha a sua cidade!!!");
			form.document.getElementById('cidades').focus();
			return (false);
		}
	}
	else
	{
		if (form.document.getElementById('cidades2').value == "")
		{
			alert("Por favor preencha a sua cidade!!!");
			form.document.getElementById('cidades2').focus();
			return (false);
		}
		else
		{
			form.document.getElementById('cidades').value = form.document.getElementById('cidades2').value;
		}
	}
	if (form.document.getElementById('cep').value == "")
	{
		alert("Por favor preencha o seu CEP!!!");
		form.document.getElementById('cep').focus();
		return (false);
	}
	if (form.document.getElementById('telefones').value == "")
	{
		alert("Preencha o campo telefones corretamente.");
		form.document.getElementById('telefones').focus();
		return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.document.getElementById('email').value)))
	{
		alert("Por favor informe um e-mail válido.")
		form.document.getElementById('email').focus();
		return (false);
	}
	if (form.document.getElementById('numero').value == "")
	{
		alert("Por favor preencha o número da carteira de habilitação!!!");
		form.document.getElementById('numero').focus();
		return (false);
	}
	if (form.document.getElementById('categoria').value == "")
	{
		alert("Por favor preencha a categoria da carteira de habilitação!!!");
		form.document.getElementById('categoria').focus();
		return (false);
	}
	if (form.document.getElementById('ano').value == "")
	{
		alert("Por favor preencha o ano da sua moto!!!");
		form.document.getElementById('ano').focus();
		return (false);
	}
	if (form.document.getElementById('modelo').value == "")
	{
		alert("Por favor preencha o modelo da sua moto!!!");
		form.document.getElementById('modelo').focus();
		return (false);
	}
	if (form.document.getElementById('placa').value == "")
	{
		alert("Por favor preencha a placa da sua moto!!!");
		form.document.getElementById('placa').focus();
		return (false);
	}
	if (form.document.getElementById('login').value == "")
	{
		alert("Por favor preencha o campo login!!!");
		form.document.getElementById('login').focus();
		return (false);
	}
	if (form.document.getElementById('senha').value == "")
	{
		alert("Por favor preencha o campo senha!!!");
		form.document.getElementById('senha').focus();
		return (false);
	}
	if (form.document.getElementById('confSenha').value == "")
	{
		alert("Por favor preencha o campo de confirmação de senha!!!");
		form.document.getElementById('confSenha').focus();
		return (false);
	}
	if (form.document.getElementById('senha').value != form.document.getElementById('confSenha').value)
	{
		alert("Os campos senha e confirmação de senha devem ser preenchidos iguais!!!");
		form.document.getElementById('confSenha').focus();
		return (false);
	}
	if(form.indicou[0].checked == false && form.indicou[1].checked == false)
	{
		alert("Por favor selecione um opção no campo: Você foi indicado por alguém do clube?");
		return (false);
	}
	else
	{
		if(form.indicou[0].checked == true)
		{
			if (form.document.getElementById('quem').value == "")
			{
				alert("Por favor preencha o campo com o nome completo de quem o indicou!!!");
				form.document.getElementById('quem').focus();
				return (false);
			}
		}
	}
	return (true);
}


//função para checarAltDados
function checarAltDados(frmAltDados)
{
	var form = document.getElementById('frmAltDados');
	
	if (form.document.getElementById('nome').value == "")
	{
		alert("Por favor preencha o seu nome!!!");
		form.document.getElementById('nome').focus();
		return (false);
	}
	if (form.document.getElementById('dataNasc').value == "")
	{
		alert("Por favor preencha a sua data de nascimento!!!");
		form.document.getElementById('dataNasc').focus();
		return (false);
	}
	else
	{
		if(!(/^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/.test(form.document.getElementById('dataNasc').value)))
		{
			alert("Favor informar uma data válida.");
			return (false);
		}
	}
	if (form.document.getElementById('tipoSanguineo').value == "")
	{
		alert("Por favor preencha o seu tipo sanguíneo!!!");
		form.document.getElementById('tipoSanguineo').focus();
		return (false);
	}
	if (form.document.getElementById('profissao').value == "")
	{
		alert("Por favor preencha a sua profissão!!!");
		form.document.getElementById('profissao').focus();
		return (false);
	}
	if (form.document.getElementById('endereco').value == "")
	{
		alert("Por favor preencha o seu endereço!!!");
		form.document.getElementById('endereco').focus();
		return (false);
	}
	if (form.document.getElementById('bairro').value == "")
	{
		alert("Por favor preencha o seu bairro!!!");
		form.document.getElementById('bairro').focus();
		return (false);
	}

	var indice = form.document.getElementById('pais').selectedIndex;

	if (form.document.getElementById('pais').options[indice].text == "Brasil")
	{
		if (form.document.getElementById('uf').value == "")
		{
			alert("Por favor selecione o seu estado!!!");
			form.document.getElementById('uf').focus();
			return (false);
		}

		if (form.document.getElementById('cidades').value == "")
		{
			alert("Por favor preencha a sua cidade!!!");
			form.document.getElementById('cidades').focus();
			return (false);
		}
	}
	else
	{
		if (form.document.getElementById('cidades2').value == "")
		{
			alert("Por favor preencha a sua cidade!!!");
			form.document.getElementById('cidades2').focus();
			return (false);
		}
		else
		{
			form.document.getElementById('cidades').value = form.document.getElementById('cidades2').value;
		}
	}
	if (form.document.getElementById('cep').value == "")
	{
		alert("Por favor preencha o seu CEP!!!");
		form.document.getElementById('cep').focus();
		return (false);
	}
	if (form.document.getElementById('telefones').value == "")
	{
		alert("Preencha o campo telefones corretamente.");
		form.document.getElementById('telefones').focus();
		return (false);
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.document.getElementById('email').value)))
	{
		alert("Por favor informe um e-mail válido.")
		form.document.getElementById('email').focus();
		return (false);
	}
	if (form.document.getElementById('numero').value == "")
	{
		alert("Por favor preencha o número da carteira de habilitação!!!");
		form.document.getElementById('numero').focus();
		return (false);
	}
	if (form.document.getElementById('categoria').value == "")
	{
		alert("Por favor preencha a categoria da carteira de habilitação!!!");
		form.document.getElementById('categoria').focus();
		return (false);
	}
	if (form.document.getElementById('ano').value == "")
	{
		alert("Por favor preencha o ano da sua moto!!!");
		form.document.getElementById('ano').focus();
		return (false);
	}
	if (form.document.getElementById('modelo').value == "")
	{
		alert("Por favor preencha o modelo da sua moto!!!");
		form.document.getElementById('modelo').focus();
		return (false);
	}
	if (form.document.getElementById('placa').value == "")
	{
		alert("Por favor preencha a placa da sua moto!!!");
		form.document.getElementById('placa').focus();
		return (false);
	}
	if (form.document.getElementById('nSenha').value != "")
	{
		if (form.document.getElementById('confNSenha').value == "")
		{
			alert("Por favor preencha o campo de confirmação de senha!!!");
			form.document.getElementById('confNSenha').focus();
			return (false);
		}
		else
		{
			if (form.document.getElementById('nSenha').value != form.document.getElementById('confNSenha').value)
			{
				alert("Os campos nova senha e confirmação de senha devem ser preenchidos iguais!!!");
				form.document.getElementById('confNSenha').focus();
				return (false);
			}
		}
	}
	if (form.document.getElementById('confNSenha').value != "")
	{
		if (form.document.getElementById('nSenha').value == "")
		{
			alert("Por favor preencha o campo nova senha!!!");
			form.document.getElementById('nSenha').focus();
			return (false);
		}
		else
		{
			if (form.document.getElementById('nSenha').value != form.document.getElementById('confNSenha').value)
			{
				alert("Os campos nova senha e confirmação de senha devem ser preenchidos iguais!!!");
				form.document.getElementById('nSenha').focus();
				return (false);
			}
		}
	}
	if(form.indicou[0].checked == false && form.indicou[1].checked == false)
	{
		alert("Por favor selecione um opção no campo: Você foi indicado por alguém do clube?");
		return (false);
	}
	else
	{
		if(form.indicou[0].checked == true)
		{
			if (form.document.getElementById('quem').value == "")
			{
				alert("Por favor preencha o campo com o nome completo de quem o indicou!!!");
				form.document.getElementById('quem').focus();
				return (false);
			}
		}
	}
	return (true);
}


//função para checar CadAnuncio
function checarRespTopico(frmRespTopico)
{
	form = document.getElementById('frmRespTopico');

	if (form.document.getElementById('mensagem').value == "")
	{
		alert("O campo mensagem está vazio!!!");
		form.document.getElementById('mensagem').focus();
		return (false);
	}
	return (true);
}


function sem_letras(){
    if ((window.event.keyCode < 48) | (window.event.keyCode > 57)){
        window.event.keyCode = 0
    }
}

function mascDATA(id)
{
	var campo = document.getElementById(id);

	if(campo.value.length == "2")
	{
		campo.value += "/";
	}

	if(campo.value.length == "5")
	{
		campo.value += "/";
	}
	
	if(campo.value.length == "10")
	{
		campo.value;
	}
}