Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 5844)
+++ trunk/expressoMail1_2/js/main.js	(revision 5858)
@@ -3168,84 +3168,144 @@
 }
 
-function import_window(){
-	var win = arrayJSWin["import_window"];
-	var form_upload = Element("form_upload");
-	if(!win) {
-		var form = document.createElement("DIV");
-		form.id  = "import_window";
-		form.style.visibility = "hidden";
-		form.style.position = "absolute";
-		form.style.background = "#eeeeee";
-		form.style.left = "0px";
-		form.style.top  = "0px";
-		form.style.width = "0px";
-		form.style.height = "0px";
-		document.body.appendChild(form);
-		form_upload = document.createElement("DIV");
-		form_upload.id = "form_upload";
-		form_upload.style.position = "absolute";
-		form_upload.style.top = "5px";
-		form_upload.style.left = "5px";
-		form_upload.name =  get_lang('zip mails to import');
-		form_upload.style.width = "450px";
-		form_upload.style.height = "100px";
-		form.appendChild(form_upload);
-		form.style.width  =  form.firstChild.style.width;
-		form.style.height = form.firstChild.style.height;
-		form.style.zIndex = "10000";
-		var title = form.firstChild.name;
-		var wHeight = form.offsetHeight + "px";
-		var wWidth =  form.offsetWidth   + "px";
-		form.style.width = form.offsetWidth - 5;
-		win = new dJSWin({
-			id: 'win_'+form.id,
-			content_id: form.id,
-			width: wWidth,
-			height: wHeight,
-			title_color: '#3978d6',
-			bg_color: '#eee',
-			title: title,
-			title_text_color: 'white',
-			button_x_img: '../phpgwapi/images/winclose.gif',
-			border: true});
-		win.draw();
-	}
+function import_window()
+{
+	var importEmails = $("#importEmails");
+		importEmails.html( DataLayer.render( BASE_PATH + "modules/mail/templates/importEmails.ejs", {}));
+		importEmails.dialog(
+		{
+			height		: 280,
+			width		: 500,
+			resizable	: false,
+			title		: get_lang('zip mails to import'),
+			modal		: true,
+			buttons		: [
+							 {
+							 	text	: get_lang("Close"), 
+							 	click	: function()
+							 	{
+							 		importEmails.dialog("destroy");
+							 	}
+							 },
+							 {
+							 	text	: get_lang("Import"), 
+							 	click	: function()
+							 	{
+							 		var input_file	 = importEmails.find("input[type=file]");
+							 		var input_hidden = importEmails.find("input[name=folder]"); 
+							 		
+							 		if( input_file.attr("value") == "" )
+							 		{
+							 			$.Zebra_Dialog(get_lang("You must choose a file") + " !",{
+							 				'type'				: 'warning',
+							 				'overlay_opacity'	: '0.5',
+							 				'onClose'			:  function(){
+							 					$("#importMessageAccordion").accordion('activate',0);	
+							 				}
+							 			});
+							 		}
+							 		else
+							 		{
+								 		if( input_hidden.attr("value") == "" )
+											$.Zebra_Dialog( get_lang("You must choose a folder") + " !" , {
+												'type'				: 'warning',
+												'overlay_opacity'	: '0.5',
+								 				'onClose'			:  function(){
+								 					$("#importMessageAccordion").accordion('activate',1);	
+								 				}
+											});
+								 		else
+								 		{
+								 			var handler_return = function(data)
+								 			{
+								 				importEmails.dialog("destroy");
+								 				
+								 				return_import_msgs( data, input_hidden.attr("value") );
+								 			}
+
+								 			var formSend =  document.getElementById("importFileMessages");
+								 			
+								 			write_msg(get_lang('You must wait while the messages will be imported...'));
+											
+								 			cExecuteForm('$this.imap_functions.import_msgs', formSend , handler_return );
+								 		}
+							 		}
+							 	}
+							 }
+						]
+		});
+
+	importEmails.css("overflow","hidden");
+		
+	importEmails.find("input[type=file]").change(function()
+	{ 
+		var deniedExtension = true;
+		var fileExtension 	= ["eml","zip"];
+		var fileName 		= importEmails.find("input[type=file]").attr('value');
+			fileName 		= fileName.split(".");
+		
+		if( fileName[1] )
+		{
+			for( var i in fileExtension )
+			{
+				if( fileExtension[i].toUpperCase() === fileName[1].toUpperCase() )
+				{
+					deniedExtension = false;
+					break;
+				}
+			}
+		}
+
+		if( deniedExtension )
+		{
+			$.Zebra_Dialog( get_lang('File extension forbidden or invalid file') , {
+				'type'				: 'warning',
+				'overlay_opacity'	: '0.5'
+			});
+		}
+
+		$("#lblFileName").html( ( !deniedExtension ) ? importEmails.find("input[type=file]").attr('value') : "" );
+		
+	});	
+		
+	$("#importMessageAccordion").accordion();	
+
+	var foldersTree = jQuery("#foldertree-container-importMessage")
+	.removeClass('empty-container')
+	.html(DataLayer.render(BASE_PATH + 'api/templates/foldertree.ejs', {folders: [cp_tree1, cp_tree2, [] ]}))
+	.find("#foldertree").treeview()
+	.click(function(event)
+	{
+		//request new selected folder messages
+		var target = $(event.target);
+
+		if( target.is('.collapsable-hitarea, .expandable-hitarea, .lastCollapsable, .lastExpandable, .treeview') )
+		    return;
+
+		if( !target.attr('id') )
+		    target = target.parent();
+
+        if (target.attr('id') == "foldertree") return;
+		
+		var targetId = target.attr('id');
+		var child = target.find('.folder');
+		
+		$('.filetree span.folder.selected').removeClass('selected');
+		if(!target.is('#foldertree > .expandable, #foldertree > .collapsable'))
+			$(target).children('.folder').addClass('selected');
+		
+		selectedFolder = {
+		    id: targetId, 
+		    name: child.attr('title'),
+		    'class': child.attr('class')
+		};
+		
+		importEmails.find("input[name=folder]").attr("value", targetId);
+	});
 	
-    form_upload.innerHTML = '<div style="margin:3px;">' +  
-							'<fieldset>' + 
-								'<legend>' + get_lang('zip mails to import') + '</legend>' + 
-								'<form method="POST" name="form_import" enctype="multipart/form-data">' + 
-									'<input name="file_1" maxlength="255" size="35" id="file_1" type="file"><br>' + 
-									'<input style="margin:5px;" title="'+get_lang('Select a folder')+'" value="'+get_lang('Select a folder')+'" type="button" onclick="javascript:select_import_folder()">'+ 
-									'<input title="'+get_lang("Close")+'" value="'+get_lang("Close")+'" type="button" onclick="arrayJSWin[\'import_window\'].close();">' + 
-								'</form>' +                                                              
-							'</fieldset>' + 
-							'</div>'; 
-    win.open();
-}
-
-function import_msgs(wfolders_tree){
-	function handler(data){
-		// Its necessary to encapsulate the data returned (IE bugfix)
-		return_import_msgs(data,wfolders_tree);
-	}
-	var countFiles = document.form_import.countFiles;
-	if(!countFiles){
-		countFiles = document.createElement("INPUT");
-		countFiles.type = "hidden";
-		countFiles.name = "countFiles";
-		countFiles.value = "1";
-		document.form_import.appendChild(countFiles);
-	}
-	var folder = document.createElement("INPUT");
-	folder.type = "hidden";
-	folder.name = "folder";
-	folder.value = wfolders_tree._selected.id;
-	document.form_import.appendChild(folder);
-	write_msg(get_lang('You must wait while the messages will be imported...'));
-
-	cExecuteForm('$this.imap_functions.import_msgs', document.form_import, handler);
-}
-function return_import_msgs(data, wfolders_tree){
+	$("#lblFileName").prev().css("margin-left", "10px");
+	$("#lblFileName").prev().css("font-weight", "bold");
+}
+
+function return_import_msgs(data, folderID){
 	if(data && data.error){
 		write_msg(data.error);
@@ -3274,5 +3334,5 @@
 					Element("dJSWin_wfolders_bok").blur();
 				}				
-				if(openTab.imapBox[0] == wfolders_tree._selected.id)
+				if(openTab.imapBox[0] == folderID)
 				{
 					openTab.imapBox[0] = '';
