﻿function gw$(o)
{
    if (o.substring)
    {
        return document.getElementById(o);
    }
    else
    {
        return o;
    }
};

function showError(e)
{
    if (e.substring)
    {
        alert(e);
    }
    else if (e.message)
    {
        alert(e.message);
    }
    else
    {
        alert("An unknown error occurred.");
    }
};

function showAjaxError()
{
    showError(new Error('An error occurred while communicating with the server.  Please refresh the page and try again.'));
};

function clearList(list)
{
    list.options.length = 0;
};

function getListValue(o)
{
    o = gw$(o);
    return o.options[o.selectedIndex].value;
};

function addListItem(list, val, text)
{
    var opt = document.createElement('option');
    opt.value = val;
    opt.text = text;
    list.options[list.options.length] = opt;
};

function newGuid()
{
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()).toUpperCase();
};

function S4()
{
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};