40d676187f0c409f0a9d65940cf44dbea4a23fb8
[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    refreshAvailableTags();
122    refreshSelectedTags();
123    refreshPhotoIndex();
124    refreshPhotoIndex();
125 }
126
127 function setViewMode(mode)
128 {
129    var exprt = document.getElementById('output');
130    exprt.innerHTML = "Loading...";
131    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
132 }
133
134 function clearSearch()
135 {
136    document.getElementsByName('searchfor')[0].value = '';
137 }
138
139 function init_phpfspot()
140 {
141    refreshAvailableTags();
142
143    if(photo = getPhotoToShow()) {
144       showImage(photo)
145       refreshSelectedTags();
146    }
147    else {
148       if(refreshSelectedTags()) {
149          showPhotoIndex();
150       }
151    }
152 }
153
154 function setBackGrdColor(item, color)
155 {
156    if(color == 'mouseover')
157       item.style.backgroundColor='#c6e9ff';
158    if(color == 'mouseout')
159       item.style.backgroundColor='#eeeeee';
160    if(color == 'mouseclick')
161       item.style.backgroundColor='#93A8CA';
162 }
163
164 function getPhotoToShow()
165 {
166    // update selected tags
167    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
168
169    // if no image needs to be shown, return false from here
170    if(photo_to_show == "")
171       return false;
172    
173    return photo_to_show;
174 }
175
176 function showCalendar(date_box, click_obj)
177 {
178    var calendar = document.getElementById('calendar');
179    if(date_box == 'from') {
180       var xpos = document.getElementById('frompic').offsetLeft;
181       var ypos = document.getElementById('frompic').offsetTop;
182       calendar_mode = 'from';
183    }
184    if(date_box == 'to') {
185       var xpos = document.getElementById('topic').offsetLeft;
186       var ypos = document.getElementById('topic').offsetTop;
187       calendar_mode = 'to';
188    }
189    calendar.style.left = xpos + 60 + 'px';
190    calendar.style.top = ypos + 80 + 'px';
191
192    if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') {
193       calendar.style.visibility = 'visible';
194       calendar.innerHTML = "Loading...";
195       calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix'));
196       calendar_shown = 1;
197    }
198    else {
199       calendar.style.visibility = 'hidden';
200       calendar_shown = 0;
201    }
202 }
203
204 function setMonth(year, month, day)
205 {
206    var calendar = document.getElementById('calendar');
207    calendar.innerHTML = "Loading...";
208    calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day));
209 }
210
211 function setCalendarDate(year, month, day)
212 {
213    document.getElementById(calendar_mode+'year').value = year;
214    document.getElementById(calendar_mode+'month').value = month;
215    document.getElementById(calendar_mode+'day').value = day;
216 }
217
218 function resetAll()
219 {
220    HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
221    clearSearch();
222 }
223
224 var startup = 1;
225 var calendar_shown = 0;
226 var calendar_mode = '';