var isIE = !!document.all;
var isIE6 = navigator.userAgent.indexOf('MSIE 6') > -1;
var isIE7 = navigator.userAgent.indexOf('MSIE 7') > -1;

function getDocumentHeight()
{
    var body = document.body,
        html = document.documentElement;

    var height = Math.max(
        body.scrollHeight, body.offsetHeight, 
        html.clientHeight, html.scrollHeight, html.offsetHeight
    );
        
    var height2 = Math.max(
        //document.getElementById('root').clientHeight,
        document.getElementById('content').clientHeight,
        document.getElementById('rightcol').clientHeight
    );
    
    var m = [
        document.getElementById('root').clientHeight,
        document.getElementById('content').clientHeight,
        document.getElementById('rightcol').clientHeight
    ];

    
    //alert(document.getElementById('content').clientHeight);

    height -= 270;
    height2 += 30;

    return Math.max(height, height2);
    
}

function getScrollTop() 
{
    return sizeFilterResults(
        window.pageYOffset ? window.pageYOffset : 0, 
        document.documentElement ? document.documentElement.scrollTop : 0, 
        document.body ? document.body.scrollTop : 0	);
}

function sizeFilterResults(n_win, n_docel, n_body) 
{
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

if (isIE6)
    var resizeColsCall = false;

function resizeCols(mode)
{
    return;
    if (isIE6 && resizeColsCall)
        return;

    var leftcol_id  = 'leftcol';
    var rightcol_id = 'rightcol';
    var colsHeight = getDocumentHeight();
    var property = (isIE6) ? 'height' : 'minHeight';

    if (document.getElementById(leftcol_id) !== null)
        document.getElementById(leftcol_id).style[property] = colsHeight + 'px';
        
    if (document.getElementById(rightcol_id) !== null)
        document.getElementById(rightcol_id).style[property] = colsHeight + 'px';

    if (isIE6)
        resizeColsCall = true;
}

function resizeColsInit()
{
    // выходим, если функция уже выполнялась
    if (arguments.callee.done) return;

    // устанавливаем флаг, чтобы функция не исполнялась дважды
    arguments.callee.done = true;
    // что-нибудь делаем
    resizeCols();
};

/* для Mozilla/Firefox/Opera 9 */
if (document.addEventListener)
{
    document.addEventListener("DOMContentLoaded", resizeColsInit, false);
}

/* для Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=\"__ie_onload\" defer=\"defer\" src=\"javascript:void(0)\"><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
	resizeColsInit(); // вызываем обработчик для onload
    }
};
/*@end @*/

/* для Safari */
if (/WebKit/i.test(navigator.userAgent)) {
    // условие для Safari
    var _timer = setInterval(function() {
	if (/loaded|complete/.test(document.readyState)) {
	    clearInterval(_timer);
	    resizeColsInit(); // вызываем обработчик для onload
	}
    }, 10);
}


