function ShowImageBox(dialogbox,imagetarget,size,imagelarge,width,height,imageoriginal,owidth,oheight)
{
 wwidth = document.documentElement.clientWidth - 40;
 hheight = document.documentElement.clientHeight - 156;
 lwidth = width;
 lheight = height;
 lowidth = owidth;
 loheight = oheight;
 if (width > wwidth)
 {
  lwidth = wwidth;
  lheight = height - (Math.round(((width - lwidth) / width) * height));
 }
 if (lheight > hheight)
 {
 llheight = lheight;
  lheight = hheight;
  lwidth = lwidth - (Math.round(((llheight - lheight) / llheight) * lwidth));
 }
 if (owidth > wwidth)
 {
  lowidth = wwidth;
  loheight = oheight - (Math.round(((owidth - lowidth) / owidth) * oheight));
 }
 if (loheight > hheight)
 {
 lloheight = loheight;
  loheight = hheight;
  lowidth = lowidth - (Math.round(((lloheight - loheight) / lloheight) * lowidth));
 }
 if (size == 1)
 {
 posX = PosXSearch(lwidth);
 posY = PosYSearch(lheight);
 document.getElementById(imagetarget).innerHTML = '<a onClick=\"ShowImageBox(\'' + dialogbox + '\', \'' + imagetarget + '\',2, \'' + imagelarge + '\', ' + width + ', ' + height + ', \'' + imageoriginal + '\', ' +  owidth + ', ' + oheight + ')\"><img src=\"' + imagelarge + '\" width=\"' + lwidth + '\" height=\"' + lheight + '\" border=\"0\" /></a>';
 }
 if (size == 2)
 {
 posX = PosXSearch(lowidth);
 posY = PosYSearch(loheight);
 document.getElementById(imagetarget).innerHTML = '<a onClick=\"CloseImageBox(\'' + dialogbox + '\')\"><img src=\"' + imageoriginal + '\" width=\"' + lowidth + '\" height=\"' + loheight + '\" border=\"0\" /></a>';
 }
 document.getElementById(dialogbox).style.display = "block";
 document.getElementById(dialogbox).style.top = posY + "px";
 document.getElementById(dialogbox).style.left = posX + "px";
 document.getElementById(dialogbox).style.width = lwidth + "px";
 document.getElementById(dialogbox).style.height = lheight + "px";
}

function PosXSearch(width)
{
 wwidth = document.documentElement.clientWidth;
 posX = wwidth - width;
 if (posX < 1) posX = 0;
 if (posX > 0)
 {
  posX = Math.round(posX / 2);
 }
 return posX;
}

function PosYSearch(height)
{
 hheight = document.documentElement.clientHeight;
 posY = hheight - (height + 115);
 if (posY < 1) posY = 0;
 if (posY > 0)
 {
  posY = Math.round(posY / 2);
 }
 posY = posY + YOffset();
 return posY;
}

 function YOffset()
 {
 Yoffset = window.pageYOffset; if(!Yoffset)
 Yoffset = document.body.scrollTop;
 if(!Yoffset)
 Yoffset = document.documentElement.scrollTop;
 if(!Yoffset)
 Yoffset = 0;
 return Yoffset;
}

function CloseImageBox(dialogbox)
{
 document.getElementById(dialogbox).style.display = "none";
}

function CloseImageBoxAndClearBox(dialogbox,imagetarget)
{
 document.getElementById(imagetarget).innerHTML = '';
 document.getElementById(dialogbox).style.display = "none";
}
