    function getViewportWidth() {
        var width = 0;
        if( document.documentElement && document.documentElement.clientWidth ) {
            width = document.documentElement.clientWidth;
        }
        else if( document.body && document.body.scrollWidth ) {
            width = document.body.scrollWidth;
        }
        else if( window.innerWidth ) {
            width = window.innerWidth - 18;
        }
        return width;
    }

    function getViewportHeight () {
        var height = 0;
        if( document.documentElement && document.documentElement.clientHeight ) {
            height = document.documentElement.clientHeight;
        }
        else if( document.body && document.body.scrollHeight ) {
            height = document.body.scrollHeight;
        }
        else if( window.innerHeight ) {
            height = window.innerHeight - 18;
        }
        return height;
    }
   
    function getViewportScrollX() {
        var scrollX = 0;
        if( document.documentElement && document.documentElement.scrollLeft ) {
            scrollX = document.documentElement.scrollLeft;
        }
        else if( document.body && document.body.scrollLeft ) {
            scrollX = document.body.scrollLeft;
        }
        else if( window.pageXOffset ) {
            scrollX = window.pageXOffset;
        }
        else if( window.scrollX ) {
            scrollX = window.scrollX;
        }
        return scrollX;
    }

    function getViewportScrollY() {
        var scrollY = 0;
        if( document.documentElement && document.documentElement.scrollTop ) {
            scrollY = document.documentElement.scrollTop;
        }
        else if( document.body && document.body.scrollTop ) {
            scrollY = document.body.scrollTop;
        }
        else if( window.pageYOffset ) {
            scrollY = window.pageYOffset;
        }
        else if( window.scrollY ) {
            scrollY = window.scrollY;
        }
        return scrollY;
    }

function newWindow2(foto)
 {
  bg    = document.getElementById('box_image_bg');
  image = document.getElementById('box_image');
  bg.style.width   = getViewportWidth(); 
  bg.style.height  = getViewportHeight();
  image.style.width= getViewportWidth();
//  bg.style.-moz-opacity: 0.8;
  
  image.onclick = function ()
   {
    bg.style.width='0px';
    bg.style.height='0px';
    this.style.width='0px';
    this.innerHTML='';   
   }
  
   if (window.innerHeight) 
    h = window.innerHeight;
   else
    h=document.body.offsetHeight;
    
  imgload=document.createElement('img');
  imgload.src=foto;
  imgload.alt='nieprawidłowy link do zdjęcia';
  imgload.style.marginTop='15px';
  imgload.onload = function ()
   {
    inner ='<table style="margin-top:'+(getViewportScrollY())+';"><tr><td style="background:none;height:'+h+'">';
    inner+='<table>';
    inner+='<tr><td style="width:15px;"></td>';
    inner+='<td>';
     inner+='<table>';
     inner+='<tr><td id="image_destination"></td></tr>';
     inner+='<tr><td style="height:30px;">Zamknij</td></tr>';
     inner+='</table>';
    inner+='</td>';
    inner+='<td style="width:15px;"></td></tr>';
    inner+='</table>';
    inner+='</td></tr></table>'
    image.innerHTML=inner;
    document.getElementById('image_destination').appendChild(imgload);
   } 
 }
