Index: /sandbox/expressoMail1_2/corretor_ortografico/spell_checker/js/spell_checker.js
===================================================================
--- /sandbox/expressoMail1_2/corretor_ortografico/spell_checker/js/spell_checker.js	(revision 2477)
+++ /sandbox/expressoMail1_2/corretor_ortografico/spell_checker/js/spell_checker.js	(revision 2486)
@@ -48,4 +48,5 @@
 cp.set_transfer_mode('post');
 cp.set_response_type('text');
+
 function beginSpellCheck(){
 if(!blockSpellCheck){
@@ -53,4 +54,5 @@
     area = "body_" + currentTab;
     aba = currentTab;
+
     //var cp = new cpaint();
     // alert("Seta globals");
@@ -94,19 +96,19 @@
 // If there are already any onload handlers loaded in the page, we'll add our onload
 // handler first and then call the old one, rather than completely overriding it.
-if(window.onload)
-{
-        window.onload = new setupSpellCheckers();
-	
-        /*var old_onload = window.onload;
-	window.onload = function(e)
-	{
-		var test = new setupSpellCheckers(e);
-		old_onload(e);
-	}*/
-}
-else
-{
-	window.onload = new setupSpellCheckers();
-}
+    if(window.onload)
+    {
+            window.onload = new setupSpellCheckers();
+
+            /*var old_onload = window.onload;
+            window.onload = function(e)
+            {
+                    var test = new setupSpellCheckers(e);
+                    old_onload(e);
+            }*/
+    }
+    else
+    {
+            window.onload = new setupSpellCheckers();
+    }
 
 //window.onload =new setupSpellCheckers();
@@ -135,7 +137,7 @@
 
     if(ifr.contentWindow)
-    ifr=ifr.contentWindow.document;
+        ifr=ifr.contentWindow.document;
     else
-    ifr=ifr.contentDocument;
+        ifr=ifr.contentDocument;
     var texto = ifr.body.innerHTML;
 
@@ -148,5 +150,4 @@
 
 function setupSpellChecker(){
-
 
         currObj = this;
@@ -171,5 +172,8 @@
 	currObj.controlPanelDiv.className = 'control_panel';
         currObj.controlPanelDiv.id = 'control_panel_' + currentTab;
-	document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv);
+	document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv); 
+       
+       
+        
 
 	//the span that toggles between spell checking and editing
@@ -223,6 +227,7 @@
 function ajaxSpell(varName, width, height, spellUrl, divId, name, id, title, value)
 {
-        
-       currObj = this;
+
+        currObj = this;
+
 
 	currObj.config               = new Array();         //the array of configuration options
@@ -307,4 +312,6 @@
 	ajaxSpell.prototype.resetSpellChecker    = resetSpellChecker;
 	ajaxSpell.prototype.resetAction          = resetAction;
+        
+
 
       
@@ -327,4 +334,45 @@
         
 }; // end setCurrentObject
+
+
+/*************************************************************
+ * showMenu
+ *
+ * This function is associated with the click event
+ *  of all the tags span with correctd_word class.
+ *
+ *************************************************************/
+function showMenu(){
+    var evento = this.onclick.toString();
+    evento = evento.replace("function onclick(event) {", "");
+    evento = evento.replace("}", "");
+    var array_func = evento.split(";");
+    eval(array_func[0]);
+    eval(array_func[1]);
+    return false;   
+}
+
+/*************************************************************
+ * showMenu
+ *
+ * This function is associated with the click event
+ *  of all the tags div with suggestion class.
+ *
+ *************************************************************/
+function replaceMenu(){
+    var evento = this.onclick.toString();
+    if(spellingSuggestionsDiv)
+    {
+
+        spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
+	spellingSuggestionsDiv = null;
+    }
+    evento = evento.replace("function onclick(event) {", "");
+    evento = evento.replace("}", "");
+    var array_func = evento.split(";");
+    eval(array_func[0]);
+    return false;
+}
+
 
 
@@ -344,6 +392,14 @@
 function spellCheck_cb(new_data)
 {
+	 //adicionado nathalie
+        var ifr= currObj.objToCheck;
+        if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+        else
+            ifr=ifr.contentDocument;
+
 
         with(currObj);
+
 	new_data = new_data.toString();
 	var isThereAMisspelling = new_data.charAt(0);
@@ -353,7 +409,20 @@
 	{
             
-		currObj.spellingResultsDiv.parentNode.removeChild(spellingResultsDiv);
-	}
-
+		ifr.removeChild(currObj.spellingResultsDiv.id);
+                
+	}
+
+        
+        /*currObj.spellingResultsDiv =  document.createElement('DIV');
+	currObj.spellingResultsDiv.className = 'edit_box';
+        currObj.spellingResultsDiv.id = 'edit_box'; //Added the id property - By Nathalie
+	currObj.spellingResultsDiv.style.width =  "99%";//the width of the textarea
+	currObj.spellingResultsDiv.style.height = 300;  //   = height; //currObj.objToCheck.style.height;
+	currObj.spellingResultsDiv.innerHTML = new_data;       
+      	currObj.objToCheck.style.display = "none";
+	currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv,currObj.objToCheck);
+	currObj.statusSpan.innerHTML = ""; */
+
+        //Testes nathalie - substituido
         currObj.spellingResultsDiv =  document.createElement('DIV');
 	currObj.spellingResultsDiv.className = 'edit_box';
@@ -361,13 +430,46 @@
 	currObj.spellingResultsDiv.style.width =  "99%";//the width of the textarea
 	currObj.spellingResultsDiv.style.height = 300;  //   = height; //currObj.objToCheck.style.height;
-	currObj.spellingResultsDiv.innerHTML = new_data;
-
-       	currObj.objToCheck.style.display = "none";
+     	currObj.spellingResultsDiv.innerHTML = new_data;
+        currObj.spellingResultsDiv.border = 0;
+        //currObj.spellingResultsDiv.style.display = "none";
+      	//currObj.objToCheck.style.display = "none";
+	currObj.statusSpan.innerHTML = ""; 
+       
+        // Teste de iFrame - Nathalie
+         var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+         ifr.body.innerHTML =  "";
+         var cssLink = document.createElement("link")
+         cssLink.href = "spell_checker/css/spell_checker.css";
+         cssLink .rel = "stylesheet";
+         cssLink .type = "text/css";            
+         ifr.body.appendChild(cssLink);     
+         ifr.body.appendChild(currObj.spellingResultsDiv);
+
+
+        // Obtain all the span tags which have highlight className
+        //    and add the eventListener for the click - This event shows the suggestions menu
+        var nodeArray = ifr.getElementsByTagName("span");
+        var totArray = nodeArray.length;
+        for (var i = 0 ; i < totArray ; i++) {
+            var node = nodeArray[i];
+            if (node.className == "highlight") {
+                ifr.getElementsByTagName("span")[i].addEventListener("click", showMenu , true);
+
+            }
+        }
+
+
+//adicionado Paula
+//    currObj.objToCheck.style.display = "none"; //Paula
         //currObj.objToCheck.parentNode.
         //currObj.objToCheck.parentNode.appendChild(currObj.spellingResultsDiv,currObj.objToCheck);
-	currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab));
+//	currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab)); //Paula
 	currObj.statusSpan.innerHTML = "";    
