Index: sandbox/webservice/restclient/index.html
===================================================================
--- sandbox/webservice/restclient/index.html	(revision 6339)
+++ sandbox/webservice/restclient/index.html	(revision 6383)
@@ -4,4 +4,5 @@
 	<script type="text/javascript" src="./libs/jquery.js"></script>
 	<script type="text/javascript" src="./libs/jquery.json-2.3.min.js"></script>
+	<script type="text/javascript" src="./libs/json2.js"></script>
 	<script type="text/javascript" src="./libs/jsonreport.js"></script>
 	<script type="text/javascript" src="./libs/Base64.js"></script>
@@ -32,30 +33,38 @@
 	</style>
 	</HEAD>
-	<BODY>
+	<BODY style="margin-bottom:10px;padding:0px;overflow:hidden">
 		<DIV style="display:none" class="loader" id="loader">
 			<label id="loader_msg"></label><br>
 			<img src="./images/loader.gif"/>
 		</DIV>
-		<TABLE>
+		<DIV style="overflow:auto;height:100%;float:left;width:30%;padding-right:10px">
+		<TABLE style="width:100%">
 			<TR><TD><b>Servidor</b></TD>
 				<TD><select id="server"><option value="">Selecionar ....</option></select>
 					<input id="bt_servers" type="button" value="Listar Servidores" onclick="javascript:jExecute('AvailableServers')"/>
-					<input  id="bt_version" type="button" value="Vers&atilde;o API" onclick="javascript:jExecute('ExpressoVersion')"/>
-					<input  id="bt_version" type="button" value="Teste Erro" onclick="javascript:jExecute('Teste')"/>
 				</TD>
 			</TR>
-			<TR><TD><b>Login</b></TD>
-			<TD>
-				<input type="text" id="user"/>
-				<input id="bt_myPicture" type="button" value="Visualizar Foto" onclick="javascript:jExecute('GetMyPicture')"/>
-			</TD>
+			<TR><TD><b>Login</b></TD><TD><input type="text" id="user"/>
+			<input id="bt_login" type="button" value="Conectar" onclick="javascript:jExecute('Login')"/>
+					<input class="ui-button" id="bt_logout" type="button" value="Desconectar" onclick="javascript:jExecute('Logout')"/> 
+			</TD></TR>
+			<TR><TD><b>Senha</b></TD><TD><input type="password" id="password"/></TD></TR>
+			<TR><TD colspan=2>
+					<input id="bt_myPicture" type="button" value="Visualizar Foto" onclick="javascript:jExecute('GetMyPicture')"/>
+					<input  id="bt_error" type="button" value="Teste Erro" onclick="javascript:jExecute('Teste')"/>
+					<input  id="bt_version" type="button" value="Vers&atilde;o API" onclick="javascript:jExecute('ExpressoVersion')"/>
+			</TD></TR>
+		</TABLE>
+		<BR>
+		<TABLE style="width:100%">
+			<TR><TD><b>Suporte /<br>Sugest&atilde;o</b></TD>
+				<TD><textarea id="text_message">Texto do e-mail de suporte/sugestao!!</textarea></TD>
+				</TR>
+				<TR><TD></TD>
+				<TD><input id="bt_sugestao" type="button" value="Enviar Sugest&atilde;o" onclick="javascript:jExecute('SendSupportFeedback')"/></TD>
 			</TR>
-			<TR><TD><b>Senha</b></TD><TD><input type="password" id="password"/>
-					<input id="bt_login" type="button" value="Conectar" onclick="javascript:jExecute('Login')"/>
-					<input id="bt_logout" type="button" value="Desconectar" onclick="javascript:jExecute('Logout')"/>
-					</TD></TR>
 		</TABLE>
-		<BR><BR>
-		<TABLE>
+		<BR>
+		<TABLE style="width:100%">
 			<TR><TD><b>Para</b></TD>		<TD><input type="text" id="msg_to"/></TD></TR>
 			<TR><TD><b>CC</b></TD>			<TD><input type="text" id="msg_cc"/></TD></TR>
@@ -64,60 +73,57 @@
 			<TR><TD><b>Assunto</b></TD>		<TD><input type="text" id="msg_subject"/></TD></TR>
 			<TR><TD><b>Conteudo</b></TD>	<TD><textarea id="text_message_body">Texto do e-mail enviado.</textarea></TD></TR>
