function fechaDiv(divID) {
    $("div#" + divID + "").hide("slow");
}


function abreDiv(divID) {
    //alert(event.y);
    //document.getElementById(divID).style.top  = "340";
    //document.getElementById(divID).style.left = "340";


    $("div#" + divID + "").show("slow");
}


function criaXMLHttp() {
	if (typeof XMLHttpRequest != "undefined") 
		return new XMLHttpRequest();
	else if (typeof ActiveXObject != "undefined") { // suporte ao IE 7
		var aVersoes = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0",
		"MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0",
		"MSXML2.XMLHttp", "Microsoft.XMLHttp"
		];
		for (var i = 0; i < aVersoes.length; i++){
			try{
				return new ActiveXObject(aVersoes[i]);
			}catch (e) {}
		}
	}
	// se nenhum objeto xmlhttp for suportado
	throw new Error("Seu browser nao suporta AJAX");
}

function abrePagina(url,div){
	var oXMLHttp = criaXMLHttp();
	oXMLHttp.open("get",url, true);
	oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXMLHttp.onreadystatechange = function (){

		if(oXMLHttp.readyState == 1)
			abrePaginaExibir('<p>Carregando......</p>',div);
		if(oXMLHttp.readyState == 4)
			abrePaginaExibir(oXMLHttp.responseText,div);
	};
	oXMLHttp.send(null);
}


function abrePaginaExibir(sTxt,div){
    var divStatus = document.getElementById(div);
	divStatus.innerHTML = sTxt;
}



$(function(){
	//Funções para compatibilidade dos IEs
	if (jQuery.browser.msie) {
		//Adiciona o :hover a todos os elementos no IE6, através da class .hover
		if(parseInt(jQuery.browser.version) == 6){
			$("button, li, a, h3, tr, img, .border2")
				.hover(
					function(){ $(this).addClass("hover") },
					function(){ $(this).removeClass("hover") }
				)
		}
		//-----
		//Adiciona o :focus a todos os elementos nos IEs, através da class .focus
		$("input, textarea, a, button, h3")
			.focus(function(){ $(this).addClass("focus") })
			.blur(function(){ $(this).removeClass("focus") })
		//-----
	}
	//-----
	
	//transparencia_divs_do_meio
	$('.clientes img').fadeTo('slow',0.2);
	$('.clientes img').hover(function(){$(this).fadeTo('slow',1.0)},
	function(){$(this).fadeTo('slow',0.2)}
	)
	//fim: transparencia_divs_do_meio
	
	// Indique a um amigo
	$(".indique").click(function(){ $("#indicar").animate({'top':'0'}, 'fast') })
	$("#indicar button").click(function(){ $("#indicar").animate({'top':'-200px'}, 'fast') })
	//-----
	
	// Muda o texto a direita ao passar o mouse sobre os links
	$('.clientes a, .clientes a').hover(function(){
		$('.pessoaltxt h2').text($(this).text());
		$('.pessoaltxt span').text($(this).attr("title"));
	}, function(){
	});
	//-----
	
	// Muda o texto a direita ao passar o mouse sobre os links
	$('#mapa_atuacao a').hover(function(){
		var a = $(this);
		//$('.pessoaltxt h2').text($(a + ' h2').text());
		$('.pessoaltxt span').html($(a).html());
	}, function(){
	});
	//-----
	
	jQuery(function(){jQuery('a.topo').click(function(e){var $c = jQuery(this).parents();$c.stop().scrollTo( 0, {speed:1000,axis:$c.attr('id'), queue:true} );});});
	
	function toggle(el, alvo){
	$(el).click(function(){
		$(this).toggleClass("expanded").blur()
		$(alvo).slideToggle()
	})
	};
});





/*'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
''  Inscricao.class.asp
''  Created on:      24-ago-2010 23:19:13
''  Original author: Romero Gonçalves Dias
''  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''  Modification history:
''  
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''*/


