var bExtPopupInited = false;
var obWndDiv = false; 
var bExtPopupActive = false;
function HideExtPopup()
{
	bExtPopupActive = false;
	obWndDiv.style.visibility = "hidden";
}
function InitExtPopup()
{
	bExtPopupInited = true;
	obWndDiv = document.createElement("div");
	obWndDiv.setAttribute("id", "wnddiv");
	obWndDiv.onclick = function(){HideExtPopup();}
	document.body.appendChild(obWndDiv);
	obWndDiv.style.visibility = "hidden";
	obWndDiv.innerHTML = "";
	obWndDiv.style.display = "none";
}

function ShowExtPopup(nLeft, nTop, nWidth, nHeight, sContent)
{
	if(!bExtPopupInited){InitExtPopup();}
	if(bExtPopupActive){HideExtPopup();}
	bExtPopupActive = true;
	obWndDiv.style.visibility = "hidden";
	obWndDiv.style.left = nLeft + "px";
	obWndDiv.style.top = nTop + "px";
	if (String(nWidth).indexOf("%") >= 0) {
		obWndDiv.style.width = parseInt(nWidth) + "%";
	} else {
		obWndDiv.style.width = parseInt(nWidth) + "px";
	}
	obWndDiv.style.height = nHeight + 14 + "px";
	obWndDiv.innerHTML = sContent+"<div class='closemessage'>закрыть окно</div>";
	obWndDiv.style.visibility = "visible";
	obWndDiv.style.display = "block";
}
var bUseNewStylePopup = true;
function showFullsize(sSrc1, nWidth1, nHeight1)
{
	var sSrc2="", nWidth2=0, nHeight2=0;
	var scroll = "no", top = 0, left = 0, width = 0, height = 0;
	width = Math.floor(nWidth1) + Math.floor(nWidth2) + (Math.floor(nWidth2) != 0 ? 1 : 0);
	height = Math.max(nHeight1, nHeight2);
	if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
	if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
	if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
	width = Math.min(width, screen.width-10)+((scroll=="yes")?40:20);
	height = Math.min(height, screen.height-28);
	
	if(!bUseNewStylePopup)
	{
		var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
		wnd.document.write("<html><head><title>Детальный просмотр</title></head>\n");
		wnd.document.write("<body style='margin:0;padding:0;' onKeyPress=\"if(window.event.keyCode == 27)window.close();\">\n");
		wnd.document.write("<img style='border:0;float:left;margin:0;padding:0;' src=\""+sSrc1+"\" />");
		if(sSrc2 != "") wnd.document.write("<img src=\""+sSrc2+"\" style='border:0;border-left:1px solid #000;float:left;margin:0;padding:0;' />");
		wnd.document.write("</body></html>");
		wnd.document.close();
	}else
	{
		var w = Math.floor(nWidth1) + Math.floor(nWidth2) + (Math.floor(nWidth2) != 0 ? 1 : 0);
		var h = Math.max(nHeight1, nHeight2);
			var myWidth = 0, myHeight = 0;
			if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
			}
			var scrOfX = 0, scrOfY = 0;
			if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
			} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
			} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
			}
		var cw = myWidth;
		var ch = myHeight;
		var sx = scrOfX;
		var sy = scrOfY;
		var ix = 0;
		var iy = 0;
		if(w>(cw-50)){ix= sx + 10}else{ix=sx+(cw-w)/2;}
		if(h>(ch-50)){iy= sy + 10}else{iy=sy+(ch-h)/2;}
		sContent="<img style='border:0;float:left;margin:0;padding:0;' src=\""+sSrc1+"\" />";
		if(sSrc2 != ""){sContent += "<img src=\""+sSrc2+"\" style='border:0;border-left:1px solid #000;float:left;margin:0;padding:0;' />";}
		//sContent += "";
		//alert("Popup at (x:"+ix+"px, y:"+iy+"px) scroll: (x"+sx+"px, y:"+sy+"px) wndwidth (x:"+cw+"px, y:"+ch+"px)");
		ShowExtPopup(ix, iy, w, h, sContent);
	}
}