-			<TR><TD><b>Anexos</b></TD>		<TD><input type="file" id="msg_attach_1"/></TD></TR>
-			<TR><TD></TD>					<TD><input type="file" id="msg_attach_2"/></TD></TR>
-			<TR><TD></TD>					<TD><input id="bt_send_msg" type="button" value="Enviar Mensagem" onclick="javascript:jExecute('Send')"/></TD></TR>
+			<TR><TD colspan=2><input type="file" id="msg_attach_1"/></TD></TR>
+			<TR><TD colspan=2><input type="file" id="msg_attach_2"/></TD></TR>
+			<TR><TD></TD>
+			<TD><input id="bt_send_msg" type="button" value="Enviar Mensagem" onclick="javascript:jExecute('Send')"/></TD></TR>
 		</TABLE>
-		<BR><BR>
-		<TABLE>
-			<TR><TD><b>Esvaziar Lixeira</b></TD>
-				<TD><input id="bt_esvaziar_lixeira" type="button" value="Esvaziar Lixeira" onclick="javascript:jExecute('CleanTrash')"/></TD>
+		<BR>
+		<TABLE style="width:100%">
+			<TR><TD nowrap><b>Pastas IMAP</b></TD>
+				<TD><input type="text" id="search_folders"/>
+				<input id="bt_listFolders" type="button" value="Pesquisar" onclick="javascript:jExecute('Mail/Folders')"/>
+				
+			<TR><TD></TD>
+				<TD colspan=2><select id="folder_id" onchange="javascript:jExecute('Mail/Messages')"><option value="INBOX">Selecionar pasta</option></select>
+				<input id="bt_del_folder" type="button" value="Apagar Pasta" onclick="javascript:jExecute('DelFolder')"/>
+				<input id="bt_clear_trash" type="button" value="Esvaziar Lixeira" onclick="javascript:jExecute('CleanTrash')"/>
+				<input id="bt_rename_folder" type="button" value="Renomear Pasta" onclick="javascript:jExecute('RenameFolder')"/>
+				</TD>
+				</TR>
+			<TR><TD></TD>
+				<TD colspan="3"><input type="text" id="new_folder_name"/>
+					<input id="bt_add_folder" type="button" value="Adicionar Pasta" onclick="javascript:jExecute('AddFolder')"/>
+				</TD>
 			</TR>
-			<TR><TD><b>Suporte/Sugest&atilde;o</b></TD>
-				<TD><textarea id="text_message">Texto do e-mail de suporte/sugestao!!</textarea></TD>
-				<TD><input id="bt_sugestao" type="button" value="Enviar Sugest&atilde;o" onclick="javascript:jExecute('SendSupportFeedback')"/></TD>
-			</TR>
-		</TABLE>
-		<BR><BR>
-		<TABLE>
-			<TR><TD><b>Pastas IMAP</b></TD>
-				<TD><input type="text" id="search_folders"/><input id="bt_listFolders" type="button" value="Pesquisar" onclick="javascript:jExecute('Mail/Folders')"/></TD>
-				<TD colspan=2><select id="folder_id" onchange="javascript:jExecute('Mail/Messages')"><option value="INBOX">Selecionar pasta</option></select>
+			<TR><TD colspan=3><HR></TD></TR>
+			<TR><TD><b>Mensagens</b></TD><TD>
 					<select id="message_id" onchange="javascript:jExecute('getMessage')"><option value="-1">Selecionar mensagem</option></select>
+			</TD></TR>
+			<TR><TD colspan=3><HR></TD></TR>
+			<TR><TD><b>Anexos</b></TD><TD>
 					<select id="attachment_id" onchange="javascript:jExecute('getAttachment')"><option value="-1">Selecionar Anexo</option></select>
 				</TD>
 			</TR>
-			<TR><TD></TD><TD></TD>
-				<TD colspan=2><input id="bt_del_folder" type="button" value="Apagar Pasta" onclick="javascript:jExecute('DelFolder')"/></TD>
-			</TR>
-			<TR><TD></TD><TD></TD>
-				<TD><input type="text" id="new_folder_name"/></TD>
-				<TD>
-					<input id="bt_add_folder" type="button" value="Adicionar Pasta" onclick="javascript:jExecute('AddFolder')"/><br>
-					<input id="bt_rename_folder" type="button" value="Renomear Pasta" onclick="javascript:jExecute('RenameFolder')"/>
+			</TABLE><BR>
+			<TABLE style="width:100%">
+			<TR><TD colspan=2><b>CatÃ¡logo</b></TD><TD><input type="radio" name="contactType" value="1" checked="checked">Pessoal<input type="radio" name="contactType" value="2"/>Global</TD></TR>
+			<TR><TD></TD>
+				<TD colspan=2><input type="text" id="search_catalog"/><input id="bt_catalog" type="button" value="Pesquisar" onclick="javascript:jExecute('getCatalog')"/>
+					<br><select id="sel_catalog" onchange="javascript:jExecute('getCatalogPicture')"><option value="-1">Selecionar contato</option></select>
 				</TD>
