var images_manager_handle;

function redirect(url)
{
    setTimeout('document.location.href = "'+url+'"', 3000);
}

function manage_images(theform)
{
    height = 600;
    width = 800;

    if (typeof(theform.id.value) != 'undefined')
    {
        url = ROOT + '/image.php?publication_id=' + theform.id.value;
    }
    else
    {
        url = ROOT + '/image.php?start_time=' + theform.start_time.value + '&post_hash=' + theform.post_hash.value;
    }

    images_manager_handle = window.open(url, 'ImagesManager', 'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
	return false;
}

function close_images()
{
	images_manager_handle.close();
    return true;
}

function image(id)
{
    theform = opener.document.publication;
    theform.content.value += '[IMG]'+id+'[/IMG]\n';
    theform.content.focus();
    top.opener.focus();
}

function smilie(code)
{
    if (typeof(opener.document.publication) != 'undefined')
    {
        theform = opener.document.publication;
    }
    else if (typeof(opener.document.comment) != 'undefined')
    {
        theform = opener.document.comment;
    }
    else
    {
        theform = opener.document.comment_edit;
    }

    theform.content.value += code+' ';
    theform.content.focus();
    top.opener.focus();
}

function show_help(action)
{
    window.open(ROOT + '/help.php?action=' + action, 'Helper', 'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=700,height=600');
}

function show_smilies()
{
    window.open(ROOT + '/smilies.php', 'Smilies', 'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=300');
}

function show_preview(text)
{
    var form_source = '<form id="dummy_form" name="dummy_form" action="'+ROOT+'/publication.php?action=preview" method="post" target="preview">'+
        '<input type="hidden" name="content" />'+
        '</form>';

    var dummy = document.getElementById('dummy');
    dummy.innerHTML = form_source;

    var theform = document.getElementById('dummy_form');
    theform.content.value = text;
    window.open('', 'preview', 'statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=300');
    theform.submit();
}