﻿String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function openImageWindow(img, width, height)
{       
    var NewWindow
    var left = (screen.width-width)/2;
    var top = (screen.height-height)/2;

    var sFeatures = "top="+top+", left="+left+", width="+width+", height="+height+", "
            + "toolbar=no, menubar=no, location=no, directories=no, resizable=no, scrollbars=no";
    NewWindow = open("", "myWin", sFeatures, true);
    NewWindow.document.open();
    NewWindow.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"+
    "<html xmlns='http://www.w3.org/1999/xhtml'>"+
    "<head>"+
        "<title>Фото</title>"+
    "</head>"+
    "<body style='margin: 0px; padding: 0px'>"+
    "<img src='"+img+"' width='"+width+" 'height='"+height+"' alt='' />"+
    "</body>"+
    "</html>");
    NewWindow.document.close();              
}
function openWindow(sPage, width, height)
{
    var left = (screen.width-width)/2;
    var top = (screen.height-height)/2;

    var sFeatures= "top="+top+", left="+left+", width="+width+", height="+height+", "
	    + "toolbar=no, menubar=no, location=no, directories=no, resizable=no, scrollbars=yes";
    var oNewWindow = window.open(sPage, "", sFeatures, true);
}
function GetScrollY()
{
    if (window.navigator.appName.toLowerCase().indexOf('explorer') == -1)
    {
        return window.pageYOffset;
    }
    else
    {
        if (document.documentElement && document.documentElement.scrollTop) {
            return document.documentElement.scrollTop;
        }
        else if (document.body) {
            return document.body.scrollTop;
        }
    }
    return 0;
}
function GetScrollX() {
    if (window.navigator.appName.toLowerCase().indexOf('explorer') == -1) {
        return window.pageXOffset;
    }
    else {
        if (document.documentElement && document.documentElement.scrollLeft) {
            return document.documentElement.scrollLeft;
        }
        else if (document.body) {
            return document.body.scrollLeft;
        }
    }
    return 0;
}
function isNumber(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))  return false;
    return true;
}
function GetElementPosition(element) {
    var result = new Object();
    result.x = 0;
    result.y = 0;
    result.width = 0;
    result.height = 0;
    if (element.offsetParent) {
        result.x = element.offsetLeft;
        result.y = element.offsetTop;
        var parent = element.offsetParent;
        while (parent) {
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
            var parentTagName = parent.tagName.toLowerCase();
            if (parentTagName != "table" &&
                parentTagName != "body" && 
                parentTagName != "html" && 
                parentTagName != "div" && 
                parent.clientTop && 
                parent.clientLeft) {
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (element.left && element.top) {
        result.x = element.left;
        result.y = element.top;
    }
    else {
        if (element.x) {
            result.x = element.x;
        }
        if (element.y) {
            result.y = element.y;
        }
    }
    if (element.offsetWidth && element.offsetHeight) {
        result.width = element.offsetWidth;
        result.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        result.width = element.style.pixelWidth;
        result.height = element.style.pixelHeight;
    }
    return result;
}
function SetElementHeight(element, height) {
    if (element && element.style) {
        element.style.height = height + "px";
    }
}
function SetElementWidth(element, width) {
    if (element && element.style) {
        element.style.width = width + "px";
    }
}
function SetElementX(element, x) {
    if (element && element.style) {
        element.style.left = x + "px";
    }
}
function SetElementY(element, y) {
    if (element && element.style) {
        element.style.top = y + "px";
    }
}
function RestoreScrollPosition() {
    if (window.navigator.appName.toLowerCase().indexOf('explorer') == -1) {
        window.scrollTo(theForm.elements['__SCROLLPOSITIONX'].value, theForm.elements['__SCROLLPOSITIONY'].value);
    }
    else {
        window.scrollTo(theForm.__SCROLLPOSITIONX.value, theForm.__SCROLLPOSITIONY.value);
    }
    if ((typeof(theForm.oldOnLoad) != "undefined") && (theForm.oldOnLoad != null)) {
        return theForm.oldOnLoad();
    }
    return true;
}
function ShowHideFiltr(element_id, image_id)
{
    var element = document.getElementById(element_id);
    var image = document.getElementById(image_id);
    if (element && element.style)
    {
        if (element.style.display == "block")
        {
            element.style.display = "none";
            image.src = "/admin/images/icon2.gif";
            image.alt = "Показать фильтр";
        }
        else
        {
            element.style.display = "block";
            image.src = "/admin/images/icon3.gif";
            image.alt = "Скрыть фильтр";
        }
    }
}