var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id)
{
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}
function getSty(id)
{
return (isNS4 ? getRef(id) : getRef(id).style);
}
function login()
{
	v_usr = document.frm_login.txt_id.value;
	v_psw = document.frm_login.txt_psw.value;
	cpaint_call(
	  './lib/func.php',
	  'GET',
	  'login',
	  v_usr,
	  v_psw,
	  exe_login,
	  'TEXT');
}
function exe_login(valor)
{
	if(valor == "erro")
		alert("Login inválido!!!\nVerifique seu e-mail e SENHA, por favor...");
	else
	{
		v_dado = valor.split("|");
		v_aux = "<span style='padding-top:5px'>Seja bem vindo, <strong>" + v_dado[0] + "</strong></span>";
		v_aux += "&nbsp;&nbsp;<a href='javascript:logout();'><img src='imagens/bt_logout.jpg' align='absmiddle' /></a>";
		getRef("login").innerHTML = v_aux;
		var aux_lnk = "cadastro.php?id=" + v_dado[1] + "&nv=" + v_dado[2];
		var v_menu = new Array("usr","cadger","cons","grp","mkt","usr_sist","etiq","eventos","senha","cad","doa","senha","cons","mkt","etiq","eventos","senha");
		var v_link = new Array("usr_homol.php","cad_geral.php","consulta.php","grupos.htm","mailmkt.php","cad_usuarios.php","etiquetas/rel_etiqueta.php","eventos/evento.php","alt_senha.php",aux_lnk,"doacao.php?id=" + v_dado[1] + "&nv=1","alt_senha.php","consulta.php","mailmkt.php","etiquetas/rel_etiqueta.php","eventos/evento.php","alt_senha.php");
		nv = v_dado[2];
		aux = "";
		if (nv== 1) //usuário parceiro
		{
			v_ini = 9;
			v_fim = 11;
		}
		else if (nv==2) //usuário gerenciador
		{
			v_ini = 12;
			v_fim = 16;
		}
		else if (nv=3) //usuário administrador
		{
			v_ini = 0;
			v_fim = 8;
		}
		
		for(i=v_ini;i<=v_fim;i++)
			aux += "<a href='" + v_link[i] + "' target='frm_conteudo'><img src='imagens/mn_" + v_menu[i] + ".jpg' /></a><br />";
		getRef("frm_conteudo").src = "tela_centro.php?nv="+nv;
		getRef("menu").innerHTML = aux;
		getSty("menu").visibility = "visible";
	}
}
function logout()
{
	window.location='index.php';
}
function cadastra_grp(x)
{
	v_query = window.opener.document.frm1.query.value;
	cpaint_call(
	  'func.php',
	  'GET',
	  'exe_cadgrp',
	  x,
	  v_query,
	  fecha_jan,
	  'TEXT');
}
function fecha_jan(valor)
{
	window.close();
}
function muda_mkt(tp)
{
	cpaint_call(
	  './lib/func.php',
	  'GET',
	  'muda_mkt',
	  tp,
	  exe_mudamkt,
	  'TEXT');
}

function exe_mudamkt(valor)
{
	v_linha = valor.split("||");
	//limpa o select
	x = getRef("sl_dest").options.length;
	for(i=1;i<x;i++)
		getRef("sl_dest").options[1] = null;
	//carrega o select
	for(i=1;i<=v_linha.length;i++)
	{
		v_dado = v_linha[i-1].split("|");
		op = new Option(v_dado[1],v_dado[0]);
		getRef("sl_dest").options[i] = op;
	}
}

function carrega_inst(tp,idx)
{
	if(tp==1)
		uf = getRef("sl_uf"+idx).value;
	else
		uf = getRef("sl_cidade"+idx).value;
	//alert(uf);
	cpaint_call(
	  './lib/func.php',
	  'GET',
	  'carrega_inst',
	  tp,
	  uf,
	  idx,
	  exe_carrega_inst,
	  'TEXT');
}

function exe_carrega_inst(valor)
{
	//alert(valor);
	valores = valor.split("||");
	tipos = valores[0].split("|");
	dados = valores[1].split("|");
	if(tipos[1]==1) aux="sl_cidade";else aux="sl_inst";
	aux = aux + tipos[0].toString();

	//limpar os combos
	getRef("sl_inst" + tipos[0].toString()).options.length = 0;
	if(tipos[1]==1)
		while(getRef("sl_cidade" + tipos[0]).options.length > 0)
			getRef("sl_cidade" + tipos[0]).options[0] = null;
	op1 = new Option("--Selecione a Cidade--","");
	getRef("sl_cidade" + tipos[0].toString()).options[0] = op1;
	
	//	getRef("sl_inst" + tipos[0]).options[0] = null;
	op = new Option("--Selecione a Instituição--","");
	getRef("sl_inst" + tipos[0].toString()).options[0] = op;	
	for(i=0;i<dados.length;i++)
	{
		op = new Option(dados[i],dados[i]);
		getRef(aux).options[i+1] = op;
	}
	
}

function lista_inst()
{
	uf = getRef("sl_uf1").value;
	cpaint_call(
	  './lib/func.php',
	  'GET',
	  'carrega_inst',
	  1,
	  uf,
	  1,
	  exe_lista_inst,
	  'TEXT');
}
function exe_lista_inst(valor)
{
	valores = valor.split("||");
	tipos = valores[0].split("|");
	dados = valores[1].split("|");
	aux="sl_cidade"
	//limpar os combos
	while(getRef("sl_cidade" + tipos[0]).options.length > 0)
		getRef("sl_cidade" + tipos[0]).options[0] = null;

	op = new Option("--Selecione a Cidade--","");
	getRef("sl_cidade" + tipos[0]).options[0] = op;
	
	for(i=0;i<dados.length;i++)
	{
		op = new Option(dados[i],dados[i]);
		getRef(aux + tipos[0]).options[i+1] = op;
	}
}
