if(window.back==undefined) {
    window.back = function() {
        window.history.back(-1);
    }
}

/** Dispara un evento de webFlow
 * @param frm formulario
 * @param eventName Nombre del evento.
 * @param formFieldName nombre del campo para asignar un valor.
 *        Si no existe se crea uno dentro del formulario. Opcional
 * @param formFieldValue valor a asignar a formFieldName
 */
function fireWebFlowEvent(frm, eventName, formFieldName, formFieldValue) {
    if (frm==null || frm==undefined) {
        frm = document.createElement("FORM");
        document.body.appendChild(frm);
    }


    var creadoEvenField=false;
    var eventField = frm["_eventId"];
    if (eventField==undefined) {
        eventField = document.createElement("input");
        eventField.type="hidden";
        eventField.name="_eventId";
        frm.appendChild(eventField);
        creadoEventField=true;
    }
    eventField.value=eventName;
    if (formFieldName!=undefined && formFieldValue!=undefined) {
        if (frm[formFieldName]==undefined) {
            var i = document.createElement("input");
            i.type="hidden";
            i.name=formFieldName;
            frm.appendChild(i);
            i.value=formFieldValue;
        } else {
            frm[formFieldName].value=formFieldValue;
        }
    }
    if (frm.onsubmit!=undefined) {
        frm.onsubmit();
    }
    frm.submit();

    if (creadoEventField) {
        frm.removeChild(eventField);
    }
}

try {
    Calendar._TT["ABOUT"]=Calendar._TT["ABOUT"].split("\n\n")[1];
} catch(e) {}

Menu = {
    onShowSubmenu : false,
    currentSubMenu : null,
    hideSubmenu : function(submenu) {
        if (submenu!=undefined && submenu!=null) {
            submenu.style.display="none";
        }
    },

    calcLeft : function(o) {
        return o.offsetLeft+(o.offsetParent!=null?Menu.calcLeft(o.offsetParent):0);
    },

    calcTop : function(o) {
        return o.offsetTop + (o.offsetParent!=null?Menu.calcTop(o.offsetParent):0);
    },

    showSubmenu : function(button, submenu) {
        Menu.currentSubMenu = submenu;
        submenu.style.left=Menu.calcLeft(button)+"px";
        if (window.event!=undefined) {
            submenu.style.top=(Menu.calcTop(button) + button.offsetHeight) +"px";
        } else {
            submenu.style.top=(Menu.calcTop(button) + button.offsetHeight) +"px";
        }
        submenu.style.display="block";
    },

    onMouseOverMenu : function(obj) {
        Menu.onShowSubmenu=true;
        if (Menu.currentSubMenu!=null) {
            Menu.hideSubmenu(Menu.currentSubMenu);
            Menu.currentSubMenu = null;
        }

        var baseName = String(obj.id);
        baseName = baseName.substring(0,baseName.length-2);

        var button = document.getElementById(baseName);
        var submenu = document.getElementById(baseName+"_submenu");

        if (submenu!=null && submenu!=undefined) {
            Menu.showSubmenu(button, submenu);
        }
        Menu.onShowSubmenu=false;
    },

    onMouseOutMenu : function(obj) {
        if (Menu.currentSubMenu!=null) {
            Menu.hideSubmenu(currentSubMenu);
        }
        Menu.currentSubMenu = null;
    }
};

Blink = {
    blink : function() {
        for (var i=0; i < Blink.objects.length; i++) {
            var o = Blink.objects[i];
            if (o.blink_color==undefined) {
                o.blink_color=o.style.color;
                o.blink_onmouseover=o.onmouseover;
                o.blink_onmouseout=o.onmouseout;
                o.onmouseover=null;
                o.onmouseout=null;
            }
            if (Blink.status) {
                o.blink_onmouseover();
            } else {
                o.blink_onmouseout();
            }
            //o.style.color = Blink.status?"white":o.blink_color;
        }
        Blink.status=!Blink.status;
    },
    status : false,
    objects : []
}


setInterval("Blink.blink()", 500);

function Grilla(n, cntfr, cnt) {
    var cntp = String(cnt/cntfr);
    cntp = cntp.substring(0,cntp.indexOf("."));
    cntp = Number(cntp)+1;
    return {
        irPagina : function(pagina) {
            this.setVisiblePagina(this.pagina,false);
            this.pagina = pagina;
            this.setVisiblePagina(this.pagina,true);
            try {
                document.getElementById(this.nombre+"_pagina_corriente").innerHTML=this.pagina+1;
                document.getElementById(this.nombre+"_pagina_total").innerHTML=cntp;
            } catch(e) {}
        },
        paginar : function(direccion) {
            var p=this.pagina+direccion;
            if (p < 0) {
                return;
            }
            var yy=p*this.cantidadFilasPorPagina;
            if (yy > this.cantidadFilas) {
                return;
            }
            this.irPagina(p);
        },
        nombre : n,
        cantidadFilas : cnt,
        cantidadFilasPorPagina : cntfr,
        cantidadPaginas : cntp,
        pagina : 0,
        setVisiblePagina : function(pagina,show) {
            for (var y = 0; y < this.cantidadFilasPorPagina; y++) {
                var yy=(this.pagina*this.cantidadFilasPorPagina)+y;
                if (yy >= this.cantidadFilas) {
                    break;
                }
                var id="grilla_"+this.nombre+"_"+yy;
                document.getElementById(id).style.display=(show ? "" : "none");
            }
        }
    }
}

