//******************Show/Hide objects methods begin******************
function ShowObjects(arrIdList) {
    if (arrIdList == null) return;
    for (var i = 0; i < arrIdList.length; i++)
        ShowObject(this.$(arrIdList[i]));
}
function HideObjects(arrIdList) {
    if (arrIdList == null) return;
    for (var i = 0; i < arrIdList.length; i++)
        HideObject(this.$(arrIdList[i]));
}
function ShowObject(obj) {
    if (obj == null) return;
    obj.style.display = 'block';
    obj.style.visibility = 'visible';
}
function HideObject(obj) {
    if (obj == null) return;
    obj.style.display = 'none';
    obj.style.visibility = 'hidden';
}
function ShowObjectById(id) {
    if (id == null) return;
    var obj = $(id);
    if (obj == null) return;
    obj.style.display = 'block';
    obj.style.visibility = 'visible';
}
function HideObjectById(id) {
    if (id == null) return;
    var obj = $(id);
    if (obj == null) return;
    obj.style.display = 'none';
    obj.style.visibility = 'hidden';
}
//******************Show/Hide objects methods end********************
//*********Disable / Enable validators on client side begin**********
function DisableValidator(valid) {
    var val = $(valid);
    if (val == null) return;
    ValidatorEnable(val, false);
}
//Function for enabling validator on client side
function EnableValidator(valid) {
    var val = $(valid);
    if (val == null) return;
    ValidatorEnable(val, true);
}
//Disable all validators
function DisableValidators() {
    if (typeof (Page_Validators) != 'undefined' && Page_Validators != null) {
        for (var i = 0; i < Page_Validators.length; i++)
            ValidatorEnable(Page_Validators[i], false);
    }
}
//*********Disable / Enable validators on client side end************
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function RemoveChildren(element) {
    for (var i = element.childNodes.length - 1; i >= 0; i--)
        element.removeChild(element.childNodes(i));
}
function GetElementsByClassName(className, tag, elm) {
    var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all) ? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for (var i = 0; i < length; i++) {
        current = elements[i];
        if (testClass.test(current.className)) {
            returnElements.push(current);
        }
    }
    return returnElements;
}
//<array>.exists(<value>). Returns true, if <value> exists in <array>, and false, if it doesn't.
Array.prototype.exists = function(x) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == x) return true;
    }
    return false;
}
//Removes given item from array if item exists
Array.prototype.removeItem = function(x) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == x) {
            this.splice(i, 1);
        }
    }
}
function ShowAsyncErrorMessage(details) {
    HideTaskProgress();
    isInProcess = false;
    if (details.indexOf('There was an error processing the request.') > -1) {
        if (self != top)
            window.top.location.href = '../main/AutoLogoffPage.aspx';
        else
            window.location.href = '../main/AutoLogoffPage.aspx';
    }
    else {
        var msg = 'An error occurred on server side.\n\n' + details;
        alert(msg);
    }
}
function ActionResult(result) {
    var arr = result.split('###');
    if (arr.length != 5) {
        alert('Wrong action result.');
        return;
    }
    this.Message = arr[0];
    this.IsCompleted = (arr[1] == 'True' || arr[1] == 'true');
    this.EntityId = parseInt(arr[2]);
}
function IsDate(value) {
    return (!isNaN(new Date(value).getYear()));
}
function ObjectPosition(obj) {
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}
function EncodeMessage(msg) {
    return msg.replace(/<br>/gi,"\n");
}
function OpenWindow(address) {
    window.open(address, "", "status,height=400,width=600,scrollbars,resizable");
}
