
// Constantes FireFox e Opera
var BACKSPACE = 8, DEL = 46, DIREITA = 39, ESQUERDA = 37, TAB = 9, ENTER = 13;
var HOME = 36, END = 35, VIRGULA = 44, NMIN = 48, NMAX = 57;

// Captura eventos
var IE = document.all ? true : false
if (!IE) document.captureEvents (Event.MOUSEMOVE)

// exibe loading se disponível
var t_loading = false;
if (navigator.appVersion.indexOf('MSIE') != -1) {
	var temp = navigator.appVersion.split('MSIE');
	var versao = parseFloat(temp[1]);
	if (versao <= 6) t_loading = true;
}

// Retorna ascii tecla pressionada
function getKey(evt) { return evt ? (evt.keyCode ? evt.keyCode : (evt.which ? evt.which : evt.charCode)) : null; }

// Retorna se valor é vazio / nulo
function IsEmpty(str) { return ((str == null) || (str.length == 0) || (str == '')); }

// Retorna somente numeros
function isDigit(c) { return ((c >= '0') && (c <= '9')); }

// Obtem objetos pelo ID
function gE(tI) {
	if (document.getElementById) { return document.getElementById(tI); }
	else if (document.all) { return document.all[tI]; } else return false;
}

// Formata / Codifica dados de formulários em UTF-8 para Ajax
function gForm(obj) { return encodeURI(gE(obj).value); }

// Requer confirmação para operação de exclusão
function OpConfirme(msg) { if (confirm(msg)) { return true; } else { return false; } }

// Retira espaços em brancos no início e no fim de uma string
function Trim(str) {
	var l, fim, i, j;
	for (l = 0; l < str.length; l++) { if (str.charAt(l) != ' ') { break; } }
	if (l == str.length) { return ''; }
	fim = str.length - 1;
	for (i = 0; i < str.length; i++) { if (str.charAt(i) != ' ') { break; } }
	for (j = fim; j > 0; j--) { if (str.charAt(j) != ' ') { break; } }
	return str.substring(i, j + 1);
}

function ControlKey(key) {
	if (key == HOME || key == END) { return true; }
	else if (key == BACKSPACE || key == DEL || key == TAB || key == ENTER || key == ESQUERDA || key == DIREITA) { return true; }
	else { return false; }
}

// retorna somente números
function SoNum(evtKeyPress) {
	var key = getKey(evtKeyPress);
	if (ControlKey(key)) return true;
	if (key >= NMIN && key <= NMAX) { return true; }
	return false;
}

// limpas caracteres de formatação
function LimparFormatacao(Str) {
	var s = '', espaco = 'X X';
	Str = Trim(Str);
	for (var i = 0; i < Str.length ; i++) {
		if (Str.charAt(i) != '/' && Str.charAt(i) != '-' && Str.charAt(i) != '.'  && Str.charAt(i) != ',' &&
			Str.charAt(i) != ';' && Str.charAt(i) != '|' && Str.charAt(i) != espaco.charAt(1) && Str.charAt(i) != '\\' &&
			Str.charAt(i) != ':' && Str.charAt(i) != '(' && Str.charAt(i) != ')') { s = s + Str.charAt(i); }
	}
	return s;
}

// função para tabulação automática
function autoTab(origem, destino) {
	if (origem.getAttribute && origem.value.length == origem.getAttribute('maxlength')) {
		gE(destino).focus();
		return true;
	}
}

// Abre janela popup personalizada
function AbrirPop(pagina, nome, coord_x, coord_y, barras, fixo, full) {
	var esq = (screen.width - coord_x) / 2;
	var top = ((screen.height - coord_y) / 2) - 40;
	var win_props = 'resizable=' + fixo + ', status=0, scrollbars=' + barras + ', directories=0, toolbar=0, width=' + coord_x + ', height=' + coord_y + ', top=' + top + ', left=' + esq + ', fullscreen=' + full
	var jan = window.open(pagina, nome, win_props);
	if (parseInt(navigator.appVersion) >= 4) { jan.window.focus(); }
}

// Abre janela popup para exibir foto
function Abrir_Foto(pagina) {
	var jan = window.open(pagina, 'Visualizar', 'resizable=yes, status=0, scrollbars=no, directories=0, toolbar=0, width=200, height=160, top=10, left=10');
	if (parseInt(navigator.appVersion) >= 4) { jan.window.focus(); }
}

// Pré-seleciona item em drop-down
function Selecione(obj_select, valor) {
	if (valor != '') {
		for (var i = 0; i < obj_select.options.length; i++) {
			if (obj_select.options[i].value == valor) { obj_select.selectedIndex = i; break; }
		}
	}
}

// Pré-seleciona item em drop-down multiplas
function SelecioneMulti(obj_select, valor) {
	if (valor != '') {
		var vetor = valor.split(',');
		for (var i = 0; i < vetor.length; i++) {
			for (var j = 0; j < obj_select.options.length; j++) {
				if (obj_select.options[j].value == vetor[i]) { obj_select.options[j].selected = true; }
			}
		}
	}
}

// verifica se ao menos um checkbox foi preenchido
function ValChecks(obj) {
	var check = true;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked == true) check = false;
	}
	return check;
}

// Função para controlar paginação
function Pag_Control(pag) {
	if (!isNaN(pag)) {
		gE('pag').value = pag;
		gE('form_busca').submit();
	}
}

// bloqueia campos de seleção de arquivo
function BlockEdit(msg) { alert(msg); return false; }

////////////////////////////////////////////////////////////////////////////////////////////////////
// Funções de Formatação
////////////////////////////////////////////////////////////////////////////////////////////////////

// Função que formata data ##/##/#### (digitação)
function ajustaData(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 2 || input.value.length == 5) { input.value += '/' ; }
	}
	return true;
};

