2d7e780c4cf7b4a63400d2dceb7c03a0a75191ae
[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
54 function showPhotoIndex(begin_with)
55 {
56    if(begin_with == undefined)
57       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
58    else
59       HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
60 }
61
62 function showBubbleDetails(object, id, direction)
63 {
64    HTML_AJAX.replace(object, encodeURI('rpc.php?action=showbubbledetails&id=' + id + '&direction=" + direction'));
65 }
66
67 // if photo index is currently shown, refresh it
68 function refreshPhotoIndex()
69 {
70    if(document.getElementById("matrix") != undefined || startup == 1) {
71       showPhotoIndex();
72       startup = 0;
73    }
74 }
75
76 function click(object)
77 {
78    if(object.blur)
79       object.blur();
80
81 }
82
83 // set the radio button with the given value as being checked
84 // do nothing if there are no radio buttons
85 // if the given value does not exist, all the radio buttons
86 // are reset to unchecked
87 function setCheckedValue(condition, value) {
88
89    var count = condition.length;
90    if(count == undefined) {
91       condition.checked = (condition.value == value.toString());
92       return;
93    }
94    for(var i = 0; i < count; i++) {
95       condition[i].checked = false;
96       if(condition[i].value == value.toString()) {
97          condition[i].checked = true;
98       }
99    }
100 }
101
102 function startTagSearch(searchfor)
103 {
104    HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
105    refreshAvailableTags();
106    refreshSelectedTags();
107    showPhotoIndex();
108
109 }
110
111 function clearSearch()
112 {
113    document.getElementsByName('searchfor')[0].value = '';
114 }
115
116 var startup = 1;