//------------------------------------------------------------------------------
// _isArray(obj) 
//------------------------------------------------------------------------------
function _isArray(obj) 
{
    return _isObject(obj) && obj.constructor == Array;
}

//------------------------------------------------------------------------------
// _isBoolean(obj) 
//------------------------------------------------------------------------------
function _isBoolean(obj) 
{
    return typeof obj == 'boolean';
}

//------------------------------------------------------------------------------
// _isEmpty(obj) 
//------------------------------------------------------------------------------
function _isEmpty(obj) 
{
	if (_isNull(obj)||_isUndefined(obj)) 
		return true;
	
	if (_isString(obj))
		return _trim(obj)==""?true:false;
			
	if (_isNumber(obj))
		return (obj>0)?false:true;

    if (_isArray(obj)) 
		return (0==obj.length)?true:false;
}

//------------------------------------------------------------------------------
// _isFunction(obj) 
//------------------------------------------------------------------------------
function _isFunction(obj) 
{
    return typeof obj == 'function';
}

//------------------------------------------------------------------------------
// _isNull(obj) 
//------------------------------------------------------------------------------
function _isNull(obj) 
{
    return typeof obj == 'object' && !obj;
}

//------------------------------------------------------------------------------
// _isNumber(obj) 
//------------------------------------------------------------------------------
function _isNumber(obj) 
{
    return typeof obj == 'number' && isFinite(obj);
}

//------------------------------------------------------------------------------
// _isObject(obj) 
//------------------------------------------------------------------------------
function _isObject(obj)
{
    return (obj && typeof obj == 'object')||_isFunction(obj);
}

//------------------------------------------------------------------------------
// _isString(obj) 
//------------------------------------------------------------------------------
function _isString(obj) 
{
    return typeof obj == 'string';
}

//------------------------------------------------------------------------------
// _isUndefined(obj) 
//------------------------------------------------------------------------------
function _isUndefined(obj) 
{
    return typeof obj == 'undefined';
} 

//------------------------------------------------------------------------------
// _constructor(obj)
//------------------------------------------------------------------------------
function _constructor(obj)
{
    if(!_isObject(obj))
        return "";
    var strContructor = String(obj.constructor);
    if(_isUndefined(strContructor))
        return "";

    var oRegFindExp = new RegExp("function[\\s]*[^\\s({]+", "ig");
    var oRegCleanExp = new RegExp("function[\\s]*", "ig");
    if(!oRegFindExp.test(strContructor))
        return strContructor;
    else
    {
        var arrMatches = strContructor.match(oRegFindExp);
        if(arrMatches && arrMatches.length > 0)
            return arrMatches[0].replace(oRegCleanExp, "");
    }
    return "";            
}	 

//------------------------------------------------------------------------------
// _trim(s)
//------------------------------------------------------------------------------
function _trim(s)
{
    return s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}	 

//------------------------------------------------------------------------------
// _getNumeric(s)
//------------------------------------------------------------------------------
function _getNumeric(s)
{
	if(_isUndefined(s))
		return "";
	return String(s).replace(new RegExp("[^0-9.,]", "ig"), "");
}

//------------------------------------------------------------------------------
// _getAlpha(s)
//------------------------------------------------------------------------------
function _getAlpha(s)
{
	if(_isUndefined(s))
		return "";
	return String(s).replace(new RegExp("[0-9]", "ig"), "");
}


//------------------------------------------------------------------------------
// _encodeURI(s)
//------------------------------------------------------------------------------
function _encodeURI(s)
{
  if(encodeURIComponent) 
    return encodeURIComponent(s);
  if(escape)
    return escape(s);
}

//------------------------------------------------------------------------------
// _decodeURI(s)
//------------------------------------------------------------------------------
function _decodeURI(s)
{
  if(decodeURIComponent) 
    return decodeURIComponent(s);
  if(unescape)
    return unescape(s);
}

//------------------------------------------------------------------------------
// _xmlEncode(str) 
//------------------------------------------------------------------------------
function _xmlEncode(str) 
{ 
    var m = {
        '\"' : '&quot;',
        '\'' : '&quot;',
        '&' : '&amp;',
        '<' : '&lt;',
        '>' : '&gt;' };
    var retVal = "";
    for( var nIdx = 0, nCnt = str.length; nIdx < nCnt; nIdx++)
    {
        var c = m[str.charAt(nIdx)];
        if(!_isEmpty(c))
            retVal += c;
        else
            retVal += str.charAt(nIdx);
    }
    
    return retVal;
}

//------------------------------------------------------------------------------
// _htmlEncode(str) 
//------------------------------------------------------------------------------
function _htmlEncode(str) 
{ 
    var m = {
        '\"' : '&quot;',
        '\'' : '&quot;',
        '&' : '&amp;',
        '<' : '&lt;',
        '>' : '&gt;' };
    var retVal = "";
    for( var nIdx = 0, nCnt = str.length; nIdx < nCnt; nIdx++)
    {
        var c = m[str.charAt(nIdx)];
        if(!_isEmpty(c))
            retVal += c;
        else
            retVal += str.charAt(nIdx);
    }
    return retVal;
}

