//Função para adicionar um evento a um objeto, independente do navegador.
function addEvent(obj, evType, fn){
	if (obj.addEventListener){						//Todos os demais navegadores
		obj.addEventListener(evType, fn, false);
	}
	else if (obj.attachEvent){						//IE
		obj.detachEvent('on'+evType, fn);
		obj.attachEvent('on'+evType, fn);
	}
}

//Adiciona a função jsInicializar ao evento load da página da página
addEvent(window,'load',jsInicializar)

// Função para inicializar as demais funções necessárias para o correto funcionamento do site
function jsInicializar() {
	jsFormataInput();
	/*
	jsTextArea();
	*/
}

// Função para formatar o conteúdo do input/text para formato data, prefixo, telefone, hora e monetário,
// de acordo com a classe CSS.
function jsFormataInput(){
		if (document.getElementsByTagName){				//IE + Opera + FireFox
		var oInputs = document.getElementsByTagName('input');	//Retorna todos os objetos input

		for (var i=0; i<oInputs.length; i++){		//Percorre todos os objetos
			if (oInputs[i].className == 'csTelefonePre' || oInputs[i].className == 'csTelefone' ||	//Formata os elementos do tipo data, hora,
				oInputs[i].className == 'csData' || oInputs[i].className == 'csTextHora' ||			//prefixo de telefone, telefone e ramal.
				oInputs[i].className == 'csRamal' || oInputs[i].className == 'csTelefoneComp' ||
				oInputs[i].className == 'csCEP'){
				addEvent(oInputs[i],'keypress',jsFormatacao)

			}else if (oInputs[i].className == 'csMonetario'){	//Formata os elementos do tipo monetário.
				oInputs[i].onkeypress = 
					function() {
						if (document.all){			//IE + Opera
							var evnt = window.event;
							var tecla = evnt.keyCode;
							var sValor = this.value;
							var virgulaPos = sValor.indexOf(',', 0);
							var quantDec = 2;

							if ((tecla < 48 || tecla > 57) && tecla != 44) {//Permite apenas números e vírgula.
								evnt.returnValue = false;
							}else if(tecla == 44 && virgulaPos > -1){//Não permite que o usuário digite a vírgula duas vezes
								evnt.returnValue = false;
							}else if(sValor == '0' && tecla == 48){//Não permite o usuário digitar zero se o valor do campo for '0'.
								evnt.returnValue = false;
							}else if(sValor == '' && tecla == 44){//Acrescenta zero quando o usuário digita somente vírgula
								this.value = '0';
							}else if(virgulaPos > -1 && (sValor.length - (virgulaPos + 1)) >= quantDec){//Não permite que o usuário digite mais de duas casas após a vírgula
								evnt.returnValue = false;
							}
						}
					}

			}else if (oInputs[i].className == 'csFormatacao'){	//Formata os elementos do tipo formatação de texto.
				oInputs[i].readOnly=true;
				oInputs[i].onmouseover = function() {this.select()};

			}else if (oInputs[i].className == 'csArquivo' || oInputs[i].className == 'csTamanho'){
				oInputs[i].readOnly=true;
			}
			
			if(oInputs[i].readOnly)	// Se o bjeto é readOnly, não recebe foco.
				oInputs[i].tabIndex = -1;
		}
	}
}

