issue41, remove any trace of the javascript bubble
[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 // if photo index is currently shown, refresh it
70 function refreshPhotoIndex()
71 {
72    if(document.getElementById("matrix") != undefined || startup == 1) {
73       showPhotoIndex();
74       startup = 0;
75    }
76 }
77
78 function click(object)
79 {
80    if(object.blur)
81       object.blur();
82
83 }
84
85 // set the radio button with the given value as being checked
86 // do nothing if there are no radio buttons
87 // if the given value does not exist, all the radio buttons
88 // are reset to unchecked
89 function setCheckedValue(condition, value) {
90
91    var count = condition.length;
92    if(count == undefined) {
93       condition.checked = (condition.value == value.toString());
94       return;
95    }
96    for(var i = 0; i < count; i++) {
97       condition[i].checked = false;
98       if(condition[i].value == value.toString()) {
99          condition[i].checked = true;
100       }
101    }
102 }
103
104 function startTagSearch(searchfor)
105 {
106    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
107    refreshAvailableTags();
108    refreshSelectedTags();
109    showPhotoIndex();
110
111 }
112
113 function setViewMode(mode)
114 {
115    var exprt = document.getElementById('output');
116    exprt.innerHTML = "Loading...";
117    exprt.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_export&mode=' + mode));
118 }
119
120 function clearSearch()
121 {
122    document.getElementsByName('searchfor')[0].value = '';
123 }
124
125 function init_phpfspot()
126 {
127    refreshAvailableTags();
128
129    if(photo = getPhotoToShow()) {
130       showImage(photo)
131       refreshSelectedTags();
132    }
133    else {
134       if(refreshSelectedTags()) {
135          showPhotoIndex();
136       }
137    }
138 }
139
140 function setBackGrdColor(item, color)
141 {
142    if(color == 'mouseover')
143       item.style.backgroundColor='#c6e9ff';
144    if(color == 'mouseout')
145       item.style.backgroundColor='#eeeeee';
146    if(color == 'mouseclick')
147       item.style.backgroundColor='#93A8CA';
148 }
149
150 function getPhotoToShow()
151 {
152    // update selected tags
153    var photo_to_show = HTML_AJAX.grab(encodeURI('rpc.php?action=get_photo_to_show'));
154
155    // if no image needs to be shown, return false from here
156    if(photo_to_show == "")
157       return false;
158    
159    return photo_to_show;
160 }
161
162
163
164 var startup = 1;
165