-        
-     
+
+        
 	if(currObj.config['useIcons'])
 	{
@@ -406,5 +508,51 @@
  *************************************************************/
 function spellCheck() {
-
+// adicionado nathalie
+/*        with(currObj);
+	var query;
+
+	if(currObj.spellingResultsDiv)
+	{
+		currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
+		currObj.spellingResultsDiv = null;
+	}
+	
+	if(currObj.config['useIcons'])
+	{
+		currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Verificar Ortografia\" alt=\"Verificar Ortografia\" border=\"0\" />";
+	}
+	else
+	{
+		currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Verificar Ortografia</a>";
+	}
+	
+	if(currObj.config['useIcons'])
+	{
+		currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Verificando Ortografia...\" alt=\"Verificando Ortografia...\" border=\"0\" />";
+	}
+	else
+	{
+		currObj.statusSpan.innerHTML = "Verificando Ortografia...";
+	}	
+        
+        // Obtain the HTML content from iframe (edit area)
+         var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+         var texto = ifr.body.innerHTML;
+        
+        
+        query = texto;
+        //query = currObj.objToCheck.value;        
+        
+	//query = query.replace(/\r?\n/gi, "<br />"); //  Commented from the original by Nathalie
+        query = query.replace(/\r?\n/gi, " ");  // replace \n with " " - By Nathalie
+       
+	
+	cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName']);
+*/
+//adicionado Paula
         if(!blockSpellCheck) {
             blockSpellCheck = true;
@@ -472,5 +620,5 @@
 function addWord(id)
 {
-	var wordToAdd = document.getElementById(id).innerHTML;
+        var wordToAdd = document.getElementById(id).innerHTML;
 	
 	with(currObj);
@@ -509,5 +657,6 @@
 function addWord_cb(returnedData)
 {
-	with(currObj);
+	
+        with(currObj);
 	currObj.statusSpan.innerHTML = "";
 	resumeEditing();
@@ -570,4 +719,5 @@
 function getTarget(e)
 {
+        
 	var value;
 	if(checkBrowser() == "ie")
@@ -594,6 +744,5 @@
 function checkBrowser()
 {
-      
-	var theAgent = navigator.userAgent.toLowerCase();
+        var theAgent = navigator.userAgent.toLowerCase();
 	if(theAgent.indexOf("msie") != -1)
 	{
@@ -658,4 +807,23 @@
 	spellingSuggestionsDiv.style.display = 'block';
 	currObj.statusSpan.innerHTML = "";
+
+        //adicionado os listener - nathalie
+         var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+
+        var nodeArray = ifr.getElementsByTagName("div");
+        var totArray = nodeArray.length;
+        for (var i = 0 ; i < totArray ; i++) {
+            var node = nodeArray[i];
+            if (node.className == "suggestion" || node.className == "ignore" ) {
+                ifr.getElementsByTagName("div")[i].addEventListener("click", replaceMenu , true);
+
+            }
+        }
+
+
 }; //end showSuggestions_cb
 
@@ -678,7 +846,17 @@
 function showSuggestions(word, id)
 {
+        
+        //adicionado nathalie
+         var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+
+//alterado - colocar ifr
         language =  document.getElementById("selectLanguage");
         language = language[document.getElementById("selectLanguage").selectedIndex].value;
         
+     
         with(currObj);
 	if(currObj.config['useIcons'])
@@ -690,11 +868,15 @@
 		currObj.statusSpan.innerHTML = "Procurando...";
 	}
+       
 	var x = findPosXById(id);
-	var y = findPosYById(id);
-	
-	var scrollPos = 0;
+	var y = findPosYById(id);      
+        
+        var scrollPos = 0;
 	if(checkBrowser() != "ie")
 	{
-		scrollPos = currObj.spellingResultsDiv.scrollTop;
+		
+                //scrollPos = currObj.spellingResultsDiv.scrollTop;
+                scrollPos = ifr.getElementById(currObj.spellingResultsDiv.id).scrollTop;
+               
 	}
 
@@ -709,4 +891,7 @@
 	spellingSuggestionsDiv.style.left = x + 'px';
 	spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px';
+       
+        
+               
 	
 	// Bah. There's got to be a better way to deal with this, but the click
@@ -714,37 +899,106 @@
 	// showing and hiding the suggestion box, so we'll ignore the first
 	// click.
-	spellingSuggestionsDiv.ignoreNextClick = true;
-	
-	document.body.appendChild(spellingSuggestionsDiv);
-	
+	//spellingSuggestionsDiv.ignoreNextClick = true; // comentado Nathalie
+
+        
+	//document.body.appendChild(spellingSuggestionsDiv);
+        ifr.body.appendChild(spellingSuggestionsDiv); //alterado nathalie
+        
+
+
+
+        
 	cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id, language);
 }; // end showSuggestions
 
 
+
 /*************************************************************
  * replaceWord
  *
- * The replaceWord function takes the id of the misspelled word
- * that the user clicked on and replaces the innerHTML of that
- * span with the new word that the user selects from the suggestion
- * div.  It hides the suggestions div and changes the color of
+ * The replaceWord function replaces the innerHTML of all the span tags
+ * that contains the old word with the new word that the user selects
+ * from the suggestion div.  It hides the suggestions div and changes the color of
  * the previously misspelled word to green to let the user know
  * it has been changed.  It then calls the switchText php function
  * with the innerHTML of the div to update the text of the text box.
  *
- * @param id The id of the span that contains the word to be replaced
- * @param newWord The word the user selected from the suggestions div
+ * @param id The id of the element to be checked
+ * @param newword The word the user selected from the suggestions div
  *                to replace the misspelled word.
  *************************************************************/
 function replaceWord(id, newWord)
 {
-     
-	document.getElementById(id).innerHTML = trim(newWord);
-	if(spellingSuggestionsDiv)
-	{
+
+   
+    var ifr= currObj.objToCheck;
+    if(ifr.contentWindow)
+        ifr=ifr.contentWindow.document;
+    else
+        ifr=ifr.contentDocument;
+
+    var valorNo = trim(ifr.getElementById(id).innerHTML);
+   
+
+    if(spellingSuggestionsDiv)
+    {
+    spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
+    spellingSuggestionsDiv = null;
+    }
+
+
+    // Obtain all span tags which have highlight className and contais the old word
+    var nodeArray = ifr.getElementsByTagName("span");
+    var totArray = nodeArray.length;
+    var nodeRemove = new Array(totArray);
+    var j = -1;
+    for (var i = 0 ; i < totArray ; i++) {
+        var node = nodeArray[i];
+        if (node.className == "highlight" && trim(node.innerHTML) == valorNo ) {
+            j++;
+            nodeRemove[j] = node.id;
+        }
+    }
+
+    //Replace the class of the span tags with highlight and the innerHTML with the new_word
+    for (var i = 0 ; i <= j ; i++) {
+        ifr.getElementById(nodeRemove[i]).innerHTML = newWord;
+        ifr.getElementById(nodeRemove[i]).className = "corrected_word";
+    }
+
+
+    return false;
+
+
+// FIMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
+
+         //FunÃ§Ã£o antiga - substitui apenas uma palavra
+   /*       var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+
+        var valorNo = trim(newWord);        
+        if(spellingSuggestionsDiv)
+	{
+
+                spellingSuggestionsDiv.style.display = 'none';
 		spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
 		spellingSuggestionsDiv = null;
 	}
-	document.getElementById(id).className = "corrected_word";
+	
+        var fake = document.createTextNode(valorNo);
+        
+       var parent =  ifr.getElementById(id).parentNode;
+
+            
+       parent.replaceChild(fake, ifr.getElementById(id)); 
+
+        return false;*/
+
+            
+
+
 }; // end replaceWord
 
@@ -765,10 +1019,16 @@
 function switchText()
 {
-
+        
         with(currObj);
         //By Nathalie - The Element means that this div belongs to the current tab
-        var parentElement = Element(currObj.spellingResultsDiv.id); 
+        //var parentElement = Element(currObj.spellingResultsDiv.id); //alterado nathalie
+        var ifr= currObj.objToCheck;
+        if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+        else
+            ifr=ifr.contentDocument;
+        var parentElement =ifr.getElementById(currObj.spellingResultsDiv.id); //alterado nathalie
         // Obtain all span tags which have highlight className or corrected_word className
-        var nodeArray = parentElement.getElementsByTagName("span");
+        var nodeArray = ifr.getElementsByTagName("span");
         var totArray = nodeArray.length;
         var nodeRemove = new Array(totArray);
@@ -787,11 +1047,11 @@
         //Remove span tags which have highlight className or corrected_word className
         for (var i = 0 ; i <= j ; i++) {
-            var valorNo = document.getElementById(nodeRemove[i]).innerHTML;
+            var valorNo = ifr.getElementById(nodeRemove[i]).innerHTML;
             var fake = document.createTextNode(valorNo);
-            var parent =  document.getElementById(nodeRemove[i]).parentNode;
-            parent.replaceChild(fake, document.getElementById(nodeRemove[i]));            
+            var parent =  ifr.getElementById(nodeRemove[i]).parentNode;
+            parent.replaceChild(fake, ifr.getElementById(nodeRemove[i]));
         }
 
-       var text = currObj.spellingResultsDiv.innerHTML;
+	var text = ifr.getElementById(currObj.spellingResultsDiv.id).innerHTML;
 
         text = text.replace(/&nbsp;/gi, " %u2026 "); // Replace &nbsp; with the code %u2026
@@ -816,6 +1076,8 @@
 function switchText_cb(new_string)
 {
-    
-        with(currObj);
+
+
+//adicionado Paula
+    with(currObj);
 
         new_string = new_string.replace(/ %u2026/gi, "&nbsp;"); // Replace the code %u2026 with &nbsp;
@@ -834,13 +1096,19 @@
             ifr=ifr.contentDocument;
          var texto = ifr.body.innerHTML;
-     
+
+         ifr.body.innerHTM = ""; //adicionado nathalie
          ifr.body.innerHTML = new_string;
+         currObj.spellingResultsDiv = null; //adicionado nathalie
+
+         
+
 	currObj.objToCheck.disabled = false;
         
-	if(currObj.spellingResultsDiv)
-	{
-		currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
+	//Removido Nathalie
+        /*if(currObj.spellingResultsDiv)
+	{
+		ifr.removeChild(currObj.spellingResultsDiv); //Alterado nathalie
 		currObj.spellingResultsDiv = null;
-	}
+	}*/
 	currObj.objToCheck.style.display = "block";
 	currObj.resetAction();
@@ -884,5 +1152,5 @@
 	{
 		
-                spellingSuggestionsDiv.id.parentNode.removeChild(spellingSuggestionsDiv); 
+                spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 
 		spellingSuggestionsDiv = null;
 	}
@@ -900,4 +1168,6 @@
 function resetAction()
 {
+
+//adicionado Paula
 	with(currObj);
 	/*if(currObj.config['useIcons'])
@@ -925,6 +1195,14 @@
 function resetSpellChecker()
 {
-   
-	with(currObj);
+        
+	//adicionado nathalie
+        var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+
+
+        with(currObj);
 	currObj.resetAction();
 	
@@ -935,5 +1213,5 @@
 	if(currObj.spellingResultsDiv)
 	{
-		currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
+		ifr.removeChild(currObj.spellingResultsDiv); //alterado nathalie
 		currObj.spellingResultsDiv = null;
 	}
@@ -958,9 +1236,20 @@
  * @return int The X coordinate of the object
  *************************************************************/
-function findPosXById(object)
-{
-	
+    function findPosXById(object)
+{
+        
+        //adicionado Nathalie
+        var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+        var obj = ifr.getElementById(object);
+
+
         var curleft = 0;
-	var obj = document.getElementById(object);
+	//var obj = document.getElementById(object); //removido nathalie
+
+
 	if(obj.offsetParent)
 	{
@@ -991,7 +1280,16 @@
 function findPosYById(object)
 {
+        
+        //adicionado Nathalie
+        var ifr= currObj.objToCheck;
+         if(ifr.contentWindow)
+            ifr=ifr.contentWindow.document;
+         else
+            ifr=ifr.contentDocument;
+        var obj = ifr.getElementById(object); //removido Nathalie
+
     
 	var curtop = 0;var curtop = 0;
-	var obj = document.getElementById(object);
+	//var obj = document.getElementById(object); //removido Nathalie
 	if(obj.offsetParent)
 	{
