var AjaxLoaderLarge = "Operacao/SourceDTOP/AjaxLoaderLarge"
var loadingFCV = "<div style=\"margin: 0 auto;text-align:center\"><img src=\"" + urlGlobal + AjaxLoaderLarge + "\" alt=\"\" width=\"64\" height=\"64\" /></div></div>";
function atualizarFCV(obj, codigoFcv) {
    obj.html(loadingFCV);
    var url = urlGlobal;
    url += "Operacao/Detalhes/Fcv/";
    url += "?fcv=";
    url += codigoFcv;

    $(obj).load(url, function () {
        $(this)
            .find(".btn.btn-mini.btn-info-fcv.btn-warning")
                .each(function () {
                    $(this)
                    .removeClass("btn-warning")
                    .addClass("disabled")
                    .unbind("click");
                    $(this).attr("disabled", "disabled");
                });
    });
}

var fcv_template = "<div id='{divId}' class='hide modal-fcv' title='{title}'>";
fcv_template += "<div id='modal-fcv-conteudo_{id}' class='modal-body modal-body-fcv'>";
fcv_template += "</div>";
//fcv_template += "<button type='button' class='btn btn-info' style='float: right;margin-right: 4px;' ";
//fcv_template += "onclick=\"";
//fcv_template += "javascript:atualizarFCV($('#modal-fcv-conteudo_{id}'), {id});\">";
//fcv_template += "Atualizar</button>";
fcv_template += "</div>";
function carregarFCV(fcv) {
    var divId = "fcv_" + fcv.Codigo(),
        div = null;

    div = $("#" + divId);

    if (div.length == 0) {
        var newDiv = fcv_template;
        newDiv = newDiv.replace(/{divId}/g, divId);
        newDiv = newDiv.replace(/{id}/g, fcv.Codigo());
        newDiv = newDiv.replace(/{title}/g, fcv.Descricao());
        $("#fcvs").append(newDiv);

        div = $("#" + divId);

        div.dialog({
            autoOpen: false,
            modal: false,
            draggable: true,
            resizable: false,
            width: 575,
            position: ['center', 45],
            show: "blind",
            dialogClass: "dialog-fcv",
            open: function () {
                atualizarFCV($("#modal-fcv-conteudo_" + fcv.Codigo()), fcv.Codigo());
            },
            close: function (ev, ui) {
                $("#" + divId).remove();
            }
        });
    }

    div.dialog("open");
}

function showModalInfoTerminal(o) {
    var divId = "#fcvInfoTerminal" + o.id;

    divId += "_" + o.modeloTerminal;

    $div = $(divId);
    $tr = $div.closest("tr");
    $tr.toggleClass("info-adicional-hide");
    if (!$tr.hasClass("info-adicional-hide")) {
        $('body').data("codTerminalAux", o.codigo)
        atualizarFCVInfoTerminal($div.get(0), o.carregarLinha); //passa somente o objeto HtmlElement
    }
}


function atualizarFCVInfoTerminal(obj, carregarLinha) {
    $(obj).html(carregandoFCV);
    var url = urlGlobal;
    url += "Operacao/Detalhes/InfoAdicional";
    url += "?codTerminal=";
    url += $('body').data("codTerminalAux");
    url += "&carregarLinha=";
    url += carregarLinha;

    $(obj).load(url, function (response, status, xhr) {
        if (status == "error") {
            alert("ERRO: [" + response + "]");
            return;
        }
    });
}