/**
 * Class responsavel em pegar dados do formularios
 * @autor Cristian Cardoso
 * @atualizacao 30/07/2009
 * @hora 10:50
 * @vercao 0.1.3
 */
//if (PegaDadosFormulario == undefined) var PegaDadosFormulario = {};
//PegaDadosFormulario = function() {};

//PegaDadosFormulario.prototype = {
var PegaDados = {
    Informacoes : "",
    valida : '',

    Formulario : function(form, valida)
    {
        this.valida = (valida == undefined || valida == '') ? true : valida;

        this.Informacoes = "form=" + form;
        var frm = document.forms[form];
        var numElementos = frm.elements.length;
        for (var i = 0; i < numElementos; i++)
        {
            var campo = frm.elements[i];
            switch (campo.type)
            {
                case "radio":
                    this.PegaDadosRADIO(campo);
                    break;
                case "checkbox":
                    this.PegaDadosCHECKBOX(campo);
                    break;
                case 'select-multiple' :
                    this.PegaDadosSELECTMULTIPLE(campo);
                    break;
                case "button":
                case "reset":
                case "submit":
                    break;
                default:
                    this.PegaDadosPADRAO(campo);
                    break;
            }

        }
        return this.Informacoes;
    },

    PegaDadosPADRAO : function(campo)
    {
        if (this.Informacoes.indexOf('&' + campo.name + '=') == -1){
            if (campo.getAttribute("valida") == null)
            {
                if(this.valida)
                {
                    this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(campo.value) + "&" + campo.name + "_Valida=" + encodeURIComponent(",,," + campo.type);
                }
                else
                { 
                    this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(campo.value);
                }
            }
            else
            {
                if(this.valida)
                {
                    this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(campo.value) + "&" + campo.name + "_Valida=" + encodeURIComponent(campo.getAttribute("valida") + "," + campo.type);
                }
                else
                {
                    this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(campo.value);
                }
            }
        }
    },
		
    PegaDadosCHECKBOX : function(campo)
    {
        if (campo.checked == true) this.PegaDadosPADRAO(campo);
    },
    
    PegaDadosRADIO : function(campo)
    {
        var obj = this.GetName(campo.name);
        for (var i = 0; i < obj.length; i++)
        {
            if (obj[i].checked)
            {
                //alert (obj[i].value);
                this.PegaDadosPADRAO(obj[i]);
            }
        }
    },

    PegaDadosSELECTMULTIPLE : function(campo)
    {
        var valores = '';
        for(var i = 0; i < campo.options.length; i++)
        {
            if(campo.options[i].selected)
            {
                if (valores == '')
                {
                    valores = campo.options[i].value;
                }
                else
                {
                    valores += ';' + campo.options[i].value;
                }
            }
        }

        if (campo.getAttribute("valida") == null)
        {
            if(this.valida)
            {
                this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(valores) + "&" + campo.name + "_Valida=" + encodeURIComponent(",,," + campo.type);
            }
            else
            {
                this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(valores);
            }
        }
        else
        {
            if(this.valida)
            {
                this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(valores) + "&" + campo.name + "_Valida=" + encodeURIComponent(campo.getAttribute("valida") + "," + campo.type);
            }
            else
            {
                this.Informacoes += "&" + campo.name + "=" + encodeURIComponent(valores);
            }
        }
    },
    
    GetName : function(elemento)
    {
        return document.getElementsByName(elemento);
    }

};
//var PegaDados = new PegaDadosFormulario();

