
/* ------------------------------------------------------------------------- */
/* Cores */

function bOn(obj, label) {
	obj.style.borderColor = "#333333";
}

function bOff(obj, label) {
	obj.style.borderColor = "#999999";
}

function trOnOff(chk, cod) {
	var cel = document.getElementById("tr-reg-"+cod).getElementsByTagName("td");
	var i;
	
	for(i = 0; i < cel.length; i++) {
		if(chk.checked) {
			cel[i].style.backgroundColor = "#F0F0F0";
		}
		else {
			cel[i].style.backgroundColor = "#FFFFFF";
		}
	}
}

function trOn(obj) {
	var cel = obj.getElementsByTagName("td");
	var i;
	
	for(i = 0; i < cel.length; i++) {
		if(cel[i].style.backgroundColor.toUpperCase() != "#F0F0F0") {
			cel[i].style.backgroundColor = "#FFFF99";
		}
	}
}

function trOff(obj) {
	var cel = obj.getElementsByTagName("td");
	var i;
	
	for(i = 0; i < cel.length; i++) {
		if(cel[i].style.backgroundColor.toUpperCase() != "#F0F0F0") {
			cel[i].style.backgroundColor = "#FFFFFF";
		}
	}
}

/* ------------------------------------------------------------------------- */
/* Geral */

function divExpandeCollapse(dv) {
	var div = document.getElementById(dv);
	
	if(div.style.height == "20px") {
		div.style.height = "100px";
	}
	else {
		div.style.height = "20px";	
	}
	
	return false;
}

function logout() {
	return confirm("Confirmar logout?");
}

/* ------------------------------------------------------------------------- */
/* Popups */

function popupImprimir(url) {
	var wid = 680;
	var hei = 480;
	
	var param = popupCentralizar(wid, hei);

	window.open(url, "ACAO_IMPRIMIR", "menubar=no, toolbar=no, scrollbars=yes, resizable=no, status=yes, directories=no, " + param);
}

// -----------------------------------------------------------------------
// Forms

function vRetorno(frm_name, acao) {
	var frm = document.forms[frm_name];
	frm.retact.value = acao;
}

function vFrmFiltroEnter(frm_name) {
	if(event.keyCode == 13) {
		vFiltro(frm_name, 1);
	}
	
	return false;
}

function vFiltro(f, pg, ord, sent) {
	var frm = document.forms[f];

	if(!pg) {
		pg = 1;
	}
	
	if(ord) {
		frm.filtro_ordenar.value = ord;
	}
	
	if(sent) {
		frm.filtro_sentido.value = sent;
	}
	
	frm.filtro.value = "ativar";
	frm.filtro_pgn.value = pg;
	
	vAlerta("INFO", "Processando...");
	
	frm.submit();
}

function vFiltroReiniciar(f) {
	var frm = document.forms[f];
	
	frm.filtro.value = "";
	frm.filtro_ordenar.value = "";
	frm.filtro_sentido.value = "";
	frm.filtro_pgn.value = 1;
	frm.filtro_pgn_qtd_reg.value = 10;
	
	vAlerta("INFO", "Processando...");
	
	frm.submit();
}

function vPgnQtdReg(obj, f) {
	var frm = document.forms[f];
	var qtd = frm.filtro_pgn_qtd_reg;
	
	qtd.value = obj.value;
}

function vExcluir() {
	if(!confirm('Confirmar exclusão?')) {
		return false;
	}
	
	vAlerta("INFO", "Processando...");
	
	return true; 
}

function vAtivar(frm_name) {
	var frm = document.forms[frm_name];
	
	if(!vCheckbox(frm)) {
		vAlerta("ERRO", "Selecione pelo menos 1 registro");
		//return false;
	}
	
	if(confirm('Confirmar ativação de registros?')) {
		vAlerta("INFO", "Processando...");
		
		frm.action+= "&acao=ativar";
		frm.submit();
		
		return true
	}
		
	return false;
}

function vDesativar(frm_name) {
	var frm = document.forms[frm_name];
	
	if(!vCheckbox(frm)) {
		vAlerta("ERRO", "Selecione pelo menos 1 registro");
		//return false;
	}
	
	if(confirm('Confirmar desativação de registros?')) {
		vAlerta("INFO", "Processando...");
		
		frm.action+= "&acao=desativar";
		frm.submit();
		
		return true
	}
		
	return false;
}