// Função para formatar o conteúdo do input/text para formato data, prefixo, telefone, hora e monetário,
// de acordo com a classe CSS.
function jsFormatacao(e){
	if (typeof(e)=='undefined')var e=window.event;	//Captura o evento no IE
	var oText = e.target?e.target:e.srcElement;		//Retorna o objeto para o IE e os demais
	if(oText.nodeType == 3)oText=oText.parentNode;	//Corrige bug no Safari
	var sValue = oText.value;						//Retorna o valor atual do objeto
	var nTecla = window.event?e.keyCode:e.which;	//Retorna o valor da tecla pressionada
	var oProxCampo = jsProximoCampo(oText.id);		//Retorna o próximo campo do formulário

	if (nTecla != 8 && nTecla != 13){				//se for "backspace" ou "enter" não faz nada
		expressao = /[\.\,\:\/\-\(\) ]/gi;			//Expressão regular para limpar os caracteres de formatação
		sValue = sValue.toString().replace(expressao, '');	//Limpa ps caracteres

		var nLenO = sValue.length;					//Retorna a quantidade de caracteres do objeto
		var nLenM = nLenO;							//Inicia o tamanho da máscara com o tamanho da string
		var nCount = 0;								//Inicia o contador
		var sSaida = '';							//Limpa a saída
		var sMask = '';								//Limpa a máscara

		switch (oText.className){					//Verifica o tipo de máscara que deverá ser aplicada
			case 'csData':						//Máscara de data
				sMask = '99/99/9999'; break;
			case 'csTextHora':						//Máscara de hora
				sMask = '99:99'; break;
			case 'csTelefonePre':					//Máscara de prefixo de telefone
				sMask = '99'; break;
			case 'csTelefone':						//Máscara de telefone
				sMask = '99999999'; break;
			case 'csTelefoneComp':					//Máscara de telefone com prefixo
				sMask = '(99)9999-9999'; break;
			case 'csRamal':							//Máscara de ramal
				sMask = '9999'; break;
			case 'csCEP':							//Máscara de ramal
				sMask = '99.999-999'; break;
		}

		for (var i=0; i <= nLenM; i++) {			//Percorre o total de caracteres da máscara
			var bMask = (sMask.charAt(i).search(expressao)!=-1);	//Procura o caracter atual de ntro da máscara

			if (bMask) {							//O caracter é da máscara
				sSaida += sMask.charAt(i);			//Adiciona a máscara à saída
				nLenM++;							//Incrementa o contador da máscara
			} else {								//O caracter não é da máscara
				sSaida += sValue.charAt(nCount);	//Adiciona o caracter à saída
				nCount++;							//Incrementa o contador da string
			}
		}

		oText.value = sSaida;						//Devolve o valor formatado para o objeto

		if (sMask.charAt(i-1) == '9')				//Permite apenas números
			if (!(nTecla>47 && nTecla<58))			//Só retorna se for um números de 0 a 9
				return false;

		if (oProxCampo && oText.value.length == (sMask.length)-1){	//Foca o próximo campo se for a hora
			if (window.event)						//IE
				setTimeout ('document.getElementById(\'' + oProxCampo.id + '\').focus()', 50);
			else									//Demais navegadores
				oProxCampo.focus();
		}
	}else
		return true;
	
}

//Localiza o próximo campo no formulário, que deverá receber o foco.
function jsProximoCampo(sNome){
	if (document.getElementsByTagName){				//IE + Opera + FireFox
		var oForms = document.forms;				//Retorna todos o forms do documento

		for (var i=0; i < oForms.length; i++){		//Navega entre todos os formulários do documento.
			var oForm = oForms[i];					//Retorna o form atual

			for (var j=0; j < oForm.length; j++){	//Navega entre todos os objetos do formulário.
				if (oForm[j].id == sNome) {			//Verifica se o objeto é o que foi passado como parâmetro.
					if (oForm[j+1].id)				//Verifica se existe outro objeto após o objeto atual.
						return oForm[j+1];			//Retorna o objeto que deverá receber o foco.
				}
			}
		}
	}
}

//Função para abrir conteúdo adcional de notícias e projetos
function jsAbrirAdicionais(sId){
	jsFecharAdicionais();
	if (document.getElementById(sId))
		document.getElementById(sId).style.display = 'block';
}

//Função para abrir conteúdo adicional de igrejas
function jsCadastrarIgreja(){
	if (document.getElementById('stNovo').checked){
		document.getElementById('dvCadastrarIgreja').style.display = (navigator.appName == 'Microsoft Internet Explorer' ? 'block' : 'table');
		document.getElementById('dvIgreja').style.display = 'none';
		document.getElementById('cdIgreja').value = '';
	}else{
		document.getElementById('dvCadastrarIgreja').style.display = 'none';
		document.getElementById('dvIgreja').style.display = (navigator.appName == 'Microsoft Internet Explorer' ? 'block' : 'table');
	}
}



//Função para fechar conteúdo adcional de notícias e projetos
function jsFecharAdicionais(){
	if (document.getElementById('divAdicionalFotos'))
		document.getElementById('divAdicionalFotos').style.display = 'none';
	if (document.getElementById('divAdicionalVideos'))
		document.getElementById('divAdicionalVideos').style.display = 'none';
	if (document.getElementById('divAdicionalAudios'))
		document.getElementById('divAdicionalAudios').style.display = 'none';
	if (document.getElementById('divAdicionalTextos'))
		document.getElementById('divAdicionalTextos').style.display = 'none';
}

