function CleanWhitespace(node)
{
    /* http://www.dustindiaz.com/easier-dom-walking-with-cleanwhitespace/ */
    var notWhitespace = /\S/;

    for (var x = 0; x < node.childNodes.length; x++)
    {
        var childNode = node.childNodes[x];
        if ((childNode.nodeType == 3) && (!notWhitespace.test(childNode.nodeValue)))
        {
            node.removeChild(node.childNodes[x]);
            x--;
        }
        if (childNode.nodeType == 1)
        {
            CleanWhitespace(childNode);
        }
    }
}

function CreateRequest()
{
    var request = null;

    try
    {
        request = new XMLHttpRequest();
    }
    catch (trymicrosoft)
    {
        try
        {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (othermicrosoft)
        {
            try
            {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (failed)
            {
                request = null;
            }
        }
    }

    return request;
}

function EmptyNode(elementName)
{
    var nodeToEmpty = document.getElementById(elementName);
    if (nodeToEmpty != null)
    {
        while (nodeToEmpty.firstChild)
            nodeToEmpty.removeChild(nodeToEmpty.firstChild);
    }
}

function RemoveNode(elementName)
{
    var nodeToRemove = document.getElementById(elementName);
    if (nodeToRemove != null)
    {
        if (nodeToRemove.parentNode != null)
            nodeToRemove.parentNode.removeChild(nodeToRemove);
    }
}

function Trim(input)
{
    return input.replace(/^\s+|\s+$/g, '');
}