var imageRelation=
{
    open: function( url, attributeID )
    {
        var width = 900;
        var height = 600;
        var winName = 'imagerelation_' + attributeID;

        url += '/' + document.getElementById( 'imagerelation-data-' + attributeID ).value;

        var sx = screen.width / 2 - width / 2;
        var sy = screen.height / 2 - height / 2;
        var win = window.open( url, winName, 'width=' + width + ',height=' + height + ',location=0,scrollbars=1,menu=0,status=0,titlebar=0,title=0,toolbar=0,screenx='
            + sx +',left=' + sx + ',screeny=' + sy + ',top=' + sy );

        return ( win )? false: true;
    },

    select: function( attributeID, objectID, nodeID, name )
    {
        if ( window.opener )
        {
            window.opener.document.getElementById( 'imagerelation-data-' + attributeID ).value = objectID;
            window.opener.document.getElementById( 'imagerelation-name-' + attributeID ).innerHTML = name;
            window.opener.document.getElementById( 'imagerelation-thumbnail-' + attributeID ).innerHTML = document.getElementById( 'imagerelation-thumbnail-node-' + nodeID ).innerHTML;

            var removeButton = window.opener.document.getElementById( 'imagerelation-remove-' + attributeID );
            removeButton.className = 'button';
            removeButton.disabled = false;
        }

        window.close();
    },

    clear: function( attributeID )
    {
        // TODO: ask for confirmation?
        document.getElementById( 'imagerelation-data-' + attributeID ).value = 0;
        document.getElementById( 'imagerelation-name-' + attributeID ).innerHTML = 'No associated image';
        document.getElementById( 'imagerelation-thumbnail-' + attributeID ).innerHTML = '&nbsp;';

        var removeButton = document.getElementById( 'imagerelation-remove-' + attributeID );
        removeButton.className = 'button-disabled';
        removeButton.disabled = true;

        return false;
    }
}
