function WindowOpen(vUrl, vWidth, vHeight, vScroll, vResize) {
    vLeft = (screen.availWidth - vWidth) / 2;
    vTop = (screen.availHeight - vHeight) / 2;
    if (!vScroll) vScroll = 'no';
    if (!vResize) vResize = 'no';
    parameters = '';
    parameters += 'toolbar=no,';
    parameters += 'location=no,';
    parameters += 'directories=no,';
    parameters += 'status=no,';
    parameters += 'menubar=no,';
    parameters += 'scrollbars=' + vScroll + ',';
    parameters += 'resizable=' + vResize + ',';
    parameters += 'left=' + vLeft + ',';
    parameters += 'top=' + vTop + ',';
    parameters += 'width=' + vWidth + ',';
    parameters += 'height=' + vHeight;
    wId = window.open(vUrl, 'NewWin' + GetRand(), parameters);
    wId.focus();
}
function GetRand() {
    result = '';
    result = Math.random() + '1';
    result = result.split('.');
    return result[1];
}
function stringTrim(strToTrim) {
    var tmp_str = new String(strToTrim);
    return (tmp_str.replace (/^\s+|\s+$/g, ''));
}
function SetCookie(sName, sValue) {
    document.cookie = sName + '=' + escape(sValue) + '; expires=Fri, 25 Dec 2020 23:59:59 GMT;';
}
function DelCookie(sName) {
    document.cookie = sName + '=; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
}
function GetCookie(sName) {
    var aCookie = document.cookie.split('; ');
    for (var i=0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split('=');
        if (sName == aCrumb[0]) return unescape(aCrumb[1]);
    }
    return null;
}
function showModalMessage(vText) {
    var winStage = $('#bodystage');
    var winModal = $('#modunit');
    var modMessArea = $('#modunitarea');
    var modMessAreaText = $('#modunitareatext');
    var winStageOffset = $(winStage).offset();
    $(winModal).css({'left':winStageOffset.left,'top':winStageOffset.top,'height':$(winStage).height()});
    $(winModal).show();
    $(modMessAreaText).html(vText);
    var modMessArea_Left = ($(winStage).width()-$(modMessArea).width()) / 2;
    $(modMessArea).css({'left':winStageOffset.left+modMessArea_Left, 'top':50});
    $(modMessArea).show();
}
function hideModalMessage() {
    var winModal = $('#modunit');
    var modMessArea = $('#modunitarea');
    var modMessAreaText = $('#modunitareatext');
    $(winModal).hide();
    $(modMessArea).hide();
    $(modMessAreaText).html('');
}
function ajaxModalMessage(vURL) {
    var sAjaxURL = '/' + sSitePath + 'patterns/' + vURL;
    if (aModOnProgress != 0) return;
    aModOnProgress = 1;
    var req = getXmlHttpRequest();
    req.onreadystatechange = function () {
        if (aModOnProgress == 0) { req.abort(); return; }
        if (req.readyState != 4) return;
        aModOnProgress = 0;
        showModalMessage(req.responseText);
    }
    req.open('GET', sAjaxURL, true);
    req.send(null);
    return false;
}
/* Ширина клиентской (рабочей) области окна */
function getClientWidth() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}
/* Высота клиентской (рабочей) области окна */
function getClientHeight() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}
/* На сколько прокручен документ с верху */
function getBodyScrollTop() {
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
/* На сколько прокручен документ с лева */
function getBodyScrollLeft() {
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}
/* Координата центра с учетом скроллинга по оси X */
function getClientCenterX() {
    return parseInt(getClientWidth() / 2) + getBodyScrollLeft();
}
/* Координата центра с учетом скроллинга по оси Y */
function getClientCenterY() {
    return parseInt(getClientHeight() / 2) + getBodyScrollTop();
}
/* Размер документа по вертикали */
function getDocumentHeight() {
    return (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}
/* Размер документа по горизонтали */
function getDocumentWidth() {
    return (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
}
function setFooterPosition(gBlocks) {
    var gBlocksHeight = 0;
    var clientHeight = getClientHeight();
    for (var gBlock in gBlocks) {
        //alert($('#' + gBlocks[gBlock]).height());
        gBlocksHeight += $('#' + gBlocks[gBlock]).height();
    }
    //alert('window: ' + clientHeight + ' site: ' + gBlocksHeight);
    if (gBlocksHeight > clientHeight) return;
    $('#footerpadding').height(clientHeight - gBlocksHeight);
}
