function alertuser(msg)
{
    alert(msg);
}

function confirmuser(msg)
{
    return confirm(msg);
}

function urlencode(str)
{
    encodeStr = escape(str).replace(/\+/g, "%2b");
    return encodeStr;
}

function urldecode(str)
{
    decodeStr = unescape(str.replace(/\+/g, " "));
    return decodeStr;
}

function arraypush(a,o)
{
    a[a.length] = o;
}

function arraypop(a)
{
    o = a[a.length - 1];

    a.length = a.length - 1;

    return o;
}

function arraypeek(a,i)
{
    return a[i];
}

hexVals = "0123456789abcdef";

function toHex(val)
{
    r = val % 16
    l = (val - r) / 16;

    hexVal = hexVals.charAt(l) + hexVals.charAt(r);

    return hexVal;
}

function launchURL(field)
{
    if (document.clientform.elements[field].value != "")
    {
        window.open(document.clientform.elements[field].value);
    }
}

function selectoptionfind(a,s)
{
    len = a.length;
    for (i = 0; i < len; i++)
    {
        if (a[i].value == s)
        {
            return i;
        }
    }

    return -1;
}

function gettop(w)
{
    if (!w.webmailtopwindow)
    {
        w = w.parent;

        if (!w.webmailtopwindow)
        {
            w = w.top;
        }
    }

    return w;
}

function switchbutton(target, name, disabled)
{
    switchbuttonex(target, "clientform", name, disabled)
}

function switchbuttonex(target, targetform, name, disabled)
{
    w = gettop(this);

    if ((f = w.frames[target]) && (c = f.document.forms[targetform]))
    {
        if ((b = c.elements[name]))
        {
            b.disabled = disabled;
        }

        if ((b = c.elements['alt_' + name]))
        {
            b.disabled = disabled;
        }
    }
}

function javaobjecttostring(javaobject)
{
    if (javaobject == null)
    {
        str = "";
    }
    else
    {
        str = javaobject + "";
    }

    return str;
}

function crawltotop()
{
    w = top;

    while (!w.webmailtopwindow && w.opener && !w.opener.closed)
    {
        w = w.opener.top;
    }

    return w;
}

function savechildwindow(walkToTop, windowHandle)
{
    if (walkToTop)
    {
        w = crawltotop();
    }
    else
    {
        w = gettop(this);
    }

    arraypush(w.openedwindows, windowHandle);
}

function handleUnload()
{
    closechildwindows("");
}

function closechildwindows(promptStr)
{
    windowsClosed = false;

    w = gettop(this);

    if (w.openedwindows)
    {
        closeWindows = true;

        if (promptStr != "")
        {
            promptRequired = false;

            id = 0;

            while (id < w.openedwindows.length)
            {
                child = arraypeek(w.openedwindows, id);

                if (child && !child.closed)
                {
                    if (child.webmailpromptclose && !child.webmailkeepopen)
                    {
                        promptRequired = true;
                    }
                }

                id++;
            }

            if (promptRequired)
            {
                closeWindows = confirm(promptStr);
            }
        }

        if (closeWindows)
        {
            windowsClosed = true;

            while (w.openedwindows.length != 0)
            {
                child = arraypop(w.openedwindows);

                if (child && !child.closed && !child.webmailkeepopen)
                {
                    child.close();
                }
            }
        }
    }

    return windowsClosed;
}

function reloadchildwindows()
{
    w = gettop(this);

    if (w.openedwindows)
    {
        id = 0;

        while (id < w.openedwindows.length)
        {
            child = arraypeek(w.openedwindows, id);

            if (child && !child.closed)
            {
                promptRequired = false;

                if (child.webmailpromptclose && !child.webmailkeepopen)
                {
                    promptRequired = true;
                }

                if (!promptRequired)
                {
                    child.location.reload();
                }
            }

            id++;
        }
    }
}

function loadbuttons(framename, gDir, lDir, hole_src, str)
{
    doc = top.frames[framename].document;

    btns = str.split("|");
    count = btns.length;

    for (i = 0; i < count; i = i + 3)
    {
        index = btns[i];
        gifname = btns[i + 1];
        buttonname = btns[i + 2];

        buttonindexname = "b_" + index;

        ele = doc.images[buttonindexname];

        if (ele)
        {
            ugDir = gDir;
            ulDir = lDir;

            if (gifname == '')
            {
                ugDir = '';
                ulDir = '';

                gifname = hole_src;
            }

            loadgif(ele, ugDir, ulDir, gifname, buttonname);
        }
    }
}