// Função que formata cpf ###.###.###-## (digitação)
function ajustaCPF(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 3 || input.value.length == 7) { input.value += '.'; }
		else if (input.value.length == 11) { input.value += '-'; }
	}
	return true;
}

// Função que formata cnpj ##.###.###/####-## (digitação)
function ajustaCNPJ(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 2 || input.value.length == 6) { input.value += '.'; }
		else if (input.value.length == 10) { input.value += '/'; }
		else if (input.value.length == 15) { input.value += '-'; }
	}
	return true;
}

// Função que formata cep ##.###-#### (digitação)
function ajustaCEP(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 2) { input.value += '.' ; }
		else if (input.value.length == 6) { input.value += '-' ; }
	}
	return true;
}

// Função que formata telefone (##) ####-#### (digitação)
function ajustaFone(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 0 || input.value.length == 1) { input.value = '(' + input.value; }
		else if (input.value.length == 3) { input.value += ') '; }
		else if (input.value.length == 4) { input.value += ' '; }
		else if (input.value.length == 9) { input.value += '-'; }
	}
	return true;	
}

// Função para formatar valores decimais (digitação : numéricos e com somente uma vírgula)
function ajustaDecimal(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == VIRGULA) if (input.value.indexOf(',') == -1) return true;
	return (key >= NMIN && key <= NMAX);
}

// Função para formatar valores monetários (digitação : pontos para milhares e virgula para centavos)
function ajustaMoeda(campo, tammax, evtKeyPress) {
	var key = getKey(evtKeyPress), vr = LimparFormatacao(campo.value);
	tam = vr.length;
	if (ControlKey(key)) return true;
	if (tam < tammax) { tam += 1; } else { return false; }
	if (key >= NMIN && key <= NMAX) {
		if (tam <= 2 ) { campo.value = vr; }
		if ((tam > 2) && (tam <= 5)) { campo.value = vr.substr(0, tam - 2) + ',' + vr.substr(tam - 2, tam); }
		if ((tam >= 6) && (tam <= 8)) { campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }
		if ((tam >= 9) && (tam <= 11)) { campo.value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
		if ((tam >= 12) && (tam <= 14)) { campo.value = vr.substr(0, tam - 11) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }
		if (tam >= 15) { campo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }
	} else { return false; }
}

// Função que formata período ##/#### (digitação)
function ajustaReferencia(input, evento) {
	var key = getKey(evento);
	if (ControlKey(key)) return true;
	if (key == ENTER) return false;
	if (key < NMIN || key > NMAX) { evento.returnValue = false; return false; }
	else {
		if (input.value.length == 2) { input.value += '/' ; }
	}
	return true;
}

// Formata valor monetário para exibição
function MoedaMascara(num) {
	if (isNaN(num)) num = '0';
	var sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	var cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents < 10) cents = '0' + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
	return (((sign) ? '' : '-') + num + ',' + cents);
}

// format valor para ponto decimal
function CMoeda(valor) { return valor.replace('.', '').replace(',', '.'); }

////////////////////////////////////////////////////////////////////////////////////////////////////
// Validação de Inputs
////////////////////////////////////////////////////////////////////////////////////////////////////

// Verifica formato de E-mail
function vEmail(email) {
	var BadChars = 'áàâãäêéèëíìïîóòôõöúùûüçÿý*´`$#!\'"¨&(){}?/\^~:;,= ';
	var GoodChars = '@.'; 
	var posarroba = email.indexOf ('@', 0);
	if (email.length < 6) { return true; }
	for (var i = 0; i < email.length; i++) { if (BadChars.indexOf(email.charAt(i)) != -1) { return true; } }
	for (var i = 0; i < GoodChars.length; i++) {
		if (email.indexOf(GoodChars.charAt(i)) == -1) return true;
		if (email.indexOf(GoodChars.charAt(i), 0) == 0) return true;
		if (email.lastIndexOf(GoodChars.charAt(i)) > email.length - 3) return true;
	}
	if (email.lastIndexOf('@') > email.lastIndexOf('.')) return true;
	if (email.indexOf ('@.', 0) != -1 || email.indexOf ('.@', 0) != -1) return true;
	if (email.indexOf ('@', posarroba + 1) != -1) return true;
	return false;
}

// Valida validade de Data
function vData(data) {
	if (data == '') { alert('Data não digitada!'); return true; }
	else if (data.length < 8) { alert('Formato de campo "Data" inválido!'); return true; }
	var v_data = data.split('/');
	var tmpDia = Math.abs(v_data[0]), tmpMes = Math.abs(v_data[1]), tmpAno = Math.abs(v_data[2]);
	var bissexto, d = new Date();
	var nDia = d.getDate(), nMes = (d.getMonth()+1), nAno = d.getFullYear();
	if (isNaN(tmpDia) || isNaN(tmpMes) || isNaN(tmpAno)) { alert('Valores não permitidos para campo "Data".'); return true; }
	if ((tmpDia <= 0) || (tmpDia > 31) || (tmpMes <= 0) || (tmpMes > 12)) { alert('Valores para "Data" inválidos!'); return true; }
	else {
		if ((tmpAno % 4 == 0) || (tmpAno % 100 == 0) || (tmpAno % 400 == 0)) { bissexto = 1; } // Verificando se o ano é bissexto
		if ((tmpMes == 2) && (bissexto == 1) && (tmpDia > 29)) { alert('Dia inválido para Mês selecionado!\n(O ano selecionado não corresponde a ano Bissexto)'); return true; } // Valindando o mês de fevereiro
		if ((tmpMes == 2) && (bissexto != 1) && (tmpDia > 28)) { alert('Dia inválido para Mês selecionado!'); return true; }
		/* Validando o mês */
		if ((tmpDia == 31) && ((tmpMes == 4) || (tmpMes == 6) || (tmpMes == 9) || (tmpMes == 11))) { alert('Relação Dia/Mês inválida!\n(O Mês selecionado não possui 31 dias)'); return true; }
		return false;
	}
}