//Função para executar conteúdo adcional de mídia de notícias e projetos
function jsPlay(sURL, bTipo, nuW, nuH, sTitulo){
	var sSaida = '';

	sSaida = '<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="' + nuW + 'px" height="' + nuH + 'px" align="center">';

	sSaida += '	<param name="URL" value="' + sURL + '" ref="" />'
	sSaida += '	<param name="rate" value="1" />'
	sSaida += '	<param name="balance" value="0" />'
	sSaida += '	<param name="currentPosition" value="0" />'
	sSaida += '	<param name="defaultFrame" value="value" />'
	sSaida += '	<param name="playCount" value="1" />'
	sSaida += '	<param name="autoStart" value="-1" />'
	sSaida += '	<param name="currentMarker" value="0" />'
	sSaida += '	<param name="invokeURLs" value="-1" />'
	sSaida += '	<param name="baseURL" value="" />'
	sSaida += '	<param name="volume" value="100" />'
	sSaida += '	<param name="mute" value="0" />'
	sSaida += '	<param name="uiMode" value="mini" />'
	sSaida += '	<param name="stretchToFit" value="0" />'
	sSaida += '	<param name="windowlessVideo" value="0" />'
	sSaida += '	<param name="enabled" value="1" />'
	sSaida += '	<param name="enableContextMenu" value="-1" />'
	sSaida += '	<param name="fullScreen" value="0" />'
	sSaida += '	<param name="SAMIStyle" value="" />'
	sSaida += '	<param name="SAMILang" value="" />'
	sSaida += '	<param name="SAMIFilename" value="" />'
	sSaida += '	<param name="captioningID" value="" />'
	sSaida += '	<param name="enableErrorDialogs" value="0" />'
	sSaida += '	<param name="_cx" value="4075" />'
	sSaida += '	<param name="_cy" value="4366" />'
	sSaida += '</object>'

	if (bTipo == 1){
		document.getElementById('dvPlayerVideo').innerHTML = sSaida;
		document.getElementById('h4TituloVideo').innerHTML = sTitulo ? sTitulo : 'Arquivo de Vídeo';
	}
	else{
		document.getElementById('dvPlayerAudio').innerHTML = sSaida;
		document.getElementById('h4TituloAudio').innerHTML = sTitulo ? sTitulo : 'Arquivo de Áudio';
	}
}


//Função para gerar uma saudação, com data.
function jsSaudacao(){
	var now = new Date();
	var mName = now.getMonth() + 1;
	var dName = now.getDay() + 1;
	var dayNr = now.getDate();
	var yearNr=now.getYear();
	var sSaudacao

	if (yearNr<2000){yearNr = yearNr+1900}
	if(dName==1) Day = 'Domingo';
	if(dName==2) Day = 'Segunda-feira';
	if(dName==3) Day = 'Terça-feira';
	if(dName==4) Day = 'Quarta-feira';
	if(dName==5) Day = 'Quinta-feira';
	if(dName==6) Day = 'Sexta-feira';
	if(dName==7) Day = 'Sábado';
	if(mName==1) Month = 'Janeiro';
	if(mName==2) Month = 'Fevereiro';
	if(mName==3) Month = 'Março';
	if(mName==4) Month = 'Abril';
	if(mName==5) Month = 'Maio';
	if(mName==6) Month = 'Junho';
	if(mName==7) Month = 'Julho';
	if(mName==8) Month = 'Agosto';
	if(mName==9) Month = 'Setembro';
	if(mName==10) Month = 'Outubro';
	if(mName==11) Month = 'Novembro';
	if(mName==12) Month = 'Dezembro';
	sSaudacao = ' ' + Day + ', ' + dayNr + ' de ' + Month + ' de ' + yearNr;

	if (( now.getHours() >= 0 && now.getHours() <=3 ) || ( now.getHours() >= 18 && now.getHours() <=24 ))
		sSaudacao += ' - Boa noite';
	else if ( now.getHours() >= 4 && now.getHours() <= 11 )
		sSaudacao += ' - Bom dia';
	else if ( now.getHours() >= 12 && now.getHours() <= 17 )
		sSaudacao += ' - Boa tarde';

	document.write(sSaudacao + '!')
}

