var FF=(navigator.userAgent.indexOf("Firefox")!=-1);
var IE=(navigator.userAgent.indexOf("MSIE")!=-1);

function getAttr(obj,attr) {
	try {
		if (obj.length) {
			if (obj[0].attributes) {
				return obj[0].attributes.getNamedItem(attr).value;
			}
			else {
             	return obj[0][attr];
			}
		}
		else {
			if (obj.attributes) {
				return obj.attributes.getNamedItem(attr).value;
			}
			else {
				return obj[attr];
			}
		}
	}
	catch (e) {
		return '';
	}
}

function show(idx) {
	var A = ['psqfor','psqapl'];
	var os = document.getElementById(A[idx]);
	var oh = document.getElementById(A[(idx + 1) % 2]);
	os.style.display = 'block';
	os.style.visibility = 'visible';
	oh.style.display = 'none';
	oh.style.visibility = 'hidden';
}

function makeT(x_cap, y_cap, M, ordgrad, alg, cssprf, nowrap, tbcsssfx) {
	var i, j;
	var o = '</TABLE><P>';
	var row, caption;
	var ct_rowspan = new Array(M[0].length + 1); // + 1 para rowspan nos titulos de linhas
	var ct_colspan = new Array(M.length + 1); // + 1 para colspan nos titulos de colunas
	var col_style='';

    /* sufixo para margens diferenciadas em tabela. */
	if (typeof(tbcsssfx)=='undefined') {
		tbcsssfx='';
	}

    /* nowrap para a tabela inteira*/
	if (typeof(nowrap)=='undefined') {
		nowrap='';
	}

	/* Prefixo css para outros modelos de cor (Ex.: 'red_'). */
	if (typeof(cssprf)=='undefined') {
		cssprf='';
	}

	/* Alinhamento horizontal da tabela */
	if (typeof(alg)=='undefined') {
		alg = '';
	}
	else {
		alg = 'align="'+alg+'"';
	}

	/* Inicializamos os spans */
	/* ATE length, pois a ultima posicao eh para os cabeçalhos */
	for (i=0; i < ct_rowspan.length; i++) {
		ct_rowspan[i] = 0;
	}

	for (i=0; i < ct_colspan.length; i++) {
		ct_colspan[i] = 0;
	}

	for (i=M.length-1; i>=0; i--) {
		row = '</TR>';
		for (j=M[i].length-1; j>=0; j--) {
			if (typeof(M[i][j])=='number') {
				if (M[i][j] & ROWSPAN) {
					ct_rowspan[j]++;
				}
                if (M[i][j] & COLSPAN) {
					ct_colspan[i]++;
				}
			}
			else {
				var txt_span='';
				if (ct_rowspan[j] > 0) {
					txt_span = 'rowspan=' + (ct_rowspan[j] + 1);
					ct_rowspan[j] = 0;
				}
				else if (ct_colspan[i] > 0) {
					txt_span = 'colspan=' + (ct_colspan[i] + 1);
					ct_colspan[i] = 0;
				}
				if (M[i][j]==NOBG) {
					col_style='tb_corner';
				}
				else {
					col_style = cssprf + 'tb_' + (ordgrad ? (j % 2) : (i % 2));
				}
				row = '<TD class="' + col_style + '" ' + txt_span + ' ' + nowrap + '>' + (M[i][j]=='' ? '&nbsp' : M[i][j] ) + '</TD>' + row;
			}
		}
		if (x_cap && x_cap.length) {
			if (typeof(x_cap[i])=='number') {
                if (x_cap[i] & ROWSPAN) {
					ct_rowspan[M[0].length]++;
				}
			}
			else {
				var txt_span='';
				if (ct_rowspan[M[0].length] > 0) {
					txt_span = 'rowspan=' + (ct_rowspan[M[0].length] + 1);
					ct_rowspan[M[0].length] = 0;
				}
				if (x_cap[i]==NOBG) {
					col_style='tb_corner';
				}
				else {
					col_style= cssprf + 'tb_cap_ver';
				}

				row = '<TD class="' + col_style + '" ' + txt_span + ' >' + ((x_cap[i]==NOBG) ? '' : x_cap[i]) + '</TD>' + row;
			}
		}

		row = '<TR>' + row;
		o = row + o;
	}
	if (y_cap && y_cap.length) {
		caption = '</TR>';
		for (i=y_cap.length-1; i>=0; i--) {
			if (typeof(y_cap[i])=='number') {
                if (y_cap[i] & COLSPAN) {
					ct_colspan[M.length]++;
				}
			}
			else {
				var txt_span='';
				if (ct_colspan[M.length] > 0) {
					txt_span = 'colspan=' + (ct_colspan[M.length] + 1);
					ct_colspan[M.length] = 0;
				}
				if (y_cap[i]==NOBG) {
					col_style='tb_corner';
				}
				else {
					col_style= cssprf + 'tb_cap_ver';
				}
				caption = '<TD class="' + col_style + '" ' + txt_span + ' >' + ((y_cap[i]==NOBG) ? '' : y_cap[i]) + '</TD>' + caption;
			}
		}
		if (x_cap && x_cap.length) {
			caption = '<TD class="tb_corner"></TD>' + caption;
		}
		caption = '<TR>' + caption;
		o = caption + o;
	}
	o = '<TABLE border=0 cellpadding=0 cellspacing=0 ' + alg + ' class="tb' + tbcsssfx + '" style="position: relative; left: auto; top: auto;">' + o;
    document.write('<TEXTAREA OnFocus="this.select();">'+o+'</TEXTAREA>');
    //document.write(o);
}