// Valida formato de Referencia
function vReferencia(ref) {
	var d = new Date();
	var mes = Math.abs(ref.substring(0, 2)), ano = Math.abs(ref.substring(3, 7));
	var nAno = d.getFullYear();
	if (isNaN(mes) || isNaN(ano)) { alert('Valores não permitidos para campo "MM/AAAA".'); return true; }
	if ((mes < 1) || (mes > 12) || (ano > (nAno + 1))) { alert('Valores não permitidos para campo "MM/AAAA".'); return true; }
	return false;
}

// Verifica período de data (data final menor que data inicio)
function vDataPeriodo(di, df) {
	var dia_i = Math.abs(di.substring(0,2)), mes_i = Math.abs(di.substring(3,5)), ano_i = Math.abs(di.substring(6,10));
	var dia_f = Math.abs(df.substring(0,2)), mes_f = Math.abs(df.substring(3,5)), ano_f = Math.abs(df.substring(6,10));
	if ((ano_f < ano_i) || ((dia_f < dia_i) && (mes_f == mes_i) && (ano_f == ano_i)) || ((mes_f < mes_i) && (ano_f == ano_i))) {
		alert('Data final menor que a data inicial!');
		return true;
	}
}

// valida período (data inicial / data final)
function vPeriodo(d_ini, d_fim) {
	if (vData(d_ini.value)) { d_ini.focus(); return true; }
	else if (vData(d_fim.value)) { d_fim.focus(); return true; }
	else if (vDataPeriodo(d_ini.value, d_fim.value)) { d_fim.focus(); return true; }
	else { return false; }
}

// Verifica formato de HH:MM
function vHora(horario) {
	var tmpHora = Math.abs(horario.substring(0,2)), tmpMinuto = Math.abs(horario.substring(3,5));
	if ((tmpHora < 0) || (tmpHora > 23) || (tmpMinuto < 0) || (tmpMinuto > 59)) return true;
	return false;
}

// Função que testa farmato de n. de telefone
function vFone(str) {
	if ((str.length == 0) || (str.length != 10)) { return false; }
	if (isNaN(str)) { return false; }
	return true;
}

// Função que testa farmato de CEP
function vCEP(str) {
	if ((str.length == 0) || (str.length != 8)) { return false; }
	if (isNaN(str)) { return false; }
	return true;
}

// Função que testa validade de CPF
function vCPF(str) {
	var NR_CPF = str.substr(0, 9), NR_DV = str.substr(9, 2), d1 = 0, d2 = 0;
	if ((str.length > 11) || IsEmpty(NR_CPF)) return false;
	for (var i = 0; i < 9; i++) d1 += NR_CPF.charAt(i) * (10 - i);
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (NR_DV.charAt(0) != d1) return false;
	d1 *= 2;
	for (var i = 0; i < 9; i++) d1 += NR_CPF.charAt(i) * (11 - i);
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (NR_DV.charAt(1) != d1) return false;
	return true;
}

// Função que testa validade de CNPJ
function vCNPJ(str) {
	var vale, int_z, int_i, int_j, soma, fim
   if (vale = (str.length == 14))
      for (int_z = 0; int_z < 2; int_z++) {
         soma = 0;
         for (int_i = (5 + int_z), int_j = 0; int_j < (12 + int_z); int_i--, int_j++) {
            soma += (str.substr(int_j, 1) * int_i);
            if(int_i == 2) int_i = 10;
         }
         fim = (((soma % 11) < 2) ? 0 : (((soma % 11) == 10) ? 1 : 11 - (soma % 11)));
         if (!(vale = (str.substr((12 + int_z), 1) == fim)))
            break;
      }
   return vale;
}

// Formata, valida e exibe informações relativas se necessário (usa evento onblur : numérico)
// obj = campo; tam = tamanho máx do campo; tipo = cpf | cnpj | data | cep | moeda
function vEditaNum(obj, tam, tipo) {
	var i, strCampo = obj.value, j = 0, nTamanho = obj.value.length, szCampo = '';
	for (i = nTamanho - 1; i >= 0; i--) {
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}
	if (j == 0) { obj.value = ''; return; }
	switch (tipo) {
		case 'data':
			if (vData(strCampo)) { obj.focus(); }
			else { obj.value = szCampo.substr(0, 2) + '/' + szCampo.substr(2, 2) + '/' + szCampo.substr(4, 4); }
			break;
		case 'periodo':
			if (!vPeriodo(strCampo)) { alert('Formato de período inválido [MM/AAAA]!'); obj.focus(); }
			else { obj.value = szCampo.substr(0, 2) + '/' + szCampo.substr(2, 4); }
			break;
		case 'cpf':
			if (!vCPF(szCampo)) { alert('Número de CPF inválido!'); obj.focus(); }
			else { obj.value = szCampo.substr(0, 3) + '.' + szCampo.substr(3, 3) + '.' + szCampo.substr(6, 3) + '-' + szCampo.substr(9, 2); }
			break;
		case 'cnpj':
			if (!vCNPJ(szCampo)) { alert('Número de CNPJ / CGC inválido!'); obj.focus(); }
			else { obj.value = szCampo.substr(0, 2) + '.' + szCampo.substr(2, 3) + '.' + szCampo.substr(5, 3) + '/' + szCampo.substr(8, 4) + '-' + szCampo.substr(12, 2); }
			break;
		case 'cep':
			if (!vCEP(szCampo)) { alert('O CEP digitado possui formato inválido!'); obj.focus(); }
			else { obj.value = szCampo.substr(0, 2) + '.' + szCampo.substr(2, 3) + '-' + szCampo.substr(5, 3); }
			break;
		case 'fone':
			if (!vFone(szCampo)) { alert('Número de telefone digitado possui formato inválido!'); obj.focus(); }
			else { obj.value = '(' + szCampo.substr(0, 2) + ') ' + szCampo.substr(2, 4) + '-' + szCampo.substr(6, 4); }
			break;
		case 'moeda':
			if (szCampo.length > 0) { MoedaMascara(szCampo); }
			break;
	}
}

