function openImage(img)
{
    img1 = new Image();
    img1.src = (img);
    control(img);
}
function control(img)
{
    if ((img1.width != 0) && (img1.height != 0))
    {
        viewImage(img);
    }
    else
    {
        myFunction = "control('" + img + "')";
        myDelay = setTimeout(myFunction, 20);
    }
}
function viewImage(img)
{
    myWidth = img1.width + 20;
    myHeight = img1.height + 20;
    windowProperties = "width=" + myWidth + ",height=" + myHeight;
    myWindow = window.open(img, "", windowProperties);
}