]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/SugarFields/Fields/Collection/SugarFieldCollection.js
Release 6.3.0beta1
[Github/sugarcrm.git] / jssource / src_files / include / SugarFields / Fields / Collection / SugarFieldCollection.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37 if(typeof(SUGAR.collection) == "undefined") {
38     SUGAR.collection = function(form_name, field_name, module, popupData){
39
40         /*
41          * boolean variable to handle expand/collapse views
42          * false if the collection field is collapsed and true if the rows are expanded.
43          */
44         this.more_status = false;
45         
46         /*
47          * Store the form name containing this field.  Example: EditView
48          */
49         this.form = form_name;
50         
51         /*
52          * Store the name of the collection field. Example: account_name 
53          */
54         this.field = field_name;
55         
56         
57         /*
58          * Store the unique form + field name that uses the combination of form and field
59          */
60         this.field_element_name = this.form + '_' + this.field;
61         
62         /*
63          * Store the name of the module from where come the field. Example: Accounts 
64          */
65         this.module = module;
66         
67         /*
68          * Number of secondaries linked records (total of linked records - 1). 
69          */
70         this.fields_count = 0;
71         
72         /*
73          * Number of extra fields. 
74          */
75         this.extra_fields_count = 0;
76         
77         /*
78          * Set to true if it is the initialization. 
79          */
80         this.first = true;
81         
82         /*
83          * Name of the primary field. Example: "accounts_collection_0" 
84          */
85         this.primary_field = "";
86         
87         /*
88          * Store the row cloned in key "0" and the context cloned in key "1". 
89          */
90         this.cloneField = new Array();
91         
92         /*
93          * Store the sqs_objects for the cloned row encoded in JSON. 
94          */
95         this.sqs_clone = "";
96         
97         /*
98          * Store the name and the id of all the secondaries linked records. this is used to create the secondary rows. 
99          */
100         this.secondaries_values = new Array();
101         
102         /*
103          * Store all the extra fields which has been updated in the collection field to save on save of the main record. 
104          */
105         this.update_fields = new Object();
106         
107         /*
108          * boolean variable indicating whether or not to show the expand/collapse arrow
109          */
110         this.show_more_image = true;
111
112     };
113     
114     SUGAR.collection.prototype = {
115         /*
116          * Remove the row designated by the passed 'id' or clear the row if there is only one row. 
117          */
118         remove: function(num){
119             // if there is only one record, clear it instead of removing it
120             // this is determined by the visibility of the drop down arrow element
121             var radio_els = this.get_radios();
122             var div_el;
123             if(radio_els.length == 1) {
124                 div_el = document.getElementById(this.field_element_name + '_input_div_' + num);
125                 var input_els = div_el.getElementsByTagName('input');
126                 //Clear text field
127                 input_els[0].value = '';
128                 
129                 //Clear hidden field
130                 input_els[1].value = '';
131                 
132                 if(this.primary_field) {
133                    div_el = document.getElementById(this.field_element_name + '_radio_div_' + num);
134                    radio_els = div_el.getElementsByTagName('input');
135                    //Clear the radio field
136                    radio_els[0].checked = false;
137                 }
138             } else {    
139                 div_el = document.getElementById(this.field_element_name + '_input_div_' + num);
140                 if (!div_el)
141                     div_el = document.getElementById(this.field_element_name + '_radio_div_' + num);
142                 var tr_to_remove = document.getElementById('lineFields_' + this.field_element_name + '_' + num);
143                 div_el.parentNode.parentNode.parentNode.removeChild(tr_to_remove);
144                 
145                 var div_id = 'lineFields_' + this.field_element_name + '_' + num;
146                 if (typeof sqs_objects[div_id.replace("_field_", "_")] != 'undefined') {
147                     delete (sqs_objects[div_id.replace("_field_", "_")]);
148                 }
149                 var checked=false;
150                 for(var k=0; k< radio_els.length; k++){
151                     if(radio_els[k].checked){
152                         checked=true;
153                     }
154                 }
155                 // If we remove an entry marked as the primary, set another record as the primary 
156                 var primary_checked = document.forms[this.form].elements[this.field+"_allowed_to_check"];
157                 var allowed_to_check = true;
158                 if(primary_checked && primary_checked.value == 'false'){
159                         allowed_to_check = false;
160                 }
161                 if(/EditView/.test(this.form) && !checked && typeof radio_els[0] != 'undefined' && allowed_to_check) {
162                     radio_els[0].checked = true;
163                     this.changePrimary(true);
164                     this.js_more();
165                     this.js_more();
166                 }
167                 // if there is now only one record, hide the "more..." link
168                 if(radio_els.length == 1){
169                     this.more_status = false;
170                                         if (document.getElementById('more_'+this.field_element_name) && document.getElementById('more_'+this.field_element_name).style.display != 'none') {
171                             document.getElementById('more_'+this.field_element_name).style.display='none';                      
172                                         }
173
174                     this.show_arrow_label(false);
175                     this.js_more();
176                 }else{
177                         this.js_more();
178                     this.js_more();
179                 }
180             }
181         },
182         
183         get_radios: function() {
184                 return YAHOO.util.Selector.query('input[name^=primary]', document.getElementById(this.field_element_name+'_table'));
185         },
186         
187         /*
188          * Add a new empty row.
189          */
190         add: function(values){
191             this.fields_count++;
192             var Field0 = this.init_clone(values);
193             this.cloneField[1].appendChild(Field0);
194             //Enable quicksearch for this field
195             enableQS(true);
196             this.changePrimary(false);
197                       
198             //If the arrow field and label are collapsed, un-collapse it
199             if(document.getElementById('more_'+this.field_element_name) && document.getElementById('more_'+this.field_element_name).style.display == 'none'){
200                document.getElementById('more_'+this.field_element_name).style.display='';
201             }
202             
203             if(!this.is_expanded()) {
204                this.js_more();
205                this.show_arrow_label(true);
206             }
207         },
208         
209         /*
210          * Add the secondaries rows on load of the page.
211          */
212         add_secondaries: function(){
213             var clone_id = this.form + '_' + this.field + '_collection_0';
214             YAHOO.util.Event.onContentReady(clone_id, function(c){
215                 c.create_clone();
216                 enableQS();
217                 c.changePrimary(true);
218                 for(key in c.secondaries_values){
219                     if (isInteger(key)) {
220                         c.add(c.secondaries_values[key]);
221                     }
222                 }
223                 c.js_more();
224                 // Update the "hash" of the unchanged form, because this is just adding data, not actually changing anything
225                 initEditView(document.forms[c.form]);
226             }, this);
227         },
228         /*
229          * Create the new row from a cloned row. 
230          */
231         init_clone: function(values){
232                 
233                 //Safety check, this means that the clone field was not created yet
234                 if(typeof this.cloneField[0] == 'undefined') {
235                    return;
236                 }
237                 
238             if (typeof values == "undefined") {
239                 values = new Array();
240                 values['name'] = "";
241                 values['id'] = "";
242             }
243             
244             var count = this.fields_count;
245             
246             //Clone the table element containing the fields for each row, use safe_clone uder IE to prevent events from being cloned
247             var Field0 = SUGAR.isIE ? 
248                 SUGAR.collection.safe_clone(this.cloneField[0], true) : 
249                 this.cloneField[0].cloneNode(true);
250
251             Field0.id = "lineFields_"+this.field_element_name+"_"+count;
252                         
253             for ( var ii = 0; ii < Field0.childNodes.length; ii++ ){
254                 if(typeof(Field0.childNodes[ii].tagName) != 'undefined' && Field0.childNodes[ii].tagName == "TD") {             
255                     for (var jj = 0; jj < Field0.childNodes[ii].childNodes.length; jj++) {
256                         currentNode = Field0.childNodes[ii].childNodes[jj];
257                         this.process_node(Field0.childNodes[ii], currentNode, values);
258                     } //for
259                 } //if
260             } //for
261             return Field0;
262         },
263         /**
264          * process_node
265          * 
266          * method to process cloning of nodes, moved out of init_clone so that
267          * this may be recursively called
268          */
269         process_node: function(parentNode, currentNode, values) {
270             if(parentNode.className == 'td_extra_field'){
271                 // If this is an extra field
272                 if(parentNode.id){
273                     parentNode.id='';
274                 }
275                 var toreplace = this.field + "_collection_extra_0";
276                 var re = new RegExp(toreplace, 'g');
277                 parentNode.innerHTML = parentNode.innerHTML.replace(re, this.field + "_collection_extra_" + this.fields_count);
278             } else if (currentNode.tagName && currentNode.tagName == 'SPAN') { 
279                 //If it is our div element, recursively find all input elements to process
280                 currentNode.id = /_input/.test(currentNode.id) ? this.field_element_name + '_input_div_' + this.fields_count :  this.field_element_name + '_radio_div_' + this.fields_count;            
281                                 if (/_input/.test(currentNode.id)) {
282                                         currentNode.name = 'teamset_div';
283                                 }
284                 
285                 var input_els = currentNode.getElementsByTagName('input');
286                 for ( var x = 0; x < input_els.length; x++ ){
287                         if(input_els[x].tagName && input_els[x].tagName == 'INPUT') {
288                            this.process_node(parentNode, input_els[x], values);
289                         }
290                 }
291             } else if (currentNode.name) {
292                 // If this is a standard field
293                 var toreplace = this.field + "_collection_0";
294                 var re = new RegExp(toreplace, 'g');
295                 var name = currentNode.name;                
296                 var new_name = name.replace(re, this.field + "_collection_" + this.fields_count);
297                 var new_id = currentNode.id.replace(re, this.field + "_collection_" + this.fields_count);
298
299                 switch (name) {
300                     case toreplace:
301                         var sqs_id = this.form + '_' + new_name;
302                         if (typeof this.sqs_clone != 'undefined') {
303                                 var sqs_clone = YAHOO.lang.JSON.stringify(this.sqs_clone);
304                             eval('sqs_objects[sqs_id]=' + sqs_clone);
305                             
306                             for (var pop_field in sqs_objects[sqs_id]['populate_list']) {
307                                 if (typeof sqs_objects[sqs_id]['populate_list'][pop_field] == 'string') {
308                                     sqs_objects[sqs_id]['populate_list'][pop_field] = sqs_objects[sqs_id]['populate_list'][pop_field].replace(RegExp('_0', 'g'), "_" + this.fields_count);
309                                 }
310                             }
311                             for (var req_field in sqs_objects[sqs_id]['required_list']) {
312                                 if (typeof sqs_objects[sqs_id]['required_list'][req_field] == 'string') {
313                                     sqs_objects[sqs_id]['required_list'][req_field] = sqs_objects[sqs_id]['required_list'][req_field].replace(RegExp('_0', 'g'), "_" + this.fields_count);
314                                 }
315                             }
316                         }
317                         
318                         currentNode.name = new_name;
319                         currentNode.id = new_id;
320                         currentNode.value = values['name'];
321                         break;
322                     case "id_" + toreplace:
323                         currentNode.name = new_name.replace(RegExp('_0', 'g'), "_" + this.fields_count);
324                         currentNode.id = new_id.replace(RegExp('_0', 'g'), "_" + this.fields_count);
325                         currentNode.value = values['id'];
326                         break;
327                     case "btn_" + toreplace:
328                         currentNode.name = new_name;
329                         currentNode.attributes['onclick'].value = currentNode.attributes['onclick'].value.replace(re, this.field + "_collection_" + this.fields_count);
330                         currentNode.attributes['onclick'].value = currentNode.attributes['onclick'].value.replace(RegExp(this.field + "_collection_extra_0", 'g'), this.field + "_collection_extra_" + this.fields_count);
331                         break;
332                     case "allow_new_value_" + toreplace:
333                         currentNode.name = new_name;
334                         currentNode.id = new_id;
335                         break;
336                     case "remove_" + toreplace:
337                         currentNode.name = new_name;
338                         currentNode.id = new_id;
339                         currentNode.setAttribute('collection_id', this.field_element_name);
340                         currentNode.setAttribute('remove_id', this.fields_count);
341                         currentNode.onclick = function() { 
342                                collection[this.getAttribute('collection_id')].remove(this.getAttribute('remove_id'));
343                         };
344                         break;
345                     case "primary_" + this.field + "_collection":
346                         currentNode.id = new_id;
347                         currentNode.value = this.fields_count;
348                         currentNode.checked = false; //Firefox
349                         currentNode.setAttribute('defaultChecked', '');
350                         break;
351                     default:
352                         alert(toreplace + '|' + currentNode.name + '|' + name + '|' + new_name);
353                         break;
354                 } //switch
355             } //if-else
356                 
357         },
358         
359         /*
360          * Collapse or expand the rows to show for the editview(depending of the this.more_status attribute).
361          */
362         js_more: function(val){
363             if(this.show_more_image){
364                     var more_ = document.getElementById('more_img_'+this.field_element_name);
365                     var arrow = document.getElementById('arrow_'+this.field);
366                     var radios = this.get_radios();
367                     // if we want to collapse
368                     if(this.more_status == false){
369                         more_.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=advanced_search.gif";
370                         this.more_status = true;
371                         // show the primary only and hidde the other one.
372                         var hidden_count = 0;
373                         for(var k=0; k< radios.length; k++){
374                             if (radios[k].type && radios[k].type == 'radio') {
375                                 if (radios[k].checked) {
376                                     radios[k].parentNode.parentNode.parentNode.style.display = '';
377                                 } else {
378                                     radios[k].parentNode.parentNode.parentNode.style.display = 'none';
379                                     hidden_count++;
380                                 }
381                             }
382                         }
383                         //rrs - add code to not remove the first field if non if the fields are selected as primary
384                         if(hidden_count == radios.length){
385                                 radios[0].parentNode.parentNode.parentNode.style.display = '';
386                         }
387                         
388                         arrow.value = 'hide';
389                     }else{
390                         more_.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=basic_search.gif";
391                         this.more_status=false;
392                         // display all the records
393                         for(var k=0; k< radios.length; k++){
394                             if(isInteger(k)){
395                                 radios[k].parentNode.parentNode.parentNode.style.display='';
396                             }
397                         }
398
399                         arrow.value = 'show';
400                     }
401
402                     var more_div = document.getElementById('more_div_'+this.field_element_name);
403                     if(more_div) {
404                       more_div.innerHTML = arrow.value == 'show' ? SUGAR.language.get('app_strings','LBL_HIDE') : SUGAR.language.get('app_strings','LBL_SHOW');
405                     }
406                     
407                 }
408         },
409         /*
410          * Create the clone on load of the page and store it in this.cloneField
411          */
412         create_clone: function() {
413             var oneField = document.getElementById('lineFields_'+this.field_element_name+'_0');
414             this.cloneField[0] = SUGAR.isIE ?
415                 SUGAR.collection.safe_clone(oneField, true) :
416                 oneField.cloneNode(true);
417             this.cloneField[1] = oneField.parentNode;
418             this.more_status = true;
419             var clone_id = this.form + '_' + this.field + '_collection_0';
420
421             if (typeof sqs_objects != 'undefined' && typeof sqs_objects[clone_id] != 'undefined') {
422                 var clone = YAHOO.lang.JSON.stringify(sqs_objects[clone_id]);
423                 eval('this.sqs_clone=' + clone);
424             }
425         },
426         /**
427          * Validates team set to check if the primary team id has been set or not
428          */
429                 validateTemSet : function(formname, fieldname) {
430                         var table_element_id = formname + '_' + fieldname + '_table';
431                         if(document.getElementById(table_element_id)) {
432                            var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
433                            var has_primary = false;
434                            var primary_field_id = fieldname + '_collection_0';
435                            for(t in input_elements) {
436                                     primary_field_id = fieldname + '_collection_' + input_elements[t].value;
437                                 if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
438                                    if(document.forms[formname].elements[primary_field_id].value != '') {
439                                           has_primary = true;
440                                    }
441                                    break;
442                                 }                                                                  
443                            }       
444                            if(!has_primary) {
445                                         return false;
446                            }
447                            return true;
448                         }
449                         return true;
450                 }, 
451         /**
452          * return an array of teamids for a team field
453          */
454                 getTeamIdsfromUI: function(formname, fieldname) {
455                         var team_ids = new Array();
456                         var table_element_id = formname + '_' + fieldname + '_table';
457                         if(document.getElementById(table_element_id)) {
458                            input_elements = YAHOO.util.Selector.query('input[type=hidden]', document.getElementById(table_element_id));
459                            for(t = 0; t < input_elements.length; t++) {
460                              if (input_elements[t].id.match("id_" + fieldname + "_collection_") != null) {
461                                 team_ids.push(input_elements[t].value);
462                              } // if
463                            } // for                
464                         } // if
465                     return team_ids;
466                 },
467         /**
468          * return a primary team id
469          */
470                 getPrimaryTeamidsFromUI: function(formname, fieldname) {
471                         var table_element_id = formname + '_' + fieldname + '_table';
472                         if(document.getElementById(table_element_id)) {
473                                 var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
474                                 for(t in input_elements) {
475                                         var primary_field_id = 'id_' + document.forms[formname][fieldname].name + '_collection_' + input_elements[t].value;
476                                         if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
477                                            if(document.forms[formname].elements[primary_field_id].value != '') {
478                                                    return document.forms[formname].elements[primary_field_id].value;
479                                            } // if
480                                         } // if
481                                 } // for
482                         } // if
483                         return '';      
484                 },
485         /*
486          * Change the primary row onchange of the radio button.
487          */
488         changePrimary: function(noAdd){
489             var old_primary = this.primary_field;
490             var radios=this.get_radios();
491             for (var k = 0; k < radios.length; k++) {
492                 var qs_id = radios[k].id.replace('primary_','');
493                 if (radios[k].checked) {
494                     this.primary_field = qs_id;
495                 } else {
496                         qs_id = qs_id + '_' + k;
497                 }
498
499                 qs_id = this.form + '_' + qs_id;
500
501                 if(typeof sqs_objects != 'undefined' && typeof sqs_objects[qs_id] != 'undefined' && sqs_objects[qs_id]['primary_field_list']){
502                     for (var ii = 0; ii < sqs_objects[qs_id]['primary_field_list'].length; ii++) {
503                         if (radios[k].checked && qs_id != old_primary) {
504                             sqs_objects[qs_id]['field_list'].push(sqs_objects[qs_id]['primary_field_list'][ii]);
505                             sqs_objects[qs_id]['populate_list'].push(sqs_objects[qs_id]['primary_populate_list'][ii]);
506                         }else if(old_primary == qs_id && !radios[k].checked){
507                             sqs_objects[qs_id]['field_list'].pop();
508                             sqs_objects[qs_id]['populate_list'].pop();
509                         }
510                     }
511                 }
512             }
513             
514             if (noAdd) {
515                 enableQS(false);
516             }
517             this.first = false;
518         },
519         /*
520          * Collapse or expand the rows to show for the detailview. 
521          */
522         js_more_detail: function(id){
523             var more_img = document.getElementById('more_img_'+id);
524             if(more_img.style.display == 'inline'){
525                 more_img.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=advanced_search.gif";
526             }else{
527                 more_img.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=basic_search.gif";
528             }
529         },
530         /*
531          * Replace the first field with the specified values
532          */
533         replace_first: function(values){
534                 for (var i = 0; i <= this.fields_count; i++) {
535                         var div_el = document.getElementById(this.field_element_name + '_input_div_' + i);
536                 if(div_el) { 
537                                 var name_field = document.getElementById(this.field_element_name+"_collection_" + i);
538                                         var id_field = document.getElementById("id_"+this.field_element_name+"_collection_" + i);
539                                 name_field.value = values['name'];
540                                 id_field.value = values['id'];
541                                 break;
542                 }
543                 }
544         },
545         /*
546          * Remove all empty fields from the widget.
547          */
548         clean_up: function(){
549             //clean up any rows that have been added but do not contain any data
550             var divsToClean = new Array();
551             var isFirstFieldEmpty = false;
552             var divCount = 0;
553             for (var i = 0; i <= this.fields_count; i++) {
554                 var div_el = document.getElementById(this.field_element_name + '_input_div_' + i);
555                 if(div_el) {        
556                         input_els = div_el.getElementsByTagName('input');
557                         for ( var x = 0; x < input_els.length; x++ ){
558                                 if(input_els[x].id && input_els[x].name == (this.field + '_collection_' + i) && trim(input_els[x].value) == '') {
559                                         if(divCount == 0){
560                                                 isFirstFieldEmpty = true;
561                                         } else {
562                                                 divsToClean.push(i);
563                                         }
564                                 }
565                                 
566                         }
567                         divCount++;
568                 }
569             }
570
571             for(var j = 0; j < divsToClean.length; j++){
572                 this.remove(divsToClean[j]);
573             }
574             return isFirstFieldEmpty;
575         },
576         
577         show_arrow_label: function(show) {
578             var more_div = document.getElementById('more_div_'+this.field_element_name);
579             if(more_div) {
580                more_div.style.display = show ? '' : 'none';
581             }           
582         },
583         
584         /**
585          * is_expanded
586          * helper function to determine whether or not the widget is expanded (all teams are shown)
587          */
588         is_expanded: function() {
589             var more_div = document.getElementById('more_div_'+this.field_element_name);
590             if(more_div) {
591                return more_div.style.display == '';
592             }
593             return false;
594         }
595     };
596
597         SUGAR.collection.safe_clone = function(e, recursive)
598         {
599                 if (e.nodeName == "#text")
600                 {
601                         return document.createTextNode(e.data);
602                 }
603                 if(!e.tagName) return false;
604                 
605                 var newNode = document.createElement(e.tagName);
606                 if (!newNode) return false;
607                 
608                 var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'height', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
609
610         //clee. - Bug: 44976 - IE7 just does not calculate height properties correctly for input elements
611                 if(SUGAR.isIE7 && e.tagName.toLowerCase() == 'input')
612                 {
613                         var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
614                 } else {
615                         var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'height', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
616                 }
617                 
618                 for (var i in properties)
619                 {
620                         if (e[properties[i]])
621                         {
622                                 if ((properties[i] != 'style' || !SUGAR.isIE) && 
623                                         //Only <a> and <iframe> tags can have hrefs
624                                         (properties[i] != 'href'  || e.tagName == 'a' || e.tagName == 'iframe'))
625                                         newNode[properties[i]] = e[properties[i]];
626                         }
627                 }
628                 if(recursive)
629                 {
630                         for (var i in e.childNodes)
631                         {
632                                 if(e.childNodes[i].nodeName && (!e.className || e.className != "yui-ac-container"))
633                                 {
634                                         var child = SUGAR.collection.safe_clone(e.childNodes[i], true);
635                                         if (child) newNode.appendChild(child);
636                                 }
637                         }
638                 }
639                 return newNode;
640         }
641 }