




tempImg = null;
picsFolderOffline = "/system/galleries/pics/";
picsFolder = "/pics/";

var cmsroot = "/";
cmsroot = cmsroot.substring(0, cmsroot.length - 1);

function getOffset(element, offsetName) {
	var result = 0;
	while (element != null) {
		result += eval("element." + offsetName);
		element = element.offsetParent;
	}
	return result;
}

var timeouts = new Array(0);

function showMenu(menuId) {
	document.getElementById("menu" + menuId).style.left = getOffset(document.getElementById("im" + menuId), "offsetLeft");
	document.getElementById("menu" + menuId).style.top = getOffset(document.getElementById("im" + menuId), "offsetTop") + document.getElementById("im" + menuId).offsetHeight - 2;
	document.getElementById("menu" + menuId).style.visibility = "visible";
}

function hideMenu(menuId) {
	timeouts[menuId] = window.setTimeout("doHideMenu(" + menuId + ")", 10);
}

function doHideMenu(menuId) {
	document.getElementById("menu" + menuId).style.visibility = "hidden";
}

function doNotHide(menuId) {
	window.clearTimeout(timeouts[menuId]);
}

function openBigPicture(url, title, rootApplied) {
	if (!title) var title = defaultPopupTitle;
	if ((url.substring(0, 1) == "/") && (!rootApplied)) url = cmsroot + url.replace(picsFolderOffline, picsFolder).replace(cmsroot, "");
	tempImg = new Image();
	tempImg.src = url;
	imageOpener(url, title);
}

function imageOpener(url, title) {
	if ((tempImg.width != 0) && (tempImg.height != 0)) {
		var canScroll = 0;
		var w = tempImg.width;
		var h = tempImg.height;
		if (!title) var title = defaultPopupTitle;
		if (w > (screen.width - 150)) {
			w = screen.width - 150;
			canScroll = 1;
		}
		if (h > (screen.height - 150)) {
			h = screen.height - 150;
			canScroll = 1;
		}
		var left = (screen.width - w) / 2;
		var top = (screen.height - h) / 2;
		win = window.open('', 'Popup', 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',menubar=0,location=0,resizable=0,scrollbars=' + canScroll + ',directories=0,scroll=' + canScroll + ',status=0,menubar=0,locationbar=0,statusbar=0,titlebar=0,toolbar=0');
		win.document.open();
		win.document.write("<html><head><title>" + title + "</title></head><body bgcolor=#FFFFFF leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><img src='" + url + "' width='" + tempImg.width + "' height='" + tempImg.height + "'></body></html>");
		win.document.close();
		win.moveTo(left, top);
		win.focus();
	} else {
    toFunc = "imageOpener('" + url + "', '" + title + "')";
    tim = setTimeout(toFunc, 20);
	}
}

function openImageWindow(url, title) {
	if (!title) var title = defaultPopupTitle;
	url = url.replace("/system/galleries/pics/", "/pics/");
	if (url.substring(0, 1) == "/") url = cmsroot + url.replace(picsFolderOffline, picsFolder).replace(cmsroot, "");
	openBigPicture(url, title, true);
}

function openWindow(url, w, h, canScroll) {
	if (!canScroll) canScroll = 0;
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	var pat = new RegExp("^/", "");
	url = url.replace(pat, "/");
	win = window.open(url, 'Popup', 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',menubar=0,location=0,resizable=1,scrollbars=' + canScroll + ',directories=0,scroll=' + canScroll + ',status=0,menubar=0,locationbar=0,statusbar=0,titlebar=0,toolbar=0');
}

function printPage(url) {
	wndName = "printWnd";
    if ((url == null) || (url == '#')) {
		return;
	}
	var shiftH = 200;
	var shiftV = 280;
	var w = screen.availWidth - shiftH;
	var h = screen.availHeight - shiftV;
	var t = shiftV / 2;
	var l = shiftH / 2;
	var wndFeatures = "toolbar=no,location=no,directories=no,titlebar=no,status=yes,menubar=1,scrollbars=yes,resizable=yes,top=" + t + ",left=" + l + ",width=" + w + ",height=" + h;
	var popupWnd = window.open(url, wndName, wndFeatures);
	if(popupWnd != null) {
		popupWnd.moveTo(l,t);
		if (popupWnd.opener == null) {
			popupWnd.opener = self;
		}
		popupWnd.focus();
	}
}

function printWindow(){
	var ver = parseInt(navigator.appVersion);
	if ((ver >= 4) && (navigator.appVersion.indexOf("MSIE 5.5") == -1)) {
		window.print();
	}
}