﻿Type.registerNamespace('ATI.Ajax.Scripts');
ATI.Ajax.Scripts.YesNo = function(){
}
ATI.Ajax.Scripts.YesNo.prototype = {    
    Yes: 1,
    No: 0
}
ATI.Ajax.Scripts.YesNo.registerEnum("ATI.Ajax.Scripts.YesNo", false);

//Search modes
ATI.Ajax.Scripts.SearchMode = function() {
}
ATI.Ajax.Scripts.SearchMode.prototype = {
    Default: 0,
    EllipseRoute: 1
}
ATI.Ajax.Scripts.SearchMode.registerEnum("ATI.Ajax.Scripts.SearchMode", false);

ATI.Ajax.Scripts.FormActions = function(){
}
ATI.Ajax.Scripts.FormActions.prototype = {    
    Close: 0,
    CloseAndRedirect: 1,
    AddNewClearForm: 2,
    AddNewLeaveData: 3,
    PickEntity: 4,
    CloseAndGoArchive: 5
}
ATI.Ajax.Scripts.FormActions.registerEnum("ATI.Ajax.Scripts.FormActions", false);


ATI.Ajax.Scripts.ExceptionHolder = function(p_message, p_stackTrace, p_exceptionType, 
            p_statusCode, p_serverCode, p_timedOut) {
    ATI.Ajax.Scripts.ExceptionHolder.initializeBase(this);
    
    this._timedOut = p_timedOut == null ? false : p_timedOut;
    this._message = p_message == null ? '' : p_message;
    this._stackTrace = p_stackTrace == null ? '' : p_stackTrace;
    this._exceptionType = p_exceptionType == null ? '' : p_exceptionType;
    this._statusCode = p_statusCode == null ? 0 : p_statusCode;
    this._serverCode = p_serverCode == null ? 0 : p_serverCode;
}

ATI.Ajax.Scripts.ExceptionHolder.prototype = {        
    get_exceptionType: function() {
        return this._exceptionType;
    },
    
    get_stackTrace: function() {
        return this._stackTrace;
    },
    
    get_message: function() {
        return this._message;
    },
    
    get_statusCode: function() {
        return this._statusCode;
    },
    
     get_serverCode: function() {
        return this._serverCode;
    },
    
    get_timedOut: function() {
        return this._timedOut;
    }
}

ATI.Ajax.Scripts.ExceptionHolder.registerClass('ATI.Ajax.Scripts.ExceptionHolder');

window.GetErrorDescription = function(p_obj, p_bHtml) {
    if (p_bHtml == null)
        p_bHtml = true;        
    var sSeparator = (p_bHtml ? "<br />" : "\n");    
    var _error = p_obj;    
    if (p_obj.__type == "ATI.BO.DataTransferObjects.RequestResultDTO")
        eval('_error=' + p_obj.ExceptionJSON);        
    
    return "������ ��� ������� �� ������:" + sSeparator +
            (_error._displayStackTrace ? 
                ("���������� �����: " +  _error.get_stackTrace() + sSeparator) : '') +
            "�������� ������: " + _error.get_message() + sSeparator +
            "��� ������: " + _error.get_statusCode() + sSeparator +
            (_error.get_serverCode 
				? ("��� �������: " + _error.get_serverCode() + sSeparator)
				: "") +
            "��� ������: " + _error.get_exceptionType() + sSeparator +
            (_error.get_timedOut() ? "����� �������� �������. " : "");
}



window.document.getElementByPartOfID = function (p_sNamePart, p_sTagName){
    var aReturn = [];
    var aElements = document.getElementsByTagName(p_sTagName);
    if (aElements &&
        aElements.length > 0)
    for (var i = 0; i < aElements.length; ++i)
        if (aElements[i].id &&
            aElements[i].id.indexOf(p_sNamePart) != -1)
            Array.add(aReturn, aElements[i]);
    return aReturn;   
}

Object.clone = function(p_obj) {
    var newobj = {};
    for (var prop in p_obj)
        if (p_obj[prop] == null)
            newobj[prop] = null;
        else if (typeof(p_obj[prop]) == "number" ||
            typeof(p_obj[prop]) == "string" ||
            typeof(p_obj[prop]) == "boolean" ||
            typeof(p_obj[prop]) == "function" ||
            p_obj[prop] instanceof Date)
            newobj[prop] = p_obj[prop];
    else if (p_obj[prop] instanceof Array) {
            newobj[prop] = new Array();
            for (var i = 0; i < p_obj[prop].length; ++i)
                if (typeof(p_obj[prop][i]) == "number" ||
                    typeof(p_obj[prop][i]) == "string" ||
                    typeof(p_obj[prop][i]) == "boolean" ||
                    typeof(p_obj[prop][i]) == "function" ||
                    p_obj[prop][i] instanceof Date)
                    newobj[prop][i] = p_obj[prop][i];
                else
                newobj[prop][i] = Object.clone(p_obj[prop][i]);
        }
        else
            newobj[prop] = Object.clone(p_obj[prop]);
    return newobj;
}

String.join = function(p_arr, p_separator){
    var sReturn = '';
    if (!p_arr)
        return sReturn;
    if (p_separator == null ||
        p_separator == '')
        p_separator = ',';
    if (p_arr != null && 
        p_arr instanceof Array &&
        p_arr.length > 0) {
        for (var i = 0; i < p_arr.length; ++i) {
            if (sReturn != '')
                sReturn += p_separator;
            sReturn += p_arr[i];
        }   
    }
    return sReturn;
}

String.Format = function() {
    if( arguments.length == 0 )
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

window.DoCancelEvent = function(p_event) {
    if (p_event != null) {
        var domEventVar = new Sys.UI.DomEvent(p_event);
        domEventVar.preventDefault();
        domEventVar.stopPropagation();
    }
};

Function.isFunction = function(fun) {
    return typeof (fun) == "function";
};

if (String.isNullOrEmpty == null) {
    String.isNullOrEmpty = function(str) {
        return str == null || str == '';
    }
};

window.openLoginIfNeeded = function(domEvent, sender, handler) {
    var result = true;
    if (window["OnProtectedLinkClick"]) {
        var result = OnProtectedLinkClick(sender, handler);
        if (domEvent) {
            window.DoCancelEvent(domEvent);
        }
    }
    return result;
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();