// Circulo Militar

// Abre links em outra janela ( Padrão da W3C )
function AbrirJanela(endereco){
	window.open(endereco);
}

// Cadastra o Email pelo site
function insereEmail(){
	var rtn = true;
	var obj;
	var obj2;
	obj = $("email");
	obj2 = $("nome");
	
	if(obj2.value == "" && obj.value == ""){
		alert('Informe o nome e email!');
		obj2.focus();
		rtn = false;
	}else if (obj2.value == "" && obj.value != ""){
		alert('Informe o nome!');
		obj2.focus();
		rtn = false;
	}else {
		if (obj.value == "") {
			alert('Informe o email!');
			obj.focus();
			rtn = false;
		} else {
			if (!isEmail(obj.value)) {
				alert('Email inválido!');
				obj.focus();
				rtn = false;
			}
		}
	}
	
	if (rtn) {
		var op = "operacao=insereEmail";
		op += "&nome="+ $("nome").value;
		op += "&email="+ $("email").value;
		fnAjax("GET", "divEmail", aplUrl+"inc/ajax.asp", op, "posEmail();", "");
		
	}
}

//Msg Email
function posEmail() {
	alert(document.getElementById("retorno").value);
	document.getElementById("nome").value = "";
	document.getElementById("email").value = "";
}

// Resultado da Enquete
function fnEnqueteResultado() {
	//var op = "operacao=getResultado";
	//fnAjax("GET", "id_enquete", aplUrl + "enquete/ajax.asp", op, "", "");
	
	new Ajax.Updater("id_enquete", aplUrl + "enquete/ajax.asp", {
		parameters: "operacao=getResultado"
	});
	resizeEquals();
	$("botao_resultado").style.display = 'none';
}

//resize Equalcolumn
function resizeEquals(){
	if (typeof ddequalcolumns.timer!="undefined") clearTimeout(ddequalcolumns.timer); ddequalcolumns.timer=setTimeout("ddequalcolumns.resetHeights()", 200);
}


//Agenda Home
function AgendaHome(dia){
	var op = "operacao=AgendaHome";
	op += "&"+dia+"=S";
	fnAjax("GET", "divAgenda", aplUrl+"inc/ajax.asp", op, "", "");
	}
	
//Agenda Home
function TrocaClasse(Dia, dia1, dia2, dia3, dia4, dia5, dia6){
		document.getElementById(Dia).className = 'botao_on';
		document.getElementById(dia1).className = 'botao_off';
		document.getElementById(dia2).className = 'botao_off';
		document.getElementById(dia3).className = 'botao_off';
		document.getElementById(dia4).className = 'botao_off';
		document.getElementById(dia5).className = 'botao_off';
		document.getElementById(dia6).className = 'botao_off';
	}
	
// Muda Imagem Principal da galeria
function mudarImagem(caminho, fotoAtual) {	
	document.getElementById('fotoAtual').value = fotoAtual
	 var parametros = "operacao=ImgPrincipal&caminho="+caminho;
	 fnAjax("GET", "divFoto", aplUrl + "inc/ajax.asp", parametros, "", "");
}

// Muda Legenda Principal da galeria
function mudarLegenda(novalegenda, legenda){
	var leggaleria = document.getElementById(legenda);
	leggaleria.innerHTML = novalegenda;
	return false; 
}

function NavegacaoImg(tipo){
	
	var fotoAtual = document.getElementById('fotoAtual').value;
	var fotoTotal = document.getElementById('fotoTotal').value;
	
	if (tipo == 'a'){
		if(fotoAtual > 1){
			fotoAtual = parseInt(fotoAtual) - 1;
			mudarImagem(document.getElementById('img_nova' + fotoAtual).value, fotoAtual);
		}
	}else {
		if(fotoAtual < fotoTotal){
			fotoAtual = parseInt(fotoAtual) + 1;
			mudarImagem(document.getElementById('img_nova' + fotoAtual).value, fotoAtual);
		}
	}
}

// Muda Imagem Principal da galeria
function loadPhoto(foto, legenda) {	
	 var parametros = "operacao=loadPhoto&foto="+foto;
	 parametros += "&legenda="+legenda;
	 fnAjax("GET", "divFotoM", aplUrl + "inc/ajax.asp", parametros, "", "");
}

//Valida biblia on-line
function fnValBiblia() {
	if (document.getElementById("biblia-texto").value.length < 3) {
		alert("A palavra-chave deve conter no mínimo 3 caracteres");
		document.getElementById("biblia-texto").focus();
		return false;
	}
	return true;
}

function getCap() {
	var pars_ = "operacao=getCap&CodLivro="+$("CodLivro").value;
	fnAjax('post', 'id_cap', aplUrl + 'inc/ajax.asp', pars_, "reloadSpry();getVer();");
}

function reloadSpry() {
	capitulo_.reset();
	capitulo_.destroy();
	capitulo_ = new Spry.Widget.ValidationSelect("capitulo_", {validateOn:["blur"]});
}

function getVer() {
	var pars_ = "operacao=getVer&CodLivro="+$("CodLivro").value+"&CodCapitulo="+$("CodCapitulo").value;
	fnAjax('post', 'id_ver', aplUrl + 'inc/ajax.asp', pars_, "");
}

function fnBusca(form) {
	if (Spry.Widget.Form.validate(form) == true){
		$("cmdBuscar").disabled = true;
		form.action = "passagem.asp";
		form.submit();
	} else {
		alert("Atenção. Há campos que não foram preenchidos corretamente!");	
	}
}

function fnPedido(form) {
	if (Spry.Widget.Form.validate(form) == true){
		$("cmdPedido").disabled = true;
		$("operacao").value="sav";
		form.submit();
	} else {
		alert("Atenção. Há campos que não foram preenchidos corretamente!");	
	}
}

function fnContato(form) {
	if (Spry.Widget.Form.validate(form) == true){
		$("cmdContato").disabled = true;
		$("operacao").value="sav";
		form.submit();
	} else {
		alert("Atenção. Há campos que não foram preenchidos corretamente!");	
	}
}

function fnCadastro(form) {
	if (Spry.Widget.Form.validate(form) == true){
		$("cmdCadastro").disabled = true;
		$("operacao").value="sav";
		form.submit();
	} else {
		alert("Atenção. Há campos que não foram preenchidos corretamente!");	
	}
}

//Img Principal de Imoveis
function ImgP(codigo){
	var op = "operacao=ImgP";
	op += "&CodFoto="+codigo;
	//alert(op)
	fnAjax("GET", "divFoto", aplUrl + "inc/ajax.asp", op, "");
}

//Pega a foto do Anterior e Proximo de Imoveis
function getFotos(tipo){
	
	var fotoAtual = document.getElementById('fotoAtual').value;
	var fotoTotal = document.getElementById('fotoTotal').value;
	
	if (tipo == 'a'){
		if(fotoAtual > 1){
			fotoAtual = parseInt(fotoAtual) - 1;
			ImgP(arrFotos[fotoAtual-1]);
		}
	}else {
		if(fotoAtual < fotoTotal){
			fotoAtual = parseInt(fotoAtual) + 1;
			ImgP(arrFotos[fotoAtual-1]);
		}
	}
	document.getElementById('fotoAtual').value = fotoAtual;
}