function loadgif(button, gifDir, langGifDir, url, altText)
{
    baseUrl = window.location.protocol + '//' + window.location.host;

    dir = langGifDir;

    if (url.charAt(0) == "~")
    {
        url = url.substring(1);
        dir = gifDir;
    }

    if (dir != "")
    {
        url = dir + url;
    }

    url = baseUrl + url;

    if (button.src != url)
    {
        button.src = url;
    }

    if (button.alt != altText)
    {
        button.alt = altText;
    }
}

function closeme(target,window,action)
{
    closechildwindows("");

    t = gettop(this);
    o = t.opener;

    if (o && !o.closed)
    {
        o.focus();

        w = gettop(o);

        if (w)
        {
            f = null;

            c = w.frames[target];

            if (c)
            {
                f = c.childclosed
            }

            if (f == null)
            {
                f = w.childclosed
            }

            if (f != null)
            {
                f(window,action);
            }
        }
    }

    t.close();
}

function lsfind(instring,findstring,sep)
{
    found = false;

    if (instring.length)
    {
        strings = instring.split(sep);
        len = strings.length;

        for (ix = 0; (ix < len) && !found; ix++)
        {
            found = (strings[ix] == findstring);
        }
    }

    if (found)
    {
        rc = ix;
    }
    else
    {
        rc = 0;
    }

    return rc;
}

function lsremove(instring,findstring,sep)
{
    newstring = "";

    if (instring.length)
    {
        strings = instring.split(sep);
        ln = strings.length;

        for (ix = 0; ix < ln; ix++)
        {
            if (strings[ix] != findstring)
            {
                newstring = newstring + strings[ix] + sep;
            }
        }

        ln = newstring.length;
        if (newstring.charAt(ln -1) == ",")
        {
            newstring = newstring.substring(0,ln -1);
        }
    }

    return newstring;

}

function getDocumentElementById(d, id)
{
    e = null;

    if (d.getElementById)
    {
        e = d.getElementById(id);
    }
    else if (d.all)
    {
        e = d.all[id];
    }

    return e;
}

function getDocumentElementYPos(d, id)
{
    curtop = 0;

    obj = getDocumentElementById(d, id);

    if (obj)
    {
        if (obj.offsetParent)
        {
            while (obj.offsetParent)
            {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
    }

    return curtop;
}

function getDocumentElementHeight(d, id)
{
    objHeight = 0;

    obj = getDocumentElementById(d, id);

    if (obj)
    {
        objHeight = obj.offsetHeight;
    }

    return objHeight;
}

function getnamedchildwindow(walkToTop, windowName)
{
    if (walkToTop)
    {
        w = crawltotop();
    }
    else
    {
        w = top;
    }

    id = 0;

    while (id < w.openedwindows.length)
    {
        child = arraypeek(w.openedwindows, id);

        if( child && !child.closed && child.name == windowName )
        {
            return child;
        }

        id++;
    }

    return null;
}

function settabindex(field, index)
{
    if (f = document.clientform[field])
    {
        f.tabIndex = index;
    }
}

function checkurllength(urllength, maxurllength)
{
    ok = false;

    if (maxurllength == -1)
    {
        ok = true;
    }
    else if (urllength <= maxurllength)
    {
        ok = true;
    }

    return ok;
}

function setAllButtonsEnabled(formWindow, formName, enabled)
{
    if ((bf = top.frames[formWindow]) &&
        (c = bf.document.forms[formName]))
    {
        for (var i = 0; i < c.elements.length; i++)
        {
            if (c.elements[i].type == 'submit')
            {
                c.elements[i].disabled = !enabled;
            }
        }
    }
}

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 trim(totrim, trimcharacters)
{
    return trimEx(totrim, trimcharacters, true, true);
}

function trimEx(totrim, trimcharacters, trimleft, trimright)
{
    k = 0;

    if (trimleft)
    {
        while (k < totrim.length && trimcharacters.indexOf(totrim.charAt(k)) != -1)
        {
            k = k + 1;
        }
    }

    startIndex = k;

    k = totrim.length;

    if (trimright)
    {
        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);
}
