/**
 * @author mauricio
 */
(function() {

    YAHOO.namespace("LOGIN_SYS");
    var LOGIN_SYS = YAHOO.LOGIN_SYS;
    TABFRWK.TABWEB.LOGIN_SYS = YAHOO.LOGIN_SYS;

    TABFRWK.TABWEB.LOGIN_SYS.setFormLogin = function(){
        
        /*var LOGIN_CHECKBOX = new inputEx.CheckBox({
            rightLabel: 'Pasaporte',
            parentEl: 'field_check_login',
            sentValues: ['YES', 'NO'],
            value: ''
        });*/

        /*var LOGIN_RUT = new inputEx.StringField( {
            label : '',
            value : '',
            size : 20,
            parentEl : 'field_rut_login'
        });

        var LOGIN_CLAVE = new inputEx.StringField( {
            label : '',
            value : '',
            size : 20,
            parentEl : 'field_clave_login'
        });*/

        var div = YAHOO.util.Dom.get('field_button_login');

        var buttonCreate = new YAHOO.widget.Button( {
            label : "Entrar",
            id : "buttonCreate",
            container : div
        });

        var sendFormData = function() {

            //vb_CheckBox = LOGIN_CHECKBOX.getValue();
            vt_rutValue = YAHOO.util.Dom.get('field_rut_login').value;
            vt_ClaveValue = YAHOO.util.Dom.get('field_clave_login').value;

            vbSaveData = 'YES';
            if(vbSaveData=='YES'){

                /*if(vb_CheckBox=='NO'){
                    vbStateReturn = getValidateRut(vt_rutValue);
                    if(vbStateReturn=='ERROR'){
                        alert('Su rut es incorrecto por favor digítelo correctamente, gracias');
                    }
                    vbStateReturn = 'OK';
                }
                if(vb_CheckBox=='YES'){
                    vbStateReturn = 'OK';
                }*/

                vbStateReturn = 'OK';
                if(vbStateReturn=='OK'){
                    rut = 'rut=' + vt_rutValue;
                    clave = '&clave=' + vt_ClaveValue;

                    vt_concat_data = rut + clave;

                    var callback = {
                        success : function(o) {
                            var vt_response = o.responseText;

                            if(vt_response=='MADRE'){
                                window.open('madres/index.php','_self');
                            }
                            if(vt_response=='PADRE'){
                                window.open('familia/papa_principal.php','_self');
                            }
                            if(vt_response=='HERMANOS'){
                                window.open('familia/hermanos_principal.php','_self');
                            }
                            if(vt_response=='ABUELOS'){
                                window.open('familia/abuelos_principal.php','_self');
                            }
                            if(vt_response=='ERROR'){
                                alert('No se encuentra el usuario en el sistema, revíse la información digitada, gracias!');
                            }
                        },
                        failure : function(o) {
                        }
                    }
                    vt_uri = TABFRWK.WEB_CONNECT_PATH+ 'validar_login.php?'+vt_concat_data;
                    YAHOO.util.Connect.asyncRequest('GET', vt_uri,callback);
                }
            }
        }
        buttonCreate.on("click", sendFormData);

    }

})();