// Verifica preenchimento de dados de login
function ValLogin(d) {
	if (d.user_name.value.length < 3) { alert('Por favor, digite seu nome de usuário\ne senha antes de continuar!'); d.user_name.focus(); return false; }
	else if (d.user_pass.value.length < 3) { alert('Por favor, digite sua senha para efetuar o login!'); d.user_pass.focus(); return false }
	else { d.sub_login.disabled = true; return true; }
}

// Verifica preenchimento de email para lembrar senha
function ValLembrar(d) {
	if (vEmail(d.Email.value)) { alert('Endereço de E-mail inválido: ' + gE('Email').value); d.Email.focus(); return false; }
	else { d.sub_login.disabled = true; return true; }
}

// Função para exibir imagem node ([+], [-] e [.])
function ViewNode(div, img) {
	var obj = gE(div);
	if (obj.style.display == 'block') { obj.style.display = 'none'; setTimeout('tImg("' + img + '",1)', 200); return false; }
	else if (obj.style.display == 'none') { obj.style.display = 'block'; setTimeout('tImg("' + img + '",2)', 200); return true; }
	else { setTimeout('tImg("' + img + '", 0)', 200); return true; }
}

// Função para exibir / ocultar seção de uma página
function ViewSecao(div) {
	var obj = gE(div);
	if (obj.style.display == 'none') { obj.style.display = 'block'; }
	else { obj.style.display = 'none'; }
	return false;
}

//Função para trocar imagem de node
function tImg(img, opc) {
	if (opc == 1) { gE(img).src = '../images/node_mais.gif'; gE(img).alt = '+'; }
	else if (opc == 2) { gE(img).src = '../images/node_menos.gif'; gE(img).alt = '-'; }
	else { gE(img).src = '../images/node_item.gif'; gE(img).alt = '.'; }
}

// Função para exiber / ocultar opção de alteração de senha
function View_Senha() {
	var varAlt = gE('alt_senha');
	var varLnk = gE('no_alt');
	if (varAlt.style.display == 'none') {
		varAlt.style.display = 'inline';
		varLnk.style.display = 'none';
	} else {
		varAlt.style.display = 'none';
		varLnk.style.display = 'inline';
		gE('Senha').value = '';
		gE('ReSenha').value = '';
	}
}

// exibe/oculta opções de busca (classificados)
function Opc_Busca(obj) {
	var vatObj = gE(obj);
	if (vatObj.style.display == 'none') { vatObj.style.display = 'block'; }
	else { vatObj.style.display = 'none'; }
}

// Cria objeto para AJAX
function GetXmlHttpObject() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest(); // Cria objeto XMLHttpRequest em não ie
	} else if (window.ActiveXObject) {
		try { // Cria XMLHttpRequest via MS ActiveX
			xmlreq = new ActiveXObject('Msxml2.XMLHTTP'); // versões atuais do ie
		} catch (e1) {
			try {
				xmlreq = new ActiveXObject('Microsoft.XMLHTTP'); // suportada por velhas versões do ie
			} catch (e2) { /* não pode criar um XMLHttpRequest com ActiveX */ }
		}
	}
	return xmlreq;
}

// Executa operação Ajax com loading
function ExecAjax(idLoading, idExibe, Url, Arg, idBtn) {
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) { alert('Esse browser não tem recursos para uso do Ajax.'); return; }
	if (idBtn) { title = gE(idBtn).value; gE(idBtn).disabled = true; gE(idBtn).value = 'Aguarde...'; }
	gE(idLoading).style.display = 'block';
	xmlHttp.open('post', Url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 1) {
			if (t_loading) gE(idExibe).style.display = 'none';
		} else if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
			if (xmlHttp.status == 200) {
				gE(idLoading).style.display = 'none';
				gE(idExibe).innerHTML = unescape(xmlHttp.responseText);
				if (t_loading) gE(idExibe).style.display = 'block';
				if (idBtn) { gE(idBtn).disabled = false; gE(idBtn).value = title; }
				ExtraiScript(unescape(xmlHttp.responseText));
			} else { alert('Ocorreu um erro:\nNúmero do erro: ' + xmlHttp.status + '.\nDescrição: ' + xmlHttp.statusText + '.\nLocal: ' + idExibe); }
		} else { /* Executa outra função baseada no status */ }
	}
	xmlHttp.send(Arg);
}

// Executa operação Ajax sem loading
function ExecAjaxSp(idExibe, Url, Arg, idBtn) {
	var xmlHttp = GetXmlHttpObject();
	var title = '';
	if (xmlHttp == null) { alert('Esse browser não tem recursos para uso do Ajax.'); return; }
	xmlHttp.open('post', Url, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 1) {
			if (gE(idBtn)) { title = gE(idBtn).value; gE(idBtn).disabled = true; gE(idBtn).value = 'Aguarde'; }
		} else if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
			if (xmlHttp.status == 200) {
				gE(idExibe).innerHTML = unescape(xmlHttp.responseText);
				if (gE(idBtn)) { gE(idBtn).disabled = false; gE(idBtn).value = title; }
				ExtraiScript(unescape(xmlHttp.responseText));
			} else { alert('Ocorreu um erro:\nNúmero do erro: ' + xmlHttp.status + '.\nDescrição: ' + xmlHttp.statusText + '.\nLocal: ' + idExibe); }
		} else { /* Executa outra função baseada no status */ }
	}
	xmlHttp.send(Arg);
}

