function popup(url, width, height, scrollbars)
{
	var config = "width=" + width + ",height=" + height + ",menubar=1,"
		+ "toolbar=0,location=0,status=1,resizable=1,scrollbars="
		+ (scrollbars == 1 ? "1" : "0") + ",top="
		+ ((window.screen.height - height) / 4) + ",left="
		+ ((window.screen.width - width) / 3);
	var obj = window.open(url,'', config);
	obj.focus();
}

function getObject(id, oWindow)
{
	if(oWindow == null) oWindow = window;
	var obj = oWindow.document.all ? oWindow.document.all[id] : oWindow.document.getElementById(id);
	return obj;
}

/* Converte uma cor hexadecimal em RGB.
 * Isso é para compatibilizar com o Mozilla.
 */
function hex2rgb(hex) {
	if(hex.match(/^#[a-f0-9]{6}$/) == null) {
		return hex;
	}
	hex = hex.replace(/^#/, "");
	var r = hex.substr(0, 2);
	var g = hex.substr(2, 2);
	var b = hex.substr(4, 2);
	var rgb = 'rgb(' + hexdec(r) + ', ' + hexdec(g) + ', ' + hexdec(b) + ')';
	return rgb;
}
function hexdec(hex) {
	var D = [];
	D['0'] = 0; D['1'] = 1; D['2'] = 2; D['3'] = 3; D['4'] = 4;
	D['5'] = 5; D['6'] = 6; D['7'] = 7; D['8'] = 8; D['9'] = 9;
	D['A'] = 10; D['B'] = 11; D['C'] = 12; D['D'] = 13; 
	D['E'] = 14; D['F'] = 15;	
	var a = hex.substr(0, 1).toUpperCase();
	var b = hex.substr(1, 1).toUpperCase();
	return D[a] * 16 + D[b];
}

/* Confirmar exclusão
 */
function confirmar_exc(form, url) {
	if(!form.ckExcluir) {
		return ;
	}
	with(form) {
		var arr = ckExcluir.length ? ckExcluir : [ckExcluir];
		var str = "", total = 0;
		for(var i = 0; i < arr.length; i++) {
			if(arr[i].checked) {
				if(str != "") str += ",";
				str += arr[i].value;
				total++;
			}
		}
		if(total == 0) {
			alert("Você não selecionou nenhum registro para excluir!");
			return ;
		}
		var msg = "Deseja excluir " + (total == 1 ? "o registro selecionado?" : "os " + total + " registros selecionados?");
		if(!confirm(msg)) {
			return ;
		}
		url += (url.indexOf('?') == -1 ? '?' : '&');
		location.href = url + 'excluir=' + str;
	}
}

var lrLegenda_timer = -1;

function mostrarLegenda(legenda, e)
{
	var obj = getObject('lrLegendaArq');
	obj.innerHTML = legenda;
	obj.style.top = e.clientY;
	obj.style.left = e.clientX + 20;
	obj.style.display = "block";
}

function ocultarLegenda()
{
	getObject('lrLegendaArq').style.display = 'none';
}

// Identificador único
function uniqid() {
	return (new Date()).getTime() + parseInt(Math.random() * 999999);
}

function mascararData(obj) {
	obj.value = obj.value.replace(/[^0-9\/]/, '');
	if(obj.value.length == 2 || obj.value.length == 5) {
		obj.value += '/';
	}
}

function conferirData(data) {
	if(data.match('^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$') == null) {
		return false;
	}
	var arr = data.split('/');
	var dia = parseInt(arr[0], 10);
	var mes = parseInt(arr[1], 10);
	var ano = parseInt(arr[2], 10);
	if(dia < 1 || dia > 31) return false;
	if(mes < 1 || mes > 12) return false;
	if(ano < 1970 || ano > 2099) return false;
	if(mes == 2) {
		if(ano % 4 == 0) return dia <= 29;
		return dia <= 28;
	}
	if(mes == 4 || mes == 6 || mes == 9 || mes == 11) {
		return dia <= 30;
	}
	return true;
}

function img_normal(n, w, h, L) {
	w += 50; h += 50;
	var top = (window.screen.height - h) / 4;
	var left= (window.screen.width - w) / 2;
	var obj = window.open('','','width='+w+',height='+h+',resizable=0,menubar=0,toolbar=0,location=0,status=0,top='+top+',left='+left);
	with(obj.document) {
		open();
		write('<html>\n<head>\n<title>'+L+'</title>\n</head>\n\n');
		write('<body bgcolor="black" onLoad="self.resizeTo('+w+','+h+')" ');
		write('topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">\n');
		write('<div style="width: 100%; height: 100%; overflow: hidden">\n');
		write('<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">\n');
		write('<tr>\n<td align="center">');
		write('<img src="'+n+'/normal.JPG">');
		write('</td>\n</tr>\n</table>\n</div>\n</body>\n\n</html>');
		close();
	}
}

