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