/** Открывает окно
 *  @param string path url загружаемого контента
 *  @param int width ширина окна
 *  @param int height высота окна
 *  @return WindowElement */
function windowOpen(path, width, height) {
	var wnd = window.open(path, '_blank', 'width='+width+', height='+height+',toolbar=no,menubar=no,scrollbars=yes,status=yes,resizable=yes');
	wnd.focus();
	return wnd;
}

function windowOpenFull(path, width, height) {
	var wnd = windowOpen(path, width, screen.availHeight);
	wnd.moveTo(20, 0);
}

/** Открывает слой с изображением
 *  @param event event событие
 *  @param string path путь до изображения
 *  @param int width ширина изображения
 *  @param int height высота изображения
 *  @return false */
function imageLayerOpen(event, path, width, height) {
	event.cancelBubble=true;
//	event.stopPropagation();
	new alzEventer(document.body, 'click', function(event){with(document.getElementById('imageLayer')){style.display='none';innerHTML='';} this.remove(); return false;}).add();

	if (!document.getElementById('imageLayer')) {
		var n = document.createElement('DIV');
		n.id = 'imageLayer';
		document.body.appendChild(n);
	}
	var layerWidth = width + 12;
	var layerHeight = height + 12;

	var fromLeft = Math.round(event.clientX - width/2);
	if (fromLeft+layerWidth > alzGetClientWidth()-20) fromLeft = alzGetClientWidth()-20-layerWidth;
	if (fromLeft < 0) fromLeft=0;
	fromLeft += document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;

	var fromTop = Math.round(event.clientY - height/2);
	if (fromTop+layerHeight > alzGetClientHeight()) fromTop = alzGetClientHeight() - layerHeight;
	if (fromTop < 0) fromTop=0;
	fromTop += document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;

	with (document.getElementById('imageLayer')) {
		innerHTML = '<img src="'+path+'" width="'+width+'" height="'+height+'">';
		style.width = width+'px'; style.height = height+'px';
		style.top = fromTop+'px'; style.left = fromLeft+'px';
		style.display = 'block';
	}
	return false;
}

function windowImageOpen(path, width, height) {
	var wnd = window.open('about:blank', '_blank', 'width='+width+', height='+height+',toolbar=no,menubar=no,scrollbars=no,status=yes,resizable=yes');
	wnd.document.write(
		 '<html><head><title>'+path.replace(/^.*\/([^\/]+)$/, '$1')+' ['+width+'X'+height+']</title></head>'
		+'<body style="margin:0; padding:0"><img src="'+path+'" width="'+width+'" height="'+height+'" title="Нажмите чтобы закрыть окно с изображением" onclick="window.close()" style="cursor:pointer"></body></html>');
	wnd.document.close();
	wnd.focus();
	return false;
}
