Index: branches/2.2/workflow/js/userinterface/orgchartPrint.js
===================================================================
--- branches/2.2/workflow/js/userinterface/orgchartPrint.js	(revision 795)
+++ branches/2.2/workflow/js/userinterface/orgchartPrint.js	(revision 3167)
@@ -1,10 +1,16 @@
+/**
+* Show / Hide all employees
+*/
 function toggleEmployeesVisibility()
 {
 	if ($('#employeesVisibility').attr('checked'))
-		$('div.employees').show();
+		$('tr.employees').show();
 	else
-		$('div.employees').hide();
-}
-
+		$('tr.employees').hide();
+}
+
+/**
+* Highlight supervisor names?
+*/
 function toggleHighlightSupervisor()
 {
@@ -15,12 +21,12 @@
 }
 
+/**
+* Show / Hide orgchart area path visibility
+*/
 function toggleOrgchartPathVisibility()
 {
 	if ($('#orgchartPathVisibility').attr('checked'))
-	{
 		$('span.orgchartPath').css('visibility', 'visible').show();
-	}
-	else
-	{
+	else {
 		if ($('#orgchartPathIndentation').attr('checked'))
 			$('span.orgchartPath').show().css('visibility', 'hidden');
@@ -30,4 +36,149 @@
 }
 
+/**
+* Group by area or show a single list alphabetically ordered
+* For large sets of data this function may be potencially slow
+*/
+function toggleGroupByArea()
+{
+	/* remove the table and compute it again */
+	$('#employee_table').remove();
+
+	if ($('#groupByArea').attr('checked'))
+		showGroupedByArea();
+	else
+		showUngrouped();
+
+	/* updating supervisor highlight and orgchart path visibility */
+	toggleHighlightSupervisor();
+	toggleOrgchartPathVisibility();
+}
+
+/**
+* Centralize the creation of table rows for employees.
+* 'showAreaColumn' specifies whether the second column will be shown
+*/
+function createEmployeeRow(area_id, user_id, showAreaColumn)
+{
+	/* set a special 'class' if the employee is a supervisor one */
+	class_name = 'employee';
+	if (areas[area_id].titular_funcionario_id == areas[area_id].employees[user_id].funcionario_id)
+		class_name += 'supervisor';
+
+	/* creating the row. */
+	element = $('<tr></tr>')
+				/* name: first column */
+				.append(
+						$('<td></td>')
+							.append(
+								$('<span></span>')
+									.addClass(class_name)
+									.append(areas[area_id].employees[user_id].cn)
+							)
+							.css('width', '70%')
+						);
+
+	/* area: second (optional) column */
+	if (showAreaColumn)
+		element.append(
+						$('<td>' + areas[area_id].sigla + '</td>')
+							.css('width', '15%')
+					);
+
+	/* telephone: last column */
+	element.append(
+					$('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>')
+						.css('width', '20%')
+					)
+				.addClass('employees');
+
+	return element;
+}
+
+/**
+* Creating a employee table grouped by area
+*/
+function showGroupedByArea()
+{
+	var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
+	var i, j;
+
+	/* iterating over areas */
+	for (i=0; i < areas.length; i++) {
+
+		/* inserting area header */
+		table.append(
+				$('<tr></tr>')
+				.append(
+					$('<th></th>')
+						.css('text-align', 'left')
+						.css('height', '30')
+						.append(
+							$('<span></span>')
+								.addClass('orgchartPath')
+								.append(areas[i].orgchartPath)
+								)
+						.append(areas[i].sigla)
+					)
+		);
+
+		/* creating employee rows */
+		for (j=0; j < areas[i].employees.length; j++)
+			table.append(createEmployeeRow(i, j));
+	}
+	$('#areas_content').append(table);
+}
+
+/**
+* Creating employess ordered alphabetically and ungrouped. In this
+* function we implemented a 'merge' of all area's employee arrays.
+*
+* Be careful if you are going to update this code... =)
+*/
+function showUngrouped()
+{
+	var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
+	var i, less, end;
+
+	/* creating and reseting indexes */
+	for (i=0; i < areas.length; i++)
+		areas[i].index = 0;
+
+	/* */
+	while (true) {
+		less = -1;
+		end = true;
+
+		/* searching the area with smallest employee name */
+		for (i=0; i < areas.length; i++) {
+
+			/* if this area have employees left */
+			if (areas[i].employees.length > areas[i].index) {
+
+				/* if it's the first area reached in this iteration */
+				if (less == -1)
+					less = i;
+
+				/* updating less */
+				if (areas[i].employees[areas[i].index].cn < areas[less].employees[areas[less].index].cn)
+					less = i;
+
+				/* so, we are not done */
+				end = false;
+			}
+		}
+		/* if we are done */
+		if (end) break;
+
+		/* inserting the row */
+		table.append(createEmployeeRow(less, areas[less].index, true));
+		areas[less].index++;
+	}
+	$('#areas_content').append(table);
+}
+
+/**
+* Print me!
+*/
 function printAction()
 {
@@ -35,7 +186,11 @@
 }
 
+/**
+* Binding events to HTML elements
+*/
 function bindEvents()
 {
 	$('#employeesVisibility').click(toggleEmployeesVisibility);
+	$('#groupByArea').click(toggleGroupByArea);
 	$('#highlightSupervisor').click(toggleHighlightSupervisor);
 	$('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
@@ -45,4 +200,5 @@
 function initialSetup()
 {
+	toggleGroupByArea();
 	toggleEmployeesVisibility();
 	toggleHighlightSupervisor();
@@ -50,4 +206,7 @@
 }
 
+/**
+* Call setup functions on body onload.
+*/
 function pageLoad()
 {
Index: branches/2.2/workflow/js/userinterface/orgchart.js
===================================================================
--- branches/2.2/workflow/js/userinterface/orgchart.js	(revision 1452)
+++ branches/2.2/workflow/js/userinterface/orgchart.js	(revision 3167)
@@ -45,5 +45,5 @@
 	content += '</select></a></li>';
 	content += '<li><a href="#" onclick="window.open(\'' + enderecoImagem + '\', \'extwindow\'); return false;"><img src="templateFile.php?file=images/Process.gif">&nbsp;&nbsp;Gráfico</a></li>';
-	content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca</span></a></li>';
+	content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca&nbsp;</span><img src="templateFile.php?file=images/help.png" title="Informe o nome, área ou telefone a ser pesquisado." style="cursor: help" /></a></li>';
 	content += '<li><a href="#" onclick="printArea(); return false;"><img src="templateFile.php?file=images/imprimir.png" width="16">&nbsp;&nbsp;Imprimir</a></li>';
 	content += '</ul>';
@@ -171,5 +171,5 @@
 	var content = '<center><h2>Substituição de Chefia</h2></center>';
 	content += '<table class="employeeList">';
-	content += '<tr><th>Área</th><th>Titular</th><th>Substituto</th></tr>';
+	content += '<tr><th>Área</th><th>Titular</th><th>Substituto</th><th>Data de início</th><th>Data de término</th></tr>';
 	var current;
 	for (var i = 0; i < data.length; i++)
@@ -180,4 +180,6 @@
 		content += '<td>' + current['titular'] + '</td>';
 		content += '<td>' + current['substituto'] + '</td>';
+		content += '<td>' + current['data_inicio'] + '</td>';
+		content += '<td>' + current['data_fim'] + '</td>';
 		content += '</tr>';
 	}
@@ -294,5 +296,7 @@
 
 	/* no employee to list */
-	if ( ( ! data['employees'] || data['employees'].length == 0 ) && ( ! data['bygroup'] || data['bygroup'].length == 0 ) )
+	if ( ( ! data['employees'] || data['employees'].length == 0 ) && 
+		 ( ! data['bygroup'] || data['bygroup'].length == 0 ) &&
+		 ( ! data['bytelephone'] || data['bytelephone'].length == 0 ) )
 	{
 		div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
@@ -317,5 +321,5 @@
 		/* build the display table (headers)*/
 		content += '<table id="employeeList" class="employeeList" style="clear: both">';
-		content += '<tr>';
+		content += '<tr class="message_header">';
 		content += '<th>Nome</th>';
 		if (useArea)
@@ -344,5 +348,5 @@
 				complement = '';
 			if (employees[i]['removed'])
-				complement += ' <font color="red">(excluído)</font>';
+				complement += ' <font color="red">(inativo)</font>';
 			content += '<tr class="linha'+ i%2 + (useCategories ? ' categoria_' + employees[i]['funcionario_categoria_id'] : '') + '" onmouseover="this.className=\'highlight0\'" onmouseout="this.className=\'linha'+ i%2 + (useCategories ? ' categoria_' + employees[i]['funcionario_categoria_id'] : '') + '\'">';
 			content += '<td><a href="javascript:void(0);" onmouseover="getEmployeeInfoTimer(event, ' + employees[i]['funcionario_id'] + '); return false;" onmouseout="hideEmployeeInfo(); return false;">' + employees[i]['cn'] + complement + '</a></td>';
@@ -477,4 +481,5 @@
 			div.innerHTML += '</center><span style="color:red">Busca pelo nome: ' + searchTerm.toUpperCase( ) + '</span>' + content;
 
+		// printing records found by group
 		if ( data['bygroup'] && data['bygroup'].length )
 		{
@@ -484,4 +489,14 @@
 			if ( content )
 				div.innerHTML += '<br/><br/><span style="color:red">Busca pelo setor: ' + searchTerm.toUpperCase( ) + '</span><br/>' + content;
+		}
+
+		// printing records found by telephoneNumber
+		if ( data['bytelephone'] && data['bytelephone'].length )
+		{
+			employees = [ ];
+			employees[ 'employees' ] = data['bytelephone'];
+			content = printEmployeesHandler( employees, 'returnResult' );
+			if ( content )
+				div.innerHTML += '<br/><br/><span style="color:red">Busca pelo telefone: ' + searchTerm.toUpperCase( ) + '</span><br/>' + content;
 		}
 
