var max_inline_attachment_width = 0;

// Fallback mechanism in case GD is not available for determining
// the image size. This will cause some flashing on the screen though,
// because the resizing is done after the image has been loaded.
function in_body_attachments_resizeimage(img)
{
    if (max_inline_attachment_width && img.width>max_inline_attachment_width) {
        img.width = max_inline_attachment_width;
    }
}

function create_inline_link(id,fn) 
{
    fn = unescape(fn);
    var attlink = '[attachment ' + id + ' ' + fn + ']';

    // Find the textarea. Multiple cases for backward compatibility.
    var area = document.getElementById("phorum_textarea");
    if (! area) {
        area = document.getElementById("body");
    }
    
    if (area) 
    {
        if (area.createTextRange) /* MSIE */
        {
            area.focus(area.caretPos);
            area.caretPos = document.selection.createRange().duplicate();
            curtxt = area.caretPos.text;
            area.caretPos.text = attlink + curtxt;
        } 
        else /* Other browsers */
        {
            var pos = area.selectionStart;              
            area.value = 
                area.value.substring(0,pos) + 
                attlink +
                area.value.substring(pos);
            area.focus();
            area.selectionStart = pos + attlink.length;
            area.selectionEnd = area.selectionStart;
        }
    } else {
        alert('There seems to be a technical problem. The textarea ' +
              'cannot be found in the page. ' +
              'The textarea should have id="body" in the ' +
              'definition for this feature to be able to find it. ' +
              'If you are not the owner of this forum, then please ' +
              'alert the forum owner about this.');
    }
}

