function showModal(title_, subTitle, url_, reload, closeFunction) {
	var dimension = document.viewport.getDimensions();// -> { width: Number, height: Number }
	dimension.width = dimension.width > 900 ? 600 : dimension.width - 200;
	dimension.height = dimension.height > 700 ? 600 : dimension.height - 120;

	title_ = subTitle ? title_ +  ": <span>" + clearPath(subTitle) + "</span>" : title_;
	var win = new Window({
		className: "alphacube",
		title: title_,
		width: dimension.width,
		height: 490,
		url: url_,
		onClose: reload == true ? (function() {window.location.reload(true);}) : closeFunction,
		showEffectOptions: {duration:1},
		hideEffectOptions: {duration:0.1},
		resizable: false,
		draggable: false,
		minimizable: false,
		maximizable: false
	});
	win.showCenter(true);
	win.toFront();
	return win;
}

function showMiniModal(event, title_, div) {
	Windows.closeAll();
	var win = new Window({
		className: "alphacube",
		title: title_,
		width:320,
		height:200,
		top: Event.pointerY(event),
		left: Event.pointerX(event) + 10,
		showEffectOptions: {duration:0.0},
		hideEffectOptions: {duration:0.0},
		resizable: false,
		opacity: 1,
		draggable: true
	});
	win.setContent(div);
	win.show();
	return win;
}

function showModalNoIframe(title_, subTitle, content) {
	var dimension = document.viewport.getDimensions();// -> { width: Number, height: Number }
	dimension.width = dimension.width > 900 ? 800 : dimension.width - 100;
	dimension.height = dimension.height > 700 ? 600 : dimension.height - 100;
	title_ = subTitle ? title_ +  ": <span>" + clearPath(subTitle) + "</span>" : title_;
	var win = new Window({
		className: "alphacube",
		title: title_,
		width: dimension.width,
		height: dimension.height,
		showEffectOptions: {duration:1},
		hideEffectOptions: {duration:0.1},
		resizable: false,
		draggable: false
	});
	win.setContent(content);
	win.showCenter(true);
	return win;
}

function closeCurrentWindow(event) {
	var id = Windows.getFocusedWindow().getId();
	if (id && id.indexOf("tooltip") != -1) {
		Windows.closeAll();
	} else {
		Windows.close(Windows.getFocusedWindow().getId(), event);
	}
}

function showPopup(title, link) {
	window.open(link, title, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=1280,height=960,left=0,top=0');
}

function openConfirmDialog(msg, okFunction, cancelFunction) {
	Dialog.confirm(msg,
		{
			 width:300,
	    	 className: "alphacube",
	    	 okLabel: "Sim",
	    	 cancelLabel:"Não",
	    	 showEffectOptions: {duration:0.0},
			 hideEffectOptions: {duration:0.0},
	    	 cancel: cancelFunction,
	    	 ok: okFunction
    	}
    );
    return false;
}

function removeDialog(url, name) {
	openConfirmDialog("Confirma a exclusão de " + name + "?", function() {
		location = url;
	});
}

function openAlertDialog(msg) {
	Dialog.alert(msg,
		{
         	width:300,
         	className: "alphacube",
         	showEffectOptions: {duration:0.0},
			hideEffectOptions: {duration:0.0},
         	okLabel: "Fechar"
		}
	);
}

function clearPath(path) {
	if (path.lastIndexOf("/") != -1) {
		return path.substring(path.lastIndexOf("/") + 1, path.length);
	} else {
		return path;
	}
}
