var divFlotante = "divContenidoPopupCentro";
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function posicionarDIVpopupCentral() {
    var scrollTop = document.documentElement.scrollTop;
    var XpositionDIV = (document.documentElement.clientWidth/2) - (document.getElementById('divContenedorPopupCentro').clientWidth/2);
    var YpositionDIV = (document.documentElement.clientHeight/2) - (document.getElementById('divContenedorPopupCentro').clientHeight/2) + scrollTop;
    if(YpositionDIV < 0) {
        YpositionDIV = 10;
    }
    if (window.innerHeight || window.opera) {
        var pageHeight = window.innerHeight + window.scrollMaxY;
        //var YpositionDIV = window.innerHeight + window.outerHeight;
    } else if (document.body) {
        //var YpositionDIV = document.documentElement.clientHeight + document.getElementById('divContenedorPopupCentro').clientHeight + scrollTop;
        var pageHeight = document.body.offsetHeight;
    }
    //alert(document.getElementById('divContenedorPopupCentro').clientHeight);

    document.getElementById('divContenedorPopupCentro').style.left = XpositionDIV+'px';
    document.getElementById('divContenedorPopupCentro').style.top =  YpositionDIV+'px';

    document.getElementById('divContenedorPopupCentro').style.visibility = "visible";
    document.getElementById('divPantallaNegra').style.top = '0px';
    document.getElementById('divPantallaNegra').style.visibility = "visible";
    document.getElementById('divPantallaNegra').style.width = document.documentElement.clientWidth+'px';
    document.getElementById('divPantallaNegra').style.height = pageHeight+'px';

    if($.browser.msie) {
        if(typeof document.forms!='undefined') {
            for(var i=0;i<=document.forms.length;i++) {
                if(typeof document.forms[i]!='undefined') {
                    $( document.forms[i].elements ).hide();
                }
            }
        }
    }

    $('#impacte').hide();
    return false;
}

function cerrar(divId) {
    if(document.getElementById(divId)) {
        if(document.getElementById('divContenedorPopupCentro').style.visibility == "visible") {
            if(document.getElementById('divPantallaNegra')) {
                document.getElementById('divPantallaNegra').style.visibility = "hidden";
            }
            document.getElementById('divContenedorPopupCentro').style.visibility = "hidden";
            if($.browser.msie) {
                if(typeof document.forms!='undefined') {
                    for(var i=0;i<=document.forms.length;i++) {
                        if(typeof document.forms[i]!='undefined') {
                            $( document.forms[i].elements ).show();
                        }
                    }
                }
            }
            $('#impacte').show();
        }
        document.getElementById(divId).innerHTML = "";
    }
    return false;
}

function exitBonoHoras() {
    var _values_send = "aj_op=exitBonoHoras"; //variables
    getPlainText(_values_send,'bonosCuerpo');
}
function sendLoginBonosForm() {
    var _values_send = "aj_op=loginBonosForm&codEwn="+$('#idCodEwn').val()+"&passEwn="+$('#idPassEwn').val(); //variables
    getPlainText(_values_send,'bonosCuerpo');
}
function getDetailedBonosClient(start) {
    if(typeof start == 'undefined') {
        start = "";
    }
    var _values_send = "aj_op=getDetailedBonosClient&start="+start; //variables
    getPlainText(_values_send,'bonosCuerpo');
}
function getPassCliHot() {
    var _values_send = "aj_op=getPassCliHot"; //variables
    getPlainText(_values_send,'bonosCuerpo');
}
function modPassCliHot(newpass) {
    var _values_send = "aj_op=modPassCliHot&newpass="+newpass; //variables
    getPlainText(_values_send,'bonosCuerpo');
}

function getPlainText(_values_send,divId) {
    $.ajax({
        type: "POST",
        url: "bono_horas.php",
        data: _values_send,
        beforeSend: function() {
            var loading = "<div style='font-weight: bold; border: 1px dotted #ccc; background-color: #fff; text-align: center; margin: 20px 10px; padding: 50px;'>Cargando ... <br/><img src='/images/ajax-loader.gif'/></div>";
            $('#'+divId).html(loading);
        },
        success: function(_retorno){
            //$('#'+divId).html(msg);
            _retorno = unescape(_retorno);
            _retorno=_retorno.replace(/\+/gi," ");
            //alert(_retorno);
            //document.getElementById(divId).innerHTML=_retorno;
            $('#'+divId).html(_retorno);
            if(divId == divFlotante) {
                posicionarDIVpopupCentral();
            }
        }
    });
}