﻿function $(id)
{
    if (typeof id != 'string')
        return id;
    var obj = document.getElementById ? document.getElementById(id) : document.all[id];
    if (obj == null)
    {
        obj = document.getElementsByName(id);
        if (obj != null)
            obj = obj[0];
    }
    return obj;
}

function $v(id)
{
    var obj = $(id);
    if (obj == null)
        return null;
    if (typeof obj != 'object')
        alert('!' + obj + (typeof obj));
    if (typeof obj.tagName != 'undefined')
        if (obj.tagName == 'INPUT')
            return obj.value;
    if (obj['innerHTML'] != null)
        return obj.innerHTML.replace(/<[^<]*?>/g, '');
    return null;
}

function pageLoaded()
{
    if (typeof startPage == 'function')
        startPage();
}

var eventList;

function logOff()
{
    if (confirm(CONFIRM_LOGOFF))
    	window.location = "logoff.aspx";
}

function NewWindow(mypage, myname, w, h, scroll) 
{
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4) 
        win.window.focus();
}

function popupMessage(width, url) 
{
    w = window.open(url,"popupMessage","width="+width+",height=525,toolbar=no,status=no,resizable=no,scrollbars=yes");
    w.focus();
}

function col( row, colour )
{
    row.style.backgroundColor=colour;
}

function popUp(URL) 
{
	day = new Date();
	id = day.getTime();
	window.open(URL, id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,height=500,width=492'); 
}

function $reloadPage(wnd)
{
    if (wnd == null)
        wnd = window;
    var url = wnd.document.location.href;
    var idx = url.indexOf('?');
    if (idx == -1)
        url += '?';
    else
    {
        var base = url.substring(0, idx);
        var params = url.substring(idx + 1).split('&');
        var params2 = [];
        for (var i = 0; i < params.length; i++)
        {
            var p = params[i];
            if (p.indexOf('_refresh=') == 0)
                continue;
            params2[params2.length] = p;
        }
        url = base;
        if (params2.length > 0)
        {
            url += '?';
            for (var i = 0; i < params2.length; i++)
            {
                if (i > 0)
                    url += '&';
                url += params2[i];
            }
        }
    }
    if (url.indexOf('?') == -1)
        url += '?';
    else
        url += '&';
    url += '_refresh=' + (new Date().getTime());
    wnd.document.location.href = url;
}

    function tryParseFloat(value, defaultValue)
    {
        value = parseFloat(value);
        if (!isNaN(value))
            return value;
        else
            return defaultValue ? defaultValue : null;
    }

    function getFieldValue(id)
    {
        if (document.getElementById)
            return document.getElementById(id).innerHTML;
        else
            return document.all(id).innerHTML;
    }
    
