var oPreviewDiv;
var oPreviewImg;

function preview(url)
{
    if (url == null)
    {
        document.body.removeChild(oPreviewDiv);
        document.body.removeChild(oPreviewImg);
        
        return true;
    }
    
    oPreviewDiv = document.createElement("div");
    
    oPreviewDiv.onclick = function () {preview()};
    
    oPreviewDiv.style.opacity=".5";
    oPreviewDiv.style.filter="alpha(opacity=50)"
    oPreviewDiv.style.position="absolute";
    oPreviewDiv.style.left=0;
    oPreviewDiv.style.top=0;
    oPreviewDiv.style.width="100%";
    oPreviewDiv.style.height="100%";
    oPreviewDiv.style.backgroundColor="#000000";
    oPreviewDiv.style.textAlign = "center";
    oPreviewDiv.style.cursor = "pointer";
    
    oPreviewImg = document.createElement("img");
    
    oPreviewImg.onclick = function () {preview()};
    oPreviewImg.onload = function ()
    {
        if (document.all)
            this.style.display = "block";
        
        this.style.top = (document.documentElement.scrollTop + (document.body.offsetHeight - this.height) / 2) + "px";
        this.style.left = (document.documentElement.scrollLeft + (document.body.offsetWidth - this.width) / 2) + "px";
        
        if (! document.all)
            this.style.display = "block";
    };
    
    oPreviewImg.style.position="absolute";
    oPreviewImg.style.display = "none";
    oPreviewImg.style.left=0;
    oPreviewImg.style.top=0;
    oPreviewImg.style.cursor = "pointer";
    
    oPreviewImg.src = url;
    
    document.body.appendChild(oPreviewDiv);
    document.body.appendChild(oPreviewImg);
    
    return true;
}