// Script para ler funções Javascript dentro do Ajax // Desenvolvido por Skywalker.to, Micox e Pita.
function ExtraiScript(texto){
	var ini = 0;
	while (ini != -1) {
		ini = texto.indexOf('<script', ini);
		if (ini >= 0) {
			ini = texto.indexOf('>', ini) + 1;
			var fim = texto.indexOf('</script>', ini);
			codigo = texto.substring(ini, fim);
			eval(codigo);
		}
	}
}

// Funções para uso do Newsletter (PORTAL)
function SubNewsletter(opc) {
	var param = 'Opc=' + opc;
	if (opc == 1) {
		if (gE('Nome').value == '') { alert('Por favor, entre com o nome para o cadastro no Newsletter.'); gE('Nome').focus(); return false; }
		if (vEmail(gE('Email').value)) { alert('Endereço de E-mail inválido: ' + gE('Email').value); gE('Email').focus(); return false; }
		param += '&Nome=' + gForm('Nome') + '&Email=' + gForm('Email');
	}
	ExecAjax('loading_news', 'form_news', 'ajax/newsletter.asp', param, null);
}

// Funções para enviar newsletter (PORTAL)
function SendNews(id) {
	var param = 'idNews=' + id;
	ExecAjaxSp('newsletter_enviar', 'ajax/newsletter_enviar.asp', param, null);
}

// Funções para mural de mensagens (PORTAL)
function Mural(v_data, qtd) {
	var param = 'Data=' + v_data + '&Qtd=' + qtd;
	ExecAjaxSp('form_mural', 'ajax/mural.asp', param, null);
}

// enviar mensagem no mural (PORTAL)
function MuralSub(v_data, qtd) {
	var param = 'Data=' + v_data;
	if (gE('Nome').value == '') { alert('Por favor, entre com o nome.'); gE('Nome').focus(); return false; }
	else if (vEmail(gE('Email').value)) { alert('Endereço de E-mail inválido: ' + gE('Email').value); gE('Email').focus(); return false; }
	else if (gE('Mensagem').value == '') { alert('Por favor, entre com a Mensagem.'); gE('Mensagem').focus(); return false; }
	else {
		param += '&Nome=' + gForm('Nome') + '&Email=' + gForm('Email') + '&Site=' + gForm('Site');
		param += '&Cidade=' + gForm('Cidade') + '&Estado=' + gForm('Estado') + '&Mensagem=' + gForm('Mensagem');
		ExecAjaxSp('form_mural', 'ajax/mural_add.asp', param, 'btn_enviar');
		setTimeout('Mural("' + v_data + '",' + qtd + ')', 250);
		gE('form_mensagem').reset();
		gE('btn_enviar').disabled = false;
	}
}

// Funções para comentários (PORTAL)
function Comentarios(tipo, id, opc) {
	var param = 'Tipo=' + tipo + '&idReferencia=' + id + '&Opcao=' + opc;
	ExecAjaxSp('form_comentarios', 'ajax/comentario.asp', param, null);
}

// enviar comentarios para a secção determinada (PORTAL)
function ComentarioSub(tipo, id, opc) {
	var param = 'Tipo=' + tipo + '&idReferencia=' + id;
	var label;
	if (opc == 'msg' || opc == 'vid' || opc == 'not') { label = 'o comentário'; }
	else if (opc == 'com') { label = 'a mensagem'; }
	if (gE('Nome').value == '') { alert('Por favor, entre com o nome.'); gE('Nome').focus(); return false; }
	else if (vEmail(gE('Email').value)) { alert('Endereço de E-mail inválido: ' + gE('Email').value); gE('Email').focus(); return false; }
	else if (gE('Comentario').value == '') { alert('Por favor, entre com ' + label + '.'); gE('Comentario').focus(); return false; }
	else {
		param += '&Nome=' + gForm('Nome') + '&Email=' + gForm('Email') + '&Site=' + gForm('Site');
		param += '&Cidade=' + gForm('Cidade') + '&Estado=' + gForm('Estado') + '&Comentario=' + gForm('Comentario');
		ExecAjaxSp('form_comentarios', 'ajax/comentario_add.asp', param, 'btn_enviar');
		setTimeout('Comentarios(' + tipo + ',' + id + ',"' + opc + '")', 250);
	}
}

// carrega barra lateral (PORTAL)
function LoadAlbumBarra(tipo, gal, fot, usr) {
	var param = 'Tipo=' + tipo;
	if (!(gal == null || typeof(gal) == 'undefined' || gal == 0)) param += '&idAlbum=' + gal;
	if (!(usr == null || typeof(usr) == 'undefined' || usr == 0)) param += '&idUsuario=' + usr;
	ExecAjax('loading', 'conteudo_lateral', 'ajax/albuns_lateral.asp', param, null);
	setTimeout('LoadAlbumCentro(' + tipo + ',' + gal + ',' + fot + ',' + usr + ')', 250);
}

// Função para carregar álbuns (PORTAL)
function LoadAlbumCentro(tipo, gal, fot, usr) {
	var param = 'Tipo=' + tipo;
	if (!(gal == null || typeof(gal) == 'undefined' || gal == 0)) param += '&idAlbum=' + gal;
	if (!(fot == null || typeof(fot) == 'undefined' || fot == 0)) param += '&idFoto=' + fot;
	if (!(usr == null || typeof(usr) == 'undefined' || usr == 0)) param += '&idUsuario=' + usr;
	ExecAjax('loading','conteudo_centro','ajax/albuns_centro.asp', param, null);
}

// Função para carregar álbuns (usada em cardápios e álbuns de fotos do site)
function LoadFotos(tipo, id) {
	var param = 'Tipo=' + tipo;
	if (!(id == null || typeof(id) == 'undefined' || id == 0)) param += '&idReferencia=' + id;
	ExecAjax('loading_fotos', 'load_fotos', '../ajax/load_fotos.asp', param, null);
}

