/**
 * @author Leandro Baena Torres
 */
function actualizarIdioma(_idioma){
    enviar("actualizarIdioma.cfm", "idioma=" + _idioma, "evaluar", "");
    setTimeout("document.location.reload()", 1000);
}

/**
 * Encuentra el alto de la pagina que ha bajado con el scroll
 * @return int
 */
function getPageScroll(){
    var yScroll;
    
    if (self.pageYOffset) { //Firefox, Safari, Opera
        yScroll = self.pageYOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) { // IE 6
            yScroll = document.documentElement.scrollTop;
        }
        else 
            if (document.body) { // otros IE
                yScroll = document.body.scrollTop;
            }
    return yScroll;
}

/**
 * Encuentra el tama&ntilde;o de la pagina
 */
function getPageSize(){
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else 
        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        }
        else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    
    var windowWidth, windowHeight;
    
    if (self.innerHeight) { // all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    }
    else 
        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        }
        else 
            if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
    
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }
    
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    }
    else {
        pageWidth = windowWidth;
    }
    
    return [pageWidth, pageHeight, windowHeight];
}

/**
 * Oculta el mensaje de alerta
 */
function ocultarMensaje(){
    document.getElementById("overlay1").style.display = "none";
}

/**
 * Configura y muestra el mensaje de alerta
 */
function mostrarMensaje(_titulo, _texto, _dir){
    var arrayPageSize = getPageSize();
    var lightboxTop = getPageScroll() + arrayPageSize[2]/2 - 70;
    var lightboxLeft = ((arrayPageSize[0]) / 2) - 100;
    
    document.getElementById("mensaje").style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
    document.getElementById("mensaje").style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
    document.getElementById("tituloMensaje").innerHTML = _titulo;
    document.getElementById("textoMensaje").innerHTML = _texto;
    document.getElementById("overlay1").style.height = (arrayPageSize[1] + 'px');
    document.getElementById("overlay1").style.display = "block";
    document.getElementById("aceptarMensaje").focus();
    document.getElementById('aceptarMensaje').onclick = function(){
        ocultarMensaje();
        if (_dir != "") {
            irA(_dir);
        }
    }
}

/**
 * Valida si los campos del formulario est&aacute;n diligenciados
 */
function validarLogin(){
    if (document.formLogin.user.value == "") {
        mostrarMensaje("Error en el usuario", "Ingrese su usuario para ingresar al sistema", "");
        return false;
    }
    if (document.formLogin.password.value == "") {
        mostrarMensaje("Error en la contrase&ntilde;a", "Ingrese su contrase&ntilde;a para ingresar al sistema", "");
        return false;
    }
    return true;
}

/**
 * Cambia la p&aacute;gina actual del navegador
 */
function irA(_dir){
    document.location.href = _dir;
}
