﻿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();
    return false;         
}

function openWindow(sPage, width, height)
{
    var left = (screen.width-width)/2;
    var top = 0;

    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);
    return false;         
}

function openWindowCenterScreen(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=no";
    var oNewWindow = window.open(sPage, "", sFeatures, true);
    return false;
}

function openWindowCenterScreenScrolled(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);
    return false;
}


function openWindowNoRes(sPage, width, height) {
    var left = (screen.width - width) / 2;
    //var top = (screen.height-height)/2;
    var top = 0;

    var sFeatures = "top=" + top + ", left=" + left + ", width=" + width + ", height=" + height + ", "
	    + "toolbar=no, menubar=no, location=no, directories=no, resizable=no, scrollbars=no";
    var oNewWindow = window.open(sPage, "", sFeatures, true);
    return false;         
}
function ITGetElementById(id)
{
    if (document.getElementById(id))
        return document.getElementById(id);
    else
        if (document.all[id])
            return document.all[id];
        else
            if (document.layers && document.layers[id])
                return (document.layers[id]);
            else
                return false;
}
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 ListEl(ListId, idFiedName, nameFieldName) {
    this.Id = ListId;
    this.El = ITGetElementById(ListId);
    this.IFN = idFiedName;
    this.NFN = nameFieldName;
}
ListEl.prototype.Fill = function(Atable) {
    this.clear();
    for (var ij = 0; ij < Atable.Rows.length; ij++) {
        var Op = new Option(Atable.Rows[ij][this.NFN], Atable.Rows[ij][this.IFN]);
        this.El.options[this.El.length] = Op;
    }
}
ListEl.prototype.clear = function() {
    for (i = this.El.length - 1; i >= 0; i--) {
        if (Number(this.El.options[i].value) >= 0) this.El.options[i] = null;
    }
    if (this.El.options[0] != null)
        this.El.options[0].selected = true;
}


//rating_stars в личном кабинете

function rating_1(current_rating, ident) {
    for (i = 1; i <= 5; i++) {
        if (i <= current_rating) {
            document.getElementById("rating_stars_" + i + "_" + ident).style.background = "url('../images/rating_stars_active.gif') no-repeat";
        } else {
            document.getElementById("rating_stars_" + i + "_" + ident).style.background = "url('../images/rating_stars.gif') no-repeat";
        }
    }
}

function rating_2(ident) {
    for (i = 1; i <= 5; i++) {
        document.getElementById("rating_stars_" + i + "_" + ident).style.background = "url('../images/rating_stars.gif') no-repeat";
    }
}