// Função para carregar albuns do portal (PORTAL)
function LoadAlbuns(tipo, ref, id) {
	var args = 'Tipo=' + tipo + '&idReferencia=' + ref;
	if (!(id == null || typeof(id) == 'undefined' || id == 0)) args += '&idAlbum=' + id;
	ExecAjaxSp('clientes_albuns', 'ajax/clientes_albuns.asp', args, null);
}

// Função para carregar fotos do albuns do portal (PORTAL)
function LoadAlbumFoto(album, foto) {
	var args = 'idAlbum=' + album + '&idFoto=' + foto;
	ExecAjax('fot_loading', 'fot_container', 'ajax/clientes_albuns_fotos.asp', args, null);
}

// Função para carregar albuns do portal usando LightBox (PORTAL)
function LoadAlbunsLBox(tipo, ref) {
	var args = 'Tipo=' + tipo + '&idReferencia=' + ref;
	ExecAjaxSp('clientes_albuns','ajax/clientes_albuns_lbox.asp', args, null);
}

// funções para edição de dados de fotos
function FotoAcao(tipo, gal, fot, act) {
	var param = 'Tipo=' + tipo + '&idReferencia=' + gal + '&idFoto=' + fot + '&Act=' + act;
	if (act == 'canc') {
		gE('foto_editar').innerHTML = '';
		gE('foto_editar').style.display = 'none';
		gE('div_upload').style.display = 'block';
	} else if (act == 'edit') {
		gE('foto_editar').style.display = 'block';
		gE('div_upload').style.display = 'none';
		ExecAjaxSp('foto_editar', '../ajax/foto_ope.asp', param, null);
	} else if (act == 'save') {
		param += '&Titulo=' + gForm('TituloEdt') + '&Descricao=' + gForm('DescricaoEdt');
		ExecAjaxSp('foto_editar', '../ajax/foto_ope.asp', param, null);
		gE('foto_editar').style.display = 'none';
		gE('div_upload').style.display = 'block';
	}
}

// Função para exibir todo o conteúdo do site (arquivo)
function ViewConteudo(tipo) { document.location = 'Arquivo.asp?Tipo=' + tipo; }

// Função para exibição em abas
function TabsSistemas(id, aba) {
	var abas = new Array('aba_ser','aba_cat','aba_usr');
	for (var i = 0; i < abas.length; i++) {
		if (abas[i] == aba) { gE(abas[i]).className = 'sel_aba'; } else { gE(abas[i]).className = 'unsel_aba'; }
	}
	var args = 'idSistema=' + id + '&Aba=' + aba;
	ExecAjax('loading', 'div_abas', '../ajax/sistemas_abas.asp', args, null);
}

// Adiciona / Remove serviço ao Sistemas
function OpeServicos(id_cliente, id_servico, opc) {
	var args = 'idSistema=' + id_cliente + '&idServico=' + id_servico + '&Opc=' + opc;
	var question = ((opc == 'add') ? 'Confirmar Adição de Serviço?' : 'Confirmar Exclusão de Serviço?');
	if (confirm(question)) {
		ExecAjaxSp('processo', '../ajax/sistemas_servicos_ope.asp', args, null);
		setTimeout('TabsSistemas(' + id_cliente + ',"aba_ser")', 250);
	}
}

// Categorias de Comécios de Clientes (exibe nodes da estrutura de categorias)
function ShowCategoriasNode(valor) {
	if (ViewNode('rc' + valor, 'img_' + valor)) {
		var args = 'idCategoria=' + valor;
		ExecAjax('ld' + valor, 'rc' + valor, '../ajax/comercios_categorias.asp', args, null);
	}
}

// Departamentos de Comércios (exibe nodes da estrutura de departamentos)
function ShowDepartamentosNode(valor) {
	if (ViewNode('rc' + valor, 'img_' + valor)) {
		var args = 'idDepartamento=' + valor;
		ExecAjax('ld' + valor, 'rc' + valor, '../ajax/local_departamentos.asp', args, null);
	}
}

// Departamentos de Comércios (exibe nodes da estrutura de departamentos) - PORTAL
function ShowDepartamentosPortal(valor) {
	if (ViewNode('rc' + valor, 'img_' + valor)) {
		var args = 'idDepartamento=' + valor;
		ExecAjax('ld' + valor, 'rc' + valor, 'ajax/local_departamentos_ver.asp', args, null);
	}
}

// lista categorias de acordo com o segmento de negocio (PORTAL - SITE YURI)
function ProdutosDepartamentos(id, pag) {
	var args = 'idDepartamento=' + id;
	if (!(pag == null || typeof(pag) == 'undefined' || pag == 0)) args += '&Pagina=' + pag;
	ExecAjax('loading', 'Departamentos', '../ajax/local_departamentos_lista.asp', args, null);
}

// Função para carregar imagem do produto (PORTAL - SITE YURI)
function ProdutoLoadImg(id, ref) {
	var args = 'idFoto=' + id + '&idProduto=' + ref;
	ExecAjax('load_imagem', 'produto_imagem', 'ajax/local_produtos_foto.asp', args, null);
}

// Função para exibição em abas
function TabsItens(id, aba) {
	var abas = new Array('aba_fot','aba_vid');
	for (var i = 0; i < abas.length; i++) {
		if (abas[i] == aba) { gE(abas[i]).className = 'sel_aba'; } else { gE(abas[i]).className = 'unsel_aba'; }
	}
	var args = 'idItem=' + id + '&Aba=' + aba;
	ExecAjax('loading', 'div_abas', '../ajax/itens_abas.asp', args, null);
}

