function trim(totrim, trimcharacters)
{
    k = 0;

    while (k < totrim.length && trimcharacters.indexOf(totrim.charAt(k)) != -1)
    {
        k = k + 1;
    }

    startIndex = k;

    k = totrim.length;

    while (k > 0 && trimcharacters.indexOf(totrim.charAt(k - 1)) != -1)
    {
        k = k - 1;
    }

    endIndex = k;

    if (startIndex >= endIndex)
    {
        endIndex = startIndex;
    }

    return totrim.substring(startIndex,endIndex);
}

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 tokenizer(str,delim)
{
    values = new Array();

    inQuotes = false;
    index = 0;
    startindex = 0;

    while (index < str.length)
    {
        c = str.charAt(index);

        if (!inQuotes)
        {
        if (c == '"')
        {
            inQuotes = true;
        }
        else if (delim.indexOf(c) != -1)
        {
            newvalue = str.substring(startindex, index);
            arraypush(values, newvalue);

            startindex = index + 1;
        }
        }
        else
        {
        if (c == '"')
        {
            inQuotes = false;
        }
        }

        index++;
    }

    newvalue = str.substring(startindex, index);
    arraypush(values, newvalue);

    return values;
}

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, 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"]) ||
        !(m = v.frames["message"]))
    {
        command = 'loadmessage(' + walkToTop + ', "' + clientWindowName + '", "' + headerText + '", "' + bodyText + '", "' + attachmentsText + '")';
        setTimeout(command ,100);
    }
    else
    {
        header = h.document;

        header.open();
        header.write(headerText);
        header.close();

        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 = top.frames[clientWindowName];

    if (!w ||
        !(v = w.frames["viewer"]) ||
        !(h = v.frames["header"]) ||
        !(a = v.frames["attachments"]) ||
        !(s = v.frames["summary"]))
    {
        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(menuFrame, buttonId)
{
    clickmenubutton(menuFrame, buttonId);
    location = '/webmail/masterwindow.mml?action=refreshtimer';
}

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();
}



