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