//Função PopUp criada em 11/08/2003 - Alencar
function PopUp(strUrl, strName, intWidth, intHeight, strRedim, strScroll, strToolBar, strMenuBar, strLocationBar, intTop, intLeft) {
	/*
	strUrl: Url que será aberta na janela pop up;
	strName: Nome da janela para casos dela ser utilizada como alvo (target);
	intWidth: Largura da janela que será criada;
	intHeight: Altura da janela que será criada;
	strRedim: Utilizar 'yes' ou 'no' informando se deseja que a janela seja redimensionável;
	strScroll: Utilizar 'yes' ou 'no' informando se deseja barras de rolagem;
	strMenuBar: Utilizar 'yes' ou 'no' informando se deseja barra de menu;
	strLocationBar: Utilizar 'yes' ou 'no' informando se deseja barra de endereço;
	intTop: Posição da janela em relação ao topo da tela;
	intLeft: Posição da janela em relação à esquerda da tela;
	*/

	if(isNaN(intTop)) intTop = ((screen.height - intHeight)/2);
	if(isNaN(intLeft)) intLeft = ((screen.width - intWidth)/2);
	if(strToolBar == 'yes') intHeight = intHeight - 25;
	if(strMenuBar == 'yes') intHeight = intHeight - 25;
	if(strLocationBar == 'yes') intHeight = intHeight - 25;

	janela = window.open(strUrl, strName, 'directories=no, menubar=' + strMenuBar + ', location=' + strLocationBar + ', toolbar=' + strToolBar + ', status=yes, width=' + intWidth + ', height=' + intHeight + ', scrollbars=' + strScroll + ', top=' + intTop + ', left=' + intLeft + ', resizable='+ strRedim);
}

function jannoredbar(str, strNmWindow, largura, altura, redim) {
	strNmWindow = window.open(str,strNmWindow,'width=' + largura + ',height=' + altura + ',scrollbars=yes, top=20, left=30, resizable=no');
	strNmWindow.location.href=str;
}

function jsAlternaCor(obj){
	var arA = obj.getElementsByTagName('a');
	var bCor = true;
	
	for(var i=0; i<arA.length; i++){
		if (!arA[i].className){
			arA[i].className = bCor ? 'csCor' : 'csNotCor';
			bCor = !bCor;
		}
	}
}

//Ajustar fonte.
function jsFonte(opcao){
	var oConteudo;

	if (oConteudo = document.getElementById('spCorpoTexto')){
		if (opcao == 1){
			if (oConteudo.style.fontSize == '100%')
				oConteudo.style.fontSize = '120%';
			else if (oConteudo.style.fontSize == '120%')
				oConteudo.style.fontSize = '140%';
			else if (oConteudo.style.fontSize == '140%')
				oConteudo.style.fontSize = '150%';
			else if (oConteudo.style.fontSize == '150%')
				oConteudo.style.fontSize = '150%';
			else
				oConteudo.style.fontSize = '120%';
		}else{
			if (oConteudo.style.fontSize == '150%')
				oConteudo.style.fontSize = '140%';
			else if (oConteudo.style.fontSize == '140%')
				oConteudo.style.fontSize = '120%';
			else if (oConteudo.style.fontSize == '120%')
				oConteudo.style.fontSize = '100%';
			else
				oConteudo.style.fontSize = '100%';
		}
	}
}

function jsValidaContato(){
	//Validação com RegEx
	var bAssunto	= document.getElementById('cdTema').value != '';
	var bNome		= document.getElementById('nmRemetente').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0?true:false;
	var bEmail		= document.getElementById('edEmail').value.search(/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]+\.([a-zA-Z]{2,4})$/) == 0?true:false;
	var bTelefone	= document.getElementById('nuTelefone').value.search(/^\([1-9][0-9]\)\d{4}-\d{4}$/) == 0?true:false;
//	var bTelefone	= document.getElementById('nuTelefone').value.search(/^([0-9]{8,10})$/) == 0?true:false;
	var bCidade		= document.getElementById('nmCidade').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
	var bMensagem	= document.getElementById('dsMensagem').value.search(/((.|\n){10,1000})$/) == 0?true:false;
	var sSaida		= '';
	var sFocus		= '';

	if ( !(bAssunto && bNome && bEmail && bTelefone && bCidade && bMensagem) ){
		sSaida = 'Corrija os campos abaixo:\n';
		if (!bAssunto){
			sSaida += '\nAssunto: ' + document.getElementById('cdTema').title;
			if (sFocus == '') sFocus='document.getElementById(\'cdTema\').focus()';
		}
		if (!bNome){
			sSaida += '\nNome: ' + document.getElementById('nmRemetente').title;
			sFocus = 'document.getElementById(\'nmRemetente\').focus()';
		}
		if (!bEmail){
			sSaida += '\nE-mail: ' + document.getElementById('edEmail').title;
			if (sFocus == '') sFocus='document.getElementById(\'edEmail\').focus()';
		}
		if (!bTelefone){
			sSaida += '\nTelefone: ' + document.getElementById('nuTelefone').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuTelefone\').focus()';
		}
		if (!bCidade){
			sSaida += '\nCidade: ' + document.getElementById('nmCidade').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmCidade\').focus()';
		}
		if (!bMensagem){
			sSaida += '\nMensagem: ' + document.getElementById('dsMensagem').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsMensagem\').focus()';
		}
		alert(sSaida);
		eval(sFocus);
	}else
		document.getElementById('frmContato').submit();
}

