﻿function PreencheCombo(sender, eventarqs) {
    if (sender._uniqueId.indexOf("$") != -1)
        $get("NomeEvento").value = "PreencheCombo" + sender._uniqueId.substring(sender._uniqueId.indexOf("$") + 1, sender._uniqueId.length);
    else
        $get("NomeEvento").value = "PreencheCombo" + sender._uniqueId;
    document.getElementById("BtEvento").click();
}

function DataInvalida(sender, args) {
    sender.set_selectedDate();
}

function Funcoes(sender, eventArgs) {
    if (eventArgs.get_item().get_value() == "Incluir") {
        window.location.search = window.location.search.substr(0, window.location.search.indexOf('=')) + "=0";
        window.location;
    }
    if (eventArgs.get_item().get_value() == "Excluir") {
        document.getElementById("BtExclui").click();
    }
    if (eventArgs.get_item().get_value() == "Sair") {
        CloseAndRebind();
    }
    if (eventArgs.get_item().get_value() == "Gravar") {
        $get("NomeEvento").value = "Gravar";
        document.getElementById("BtGravar").click();
    }
}

function ExecutaMensagem(sender, args) {
    if (sender._minimizeIconUrl != "")
        AcionaEvento(sender._minimizeIconUrl);
}

function Posiciona(campo) {
    var obj = document.getElementById(campo + "_text");
    if (obj != null)
        obj.focus();
}

function CloseAndRebind(args) {
    var oArg = new Object();
    var oWnd = GetRadWindow();
    oWnd.close(oArg);
    oWnd.BrowserWindow.refreshGrid(args);
}

function CloseForm(args) {
    var oArg = new Object();
    var oWnd = GetRadWindow();
    oWnd.close(oArg);
}

function GetRadWindow() {
    var oWindow = null
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
    return oWindow;
}

function RowDblClickConsultasRapidas(sender, eventArgs) {
    var oArg = new Object();
    arrayCampo = document.all["Retorno"].value.split(',');
    oArg.chave = "";
    for (var i = 0; i < arrayCampo.length; i++) {
        oArg.chave = oArg.chave + arrayCampo[i] + "=" + eventArgs.getDataKeyValue(arrayCampo[i]) + ";";
    }
    var oWnd = GetRadWindow();
    oWnd.close(oArg);
}
//]]>
function CancelEdit() {
    GetRadWindow().Close();
}
function ConfirmaAlerta(arg) {

    if (arg == true) {
        $get("NomeEvento").value = document.getElementById("EventoSIM").value;
    } else {
        $get("NomeEvento").value = document.getElementById("EventoNAO").value;
    }
    document.getElementById("BtEvento").click();
}

function AcionaEvento(Evento) {
    $get("NomeEvento").value = Evento;
    document.getElementById("BtEvento").click();
}
function AcionaEventoAjax(Evento) {
    $get("NomeEvento").value = Evento;
    document.getElementById("BtEventoAjax").click();
}


function AcionaConsulta(Consulta) {
    $get("NomeConsulta").value = Consulta;
    document.getElementById("BtConsulta").click();
}


window.blockConfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle) {
    var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually 
    //Cancel the event 
    ev.cancelBubble = true;
    ev.returnValue = false;
    if (ev.stopPropagation) ev.stopPropagation();
    if (ev.preventDefault) ev.preventDefault();

    //Determine who is the caller 
    var callerObj = ev.srcElement ? ev.srcElement : ev.target;

    //Call the original radconfirm and pass it all necessary parameters 
    if (callerObj) {
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again. 
        var callBackFn = function(arg) {
            if (arg) {
                callerObj["onclick"] = "";
                if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz 
                else if (callerObj.tagName == "A") //We assume it is a link button! 
                {
                    try {
                        eval(callerObj.href)
                    }
                    catch (e) { }
                }
            }
        }

        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
    }
    return false;
}
var CampoTela;
function openWin(top, left, width, height, consulta, campoTela) {
    CampoTela = campoTela;
    var oWnd = radopen("../ControlesDEV/ConsultasRapidas.aspx?consulta=" + consulta, "RadWindowConsulta");
    oWnd.set_width(width);
    oWnd.set_height(height);
    oWnd.moveTo(top, left);
}
function openWin(top, left, width, height, consulta, campoTela, param) {
    CampoTela = campoTela;
    var oWnd = radopen("../ControlesDEV/ConsultasRapidas.aspx?consulta=" + consulta + "&" + param, "RadWindowConsulta");
    oWnd.set_width(width);
    oWnd.set_height(height);
    oWnd.moveTo(top, left);
}

function OnClientCloseConsultasRapidas(oWnd, args) {
    var arg = args.get_argument();
    if (arg) {
        arrayCampo = arg.chave.split(';');
        nomeCampo = arrayCampo[0].split('=');
        $get(CampoTela).value = nomeCampo[1];
        $get(CampoTela + "_text").value = nomeCampo[1];
        if (arrayCampo.length > 2) {
            nomeCampo = arrayCampo[1].split('=');
            if ($get(CampoTela + "1") != null) {
                $get(CampoTela + "1").value = nomeCampo[1];
            }
            if ($get(CampoTela + "1_text") != null) {
                $get(CampoTela + "1_text").value = nomeCampo[1];
            }
            if (arrayCampo.length > 3) {
                document.all["Retorno"].value = CampoTela + "=" + nomeCampo[1] + ";" + arg.chave;
                AcionaEvento("AtualizaConsultaRapida");
            }
        }
    }
}

function OpenFileExplorerDialog(campoTela) {
    CampoTela = campoTela;
    var wnd = $find("ExplorerWindow");
    wnd.show();
}
function OpenConexao(campoTela) {
    CampoTela = campoTela;
    var wnd = $find("Conexao");
    wnd._navigateUrl = "../ControlesDev/Conexao.aspx?StringConnec=" + $get(CampoTela).value;
    wnd.show();
}

function OnFileSelected(oWnd, args) {
    var arg = args.get_argument();
    if (arg != null) {
        $get(CampoTela).value = arg;
        $get(CampoTela + "_text").value = arg;
    }
}

function FechandoConexao(oWnd, args) {
    var arg = args.get_argument();
    if (arg != null) {
        $get(CampoTela).value = arg;
        $get(CampoTela + "_text").value = arg;
    }
}
 