var Usuario = {

	novo: function( idPut )
	{
		showLoading();
		$( '#'+idPut ).load(
			URL_ROOT + 'Usuario/manterUsuario/TRUE'
			, function( response )
			{
				hideLoading();
			}
		);
	}

	, remover: function( idPut,cod )
	{
		$ok = confirm("Tem certeza que deseja excluir este usuário?\r\n Serão deletados todos os registros de (GRUPOS, PERFIL  e SMS).");
		if($ok){
			showLoading();
			$( '#'+idPut ).load(
				URL_ROOT + 'Usuario/removerUsuario/' + cod + '/TRUE'
				, {
					co: cod
				}
				, function( response )
				{
					hideLoading();
				}
			);
		}
	}

	, mudarEmpresaUsuario: function()
	{
		if($('#seqEmpresaAltera').val()){
			showLoading();
			$.post(
				URL_ROOT + 'Usuario/mudarEmpresa/'
				,{
					seqEmpresa: $('#seqEmpresaAltera').val()
				}
				, function( data )
				{
					hideLoading();
					window.location=URL_ROOT;		
				}
			);
		} else {
			$('#respostaMudanca').html('<span style=color:red>Selecione o cliente!</span>');
		}
	}
	
	, mostraFormEdita: function( cod, idPut )
	{
		showLoading();
		$( '#'+idPut ).load(
			URL_ROOT + 'Usuario/editarUsuario/' + cod + '/TRUE'
			, {
				seq: cod
			}
			, function( response )
			{
				hideLoading();
			}
		);
	}
	
	, mostraUsuarioLogado: function( idPut )
	{
		showLoading();
		$( '#'+idPut ).load(
			URL_ROOT + 'Usuario/usuarioLogado/'
			, {
				
			}
			, function( response )
			{
				hideLoading();
			}
		);
	}
	
	, logarUsuario: function()
	{
			
		jQuery.post(URL_ROOT + 'Usuario/autenticar/', 
				{
				txt_usuario: $('#txtUsuario').val(),
				txt_senha: $('#txtSenha').val()
				}, 
				function(data) {
					//$('#formAutentica').html(data);
					if(data=='AUTORIZA')
    				{ 
    					//$('#formAutentica').html(data);
						Usuario.mostraUsuarioLogado('formAutentica')
    				} else {
    					$('#formAutentica').html('Usuário sem permissão de acesso<br><a href=index.php >Clique aqui</a> para tentar novamente.');
    				}
				});
	}
	
	, enviar: function()
	{
		Usuario.selectAll();
		Validacao.enviar();
	}
	
	, moveAll: function( from, to, selector )
	{
		if( selector == '' || selector == null || !selector || selector.length == 0 )
		{
			selector = ':selected';
		}

		from.children( selector ).each(
			function()
			{
                to.append( $(this) );
			}
		);
		
		
	}

	, moveSelected: function( from, to )
	{
		
		Usuario.moveAll( from, to, ':selected' );
	}
	
	, moveGrupo: function( div )
	{

      
       $('#'+div).toggle(400);
        return false;
	}
	
	, selectAll: function()
	{
		$('#arrCoPerfilSelecionado option').each(function(i) {   
		  $(this).attr("selected", "selected");   
		 }); 
		 
		$('#arrCoGrupoSelecionado option').each(function(i) {   
		  $(this).attr("selected", "selected");   
		 });   
		 
	}
	
	, checkedAll: function()
	{
		$('#checkGrupoEnvio').each(function(i) {   
		  $(this).attr("checked", "checked");   
		 });	
	}
	
}