function vLiberar(frm_name) {
	var frm = document.forms[frm_name];
	
	if(!vCheckbox(frm)) {
		vAlerta("ERRO", "Selecione pelo menos 1 registro");
		//return false;
	}
	
	if(confirm('Confirmar liberação de registros?')) {
		vAlerta("INFO", "Processando...");
		
		frm.action+= "&acao=liberar";
		frm.submit();
		
		return true
	}
		
	return false;
}

function vBloquear(frm_name) {
	var frm = document.forms[frm_name];
	
	if(!vCheckbox(frm)) {
		vAlerta("ERRO", "Selecione pelo menos 1 registro");
		//return false;
	}
	
	if(confirm('Confirmar bloqueio de registros?')) {
		vAlerta("INFO", "Processando...");
		
		frm.action+= "&acao=bloquear";
		frm.submit();
		
		return true
	}
		
	return false;
}

function vAlerta(tipo, msg) {
	return;
	var m = "<font size='3'>&nbsp;&nbsp;</font>";
	var obj = parent.document.getElementById("dv-status-msg");
	
	if((tipo != "") && (tipo == 0)) {
		tipo = "OK";
	}
	
	if((tipo != "") && (tipo == 1)) {
		tipo = "ERRO";
	}
	
	if(tipo == "ERRO") {
		m = "<font color='#CC0000'><strong>ERRO<font size='3'>&nbsp;&raquo;&nbsp;</font></strong>"+msg+"</font>";
	}
	else if(tipo == "OK") {
		m = "<font color='#0000CC'><strong>OK<font size='3'>&nbsp;&raquo;&nbsp;</font></strong>"+msg+"</font>";
	}
	else if(tipo == "INFO"){
		m = "<font color='#333333'><strong>INFO<font size='3'>&nbsp;&raquo;&nbsp;</font></strong>"+msg+"</font>";
	}
	
	if(!msg) {
		obj.innerHTML = "<strong><font size='2'>&nbsp;</font></strong>";
	}
	else {
		obj.innerHTML = m;
	}
}

function vTooltip(ttip, req, tipo, msg) {
	var cnt = "";
	
	if(!ttip) {
		toolTip();
		return false;
	}
	
	if(msg) {
		cnt += msg+"<br>";
	}
	
	if(req == 1) {
		cnt += "<font color='#CC0000'>Preenchimento obrigatório</font><br>";
	}
	
	if(tipo == "email") {
		cnt += "E-mail: campo alfanumérico";
		cnt += "<br>Ex.: usuario@provedor.com.br";
	}
	else if(tipo == "url") {
		cnt += "URL: campo alfanumérico";
		cnt += "<br>Ex.: www.infomet.com.br";
	}
	else if(tipo == "cnpj") {
		cnt += "Cnpj: campo numérico";
		cnt += "<br>Ex.: xx.xxx.xxx/xxxx-xx";
	}
	else if(tipo == "data") {
		cnt += "Data: campo numérico";
		cnt += "<br>Ex.: dd/mm/aaaa";
	}
	else if(tipo == "cpf") {
		cnt += "Cpf: campo numérico";
		cnt += "<br>Ex.: xxx.xxx.xxx-xx";
	}
	else if(tipo == "numero") {
		cnt += "Campo numérico";
		cnt += "<br>Ex.: 123456";
	}
	else if(tipo == "cep") {
		cnt += "Cep: campo numérico";
		cnt += "<br>Ex.: xxxxx-xxx";
	}
	else if(tipo == "select") {
		cnt += "Lista de seleção";
		cnt += "";
	}
	else if(tipo == "checkbox") {
		cnt += "Caixa de seleção múltipla";
		cnt += "";
	}
	else if(tipo == "radio") {
		cnt += "Caixa de seleção";
		cnt += "";
	}
	else if(tipo == "arquivo") {
		cnt += "Endereço do arquivo";
		cnt += "";
	}
	else if(tipo == "null") {
	}
	else {
		cnt += "Campo alfanumérico";
		cnt += "<br>Ex.: texto1234";
	}
	
	toolTip(cnt);
}