Index: branches/2.2/expressoMail1_2/js/search.js
===================================================================
--- branches/2.2/expressoMail1_2/js/search.js	(revision 1969)
+++ branches/2.2/expressoMail1_2/js/search.js	(revision 3018)
@@ -203,146 +203,54 @@
 		ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
 	}
-	
-	//This func returns the most recent date
-	function date_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data1 = data1[0].substr(0, data1[0].indexOf('--'))
-		with ( data1 ) 
-			data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data2 = data2[0].substr(0, data2[0].indexOf('--'))
-		with ( data2 )
-			data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		return data2 - data1;
-	}
-	function date_comp_reverse(a,b)
-	{
-		return date_comp(b,a);
-	}
-	
-	function box_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(0, a.indexOf('--'));
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(0, b.indexOf('--'))
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function box_comp_reverse(a,b)
-	{
-		return box_comp(b,a);
-	}
-
-	function who_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(a.indexOf('--')+2);
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(b.indexOf('--')+2);
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function who_comp_reverse(a,b)
-	{
-		return who_comp(b,a);
-	}
-
-	function subject_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(a.indexOf('--')+2);
-	compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(b.indexOf('--')+2);
-	compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function subject_comp_reverse(a,b)
-	{
-		return subject_comp(b,a);
-	}
-
-	function size_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data1 = data1[0].substr(data1[0].indexOf('--')+2)
-		data1 = data1.substr(0,data1.indexOf('--'))
-		var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
-		if (data1.match("k"))
-			size_a = size_a * 1024;
-		else
-			if (data1.match("m"))
-				size_a = size_a * 1048576;
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data2 = data2[0].substr(data2[0].indexOf('--')+2)
-		data2 = data2.substr(0,data2.indexOf('--'))
-		var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
-		if (data2.match("k"))
-			size_b = size_b * 1024;
-		else
-			if (data2.match("m"))
-				size_b = size_b * 1048576;
-		return size_b - size_a;
-	}
-	function size_comp_reverse(a,b)
-	{
-		return size_comp(b,a);
-	}
 
 	// Form resultado
 	searchE.prototype.mount_result = function(data,sort_type){
-		var nw_array = new Array;
-		var var_tmp = data.substr(2, data.length - 4);
-		var_tmp  = var_tmp.split("####");
+		if (data == undefined)
+			return;
 		var cont = parseInt(0);
+
+                //This func returns the comparison between criterias 
+                var date_comp = function(a,b){ return a.udate > b.udate;}; 
+                var date_comp_reverse = function(a,b){ return date_comp(b,a);}; 
+                var box_comp = function(a,b){   return a.boxname > b.boxname; } 
+                var box_comp_reverse = function(a,b){   return box_comp(b,a); } 
+                var who_comp = function(a,b){ return a.from > b.from; } 
+                var who_comp_reverse = function(a,b){ return who_comp(b,a); } 
+                var subject_comp = function(a,b){ return a.subject > b.subject; } 
+                var subject_comp_reverse = function(a,b){ return subject_comp(b,a); } 
+                var size_comp = function(a,b){ return a.size > b.size; } 
+                var size_comp_reverse = function(a,b){ return size_comp(b,a); }
+
 		switch (sort_type)
 		{
 			case 'SORTDATE':
-				var_tmp.sort(date_comp);
+				data.sort(date_comp);
 				break;
 			case 'SORTDATE_REVERSE':
-				var_tmp.sort(date_comp_reverse);
+				data.sort(date_comp_reverse);
 				break;
 			case 'SORTBOX':
-				var_tmp.sort(box_comp);
+				data.sort(box_comp);
 				break;
 			case 'SORTBOX_REVERSE':
-                                var_tmp.sort(box_comp_reverse);
+                                data.sort(box_comp_reverse);
                                 break;
 			case 'SORTSUBJECT':
-				var_tmp.sort(subject_comp);
+				data.sort(subject_comp);
 				break;
 			case 'SORTSUBJECT_REVERSE':
-                                var_tmp.sort(subject_comp_reverse);
+                                data.sort(subject_comp_reverse);
 				break;
 			case 'SORTWHO':
-				var_tmp.sort(who_comp);
+				data.sort(who_comp);
 				break;
 			case 'SORTWHO_REVERSE':
-                                var_tmp.sort(who_comp_reverse);
+                                data.sort(who_comp_reverse);
 				break;
 			case 'SORTSIZE':
-				var_tmp.sort(size_comp);
+				data.sort(size_comp);
 				break;
 			case 'SORTSIZE_REVERSE':
-				var_tmp.sort(size_comp_reverse);
+				data.sort(size_comp_reverse);
 				break;
 			default:
@@ -350,13 +258,8 @@
 		}
 
-		for(var i=0; i < var_tmp.length; i++){
-			if(var_tmp[i] != "")
-			{
-				nw_array[cont] = var_tmp[i];
-				cont++;
-			}
-		}
-
-                if( (preferences.search_result_number != '65536') && (nw_array.length > 0) && (nw_array.length >= preferences.search_result_number) ){
+		if(data.length > 0 && showMsg) 
+	                        write_msg(data.length + " "+ get_lang('results found')); 
+                /* This code was lost on merge 
+		if( (preferences.search_result_number != '65536') && (nw_array.length > 0) && (nw_array.length >= preferences.search_result_number) ){
                     nw_array.length = preferences.search_result_number;
                     write_msg(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
@@ -365,4 +268,5 @@
                         write_msg(nw_array.length + " "+ get_lang('results found'));
                 }
+		*/
 
 		numBox++;
@@ -386,28 +290,11 @@
 		tbody.id    = "tbody_box_" + numBox;
 
-		for( var i=0; i < nw_array.length; i++){
+		for( var i=0; i < data.length; i++){
 			var tr = document.createElement("TR");
 			tr.style.height = preferences.line_height;
-
-			if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
-			{
-				var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-				aux1 = aux1[0].split("--");
-				nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
-				var aux = [];
-				aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-				nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-				aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-				aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-				aux = aux.concat(aux1);
-			}
-			else
-			{
-				var aux = nw_array[i].split("--");
-			}
-
-			var mailbox = aux[0];
-			var uid_msg = aux[6];
-			var subject = aux[2];
+			var aux = data[i]; 
+			var mailbox = aux.boxname; 
+			var uid_msg = aux.uid; 
+			var subject = aux.subject; 
 			tr.id = uid_msg+"_s"+global_search;
 
@@ -416,5 +303,5 @@
 			tr.name = mailbox;
 
-			if (aux[5].match("U"))
+			if (aux.flag.match("U"))
 				add_className(tr,'tr_msg_unread');
 			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
@@ -432,7 +319,7 @@
 				{
 					td.style.width = "2%";
-					if (aux[5].match('T'))
+					if (aux.flag.match('T'))
 					{
-						attachNum = parseInt(aux[5].substr(aux[5].indexOf('T')+1));
+						attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
 						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
 					}
@@ -444,8 +331,8 @@
 					td.style.width = "1%";
 					td.id = "td_message_answered_"+uid_msg;
-					if (aux[5].match('X'))
+					if (aux.flag.match('X'))
 						td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
 					else
-						if (aux[5].match('A'))
+						if (aux.flag.match('A'))
 							td1 = '<img src=templates/'+template+'/images/answered.gif>';
 						else
@@ -456,5 +343,5 @@
 					td.style.width = "1%";
 					td.id = "td_message_important_"+uid_msg;
-					if (aux[5].match("F"))
+					if (aux.flag.match("F"))
 					{
 						add_className(tr, 'flagged_msg');
@@ -474,5 +361,5 @@
 					td.style.width = "14%";
 					td.onclick = _onclick;
-					var nm_box = aux[0].split(cyrus_delimiter);
+					var nm_box = aux.boxname.split(cyrus_delimiter);
 					var td1 = nm_box.pop();
 					td.setAttribute("NoWrap","true");
@@ -493,11 +380,11 @@
 				if( j == 6)
 				{
-					if (aux[1].length > 29)
-						aux[1] = aux[1].substr(0,29) + "...";
+					if (aux.from.length > 29)
+						aux.from = aux.from.substr(0,29) + "...";
 					td.style.width = "20%";
 					td.onclick = _onclick;
 					td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
+					var td1  =  '<div style="width:100%;overflow:hidden">'+aux.from+"</div>";
 				}
 				if( j == 7)
@@ -505,12 +392,12 @@
 					var subject_encode = url_encode(subject);
 					if (! subject_encode)
-						aux[2] = get_lang("no subject") + "...";
-					if (aux[2].length > 70)
-						aux[2] = aux[2].substr(0,70) + "...";
+						aux.subject = get_lang("no subject") + "...";
+					if (aux.subject.length > 70)
+						aux.subject = aux.subject.substr(0,70) + "...";
 					td.style.width = "35%";
 					td.onclick = _onclick;
                                         td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  = aux[2];
+					var td1  = aux.subject;
 
 				}
@@ -520,5 +407,6 @@
 					td.align = "center";
 					td.onclick = _onclick;
-					var td1  = aux[3];
+					var _dat = new Date(aux.udate*1000); 
+                                        var td1 = _dat.getDate()+"/"+(_dat.getMonth()+1)+"/"+_dat.getFullYear(); 
 				}
 				if( j == 9)
@@ -527,11 +415,11 @@
 					td.align = "center";
 					td.onclick = _onclick;
-					var td1  = aux[4];
+					var td1  = borkb(aux.size);
 				}
 				if (j == 10)
 				{
-					if (aux[5].match("U"))
+					if (aux.flag.match("U"))
 						add_className(tr, 'tr_msg_unread');
-					if (aux[5].match("F"))
+					if (aux.flag.match("F"))
 						add_className(tr, 'flagged_msg');
 					var td1 = '';
@@ -550,21 +438,7 @@
 
 	var content_search =  Element('content_id_search_' + numBox);
-	// BEGIN MAKE THE SCROLL HEIGHT		
-	var defaultWidth = document.body.offsetWidth - 31;
-	var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
-	if(!menuHidden)
-		defaultWidth -= Element("folderscol").offsetWidth;			
-	var bar = Element("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
-		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;		
 	var div_scroll_result = document.createElement("DIV");
 	div_scroll_result.id = "divScrollMain_"+numBox;
-	div_scroll_result.style.height = document.body.clientHeight - offset - 120;
-	content_search.style.height = document.body.clientHeight - offset - 80;
 	div_scroll_result.style.overflow = "auto";
-	div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
-	// END MAKE THE SCROLL HEIGHT		
-		
 	
 		if(is_ie)
@@ -711,4 +585,5 @@
 			content_search.appendChild(div_scroll_result);
 		}
+		resizeWindow(); 
 	}
 
@@ -923,5 +798,4 @@
 		var handler = function(data){
 			var tmp;
-			var countTmp= new Array();
 
                         var dataTemp = data.split('=sumResults=');
@@ -934,17 +808,12 @@
 				if (tmp!=false) {
 					var tmp2 = tmp.substr(2, data.length - 4);
-					countTmp = tmp.split('####');
-				}
-			}
-//			if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
-//			if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number))
-//                        {
-//                            EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);
-//                        }
-//                        else if (data == 'many results' || countTmp.length >= preferences.search_result_number)
-//                        {
-//                            alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
-//                        }
-
+	                                } 
+	                        } 
+	                        if((data == "none") || (data.length==0)){alert(get_lang("None result was found."));} 
+	                        else if(data.length > 1000){alert(get_lang("More than %1 results. Please, try to refine your search.",1000));}
+			else if(data == "many results"){alert(get_lang("More than %1 results. Please, try to refine your search.",50));} 
+			else{EsearchE.mount_result(data);}
+
+			/* Lost code on merge
                         if ((sumResults == "none") && (countTmp.length==0)){
                             alert(get_lang("None result was found."));
@@ -953,5 +822,5 @@
                         {
                             EsearchE.mount_result((sumResults=='none')?tmp:(countTmp.length==0)?data:data+tmp);
-                        }
+                        }*/
 
 		}
