]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/SugarFields/Fields/Collection/SugarFieldCollection.js
Release 6.2.2
[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             clone_id = this.form + '_' + this.field + '_collection_0';
214
215             if(typeof sqs_objects == 'undefined' || typeof sqs_objects[clone_id] == 'undefined') {
216                 setTimeout('collection["'+this.field_element_name+'"].add_secondaries();',100); // Lowering timeout as per dwheeler to avoid SODA errors
217             } else if(typeof document.getElementById(this.form + '_' + this.field + '_collection_0') == 'undefined'){
218                 setTimeout('collection["'+this.field_element_name+'"].add_secondaries();',100);
219             } else {
220                 this.create_clone();
221                 enableQS();
222                 this.changePrimary(true);
223                 for(key in this.secondaries_values){
224                     if (isInteger(key)) {
225                         this.add(this.secondaries_values[key]);
226                     }
227                 }
228                 this.js_more();
229                 this.js_more();
230             }
231             // Update the "hash" of the unchanged form, because this is just adding data, not actually changing anything
232             initEditView(document.forms[this.form]);
233         },
234         /*
235          * Create the new row from a cloned row.
236          */
237         init_clone: function(values){
238
239                 //Safety check, this means that the clone field was not created yet
240                 if(typeof this.cloneField[0] == 'undefined') {
241                    return;
242                 }
243
244             if (typeof values == "undefined") {
245                 values = new Array();
246                 values['name'] = "";
247                 values['id'] = "";
248             }
249
250             var count = this.fields_count;
251
252             //Clone the table element containing the fields for each row, use safe_clone uder IE to prevent events from being cloned
253             Field0 = SUGAR.isIE ?
254                 SUGAR.collection.safe_clone(this.cloneField[0], true) :
255                 this.cloneField[0].cloneNode(true);
256
257             Field0.id = "lineFields_"+this.field_element_name+"_"+count;
258
259             for ( var ii = 0; ii < Field0.childNodes.length; ii++ ){
260                 if(typeof(Field0.childNodes[ii].tagName) != 'undefined' && Field0.childNodes[ii].tagName == "TD") {
261                     for (var jj = 0; jj < Field0.childNodes[ii].childNodes.length; jj++) {
262                         currentNode = Field0.childNodes[ii].childNodes[jj];
263                         this.process_node(Field0.childNodes[ii], currentNode, values);
264                     } //for
265                 } //if
266             } //for
267             return Field0;
268         },
269         /**
270          * process_node
271          *
272          * method to process cloning of nodes, moved out of init_clone so that
273          * this may be recursively called
274          */
275         process_node: function(parentNode, currentNode, values) {
276             if(parentNode.className == 'td_extra_field'){
277                 // If this is an extra field
278                 if(parentNode.id){
279                     parentNode.id='';
280                 }
281                 var toreplace = this.field + "_collection_extra_0";
282                 var re = new RegExp(toreplace, 'g');
283                 parentNode.innerHTML = parentNode.innerHTML.replace(re, this.field + "_collection_extra_" + this.fields_count);
284             } else if (currentNode.tagName && currentNode.tagName == 'SPAN') {
285                 //If it is our div element, recursively find all input elements to process
286                 currentNode.id = /_input/.test(currentNode.id) ? this.field_element_name + '_input_div_' + this.fields_count :  this.field_element_name + '_radio_div_' + this.fields_count;
287                                 if (/_input/.test(currentNode.id)) {
288                                         currentNode.name = 'teamset_div';
289                                 }
290
291                 var input_els = currentNode.getElementsByTagName('input');
292                 for ( var x = 0; x < input_els.length; x++ ){
293                         if(input_els[x].tagName && input_els[x].tagName == 'INPUT') {
294                            this.process_node(parentNode, input_els[x], values);
295                         }
296                 }
297             } else if (currentNode.name) {
298                 // If this is a standard field
299                 var toreplace = this.field + "_collection_0";
300                 var re = new RegExp(toreplace, 'g');
301                 var name = currentNode.name;
302                 var new_name = name.replace(re, this.field + "_collection_" + this.fields_count);
303
304                 switch (name) {
305                     case toreplace:
306                         var sqs_id = this.form + '_' + new_name;
307                         if (typeof this.sqs_clone != 'undefined') {
308                                 var sqs_clone = YAHOO.lang.JSON.stringify(this.sqs_clone);
309                             eval('sqs_objects[sqs_id]=' + sqs_clone);
310
311                             for (var pop_field in sqs_objects[sqs_id]['populate_list']) {
312                                 if (typeof sqs_objects[sqs_id]['populate_list'][pop_field] == 'string') {
313                                     sqs_objects[sqs_id]['populate_list'][pop_field] = sqs_objects[sqs_id]['populate_list'][pop_field].replace(RegExp('_0', 'g'), "_" + this.fields_count);
314                                 }
315                             }
316                             for (var req_field in sqs_objects[sqs_id]['required_list']) {
317                                 if (typeof sqs_objects[sqs_id]['required_list'][req_field] == 'string') {
318                                     sqs_objects[sqs_id]['required_list'][req_field] = sqs_objects[sqs_id]['required_list'][req_field].replace(RegExp('_0', 'g'), "_" + this.fields_count);
319                                 }
320                             }
321                         }
322
323                         currentNode.name = new_name;
324                         currentNode.id = new_name;
325                         currentNode.value = values['name'];
326                         break;
327                     case "id_" + toreplace:
328                         currentNode.name = new_name.replace(RegExp('_0', 'g'), "_" + this.fields_count);
329                         currentNode.id = new_name.replace(RegExp('_0', 'g'), "_" + this.fields_count);
330                         currentNode.value = values['id'];
331                         break;
332                     case "btn_" + toreplace:
333                         currentNode.name = new_name;
334                         currentNode.attributes['onclick'].value = currentNode.attributes['onclick'].value.replace(re, this.field + "_collection_" + this.fields_count);
335                         currentNode.attributes['onclick'].value = currentNode.attributes['onclick'].value.replace(RegExp(this.field + "_collection_extra_0", 'g'), this.field + "_collection_extra_" + this.fields_count);
336                         break;
337                     case "allow_new_value_" + toreplace:
338                         currentNode.name = new_name;
339                         currentNode.id = new_name;
340                         break;
341                     case "remove_" + toreplace:
342                         currentNode.name = new_name;
343                         currentNode.id = new_name;
344                         currentNode.setAttribute('collection_id', this.field_element_name);
345                         currentNode.setAttribute('remove_id', this.fields_count);
346                         currentNode.onclick = function() {
347                                collection[this.getAttribute('collection_id')].remove(this.getAttribute('remove_id'));
348                         };
349                         break;
350                     case "primary_" + this.field + "_collection":
351                         currentNode.id = new_name;
352                         currentNode.value = this.fields_count;
353                         currentNode.checked = false; //Firefox
354                         currentNode.setAttribute('defaultChecked', '');
355                         break;
356                     default:
357                         alert(toreplace + '|' + currentNode.name + '|' + name + '|' + new_name);
358                         break;
359                 } //switch
360             } //if-else
361
362         },
363
364         /*
365          * Collapse or expand the rows to show for the editview(depending of the this.more_status attribute).
366          */
367         js_more: function(val){
368             if(this.show_more_image){
369                     var more_ = document.getElementById('more_img_'+this.field_element_name);
370                     var arrow = document.getElementById('arrow_'+this.field);
371                     var radios = this.get_radios();
372                     // if we want to collapse
373                     if(this.more_status == false){
374                         more_.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=advanced_search.gif";
375                         this.more_status = true;
376                         // show the primary only and hidde the other one.
377                         var hidden_count = 0;
378                         for(var k=0; k< radios.length; k++){
379                             if (radios[k].type && radios[k].type == 'radio') {
380                                 if (radios[k].checked) {
381                                     radios[k].parentNode.parentNode.parentNode.style.display = '';
382                                 } else {
383                                     radios[k].parentNode.parentNode.parentNode.style.display = 'none';
384                                     hidden_count++;
385                                 }
386                             }
387                         }
388                         //rrs - add code to not remove the first field if non if the fields are selected as primary
389                         if(hidden_count == radios.length){
390                                 radios[0].parentNode.parentNode.parentNode.style.display = '';
391                         }
392
393                         arrow.value = 'hide';
394                     }else{
395                         more_.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=basic_search.gif";
396                         this.more_status=false;
397                         // display all the records
398                         for(var k=0; k< radios.length; k++){
399                             if(isInteger(k)){
400                                 radios[k].parentNode.parentNode.parentNode.style.display='';
401                             }
402                         }
403
404                         arrow.value = 'show';
405                     }
406
407                     var more_div = document.getElementById('more_div_'+this.field_element_name);
408                     if(more_div) {
409                       more_div.innerHTML = arrow.value == 'show' ? SUGAR.language.get('app_strings','LBL_HIDE') : SUGAR.language.get('app_strings','LBL_SHOW');
410                     }
411
412                 }
413         },
414         /*
415          * Create the clone on load of the page and store it in this.cloneField
416          */
417         create_clone: function() {
418             var oneField = document.getElementById('lineFields_'+this.field_element_name+'_0');
419             this.cloneField[0] = SUGAR.isIE ?
420                 SUGAR.collection.safe_clone(oneField, true) :
421                 oneField.cloneNode(true);
422             this.cloneField[1] = oneField.parentNode;
423             this.more_status = true;
424             var clone_id = this.form + '_' + this.field + '_collection_0';
425
426             if (typeof sqs_objects[clone_id] != 'undefined') {
427                 var clone = YAHOO.lang.JSON.stringify(sqs_objects[clone_id]);
428                 eval('this.sqs_clone=' + clone);
429             }
430         },
431         /**
432          * Validates team set to check if the primary team id has been set or not
433          */
434                 validateTemSet : function(formname, fieldname) {
435                         var table_element_id = formname + '_' + fieldname + '_table';
436                         if(document.getElementById(table_element_id)) {
437                            var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
438                            var has_primary = false;
439                            var primary_field_id = fieldname + '_collection_0';
440                            for(t in input_elements) {
441                                     primary_field_id = fieldname + '_collection_' + input_elements[t].value;
442                                 if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
443                                    if(document.forms[formname].elements[primary_field_id].value != '') {
444                                           has_primary = true;
445                                    }
446                                    break;
447                                 }
448                            }
449                            if(!has_primary) {
450                                         return false;
451                            }
452                            return true;
453                         }
454                         return true;
455                 },
456         /**
457          * return an array of teamids for a team field
458          */
459                 getTeamIdsfromUI: function(formname, fieldname) {
460                         var team_ids = new Array();
461                         var table_element_id = formname + '_' + fieldname + '_table';
462                         if(document.getElementById(table_element_id)) {
463                            input_elements = YAHOO.util.Selector.query('input[type=hidden]', document.getElementById(table_element_id));
464                            for(t = 0; t < input_elements.length; t++) {
465                              if (input_elements[t].id.match("id_" + fieldname + "_collection_") != null) {
466                                 team_ids.push(input_elements[t].value);
467                              } // if
468                            } // for
469                         } // if
470                     return team_ids;
471                 },
472         /**
473          * return a primary team id
474          */
475                 getPrimaryTeamidsFromUI: function(formname, fieldname) {
476                         var table_element_id = formname + '_' + fieldname + '_table';
477                         if(document.getElementById(table_element_id)) {
478                                 var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
479                                 for(t in input_elements) {
480                                         var primary_field_id = 'id_' + document.forms[formname][fieldname].name + '_collection_' + input_elements[t].value;
481                                         if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
482                                            if(document.forms[formname].elements[primary_field_id].value != '') {
483                                                    return document.forms[formname].elements[primary_field_id].value;
484                                            } // if
485                                         } // if
486                                 } // for
487                         } // if
488                         return '';
489                 },
490         /*
491          * Change the primary row onchange of the radio button.
492          */
493         changePrimary: function(noAdd){
494             var old_primary = this.primary_field;
495             var radios=this.get_radios();
496             for (var k = 0; k < radios.length; k++) {
497                 var qs_id = radios[k].id.replace('primary_','');
498                 if (radios[k].checked) {
499                     this.primary_field = qs_id;
500                 } else {
501                         qs_id = qs_id + '_' + k;
502                 }
503
504                 qs_id = this.form + '_' + qs_id;
505
506                 if(typeof sqs_objects[qs_id] != 'undefined' && sqs_objects[qs_id]['primary_field_list']){
507                     for (var ii = 0; ii < sqs_objects[qs_id]['primary_field_list'].length; ii++) {
508                         if (radios[k].checked && qs_id != old_primary) {
509                             sqs_objects[qs_id]['field_list'].push(sqs_objects[qs_id]['primary_field_list'][ii]);
510                             sqs_objects[qs_id]['populate_list'].push(sqs_objects[qs_id]['primary_populate_list'][ii]);
511                         }else if(old_primary == qs_id && !radios[k].checked){
512                             sqs_objects[qs_id]['field_list'].pop();
513                             sqs_objects[qs_id]['populate_list'].pop();
514                         }
515                     }
516                 }
517             }
518
519             if (noAdd) {
520                 enableQS(false);
521             }
522             this.first = false;
523         },
524         /*
525          * Collapse or expand the rows to show for the detailview.
526          */
527         js_more_detail: function(id){
528             var more_img = document.getElementById('more_img_'+id);
529             if(more_img.style.display == 'inline'){
530                 more_img.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=advanced_search.gif";
531             }else{
532                 more_img.src = "index.php?entryPoint=getImage&themeName="+SUGAR.themes.theme_name+"&imageName=basic_search.gif";
533             }
534         },
535         /*
536          * Replace the first field with the specified values
537          */
538         replace_first: function(values){
539                 for (var i = 0; i <= this.fields_count; i++) {
540                         var div_el = document.getElementById(this.field_element_name + '_input_div_' + i);
541                 if(div_el) {
542                                 var name_field = document.getElementById(this.field+"_collection_" + i);
543                                         var id_field = document.getElementById("id_"+this.field+"_collection_" + i);
544                                 name_field.value = values['name'];
545                                 id_field.value = values['id'];
546                                 break;
547                 }
548                 }
549         },
550         /*
551          * Remove all empty fields from the widget.
552          */
553         clean_up: function(){
554             //clean up any rows that have been added but do not contain any data
555             var divsToClean = new Array();
556             var isFirstFieldEmpty = false;
557             var divCount = 0;
558             for (var i = 0; i <= this.fields_count; i++) {
559                 var div_el = document.getElementById(this.field_element_name + '_input_div_' + i);
560                 if(div_el) {
561                         input_els = div_el.getElementsByTagName('input');
562                         for ( var x = 0; x < input_els.length; x++ ){
563                                 if(input_els[x].id && input_els[x].id == (this.field + '_collection_' + i) && trim(input_els[x].value) == '') {
564                                         if(divCount == 0){
565                                                 isFirstFieldEmpty = true;
566                                         } else {
567                                                 divsToClean.push(i);
568                                         }
569                                 }
570
571                         }
572                         divCount++;
573                 }
574             }
575
576             for(var j = 0; j < divsToClean.length; j++){
577                 this.remove(divsToClean[j]);
578             }
579             return isFirstFieldEmpty;
580         },
581
582         show_arrow_label: function(show) {
583             var more_div = document.getElementById('more_div_'+this.field_element_name);
584             if(more_div) {
585                more_div.style.display = show ? '' : 'none';
586             }
587         },
588
589         /**
590          * is_expanded
591          * helper function to determine whether or not the widget is expanded (all teams are shown)
592          */
593         is_expanded: function() {
594             var more_div = document.getElementById('more_div_'+this.field_element_name);
595             if(more_div) {
596                return more_div.style.display == '';
597             }
598             return false;
599         }
600     }
601
602         SUGAR.collection.safe_clone = function(e, recursive)
603         {
604                 if (e.nodeName == "#text")
605                 {
606                         return document.createTextNode(e.data);
607                 }
608                 if(!e.tagName) return false;
609
610                 var newNode = document.createElement(e.tagName);
611                 if (!newNode) return false;
612
613                 var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'height', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
614
615         //clee. - Bug: 44976 - IE7 just does not calculate height properties correctly for input elements
616                 if(SUGAR.isIE7 && e.tagName.toLowerCase() == 'input')
617                 {
618                         var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
619                 } else {
620                         var properties = ['class', 'style', 'name', 'type', 'valign', 'border', 'width', 'height', 'top', 'bottom', 'left', 'right', 'scope', 'row', 'columns', 'src', 'href', 'className', 'align', 'nowrap'];
621                 }
622                 
623                 for (var i in properties)
624                 {
625                         if (e[properties[i]])
626                         {
627                                 if ((properties[i] != 'style' || !SUGAR.isIE) &&
628                                         //Only <a> and <iframe> tags can have hrefs
629                                         (properties[i] != 'href'  || e.tagName == 'a' || e.tagName == 'iframe'))
630                                         newNode[properties[i]] = e[properties[i]];
631                         }
632                 }
633                 if(recursive)
634                 {
635                         for (var i in e.childNodes)
636                         {
637                                 if(e.childNodes[i].nodeName && (!e.className || e.className != "yui-ac-container"))
638                                 {
639                                         var child = SUGAR.collection.safe_clone(e.childNodes[i], true);
640                                         if (child) newNode.appendChild(child);
641                                 }
642                         }
643                 }
644                 return newNode;
645         }
646 }