function muda_bg(osel, prf, cor) {
	var col_old;
	var col_new;
	/* Adaptando para document.all (baseado em id - IE) e document.getElementsByName (baseado em name - FF)*/
	if (IE) {
		col_old = document.all[prf+osel.oldIdx];
		col_new = document.all[prf+osel.options[osel.selectedIndex].value];
	}
	else {
		col_old = document.getElementsByName(prf+osel.oldIdx);
		col_new = document.getElementsByName(prf+osel.options[osel.selectedIndex].value);
	}
	osel.oldIdx = osel.options[osel.selectedIndex].value;

	/* Tratando item antigo */
	if (col_old && col_old.length) {
		for (var i=0; i< col_old.length; i++) {
			col_old[i].style.backgroundColor = 'transparent';
		}
	}
	else {
		if (col_old && col_old.style) { //Para FF.......
			col_old.style.backgroundColor = 'transparent';
		}
	}

	/* Tratando novo item */
	if (col_new && col_new.length) {
		for (var i=0; i< col_new.length; i++) {
			col_new[i].style.backgroundColor = cor;
		}
	}
	else {
		if (col_new && col_new.style) {//Para FF....
			col_new.style.backgroundColor = cor;
		}
	}
}

function show_id(id) {
	var o = document.getElementById(id);
	o.style.visibility = 'visible';
	o.style.display = 'block';
}

function hide_id(id) {
	var o = document.getElementById(id);
	o.style.visibility = 'hidden';
	o.style.display = 'none';
}

/* Update 30/07/2008 - Para permitir crescimento on demand do layout, chamamos esta função OnLoad do body. */
function ajusteWidth() {
	var div_corpo = document.getElementById('corpo');
	var div_borda_NE = document.getElementById('borda_NE');
	var div_img_fundo = document.getElementById('img_fundo');
	var img_borda_SW = document.getElementById('borda_SW');
	var img_borda_S = document.getElementById('borda_S');
	var img_borda_SE = document.getElementById('borda_SE');
    div_borda_NE.style.left = div_corpo.offsetWidth - div_borda_NE.offsetWidth - 1;
    img_borda_S.width = div_corpo.offsetWidth - img_borda_SW.width - img_borda_SE.width;
	if (div_img_fundo) {
	   div_img_fundo.style.left = div_corpo.offsetWidth - div_img_fundo.offsetWidth - 2;
    }
}
