fixed path problem (missing "/")
[phpfspot.git] / phpfspot.js
1 /***************************************************************************
2  *
3  * phpfspot, presents your F-Spot photo collection in Web browsers.
4  *
5  * Copyright (c) by Andreas Unterkircher
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  ***************************************************************************/
22
23 /**
24  * show photo
25  *
26  * this function will be called by client and fetches
27  * the single-photo view via AJAX from the server.
28  * Furthermore it will scrollup the browser to the top
29  * position so the image become visibile immediatley.
30  */
31 function showPhoto(id, scrollup)
32 {
33    /* is phpfspot skeleton really displayed? */
34    if(!document.getElementById('content'))
35       return;
36
37    var content = document.getElementById('content');
38
39    /* blank the screen */
40    if(scrollup != undefined) {
41       content.innerHTML = "";
42    }
43
44    /* fetch single-photo view from server */
45    HTML_AJAX.replace(content, encodeURI(web_path + '/rpc.php?action=showphoto&id=' + id));
46
47    /* scroll the window up to the top */
48    if(scrollup != undefined) {
49       window.scrollTo(0,0);
50    }
51
52    /* delete some global vars */
53    delete(origHeight); origHeight = undefined;
54    delete(origWidth); origWidth = undefined;
55    delete(photo_details_pos); photo_details_pos = undefined;
56
57 } // showPhoto()
58
59 /**
60  * scroll browser to the last shown photo
61  *
62  * this function will be called when user returns from single-photo
63  * to the photo index. It will scroll down the window (if possible)
64  * to the position of the last shown photo.
65  */
66 function moveToThumb(thumb_id)
67 {
68    if(thumb_id == undefined)
69       return;
70
71    if(thumbimg = document.getElementById('thumbimg' + thumb_id)) {
72       window.scrollTo(0, findPos(thumbimg,'top')-100);
73    }
74
75 } // moveToThumb()
76
77 /**
78  * return position of object
79  *
80  * this function returns the position of an object.
81  * depending on the parameter 'direction' it will either
82  * return the X or Y position.
83  */
84 function findPos(obj, direction) {
85    var cur = 0;
86    if (obj.offsetParent) {
87       do {
88          if(direction == 'left')
89             cur += obj.offsetLeft;
90          if(direction == 'top')
91             cur += obj.offsetTop;
92       } while (obj = obj.offsetParent);
93    }
94    return [cur];
95
96 } // findPos()
97
98 /**
99  * opens the credits page
100  */
101 function showCredits()
102 {
103    var credits = document.getElementById("content");
104    credits.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=showcredits'));
105
106 } // showCredits()
107
108 /**
109  * tag-selection handling
110  *
111  * this function is getting called by client to either
112  * - add
113  ∗ - delete
114  * - modify tag-match condition
115  *
116  * It will then fetch the result from the server via AJAX
117  * and updates the tag-selection.
118  */
119 function Tags(mode, id)
120 {
121    var objTemp = new Object();
122
123    if(mode == "add") {
124       // add tag to users session
125       objTemp['action'] = 'addtag';
126       objTemp['id'] = id;
127    }
128    else if(mode == "del") {
129       // del tag from users session
130       objTemp['action'] = 'deltag';
131       objTemp['id'] = id;
132    }
133    else if(mode == "condition") {
134       setCheckedValue(id, id.value);
135       objTemp['action'] = 'tagcondition';
136       objTemp['mode'] = id.value;
137    }
138
139    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
140    if(retr == "ok") {
141       refreshAvailableTags();
142       refreshSelectedTags();
143       refreshPhotoIndex();
144    }
145    else {
146       window.alert("Server message: "+ retr);
147    }
148
149 } // Tags()
150
151 /**
152  * update available-tags tag-cloud
153  *
154  * this function queries an actual version of the tag-cloud
155  * for the available (not-selected) tags from the server via
156  * AJAX.
157  */
158 function refreshAvailableTags()
159 {
160    // update available tags
161    var avail_tags = document.getElementById('available_tags');
162    if(avail_tags != undefined) {
163       avail_tags.innerHTML = "Loading...";
164       avail_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_available_tags'));
165    }
166
167 } // refreshAvailableTags()
168
169 /**
170  * update selected-tags list
171  *
172  * this function queries an actual version of the tag-list
173  * for the selected tags from the server via AJAX.
174  */
175 function refreshSelectedTags()
176 {
177    // update selected tags
178    var selected_tags = document.getElementById("selected_tags");
179    if(selected_tags != undefined) {
180       selected_tags.innerHTML = "Loading...";
181       selected_tags.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=show_selected_tags'));
182    }
183
184 } // refreshSelectedTags()
185
186 /**
187  * show photo index
188  *
189  * this function will fetch the photo-index view from
190  * the server via AJAX. It's also used to browse through
191  * the photo-index pages
192  */
193 function showPhotoIndex(begin_with, last_photo)
194 {
195    var url = web_path + "/rpc.php?action=show_photo_index";
196    if(begin_with != undefined)
197       url = url + '&begin_with=' + begin_with;
198    if(last_photo != undefined)
199       url = url + '&last_photo=' + last_photo;
200
201    HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
202
203 } // showPhotoIndex()
204
205 /**
206  * update photo index
207  *
208  * this function will be called, to request a refresh of the
209  * photo index. this, for example, can be caused, when changing
210  * the tag-selection.
211  */
212 function refreshPhotoIndex()
213 {
214    /* only invoke showPhotoIndex(), if photo-index is really shown */
215    if(document.getElementById("index") != undefined || startup == 1) {
216       showPhotoIndex();
217       startup = 0;
218    }
219
220 } // refreshPhotoIndex()
221
222 /**
223  * blur cursor focus
224  *
225  * this function removes the focus-rectangle which may appear
226  * when click on a link. Not always beautiful.
227  */
228 function click(object)
229 {
230    if(object.blur)
231       object.blur();
232
233 } // click()
234
235 /**
236  * change current radio-button setting
237  *
238  * This function will check the radio-button with the given value.
239  * If no radio-button is currently displayed, this function will do
240  * nothing.
241  * If the given value does not exist, the existing radio buttons will
242  * be reseted.
243  */
244 function setCheckedValue(condition, value) {
245
246    var count = condition.length;
247    if(count == undefined) {
248       condition.checked = (condition.value == value.toString());
249       return;
250    }
251    for(var i = 0; i < count; i++) {
252       condition[i].checked = false;
253       if(condition[i].value == value.toString()) {
254          condition[i].checked = true;
255       }
256    }
257
258 } // setCheckedValue()
259
260 /**
261  * Invoke a search
262  *
263  * This function will be invoked by starting
264  * any kind of search (tag-name, photo-name, date, ...).
265  */
266 function startSearch()
267 {
268    if(document.getElementById('date_from').value != undefined) {
269       date_from = document.getElementById('date_from').value;
270    }
271    if(document.getElementById('date_to').value != undefined) {
272       date_to = document.getElementById('date_to').value;
273    }
274       
275    var objTemp = new Object();
276    objTemp['action'] = 'search';
277
278    if(document.getElementsByName('searchfor_tag')[0] != undefined &&
279       document.getElementsByName('searchfor_tag')[0].value != "") {
280       objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
281    }
282    if(document.getElementsByName('searchfor_name')[0] != undefined &&
283       document.getElementsByName('searchfor_name')[0].value != "") {
284       objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
285    }
286    if(document.getElementsByName('consider_date')[0] != undefined &&
287       document.getElementsByName('consider_date')[0].checked == true) {
288       objTemp['date_from'] = date_from;
289       objTemp['date_to'] = date_to;
290    }
291    if(document.getElementsByName('consider_rate')[0] != undefined &&
292       document.getElementsByName('consider_rate')[0].checked == true) {
293       objTemp['rate_from'] = rate_search['from'];
294       objTemp['rate_to'] = rate_search['to'];
295    }
296
297    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
298    if(retr == "ok") {
299       refreshAvailableTags();
300       refreshSelectedTags();
301       showPhotoIndex();
302    }
303    else {
304       window.alert("Server message: "+ retr);
305    }
306
307 } // startSearch()
308
309 /**
310  * enable/disable date search
311  *
312  * this function will either enable or disable the
313  * input fields for the date-search
314  */
315 function datesearch()
316 {
317    var mode = true;
318
319    if(document.getElementsByName('consider_date')[0].checked == true) {
320       mode = false;
321    }
322       
323    document.getElementById('date_from').disabled = mode;
324    document.getElementById('date_to').disabled = mode;
325  
326 } // datesearch()
327
328 /**
329  * set view mode
330  *
331  * called for photo-index export. will return the
332  * selected mode via AJAX from the server.
333  */
334 function setViewMode(srv_webpath, mode)
335 {
336    if(srv_webpath != undefined)
337       web_path = srv_webpath;
338    else
339       web_path = '';
340
341    var exprt = document.getElementById('output');
342    exprt.innerHTML = "Loading...";
343    exprt.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_export&mode=' + mode));
344
345 } // setViewMode()
346
347 /**
348  * reset all search-fields
349  */
350 function clearSearch()
351 {
352    if(document.getElementsByName('searchfor_tag')[0] != undefined)
353       document.getElementsByName('searchfor_tag')[0].value = '';
354    if(document.getElementsByName('searchfor_name')[0] != undefined)
355       document.getElementsByName('searchfor_name')[0].value = '';
356
357    if(document.getElementsByName('consider_date')[0] != undefined &&
358       document.getElementsByName('consider_date')[0].checked == true) {
359       document.getElementsByName('consider_date')[0].checked = false;
360       datesearch();
361    }
362    if(document.getElementsByName('consider_rate')[0] != undefined &&
363       document.getElementsByName('consider_rate')[0].checked == true) {
364       document.getElementsByName('consider_rate')[0].checked = false;
365    }
366
367 } // clearSearch()
368
369 /**
370  * if the client is planless, ask the server what to do
371  * next.
372  */
373 function AskServerWhatToDo()
374 {
375    return HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=what_to_do'));
376
377 } // AskServerWhatToDo()
378
379 /**
380  * init phpfspot
381  *
382  * this function will be called when the browser opens phpfspot
383  * the first time. It will fetch the tag-lists and will then
384  * switch to the right view, which the browser got told from
385  * the server (maybe someone hit the refresh button...).
386  *
387  * as parameter the server can set the correct webpath.
388  * espacialley when using user-friendly url's, the browser
389  * does not know the correct URLs to address images, stylesheets,
390  * ... then.
391  */
392 function init_phpfspot(srv_webpath)
393 {
394    if(srv_webpath != undefined)
395       web_path = srv_webpath;
396    else
397       web_path = '';
398
399    /* always load list of available tags */
400    //this should not be more necessary since 4.5.08
401    //refreshAvailableTags();
402
403    /* ask the server what we are currently displaying */
404    whattodo = AskServerWhatToDo();
405
406    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
407       showPhotoIndex();
408    }
409    if(whattodo == 'showpi_tags') {
410       refreshSelectedTags();
411       showPhotoIndex();
412    }
413    if(whattodo == 'show_photo') {
414       if(photo = getPhotoToShow()) {
415          showPhoto(photo);
416          refreshSelectedTags();
417       }
418    }
419
420 } // init_phpfspot()
421
422 /**
423  * change background-color on mouse-over
424  */
425 function setBackGrdColor(item, color)
426 {
427    if(color == 'mouseover')
428       item.style.backgroundColor='#c6e9ff';
429    if(color == 'mouseout')
430       item.style.backgroundColor='#eeeeee';
431    if(color == 'mouseclick')
432       item.style.backgroundColor='#93A8CA';
433
434 } // setBackGrdColor()
435
436 /**
437  * ask server, which photo needs to be shown
438  *
439  * when user press the refresh-button in a single-photo
440  * view or maybe enters the link via an external URL, the
441  * client does not know, what photo will be shown (dimensions...).
442  * But the server can tell this the browser.
443  */
444 function getPhotoToShow()
445 {
446    var photo_to_show = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_photo_to_show'));
447
448    // if no image needs to be shown, return false from here
449    if(photo_to_show == "")
450       return false;
451    
452    return photo_to_show;
453
454 } // getPhotoToShow()
455
456 /**
457  * a fake-zoom for photo
458  *
459  * a quick to let the browser do some zooming on
460  * photos.
461  */
462 function zoom(mod)
463 {
464    var photo;
465
466    if(mod == undefined)
467       return;
468
469    /* internet explorer */
470    if(document.images['photo'].width)
471       photo = document.images['photo'];
472
473    /* all others */
474    if(photo == undefined && document.getElementById('photo').width)
475       photo = document.getElementById('photo');
476
477    if(photo != undefined) {
478
479       if(origWidth == undefined)
480          origWidth = photo.width;
481       if(origHeight == undefined)
482          origHeight = photo.height;
483
484       if(mod != 0) {
485          new_w = photo.width * (1 + mod/100);
486          new_h = photo.height * (1 + mod/100);
487          photo.width = new_w;
488          photo.height = new_h;
489
490          if(photo_details_pos == undefined) {
491             photo_details_pos = findPos(document.getElementById('photo_details'),'left');
492          }
493
494          if((photo.offsetLeft + new_w) >= photo_details_pos-20) {
495             hidePhotoDetails('true');
496          }
497          else {
498             hidePhotoDetails('false');
499          }
500       }
501       else {
502          photo.width = origWidth;
503          photo.height = origHeight;
504          hidePhotoDetails('false');
505       }
506    }
507
508 } // zoom()
509
510 /**
511  * hides the photo details layin
512  *
513  * if the photo is getting zoomed quiet large, this will
514  * auto-hide (and also restore) the photo-details-box.
515  */
516 function hidePhotoDetails(mode)
517 {
518    var photo_details;
519
520    if(photo_details = document.getElementById('photo_details')) {
521       if(mode == 'true') {
522          photo_details.style.visibility = 'hidden';
523          photo_details.style.display = 'none';
524       }
525       else {
526          photo_details.style.visibility = 'visible';
527          photo_details.style.display = '';
528       }
529    }
530 } // hidePhotoDetails()
531
532 /**
533  * show calendar
534  */
535 function showCalendar(date_box, click_obj)
536 {
537    var calendar;
538    var userdate;
539
540    calendar = document.getElementById('calendar');
541    if(calendar == undefined) {
542       window.alert("Can not find element 'calendar'");
543       return;
544    }
545
546    userdate = document.getElementById('date_' + date_box);
547
548    if(userdate == undefined) {
549       window.alert("Can not find element 'date_'" + date_box);
550       return;
551    }
552
553    userdate = userdate.value;
554
555    if(date_box == 'from') {
556       var xpos = document.getElementById('frompic').offsetLeft;
557       var ypos = document.getElementById('frompic').offsetTop;
558       calendar_mode = 'from';
559    }
560    if(date_box == 'to') {
561       var xpos = document.getElementById('topic').offsetLeft;
562       var ypos = document.getElementById('topic').offsetTop;
563       calendar_mode = 'to';
564    }
565    calendar.style.left = xpos + 100 + 'px';
566    calendar.style.top = ypos + 120 + 'px';
567
568    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
569       calendar.style.visibility = 'visible';
570       calendar.innerHTML = "Loading...";
571       calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&date=' + userdate));
572       calendar_shown = 1;
573    }
574    else {
575       hideCalendar();
576    }
577
578 } // showCalendar()
579
580 /**
581  * hide calendar
582  */
583 function hideCalendar()
584 {
585    var calendar = document.getElementById('calendar');
586    if(calendar.style.visibility != 'hidden') {
587       calendar.style.visibility = 'hidden';
588       calendar_shown = 0;
589    }
590 } // hideCalendar()
591
592 /**
593  * switch month in calendar
594  */
595 function setMonth(year, month, day)
596 {
597    var calendar = document.getElementById('calendar');
598    calendar.innerHTML = "Loading...";
599    calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&date='+ year +'-'+ month +'-'+ day));
600 }
601
602 /**
603  * get the user-selected date from the calendar and
604  * put it into the date-search boxes
605  */
606 function setCalendarDate(userdate)
607 {
608    document.getElementById('date_'+calendar_mode).value = userdate;
609    hideCalendar();
610
611 } // setCalendarDate()
612
613 /**
614  * reset phpfspot complelely and move to the begining
615  */
616 function resetAll()
617 {
618    HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset'));
619    clearSearch();
620    refreshAvailableTags();
621    refreshSelectedTags();
622    refreshPhotoIndex();
623
624 } // resetAll()
625
626 /**
627  * find objects with their class-name
628  */
629 function WSR_getElementsByClassName(oElm, strTagName, oClassNames){
630    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
631    var arrReturnElements = new Array();
632    var arrRegExpClassNames = new Array();
633    if(typeof oClassNames == "object"){
634       for(var i=0; i<oClassNames.length; i++){
635          arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames[i].replace(/-/g, "\-") + "(\s|$)"));
636       }
637    }
638    else{
639       arrRegExpClassNames.push(new RegExp("(^|\s)" + oClassNames.replace(/-/g, "\-") + "(\s|$)"));
640    }
641    var oElement;
642    var bMatchesAll;
643    for(var j=0; j<arrElements.length; j++){
644       oElement = arrElements[j];
645       bMatchesAll = true;
646       for(var k=0; k<arrRegExpClassNames.length; k++){
647          if(!arrRegExpClassNames[k].test(oElement.className)){
648             bMatchesAll = false;
649             break;
650          }
651       }
652       if(bMatchesAll){
653          arrReturnElements.push(oElement);
654       }
655    }
656    return (arrReturnElements)
657
658 } // WSR_getElementsByClassName()
659
660 /**
661  * javascript based photo preloading
662  */
663 function preloadPhotos(image_url) {
664
665    var i;
666    var timeout = 1000;
667    var waiting = 100;
668    var counting;
669
670    lbImg = WSR_getElementsByClassName(document,"img","thumb");
671    if(lbImg != undefined) {
672       for(i=0;i<lbImg.length;i++){
673          lbImg[i].src=image_url[i];
674          // to not bomb the server with requests, give the page some time
675          // to load the images one by one. if a image exceeds the timeout,
676          // the next image will be loaded.
677          if(lbImg[i].complete != undefined && lbImg[i].complete != true) {
678             counting = 0;
679             while(lbImg[i].complete != true && counting < timeout) {
680                window.setTimeout("noop()", waiting);
681                counting+=waiting;
682             }
683          }
684       }
685    }
686
687 } // preloadPhotos()
688
689 /* a function that does nothing */
690 function noop() {}
691
692 /**
693  * start slideshow
694  */
695 function startSlideShow(srv_webpath)
696 {
697    if(srv_webpath != undefined)
698       web_path = srv_webpath;
699    else
700       web_path = '';
701
702    if(!sliding) {
703       HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=reset_slideshow'));
704       nextSlide();
705       sliding = setInterval("nextSlide()", sliding_time*1000);
706       document.getElementById('stop_ico').src = web_path + "/resources/32_stop.png";
707    }
708    else {
709       clearInterval(sliding);
710       sliding = 0;
711       document.getElementById('stop_ico').src = web_path + "/resources/32_play.png";
712    }
713
714 } // startSlideShow()
715
716 /**
717  * switch to next slide
718  */
719 function nextSlide()
720 {
721    var next_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_next_slideshow_img'));
722    document.getElementById('slide_img').src = next_img;
723
724 } // nextSlide()
725
726 /**
727  * switch to previous slide
728  */
729 function prevSlide()
730 {
731    var prev_img = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_prev_slideshow_img'));
732    document.getElementById('slide_img').src = prev_img;
733
734 } // prevSlide()
735
736 /**
737  * interrupt slide show
738  */
739 function pauseSlideShow()
740 {
741    if(!sliding_paused) {
742       sliding_paused = 1;
743       clearInterval(sliding);
744       document.getElementById('pause_ico').src = web_path + "/resources/32_play.png";
745    }
746    else {
747       sliding_paused = 0;
748       sliding = setInterval("nextSlide()", sliding_time*1000);
749       document.getElementById('pause_ico').src = web_path + "/resources/32_pause.png";
750    }
751
752 } // pauseSlideShow()
753
754 /**
755  * start auto-browse
756  */
757 function startAutoBrowse()
758 {
759    if(!autobrowse) {
760       autoBrowse();
761       autobrowse = setInterval("autoBrowse()", 5000);
762    }
763    else {
764       clearInterval(autobrowse);
765       autobrowse = 0;
766       document.getElementById('autobrowse_ico').src = web_path + "/resources/16_play.png";
767    }
768
769 } // startAutoBrowser()
770
771 /**
772  * auto-browsing
773  */
774 function autoBrowse()
775 {
776    if(document.getElementById('next_link')) {
777       var next_link = document.getElementById('next_link').href;
778       window.location.href = next_link;
779       document.getElementById('autobrowse_ico').src = web_path + "/resources/16_pause.png";
780    }
781    /* we have reached the last photo */
782    else {
783       if(ab_ico = document.getElementById('autobrowse_ico'))
784          ab_ico.src = web_path + "/resources/16_play.png";
785       clearInterval(autobrowse);
786    }
787
788 } // autoBrowse()
789
790 /**
791  * initiate slider to modify slide-switching-speed
792  */
793 function initSlider()
794 {
795    var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
796    var inputEl = document.forms[0]["slider-input-1"];
797    var s = new Slider(sliderEl, inputEl);
798    s.setMinimum(1);
799    s.setMaximum(10);
800    s.setValue(sliding_time);
801    document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
802    s.onchange = function () {
803       sliding_time = s.getValue();
804       document.getElementById("current_slide_time").innerHTML = sliding_time + "s Interval";
805       if(!sliding_paused && sliding) {
806          clearInterval(sliding);
807          sliding = setInterval("nextSlide()", sliding_time*1000);
808       }
809    };
810    window.onresize = function () {
811       s.recalculate();
812    };
813
814 } // initSlider()
815
816 /**
817  * if the sort-order (photo-name, date, ...) has been
818  * changed, update the photo-index view.
819  */
820 function update_sort_order(obj)
821 {  
822    var objTemp = new Object();
823    objTemp['value'] = obj.options[obj.selectedIndex].value;
824
825    var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_sort_order', objTemp);
826
827    if(retr == "ok") {
828       showPhotoIndex();
829    }
830    else {
831       window.alert("Server message: "+ retr);
832    }
833
834 } // update_sort_order()
835
836 /**
837  * if the photo-version ѕelect-box has changed, set the newly
838  * choosen photo version as the to-be-displayed photo version
839  */
840 function update_photo_version(obj, current_photo)
841 {
842    var objTemp = new Object();
843    objTemp['photo_version'] = obj.options[obj.selectedIndex].value;
844    objTemp['photo_idx'] = current_photo;
845
846    var retr = HTML_AJAX.post(web_path + '/rpc.php?action=update_photo_version', objTemp);
847
848    if(retr == "ok") {
849       showPhoto(current_photo);
850    }
851    else {
852       window.alert("Server message: "+ retr);
853    }
854
855 } // update_photo_version()
856
857 /**
858  * show rate stars
859  *
860  * this function will show the requested amount of
861  * rate-stars.
862  *
863  * @param string mode
864  * @param int level
865  */
866 function show_rate(mode, level)
867 {
868    var i;
869
870    for(i = 1; i <= 5; i++) {
871       if(i <= level) {
872          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
873       }
874       else {
875          document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
876       }
877    }
878
879 } // show_rate()
880
881 /**
882  * set rate stars
883  *
884  *
885  * this function will set the requested rate-stars-amount into a global
886  * variable (which will then later be used on form-submit) and will also
887  * update the display.
888  *
889  * @param string mode
890  * @param int level
891  */
892 function set_rate(mode, level)
893 {
894    rate_search[mode] = level;
895    show_rate(mode, level);
896
897 } // set_rate()
898
899 /**
900  * reset rate stars
901  *
902  * this function will reset the rate-star to their initial value.
903  *
904  * @param string mode
905  */
906 function reset_rate(mode)
907 {
908    if(rate_search[mode] == undefined)
909       rate_search[mode] = 0;
910
911    show_rate(mode, rate_search[mode]);
912
913 } // reset_rate()
914
915 /**
916  * handle key events
917  */
918 function keyDown(e) {
919    var evt = (e) ? e:(window.event) ? window.event:null;
920
921    if(evt) {
922       var key = (evt.charCode) ? evt.charCode :
923          ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
924
925
926       if(key == 37) /* left curosr */ {
927          if(document.getElementById('prev_link')) {
928             var prev_link = document.getElementById('prev_link').href;
929             window.location.href = prev_link;
930          }
931          return;
932       }
933       if(key == 38) /* up cursor */ {
934       }
935       if(key == 39) /* right curosr */ {
936          if(document.getElementById('next_link')) {
937             var next_link = document.getElementById('next_link').href;
938             window.location.href = next_link;
939          }
940          return;
941       }
942       if(key == 73 && evt.altKey && evt.ctrlKey) /* ctrl+alt+i */ {
943          showPhotoIndex();
944          return;
945       }
946       if(key == 82 && evt.altKey && evt.ctrlKey) /* ctrl+alt+r */ {
947          resetAll();
948          return;
949       }
950    }
951 }
952
953 document.onkeydown=keyDown;
954 if(document.layers) {
955    document.captureEvents(Event.KEYDOWN);
956 }
957
958 // will be reseted by first viewing photo-index
959 var startup = 1;
960 // calendar specific
961 var calendar_shown = 0;
962 var calendar_mode = '';
963 // auto-browsing & sliding
964 var autobrowse = 0;
965 var sliding = 0;
966 var sliding_paused = 0;
967 var sliding_time = 3;
968 // zooming
969 var origHeight;
970 var origWidth;
971 // position of the last shown photo in photo-index
972 var photo_details_pos;
973 var web_path;
974 var rate_search = new Array();