if(afw === undefined){ var afw = {}; }
afw.common =
{
    addClass : function(oElement, sClassName)
    {
        if(!oElement || sClassName == undefined)
        {
            return false;
        }
        if(!afw.common.classExists(oElement, sClassName))
        {
            if(oElement.className)
            {
                oElement.className += ' ' + sClassName;
            }
            else
            {
                oElement.className = sClassName;
            }
        }
        return true;
    }
    ,addEvent : function(evt, el, fn)
    {
        if(el.addEventListener)
        {
            el.addEventListener(evt, fn, false);
        }
        else if(el.attachEvent)
        {
            return el.attachEvent('on' + evt, fn);
        }
    }
    ,classExists : function(oElement, sClassName)
    {
        if(!oElement || sClassName == undefined)
        {
            return false;
        }
        if(oElement.className.indexOf(' ') > -1)
        {
            var i, m, aClasses = oElement.className.split(' ');
            for(i = 0, m = aClasses.length; i < m; ++i)
            {
                if(aClasses[i] == sClassName)
                {
                    return true;
                }
            }
        }
        else if(sClassName == oElement.className)
        {
            return true;
        }
        return false;
    }
    ,getClientDimensions : function()
    {
        var res =
        {
            width : document.documentElement.scrollWidth
            ,height : document.documentElement.scrollHeight
        };
        return res;
    }
    ,getElementDimensions : function(oElement)
    {
        if(!oElement)
        {
            return false;
        }
        var res = 
        {
            width : oElement.offsetWidth
            ,height : oElement.offsetHeight
        };
        return res;
    }
    ,getElement : function(sId)
    {
        var oReturn = null;
        if(document.getElementById)
        {
            if(document.getElementById(sId))
            {
                oReturn = document.getElementById(sId);
            }
        }
        return oReturn;
    }
    ,initiate : function()
    {
        var i, m, a, params = afw.common.location.search.substring(1).split('&');
        for(i = 0, m = params.length; i < m; ++i)
        {
            a = params[i].split('=');
            if(a[0] == 'pc')
            {
                afw.common.parseLinks('pc');
            }
        }
    }
    ,location : // http://www.alertir.com/index.php?foo=bar&alpha=beta#omega
    {
        hash : window.location.hash // #omega
        ,host : window.location.host // www.alertir.com (or www.alertir.com:81 if port is present)
        ,hostname : window.location.hostname // www.alertir.com
        ,href : window.location.href // complete url
        ,pathname : window.location.pathname // /index.php
        ,port : window.location.port // 81 (if present)
        ,protocol : window.location.protocol // http:
        ,search : window.location.search // ?foo=bar&alpha=beta
    }
    ,parseLinks : function(sAppend, oContainer)
    {
        if(typeof(oContainer) === 'undefined')
        {
            oContainer = document;
        }
        var i, m, search, aLinks = oContainer.getElementsByTagName('A');
        for(i = 0, m = aLinks.length; i < m; ++i)
        {
            if(aLinks[i].host + aLinks[i].pathname == afw.common.location.host + afw.common.location.pathname)
            {
                search = '?' + sAppend + '&' + aLinks[i].search.substring(1);
                aLinks[i].href = aLinks[i].href.replace(aLinks[i].search, search);
            }
        }
    }
    ,randomID : function(sPrefix, iLength)
    {
        if(sPrefix == undefined){ sPrefix = ''; }
        if(iLength == undefined){ iLength = 12; }
        var result = '', i, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''), m = chars.length;
        for(i = 0; i < iLength; ++i)
        {
            if(result === '')
            {
                result += chars[afw.common.randomNumber(10, m - 1)];
            }
            else
            {
                result += chars[afw.common.randomNumber(0, m - 1)];
            }
        }
        return sPrefix + result;
    }
    ,randomNumber : function(min, max)
    {
        if(min == undefined){ min = 1; }
        if(max == undefined){ max = 100; }
        return Math.floor(Math.random() * ((max - min) + 1)) + min;
    }
    ,removeClass : function(oElement, sClassName)
    {
        if(!oElement || sClassName == undefined)
        {
            return false;
        }
        var i, m, sNewClasses = '', sClasses = oElement.className;
        if(sClasses.indexOf(' ') != -1)
        {
            var aClasses = sClasses.split(' ');
            for(i = 0, m = aClasses.length; i < m; ++i)
            {
                if(aClasses[i] != sClassName)
                {
                    sNewClasses += ' ' + aClasses[i];
                }
            }
            sNewClasses = (sNewClasses.length > 0 ? sNewClasses.substring(1) : '');
        }
        else
        {
            if(sClasses != sClassName)
            {
                sNewClasses = sClasses;
            }
        }
        oElement.className = sNewClasses;
        return true;
    }
    ,setOpacity : function(o, i)
    {
        o.style.opacity = i / 100;
        o.style.filter = 'alpha(opacity=' + i + ')';
    }
    ,trim : function(s)
    {
        return s.replace(/^\s+|\s+$/g, '');
    }
};
if(typeof(afw.module) == 'undefined')
{
    afw.module = {};
}
afw.common.addEvent('load', window, afw.common.initiate);
