// JavaScript Document
function charUpdate2(charmax , campo, txt){
	field = document.getElementById(campo);
	
	restante = charmax - (field.value.length);
	txt_field = document.getElementById("contador");
	
	if (txt == 1)
		txt_field.innerHTML = "Faltam <b>"+restante+"</b> caracteres.";
	else{
		txt_field.innerHTML = "<b>"+restante+"</b>";
		if (restante <= 140 && restante >= 20)
			txt_field.style.color = "#CCCCCC";
		if (restante <= 19 && restante >= 10)
			txt_field.style.color = "#5c0002";
		else if (restante <= 9)
			txt_field.style.color = "#d40d12";
	}
	
	
	if(restante <= 0){
		field.value = field.value.substring(0, (charmax-1) );
		if (txt == 1)
			txt_field.innerHTML = "<b><font color='#FF0000'>Limite de caracteres alcan&ccedil;ado.</font></b>";
	}
}
function charUpdate( charmax , campo){
	field = document.getElementById(campo);
	txt_field = document.getElementById("contador");
	txt_field.innerHTML = field.value.length;
	if(field.value.length >= charmax )
		field.value = field.value.substring(0, charmax );
}

function addFavoritos(){
	var url = "http://www.icezonasul.com.br/";
	var title = "<?php echo htmlentities(addslashes('Igreja Cristã Evangélica da Zona Sul')); ?>";
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	} else if(document.all){
		window.external.AddFavorite(url, title);
	}
}

function popupImprimir(area,id,width,height){
	var url;
	
	if(area == "noticia"){
		url = "script/php/imprimir.php?id=";
	}
	window.open(url+id,"imprirmir_"+area,"width="+width+",height="+height);
	
}
var larguraJanela, larguraJanela, larguraPagina, alturaPagina; 
function pegarPosicaoCentro(largura,altura){

	larguraJanela = $(window).width();
	alturaJanela = $(window).height();

	var lateral = Math.round((larguraJanela - largura) / 2);
	var topo	= Math.round((alturaJanela - altura) / 2);
	
	var teste = $(document).scrollTop();

	topo += teste;

	return topo+":"+lateral;
}
var msgBox = ""
var blackBg = "";

function abrirCaixaDialogo(area){

	larguraPagina = $(document).width();
	alturaPagina = $(document).height();
	
	blackBg = document.getElementById("bgMensagem");
	blackBg.style.left		= "0px";
	blackBg.style.top		= "0px";
	blackBg.style.width		= larguraPagina+"px";
	blackBg.style.height	= alturaPagina+"px";
	blackBg.style.display	= "block";
	
	msgBox = document.getElementById("caixaMensagem");
	
	if (area == "lembrarSenha"){
		var largura = 500;
		var altura	= 150;
		
		var posicoes = pegarPosicaoCentro(largura,altura).split(":");
		
		var topo	= posicoes[0];
		var lateral	= posicoes[1];

		document.getElementById("palcoCaixaDialogo").style.height = "300px";
		
		msgBox.style.top		= topo+"px";
		msgBox.style.left		= lateral+"px";
		msgBox.style.display	= "block";
		
		
	}
}
function fecharCaixaDialogo(){
	blackBg.style.display	= "none";
	msgBox.style.display	= "none";
}
function ClearForm(){
	if (document.form_fale.Mensagem.value.length > 0) {
		txt_field.innerHTML = 0;
	}
	document.form_fale.reset()
}

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function validaContato() {
	var msgErro = "";
	if (document.form_Contato.nome.value == ""){ msgErro = msgErro + "   *  ' Nome'  está vazio.\n"; }
	if (document.form_Contato.email.value == ""){ msgErro = msgErro + "   *  ' E-mail'  está vazio.\n"; }
	else {
	if (! validarEmail(document.form_Contato.email.value)) {
		msgErro = msgErro + "   *  ' E-mail ' não é válido\n";
	}
	}
	if (document.form_Contato.assunto.value == ""){ msgErro = msgErro + "   *  ' Assunto '  está vazio.\n"; }
	if (document.form_Contato.mensagem.value == ""){ msgErro = msgErro + "   *  ' Mensagem '  está vazio.\n"; }

	if (msgErro != "") {
		alert("Os seguintes erro foram encontrados:\n\n" + msgErro);
		return false;
	}
	else{
	document.form_Contato.submit();
	}
}

//----------------------------------------------------------------------------------------------------------------------//

function ucwords( str ) {
	return str.toLowerCase().replace(/\w+/g, function(s){
		return s.charAt(0).toUpperCase() + s.substr(1);
	});
}					

