addLoadEvent(function() {
	$.tablesorter.addParser({
		 // set a unique id
        id: 'user-birthdate',
        is: function(s) {
                // return false so this parser is not auto detected
                return false;
        },
        format: function(s) {
                // format your data for normalization
                var dateSplit = s.substr(0,10).split('/');
				
				if (3 !== dateSplit.length) {
					return 0;
				} else {
                	return (dateSplit[2] + '-' + dateSplit[1] + '-' + dateSplit[0] + s.substr(11,19));
				}
		},
        // set type, either numeric or text
        type: 'text'
	});

	$.tablesorter.addParser({
		// set a unique id
		id: 'tempo-aberta',
		is: function(s) {
			// return false so this parser is not auto detected
			return false;
		},
		format: function(s) {
			// format your data for normalization
			var tempoSplit = s.split(' ');
			var dias       = tempoSplit[0];
			var horaSplit  = tempoSplit[2].split(':');
			
			while (dias.length < 3) {
				dias = '0' + dias;
			}

			return (dias + horaSplit[0] + horaSplit[1] + horaSplit[2]);
		},
		// set type, either numeric or text
		type: 'text'
	});
});

// Seleciona todos os registros de uma jGrid
function jGridSelectAll() {
	var input  = $("input:checkbox[name='jcheck']");
	var linhas = $('tr.trdata');
	var check  = $('#ckbselectall').attr('checked');
	
	// marca ou desmarca todos os checkbox's da jGrid
	input.each(function() {
    	$(this).attr('checked', check);
	})
	
	// colore as linhas selecionadas
	linhas.each(function() {
		if (check) {
			$(this).attr('className', 'even trdata checked');
		} else {
			$(this).attr('className', 'even trdata');
		}
	})
}

// Muda a cor da linha quando um registro é selecionado
function jGridChangeColor(cb) {
	var elemento = $('#line' + cb.id);
	
	if (cb.checked) {
		elemento.attr('className', 'even trdata checked');
	} else {
		elemento.attr('className', 'even trdata');
	}
}

// Chama o form com a ação seleciona
function jQueryForm(value) {
	if (value != '') {
		var selecionados = $("input:checkbox[name='jcheck']:checked");
		
		if (selecionados.length == 0) {
			alert('Nenhum registro foi selecionado!');
			$('#jselect').val('');
		} else {
			if (confirm('Confirma a execução da ação selecionada?')) {
				$('#jQueryForm').submit();
			} else {
				$('#jselect').val('');
			}
		}
	}
}
