var enlargedImageTestLoader = new Image();
var enlargeImageTextPopupLink;
var enlargeImageTextPopupLinkStatic;
var nonHyperlinkedPackshot;
var hyperlinkedPackshot;

// Check to see if the enlarged packshot exists
function CheckEnlargedPackshotExists(imagesrc, enlargeImageTextLinkControlId, nonHyperlinkedPackshotControlId, hyperlinkedPackshotControlId)
{
    enlargeImageTextPopupLink = document.getElementById(enlargeImageTextLinkControlId);
    enlargeImageTextPopupLinkStatic = document.getElementById('EnlargeImageTextLinkStatic');
    nonHyperlinkedPackshot = document.getElementById(nonHyperlinkedPackshotControlId);
    hyperlinkedPackshot = document.getElementById(hyperlinkedPackshotControlId);

    enlargedImageTestLoader.onerror = EnlargedImageLoadError;    
    enlargedImageTestLoader.onload = EnlargedImageLoadOK;
    enlargedImageTestLoader.src = imagesrc;
   
    return true;
}

// Loading the enlarged image errored
function EnlargedImageLoadError()
{
    //enlargedImageTestLoader = null;

    var visibleElement = '';
    var invisibleElement = 'none';

    // Check we can access them
    if(enlargeImageTextPopupLink != null)
    {
        enlargeImageTextPopupLink.style.display='none';   
    }
    
    if (enlargeImageTextPopupLinkStatic != null)
    {
        enlargeImageTextPopupLinkStatic.style.display='';
    }
    
    if (hyperlinkedPackshot != null)
    {
        hyperlinkedPackshot.style.display='none';
    }
    
    if (nonHyperlinkedPackshot != null)
    {
        nonHyperlinkedPackshot.style.display='';
    }
    
    enlargeImageTextPopupLink = null;
    enlargeImageTextPopupLinkStatic = null;
    hyperlinkedPackshot = null;
    nonHyperlinkedPackshot = null;
    
    return true;
}

// Loading the enlarged image was successful
function EnlargedImageLoadOK()
{
    return true;
}

// View the enlarged version of the image.
function ViewEnlargedImage(mediaId)
{
    var url = '/EnlargedImage.aspx?mid='+mediaId + '&js=1'
    var name = 'EnlargedImage' + mediaId;
    window.open(url, name, 'width=500,height=600, location=0');
    return false;
}

// Can we use javascript to close the popup?
function CanClosePopup()
{
    var closeLink = document.getElementById('ClosePopup');
    if (closeLink != null)
    {
        closeLink.style.visibility='visible';
    }
    return true;
}

// Close the popup
function ClosePopup()
{
    self.close();
    return false;
}