function verificaTxtData(strData) {
    if (!validaData(strData)) {
        alert("A data não foi preenchida corretamente! Padrao dd/mm/aaaa.");
        document.formInscricao.dtNascimento.value = "";
    } else {
        document.formInscricao.labelError.value = "";
        document.formInscricao.labelError.style.backgroundColor = 'white';
    }
}


function verificaTxtCpf(strCPF) {
    if (!validaCpf(strCPF)) {
        alert("O CPF não foi preenchido corretamente! Padrao 999.999.999-99");
        document.formInscricao.cpf.value = "";
        document.formInscricao.cpf.focus();
    } else {
        document.formInscricao.labelError.value = "";
        document.formInscricao.labelError.style.backgroundColor = 'white';
    }
}



function verificaTxtEmail(strEmail) {
    if (!validaEmail(strEmail)) {
        alert("Preencha o campo com um e-mail válido.");
        document.formInscricao.email.value = "";
    } else {
        document.formInscricao.labelError.value = "";
        document.formInscricao.labelError.style.backgroundColor = 'white';
    }
}

function validaData(strData) {
    var er = new RegExp(/([0-2][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9]{3})/);
    return er.test(strData);
}



function validaEmail(strEmail) {
  var ER = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
  return ER.test(strEmail);
}



function validaCpf(strCPF) {
    var ER = new RegExp(/^\d{3}.\d{3}.\d{3}-\d{2}$/i);
    return ER.test(strCPF);
}



function habilitaTxtOutros() {
    if (document.formInscricao.outros.checked == 1) {
        document.formInscricao.txtOutros.style.display = '';
        document.formInscricao.txtOutros.focus();
    }
    else if (document.formInscricao.outros.checked == 0) {
        document.formInscricao.txtOutros.value = '';
        document.formInscricao.txtOutros.style.display = 'none';
    }
}


function mostraProblemaSaude(valor) 
{
    if (valor == 'SIM') {
        document.formInscricao.descricaoProblemaSaude.style.display = "";
        document.formInscricao.descricaoProblemaSaude.focus();
    }
    else if (valor == 'NAO') {
    document.formInscricao.descricaoProblemaSaude.value = "";
        document.formInscricao.descricaoProblemaSaude.style.display = "none";
    }
}



function verificaRadioProblemaSaude(){
	var objForm = document.formInscricao;
		
	for(var i =0; i<objForm.length; i++) {
		if(objForm.elements[i].name == 'idProblemaSaude')
		{
			if(objForm.elements[i].value == 'SIM' && objForm.elements[i].checked == 1 && document.formInscricao.descricaoProblemaSaude.value == "")
			{
				return false;
			} 
			if(objForm.elements[i].value == 'SIM' && objForm.elements[i].checked == 1 && document.formInscricao.descricaoProblemaSaude.value != "")
			{
				return true;
			}	
			if(objForm.elements[i].value == 'NAO' && objForm.elements[i].checked == 1)
			{
				return true;
			}				
		}
	}
}



function validaFormInscricao() {
    if (document.formInscricao.outros.checked == 1 && !document.formInscricao.txtOutros.value) {
        alert("Preencha o campo outros!");
        document.formInscricao.txtOutros.focus();
        return false;
    }

    else if (document.formInscricao.nome.value == "") {
        alert("Preencha o nome!");
        document.formInscricao.nome.focus();
        return false;
    }
    else if (document.formInscricao.idCategoria.value == "") {
        alert("Selecione uma categoria!");
        document.formInscricao.idCategoria.focus();
        return false;
    }
    else if (document.formInscricao.dtNascimento.value == "") {
        alert("Preencha sua data de nascimento!");
        document.formInscricao.dtNascimento.focus();
        return false;
    }
    else if (document.formInscricao.cpf.value == "" || !validaCpf(document.formInscricao.cpf.value)) {
        alert("Preencha seu CPF!");
        document.formInscricao.cpf.focus();
        return false;
    }
    else if (document.formInscricao.rg.value == "") {
        alert("Preencha seu RG!");
        document.formInscricao.rg.focus();
        return false;
    }
    else if (!verificaRadioProblemaSaude()){
	    alert("Preencha o campo problema de saúde!");
        document.formInscricao.idDeclaracao.focus();
        return false;
    }
    else if (document.formInscricao.idDeclaracao.checked == 0) {
        alert("Marque o campo Declaração!");
        document.formInscricao.idDeclaracao.focus();
        return false;
    } else {
		document.formInscricao.btnEnviar.value = "Enviando sua inscrição, aguarde....";
        return true;
    }
}



