﻿function Clear_Data(cellID) {
    var cell = document.getElementById(cellID);
    if (cell != null) {
        cell.innerHTML = "";
    }
}

function Show_Hide_Element(elemID, disValue) {
    var obj = document.getElementById(elemID);
    if (obj != null) {
        if (obj.style.display == null || obj.style.display == "" || obj.style.display == "none") {
            obj.style.display = disValue;
        }
        else if (obj.style.display == disValue) {
            obj.style.display = "none";
        }
    }
}

function showplayer(e, url, element, text) {
    remove_playervideotable();
    //.Replace("\"", "&quot;").Replace("'", "&#39;")
    document.getElementById("hiddenPlayer").href = url.replace("&quot;", "\"").replace("&#_39;", "'"); //"ftp://80.73.15.17/video.flv";
    document.getElementById("hiddenPlayerCaption").innerHTML = text;
    set_playervideotable_position();

    document.getElementById("playerVideoDiv").style.display = "table";
    flowplayer("hiddenPlayer", "Players/flowplayer-3.2.4.swf");
    document.getElementById("backgrounddiv").style.display = "block";
    document.getElementById("backgrounddiv").style.height = getPageSize() + "px";
}

function remove_playervideotable() {
    document.getElementById("hiddenPlayer").href = "";
    document.getElementById("playerVideoDiv").style.display = "none";
    document.getElementById("backgrounddiv").style.display = "none";
}

function set_playervideotable_position() {
    //var height = document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
    //var width = document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;

    document.getElementById("playerVideoDiv").style.top = new Number((height / 2) - 240 + getScrollXY()[1]) + "px";
    document.getElementById("playerVideoDiv").style.left = new Number((width / 2) - 320 + getScrollXY()[0]) + "px";
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

function getPageSize() {
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight) {
        xScroll = document.documentElement.scrollWidth;
        yScroll = document.documentElement.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    return pageHeight; //,pageWidth, windowWidth,windowHeight
}

function getBrowserInfo() {
    var t, v = undefined;
    if (window.opera) {
        t = 'Opera';
    }
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE') + 5;
        v = nv.substring(s, s + 1);
    }
    else if (navigator.appName) {
        t = 'Netscape';
    }
    return { type: t, version: v };
}
function bookmark(a) {
    var url = document.location;
    var title = document.title;

    var b = getBrowserInfo();
    if (b.type == 'IE') {
        window.external.AddFavorite(url, title);
    }
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = url + ',' + title;
        return true;
    }
    else if (b.type == "Netscape") {
        window.sidebar.addPanel(title, url, "");
    }
    else {
        alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    }
    return false;
}

function ShowPopupDiv(backgroundElementId, popupElementId, captionElementId, titleText) {
    document.getElementById(backgroundElementId).style.display = "block";
    document.getElementById(backgroundElementId).style.height = getPageSize() + "px";
    document.getElementById(popupElementId).style.display = "block";

    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;
    var popupOffsetHeight = document.getElementById(popupElementId).offsetHeight;

    document.getElementById(popupElementId).style.top = new Number((height / 2) - (popupOffsetHeight / 2) + getScrollXY()[1]) + "px";
    document.getElementById(popupElementId).style.left = new Number((width / 2) - 320 + getScrollXY()[0]) + "px";

    document.getElementById(captionElementId).innerHTML = titleText;
}

function RemovePopupControl(backgroundElementId, popupElementId) {
    document.getElementById(backgroundElementId).style.display = "none";
    document.getElementById(popupElementId).style.display = "none";
}


function ShowHide_Element(sender, elemID, showIMG, hideIMG) {
    var elem = document.getElementById(elemID);
    if (elem.style.display == "none") {
        elem.style.display = "block";
        sender.src = hideIMG;
    }
    else {
        elem.style.display = "none";
        sender.src = showIMG;
    }
}
