function closePopup() {
	document.getElementById("popUp").style.display = "none";
}
function Browser() {
	var ua = navigator.userAgent.toLowerCase();
	this.gecko = (navigator.product == "Gecko");
	this.compatible = true;
	this.ie6 = false;this.ie7 = false;
	var ie = ua.search(/msie\s((\d+)(\.\d+)*)/);
	var firefox = ua.search(/firefox\//);
	var kmeleon = ua.search(/k-meleon\//);
	var flock = ua.search(/flock\//);
	var netscape = ua.search(/netscape\//);
	var mozilla = ua.search(/mozilla\//);
	switch (true) {
		case ie != -1 && !window.opera && typeof window.showHelp != "undefined" && !window.sidebar: this.ie = true; break;
		case firefox != -1 && flock == -1 && !window.opera : this.firefox = true; break;
		case kmeleon != -1 && !window.opera : this.kmeleon = true; break;
		case netscape != -1 && !window.opera && (document.getElementById && !document.all) :	this.netscape = true; break;
		case flock != -1 && !window.opera : this.flock = true; break;
		case mozilla != -1 && !window.opera && !window.showHelp : this.mozilla = true; break;
		case window.opera : this.opera = true; break;
		default : this.compatible = false; break;
	}
	if (this.ie) {
		var version = ua.match(/msie\s((\d+)(\.\d+)*)/)[1];
		if (parseFloat(version) > 6) {
			this.ie7 = true;
		}
		if (parseFloat(version) < 5.5) {
			this.compatible = false;
		}
		if (this.ie && !this.ie7) {
			this.ie6 = true;
		}
	} else if (this.gecko) {
		var a = ua.match(/rv:([\d\.\w]+)/);
		var rvGecko = 0;
		if (a) {
			var rvParts = a[1].split(".");
			rvGecko = rvParts[0] + ".";
			for (var i = 1; i < rvParts.length; i++) {
				var val = parseInt(rvParts[i]) + "";
				rvGecko += (val.length == 1 ? "0" : "") + val;
			}
			rvGecko = parseFloat(rvGecko);
		}

		if (rvGecko < 1.06) {
			this.compatible = false;
		}
		
		if (this.mozilla) {
			if (rvGecko < 1.07) {
				this.compatible = false;
			}
		}
	} else {
		this.compatible = false;
	}
}
browser = new Browser();
function divBlock(mode) {
	if (mode) {
		divBlock.close();
	} else {
		divBlock.open();
	}
}
divBlock.open = function () {
	divBlock.div = jQuery('<div id="divBlock"></div>')
		.appendTo(document.body)
		.css("visibility", "visible")
		.fadeTo("fast", 0.6);
};
divBlock.close = function () {
	divBlock.div
		.css("visibility", "hidden")
		.hide()
		.remove();
};

function addElement(element, attributes, parent) {
	if (!parent) parent = document.body;
	var re_id = new String(new RegExp("id=[\\w\-]+").exec(attributes));
	var id = re_id.substring(re_id.indexOf("id=") +3);
	var elem = $(id);
	if (elem && elem != null) removeElement(elem);
	var elem = document.createElement(element);
	if (attributes) {
		var parts = attributes.split(";");
		for (i = 0; i < parts.length; i++) {
			var attrib = parts[i].split("=")[0];
			var value = parts[i].split("=")[1];
			elem.setAttribute(attrib, value);
		}
	}
	parent.appendChild(elem);
	return elem;
}
function removeElement(element) {
	element = $(element);
	while (element.hasChildNodes()) {
		element.removeChild(element.firstChild);
	}
	element.parentNode.removeChild(element);
}
function $(obj) {
	return (typeof(obj) == "string") ? document.getElementById(obj) : obj;
}
function centerObj(width, height, canvas) {
	var x = 0, y = 0, refWidth = 0, refHeight = 0;

	if (canvas) {
		refWidth = getCanvasWidth();
		refHeight = getCanvasHeight();
	} else {
		refWidth = screen.width;
		refHeight = screen.height;
	}

	if (width) {
		if (refWidth > width) {
			x = (refWidth - width) / 2;
		}
	}

	if (height) {
		if (refHeight > height) {
			y = (refHeight - height) / 2;
		}
	}
	return {left:x, top:y};
}
function getCanvasWidth() {
	var doc = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
	return doc.clientWidth;
}

/*
Ver comentário da função getCanvasWidth().
*/
function getCanvasHeight() {
	var doc = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
	return doc.clientHeight;
}
