﻿var AJAX_PAGE="/_layouts/efficientelrext/AJAXRequestManager.aspx";

var isMozilla = navigator.appName == "Netscape" && (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
var isIE = navigator.appName == "Microsoft Internet Explorer";
var СorrespondToSystemRequirments = isIE || isMozilla;


function LaunchTest(path)
{
    var width = screen.width - 100;
    var height = screen.height - 100;
    
    var closeReason = window.showModalDialog(path, '', 'dialogHeight: ' + height + 'px; dialogWidth: ' + width + 'px; center: Yes; help: No; resizable: No; status: No; scroll: yes;');        
//    if (closeReason != null)
//    {        
//        //var hfTWCR = getControlById("hfTestWindowCloseReason");            
//        //hfTWCR.value = closeReason;                                    
//        //doSimplePostBack();         
//        //return false;
//    }        

    //window.open(path, null, "fullscreen");
    document.location.reload(true);        
    return;
}

function WBMNItemParentOpen(path)
{
    if (path == '')
        return;
    parent.location.href = path;
    return;
}

function WBMNItemBlankOpen(path)
{
    if (path == '')
        return;
    window.open(path);
    return;
}

function SimpleConfirm(message)
{    
    return confirm(message);    
}

function _CreateXmlHttp()
{
    var xmlhttp = null;    
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XmlHttp");        
    }
    catch (e)
    {
       try
       {
            xmlhttp = new ActiveXObject("MSXML.XMLHTTP");
       }
       catch (e2)
       {
            xmlhttp = false;
       }
    }    
    if ( !xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
        xmlhttp = new XMLHttpRequest();
    }    
    return xmlhttp;
}

function _CreateXmlDOM()
{
    var xdoc = false;
    
    try
    {
        xdoc = new ActiveXObject("Msxml2.DOMDocument");
    }
    catch (e)
    {
        try
        {
            xdoc = new ActiveXObject("MSXML.DOMDocument");
        }
        catch(e2)
        {
            xdoc = false;
        }
    }
    
    if (!xdoc && document.implementation.createDocument)
    {         
        xdoc = document.implementation.createDocument("","",null);
    }
    
    return xdoc;
}


function SendDataToServer(dataId, args, data)
{
    var xmlhttp = _CreateXmlHttp();


    if (data != null)
        xmlhttp.open("POST",AJAX_PAGE,false);
    else
        xmlhttp.open("GET",AJAX_PAGE,false);   
        

    xmlhttp.setRequestHeader("rid", dataId);        
    xmlhttp.setRequestHeader("args", args);        
    
    if (data != null)
        xmlhttp.setRequestHeader('Content-length', data.length);             

    try
    {    
        xmlhttp.send(data);                     
    }
    catch (e)
    {
    
        alert(e.message == undefined ? e : e.message);
    }           
    
}

// меняет доступность элемента (атрибут disabled) и всех вложенных в него элементов
function ChangeAbility(element, enable)
{   

    element.disabled = null;
    alert(element.nodeName + ".disabled = " + element.disabled);
    
    for (var i = 0; i < element.childNodes.length; i++)
    {
        try
        {
            ChangeAbility(element.childNodes[i], enable);
        }
        catch (e) { }  // на некоторые узлы это может не прокатить (например на пустой узел)    
    }
}


/////// PanelWait methods group
    function BtnOK_InitializeWait(strBtnId, tBodyWait, tBodyMain)
    {    
    
        if (window.g_OKClicked == undefined)
        {                        
            document.getElementById(tBodyWait).style.display = 'block';                        
            document.getElementById(tBodyMain).style.display='none';            
            window.g_OKClicked = true;            
            setTimeout('aspnetForm.' + strBtnId + '.click()', 1);
            return false;
        }
        else
            return true;
    }

    /////// end of PanelWait methods group

var EfficientLab = new Object();


/* core js namespaces */

EfficientLab.Globals = new Object();  //its content is generated by ElrWebPage class

EfficientLab.Ajax = new Object();

EfficientLab.System = new Object();

/*////////////////////////////////
EfficientLab.System implementation
////////////////////////////////*/

EfficientLab.System.Env_Class = function() {

    this.resizeEventHandlers = new Array();
    this.resizeHandlersIndex = new Object();

    this.addResizeEventHandler = function(func) {
        if (this.resizeHandlersIndex[func] != null && this.resizeHandlersIndex[func] != undefined) {
            this.resizeEventHandlers.push(func);
            this.resizeHandlersIndex[func] = func;
        }
    }

    this.onWindowResize = function() {        
        for (var i = 0; i < EfficientLab.System.Env.resizeEventHandlers.length; i++) {
            alert(EfficientLab.System.Env.resizeEventHandlers.length);
            EfficientLab.System.Env.resizeEventHandlers[i].call();
        }
    }

}

EfficientLab.System.Env = new EfficientLab.System.Env_Class();

window.onresize = EfficientLab.System.Env.onWindowResize;

EfficientLab.System.DlgHelper_Class = function() {

    this.commonShowDialogEx = function(url, width, height, args, center, help, resizable, status, scrollable) {
        var features = "dialogWidth: " + width + ";" +
                        "dialogHeight: " + height + ";" +
                        "center: " + center + ";" +
                        "help: " + help + ";" +
                        "resizable: " + resizable + ";" +
                        "status: " + status + ";" +
                        "scroll: " + scrollable + ";";

        return window.showModalDialog(url, args, features);
    }

    this.closeDialog = function(result) {
        window.dialogResult = result;
        window.close();
    }

    this.commonShowDialog = function(url, width, height, args) {
        return this.commonShowDialogEx(url, width, height, args, "yes", "no", "no", "yes", "no");
    }

}

EfficientLab.System.DlgHelper = new EfficientLab.System.DlgHelper_Class();


/*///////////////////////////////////////
End of EfficientLab.System implementation
///////////////////////////////////////*/