-			</TR>
-			<TR><TD><b>Contatos</b></TD>
-				<TD colspan=3><input type="text" id="search_contacts"/><input id="bt_contacts" type="button" value="Pesquisar" onclick="javascript:jExecute('getContacts')"/>
-					<select id="sel_contacts" onchange="javascript:jExecute('getContactPicture')"><option value="-1">Selecionar contato</option></select>
-
-				</TD>
-			</TR>
-			<TR><TD><b>Catalogo</b></TD>
-				<TD colspan=3>
-					<input type="text" id="search_catalog"/><input id="bt_catalog" type="button" value="Pesquisar" onclick="javascript:jExecute('getCatalog')"/>
-					<select id="sel_catalog" onchange="javascript:jExecute('getCatalogPicture')"><option value="-1">Selecionar contato</option></select>
-				</TD>
-			</TR>
+			</TR>			
 		</TABLE>
-		<BR><BR>
-		<TABLE>
-			<TR><TD><b>Resposta JSON-RPC</b>
+		</DIV>
+		<DIV style="overflow:auto;height:100%;float:right;width:69%">
+			<TABLE>
+				<TR><TD><b>Resposta JSON-RPC</b>
 				<input id="bt_clear" type="button" value="Limpar Sa&iacute;da" onclick="javascript:clearOut()"/>
-			</TD></TR>
-			<TR><TD style="background:#FFF !important;padding:0px;">
-				<img id="img_photo" style="display:none;"/>
-				<div id="message" class="jsonreport"></div>
-			</TD></TR>
-		</TABLE>
+				</TD></TR>
+				<TR><TD style="background:#FFF !important;padding:0px;">
+					<img id="img_photo" style="display:none;"/>
+					<div id="message" class="jsonreport"></div>
+				</TD></TR>
+			</TABLE>
+		</DIV>
 	</BODY>
 	<script language="Javascript">
@@ -135,49 +141,11 @@
 				setCookie ("auth", a_response.result.auth);
 				setCookie ("server", $('#server').val());
-				$('#user').attr("disabled", true);
-				$('#password').attr("disabled", true);
-				$('#server').attr("disabled", true);
-
-				$('#bt_servers').attr("disabled", true);
-				$('#bt_login').attr("disabled", true);
-				$('#bt_logout').prop('disabled',false);
-				$('#bt_listFolders').prop('disabled',false);
-				$('#bt_contacts').prop('disabled',false);
-				$('#bt_catalog').prop('disabled',false);
-				$('#sel_contacts').prop('disabled',false);
-				$('#sel_catalog').prop('disabled',false);
-				$('#search_contacts').prop('disabled',false);
-				$('#search_catalog').prop('disabled',false);
-				$('#search_folders').prop('disabled',false);
-
+				invalidateFields("in");
 			}
 			else if(_action == 'Logout' || (a_response.error && a_response.error.code == 7 )) {
-				$('#user').prop('disabled',false);
-				$('#password').prop('disabled',false);
-				$('#server').prop('disabled',false);
-
-				$('#bt_servers').prop('disabled',false);
-				$('#bt_login').prop('disabled',false);
-				$('#bt_logout').attr("disabled", true);
-				$('#bt_contacts').attr("disabled", true);
-				$('#bt_catalog').attr("disabled", true);
-				$('#bt_listFolders').attr("disabled", true);
-				$('#bt_del_folder').attr("disabled", true);
-				$('#bt_add_folder').attr("disabled", true);
-				$('#bt_rename_folder').attr("disabled", true);
-
-				$('#folder_id').attr("disabled", true);
-				$('#message_id').attr("disabled", true);
-				$('#attachment_id').attr("disabled", true);
-				$('#sel_contacts').attr("disabled", true);
-				$('#sel_catalog').attr("disabled", true);
-				$('#search_contacts').attr("disabled", true);
-				$('#search_catalog').attr("disabled", true);
-				$('#search_folders').attr("disabled", true);
-				$('#new_folder_name').attr("disabled", true);
-
 				clearOut();
 				setCookie ("auth", '');
 				setCookie ("server", '');
+				invalidateFields("out");
 			}
 		}
@@ -224,5 +192,5 @@
 					}
 					else{
-						$('#attachment_id').attr("disabled", true);
+						$('#attachment_id').prop("disabled", true);
 					}
 				}
@@ -240,17 +208,8 @@
 			}
 
