function ShowImageInDiv(url, w, h) {		
	clientHeight = getClientHeight();
	clientWidth = getClientWidth();
	if (h > clientHeight) h = clientHeight;
	if (w > clientWidth) w = clientWidth;
	
	var element = document.getElementById("mainbody");
	
	mainDiv = document.createElement('div');
	mainDiv.setAttribute("style", "width:"+clientWidth+"px;height:"+getClientYOffset()+"px;");
	mainDiv.setAttribute("class", "ShowImageDiv");
	mainDiv.className = "ShowImageDiv";
	mainDiv.style.width = clientWidth+"px";
	mainDiv.style.height = getClientYOffset()+"px";
	mainDiv.style.top = 0 + "px";
	mainDiv.style.left = 0 + "px";
	mainDiv.style.position = "absolute";
	mainDiv.setAttribute("onclick", "javascript:closeImage();");
	mainDiv.onclick = function(){ closeImage(); };
	mainDiv.id = "ShowImageDiv";
	element.appendChild(mainDiv);
	

	img = document.createElement('img');
	img.src = url;
	img.width = w;
	img.height = h;
	img.setAttribute("style", "margin-top:"+getPosY(h)+"px;");
	img.style.marginTop = getPosY(h)+"px";
	mainDiv.appendChild(img);
	closeDiv = document.createElement('div');
	closeDiv.innerHTML = "<a href=\"javascript:void(0);\">Закрыть</a>";
	mainDiv.appendChild(closeDiv);
	
	
}

function closeImage() {
	document.getElementById("ShowImageDiv").parentNode.removeChild(document.getElementById("ShowImageDiv"));
}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function getPosY(h) {
	if (self.innerHeight) {
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		y = document.documentElement.clientHeight;
	} else if (document.body) {
		y = document.body.clientHeight; 
	}
	y = y/2 - h/2 + getBodyScrollTop();
	return y
}

function getBodyScrollTop() {
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft() {
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientYOffset() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollHeight:document.body.scrollHeight;
}
