var client_height = 0;
var Statred = 0;
var inti;
//var animationPhoto = new Sys.Preview.UI.Effects.LengthAnimation();
var img = $get("imgPhotoViewer");
var div = $get("divPhotoViewer");
//var ImgTarget = new Sys.UI.Control(img);
//var DivTarget = new Sys.UI.Control(div);


/*Cookies*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "");
}


function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}
/**/
function screenSize() {
    var w, h; // Объявляем переменные, w - длина, h - высота
    w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
    h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
    return { w: w, h: h };
}


// Функция для добавления обработчика событий
function addHandler(object, event, handler, useCapture) {
    if (object.addEventListener) {
        object.addEventListener(event, handler, useCapture ? useCapture : false);
    } else if (object.attachEvent) {
        object.attachEvent('on' + event, handler);
    } else alert("Add handler is not supported");
}
// Добавляем обработчики
/* Gecko */
addHandler(window, 'load', WindowLoad);
addHandler(window, 'resize', WindowLoad);

function WindowLoad(event) {
    //var rpanel = document.getElementById('right_panel');
    var cpanel = document.getElementById('center_panel');
    //var lpanel = document.getElementById('left_panel');    
    var w = screenSize().w;
    var h = screenSize().h;
    hh = client_height / h;
    client_height = h;
}





function iframe_resize() {
    if (document.getElementById("ctl00_iframe_chat") != null) {
        document.getElementById("ctl00_iframe_chat").height = $get("ctl00_PanelChat").clientHeight - 23;
        var th = document.getElementById("ctl00_iframe_chat").contentDocument.getElementById("TextHere");

        if (th != null) {
            var ht = $get("ctl00_PanelChat").clientHeight - 44 - 120;
            th.style.height = ht + "px";
        }
    }
}

function iframe_resize_back() {
    if (document.getElementById("ctl00_iframe_chat") != null) {
        document.getElementById("ctl00_iframe_chat").height = $get("ctl00_PanelChat").clientHeight - 23;
        var th = document.getElementById("ctl00_iframe_chat").contentDocument.getElementById("TextHere");
        if (th != null) {
            var ht = 400 - 44 - 120;
            th.style.height = ht + "px";
        }
    }
}




function ShowChat() {
    var ChatState = getCookie("chatState");
    var aRez = $get("ctl00_iframe_chat");
    if (aRez != null) {
        var hre = document.getElementById("aResizeit");
        if (ChatState == "Min") {
            aRez.style.height = "20px";
            aRez.height = 28;
            hre.innerHTML = "Востановить";
            aRez.style['height'] = "28px";
            document.getElementById("iframe_chat").height = 1;
        }
        if (ChatState == "Max") {
            aRez.style['height'] = "520px";
            hre.innerHTML = "Свернуть";
        }
    }
}

function Resizeit() {
    //var aRez = $get("ctl00_PanelChat");
    var hre = document.getElementById("aResizeit");
    if (hre.innerHTML.indexOf('minimize.png') > 0) {
        //aRez.style['height'] = "30px";
        hre.innerHTML = "<img src='images/headertab/maximize.png' />";
        setCookie("chatState", "Min", "", "/");
        document.getElementById("ctl00_iframe_chat").height = "0px";
        $get("DivCapChat").className = "backHeader";
    }
    else {
        document.getElementById("ctl00_iframe_chat").height = "520px";
        var ht = document.getElementById("ctl00_iframe_chat").clientHeight + 23;
        //aRez.style['height'] = ht + "px"; //"300px";
        hre.innerHTML = "<img src='images/headertab/minimize.png' />";
        setCookie("chatState", "Max", "", "/");
        $get("DivCapChat").className = "backHeader_active";
    }
    clearInterval(inti);


}


