Merge pull request #2839 from Hypolite/Issue-#2822
[friendica.git/.git] / view / theme / frost-mobile / js / theme.js
1 $(document).ready(function() {
2
3         /* enable tinymce on focus and click */
4         $("#profile-jot-text").focus(enableOnUser);
5         $("#profile-jot-text").click(enableOnUser);
6
7 /*$('html').click(function() { $("#nav-notifications-menu" ).hide(); });*/
8
9         /*$('.group-edit-icon').hover(
10                 function() {
11                         $(this).addClass('icon'); $(this).removeClass('iconspacer');},
12                 function() {
13                         $(this).removeClass('icon'); $(this).addClass('iconspacer');}
14         );
15
16         $('.sidebar-group-element').hover(
17                 function() {
18                         id = $(this).attr('id');
19                         $('#edit-' + id).addClass('icon'); $('#edit-' + id).removeClass('iconspacer');},
20
21                 function() {
22                         id = $(this).attr('id');
23                         $('#edit-' + id).removeClass('icon');$('#edit-' + id).addClass('iconspacer');}
24         );
25
26
27         $('.savedsearchdrop').hover(
28                 function() {
29                         $(this).addClass('drop'); $(this).addClass('icon'); $(this).removeClass('iconspacer');},
30                 function() {
31                         $(this).removeClass('drop'); $(this).removeClass('icon'); $(this).addClass('iconspacer');}
32         );
33
34         $('.savedsearchterm').hover(
35                 function() {
36                         id = $(this).attr('id');
37                         $('#drop-' + id).addClass('icon');      $('#drop-' + id).addClass('drophide'); $('#drop-' + id).removeClass('iconspacer');},
38
39                 function() {
40                         id = $(this).attr('id');
41                         $('#drop-' + id).removeClass('icon');$('#drop-' + id).removeClass('drophide'); $('#drop-' + id).addClass('iconspacer');}
42         );*/
43
44
45         $('#event-share-checkbox').change(function() {
46
47                 if ($('#event-share-checkbox').is(':checked')) { 
48                         $('#acl-wrapper').show();
49                 }
50                 else {
51                         $('#acl-wrapper').hide();
52                 }
53         }).trigger('change');
54
55
56         $(".popupbox").click(function () {
57                 var parent = $( $(this).attr('href') ).parent();
58                 if (parent.css('display') == 'none') {
59                         parent.show();
60                 } else {
61                         parent.hide();
62                 }
63                 return false;
64         });
65
66
67
68         if(typeof window.AjaxUpload != "undefined") {
69                 var uploader = new window.AjaxUpload(
70                         window.imageUploadButton,
71                         { action: 'wall_upload/'+window.nickname+'?nomce=1',
72                                 name: 'userfile',
73                                 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
74                                 onComplete: function(file,response) {
75                                         addeditortext(window.jotId, response);
76                                         $('#profile-rotator').hide();
77                                 }                                
78                         }
79                 );
80
81                 if($('#wall-file-upload').length) {
82                         var file_uploader = new window.AjaxUpload(
83                                 'wall-file-upload',
84                                 { action: 'wall_attach/'+window.nickname+'?nomce=1',
85                                         name: 'userfile',
86                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },
87                                         onComplete: function(file,response) {
88                                                 addeditortext(window.jotId, response);
89                                                 $('#profile-rotator').hide();
90                                         }                                
91                                 }
92                         );
93                 }
94         }
95
96
97         if(typeof window.aclInit !="undefined" && typeof acl=="undefined"){
98                 acl = new ACL(
99                         baseurl+"/acl",
100                         [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
101                 );
102         }
103
104         switch(window.autocompleteType) {
105                 case 'msg-header':
106                         $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
107                                         $("#recip-complete").val(data.id);
108                         });
109                         break;
110                 case 'contacts-head':
111                         $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
112
113
114                         $("#contacts-search").keyup(function(event){
115                                 if(event.keyCode == 13){
116                                         $("#contacts-search").click();
117                                 }
118                         });
119                         $(".autocomplete-w1 .selected").keyup(function(event){
120                                 if(event.keyCode == 13){
121                                         $("#contacts-search").click();
122                                 }
123                         });
124                         break;
125                 case 'display-head':
126                         $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
127                         break;
128                 default:
129                         break;
130         }
131
132
133 /*      if(window.autoCompleteType == "display-head") {
134                 //$(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
135                 // make auto-complete work in more places
136                 //$(".wall-item-comment-wrapper textarea").contact_autocomplete(baseurl+"/acl");
137                 $(".comment-wwedit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
138         }*/
139
140
141         if(window.aclType == "settings-head" || window.aclType == "photos_head" || window.aclType == "event_head") {
142                 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
143                         var selstr;
144                         $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
145                                 selstr = $(this).text();
146                                 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
147                                 $('#jot-public').hide();
148                         });
149                         if(selstr == null) { 
150                                 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
151                                 $('#jot-public').show();
152                         }
153
154                 }).trigger('change');
155         }
156
157         if(window.aclType == "event_head") {
158                 $('#events-calendar').fullCalendar({
159                         events: baseurl + window.eventModuleUrl +'/json/',
160                         header: {
161                                 left: 'prev,next today',
162                                 center: 'title',
163                                 right: 'month,agendaWeek,agendaDay'
164                         },                      
165                         timeFormat: 'H(:mm)',
166                         eventClick: function(calEvent, jsEvent, view) {
167                                 showEvent(calEvent.id);
168                         },
169                         
170                         eventRender: function(event, element, view) {
171                                 //console.log(view.name);
172                                 if (event.item['author-name']==null) return;
173                                 switch(view.name){
174                                         case "month":
175                                         element.find(".fc-title").html(
176                                                 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
177                                                         event.item['author-avatar'],
178                                                         event.item['author-name'],
179                                                         event.title
180                                         ));
181                                         break;
182                                         case "agendaWeek":
183                                         element.find(".fc-title").html(
184                                                 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
185                                                         event.item['author-avatar'],
186                                                         event.item['author-name'],
187                                                         event.item.desc,
188                                                         event.item.location
189                                         ));
190                                         break;
191                                         case "agendaDay":
192                                         element.find(".fc-title").html(
193                                                 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
194                                                         event.item['author-avatar'],
195                                                         event.item['author-name'],
196                                                         event.item.desc,
197                                                         event.item.location
198                                         ));
199                                         break;
200                                 }
201                         }
202                         
203                 });
204                 
205                 // center on date
206                 var args=location.href.replace(baseurl,"").split("/");
207                 if (args.length>=5 && window.eventModeParams == 2) {
208                         $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
209                 } else if (args.length>=4 && window.eventModeParams == 1) {
210                         $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
211                 }
212                 
213                 // show event popup
214                 var hash = location.hash.split("-")
215                 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
216         }       
217
218 });
219
220 // update pending count //
221 $(function(){
222
223         $("nav").bind('nav-update',  function(e,data){
224                 var elm = $('#pending-update');
225                 var register = $(data).find('register').text();
226                 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
227                 elm.html(register);
228         });
229 });
230
231
232
233 function homeRedirect() {
234         $('html').fadeOut('slow', function(){
235                 window.location = baseurl + "/login";
236         });
237 }
238
239
240 function initCrop() {
241         function onEndCrop( coords, dimensions ) {
242                 $PR( 'x1' ).value = coords.x1;
243                 $PR( 'y1' ).value = coords.y1;
244                 $PR( 'x2' ).value = coords.x2;
245                 $PR( 'y2' ).value = coords.y2;
246                 $PR( 'width' ).value = dimensions.width;
247                 $PR( 'height' ).value = dimensions.height;
248         }
249
250         Event.observe( window, 'load', function() {
251                 new Cropper.ImgWithPreview(
252                 'croppa',
253                 {
254                         previewWrap: 'previewWrap',
255                         minWidth: 175,
256                         minHeight: 175,
257                         maxWidth: 640,
258                         maxHeight: 640,
259                         ratioDim: { x: 100, y:100 },
260                         displayOnInit: true,
261                         onEndCrop: onEndCrop
262                 });
263         });
264 }
265
266
267 function showEvent(eventid) {
268 /*      $.get(
269                 baseurl + window.eventModuleUrl + '/?id=' + eventid,
270                 function(data){
271                         $.colorbox({html:data});
272                 }
273         );*/                    
274 }
275
276
277
278 /*
279  * TinyMCE/Editor
280  */
281
282 var editor=false;
283 var textlen = 0;
284 var plaintext = 'none';//window.editSelect;
285 //var ispublic = window.isPublic;
286
287 function initEditor(cb){
288         if (editor==false){
289 //              $("#profile-jot-text-loading").show();
290                 if(plaintext == 'none') {
291 //                      $("#profile-jot-text-loading").hide();
292                         $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
293                         $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
294                         editor = true;
295 /*                      $("a#jot-perms-icon").colorbox({
296                                 'inline' : true,
297                                 'transition' : 'elastic'
298                         });*/
299                         $("a#jot-perms-icon, a#settings-default-perms-menu").click(function () {
300                                 var parent = $("#profile-jot-acl-wrapper").parent();
301                                 if (parent.css('display') == 'none') {
302                                         parent.show();
303                                 } else {
304                                         parent.hide();
305                                 }
306 //                              $("#profile-jot-acl-wrapper").parent().toggle();
307                                 return false;
308                         });
309                         $(".jothidden").show();
310                         if (typeof cb!="undefined") cb();
311                         return;
312                 }       
313 /*              tinyMCE.init({
314                         theme : "advanced",
315                         mode : "specific_textareas",
316                         editor_selector: window.editSelect,
317                         auto_focus: "profile-jot-text",
318                         plugins : "bbcode,paste,autoresize, inlinepopups",
319                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
320                         theme_advanced_buttons2 : "",
321                         theme_advanced_buttons3 : "",
322                         theme_advanced_toolbar_location : "top",
323                         theme_advanced_toolbar_align : "center",
324                         theme_advanced_blockformats : "blockquote,code",
325                         gecko_spellcheck : true,
326                         paste_text_sticky : true,
327                         entity_encoding : "raw",
328                         add_unload_trigger : false,
329                         remove_linebreaks : false,
330                         //force_p_newlines : false,
331                         //force_br_newlines : true,
332                         forced_root_block : 'div',
333                         convert_urls: false,
334                         content_css: "$baseurl/view/custom_tinymce.css",
335                         theme_advanced_path : false,
336                         file_browser_callback : "fcFileBrowser",
337                         setup : function(ed) {
338                                 cPopup = null;
339                                 ed.onKeyDown.add(function(ed,e) {
340                                         if(cPopup !== null)
341                                                 cPopup.onkey(e);
342                                 });
343
344                                 ed.onKeyUp.add(function(ed, e) {
345                                         var txt = tinyMCE.activeEditor.getContent();
346                                         match = txt.match(/@([^ \n]+)$/);
347                                         if(match!==null) {
348                                                 if(cPopup === null) {
349                                                         cPopup = new ACPopup(this,baseurl+"/acl");
350                                                 }
351                                                 if(cPopup.ready && match[1]!==cPopup.searchText) cPopup.search(match[1]);
352                                                 if(! cPopup.ready) cPopup = null;
353                                         }
354                                         else {
355                                                 if(cPopup !== null) { cPopup.close(); cPopup = null; }
356                                         }
357
358                                         textlen = txt.length;
359                                         if(textlen != 0 && $('#jot-perms-icon').is('.unlock')) {
360                                                 $('#profile-jot-desc').html(ispublic);
361                                         }
362                                         else {
363                                                 $('#profile-jot-desc').html('&nbsp;');
364                                         }        
365
366                                  //Character count
367
368                                         if(textlen <= 140) {
369                                                 $('#character-counter').removeClass('red');
370                                                 $('#character-counter').removeClass('orange');
371                                                 $('#character-counter').addClass('grey');
372                                         }
373                                         if((textlen > 140) && (textlen <= 420)) {
374                                                 $('#character-counter').removeClass('grey');
375                                                 $('#character-counter').removeClass('red');
376                                                 $('#character-counter').addClass('orange');
377                                         }
378                                         if(textlen > 420) {
379                                                 $('#character-counter').removeClass('grey');
380                                                 $('#character-counter').removeClass('orange');
381                                                 $('#character-counter').addClass('red');
382                                         }
383                                         $('#character-counter').text(textlen);
384                                 });
385
386                                 ed.onInit.add(function(ed) {
387                                         ed.pasteAsPlainText = true;
388                                         $("#profile-jot-text-loading").hide();
389                                         $(".jothidden").show();
390                                         if (typeof cb!="undefined") cb();
391                                 });
392
393                         }
394                 });
395                 editor = true;
396                 // setup acl popup
397                 $("a#jot-perms-icon").colorbox({
398                         'inline' : true,
399                         'transition' : 'elastic'
400                 }); */
401         } else {
402                 if (typeof cb!="undefined") cb();
403         }
404 }
405
406 function enableOnUser(){
407         if (editor) return;
408         $(this).val("");
409         initEditor();
410 }
411
412 /*function wallInitEditor() {
413         var plaintext = window.editSelect;
414
415         if(plaintext != 'none') {
416                 tinyMCE.init({
417                         theme : "advanced",
418                         mode : "specific_textareas",
419                         editor_selector: /(profile-jot-text|prvmail-text)/,
420                         plugins : "bbcode,paste",
421                         theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor",
422                         theme_advanced_buttons2 : "",
423                         theme_advanced_buttons3 : "",
424                         theme_advanced_toolbar_location : "top",
425                         theme_advanced_toolbar_align : "center",
426                         theme_advanced_blockformats : "blockquote,code",
427                         gecko_spellcheck : true,
428                         paste_text_sticky : true,
429                         entity_encoding : "raw",
430                         add_unload_trigger : false,
431                         remove_linebreaks : false,
432                         //force_p_newlines : false,
433                         //force_br_newlines : true,
434                         forced_root_block : 'div',
435                         convert_urls: false,
436                         content_css: baseurl + "/view/custom_tinymce.css",
437                                  //Character count
438                         theme_advanced_path : false,
439                         setup : function(ed) {
440                                 ed.onInit.add(function(ed) {
441                                         ed.pasteAsPlainText = true;
442                                         var editorId = ed.editorId;
443                                         var textarea = $('#'+editorId);
444                                         if (typeof(textarea.attr('tabindex')) != "undefined") {
445                                                 $('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
446                                                 textarea.attr('tabindex', null);
447                                         }
448                                 });
449                         }
450                 });
451         }
452         else
453                 $("#prvmail-text").contact_autocomplete(baseurl+"/acl");
454 }*/
455
456
457
458 /*
459  * Jot
460  */
461
462 function addeditortext(textElem, data) {
463         if(window.editSelect == 'none') {
464                 var currentText = $(textElem).val();
465                 $(textElem).val(currentText + data);
466         }
467 /*      else
468                 tinyMCE.execCommand('mceInsertRawHTML',false,data);*/
469 }
470
471 function jotVideoURL() {
472         reply = prompt(window.vidURL);
473         if(reply && reply.length) {
474                 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
475         }
476 }
477
478 function jotAudioURL() {
479         reply = prompt(window.audURL);
480         if(reply && reply.length) {
481                 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
482         }
483 }
484
485
486 function jotGetLocation() {
487         reply = prompt(window.whereAreU, $('#jot-location').val());
488         if(reply && reply.length) {
489                 $('#jot-location').val(reply);
490         }
491 }
492
493 function jotShare(id) {
494         if ($('#jot-popup').length != 0) $('#jot-popup').show();
495
496         $('#like-rotator-' + id).show();
497         $.get('share/' + id, function(data) {
498                 if (!editor) $("#profile-jot-text").val("");
499                 initEditor(function(){
500                         addeditortext("#profile-jot-text", data);
501                         $('#like-rotator-' + id).hide();
502                         $(window).scrollTop(0);
503                 });
504
505         });
506 }
507
508 function jotGetLink() {
509         reply = prompt(window.linkURL);
510         if(reply && reply.length) {
511                 reply = bin2hex(reply);
512                 $('#profile-rotator').show();
513                 $.get('parse_url?binurl=' + reply, function(data) {
514                         addeditortext(window.jotId, data);
515                         $('#profile-rotator').hide();
516                 });
517         }
518 }
519
520 /*function linkdropper(event) {
521         var linkFound = event.dataTransfer.types.contains("text/uri-list");
522         if(linkFound)
523                 event.preventDefault();
524 }
525
526 function linkdrop(event) {
527         var reply = event.dataTransfer.getData("text/uri-list");
528         event.target.textContent = reply;
529         event.preventDefault();
530         if(reply && reply.length) {
531                 reply = bin2hex(reply);
532                 $('#profile-rotator').show();
533                 $.get('parse_url?binurl=' + reply, function(data) {
534                         //if (!editor) $("#profile-jot-text").val("");
535                         //initEditor(function(){
536                         addeditortext(window.jotId, data);
537                         $('#profile-rotator').hide();
538                         //});
539                 });
540         }
541 }*/
542
543 function jotClearLocation() {
544         $('#jot-coord').val('');
545         $('#profile-nolocation-wrapper').hide();
546 }
547
548 if(typeof window.geoTag === 'function') window.geoTag();
549
550
551
552 /*
553  * Items
554  */
555
556 function confirmDelete() { return confirm(window.delItem); }
557
558 /*function deleteCheckedItems() {
559         var checkedstr = '';
560
561         $('.item-select').each( function() {
562                 if($(this).is(':checked')) {
563                         if(checkedstr.length != 0) {
564                                 checkedstr = checkedstr + ',' + $(this).val();
565                         }
566                         else {
567                                 checkedstr = $(this).val();
568                         }
569                 }       
570         });
571         $.post('item', { dropitems: checkedstr }, function(data) {
572                 window.location.reload();
573         });
574 }*/
575
576 function itemTag(id) {
577         reply = prompt(window.term);
578         if(reply && reply.length) {
579                 reply = reply.replace('#','');
580                 if(reply.length) {
581
582                         commentBusy = true;
583                         $('body').css('cursor', 'wait');
584
585                         $.get('tagger/' + id + '?term=' + reply, NavUpdate);
586                         /*if(timer) clearTimeout(timer);
587                         timer = setTimeout(NavUpdate,3000);*/
588                         liking = 1;
589                 }
590         }
591 }
592
593 function itemFiler(id) {
594         
595         $.get('filer/', function(data){
596
597                 var promptText = $('#id_term_label', data).text();
598
599                 reply = prompt(promptText);
600                 if(reply && reply.length) {
601                         commentBusy = true;
602                         $('body').css('cursor', 'wait');
603                         $.get('filer/' + id + '?term=' + reply, NavUpdate);
604 /*                              if(timer) clearTimeout(timer);
605                         timer = setTimeout(NavUpdate,3000);*/
606                         liking = 1;
607 /*                              $.colorbox.close();*/
608                 }
609         });
610
611 /*              var bordercolor = $("input").css("border-color");
612         
613         $.get('filer/', function(data){
614                 $.colorbox({html:data});
615                 $("#id_term").keypress(function(){
616                         $(this).css("border-color",bordercolor);
617                 })
618                 $("#select_term").change(function(){
619                         $("#id_term").css("border-color",bordercolor);
620                 })
621                 
622                 $("#filer_save").click(function(e){
623                         e.preventDefault();
624                         reply = $("#id_term").val();
625                         if(reply && reply.length) {
626                                 commentBusy = true;
627                                 $('body').css('cursor', 'wait');
628                                 $.get('filer/' + id + '?term=' + reply);
629                                 if(timer) clearTimeout(timer);
630                                 timer = setTimeout(NavUpdate,3000);
631                                 liking = 1;
632                                 $.colorbox.close();
633                         } else {
634                                 $("#id_term").css("border-color","#FF0000");
635                         }
636                         return false;
637                 });
638         });
639 */              
640 }
641
642
643
644 /*
645  * Comments
646  */
647
648
649 function commentOpen(obj,id) {
650         if(obj.value == window.commentEmptyText) {
651                 obj.value = "";
652                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
653                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
654                 $("#mod-cmnt-wrap-" + id).show();
655                 openMenu("comment-edit-submit-wrapper-" + id);
656         }
657 }
658 function commentClose(obj,id) {
659         if(obj.value == "") {
660                 obj.value = window.commentEmptyText;
661                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
662                 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
663                 $("#mod-cmnt-wrap-" + id).hide();
664                 closeMenu("comment-edit-submit-wrapper-" + id);
665         }
666 }
667
668
669 function commentInsert(obj,id) {
670         var tmpStr = $("#comment-edit-text-" + id).val();
671         if(tmpStr == window.commentEmptyText) {
672                 tmpStr = "";
673                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
674                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
675                 openMenu("comment-edit-submit-wrapper-" + id);
676         }
677         var ins = $(obj).html();
678         ins = ins.replace("&lt;","<");
679         ins = ins.replace("&gt;",">");
680         ins = ins.replace("&amp;","&");
681         ins = ins.replace("&quot;",'"');
682         $("#comment-edit-text-" + id).val(tmpStr + ins);
683 }
684
685 function qCommentInsert(obj,id) {
686         var tmpStr = $("#comment-edit-text-" + id).val();
687         if(tmpStr == window.commentEmptyText) {
688                 tmpStr = "";
689                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
690                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
691                 openMenu("comment-edit-submit-wrapper-" + id);
692         }
693         var ins = $(obj).val();
694         ins = ins.replace("&lt;","<");
695         ins = ins.replace("&gt;",">");
696         ins = ins.replace("&amp;","&");
697         ins = ins.replace("&quot;",'"');
698         $("#comment-edit-text-" + id).val(tmpStr + ins);
699         $(obj).val("");
700 }
701
702 /*function showHideCommentBox(id) {
703         if( $('#comment-edit-form-' + id).is(':visible')) {
704                 $('#comment-edit-form-' + id).hide();
705         }
706         else {
707                 $('#comment-edit-form-' + id).show();
708         }
709 }*/
710
711
712 function insertFormatting(comment,BBcode,id) {
713         
714         var tmpStr = $("#comment-edit-text-" + id).val();
715         if(tmpStr == comment) {
716                 tmpStr = "";
717                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
718                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
719                 openMenu("comment-edit-submit-wrapper-" + id);
720                 $("#comment-edit-text-" + id).val(tmpStr);
721         }
722
723         textarea = document.getElementById("comment-edit-text-" +id);
724         if (document.selection) {
725                 textarea.focus();
726                 selected = document.selection.createRange();
727                 if (BBcode == "url"){
728                         selected.text = "["+BBcode+"=http://]" +  selected.text + "[/"+BBcode+"]";
729                         } else                  
730                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
731         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
732                 var start = textarea.selectionStart;
733                 var end = textarea.selectionEnd;
734                 if (BBcode == "url"){
735                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
736                         } else
737                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
738         }
739         return true;
740 }
741
742 function cmtBbOpen(id) {
743         $(".comment-edit-bb-" + id).show();
744 }
745 function cmtBbClose(id) {
746         $(".comment-edit-bb-" + id).hide();
747 }
748
749