﻿/*
Name:     egglib.js
Creation: 10-05-2006
LastEdit: 26-09-2006
Author:   Egbert van der Haring
Remarks:  library of useful functions for interbrowser compatibility
*/

// returns true for IE
function isIE()
{
    var client = navigator.userAgent.toLowerCase();
    return (client.indexOf("msie") != -1);
}

// returns last index of char in string
function lastIndexOf(str, ch)
{
    var nIndex = str.length;
    do
    {
        nIndex -= 1;
    } while ((str.charAt(nIndex) != ch) && (nIndex > 0));
    if (nIndex > 0)
    {
        nIndex += 1;
    }
    return nIndex;
}

// returns keycode for event
function getEventKey(e)
{
    return e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
}

// returns available height in browser client window
// input: nTop is already used number of pixels
function getAvailHeight(nTop)
{
    var nHeight = window.screen.availHeight - nTop;
    if (typeof(window.screenTop) != 'undefined')
    {
        nHeight -= window.screenTop;
    }
    else
    {
        nHeight -= 120;
    }
    return nHeight+"px";
}

// closes browser window
// NB: set in document.body.onload to close
function closeBrowser()
{
    var win = top;
    win.opener = top;
    win.close();
}
