Merge pull request #3109 from Hypolite/issue/scrap-tinymce
[friendica.git/.git] / view / theme / frost / js / theme.js
1 $(document).ready(function() {
2
3         window.navMenuTimeout = {
4                 '#network-menu-list-timeout': null,
5                 '#contacts-menu-list-timeout': null,
6                 '#system-menu-list-timeout': null,
7                 '#network-menu-list-opening': false,
8                 '#contacts-menu-list-opening': false,
9                 '#system-menu-list-opening': false,
10                 '#network-menu-list-closing': false,
11                 '#contacts-menu-list-closing': false,
12                 '#system-menu-list-closing': false
13         };
14
15 /*    $.ajaxSetup({
16         cache: false
17     });*/
18
19
20         /* enable editor on focus and click */
21         $("#profile-jot-text").focus(enableOnUser);
22         $("#profile-jot-text").click(enableOnUser);
23
24         $('.nav-menu-list, .nav-menu-icon').hover(function() {
25                 showNavMenu($(this).attr('point'));
26         }, function() {
27                 hideNavMenu($(this).attr('point'));
28         });
29
30 /*      $('html').click(function() { $("#nav-notifications-menu" ).hide(); });*/
31
32         $('.group-edit-icon').hover(
33                 function() {
34                         $(this).addClass('icon'); $(this).removeClass('iconspacer');},
35                 function() {
36                         $(this).removeClass('icon'); $(this).addClass('iconspacer');}
37                 );
38
39         $('.sidebar-group-element').hover(
40                 function() {
41                         id = $(this).attr('id');
42                         $('#edit-' + id).addClass('icon'); $('#edit-' + id).removeClass('iconspacer');},
43
44                 function() {
45                         id = $(this).attr('id');
46                         $('#edit-' + id).removeClass('icon');$('#edit-' + id).addClass('iconspacer');}
47                 );
48
49
50         $('.savedsearchdrop').hover(
51                 function() {
52                         $(this).addClass('drop'); $(this).addClass('icon'); $(this).removeClass('iconspacer');},
53                 function() {
54                         $(this).removeClass('drop'); $(this).removeClass('icon'); $(this).addClass('iconspacer');}
55         );
56
57         $('.savedsearchterm').hover(
58                 function() {
59                         id = $(this).attr('id');
60                         $('#drop-' + id).addClass('icon');      $('#drop-' + id).addClass('drophide'); $('#drop-' + id).removeClass('iconspacer');},
61
62                 function() {
63                         id = $(this).attr('id');
64                         $('#drop-' + id).removeClass('icon');$('#drop-' + id).removeClass('drophide'); $('#drop-' + id).addClass('iconspacer');}
65         );
66
67 /*      $('.nav-load-page-link').click(function() {
68                 getPageContent( $(this).attr('href') );
69                 hideNavMenu( '#' + $(this).closest('ul').attr('id') );
70                 return false;
71         });*/
72
73         $('#id_share').change(function() {
74
75                 if ($('#id_share').is(':checked')) {
76                         $('#acl-wrapper').show();
77                 }
78                 else {
79                         $('#acl-wrapper').hide();
80                 }
81         }).trigger('change');
82
83 // For event_end.tpl
84 /*              $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
85                         var selstr;
86                         $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
87                                 selstr = $(this).text();
88                                 $('#jot-public').hide();
89                         });
90                         if(selstr == null) {
91                                 $('#jot-public').show();
92                         }
93
94                 }).trigger('change');*/
95
96
97         if(typeof window.AjaxUpload != "undefined") {
98                 var uploader = new window.AjaxUpload(
99                         window.imageUploadButton,
100                         { action: 'wall_upload/'+window.nickname,
101                                 name: 'userfile',
102                                 onSubmit: function(file,ext) { $('#profile-rotator').show(); },
103                                 onComplete: function(file,response) {
104                                         addeditortext(window.jotId, response);
105                                         $('#profile-rotator').hide();
106                                 }
107                         }
108                 );
109
110                 if($('#wall-file-upload').length) {
111                         var file_uploader = new window.AjaxUpload(
112                                 'wall-file-upload',
113                                 { action: 'wall_attach/'+window.nickname,
114                                         name: 'userfile',
115                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },
116                                         onComplete: function(file,response) {
117                                                 addeditortext(window.jotId, response);
118                                                 $('#profile-rotator').hide();
119                                         }
120                                 }
121                         );
122                 }
123         }
124
125
126         if(typeof window.aclInit !="undefined" && typeof acl=="undefined"){
127                 acl = new ACL(
128                         baseurl+"/acl",
129                         [ window.allowCID,window.allowGID,window.denyCID,window.denyGID ]
130                 );
131         }
132
133
134         if(window.aclType == "settings-head" || window.aclType == "photos_head" || window.aclType == "event_head") {
135                 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
136                         var selstr;
137                         $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
138                                 selstr = $(this).text();
139                                 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
140                                 $('#jot-public').hide();
141                         });
142                         if(selstr == null) {
143                                 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
144                                 $('#jot-public').show();
145                         }
146
147                 }).trigger('change');
148         }
149
150         if(window.aclType == "event_head") {
151                 $('#events-calendar').fullCalendar({
152                         events: baseurl + window.eventModuleUrl +'/json/',
153                         header: {
154                                 left: 'prev,next today',
155                                 center: 'title',
156                                 right: 'month,agendaWeek,agendaDay'
157                         },
158                         timeFormat: 'H(:mm)',
159                         eventClick: function(calEvent, jsEvent, view) {
160                                 showEvent(calEvent.id);
161                         },
162                         loading: function(isLoading, view) {
163                                 if(!isLoading) {
164                                         $('td.fc-day').dblclick(function() { window.location.href='/events/new?start='+$(this).data('date'); });
165                                 }
166                         },
167
168                         eventRender: function(event, element, view) {
169                                 //console.log(view.name);
170                                 if (event.item['author-name']==null) return;
171                                 switch(view.name){
172                                         case "month":
173                                         element.find(".fc-title").html(
174                                                 "<img src='{0}' style='height:10px;width:10px'>{1} : {2}".format(
175                                                         event.item['author-avatar'],
176                                                         event.item['author-name'],
177                                                         event.title
178                                         ));
179                                         break;
180                                         case "agendaWeek":
181                                         element.find(".fc-title").html(
182                                                 "<img src='{0}' style='height:12px; width:12px'>{1}<p>{2}</p><p>{3}</p>".format(
183                                                         event.item['author-avatar'],
184                                                         event.item['author-name'],
185                                                         event.item.desc,
186                                                         event.item.location
187                                         ));
188                                         break;
189                                         case "agendaDay":
190                                         element.find(".fc-title").html(
191                                                 "<img src='{0}' style='height:24px;width:24px'>{1}<p>{2}</p><p>{3}</p>".format(
192                                                         event.item['author-avatar'],
193                                                         event.item['author-name'],
194                                                         event.item.desc,
195                                                         event.item.location
196                                         ));
197                                         break;
198                                 }
199                         }
200
201                 });
202
203                 // center on date
204                 var args=location.href.replace(baseurl,"").split("/");
205                 if (args.length>=5 && window.eventModeParams == 2) {
206                         $("#events-calendar").fullCalendar('gotoDate',args[3] , args[4]-1);
207                 } else if (args.length>=4 && window.eventModeParams == 1) {
208                         $("#events-calendar").fullCalendar('gotoDate',args[2] , args[3]-1);
209                 }
210
211                 // show event popup
212                 var hash = location.hash.split("-")
213                 if (hash.length==2 && hash[0]=="#link") showEvent(hash[1]);
214         }
215
216
217         switch(window.autocompleteType) {
218                 case 'msg-header':
219                         $("#recip").name_autocomplete(baseurl + '/acl', '', false, function(data) {
220                                         $("#recip-complete").val(data.id);
221                         });
222                         break;
223                 case 'contacts-head':
224                         $("#contacts-search").contact_autocomplete(baseurl + '/acl', 'a', true);
225
226
227                         $("#contacts-search").keyup(function(event){
228                                 if(event.keyCode == 13){
229                                         $("#contacts-search").click();
230                                 }
231                         });
232                         $(".autocomplete-w1 .selected").keyup(function(event){
233                                 if(event.keyCode == 13){
234                                         $("#contacts-search").click();
235                                 }
236                         });
237                         break;
238                 case 'display-head':
239                         $(".comment-wwedit-wrapper textarea").editor_autocomplete(baseurl+"/acl");
240                         break;
241                 default:
242                         break;
243         }
244
245 /*      if(window.autoCompleteType == "display-head") {
246                 //$(".comment-edit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
247                 // make auto-complete work in more places
248                 //$(".wall-item-comment-wrapper textarea").contact_autocomplete(baseurl+"/acl");
249                 $(".comment-wwedit-wrapper textarea").contact_autocomplete(baseurl+"/acl");
250         }*/
251
252         // Add Colorbox for viewing Network page images
253         //var cBoxClasses = new Array();
254         $(".wall-item-body a img").each(function(){
255                 var aElem = $(this).parent();
256                 var imgHref = aElem.attr("href");
257
258                 // We need to make sure we only put a Colorbox on links to Friendica images
259                 // We'll try to do this by looking for links of the form
260                 // .../photo/ab803d8eg08daf85023adfec08 (with nothing more following), in hopes
261                 // that that will be unique enough
262                 if(imgHref.match(/\/photo\/[a-fA-F0-9]+(-[0-9]\.[\w]+?)?$/)) {
263
264                         // Add a unique class to all the images of a certain post, to allow scrolling through
265                         var cBoxClass = $(this).closest(".wall-item-body").attr("id") + "-lightbox";
266                         $(this).addClass(cBoxClass);
267
268 //                      if( $.inArray(cBoxClass, cBoxClasses) < 0 ) {
269 //                              cBoxClasses.push(cBoxClass);
270 //                      }
271
272                         aElem.colorbox({
273                                 maxHeight: '90%',
274                                 photo: true, // Colorbox doesn't recognize a URL that don't end in .jpg, etc. as a photo
275                                 rel: cBoxClass //$(this).attr("class").match(/wall-item-body-[\d]+-lightbox/)[0]
276                         });
277                 }
278         });
279         /*$.each(cBoxClasses, function(){
280                 $('.'+this).colorbox({
281                         maxHeight: '90%',
282                         photo: true,
283                         rel: this
284                 });
285         });*/
286
287 });
288
289
290 // update pending count //
291 $(function(){
292
293         $("nav").bind('nav-update',  function(e,data){
294                 var elm = $('#pending-update');
295                 var register = $(data).find('register').text();
296                 if (register=="0") { register=""; elm.hide();} else { elm.show(); }
297                 elm.html(register);
298         });
299 });
300
301
302 $(function(){
303
304         $("#cnftheme").click(function(){
305                 $.colorbox({
306                         width: 800,
307                         height: '90%',
308                         href: baseurl + "/admin/themes/" + $("#id_theme :selected").val(),
309                         onComplete: function(){
310                                 $("div#fancybox-content form").submit(function(e){
311                                         var url = $(this).attr('action');
312                                         // can't get .serialize() to work...
313                                         var data={};
314                                         $(this).find("input").each(function(){
315                                                 data[$(this).attr('name')] = $(this).val();
316                                         });
317                                         $(this).find("select").each(function(){
318                                                 data[$(this).attr('name')] = $(this).children(":selected").val();
319                                         });
320                                         console.log(":)", url, data);
321
322                                         $.post(url, data, function(data) {
323                                                 if(timer) clearTimeout(timer);
324                                                 NavUpdate();
325                                                 $.colorbox.close();
326                                         })
327
328                                         return false;
329                                 });
330
331                         }
332                 });
333                 return false;
334         });
335 });
336
337
338 function homeRedirect() {
339         $('html').fadeOut('slow', function(){
340                 window.location = baseurl + "/login";
341         });
342 }
343
344
345 if(typeof window.photoEdit != 'undefined') {
346
347         $(document).keydown(function(event) {
348
349                         if(window.prevLink != '') { if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = window.prevLink; }}
350                         if(window.nextLink != '') { if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = window.nextLink; }}
351
352         });
353 }
354
355 function showEvent(eventid) {
356         $.get(
357                 baseurl + window.eventModuleUrl + '/?id=' + eventid,
358                 function(data){
359                         $.colorbox({html:data});
360                         $.colorbox.resize();
361                 }
362         );
363 }
364
365 function doEventPreview() {
366         $('#event-edit-preview').val(1);
367         $.post('events',$('#event-edit-form').serialize(), function(data) {
368                 $.colorbox({ html: data });
369         });
370         $('#event-edit-preview').val(0);
371 }
372
373 function initCrop() {
374         function onEndCrop( coords, dimensions ) {
375                 $PR( 'x1' ).value = coords.x1;
376                 $PR( 'y1' ).value = coords.y1;
377                 $PR( 'x2' ).value = coords.x2;
378                 $PR( 'y2' ).value = coords.y2;
379                 $PR( 'width' ).value = dimensions.width;
380                 $PR( 'height' ).value = dimensions.height;
381         }
382
383         Event.observe( window, 'load', function() {
384                 new Cropper.ImgWithPreview(
385                 'croppa',
386                 {
387                         previewWrap: 'previewWrap',
388                         minWidth: 175,
389                         minHeight: 175,
390                         maxWidth: 640,
391                         maxHeight: 640,
392                         ratioDim: { x: 100, y:100 },
393                         displayOnInit: true,
394                         onEndCrop: onEndCrop
395                 });
396         });
397 }
398
399
400 /*
401 $(document).mouseup(function (clickPos) {
402
403         var sysMenu = $("#system-menu-list");
404         var sysMenuLink = $(".system-menu-link");
405         var contactsMenu = $("#contacts-menu-list");
406         var contactsMenuLink = $(".contacts-menu-link");
407         var networkMenu = $("#network-menu-list");
408         var networkMenuLink = $(".network-menu-link");
409
410         if( !sysMenu.is(clickPos.target) && !sysMenuLink.is(clickPos.target) && sysMenu.has(clickPos.target).length === 0) {
411                 hideNavMenu("#system-menu-list");
412         }
413         if( !contactsMenu.is(clickPos.target) && !contactsMenuLink.is(clickPos.target) && contactsMenu.has(clickPos.target).length === 0) {
414                 hideNavMenu("#contacts-menu-list");
415         }
416         if( !networkMenu.is(clickPos.target) && !networkMenuLink.is(clickPos.target) && networkMenu.has(clickPos.target).length === 0) {
417                 hideNavMenu("#network-menu-list");
418         }
419 });
420
421
422 function getPageContent(url) {
423
424         var pos = $('.main-container').position();
425
426         $('.main-container').css('margin-left', pos.left);
427         $('.main-content-container').hide(0, function () {
428                 $('.main-content-loading').show(0);
429         });
430
431         $.get(url, function(html) {
432                 console.log($('.main-content-container').html());
433                 $('.main-content-container').html( $('.main-content-container', html).html() );
434                 console.log($('.main-content-container').html());
435                 $('.main-content-loading').hide(function() {
436                         $('.main-content-container').fadeIn(800,function() {
437                                 $('.main-container').css('margin-left', 'auto'); // This sucks -- if the CSS specification changes, this will be wrong
438                         });
439                 });
440         });
441 }
442 */
443
444 function showNavMenu(menuID) {
445
446         if(window.navMenuTimeout[menuID + '-closing']) {
447                 window.navMenuTimeout[menuID + '-closing'] = false;
448                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
449         }
450         else {
451                 window.navMenuTimeout[menuID + '-opening'] = true;
452
453                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
454                         $(menuID).slideDown('fast').show();
455                         window.navMenuTimeout[menuID + '-opening'] = false;
456                 }, 200);
457         }
458 }
459
460 function hideNavMenu(menuID) {
461
462         if(window.navMenuTimeout[menuID + '-opening']) {
463                 window.navMenuTimeout[menuID + '-opening'] = false;
464                 clearTimeout(window.navMenuTimeout[menuID + '-timeout']);
465         }
466         else {
467                 window.navMenuTimeout[menuID + '-closing'] = true;
468
469                 window.navMenuTimeout[menuID + '-timeout'] = setTimeout( function () {
470                         $(menuID).slideUp('fast');
471                         window.navMenuTimeout[menuID + '-closing'] = false;
472                 }, 500);
473         }
474 }
475
476
477
478 /*
479  * Editor
480  */
481
482 var editor = false;
483 var textlen = 0;
484
485 function initEditor(callback) {
486         if(editor == false) {
487                 $("#profile-jot-text-loading").show();
488
489                 $("#profile-jot-text-loading").hide();
490                 $("#profile-jot-text").css({ 'height': 200, 'color': '#000' });
491                 $("#profile-jot-text").editor_autocomplete(baseurl+"/acl");
492                 $(".jothidden").show();
493                 // setup acl popup
494                 $("a#jot-perms-icon").colorbox({
495                         'inline' : true,
496                         'transition' : 'elastic'
497                 });
498
499                 editor = true;
500         }
501         if (typeof callback != "undefined") {
502                 callback();
503         }
504 }
505
506 function enableOnUser() {
507         if (editor) {
508                 return;
509         }
510         $(this).val("");
511         initEditor();
512 }
513
514 function msgInitEditor() {
515         $("#prvmail-text").editor_autocomplete(baseurl+"/acl");
516 }
517
518 /*
519  * Jot
520  */
521
522 function addeditortext(textElem, data) {
523         var currentText = $(textElem).val();
524         $(textElem).val(currentText + data);
525 }
526
527 function jotVideoURL() {
528         reply = prompt(window.vidURL);
529         if(reply && reply.length) {
530                 addeditortext("#profile-jot-text", '[video]' + reply + '[/video]');
531         }
532 }
533
534 function jotAudioURL() {
535         reply = prompt(window.audURL);
536         if(reply && reply.length) {
537                 addeditortext("#profile-jot-text", '[audio]' + reply + '[/audio]');
538         }
539 }
540
541
542 function jotGetLocation() {
543
544 /*      if(navigator.geolocation) {
545
546                 navigator.geolocation.getCurrentPosition(function(position) {
547                         var lat = position.coords.latitude;
548                         var lng = position.coords.longitude;
549
550                         $.ajax({
551                                 type: 'GET',
552                                 url: 'http://nominatim.openstreetmap.org/reverse?format=json&lat='+lat+'&lon='+lng,
553                                 jsonp: 'json_callback',
554                                 contentType: 'application/json',
555                                 dataType: 'jsonp',
556                                 success: function(json) {
557                                         console.log(json);
558                                         var locationDisplay = json.address.building+', '+json.address.city+', '+json.address.state;
559                                         $('#jot-location').val(locationDisplay);
560                                         $('#jot-display-location').html('Location: '+locationDisplay);
561                                         $('#jot-display-location').show();
562                                 }
563                         });
564                 });
565
566         }
567         else {
568                 reply = prompt(window.whereAreU, $('#jot-location').val());
569                 if(reply && reply.length) {
570                         $('#jot-location').val(reply);
571                 }
572         }*/
573
574         reply = prompt(window.whereAreU, $('#jot-location').val());
575         if(reply && reply.length) {
576                 $('#jot-location').val(reply);
577         }
578 }
579
580 function jotShare(id) {
581         if ($('#jot-popup').length != 0) $('#jot-popup').show();
582
583         $('#like-rotator-' + id).show();
584         $.get('share/' + id, function(data) {
585                 if (!editor) $("#profile-jot-text").val("");
586                 initEditor(function(){
587                         addeditortext("#profile-jot-text", data);
588                         $('#like-rotator-' + id).hide();
589                         $(window).scrollTop(0);
590                 });
591
592         });
593 }
594
595 function jotClearLocation() {
596         $('#jot-coord').val('');
597         $('#profile-nolocation-wrapper').hide();
598 }
599
600
601 function jotGetLink() {
602         reply = prompt(window.linkURL);
603         if(reply && reply.length) {
604                 reply = bin2hex(reply);
605                 $('#profile-rotator').show();
606                 $.get('parse_url?binurl=' + reply, function(data) {
607                         addeditortext(window.jotId, data);
608                         $('#profile-rotator').hide();
609                 });
610         }
611 }
612
613
614 function linkdropper(event) {
615         var linkFound = event.dataTransfer.types.contains("text/uri-list");
616         if(linkFound)
617                 event.preventDefault();
618 }
619
620
621 function linkdrop(event) {
622         var reply = event.dataTransfer.getData("text/uri-list");
623         //event.target.textContent = reply;
624         event.preventDefault();
625         if(reply && reply.length) {
626                 reply = bin2hex(reply);
627                 $('#profile-rotator').show();
628                 $.get('parse_url?binurl=' + reply, function(data) {
629 /*                      if(window.jotId == "#profile-jot-text") {
630                                 if (!editor) $("#profile-jot-text").val("");
631                                 initEditor(function(){
632                                         addeditortext(window.jotId, data);
633                                         $('#profile-rotator').hide();
634                                 });
635                         }
636                         else {*/
637                         addeditortext(window.jotId, data);
638                         $('#profile-rotator').hide();
639 //                      }
640                 });
641         }
642 }
643
644
645 if(typeof window.geoTag === 'function') window.geoTag();
646
647
648 /*
649  * Items
650  */
651
652 function confirmDelete() { return confirm(window.delItem); }
653
654 function deleteCheckedItems(delID) {
655         if(confirm(window.delItems)) {
656                 var checkedstr = '';
657
658                 $(delID).hide();
659                 $(delID + '-rotator').show();
660                 $('.item-select').each( function() {
661                         if($(this).is(':checked')) {
662                                 if(checkedstr.length != 0) {
663                                         checkedstr = checkedstr + ',' + $(this).val();
664                                 }
665                                 else {
666                                         checkedstr = $(this).val();
667                                 }
668                         }
669                 });
670                 $.post('item', { dropitems: checkedstr }, function(data) {
671                         window.location.reload();
672                 });
673         }
674 }
675
676 function itemTag(id) {
677         reply = prompt(window.term);
678         if(reply && reply.length) {
679                 reply = reply.replace('#','');
680                 if(reply.length) {
681
682                         commentBusy = true;
683                         $('body').css('cursor', 'wait');
684
685                         $.get('tagger/' + id + '?term=' + reply, NavUpdate);
686                         /*if(timer) clearTimeout(timer);
687                         timer = setTimeout(NavUpdate,3000);*/
688                         liking = 1;
689                 }
690         }
691 }
692
693 function itemFiler(id) {
694
695         var bordercolor = $("input").css("border-color");
696
697         $.get('filer/', function(data){
698                 $.colorbox({html:data});
699                 $.colorbox.resize();
700                 $("#id_term").keypress(function(){
701                         $(this).css("border-color",bordercolor);
702                 })
703                 $("#select_term").change(function(){
704                         $("#id_term").css("border-color",bordercolor);
705                 })
706
707                 $("#filer_save").click(function(e){
708                         e.preventDefault();
709                         reply = $("#id_term").val();
710                         if(reply && reply.length) {
711                                 commentBusy = true;
712                                 $('body').css('cursor', 'wait');
713                                 $.get('filer/' + id + '?term=' + reply, NavUpdate);
714 /*                                      if(timer) clearTimeout(timer);
715                                 timer = setTimeout(NavUpdate,3000);*/
716                                 liking = 1;
717                                 $.colorbox.close();
718                         } else {
719                                 $("#id_term").css("border-color","#FF0000");
720                         }
721                         return false;
722                 });
723         });
724
725 }
726
727
728 /*
729  * Comments
730  */
731
732 function insertFormatting(comment,BBcode,id) {
733
734         var tmpStr = $("#comment-edit-text-" + id).val();
735         if(tmpStr == comment) {
736                 tmpStr = "";
737                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
738                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
739                 openMenu("comment-edit-submit-wrapper-" + id);
740                 $("#comment-edit-text-" + id).val(tmpStr);
741         }
742
743         textarea = document.getElementById("comment-edit-text-" +id);
744         if (document.selection) {
745                 textarea.focus();
746                 selected = document.selection.createRange();
747                 if (BBcode == "url"){
748                         selected.text = "["+BBcode+"=http://]" +  selected.text + "[/"+BBcode+"]";
749                         } else
750                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
751         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
752                 var start = textarea.selectionStart;
753                 var end = textarea.selectionEnd;
754                 if (BBcode == "url"){
755                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"=http://]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
756                         } else
757                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
758         }
759         return true;
760 }
761
762 function cmtBbOpen(id) {
763         $("#comment-edit-bb-" + id).show();
764 }
765 function cmtBbClose(id) {
766         $("#comment-edit-bb-" + id).hide();
767 }
768
769 function commentOpen(obj,id) {
770         if(obj.value == window.commentEmptyText) {
771                 obj.value = "";
772                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
773                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
774                 $("#mod-cmnt-wrap-" + id).show();
775                 openMenu("comment-edit-submit-wrapper-" + id);
776         }
777 }
778 function commentClose(obj,id) {
779         if(obj.value == "") {
780                 obj.value = window.commentEmptyText;
781                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
782                 $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
783                 $("#mod-cmnt-wrap-" + id).hide();
784                 closeMenu("comment-edit-submit-wrapper-" + id);
785         }
786 }
787
788
789 function commentInsert(obj,id) {
790         var tmpStr = $("#comment-edit-text-" + id).val();
791         if(tmpStr == window.commentEmptyText) {
792                 tmpStr = "";
793                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
794                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
795                 openMenu("comment-edit-submit-wrapper-" + id);
796         }
797         var ins = $(obj).html();
798         ins = ins.replace("&lt;","<");
799         ins = ins.replace("&gt;",">");
800         ins = ins.replace("&amp;","&");
801         ins = ins.replace("&quot;",'"');
802         $("#comment-edit-text-" + id).val(tmpStr + ins);
803 }
804
805 function qCommentInsert(obj,id) {
806         var tmpStr = $("#comment-edit-text-" + id).val();
807         if(tmpStr == window.commentEmptyText) {
808                 tmpStr = "";
809                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
810                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
811                 openMenu("comment-edit-submit-wrapper-" + id);
812         }
813         var ins = $(obj).val();
814         ins = ins.replace("&lt;","<");
815         ins = ins.replace("&gt;",">");
816         ins = ins.replace("&amp;","&");
817         ins = ins.replace("&quot;",'"');
818         $("#comment-edit-text-" + id).val(tmpStr + ins);
819         $(obj).val("");
820 }
821
822 /*function showHideCommentBox(id) {
823         if( $('#comment-edit-form-' + id).is(':visible')) {
824                 $('#comment-edit-form-' + id).hide();
825         }
826         else {
827                 $('#comment-edit-form-' + id).show();
828         }
829 }*/
830