
var _previousColor = null;


function igGetElement(name)
{
    var obj = null;

    var doc = document;

    if (!doc && window.document)
    {
        doc = window.document;
    }

    if (doc.getElementById)
    {
        obj = doc.getElementById(name);
    }
    else if (doc.all)
    {
        obj = doc.all[name];
    }

    return obj;
}

function igCountChecked(checkBoxID)
{
    var count = 0;

    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
        var elm = document.forms[0].elements[i];

        if (elm.type == 'checkbox')
        {
            var ids = elm.id.split('_');

            if (ids[ids.length - 1] == checkBoxID && !elm.disabled && elm.checked)
            {
                count += 1;
            }
        }
    }

    return count;
}

function igOpenWindow(url, name, limited)
{
    var limits = '';
    if (limited)
    {
        limits = 'status = 0, height = 600, width = 900, resizable = 1, scrollbars = 1';
    }
    var w = window.open(url, name, limits);
    if (window.focus)
    {
        w.focus();
    }
    return w;
}

function igTextCounter(txt, displayCount, maxlimit)
{
    var len = txt.value.length;

    if (txt > maxlimit) /* if too long...trim it! */
    {
        txt.value = txt.value.substring(0, maxlimit);
    }
    else
    {
        var text = len + '';
        /* otherwise, update 'characters left' counter */
        if (displayCount.value)
        {
            displayCount.value = text;
        }
        else
        {
            displayCount.innerHTML = text;
        }
    }
}

// To use, simple do: igGetCookie('cookieNm');
// replace cookieNm with the real cookie name, '' are required
function igGetCookie(cookieToGet)
{
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var allCookies = document.cookie.split(';');
    var tempCookie = '';
    var cookieNm = '';
    var cookieValue = '';

    for (i = 0; i < allCookies.length; i++)
    {
        // now we'll split apart each name=value pair
        tempCookie = allCookies[i].split('=');

        // and trim left/right whitespace while we're at it
        cookieNm = tempCookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed cookieToGet
        if (cookieNm == cookieToGet)
        {
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (tempCookie.length > 1)
            {
                cookieValue = unescape(tempCookie[1].replace(/^\s+|\s+$/g, ''));
            }

            // note that in cases where cookie is initialized but no value, null is returned
            return cookieValue;
        }

        tempCookie = null;
        cookieNm = '';
    }

    return null;
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expiresTime will make the
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function igSetCookie(name, value, expiresTime, path, domain, secure)
{
    // set time, it's in milliseconds
    var today = new Date();

    today.setTime(today.getTime());

    // if the expiresTime variable is set, make the correct expiresTime time, the
    // current script below will set it for x number of days, to make it
    // for hours, delete * 24, for minutes, delete * 60 * 24
    if (expiresTime)
    {
        expiresTime = expiresTime * 1000 * 60 * 60 * 24;
    }

    //alert('today ' + today.toGMTString());// this is for testing purpose only
    var expiresDate = new Date(today.getTime() + (expiresTime));
    //alert('expiresTime ' + expiresDate.toGMTString());// this is for testing purposes only

    document.cookie = name + "=" + escape(value) +
		((expiresTime) ? ";expiresTime=" + expiresDate.toGMTString() : "") + //expiresTime.toGMTString()
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
}

// this deletes the cookie when called
function igDeleteCookie(name, path, domain)
{
    if (igGetCookie(name))
    {
        document.cookie = name + "=" +
	    ((path) ? ";path=" + path : "") +
			((domain) ? ";domain=" + domain : "") +
			";expiresTime=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}
