﻿function $_logIn()
{
    
    var paramData = 'action=logIn' + 
	                '&usuario=' + encodeURIComponent($('#' + RegistroPagePrefix + 'txtUsuario').val()) + 
	                '&pass=' + encodeURIComponent($('#' + RegistroPagePrefix + 'txtPass').val()); 
	
    $.ajax({
            url: "Handler.ashx",
            type: "POST",
            data: paramData,
            dataType: "json",
            success: function(jsonObj)
                                    {
                                        if(jsonObj.status==="OK")
                                        {                                                                                                                    
                                            $('#' + RegistroPagePrefix + 'divLogOFF').hide();
                                            $('#' + RegistroPagePrefix + 'divLogON').show("slow");
                                            
                                            $('#' + RegistroPagePrefix + 'imgFoto').removeAttr("src");
                                            $('#' + RegistroPagePrefix + 'imgFoto').attr("src", jsonObj.imgFotoUrl);
                                            
                                            $('#' + RegistroPagePrefix + 'divDatos').empty();
                                            $('#' + RegistroPagePrefix + 'divDatos').html(jsonObj.datos);
                                        }
                                        else
                                        {
                                            $('#' + RegistroPagePrefix + 'txtUsuario').effect("highlight", {color:'#FF0000'}, 1000);
                                            $('#' + RegistroPagePrefix + 'txtPass').effect("highlight", {color:'#FF0000'}, 1000);
                                            $_showMessage('ERR', 'ERROR', jsonObj.msg);
                                        }
                                    }
            });
}


function $_validaFormLogIn()
{
    var err = false;
    
    if($('#' + RegistroPagePrefix + 'txtUsuario').val() === '')
    {
        err = true;
        $('#' + RegistroPagePrefix + 'txtUsuario').effect("highlight", {color:'#FF0000'}, 1000);
    }

    if($('#' + RegistroPagePrefix + 'txtUsuario').val() === '')
    {
        err = true;
        $('#' + RegistroPagePrefix + 'txtPass').effect("highlight", {color:'#FF0000'}, 1000);
    }

    if(!err)
        $_logIn();

return err;
}

