Index: /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js
===================================================================
--- /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js	(revision 6753)
+++ /sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js	(revision 6765)
@@ -10,5 +10,9 @@
 var checkAlarmsFilter = false;
 
+var auxNotificationCriteriaVetor = [];
+var auxNotification;
+
 var notifyNewMessage = [];
+var notifyNewMessageFilter = [];
 
 var dynamicPersonalContacts = new Array();
@@ -558,10 +562,29 @@
 
 //here
-
+var window_focus;
 function Notifier() {}
 
+function refreshCriteria(){
+	if(auxNotificationCriteriaVetor.length > 0){
+		for(var i=0; i<auxNotificationCriteriaVetor.length; i++){
+			auxNotificationCriteriaVetor[i].cancel();
+		}
+	}
+}
+function refreshNewMsg(){
+	if(auxNotification){
+		auxNotification.cancel();
+		notifyNewMessage = [];
+	}
+}
+
 $(document).ready( function(){
+
+	$(window).focus(function() {
+		window_focus = true;
+	}).blur(function() {
+		window_focus = false;
+	});
 	
-    // Returns "true" if this browser supports notifications.
     Notifier.prototype.HasSupport = function() {
       if (window.webkitNotifications) 
@@ -572,12 +595,8 @@
     }
 
-    // Request permission for this page to send notifications. If allowed,
-    // calls function "cb" with true.
     Notifier.prototype.RequestPermission = function(cb) {
       window.webkitNotifications.requestPermission();
     }
 
-    // Popup a notification with icon, title, and body. Returns false if
-    // permission was not granted.
     Notifier.prototype.Notify = function(icon, title, body) {
       if (window.webkitNotifications.checkPermission() == 0) {
@@ -594,8 +613,4 @@
     $(function() {
 		var notifier = new Notifier();
-		/*if(notifier.HasSupport){
-			alert("Seu navegador não dá suporte!");
-			//firefox/downloads/latest/221523/addon-221523-latest.xpi?src=dp-btn-primary
-		}*/
 		
 		if (window.webkitNotifications.checkPermission() != 0){
@@ -611,18 +626,49 @@
 }
 
-var auxNotification;
-
-function refresh(alert_new_msg, notification){
+function notificationFilter(data, notifyCriteria){
+	
+	if(parseInt(notifyCriteria)  && data.length > 0 && !window_focus ){
+	
+		var howManyCriteria = $('div.gray.filtersDeadline .message-list li').length;
+		var differenceOfNewCriteria = data.length - howManyCriteria;
+		
+		if(differenceOfNewCriteria > 0){
+			for(var i=data.length - differenceOfNewCriteria; i < data.length; i++){
+		
+			notificationCriteriaVetor = webkitNotifications.createNotification("","Critério de filtro",data[i].from+" - "+data[i].subject);
+			notificationCriteriaVetor.onclick = function(){
+				window.focus();
+				this.cancel();
+			};
+			
+			notificationCriteriaVetor.show();
+			auxNotificationCriteriaVetor.push(notificationCriteriaVetor);
+			}
+		}
+	
+	}
+
+}
+
+function refresh(alert_new_msg, notifyPermission){
+
+	if(window_focus){
+		setTimeout('refreshCriteria()', 5000);
+		setTimeout('refreshNewMsg()', 5000);
+	}
 
 	getFromAlertRules();
 	var handler_refresh = function(data){
-		if(checkAlarmsFilter){
-			handlerMessageFilter = function (data) {
+		handlerMessageFilter = function (data) {
+			notificationFilter(data, notifyPermission);
+			if(checkAlarmsFilter){
 				alarmFollowupflagged('filtersAlarms', data);
 			}
-			/* Busca  nas pastas indexadas para ver se há novas mensagens com a flag $FilteredMessage */
-			cExecute ("$this.imap_functions.getFlaggedAlertMessages&folders="+fromRules, handlerMessageFilter);
-		}
-		checkAlarmsFilter = true;
+			checkAlarmsFilter = true;
+			
+		}
+		/* Busca  nas pastas indexadas para ver se há novas mensagens com a flag $FilteredMessage */
+		cExecute ("$this.imap_functions.getFlaggedAlertMessages&folders="+fromRules, handlerMessageFilter);
+
 		if(data['msg_range_end'])
 			if(data['msg_range_end'] > 0)
@@ -766,11 +812,11 @@
 				select_msg("null","reload_msg","null");
 		
-			if(parseInt(alert_new_msg) && data.new_msgs > 0)
+			if(parseInt(alert_new_msg) && data.new_msgs > 0 && window_focus)
 				alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!");
 			
 			
-			if(parseInt(notification)  && (data.new_msgs > 0 || notifyNewMessage.length > 0) ){
+			if(parseInt(notifyPermission)  && (data.new_msgs > 0 || notifyNewMessage.length > 0) && !window_focus ){
 			
-			for(var i=0; i<data.length; i++){
+				for(var i=0; i<data.length; i++){
 					notifyNewMessage.push(true);
 				}
@@ -782,4 +828,8 @@
 						notifyNewMessage = [];
 					};
+					
+					notification.onclose = function(){
+						notifyNewMessage = [];
+					}
 					
 					if(auxNotification)
