﻿function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

function cloneValues(originId, destinationId) {
    var ctrlOrigen = document.getElementById(originId);
    var ctrlDestino = document.getElementById(destinationId);
    if (ctrlOrigen != null && ctrlDestino != null)
        ctrlDestino.value = ctrlOrigen.value;
}

function cloneMultiValues(originId1, originId2, destinationId) {
    var ctrlOrigen1 = document.getElementById(originId1);
    var ctrlOrigen2 = document.getElementById(originId2);
    var ctrlDestino = document.getElementById(destinationId);
    if (ctrlOrigen1 != null && ctrlOrigen2 != null && ctrlDestino != null)
        ctrlDestino.value = ctrlOrigen1.value + ' ' + ctrlOrigen2.value;
}

/* -------------------------------------------------------------------------------------
*   Visualización y ocultación del indicador de actualización.
* ------------------------------------------------------------------------------------- */

function showUpdateProgress() {
    setLoadingDisabled(true);
}

function hideUpdateProgress() {
    setLoadingDisabled(false);
}

/* -------------------------------------------------------------------------------------
*   Activación y desactivación de todos los elementos de una capa
* ------------------------------------------------------------------------------------- */

function setLoadingDisabled(disabled) {
    var dvLoadingLayer = document.getElementById("dvLoadingLayer");
    var dvLoadingIndicator = document.getElementById("dvLoadingIndicator");
    if (disabled) {
        dvLoadingLayer.style.position = "fixed";
        dvLoadingLayer.style.left = "0px";
        dvLoadingLayer.style.top = "0px";
        dvLoadingLayer.style.width = "100%";
        dvLoadingLayer.style.height = document.documentElement.clientHeight + "px";
        dvLoadingLayer.style.zIndex = 10000;
        dvLoadingLayer.style.display = "";

        dvLoadingIndicator.style.position = "fixed";
        dvLoadingIndicator.style.left = ((document.documentElement.clientWidth - 175) / 2) + "px";
        dvLoadingIndicator.style.top = ((document.documentElement.clientHeight - 100) / 2) + "px";
        dvLoadingIndicator.style.display = "";
        dvLoadingIndicator.style.zIndex = 10001;
    }
    else {
        dvLoadingLayer.style.display = "none";
        dvLoadingIndicator.style.display = "none";
    }
}
