
var undefined;


/*
 *  Returns TRUE if p_var is not set or if it's an empty string
 *
 *  2006-08-18, Dan Bettles, Created
 */
function isBlank (p_var)
{
    var varIsBlank = false;

    if ((p_var == null)
    || ((p_var['toString'] != undefined) && (p_var == '')))
        varIsBlank = true;

    return varIsBlank;
}



/*
 *  Saves some typing
 *
 *  2006-08-16, Dan Bettles, Created
 */
function getElement (p_id)
{
    return document.getElementById (p_id);
}



/**
 * 2006-03-08   Dan Bettles     Created
 */
function openPlainWindow (p_url, p_width, p_height)
{
    var oWindow = null;

    if (p_url && ! isBlank (p_url)) {
        var windowFeatures = '';

        if ((p_width && (p_width > 0)) || (p_height && (p_height > 0))) {
            var outerWidth = p_width || 100;  /* Defaults */
            var outerHeight = p_height || 100;
            windowFeatures = 'width=' + outerWidth + ',height=' + outerWidth + ',';
        }

        windowFeatures = windowFeatures + 'location=no,menubar=no,directories=no,toolbar=no,status=no,resizable=yes,scrollbars=yes,';
        var oDate = new Date();
        var winName = 'plainWindow_' + oDate.getTime();
        var oWindow = window.open (p_url, winName, windowFeatures);
    }

    return oWindow;
}



/*
 *  Cross-browser DOM-element factory.  Allows you to create an element with
 *  zero or more attributes and then append it to a node, all in one go.
 *
 *  Reference:
 *  http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/
 *  http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp
 *  http://cf-bill.blogspot.com/2006/03/another-ie-gotcha-dynamiclly-created.html
 *
 *  2006-08-20, Dan Bettles, Created
 */

function createElement (p_name, p_oAttr)
{
    var oElement = null;

    try
    {
        var attributes = '';

        if (p_oAttr instanceof Object)
        {
            for (var attrName in p_oAttr)
            {
                attributes += ' '+attrName+'="'+p_oAttr[attrName]+'"';
            }
        }

        oElement = window.document.createElement ('<'+p_name+attributes+'>');

        if (! oElement)  oElement = null;
    }
    catch (oException) {}

    if (! oElement)
    {
        oElement = window.document.createElement (p_name);

        if (p_oAttr instanceof Object)
        {
            for (var attrName in p_oAttr)
            {
                oElement.setAttribute (attrName, p_oAttr[attrName]);
            }
        }
    }

    return oElement;
}

function appendElement (p_oNode, p_name, p_oAttr)
{
    var oElement = createElement (p_name, p_oAttr);
    p_oNode.appendChild (oElement);
    return oElement;
}



/*
 *  Appends an element p_elementName containing p_text
 *
 *  2006-08-25, Dan Bettles, Created
 */
function appendWithText (p_oNode, p_elementName, p_text, p_oAttr)
{
    var oElement = null;
    if (! isBlank (p_oNode) && ! isBlank (p_elementName))
    {
        var oElement = appendElement (p_oNode, p_elementName, p_oAttr);

        /*
         *  Another fix for IE
         */
        if (oElement.canHaveChildren == null || oElement.canHaveChildren)
            oElement.appendChild (document.createTextNode (p_text));
        else
            oElement.text = p_text;
    }
    return oElement;
}


/* Source: http://www.quirksmode.org/js/cookies.html */

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		// Unless the expiry date is set, the cookie is trashed when the browser
		// is closed
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}



function setFormValues()
{
    var username = readCookie ('username');
    var password = readCookie ('password');

    if (username)
    {
        document.getElementById('username').value = username;
        document.getElementById('password').value = password;
    }

    return true;
}

function saveFormValues()
{
    if (document.getElementById('pleaseRememberMe').checked)
    {
        var timeToLive = 365;

        createCookie ('username'
                     ,document.getElementById('username').value
                     ,timeToLive);

        createCookie ('password'
                     ,document.getElementById('password').value
                     ,timeToLive);
    }

    return true;
}

function displayCookieControl()
{
    document.write ('<div><label for="pleaseRememberMe">Please remember me</label></div>' +
                    '<div><input class="Checkbox" id="pleaseRememberMe" type="Checkbox" name="pleaseRememberMe" /></div>');
}