
confirmation = "";

function setConfirmation(text)
{
    confirmation = text;
}

function getConfirmation()
{
    return confirmation;
}

function confirmAction(confirmText)
{
    conf = getConfirmation();

    if (conf.length > 0)
    {
        setConfirmation("");
        rc = confirm(conf);
    }
    else
    {
        rc = true;
    }

    return rc;
}

function clickmenubutton(menuFrame, buttonId)
{
    if (buttonId != "" &&
        (f = top.frames[menuFrame]) != null &&
        f.simclick != null)
    {
        f.simclick(f.document.images[buttonId]);
    }

}

function checkAppletVersion(productname,name,version)
{
    appletversion =  document.applets[name].version;

    if (typeof appletversion == 'undefined')
    {
        appletversion = javaobjecttostring(document.applets[name].GetVersion());
    }

    if (appletversion != version && !top.appletReloading)
    {
        top.appletReloading = true;
        if (confirm("Your cached copy of the " + productname + " Java applets are out of date.\nPress OK to obtain the latest code"))
        {
            top.location.reload(true);
        }
    }
}

function tellMasterClose(masterWindowName, clientWindowName, confirmMsg)
{
    if (checkUnsavedChanges(clientWindowName, confirmMsg))
    {
        if (top.getMasterURL)
        {
            mURL = top.getMasterURL();
            top.frames[masterWindowName].location = mURL + '?action=dialogclose';
        }
    }
}

function loadmessage(walkToTop, clientWindowName, reloadmessage, windowReloadRequired, charset, headerText, bodyText, attachmentsText)
{
    if (walkToTop)
    {
        t = crawltotop();
    }
    else
    {
        t = top;
    }

    w = t.frames[clientWindowName];

    if (!w ||
        !(v = w.frames["viewer"]) ||
        !(h = v.frames["header"]) ||
        !(a = v.frames["attachments"]) ||
        !(m = v.frames["message"]))
    {
        headerText = headerText.replace(/\n/g, '');
        bodyText = bodyText.replace(/\n/g, '');
        attachmentsText = attachmentsText.replace(/\n/g, '');

        command = "loadmessage(" + walkToTop + ", '" + clientWindowName + "', " + reloadmessage + ", " + windowReloadRequired + ", '" + charset + "', '" + headerText + "', '" + bodyText + "', '" + attachmentsText + "')";

        setTimeout(command ,100);
    }
    else
    {

        t.msgframecharset = charset;

        header = h.document;

        header.open();
        header.write(headerText);
        header.close();

        if (reloadmessage)
        {
            windowLocation(m, '/webmail/mail/message.mml', windowReloadRequired);
        }
        else
        {
            message = m.document;

            message.open();
            message.write(bodyText);
            message.close();
        }

        attachments = a.document;

        attachments.open();
        attachments.write(attachmentsText);
        attachments.close();


    }
}

function loadsummary(walkToTop, clientWindowName, headerText, bodyText, attachmentsText)
{
    if (walkToTop)
    {
        w = crawltotop();
    }
    else
    {
        w = top;
    }

    w = w.frames[clientWindowName];

    if (!w ||
        !(v = w.frames["viewer"]) ||
        !(h = v.frames["header"]) ||
        !(a = v.frames["attachments"]) ||
        !(s = v.frames["summary"]))
    {
        headerText = headerText.replace(/\n/g, '');
        bodyText = bodyText.replace(/\n/g, '');
        attachmentsText = attachmentsText.replace(/\n/g, '');

        command = "loadsummary(" + walkToTop + ", '" + clientWindowName + "', '" + headerText + "', '" + bodyText + "', '" + attachmentsText + "')";

        setTimeout(command,100);
    }
    else
    {
        header = h.document;

        header.open();
        header.write(headerText);
        header.close();

        summary = s.document;

        summary.open();
        summary.write(bodyText);
        summary.close();

        attachments = a.document;

        attachments.open();
        attachments.write(attachmentsText);
        attachments.close();
    }
}

function refreshmail(clientFrame, menuFrame, buttonId)
{
    clickmenubutton(menuFrame, buttonId);

    w = crawltotop();

    value = 0;

    if (w.autocompleteinit)
    {
        value = 1;
    }

    sm = "";

    cf = top.frames[clientFrame];

    if (cf)
    {
        sf = cf.frames["selector"];

        if (sf)
        {
            if ((t = sf.document.mailtable))
            {
                sm  = javaobjecttostring(t.getSelectedValues(true));
            }
        }
    }

    uvs = '/webmail/masterwindow.mml?action=refreshtimer';
    uvs += '&autocompleteinit=' + value;
    uvs += "&SelectedMsg=" + sm;

    location = uvs;
}

function doShowMessage(target, m, colour)
{
    doc = top.frames[target].document;

    doc.open();
    doc.write("<body bgcolor=" + colour + " leftmargin=3>");
    doc.write("<table width=100% cellspacing=0>");
    doc.write("<tr><td width=1%><img src='/i/webmail/messagebar/info.gif'></font></td><td><font face=arial size=1>" + m + "</font></td></tr>");
    doc.write("</table></body>");
    doc.close();
}

function closeattachwindow(target)
{
    top.frames[target].attachwindow.close();
}

function pressGif(image,state)
{
    gifname = image.src;

    fileroot_start = gifname.lastIndexOf("/") + 1;
    fileroot_end   = gifname.lastIndexOf("_");
    fileroot = gifname.substring(fileroot_start,fileroot_end);
    image.src = "/i/webmail/forms/" + fileroot + "_" + state + ".gif";
}