function jsValidaCadastro(){
	//Validação com RegEx
	var bNome			= document.getElementById('nmUsuario').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0?true:false;
	var bNascimento		= document.getElementById('dtNascimento').value.search(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/([1][9][0-9]{2}|[2][0][0][0-6])$/) == 0?true:false;
	var bSexo			= document.getElementById('dmSexo').value != '';
	var bEmail			= document.getElementById('edEmail').value.search(/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]+\.([a-zA-Z]{2,4})$/) == 0?true:false;
	var bTelefone		= document.getElementById('nuTelefone').value.search(/^\([1-9][0-9]\)\d{4}-\d{4}$/) == 0?true:false;
	var bSenha			= document.getElementById('dsSenha').value.search(/^(.{6,15})$/) == 0?true:false;
	var bConfirmacao	= document.getElementById('dsConfirmacao').value == document.getElementById('dsSenha').value;
	var bEndereco		= document.getElementById('dsEndereco').value.search(/^(.{5,100})$/) == 0?true:false;
	var bBairro			= document.getElementById('nmBairro').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
	var bCidade			= document.getElementById('nmCidade').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
	var bEstado			= document.getElementById('sgEstado').value != '';
	var bCEP			= document.getElementById('nuCEP').value.search(/^([1-9][0-9]{4})-([0-9]{3})$/) == 0?true:false;

	//Validação da igreja
	bIgreja = true; bNomeIgreja = true; bResponsavel = true; bTelefoneIgreja = true; bEnderecoIgreja = true; bBairroIgreja = true; bCidadeIgreja = true; bEstadoIgreja = true; bCEPIgreja = true;
	var stNovo			= document.getElementById('stNovo').checked;
	if (stNovo){
		bNomeIgreja		= document.getElementById('nmIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bResponsavel	= document.getElementById('nmResponsavel').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0 || document.getElementById('nmResponsavel').value == ''?true:false;
		bTelefoneIgreja	= document.getElementById('nuTelefoneIgreja').value.search(/^\([1-9][0-9]\)\d{4}-\d{4}$/) == 0 || document.getElementById('nuTelefoneIgreja').value == ''?true:false;
		bEnderecoIgreja	= document.getElementById('dsEnderecoIgreja').value.search(/^(.{5,100})$/) == 0 || document.getElementById('dsEnderecoIgreja').value == ''?true:false;
		bBairroIgreja	= document.getElementById('nmBairroIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bCidadeIgreja	= document.getElementById('nmCidadeIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bEstadoIgreja	= document.getElementById('sgEstadoIgreja').value != '';
		bCEPIgreja		= document.getElementById('nuCEPIgreja').value.search(/^([1-9][0-9]{4})-([0-9]{3})$/) == 0 || document.getElementById('nuCEPIgreja').value == ''?true:false;
	}else{
		bIgreja = document.getElementById('cdIgreja').value.search(/^[0-9]$/) == 0?true:false;
	}
	
	var sSaida			= '';
	var sFocus			= '';

	if ( !(bIgreja && bNome && bNascimento && bSexo && bEmail && bTelefone && bSenha && bConfirmacao && bEndereco && bBairro && bCidade && bEstado && bCEP && bNomeIgreja && bResponsavel && bTelefoneIgreja && bEnderecoIgreja && bBairroIgreja && bCidadeIgreja && bEstadoIgreja && bCEPIgreja ) ){
		sSaida = 'Corrija os campos abaixo:\n';

		//Dados úteis
		if(!(bNome && bNascimento && bSexo && bEmail && bTelefone && bSenha && bConfirmacao))
			sSaida += '\n* Dados Úteis\n';

		if (!bNome){
			sSaida += '\nNome: ' + document.getElementById('nmUsuario').title;
			sFocus = 'document.getElementById(\'nmUsuario\').focus()';
		}
		if (!bNascimento){
			sSaida += '\nData de Nascimento: ' + document.getElementById('dtNascimento').title;
			if (sFocus == '') sFocus='document.getElementById(\'dtNascimento\').focus()';
		}
		if (!bSexo){
			sSaida += '\nSexo: ' + document.getElementById('dmSexo').title;
			if (sFocus == '') sFocus='document.getElementById(\'dmSexo\').focus()';
		}
		if (!bEmail){
			sSaida += '\nE-mail: ' + document.getElementById('edEmail').title;
			if (sFocus == '') sFocus='document.getElementById(\'edEmail\').focus()';
		}
		if (!bTelefone){
			sSaida += '\nTelefone: ' + document.getElementById('nuTelefone').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuTelefone\').focus()';
		}
		if (!bSenha){
			sSaida += '\nSenha: ' + document.getElementById('dsSenha').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsSenha\').focus()';
		}
		if (!bConfirmacao){
			sSaida += '\nConfirmação: ' + document.getElementById('dsConfirmacao').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsConfirmacao\').focus()';
		}

		//Endereço
		if(!(bEndereco && bBairro && bCidade && bEstado && bCEP))
			sSaida += '\n\n* Sobre Você\n';

		if (!bEndereco){
			sSaida += '\nEndereço: ' + document.getElementById('dsEndereco').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsEndereco\').focus()';
		}
		if (!bBairro){
			sSaida += '\nBairro: ' + document.getElementById('nmBairro').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmBairro\').focus()';
		}
		if (!bCidade){
			sSaida += '\nCidade: ' + document.getElementById('nmCidade').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmCidade\').focus()';
		}
		if (!bEstado){
			sSaida += '\nEstado: ' + document.getElementById('sgEstado').title;
			if (sFocus == '') sFocus='document.getElementById(\'sgEstado\').focus()';
		}
		if (!bCEP){
			sSaida += '\nCEP: ' + document.getElementById('nuCEP').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuCEP\').focus()';
		}
		
		//Igreja
		if(!(bIgreja && bNomeIgreja && bResponsavel && bTelefoneIgreja && bEnderecoIgreja && bBairroIgreja && bCidadeIgreja && bEstadoIgreja && bCEPIgreja))
			sSaida += '\n\n* Sobre a Igreja\n';

		if (!bIgreja){
			sSaida += '\nIgreja: ' + document.getElementById('cdIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'cdIgreja\').focus()';
		}
		if (!bNomeIgreja){
			sSaida += '\nIgreja: ' + document.getElementById('nmIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmIgreja\').focus()';
		}
		if (!bResponsavel){
			sSaida += '\nResponsável: ' + document.getElementById('nmResponsavel').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmResponsavel\').focus()';
		}
		if (!bTelefoneIgreja){
			sSaida += '\nTelefone: ' + document.getElementById('nuTelefoneIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuTelefoneIgreja\').focus()';
		}
		if (!bEnderecoIgreja){
			sSaida += '\nEndereço: ' + document.getElementById('dsEnderecoIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsEnderecoIgreja\').focus()';
		}
		if (!bBairroIgreja){
			sSaida += '\nBairro: ' + document.getElementById('nmBairroIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmBairroIgreja\').focus()';
		}
		if (!bCidadeIgreja){
			sSaida += '\nCidade: ' + document.getElementById('nmCidadeIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmCidadeIgreja\').focus()';
		}
		if (!bEstadoIgreja){
			sSaida += '\nEstado: ' + document.getElementById('sgEstadoIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'sgEstadoIgreja\').focus()';
		}
		if (!bCEPIgreja){
			sSaida += '\nCEP: ' + document.getElementById('nuCEPIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuCEPIgreja\').focus()';
		}
		alert(sSaida);
		eval(sFocus);
	}else
		document.getElementById('frmCadastro').submit();
}


function jsValidaCadastroEdi(){
	//Validação com RegEx
	var bNome			= document.getElementById('nmUsuario').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0?true:false;
	var bNascimento		= document.getElementById('dtNascimento').value.search(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/([1][9][0-9]{2}|[2][0][0][0-6])$/) == 0?true:false;
	var bSexo			= document.getElementById('dmSexo').value != '';
	var bEmail			= document.getElementById('edEmail').value.search(/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]+\.([a-zA-Z]{2,4})$/) == 0?true:false;
	var bTelefone		= document.getElementById('nuTelefone').value.search(/^\([1-9][0-9]\)\d{4}-\d{4}$/) == 0?true:false;
	var bSenha			= document.getElementById('dsSenha').value.search(/^(.{6,15})$/) == 0?true:false;
	var bConfirmacao	= document.getElementById('dsConfirmacao').value == document.getElementById('dsSenha').value;
	var bEndereco		= document.getElementById('dsEndereco').value.search(/^(.{5,100})$/) == 0?true:false;
	var bBairro			= document.getElementById('nmBairro').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
	var bCidade			= document.getElementById('nmCidade').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
	var bEstado			= document.getElementById('sgEstado').value != '';
	var bCEP			= document.getElementById('nuCEP').value.search(/^([1-9][0-9]{4})-([0-9]{3})$/) == 0?true:false;

	//Validação da igreja
	bIgreja = true; bNomeIgreja = true; bResponsavel = true; bTelefoneIgreja = true; bEnderecoIgreja = true; bBairroIgreja = true; bCidadeIgreja = true; bEstadoIgreja = true; bCEPIgreja = true;
	var stNovo			= document.getElementById('stNovo').checked;
	if (stNovo){
		bNomeIgreja		= document.getElementById('nmIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bResponsavel	= document.getElementById('nmResponsavel').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0 || document.getElementById('nmResponsavel').value == ''?true:false;
		bTelefoneIgreja	= document.getElementById('nuTelefoneIgreja').value.search(/^\([1-9][0-9]\)\d{4}-\d{4}$/) == 0 || document.getElementById('nuTelefoneIgreja').value == ''?true:false;
		bEnderecoIgreja	= document.getElementById('dsEnderecoIgreja').value.search(/^(.{5,100})$/) == 0 || document.getElementById('dsEnderecoIgreja').value == ''?true:false;
		bBairroIgreja	= document.getElementById('nmBairroIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bCidadeIgreja	= document.getElementById('nmCidadeIgreja').value.search(/^([A-Za-zÀ-ú ]{3,100})$/) == 0?true:false;
		bEstadoIgreja	= document.getElementById('sgEstadoIgreja').value != '';
		bCEPIgreja		= document.getElementById('nuCEPIgreja').value.search(/^([1-9][0-9]{4})-([0-9]{3})$/) == 0 || document.getElementById('nuCEPIgreja').value == ''?true:false;
	}else{
		bIgreja = document.getElementById('cdIgreja').value.search(/^[0-9]$/) == 0?true:false;
		alert(bIgreja)
	}

	var sSaida			= '';
	var sFocus			= '';

	if ( !(bIgreja && bNome && bNascimento && bSexo && bEmail && bTelefone && bSenha && bConfirmacao && bEndereco && bBairro && bCidade && bEstado && bCEP && bNomeIgreja && bResponsavel && bTelefoneIgreja && bEnderecoIgreja && bBairroIgreja && bCidadeIgreja && bEstadoIgreja && bCEPIgreja ) ){
		sSaida = 'Corrija os campos abaixo:\n';

		//Dados úteis
		if(!(bNome && bNascimento && bSexo && bEmail && bTelefone && bSenha && bConfirmacao))
			sSaida += '\n* Dados Úteis\n';

		if (!bNome){
			sSaida += '\nNome: ' + document.getElementById('nmUsuario').title;
			sFocus = 'document.getElementById(\'nmUsuario\').focus()';
		}
		if (!bNascimento){
			sSaida += '\nData de Nascimento: ' + document.getElementById('dtNascimento').title;
			if (sFocus == '') sFocus='document.getElementById(\'dtNascimento\').focus()';
		}
		if (!bSexo){
			sSaida += '\nSexo: ' + document.getElementById('dmSexo').title;
			if (sFocus == '') sFocus='document.getElementById(\'dmSexo\').focus()';
		}
		if (!bEmail){
			sSaida += '\nE-mail: ' + document.getElementById('edEmail').title;
			if (sFocus == '') sFocus='document.getElementById(\'edEmail\').focus()';
		}
		if (!bTelefone){
			sSaida += '\nTelefone: ' + document.getElementById('nuTelefone').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuTelefone\').focus()';
		}
		if (!bSenha){
			sSaida += '\nSenha: ' + document.getElementById('dsSenha').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsSenha\').focus()';
		}
		if (!bConfirmacao){
			sSaida += '\nConfirmação: ' + document.getElementById('dsConfirmacao').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsConfirmacao\').focus()';
		}

		//Endereço
		if(!(bEndereco && bBairro && bCidade && bEstado && bCEP))
			sSaida += '\n\n* Sobre Você\n';

		if (!bEndereco){
			sSaida += '\nEndereço: ' + document.getElementById('dsEndereco').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsEndereco\').focus()';
		}
		if (!bBairro){
			sSaida += '\nBairro: ' + document.getElementById('nmBairro').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmBairro\').focus()';
		}
		if (!bCidade){
			sSaida += '\nCidade: ' + document.getElementById('nmCidade').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmCidade\').focus()';
		}
		if (!bEstado){
			sSaida += '\nEstado: ' + document.getElementById('sgEstado').title;
			if (sFocus == '') sFocus='document.getElementById(\'sgEstado\').focus()';
		}
		if (!bCEP){
			sSaida += '\nCEP: ' + document.getElementById('nuCEP').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuCEP\').focus()';
		}
		
		//Igreja
		if(!(bIgreja && bNomeIgreja && bResponsavel && bTelefoneIgreja && bEnderecoIgreja && bBairroIgreja && bCidadeIgreja && bEstadoIgreja && bCEPIgreja))
			sSaida += '\n\n* Sobre a Igreja\n';

		if (!bIgreja){
			sSaida += '\nIgreja: ' + document.getElementById('cdIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'cdIgreja\').focus()';
		}
		if (!bNomeIgreja){
			sSaida += '\nIgreja: ' + document.getElementById('nmIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmIgreja\').focus()';
		}
		if (!bResponsavel){
			sSaida += '\nResponsável: ' + document.getElementById('nmResponsavel').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmResponsavel\').focus()';
		}
		if (!bTelefoneIgreja){
			sSaida += '\nTelefone: ' + document.getElementById('nuTelefoneIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuTelefoneIgreja\').focus()';
		}
		if (!bEnderecoIgreja){
			sSaida += '\nEndereço: ' + document.getElementById('dsEnderecoIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsEnderecoIgreja\').focus()';
		}
		if (!bBairroIgreja){
			sSaida += '\nBairro: ' + document.getElementById('nmBairroIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmBairroIgreja\').focus()';
		}
		if (!bCidadeIgreja){
			sSaida += '\nCidade: ' + document.getElementById('nmCidadeIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmCidadeIgreja\').focus()';
		}
		if (!bEstadoIgreja){
			sSaida += '\nEstado: ' + document.getElementById('sgEstadoIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'sgEstadoIgreja\').focus()';
		}
		if (!bCEPIgreja){
			sSaida += '\nCEP: ' + document.getElementById('nuCEPIgreja').title;
			if (sFocus == '') sFocus='document.getElementById(\'nuCEPIgreja\').focus()';
		}
		alert(sSaida);
		eval(sFocus);
	}else
		document.getElementById('frmCadastro').submit();
}

//Valida o formulário de indicação de página por e-mail
function jsValidaIndicacao(){
	//Validação com RegEx
	var bNome			= document.getElementById('nmRemetente').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0?true:false;
	var bEmail			= document.getElementById('edEmail').value.search(/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]+\.([a-zA-Z]{2,4})$/) == 0?true:false;
	var bDestinatario	= document.getElementById('nmDestinatario').value.search(/^([A-Za-zÀ-ú ]{3,70})$/) == 0?true:false;
	var bEmailDes		= document.getElementById('edEmailDes').value.search(/^[a-zA-Z0-9_.-]{2,}@[a-zA-Z0-9_.-]+\.([a-zA-Z]{2,4})$/) == 0?true:false;
	var bMensagem		= document.getElementById('dsMensagem').value.search(/((.|\n){10,1000})$/) == 0?true:false;
	var sSaida			= '';
	var sFocus			= '';

	if ( !(bNome && bEmail && bDestinatario && bEmailDes && bMensagem) ){
		sSaida = 'Corrija os erros abaixo:\n';
		if (!bNome){
			sSaida += '\nNome: ' + document.getElementById('nmRemetente').title;
			sFocus = 'document.getElementById(\'nmRemetente\').focus()';
		}
		if (!bEmail){
			sSaida += '\nE-mail: ' + document.getElementById('edEmail').title;
			if (sFocus == '') sFocus='document.getElementById(\'edEmail\').focus()';
		}
		if (!bDestinatario){
			sSaida += '\nNome de destinatário: ' + document.getElementById('nmDestinatario').title;
			if (sFocus == '') sFocus='document.getElementById(\'nmDestinatario\').focus()';
		}
		if (!bEmailDes){
			sSaida += '\nE-mail de destino: ' + document.getElementById('edEmailDes').title;
			if (sFocus == '') sFocus='document.getElementById(\'edEmailDes\').focus()';
		}
		if (!bMensagem){
			sSaida += '\nMensagem: ' + document.getElementById('dsMensagem').title;
			if (sFocus == '') sFocus='document.getElementById(\'dsMensagem\').focus()';
		}
		alert(sSaida);
		eval(sFocus);
	}else
		document.getElementById('frmIndicacao').submit();
}

//Função para retornar o objeto que gerou o evento
function jsRetornaObjetoDoEvento(e){
	if (typeof(e)=='undefined')var e=window.event;	//Captura o evento no IE
	var obj = e.target?e.target:e.srcElement;		//Retorna o objeto para o IE e os demais
	if(obj.nodeType == 3)obj=obj.parentNode;	//Corrige bug no Safari

	return obj;
}

//Função para adicionar aos favoritos
function jsAdicionarFavoritos(){
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(document.location,"Projeto Águas do Rio Doce");
	}else {
		if(navigator.appName == "Netscape")
			alert ("Pressione Crtl+D para adicionar esta página em seus favoritos.");
	}
}