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