function iniciaBusca(){

	var termo = document.frmBiblia.termo_biblico.value.toLowerCase();
	var livros = new Array(
								"Gn"
								,"Ex"
								,"Lv"
								,"Nm"
								,"Dt"
								,"Js"
								,"Jz"
								,"Rt"
								,"1Sm"
								,"2Sm"
								,"1Rs"
								,"2Rs"
								,"1Cr"
								,"2Cr"
								,"Ed"
								,"Ne"
								,"Et"
								,"Jó"
								,"Sl"
								,"Pv"
								,"Ec"
								,"Ct"
								,"Is"
								,"Jr"
								,"Lm"
								,"Ez"
								,"Dn"
								,"Os"
								,"Jl"
								,"Am"
								,"Ob"
								,"Jn"
								,"Mq"
								,"Na"
								,"Hc"
								,"Sf"
								,"Ag"
								,"Zc"
								,"Ml"
								,"Mt"
								,"Mc"
								,"Lc"
								,"Jo"
								,"At"
								,"Rm"
								,"1Co"
								,"2Co"
								,"Gl"
								,"Ef"
								,"Fp"
								,"Cl"
								,"1Ts"
								,"2Ts"
								,"1Tm"
								,"2Tm"
								,"Tt"
								,"Fm"
								,"Hb"
								,"Tg"
								,"1Pe"
								,"2Pe"
								,"1Jo"
								,"2Jo"
								,"3Jo"
								,"Jd"
								,"Ap"
							);

	var limite = livros.length;
	var char1 = "";
	var char2 = "";

	if (termo.indexOf(" ") == 2)
		char1 = termo.substr(0,2);
	else if (termo.indexOf(" ") == 3)
		char1 = termo.substr(0,3);

	for(var i = 0 ; i <= limite ; i++){

		if (livros[i] == ucwords(char1)){
			document.frmBiblia.tipo_busca.value = "R"; //Referencia
		} else {
			document.frmBiblia.tipo_busca.value = "T"; //Termo
		}
	
	}
}


//----------------------------------------------------------------------------------------------------------------------//


function manipula_radio_vista(evento,obj,campo,valor){

	if(evento == 'hover'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -48px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -12px  ";
	}

	if(evento == 'down'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -60px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -24px  ";
	}

	if(evento == 'up'){
		var limite_l = document.getElementById("lmt_eqt").value;
		var campo_l = "c_eqt_";
		var obj_l = "bt_radio_";
		limpar_radio_vista(campo_l,limite_l,obj_l);
		document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -48px  ";
		document.getElementById("valor_eqt").value = valor;
		document.getElementById(campo).value = '1';
	}
	
	if(evento == 'out'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% -36px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button.gif) no-repeat 0% 0%  ";
	}
	
	
}


function limpar_radio_vista(campo,limite,obj){
	var i = 0;
	for(i=1;i<=limite;i++){
		document.getElementById(campo+i).value = "";
		document.getElementById(obj+i).style.background = "url(imagens/radio_button.gif) no-repeat 0% 0%  ";
	}
}


//----------------------------------------------------------------------------------------------------------------------//


function manipula_radio_opera(evento,obj,campo,valor){

	if(evento == 'hover'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -28px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -14px  ";
	}

	if(evento == 'down'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -28px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -28px  ";
	}

	if(evento == 'up'){
		var limite_l = document.getElementById("lmt_eqt").value;
		var campo_l = "c_eqt_";
		var obj_l = "bt_radio_";
		limpar_radio_opera(campo_l,limite_l,obj_l);
		document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -42px  ";
		document.getElementById("valor_eqt").value = valor;
		document.getElementById(campo).value = '1';
	}
	
	if(evento == 'out'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% -42px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% 0%  ";
	}
	
	
}


function limpar_radio_opera(campo,limite,obj){
	var i = 0;
	for(i=1;i<=limite;i++){
		document.getElementById(campo+i).value = "";
		document.getElementById(obj+i).style.background = "url(imagens/radio_button_opera.gif) no-repeat 0% 0%  ";
	}
}


//----------------------------------------------------------------------------------------------------------------------//


function manipula_check(evento,obj,campo,valor){
	//alert(document.getElementById(obj).style.background)
	if(evento == 'hover'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -28px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -14px  ";
	}

	if(evento == 'down'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -28px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -28px  ";
	}

	if(evento == 'up'){
		if(document.getElementById(campo).value == 1){
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -14px  ";
			document.getElementById(campo).value = '0';
		} else {
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -42px  ";
			document.getElementById(campo).value = '1';
		}
	}
	
	if(evento == 'out'){
		if(document.getElementById(campo).value == 1)
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% -42px  ";
		else 
			document.getElementById(obj).style.background = "url(imagens/check_box.gif) no-repeat 0% 0%  ";
	}
	
	
}


function limpar_echeck(){
	var limite = document.getElementById("lmt_eqt").value;

	var i = 0;
	for(i=1;i<=limite;i++){
		document.getElementById("c_eqt_"+i).value = "";
		document.getElementById("bt_radio_"+i).style.background = "url(imagens/radio_button.gif) no-repeat 0% 0%  ";
		//document.getElementById("bt_radio_"+i).src="imagens/img_radio_off.gif";
		
	}
}