2132ea511617c52842823f0609e511840e598dc9
[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 == "reset") {
24       HTML_AJAX.grab(encodeURI('rpc.php?action=reset'));
25       clearSearch();
26    }
27    else if(mode == "condition") {
28       setCheckedValue(id, id.value);
29       HTML_AJAX.grab(encodeURI('rpc.php?action=tagcondition&mode=' + id.value));
30    }
31    
32    refreshAvailableTags();
33    refreshSelectedTags();
34    refreshPhotoIndex();
35
36 }
37
38 function refreshAvailableTags()
39 {
40    // update available tags
41    var avail_tags = document.getElementById('available_tags');
42    avail_tags.innerHTML = "Loading...";
43    avail_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_available_tags'));
44 }
45
46 function refreshSelectedTags()
47 {
48    // update selected tags
49    var selected_tags = document.getElementById("selected_tags");
50    selected_tags.innerHTML = "Loading...";
51    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
52
53    // if no tags are currently selected, return false from here
54    if(selected_tags.innerHTML == "")
55       return false;
56    
57    return true;
58
59 }
60
61 function showPhotoIndex(begin_with)
62 {
63    if(begin_with == undefined)
64       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
65    else
66       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
67 }
68
69 function showBubbleDetails(object, id, direction)
70 {
71    HTML_AJAX.replace(object, encodeURI('rpc.php?action=showbubbledetails&id=' + id + '&direction=" + direction'));
72 }
73
74 // if photo index is currently shown, refresh it
75 function refreshPhotoIndex()
76 {
77    if(document.getElementById("matrix") != undefined || startup == 1) {
78       showPhotoIndex();
79       startup = 0;
80    }
81 }
82
83 function click(object)
84 {
85    if(object.blur)
86       object.blur();
87
88 }
89
90 // set the radio button with the given value as being checked
91 // do nothing if there are no radio buttons
92 // if the given value does not exist, all the radio buttons
93 // are reset to unchecked
94 function setCheckedValue(condition, value) {
95
96    var count = condition.length;
97    if(count == undefined) {
98       condition.checked = (condition.value == value.toString());
99       return;
100    }
101    for(var i = 0; i < count; i++) {
102       condition[i].checked = false;
103       if(condition[i].value == value.toString()) {
104          condition[i].checked = true;
105       }
106    }
107 }
108
109 function startTagSearch(searchfor)
110 {
111    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
112    refreshAvailableTags();
113    refreshSelectedTags();
114    showPhotoIndex();
115
116 }
117
118 function clearSearch()
119 {
120    document.getElementsByName('searchfor')[0].value = '';
121 }
122
123 function init_phpfspot()
124 {
125    refreshAvailableTags();
126
127    if(refreshSelectedTags()) {
128       showPhotoIndex();
129    }
130 }
131
132 function setBackGrdColor(item, color)
133 {
134    if(color == 'mouseover')
135       item.style.backgroundColor='#c6e9ff';
136    if(color == 'mouseout')
137       item.style.backgroundColor='#eeeeee';
138    if(color == 'mouseclick')
139       item.style.backgroundColor='#93A8CA';
140 }
141
142 var startup = 1;
143