/*Navigation*/
function ResizeNave() {
    var aRez = $get("ctl00_PanelNavigate");
    var hre = document.getElementById("aNavigateResize");
    if (hre.innerHTML.indexOf('minimize.png') > 0) {
        aRez.style['height'] = "40px";
        hre.innerHTML = "<img src='images/headertab/maximize.png' />";
        var ContainerTree = $get("ContainerTree");
        ContainerTree.style['display'] = "none";
        $get("TaskbarNavigateBtn").className = "backHeader";
    }
    else {

        aRez.style['height'] = "40px"; //"300px";
        hre.innerHTML = "<img src='images/headertab/minimize.png' />";
        var ContainerTree = $get("ContainerTree");
        ContainerTree.style['display'] = "block";
        $get("TaskbarNavigateBtn").className = "backHeader_active";
    }



    function CheckNewMessage() {
        admrmr_ru_new.AdmrmrBlockData.GetCountMessage(context, Complete_CntReq);
    }
    function Complete_cntReq(results) {
        var cnt = 0;
        cnt = getCookie("admrmr_count_message");
        if (cnt < results) {
            window.setTimeout(function() {
                window.external.msSiteModeSetIconOverlay("/icons/overlay.ico", "Example Notification");
                window.external.msSiteModeActivate();
            }, 2000);
        }
    }
}
/* PhotoView */
function ShowPhotoViewer(value) {
    var urlstart = value;
    var dark = $get("darkness");
    dark.style["display"] = "block";
    div.style["display"] = "block";
    var height = document.documentElement.clientHeight- 260;
    var width = document.documentElement.clientWidth;  //- 260;
    //div.style["width"] = width + "px";
    url = SetQueryStringParamValue("height", urlstart, height);
    //url = SetQueryStringParamValue("width", url, width);
    img.src = url;
    var left = document.documentElement.clientWidth / 2  - div.clientWidth/2;
    var top = 80;
    div.style["left"] = left + "px";
    div.style["top"] = top + "px";
    startHeight = 0; borders = 0; padding = 2;
    img.style["cursor"] = "pointer";    
    img.onclick = function() { window.navigate(urlstart); };
    img.onload = function() {
        AjaxControlToolkit.Animation.LengthAnimation.play(div, 1, 80, 'style', 'marginTop', -300, startHeight - borders - padding, "px");
        /*    with (animationPhoto) {
        set_target(div);
        set_property('style');
        set_propertyKey('marginTop');
        set_duration(0.3);
        set_startValue(-300);
        set_endValue(startHeight - borders - padding);
        initialize();
        play();
        }*/

        Sys.Application.add_init(function() {
            $create(Sys.Extended.UI.AlwaysVisibleControlBehavior, { "HorizontalSide": 1, "VerticalOffset": top, "id": "AlwaysVisibleControlExtenderPhotoView" }, null, null, div);
        });
    }

}

function ClosePhotoViewer() {
    div.style["display"] = "none";
    var dark = $get("darkness");
    dark.style["display"] = "none";
    img.src = "";
    var obj = $find("AlwaysVisibleControlExtenderPhotoView");
    //animationPhoto.dispose();
    var type = typeof (obj);
    obj.dispose();

}

/* PopUpDiv */
function ShowPopUp() {
    var str = getCookie("PopUp");
    if (str!="stopped"){
        admrmr_ru_new.AdmrmrBlockData.GetContentForPopUp(CompleteGetPopUp);    
    }

}

function CompleteGetPopUp(results) {
    divi = $get("PopUpDiv");
    divc = $get("PopUpDivContent");
    if (results != "none") {
        divc.innerHTML = results;
        var dark = $get("darkness");
        dark.style["display"] = "block";
        divi.style["display"] = "block";
        
        startHeight = 0; borders = 0; padding = 2;
        AjaxControlToolkit.Animation.LengthAnimation.play(divi, 1, 80, 'style', 'marginTop', -300, startHeight - borders - padding, "px");

        Sys.Application.add_init(function() {
        $create(Sys.Extended.UI.AlwaysVisibleControlBehavior, { "HorizontalSide": 1, "VerticalSide": 1, "id": "AlwaysVisibleControlExtenderPopUp" }, null, null, divi);
        });
    }
 }

function ClosePopUp() {
    divi = $get("PopUpDiv");
    divi.style["display"] = "none";
    var dark = $get("darkness");
    dark.style["display"] = "none";
    img.src = "";
    var obj = $find("AlwaysVisibleControlExtenderPopUp");
    //animationPhoto.dispose();
    var type = typeof (obj);
    obj.dispose();
    setCookie("PopUp", "stopped", "", "/");

}

/*New Terminal Winbdows Style*/
