d54f8b5403519a997419d21f2fab0a236d9dbd30
[phpfspot.git] / phpfspot.js
1 function showImage(id)
2 {
3    var image_div = document.getElementById("content");
4    image_div.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showphoto&id=' + id));
5 }
6
7 function showCredits()
8 {
9    var credits = document.getElementById("content");
10    credits.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=showcredits'));
11 }
12
13 function Tags(mode, id)
14 {
15    if(mode == "add") {
16       // add the tag to users session
17       HTML_AJAX.grab(encodeURI('rpc.php?action=addtag&id=' + id));
18    }
19    else if(mode == "del") {
20       // del the tag from users session
21       HTML_AJAX.grab(encodeURI('rpc.php?action=deltag&id=' + id));
22    }
23    else if(mode == "condition") {
24       setCheckedValue(id, id.value);
25       HTML_AJAX.grab(encodeURI('rpc.php?action=tagcondition&mode=' + id.value));
26    }
27
28    refreshAvailableTags();
29    refreshSelectedTags();
30    refreshPhotoIndex();
31
32 }
33
34 function refreshAvailableTags()
35 {
36    // update available tags
37    var avail_tags = document.getElementById('available_tags');
38    avail_tags.innerHTML = "Loading...";
39    avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
40 }
41
42 function refreshSelectedTags()
43 {
44    // update selected tags
45    var selected_tags = document.getElementById("selected_tags");
46    selected_tags.innerHTML = "Loading...";
47    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
48
49    // if no tags are currently selected, return false from here
50    if(selected_tags.innerHTML == "")
51       return false;
52
53    return true;
54
55 }
56
57 function showPhotoIndex(begin_with)
58 {
59    if(begin_with == undefined)
60       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
61    else
62       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
63 }
64
65 // if photo index is currently shown, refresh it
66 function refreshPhotoIndex()
67 {
68    if(document.getElementById("matrix") != undefined || startup == 1) {
69       showPhotoIndex();
70       startup = 0;
71    }
72 }
73
74 function click(object)
75 {
76    if(object.blur)
77       object.blur();
78
79 }
80
81 // set the radio button with the given value as being checked
82 // do nothing if there are no radio buttons
83 // if the given value does not exist, all the radio buttons
84 // are reset to unchecked
85 function setCheckedValue(condition, value) {
86
87    var count = condition.length;
88    if(count == undefined) {
89       condition.checked = (condition.value == value.toString());
90       return;
91    }
92    for(var i = 0; i < count; i++) {
93       condition[i].checked = false;
94       if(condition[i].value == value.toString()) {
95          condition[i].checked = true;
96       }
97    }
98 }
99
100 function startTagSearch(searchfor)
101 {
102    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
103    refreshAvailableTags();
104    refreshSelectedTags();
105    showPhotoIndex();
106 }
107
108 function startDateSearch()
109 {
110    from_year = document.getElementById('fromyear').value;
111    from_month = document.getElementById('frommonth').value;
112    from_day = document.getElementById('fromday').value;
113    from = from_year +"-"+ from_month +"-"+ from_day;
114    to_year = document.getElementById('toyear').value;
115    to_month = document.getElementById('tomonth').value;
116    to_day = document.getElementById('today').value;
117    to = to_year +"-"+ to_month +"-"+ to_day;
118
119    HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
120    
121    clearSearch();
122    refreshAvailableTags();
123    refreshSelectedTags();
124    refreshPhotoIndex();
125    refreshPhotoIndex();
126 }
127
128 function setViewMode(mode)
129 {
130    var exprt = document.getElementById('output');
131    exprt.innerHTML = "Loading...";
132    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
133 }
134
135 function clearSearch()
136 {
137    document.getElementsByName('searchfor')[0].value = '';
138 }
139
140 function AskServerWhatToDo()
141 {
142    return HTML_AJAX.grab(encodeURI('rpc.php?action=what_to_do'));
143 }
144
145 function init_phpfspot()
146 {
147    refreshAvailableTags();
148
149    whattodo = AskServerWhatToDo();
150
151    if(whattodo == 'showpi') {
152       showPhotoIndex();
153    }
154    if(whattodo == 'showpi_tags') {
155       if(refreshSelectedTags()) {
156          showPhotoIndex();
157       }
158    }
159    if(whattodo == 'showpi_date') {
160       showPhotoIndex();
161    }
162    if(whattodo == 'show_photo') {
163       if(photo = getPhotoToShow()) {
164          showImage(photo)
165          refreshSelectedTags();
166       }
167    }
168 }
169
170 function setBackGrdColor(item, color)
171 {
172    if(color == 'mouseover')
173       item.style.backgroundColor='#c6e9ff';
174    if(color == 'mouseout')
175       item.style.backgroundColor='#eeeeee';
176    if(color == 'mouseclick')
177       item.style.backgroundColor='#93A8CA';
178 }
179
180 function getPhotoToShow()
181 {
182    // update selected tags
183    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
184
185    // if no image needs to be shown, return false from here
186    if(photo_to_show == "")
187       return false;
188    
189    return photo_to_show;
190 }
191
192 function showCalendar(date_box, click_obj)
193 {
194    var calendar = document.getElementById('calendar');
195    if(date_box == 'from') {
196       var xpos = document.getElementById('frompic').offsetLeft;
197       var ypos = document.getElementById('frompic').offsetTop;
198       calendar_mode = 'from';
199    }
200    if(date_box == 'to') {
201       var xpos = document.getElementById('topic').offsetLeft;
202       var ypos = document.getElementById('topic').offsetTop;
203       calendar_mode = 'to';
204    }
205    calendar.style.left = xpos + 60 + 'px';
206    calendar.style.top = ypos + 80 + 'px';
207
208    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
209       calendar.style.visibility = 'visible';
210       calendar.innerHTML = "Loading...";
211       calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix'));
212       calendar_shown = 1;
213    }
214    else {
215       calendar.style.visibility = 'hidden';
216       calendar_shown = 0;
217    }
218 }
219
220 function setMonth(year, month, day)
221 {
222    var calendar = document.getElementById('calendar');
223    calendar.innerHTML = "Loading...";
224    calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
225 }
226
227 function setCalendarDate(year, month, day)
228 {
229    document.getElementById(calendar_mode+'year').value = year;
230    document.getElementById(calendar_mode+'month').value = month;
231    document.getElementById(calendar_mode+'day').value = day;
232 }
233
234 function resetAll()
235 {
236    HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
237    clearSearch();
238    refreshAvailableTags();
239    refreshSelectedTags();
240    refreshPhotoIndex();
241 }
242
243 var startup = 1;
244 var calendar_shown = 0;
245 var calendar_mode = '';