var ADMIN_FRAME_COUNT = 3;

function requireFrames(frame_count)
{
    if (window.top.frames.length != frame_count)
    {
        with (window.top.location)
        {
            var new_href = protocol + '//' + hostname + pathname;
            // !! laikinai
            //href = new_href; 
        }
    }
}

function saveFrameSize(name)
{
    var width = document.body.offsetWidth;
    var height = document.body.offsetHeight;
    setCookieValue(name + '_width', width, 60 * 60 * 24 * 10);
    setCookieValue(name + '_height', height, 60 * 60 * 24 * 10);
}

function restoreFrameWidth(name, pattern)
{
    var width = getCookieValue(name + '_width');
    if (width)
    {
        var frameset = parent.document.getElementById('frameset');
        if (frameset)
            frameset.cols = pattern.replace(/size/, width);
    }

}

function restoreFrameHeight(name, pattern)
{
    var height = getCookieValue(name + '_height');
    if (height)
    {
        var frameset = parent.document.getElementById('frameset');
        frameset.rows = pattern.replace(/size/, height);
    }

}

function getCookieValue(name)
{
    var cookie_pair = new Array();
    var cookie_list = document.cookie.split(';');
    var cookie_count = cookie_list.length;
    for (var i = 0; i < cookie_count; i++)
    {
        cookie_pair = cookie_list[i].split('=');
        cookie_pair[0] = cookie_pair[0].replace(/\s+/i, '');
        if (cookie_pair[0] == name)
        {
            return cookie_pair[1];
        }
    }
    return false;
}

function setCookieValue(name, value, expires)
{
    var today = new Date();
    var expires = new Date(today.getTime() + expires * 1000);
    document.cookie = name + '=' + escape(value) + ';expires=' + expires.toGMTString();
}

function submitForm(form, cms_action)
{
    form['cms_action'].value = cms_action;
    form.submit();
}

function ods()
{
    message = '';
    for( var i = 0; i < arguments.length; i++)
        message += i + ' = ' + arguments[i] + '\n';
    prompt('DEBUG\n\n' + message, message);
}