-			var select_id = (_search == '#search_contacts' ? '#sel_contacts' : (_search == '#search_catalog' ? '#sel_catalog' : ''));
-			if(select_id)
-				$(select_id).find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>");
-
-			if(a_response.result.contacts && a_response.result.contacts.length > 0) {
-				for (var j in a_response.result.contacts){
-					var value = (a_response.result.contacts[j].contactFullName != null ? a_response.result.contacts[j].contactFullName  : "Vazio (ID "+a_response.result.contacts[j].contactID+")");
-					if(select_id){
-						$(select_id).append("<option value='"+a_response.result.contacts[j].contactID+"'>"+
-							value+"</option>");
-					}
-				}
-				if(a_response.result.contacts && a_response.result.contacts.length == 1) {
+			$('#sel_catalog').find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>");
+
+			if(a_response.result.contacts && a_response.result.contacts.length > 0) {				
+				if(a_response.result.contacts && a_response.result.contacts.length == 1 && a_response.result.contacts[0].contactImagePicture) {
 					if(a_response.result.contacts[0].contactImagePicture){
 						base64Data = a_response.result.contacts[0].contactImagePicture;
@@ -263,7 +222,13 @@
 					}
 				}
-				if(select_id){
-					$(select_id).prop('disabled',false);
-				}
+				else{
+					for (var j in a_response.result.contacts){
+						var value = (a_response.result.contacts[j].contactFullName != null ? a_response.result.contacts[j].contactFullName  : "Vazio (ID "+a_response.result.contacts[j].contactID+")");					
+							$('#sel_catalog').append("<option value='"+a_response.result.contacts[j].contactID+"'>"+
+								value+"</option>");					
+					}										
+				}
+				$('#sel_catalog').prop('disabled',false);
+				
 			}
 
@@ -286,6 +251,6 @@
 	function jExecute(_action){
 		var _server = getCookie('server') ? getCookie('server') : ($('#server').val() ? $('#server').val() : null);
-		var _contactType;
-		var _contactID;
+		var _contactType = $("input[name='contactType']:checked").val();
+		var _contactID = $("#sel_catalog").val();
 		var _search;
 		var _message;
@@ -303,4 +268,9 @@
 		}
 
+		if(_action == "AddFolder" || _action == "DelFolder" || _action == "RenameFolder" || _action == "CleanTrash"){ 
+			if(!confirm("Confirmar esta aÃ§Ã£o?"))
+				return;
+		}
+
 		switch(_action){
 			case 'Mail/Folders':
@@ -333,28 +303,15 @@
 				_message = $('#text_message').val();
 				break;
-			case 'getContacts':
-				_action = 'Catalog/Contacts';
-				_search = '#search_contacts';
-				_contactType = '1';
-				$("#sel_contacts").find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>");
-				break;
 			case 'getCatalog':
 				_action = 'Catalog/Contacts';
 				_search = '#search_catalog';
-				_contactType = '2';
-				$("#sel_catalog").find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>");
-				break;
-			case 'getContactPicture':
-				_action = 'Catalog/ContactPicture';
-				_contactID = '#sel_contacts';
-				_contactType = '1';
+				$("#sel_catalog").find('option').remove().end().append("<option value='-1'>Selecionar contato</option>");
 				break;
 			case 'getCatalogPicture':
 				_action = 'Catalog/ContactPicture';
-				_contactID = '#sel_catalog';
-				_contactType = '2';
 				break;
 			case 'GetMyPicture':
 				_action = 'Catalog/ContactPicture';
+				_contactID = "";
 				_contactType = '2';
 				break;
@@ -372,5 +329,5 @@
 			  				folderID:  $('#folder_id').val(),
 			  				msgID:  $('#message_id').val(),
-							contactID:  (_contactID ? $(_contactID).val() : ""),
+							contactID: _contactID,
 							message: _message,
 			  				contactType:  _contactType,
@@ -411,5 +368,5 @@
 		var _server = getCookie('server') ? getCookie('server') : ($('#server').val() ? $('#server').val() : null);		
 		var form = document.createElement("form");		
-		$(form).attr({"action":_server+"Mail/Attachment","method":"POST"});		
+		$(form).prop({"action":_server+"Mail/Attachment","method":"POST"});		
 		var attachment = JSON.parse($('#attachment_id').val());		
 		var _params = {
@@ -456,54 +413,57 @@
 	}
 	// Reset values
-	var isLoggedIn = false;
 	if(getCookie('auth') != null && getCookie('server') != null){
-		isLoggedIn = true;
-	}
-
-	if(isLoggedIn){
-		$('#user').attr("disabled", true);
-		$('#password').attr("disabled", true);
-		$('#server').attr("disabled", true);
-		$('#bt_servers').attr("disabled",true);
-		$('#bt_login').attr("disabled", true);
-		$('#user').attr("disabled", true);
-		$('#password').attr("disabled", true);
-		$('#server').attr("disabled", true);
-		$('#bt_servers').attr("disabled", true);
-		$('#bt_login').attr("disabled", true);
-	}
-	else{
-		$('#search_contacts').attr("disabled", true);
-		$('#search_catalog').attr("disabled", true);
-		$('#search_folders').attr("disabled", true);
-		$('#new_folder_name').attr("disabled", true);
-		$('#bt_contacts').attr("disabled", true);
-		$('#bt_catalog').attr("disabled", true);
-		$('#bt_del_folder').attr("disabled", true);
-		$('#bt_add_folder').attr("disabled", true);
-		$('#bt_rename_folder').attr("disabled", true);
-		$('#bt_logout').attr("disabled", true);
-		$('#bt_listFolders').attr("disabled", true);
-		$('#bt_logout').attr("disabled", true);
-		$('#bt_listFolders').attr("disabled", true);
-		$('#search_contacts').attr("disabled", true);
-		$('#search_catalog').attr("disabled", true);
-		$('#search_folders').attr("disabled", true);
-		$('#new_folder_name').attr("disabled", true);
-		$('#bt_contacts').attr("disabled", true);
-		$('#bt_catalog').attr("disabled", true);
-		$('#bt_del_folder').attr("disabled", true);
-		$('#bt_add_folder').attr("disabled", true);
-		$('#bt_rename_folder').attr("disabled", true);
-		$('#bt_version').attr("disabled", true);
-		$('#bt_clear').attr("disabled", true);
-	}
-
-	$('#folder_id').attr("disabled", true);
-	$('#message_id').attr("disabled", true);
-	$('#attachment_id').attr("disabled", true);
-	$('#contact_id').attr("disabled",true);
-	$('#sel_contacts').attr("disabled", true);
-	$('#sel_catalog').attr("disabled", true);
+		invalidateFields("in");
+	}
+	else
+		invalidateFields("out");
+	
+	
+	function invalidateFields(status){
+		
+		// Text Fields
+		$('#user').prop("disabled", status == "in");
+		$('#password').prop("disabled", status == "in");		
+		$('#msg_to').prop("disabled", status == "out");
+		$('#msg_cc').prop("disabled", status == "out");
+		$('#msg_bcc').prop("disabled", status == "out");
+		$('#msg_replyto').prop("disabled", status == "out");
+		$('#msg_subject').prop("disabled", status == "out");
+		$('#msg_attach_1').prop("disabled", status == "out");
+		$('#msg_attach_2').prop("disabled", status == "out");		
+		$('#new_folder_name').prop("disabled", status == "out");
+		$('#search_folders').prop("disabled", status == "out");
+		$('#search_catalog').prop("disabled", status == "out");		
+		
+		// Buttons
+		$('#bt_servers').prop("disabled", status == "in");
+		$('#bt_login').prop("disabled", status == "in");				
+		$('#bt_version').prop("disabled", status == "out");
+		$('#bt_logout').prop("disabled", status == "out");						
+		$('#bt_listFolders').prop("disabled", status == "out");		
+		$('#bt_add_folder').prop("disabled", status == "out");
+		$('#bt_del_folder').prop("disabled", status == "out");
+		$('#bt_rename_folder').prop("disabled", status == "out");
+		$('#bt_clear_trash').prop("disabled", status == "out");
+		$('#bt_clear').prop("disabled", status == "out");
+		$('#bt_sugestao').prop("disabled", status == "out");
+		$('#bt_send_msg').prop("disabled", status == "out");
+		$('#bt_catalog').prop("disabled", status == "out");
+		$('#bt_myPicture').prop("disabled", status == "out");
+		$('#bt_error').prop("disabled", status == "out");
+		$("input[name='contactType']").prop("disabled", status == "out");
+		
+
+		// Select Boxes
+		$('#folder_id').prop("disabled", status == "out");
+		$('#message_id').prop("disabled", status == "out");
+		$('#attachment_id').prop("disabled", status == "out");
+		$('#sel_catalog').prop("disabled", status == "out");
+		$('#server').prop("disabled", status == "in");		
+
+		// Text Areas
+		$('#text_message_body').prop("disabled", status == "out");
+		$('#text_message').prop("disabled", status == "out");
+	}
 	</script>
 </html>
