function alertuser(msg)
{
    alert(msg);
}

function confirmuser(msg)
{
    return confirm(msg);
}

function lighturlencode(str)
{
    encodeStr = (str.replace(/\&/g, "%26")).replace(/\+/g, "%2b");

    return encodeStr;
}

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)
{
    w = gettop(this);

    if ((f = w.frames[target]) && (c = f.document.clientform))
    {
        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 loadgif(button, gifDir, langGifDir, url, altText)
{
    dir = langGifDir;

    if (url.charAt(0) == "~")
    {
        url = url.substring(1);
        dir = gifDir;
    }

    if (dir != "")
    {
        url = dir + 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;
}

