]> git.mxchange.org Git - friendica.git/blob - js/main.js
Merge pull request #594 from fermionic/20130127-add-event-id-index
[friendica.git] / js / main.js
1
2   function openClose(theID) {
3     if(document.getElementById(theID).style.display == "block") { 
4       document.getElementById(theID).style.display = "none" 
5     }
6     else { 
7       document.getElementById(theID).style.display = "block" 
8     } 
9   }
10
11   function openMenu(theID) {
12       document.getElementById(theID).style.display = "block" 
13   }
14
15   function closeMenu(theID) {
16       document.getElementById(theID).style.display = "none" 
17   }
18
19
20
21         var src = null;
22         var prev = null;
23         var livetime = null;
24         var msie = false;
25         var stopped = false;
26         var totStopped = false;
27         var timer = null;
28         var pr = 0;
29         var liking = 0;
30         var in_progress = false;
31         var langSelect = false;
32         var commentBusy = false;
33         var last_popup_menu = null;
34         var last_popup_button = null;
35
36         $(function() {
37                 $.ajaxSetup({cache: false});
38
39                 msie = $.browser.msie ;
40                 
41                 /* setup tooltips *//*
42                 $("a,.tt").each(function(){
43                         var e = $(this);
44                         var pos="bottom";
45                         if (e.hasClass("tttop")) pos="top";
46                         if (e.hasClass("ttbottom")) pos="bottom";
47                         if (e.hasClass("ttleft")) pos="left";
48                         if (e.hasClass("ttright")) pos="right";
49                         e.tipTip({defaultPosition: pos, edgeOffset: 8});
50                 });*/
51                 
52                 
53                 
54                 /* setup onoff widgets */
55                 $(".onoff input").each(function(){
56                         val = $(this).val();
57                         id = $(this).attr("id");
58                         $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
59                         
60                 });
61                 $(".onoff > a").click(function(event){
62                         event.preventDefault(); 
63                         var input = $(this).siblings("input");
64                         var val = 1-input.val();
65                         var id = input.attr("id");
66                         $("#"+id+"_onoff ."+ (val==0?"on":"off")).addClass("hidden");
67                         $("#"+id+"_onoff ."+ (val==1?"on":"off")).removeClass("hidden");
68                         input.val(val);
69                         //console.log(id);
70                 });
71                 
72                 /* setup field_richtext */
73                 setupFieldRichtext();
74
75                 /* popup menus */
76         function close_last_popup_menu() {
77                 if(last_popup_menu) {
78                 last_popup_menu.hide();
79                 last_popup_button.removeClass("selected");
80                 last_popup_menu = null;
81                 last_popup_button = null;
82                 }
83                 }
84                 $('a[rel^=#]').click(function(e){
85                         close_last_popup_menu();
86                         menu = $( $(this).attr('rel') );
87                         e.preventDefault();
88                         e.stopPropagation();
89                         if (menu.attr('popup')=="false") return false;
90                         $(this).parent().toggleClass("selected");
91                         menu.toggle();
92                         if (menu.css("display") == "none") {
93                                 last_popup_menu = null;
94                                 last_popup_button = null;
95                         } else {
96                                 last_popup_menu = menu;
97                                 last_popup_button = $(this).parent();
98                         }
99                         return false;
100                 });
101                 $('html').click(function() {
102                                                 close_last_popup_menu();
103                 });
104                 
105                 // fancyboxes
106                 $("a.popupbox").fancybox({
107                         'transitionIn' : 'elastic',
108                         'transitionOut' : 'elastic'
109                 });
110                 
111
112                 /* notifications template */
113                 var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
114                 var notifications_all = unescape($('<div>').append( $("#nav-notifications-see-all").clone() ).html()); //outerHtml hack
115                 var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
116                 var notifications_empty = unescape($("#nav-notifications-menu").html());
117                 
118                 /* nav update event  */
119                 $('nav').bind('nav-update', function(e,data){;
120                         var invalid = $(data).find('invalid').text();
121                         if(invalid == 1) { window.location.href=window.location.href }
122
123                         var net = $(data).find('net').text();
124                         if(net == 0) { net = ''; $('#net-update').removeClass('show') } else { $('#net-update').addClass('show') }
125                         $('#net-update').html(net);
126
127                         var home = $(data).find('home').text();
128                         if(home == 0) { home = '';  $('#home-update').removeClass('show') } else { $('#home-update').addClass('show') }
129                         $('#home-update').html(home);
130                         
131                         var intro = $(data).find('intro').text();
132                         if(intro == 0) { intro = '';  $('#intro-update').removeClass('show') } else { $('#intro-update').addClass('show') }
133                         $('#intro-update').html(intro);
134
135                         var mail = $(data).find('mail').text();
136                         if(mail == 0) { mail = '';  $('#mail-update').removeClass('show') } else { $('#mail-update').addClass('show') }
137                         $('#mail-update').html(mail);
138                         
139                         var intro = $(data).find('intro').text();
140                         if(intro == 0) { intro = '';  $('#intro-update-li').removeClass('show') } else { $('#intro-update-li').addClass('show') }
141                         $('#intro-update-li').html(intro);
142
143                         var mail = $(data).find('mail').text();
144                         if(mail == 0) { mail = '';  $('#mail-update-li').removeClass('show') } else { $('#mail-update-li').addClass('show') }
145                         $('#mail-update-li').html(mail);
146
147
148                         var allevents = $(data).find('all-events').text();
149                         if(allevents == 0) { allevents = ''; $('#allevents-update').removeClass('show') } else { $('#allevents-update').addClass('show') }
150                         $('#allevents-update').html(allevents);
151
152                         var alleventstoday = $(data).find('all-events-today').text();
153                         if(alleventstoday == 0) { $('#allevents-update').removeClass('notif-allevents-today') } else { $('#allevents-update').addClass('notif-allevents-today') }
154
155                         var events = $(data).find('events').text();
156                         if(events == 0) { events = ''; $('#events-update').removeClass('show') } else { $('#events-update').addClass('show') }
157                         $('#events-update').html(events);
158
159                         var eventstoday = $(data).find('events-today').text();
160                         if(eventstoday == 0) { $('#events-update').removeClass('notif-events-today') } else { $('#events-update').addClass('notif-events-today') }
161
162                         var birthdays = $(data).find('birthdays').text();
163                         if(birthdays == 0) {birthdays = ''; $('#birthdays-update').removeClass('show') } else { $('#birthdays-update').addClass('show') }
164                         $('#birthdays-update').html(birthdays);
165
166                         var birthdaystoday = $(data).find('birthdays-today').text();
167                         if(birthdaystoday == 0) { $('#birthdays-update').removeClass('notif-birthdays-today') } else { $('#birthdays-update').addClass('notif-birthdays-today') }
168
169
170                         var eNotif = $(data).find('notif')
171                         
172                         if (eNotif.children("note").length==0){
173                                 $("#nav-notifications-menu").html(notifications_empty);
174                         } else {
175                                 nnm = $("#nav-notifications-menu");
176                                 nnm.html(notifications_all + notifications_mark);
177                                 //nnm.attr('popup','true');
178                                 eNotif.children("note").each(function(){
179                                         e = $(this);
180                                         text = e.text().format("<span class='contactname'>"+e.attr('name')+"</span>");
181                                         html = notifications_tpl.format(e.attr('href'),e.attr('photo'), text, e.attr('date'), e.attr('seen'));
182                                         nnm.append(html);
183                                 });
184
185                                 $("img[data-src]", nnm).each(function(i, el){
186                                         // Add src attribute for images with a data-src attribute
187                                         $(el).attr('src', $(el).data("src"));
188                                 });
189                         }
190
191                         notif = eNotif.attr('count');
192                         if (notif>0){
193                                 $("#nav-notifications-linkmenu").addClass("on");
194                         } else {
195                                 $("#nav-notifications-linkmenu").removeClass("on");
196                         }
197                         if(notif == 0) { notif = ''; $('#notify-update').removeClass('show') } else { $('#notify-update').addClass('show') }
198                         $('#notify-update').html(notif);
199                         
200                         var eSysmsg = $(data).find('sysmsgs');
201                         eSysmsg.children("notice").each(function(){
202                                 text = $(this).text();
203                                 $.jGrowl(text, { sticky: true, theme: 'notice' });
204                         });
205                         eSysmsg.children("info").each(function(){
206                                 text = $(this).text();
207                                 $.jGrowl(text, { sticky: false, theme: 'info', life: 10000 });
208                         });
209                         
210                 });
211
212                 NavUpdate(); 
213                 // Allow folks to stop the ajax page updates with the pause/break key
214                 $(document).keydown(function(event) {
215                         if(event.keyCode == '8') {
216                                 var target = event.target || event.srcElement;
217                                 if (!/input|textarea/i.test(target.nodeName)) {
218                                         return false;
219                                 }
220                         }
221                         if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) {
222                                 event.preventDefault();
223                                 if(stopped == false) {
224                                         stopped = true;
225                                         if (event.ctrlKey) {
226                                                 totStopped = true;
227                                         }
228                                         $('#pause').html('<img src="images/pause.gif" alt="pause" style="border: 1px solid black;" />');
229                                 } else {
230                                         unpause();
231                                 }
232                         } else {
233                                 if (!totStopped) {
234                                         unpause();
235                                 }
236                         }
237                 });
238                 
239                 
240         });
241
242         function NavUpdate() {
243
244                 if(! stopped) {
245                         var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
246                         $.get(pingCmd,function(data) {
247                                 $(data).find('result').each(function() {
248                                         // send nav-update event
249                                         $('nav').trigger('nav-update', this);
250                                         
251                                         
252                                         // start live update
253
254                                         if($('#live-network').length)   { src = 'network'; liveUpdate(); }
255                                         if($('#live-profile').length)   { src = 'profile'; liveUpdate(); }
256                                         if($('#live-community').length) { src = 'community'; liveUpdate(); }
257                                         if($('#live-notes').length)     { src = 'notes'; liveUpdate(); }
258                                         if($('#live-display').length)     { src = 'display'; liveUpdate(); }
259 /*                                      if($('#live-display').length) {
260                                                 if(liking) {
261                                                         liking = 0;
262                                                         window.location.href=window.location.href 
263                                                 }
264                                         }*/
265                                         if($('#live-photos').length) { 
266                                                 if(liking) {
267                                                         liking = 0;
268                                                         window.location.href=window.location.href 
269                                                 }
270                                         }
271
272                                         
273                                         
274                                         
275                                 });
276                         }) ;
277                 }
278                 timer = setTimeout(NavUpdate,updateInterval);
279         }
280
281         function liveUpdate() {
282                 if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
283                 if(($('.comment-edit-text-full').length) || (in_progress)) {
284                         if(livetime) {
285                                 clearTimeout(livetime);
286                         }
287                         livetime = setTimeout(liveUpdate, 10000);
288                         return;
289                 }
290                 if(livetime != null)
291                         livetime = null;
292
293                 prev = 'live-' + src;
294
295                 in_progress = true;
296                 var udargs = ((netargs.length) ? '/' + netargs : '');
297                 var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&msie=' + ((msie) ? 1 : 0);
298
299                 $.get(update_url,function(data) {
300                         in_progress = false;
301                         //                      $('.collapsed-comments',data).each(function() {
302                         //      var ident = $(this).attr('id');
303                         //      var is_hidden = $('#' + ident).is(':hidden');
304                         //      if($('#' + ident).length) {
305                         //              $('#' + ident).replaceWith($(this));
306                         //              if(is_hidden)
307                         //                      $('#' + ident).hide();
308                         //      }
309                         //});
310
311                         // add a new thread
312                         $('.toplevel_item',data).each(function() {
313                                 var ident = $(this).attr('id');
314
315                                 if($('#' + ident).length == 0 && profile_page == 1) {
316                                         $('img',this).each(function() {
317                                                 $(this).attr('src',$(this).attr('dst'));
318                                         });
319                                         $('#' + prev).after($(this));
320                                 }
321                                 else {
322                                         // Find out if the hidden comments are open, so we can keep it that way
323                                         // if a new comment has been posted
324                                         var id = $('.hide-comments-total', this).attr('id');
325                                         if(typeof id != 'undefined') {
326                                                 id = id.split('-')[3];
327                                                 var commentsOpen = $("#collapsed-comments-" + id).is(":visible");
328                                         }
329
330                                         $('img',this).each(function() {
331                                                 $(this).attr('src',$(this).attr('dst'));
332                                         });
333                                         //vScroll = $(document).scrollTop();
334                                         $('html').height($('html').height());
335                                         $('#' + ident).replaceWith($(this));
336
337                                         if(typeof id != 'undefined') {
338                                                 if(commentsOpen) showHideComments(id);
339                                         }
340                                         $('html').height('auto');
341                                         //$(document).scrollTop(vScroll);
342                                 }
343                                 prev = ident;
344                         });
345
346                         // reset vars for inserting individual items
347
348                         /*                      prev = 'live-' + src;
349
350                         $('.wall-item-outside-wrapper',data).each(function() {
351                                 var ident = $(this).attr('id');
352
353                                 if($('#' + ident).length == 0 && prev != 'live-' + src) {
354                                                 $('img',this).each(function() {
355                                                         $(this).attr('src',$(this).attr('dst'));
356                                                 });
357                                                 $('#' + prev).after($(this));
358                                 }
359                                 else { 
360                                         $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
361                                         if($('#' + ident + ' ' + '.comment-edit-text-empty').length)
362                                                 $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
363                                         $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total'));
364                                         $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
365                                         $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
366                                         $('#' + ident + ' ' + '.my-comment-photo').each(function() {
367                                                 $(this).attr('src',$(this).attr('dst'));
368                                         });
369                                 }
370                                 prev = ident; 
371                         });
372                         */
373                         $('.like-rotator').hide();
374                         if(commentBusy) {
375                                 commentBusy = false;
376                                 $('body').css('cursor', 'auto');
377                         }
378                         /* autocomplete @nicknames */
379                         $(".comment-edit-form  textarea").contact_autocomplete(baseurl+"/acl");
380                 });
381         }
382
383         function imgbright(node) {
384                 $(node).removeClass("drophide").addClass("drop");
385         }
386
387         function imgdull(node) {
388                 $(node).removeClass("drop").addClass("drophide");
389         }
390
391         // Since our ajax calls are asynchronous, we will give a few 
392         // seconds for the first ajax call (setting like/dislike), then 
393         // run the updater to pick up any changes and display on the page.
394         // The updater will turn any rotators off when it's done. 
395         // This function will have returned long before any of these
396         // events have completed and therefore there won't be any
397         // visible feedback that anything changed without all this
398         // trickery. This still could cause confusion if the "like" ajax call
399         // is delayed and NavUpdate runs before it completes.
400
401         function dolike(ident,verb) {
402                 unpause();
403                 $('#like-rotator-' + ident.toString()).show();
404                 $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
405                 liking = 1;
406         }
407
408         function dosubthread(ident) {
409                 unpause();
410                 $('#like-rotator-' + ident.toString()).show();
411                 $.get('subthread/' + ident.toString(), NavUpdate );
412                 liking = 1;
413         }
414
415
416         function dostar(ident) {
417                 ident = ident.toString();
418                 $('#like-rotator-' + ident).show();
419                 $.get('starred/' + ident, function(data) {
420                         if(data.match(/1/)) {
421                                 $('#starred-' + ident).addClass('starred');
422                                 $('#starred-' + ident).removeClass('unstarred');
423                                 $('#star-' + ident).addClass('hidden');
424                                 $('#unstar-' + ident).removeClass('hidden');
425                         }
426                         else {                  
427                                 $('#starred-' + ident).addClass('unstarred');
428                                 $('#starred-' + ident).removeClass('starred');
429                                 $('#star-' + ident).removeClass('hidden');
430                                 $('#unstar-' + ident).addClass('hidden');
431                         }
432                         $('#like-rotator-' + ident).hide();     
433                 });
434         }
435
436         function getPosition(e) {
437                 var cursor = {x:0, y:0};
438                 if ( e.pageX || e.pageY  ) {
439                         cursor.x = e.pageX;
440                         cursor.y = e.pageY;
441                 }
442                 else {
443                         if( e.clientX || e.clientY ) {
444                                 cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
445                                 cursor.y = e.clientY + (document.documentElement.scrollTop  || document.body.scrollTop)  - document.documentElement.clientTop;
446                         }
447                         else {
448                                 if( e.x || e.y ) {
449                                         cursor.x = e.x;
450                                         cursor.y = e.y;
451                                 }
452                         }
453                 }
454                 return cursor;
455         }
456
457         var lockvisible = false;
458
459         function lockview(event,id) {
460                 event = event || window.event;
461                 cursor = getPosition(event);
462                 if(lockvisible) {
463                         lockviewhide();
464                 }
465                 else {
466                         lockvisible = true;
467                         $.get('lockview/' + id, function(data) {
468                                 $('#panel').html(data);
469                                 $('#panel').css({ 'left': cursor.x + 5 , 'top': cursor.y + 5});
470                                 $('#panel').show();
471                         });
472                 }
473         }
474
475         function lockviewhide() {
476                 lockvisible = false;
477                 $('#panel').hide();
478         }
479
480         function post_comment(id) {
481                 unpause();
482                 commentBusy = true;
483                 $('body').css('cursor', 'wait');
484                 $("#comment-preview-inp-" + id).val("0");
485                 $.post(  
486              "item",  
487              $("#comment-edit-form-" + id).serialize(),
488                         function(data) {
489                                 if(data.success) {
490                                         $("#comment-edit-wrapper-" + id).hide();
491                                         $("#comment-edit-text-" + id).val('');
492                                 var tarea = document.getElementById("comment-edit-text-" + id);
493                                         if(tarea)
494                                                 commentClose(tarea,id);
495                                         if(timer) clearTimeout(timer);
496                                         timer = setTimeout(NavUpdate,10);
497                                 }
498                                 if(data.reload) {
499                                         window.location.href=data.reload;
500                                 }
501                         },
502                         "json"  
503          );  
504          return false;  
505         }
506
507
508         function preview_comment(id) {
509                 $("#comment-preview-inp-" + id).val("1");
510                 $("#comment-edit-preview-" + id).show();
511                 $.post(  
512              "item",  
513              $("#comment-edit-form-" + id).serialize(),
514                         function(data) {
515                                 if(data.preview) {
516                                                 
517                                         $("#comment-edit-preview-" + id).html(data.preview);
518                                         $("#comment-edit-preview-" + id + " a").click(function() { return false; });
519                                 }
520                         },
521                         "json"  
522          );  
523          return true;  
524         }
525
526
527
528         function showHideComments(id) {
529                 if( $("#collapsed-comments-" + id).is(":visible")) {
530                         $("#collapsed-comments-" + id).hide();
531                         $("#hide-comments-" + id).html(window.showMore);
532                 }
533                 else {
534                         $("#collapsed-comments-" + id).show();
535                         $("#hide-comments-" + id).html(window.showFewer);
536                 }
537         }
538
539
540
541         function preview_post() {
542                 $("#jot-preview").val("1");
543                 $("#jot-preview-content").show();
544                 tinyMCE.triggerSave();
545                 $.post(  
546                         "item",  
547                         $("#profile-jot-form").serialize(),
548                         function(data) {
549                                 if(data.preview) {                      
550                                         $("#jot-preview-content").html(data.preview);
551                                         $("#jot-preview-content" + " a").click(function() { return false; });
552                                 }
553                         },
554                         "json"  
555                 );  
556                 $("#jot-preview").val("0");
557                 return true;  
558         }
559
560
561         function unpause() {
562                 // unpause auto reloads if they are currently stopped
563                 totStopped = false;
564                 stopped = false;
565             $('#pause').html('');
566         }
567                 
568
569     function bin2hex(s){  
570         // Converts the binary representation of data to hex    
571         //   
572         // version: 812.316  
573         // discuss at: http://phpjs.org/functions/bin2hex  
574         // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
575         // +   bugfixed by: Onno Marsman  
576         // +   bugfixed by: Linuxworld  
577         // *     example 1: bin2hex('Kev');  
578         // *     returns 1: '4b6576'  
579         // *     example 2: bin2hex(String.fromCharCode(0x00));  
580         // *     returns 2: '00'  
581         var v,i, f = 0, a = [];  
582         s += '';  
583         f = s.length;  
584           
585         for (i = 0; i<f; i++) {  
586             a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");  
587         }  
588           
589         return a.join('');  
590     }  
591
592         function groupChangeMember(gid, cid, sec_token) {
593                 $('body .fakelink').css('cursor', 'wait');
594                 $.get('group/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
595                                 $('#group-update-wrapper').html(data);
596                                 $('body .fakelink').css('cursor', 'auto');                              
597                 });
598         }
599
600         function profChangeMember(gid,cid) {
601                 $('body .fakelink').css('cursor', 'wait');
602                 $.get('profperm/' + gid + '/' + cid, function(data) {
603                                 $('#prof-update-wrapper').html(data);
604                                 $('body .fakelink').css('cursor', 'auto');                              
605                 });
606         }
607
608         function contactgroupChangeMember(gid,cid) {
609                 $('body').css('cursor', 'wait');
610                 $.get('contactgroup/' + gid + '/' + cid, function(data) {
611                                 $('body').css('cursor', 'auto');
612                 });
613         }
614
615
616 function checkboxhighlight(box) {
617   if($(box).is(':checked')) {
618         $(box).addClass('checkeditem');
619   }
620   else {
621         $(box).removeClass('checkeditem');
622   }
623 }
624
625 function notifyMarkAll() {
626         $.get('notify/mark/all', function(data) {
627                 if(timer) clearTimeout(timer);
628                 timer = setTimeout(NavUpdate,1000);
629         });
630 }
631
632
633 // code from http://www.tinymce.com/wiki.php/How-to_implement_a_custom_file_browser
634 function fcFileBrowser (field_name, url, type, win) {
635     /* TODO: If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
636        the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
637        These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
638
639
640     var cmsURL = baseurl+"/fbrowser/"+type+"/";
641
642     tinyMCE.activeEditor.windowManager.open({
643         file : cmsURL,
644         title : 'File Browser',
645         width : 420,  // Your dimensions may differ - toy around with them!
646         height : 400,
647         resizable : "yes",
648         inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
649         close_previous : "no"
650     }, {
651         window : win,
652         input : field_name
653     });
654     return false;
655   }
656
657 function setupFieldRichtext(){
658         tinyMCE.init({
659                 theme : "advanced",
660                 mode : "specific_textareas",
661                 editor_selector: "fieldRichtext",
662                 plugins : "bbcode,paste, inlinepopups",
663                 theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,image,forecolor,formatselect,code",
664                 theme_advanced_buttons2 : "",
665                 theme_advanced_buttons3 : "",
666                 theme_advanced_toolbar_location : "top",
667                 theme_advanced_toolbar_align : "center",
668                 theme_advanced_blockformats : "blockquote,code",
669                 paste_text_sticky : true,
670                 entity_encoding : "raw",
671                 add_unload_trigger : false,
672                 remove_linebreaks : false,
673                 //force_p_newlines : false,
674                 //force_br_newlines : true,
675                 forced_root_block : 'div',
676                 convert_urls: false,
677                 content_css: baseurl+"/view/custom_tinymce.css",
678                 theme_advanced_path : false,
679                 file_browser_callback : "fcFileBrowser",
680         });
681 }
682
683
684 /** 
685  * sprintf in javascript 
686  *      "{0} and {1}".format('zero','uno'); 
687  **/
688 String.prototype.format = function() {
689     var formatted = this;
690     for (var i = 0; i < arguments.length; i++) {
691         var regexp = new RegExp('\\{'+i+'\\}', 'gi');
692         formatted = formatted.replace(regexp, arguments[i]);
693     }
694     return formatted;
695 };
696 // Array Remove
697 Array.prototype.remove = function(item) {
698   to=undefined; from=this.indexOf(item);
699   var rest = this.slice((to || from) + 1 || this.length);
700   this.length = from < 0 ? this.length + from : from;
701   return this.push.apply(this, rest);
702 };
703
704 function previewTheme(elm) {
705         theme = $(elm).val();
706         $.getJSON('pretheme?f=&theme=' + theme,function(data) {
707                         $('#theme-preview').html('<div id="theme-desc">' + data.desc + '</div><div id="theme-version">' + data.version + '</div><div id="theme-credits">' + data.credits + '</div><a href="' + data.img + '"><img src="' + data.img + '" width="320" height="240" alt="' + theme + '" /></a>');
708         });
709
710 }