﻿var popupStatus = 0;

function ajaxVentana(pagina, id, titulo, divTitulo, campoImagen, imagen, idPersona, idTemas, masInfo, puesto, correo, movil, telefono, fax) {//ajaxVentana
    var divCargando = $("#divCargandoDir");
    mostrarDiv(divCargando);

    centerPopupContacto();
    loadPopupContacto();

    var div = $('#' + id);
    var divTitulo = $('#' + divTitulo);
    var divImagen = $('#' + campoImagen);

    divImagen.html("<img src='images/centroContacto/" + imagen + "'/>");

    div.load(pagina, function (response, status, xhr) {

        if (idPersona != null) {
            $("input[name=codigoUsuariosDestino]").val(idPersona);
        }

        if (idTemas != null) {
            $("input[name=codigoTemas]").val(idTemas);
        }

        if (pagina == "csChat.htm" || pagina == "csChatEng.htm") {
            estadoInicial();
        }

        if (masInfo) {
            informacionLlenar(puesto, correo, movil, telefono, fax);
        }

        if (status == "error") { div.html("hola: " + xhr.status + " " + xhr.statusText); }
        divTitulo.html(titulo);
    });

    ocultarDiv(divCargando);
}

function loadPopupContacto() {
    //carga el popup solo si esta deshabilitado
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContenidoContacto").fadeIn("slow");
        popupStatus = 1;
    }
}

//Deshabilitar el popup
function disablePopupContacto() {

    //Deshabilita el popup solo si esta cargado
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContenidoContacto").fadeOut("slow");
        popupStatus = 0;
    }
}

//Centra el popup
function centerPopupContacto() {
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContenidoContacto").height();
    var popupWidth = $("#popupContenidoContacto").width();
    //centering
    $("#popupContenidoContacto").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });

    //Necesario sólo para IE6
    $("#backgroundPopup").css({
        "height": windowHeight
    });

}

