﻿    //AJAX REQUEST
function StringBuffer() { this.buffer = []; }
StringBuffer.prototype.append = function(string) { this.buffer.push(string); return this; }
StringBuffer.prototype.toString = function() { return this.buffer.join(""); }

//Monta Drop Downs Produtos
var From = "";
function GeraDropDown() {
    var valor = "";
    From = arguments[0];
    
    if (arguments[3] != null) 
        valor += "&" + arguments[3] + "=" + document.getElementById(arguments[4]).value;

    if (arguments[5] != null)
        valor += "&" + arguments[5] + "=" + document.getElementById(arguments[6]).value;

    $("." + From + " .select-text").html('<img style="width:12px" src="img/loads/load.gif"> Carregando...');
    doRequest('server.aspx?action=' + arguments[0] + '&id=' + arguments[1] + '&ret=' + arguments[2] + valor, MontaDropDow);
}

function MontaDropDow() {
    var i, x, DDL;
    var f = eval('(' + arguments[0] + ')');

    try {
        for (i = 0; i < f.length; i++) {
            DDL = document.getElementById(f[i]["RET"]);
            DDL.length = 0;

            var ID = f[i]["ID"].split(",");
            var NOME = f[i]["NOME"].split(",");

            for (x = 0; x < ID.length; x++) {
                DDL.options[x] = new Option(NOME[x], ID[x]);
            }
        }
        DDL.value = 0;
        $("." + From + " .select-text").html('_Selecione');
    }
    catch (e) { alert(e); }
}

function UnSel() {
    var Objs = arguments;

    for (var i in Objs) {
        $("." + Objs[i] + " .select-text").html('_Selecione');
        $("." + Objs[i] + "x").removeOption(/./);
        $("." + Objs[i] + "x").addOption("0", "_Selecione"); 
        $("." + Objs[i] + "x").selectOptions("0", true);
    }
}