function TrocaTecla() { 
	if (window.event && window.event.keyCode == 13) { 
		window.event.keyCode = 9; 
		return true; 
	} 
}


function formatCPF(obj,e){
	 var keypress = window.event.keyCode;
	   if (keypress > 47 && keypress < 58 && obj.value.length < 14)	{
		if (obj.value.length == 3) 
		   obj.value = obj.value + ".";
		if (obj.value.length == 7) 
		   obj.value = obj.value + ".";
		if (obj.value.length == 11) 
		   obj.value = obj.value + "-";
	   } else 
		event.returnValue = false;
}




function formataDT(obj,e){
	var keypress = window.event.keyCode;
        if (keypress > 47 && keypress < 58 && obj.value.length < 10)
		{
		if (obj.value.length == 2) 
		   obj.value = obj.value + "/";
		if (obj.value.length == 5) 
		   obj.value = obj.value + "/";
		}
		else 
		event.returnValue = false;
}





function verificaInscricaoDuplicada(strCpf, idEvento) {
    if (strCpf != "" && idEvento != "") {
        var url = "Associado.asp?acao=verificaInscricaoDuplicada&strCpf=" + strCpf + "&idEvento=" + idEvento;
    
        var oXMLHttp = criaXMLHttp();
		oXMLHttp.open("get",url, true);
		oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXMLHttp.onreadystatechange = function () {
		    //if(oXMLHttp.readyState == 1)
		    //alert('<p>Carregando......</p>');
		    if (oXMLHttp.readyState == 4) {
		        var strReturn = oXMLHttp.responseText;
		        if (strReturn) {
		            arrReturn = strReturn.split(";");
					alert("Sua inscricao já foi realizada para este evento:\n\n" + 
						  arrReturn[0] + "\n" + 
						  arrReturn[1] + "\n" + 
						  arrReturn[2] + "\n" + 
						  arrReturn[3]
					);
		        }
		    }
		};
        oXMLHttp.send(null);
    }
}







	function preencheElementsFormInscricao(strCpf){
		var url = "Associado.asp?acao=detalhar&strCpf=" + strCpf;
		
		var oXMLHttp = criaXMLHttp();
		oXMLHttp.open("get",url, true);
		oXMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXMLHttp.onreadystatechange = function (){
			//if(oXMLHttp.readyState == 1)
			//alert('<p>Carregando......</p>');
			if(oXMLHttp.readyState == 4){
				var strReturn = oXMLHttp.responseText;
				if(strReturn){
					var arrAssociado = strReturn.split(";");
					
					document.formInscricao.nome.value 				= arrAssociado[0];
					document.formInscricao.dtNascimento.value 		= arrAssociado[1];
					document.formInscricao.rg.value 				= arrAssociado[3];
					document.formInscricao.equipePatrocinador.value = arrAssociado[4];
					document.formInscricao.endereco.value			= arrAssociado[5];
					document.formInscricao.numero.value 			= arrAssociado[6];
					document.formInscricao.bairro.value 			= arrAssociado[7];
					document.formInscricao.cidade.value 			= arrAssociado[8];
					document.formInscricao.estado.value 			= arrAssociado[9];
					document.formInscricao.cep.value 				= arrAssociado[10];
					document.formInscricao.telResidencia.value 		= arrAssociado[11];
					document.formInscricao.telCelular.value 		= arrAssociado[12];
					document.formInscricao.eMail.value 				= arrAssociado[13];
				}
			}
		};
		oXMLHttp.send(null);
	}
