function formata(o, f) {
    v_obj = o;
    v_fun = eval('formata_' + f);
    setTimeout("executa()", 1);
}

function executa(){
    v_obj.value = v_fun(v_obj.value);
}

function formata_inteiro(v){
    return v.replace(/\D/g,"");         //Remove tudo o que não é dígito
}

function formata_decimal(v) {
    v = v.replace(",", ".");        // Troca eventual vírgula por ponto
    v = v.replace(/[^\d.]/g,"");    // Elimina todos os caracteres que não são ponto decimal e números

    // Mantem somente o primeiro ponto decimal. Os demais serão ignorados
    aux = "";
    for (i = 0; i < v.split(".").length; i++) {
        if (i ==  1) {
            aux = aux + ".";
        }
        aux = aux + v.split(".")[i];
    }

    return aux;
}

// Inicio da função Numerico
function Numerico(objValor, iDecimais) {
    sValor = objValor.value;

    // Somente formata caso tenha conteudo
    if (sValor != "") {
        // Coloca o número de decimais informado
        if (sValor.indexOf(".") != -1) {
            sInteiros = sValor.substring(0, sValor.indexOf("."));
            sDecimais = sValor.substring(sValor.indexOf(".") + 1, sValor.length);
        } else {
            sInteiros = sValor;
            sDecimais = "";
        }
        if (sInteiros == "") {
            sInteiros = "0";
        }
        for (i = 0; i < iDecimais; i++) {
            sDecimais = sDecimais + "0";
        }

        // Pega somente o número de decimais informado
        sDecimais = sDecimais.substring(0, iDecimais);

        if (iDecimais > 0) {
            objValor.value = sInteiros + "." + sDecimais;
        } else {
            objValor.value = sInteiros;
        }
    }
}
// Fim da função Numerico

function MontaURL(formulario) {
    var URL = "";
    var i = 0;
    var arr = new Array(0);

    if (formulario == undefined) {
        formulario = "principal";
    }

    // Verifica se o objeto existe
    if (document.getElementById(formulario) != undefined) {

        elementos = document.getElementById(formulario).elements;

        // Monta a URL contendo todos os filtros possíveis
        var iQtde = elementos.length;

        // Pega todos os objetos que estejam marcados ou selecionados (checkbox e radio)
        while (i < iQtde) {
			elemento = elementos[i];
            if (((elemento.type == "checkbox") && elemento.checked) ||
                ((elemento.type == "radio") && elemento.checked) ||
                 (elemento.type != "checkbox") && (elemento.type != "radio")) {

                if (elemento.type != "radio") {
                    arr.push(elemento.id + "=" + escape(elemento.value));
                } else {
                    arr.push(elemento.name + "=" + escape(elemento.value));
                }
            }
			
            i++;
        }
    }

    URL = arr.join("&");

    return URL;
}


// função ajax:
// gtr_makeRequest(url,div);