//------------------------------------------------------------------------------
// getAbsoluteCoords(element, rootElement) 
//------------------------------------------------------------------------------
function getAbsoluteCoords(element, rootElement) 
{
    this.parseInteger = function (nVal)
    {
	       var nRetVal = 0;
	       if(nVal)
	       {
		          nRetVal = parseInt(nVal);
		          nRetVal = (isNaN(nRetVal))?0:nRetVal;
	       }
	       return nRetVal;
    }

    var coords = {x : 0, y : 0};
    if (!rootElement)
        rootElement = document.body;
    while (element && element != rootElement)
    {
        coords.x += element.offsetLeft - element.scrollLeft + this.parseInteger(_getNumeric( getStyleByObject( element, 'borderLeftWidth'))) + this.parseInteger(_getNumeric( getStyleByObject( element, 'paddingLeft')));
        coords.y += element.offsetTop - element.scrollTop + this.parseInteger(_getNumeric( getStyleByObject( element, 'borderTopWidth'))) + this.parseInteger(_getNumeric( getStyleByObject( element, 'paddingTop')));
        var parent = element.parentNode;
        element = element.offsetParent;
        while (element && parent && parent != element && parent != rootElement) // Firefox skips DIV's
        {
            coords.x -= parent.scrollLeft;
            coords.y -= parent.scrollTop;
            parent = parent.parentNode;
        }
    }
    return coords;
}

//------------------------------------------------------------------------------
// JSON methods
//------------------------------------------------------------------------------
(function () {
    var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        s = {
            array: function (x) {
                var a = ['['], b, f, i, l = x.length, v;
                for (i = 0; i < l; i += 1) {
                    v = x[i];
                    f = s[typeof v];
                    if (f) {
                        v = f(v);
                        if (typeof v == 'string') {
                            if (b) {
                                a[a.length] = ',';
                            }
                            a[a.length] = v;
                            b = true;
                        }
                    }
                }
                a[a.length] = ']';
                return a.join('');
            },
            'boolean': function (x) {
                return String(x);
            },
            'null': function (x) {
                return "null";
            },
            number: function (x) {
                return isFinite(x) ? String(x) : 'null';
            },
            object: function (x) {
                if (x) {
                    if (x instanceof Array) {
                        return s.array(x);
                    }
                    var a = ['{'], b, f, i, v;
                    for (i in x) {
                        v = x[i];
                        f = s[typeof v];
                        if (f) {
                            v = f(v);
                            if (typeof v == 'string') {
                                if (b) {
                                    a[a.length] = ',';
                                }
                                a.push(s.string(i), ':', v);
                                b = true;
                            }
                        }
                    }
                    a[a.length] = '}';
                    return a.join('');
                }
                return 'null';
            },
            string: function (x) {
                if (/["\\\x00-\x1f]/.test(x)) {
                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                        var c = m[b];
                        if (c) {
                            return c;
                        }
                        c = b.charCodeAt();
                        return '\\u00' +
                            Math.floor(c / 16).toString(16) +
                            (c % 16).toString(16);
                    });
                }
                return '"' + x + '"';
            }
        };

    Object.prototype.toJSONString = function () {
        return s.object(this);
    };

    Array.prototype.toJSONString = function () {
        return s.array(this);
    };
})();

String.prototype.parseJSON = function () {
    try {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                this.replace(/"(\\.|[^"\\])*"/g, ''))) &&
            eval('(' + this + ')');
    } catch (e) {
        return false;
    }
};

var g_dtReference = null;
function LoadAds(strUrl)
{
	if(g_dtReference != null)
		if((new Date()).getTime() - g_dtReference.getTime() < 500 ) // Less than 500 milliseconds between two calls.
			return;
	g_dtReference = new Date();

    var strBaseUrl = document.location.href;

    if(!_isUndefined(strUrl))
        strBaseUrl = strUrl;
    else
    {
        var nQueryIdx = strBaseUrl.lastIndexOf('?');
        var nIdx = strBaseUrl.lastIndexOf('/');
        
        if(nQueryIdx >= 0 && nIdx > nQueryIdx)
            nIdx = nQueryIdx-1;

        if(nIdx >= 0)
            strBaseUrl = strBaseUrl.substr(0, nIdx);
    }        

    updateIFrame(document.getElementById("_frmHeader"), strBaseUrl + "/Static/11/Banners/Header.htm?nDate=" + (new Date()).getTime());
    updateIFrame(document.getElementById("_frmLeftColumn"), strBaseUrl + "/Static/11/Banners/LeftColumn.htm?nDate=" + (new Date()).getTime());
    updateIFrame(document.getElementById("_frmRightTopColumn"), strBaseUrl + "/Static/11/Banners/RightTopColumn.htm?nDate=" + (new Date()).getTime());
    updateIFrame(document.getElementById("_frmRightBottomColumn"), strBaseUrl + "/Static/11/Banners/RightBottomColumn.htm?nDate=" + (new Date()).getTime());
    updateIFrame(document.getElementById("_frmWebRight"), strBaseUrl + "/Static/11/Banners/WebRight.htm?nDate=" + (new Date()).getTime());
}

function updateIFrame(eIFrame, strUrl)
{
    if( eIFrame ) 
    {
        var IFrm = null;
        if (eIFrame.contentDocument)
            IFrm = eIFrame.contentDocument; 
        else if (eIFrame.contentWindow)
            IFrm = eIFrame.contentWindow.document;
        else if (eIFrame.document)
            IFrm = eIFrame.document;

        if(IFrm)
            IFrm.location.replace(strUrl);
        else
            eIFrame.src = strUrl;
    }
}