// Função para exibição em abas
function TabsComercios(id, aba) {
	var abas = new Array('aba_fot','aba_vid','aba_dep','aba_pro');
	for (var i = 0; i < abas.length; i++) {
		if (abas[i] == aba) { gE(abas[i]).className = 'sel_aba'; } else { gE(abas[i]).className = 'unsel_aba'; }
	}
	var args = 'idComercio=' + id + '&Aba=' + aba;
	ExecAjax('loading', 'div_abas', '../ajax/comercios_abas.asp', args, null);
}

// Função para exibição em abas
function TabsHospedagens(id, aba) {
	var abas = new Array('aba_aco','aba_fot','aba_vid','aba_pac','aba_tar');
	for (var i = 0; i < abas.length; i++) {
		if (abas[i] == aba) { gE(abas[i]).className = 'sel_aba'; } else { gE(abas[i]).className = 'unsel_aba'; }
	}
	var args = 'idHospedagem=' + id + '&Aba=' + aba;
	ExecAjax('loading', 'div_abas', '../ajax/hospedagens_abas.asp', args, null);
}

// Função para exibição em abas
function TabsGastronomia(id, aba) {
	var abas = new Array('aba_fot','aba_vid','aba_car');
	for (var i = 0; i < abas.length; i++) {
		if (abas[i] == aba) { gE(abas[i]).className = 'sel_aba'; } else { gE(abas[i]).className = 'unsel_aba'; }
	}
	var args = 'idGastronomia=' + id + '&Aba=' + aba;
	ExecAjax('loading', 'div_abas', '../ajax/gastronomia_abas.asp', args, null);
}

// Função para exibir detalhes de vídeos (hospedagens, negócios, classificados etc.)
function ViewVideo(id, tipo, ref) {
	var obj = 'div_vid_' + id;
	var txt = 'txt_vid_' + id;
	var args = '';
	if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir vídeo';
	} else if (gE(obj).style.display == 'none') {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar vídeo';
		args = 'idVideo=' + id + '&Tipo=' + tipo + '&idReferencia=' + ref;
	}
	ExecAjaxSp(obj, '../ajax/clientes_videos_detalhes.asp', args, null);
}

// Função para exibir vídeos (hospedagens, negócios, classificados etc.) (PORTAL)
function LoadVideo(id, tipo, ref) {
	var args = 'idVideo=' + id + '&Tipo=' + tipo + '&idReferencia=' + ref;
	ExecAjax('vid_loading', 'vid_container', 'ajax/clientes_videos_ver.asp', args, null);
}

// lista categorias de acordo com o segmento de negocio
function NegociosCategorias (tipo, id) {
	var args = 'Tipo=' + tipo + '&idCategoria=' + id;
	ExecAjax('loading', 'Categorias', '../ajax/negocios_categorias.asp', args, null);
}

// Função para exibir itens do cardápio
function ViewCardapio(id, ref, view) {
	var obj = 'div_car_' + id;
	var txt = 'txt_car_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Itens';
		args = 'idCardapio=' + id + '&idGastronomia=' + ref;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Itens';
	}
	ExecAjaxSp(obj, '../ajax/gastronomia_cardapios_itens.asp', args, null);
}

// Função para exibir produtos dos clientes
function ViewComercioProduto(id, ref, view) {
	var obj = 'div_pro_' + id;
	var txt = 'txt_pro_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Produtos';
		args = 'idProduto=' + id + '&idComercio=' + ref;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Produtos';
	}
	ExecAjaxSp(obj, '../ajax/comercios_produtos_detalhes.asp', args, null);
}

// Função para exibir itens do cardápio no (PORTAL)
function LoadCardapio(id, ref, view) {
	var obj = 'div_car_' + id;
	var txt = 'txt_car_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Itens';
		args = 'idCardapio=' + id + '&idGastronomia=' + ref;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Itens';
	}
	ExecAjaxSp(obj, 'ajax/load_cardapios.asp', args, null);
}

// Função para exibir fotos dos álbuns dos clientes
function ViewClientesFotos(id, ref, tipo, view) {
	var obj = 'div_fot_' + id;
	var txt = 'txt_fot_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Fotos';
		args = 'idAlbum=' + id + '&Tipo=' + tipo + '&idReferencia=' + ref;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Fotos';
	}
	ExecAjaxSp(obj, '../ajax/clientes_load_fotos.asp', args, null);
}

// Funções para uso do Newsletter (PORTAL)
function SubContato(opc, id, tipo) {
	var param = 'Opc=' + opc + '&idReferencia=' + id + '&Tipo=' + tipo;
	if (opc == 'send') {
		if (gE('Nome').value == '') { alert('Por favor, entre com o Nome.'); gE('Nome').focus(); return false; }
		if (vEmail(gE('Email').value)) { alert('Endereço de E-mail inválido: ' + gE('Email').value); gE('Email').focus(); return false; }
		if (gE('Assunto').value.length < 5) { alert('Por favor, entre com o Assunto da Mensagem!'); gE('Assunto').focus(); return false; }
		if (gE('Mensagem').value.length < 5) { alert('Por favor, entre com a Mensagem!'); gE('Mensagem').focus(); return false; }
		param += '&Nome=' + gForm('Nome') + '&Email=' + gForm('Email') + '&Fone=' + gForm('Fone') + '&Assunto=' + gForm('Assunto') + '&Mensagem=' + gForm('Mensagem');
	}
	ExecAjax('load_contato', 'form_contato', 'ajax/contato.asp', param, null);
}

// Função para exibir detalhes dos pacotes locais
function LocalPacote(id, view) {
	var obj = 'div_pac_' + id;
	var txt = 'txt_pac_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Detalhes';
		args = 'idPacote=' + id;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Detalhes';
	}
	ExecAjaxSp(obj, '../ajax/local_pacotes.asp', args, null);
}

// Função para exibir detalhes dos pacotes das hospedagens de clientes
function ViewPacote(id, ref, view) {
	var obj = 'div_pac_' + id;
	var txt = 'txt_pac_' + id;
	var args = '';
	if (gE(obj).style.display == 'none' || view == 1) {
		gE(obj).style.display = 'block';
		gE(txt).innerHTML = 'Ocultar Detalhes';
		args = 'idPacote=' + id + '&idHospedagem=' + ref;
	} else if (gE(obj).style.display == 'block') {
		gE(obj).style.display = 'none';
		gE(txt).innerHTML = 'Exibir Detalhes';
	}
	ExecAjaxSp(obj, '../ajax/hospedagens_pacotes_detalhes.asp', args, null);
}

// função para recarregar abas
function LoadAbas(tipo, ref, aba) {
	switch (tipo) {
		case 'COM': TabsComercios(ref, aba); break;
		case 'HOS': TabsHospedagens(ref, aba ); break;
		case 'ITE': TabsItens(ref, aba); break;
		case 'GAS': TabsGastronomia(ref, aba); break;
		case 'CLA': TabsClassificados(ref, aba); break;
	}
}

// Função executar operações sobre fotos das fotos dos clientes
function ClientesAlbunsOpe(id, ref, tipo, act) {
	if (act == 'DEL' || act == 'DEF') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idAlbum=' + id + '&idReferencia=' + ref + '&Tipo=' + tipo + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/clientes_albuns_ope.asp', args, null);
		setTimeout('LoadAbas("' + tipo + '",' + ref + ',"aba_fot");', 200);
	}
}

// Função executar operações sobre fotos das fotos dos clientes
function ClientesAlbunsFotosOpe(id, ref, foto, tipo, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idAlbum=' + id + '&idReferencia=' + ref + '&idFoto=' + foto + '&Tipo=' + tipo + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/clientes_albuns_fotos_ope.asp', args, null);
		setTimeout('ViewClientesFotos(' + id + ',' + ref + ',"' + tipo + '",1);', 200);
	}
}

// Função executar operações sobre videos de clientes
function ClientesVideosOpe(id, ref, tipo, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idVideo=' + id + '&idReferencia=' + ref + '&Tipo=' + tipo + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/clientes_videos_ope.asp', args, null);
		setTimeout('LoadAbas("' + tipo + '",' + ref + ',"aba_vid");', 200);
	}
}

// Função executar operações sobre departamentos de comércios
function ComerciosDepartamentosOpe(dep, com, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idDepartamento=' + dep + '&idComercio=' + com + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/comercios_departamentos_ope.asp', args, null);
		setTimeout('LoadAbas("COM",' + com + ',"aba_dep");', 200);
	}
}

// Função executar operações sobre produtos dos comércios
function ComerciosProdutosOpe(pro, com, act) {
	if (act == 'DEL' || act == 'DEF') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idProduto=' + pro + '&idComercio=' + com + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/comercios_produtos_ope.asp', args, null);
		setTimeout('LoadAbas("COM",' + com + ',"aba_pro");', 200);
	}
}

// Função executar operações sobre fotos dos produtos dos comércios
function ComerciosProdutosFotosOpe(id, com, foto, act) {
	if (act == 'DEL' || act == 'DEF') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idProduto=' + id + '&idComercio=' + com + '&idFoto=' + foto + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/comercios_produtos_fotos_ope.asp', args, null);
		setTimeout('ViewComercioProduto(' + id + ',' + com + ',1);', 200);
	}
}

// Função executar operações sobre acomodações de hospedagens
function HospedagensAcomodacoesOpe(aco, hos, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idAcomodacao=' + aco + '&idHospedagem=' + hos + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/hospedagens_acomodacoes_ope.asp', args, null);
		setTimeout('LoadAbas("HOS",' + hos + ',"aba_aco");', 200);
	}
}

// Função executar operações sobre tarifas de hospedagens
function HospedagensTarifasOpe(tar, hos, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idTarifa=' + tar + '&idHospedagem=' + hos + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/hospedagens_tarifas_ope.asp', args, null);
		setTimeout('LoadAbas("HOS",' + hos + ',"aba_tar");', 200);
	}
}

// Função executar operações sobre pacotes das hospedagens
function HospedagensPacotesOpe(pac, hos, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idPacote=' + pac + '&idHospedagem=' + hos + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/hospedagens_pacotes_ope.asp', args, null);
		setTimeout('LoadAbas("HOS",' + hos + ',"aba_pac");', 200);
	}
}

// Função executar operações sobre detalhes dos pacotes das hospedagens
function HospedagensPacotesDetalhesOpe(pac, hos, ref, tipo, act) {
	if (act == 'DEL') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idPacote=' + pac + '&idHospedagem=' + hos + '&idReferencia=' + ref + '&Tipo=' + tipo + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/hospedagens_pacotes_detalhes_ope.asp', args, null);
		setTimeout('ViewPacote(' + pac + ',' + hos + ',1);', 200);
	}
}

// Função executar operações sobre cardápios de gastronomia
function GastronomiaCardapiosOpe(car, gas, act) {
	if (act == 'DEL' || act == 'DEF') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idCardapio=' + car + '&idGastronomia=' + gas + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/gastronomia_cardapios_ope.asp', args, null);
		setTimeout('LoadAbas("GAS",' + gas + ',"aba_car");', 200);
	}
}

// Função executar operações sobre itens dos cardápios de gastronomia
function GastronomiaCardapiosItensOpe(car, gas, iten, act) {
	if (act == 'DEL' || act == 'DEF') { var conf = OpConfirme('Confirmar operação de exclusão?'); } else { var conf = true; }
	if (conf) {
		var args = 'idCardapio=' + car + '&idGastronomia=' + gas + '&idItem=' + iten + '&Act=' + act;
		ExecAjaxSp('div_processo', '../ajax/gastronomia_cardapios_itens_ope.asp', args, null);
		setTimeout('ViewCardapio(' + car + ',' + gas + ',1);', 200);
	}
}
