Updates to pz:authentication documentation
[pazpar2-moved-to-github.git] / www / mobile / iphone.js
1 var count = 0;
2 var termlist = {};
3 var inApp = false;
4
5 var callback = {};
6
7 callback.init = function() {
8         if (!inApp) {
9                 callback.type = 'browser';
10         } else {
11                 callback.type = 'iphone';
12         }
13 };
14
15 String.prototype.replaceAll = function(stringToFind,stringToReplace) {
16                 var temp = this;
17                 var index = temp.indexOf(stringToFind);
18                 while(index != -1){
19                         temp = temp.replace(stringToFind,stringToReplace);
20                         index = temp.indexOf(stringToFind);
21                 }
22                 return temp;
23     }
24
25 callback.send = function() 
26 {
27         var args = [].splice.call(arguments,0);
28         for (var i = 0; i < args.length; i++) {
29                 if (args[i])
30                         args[i] = args[i].replaceAll(':','_'); 
31                 else 
32                         alert("args was null: " + i);
33         }
34         var message = "myapp:" + args.join(":");
35         if (this.type == 'iphone')
36                 document.location = message;
37         else {
38             // Debug communication with Web View
39             // document.getElementById("log").innerHTML = message;
40         }
41 }
42
43
44 function search(message) {
45         document.search.query.value = message;
46         onFormSubmitEventHandler();
47         return false;
48 }
49
50 function loaded() {
51         callback.init();
52 }
53
54 function onFormSubmit() {
55         return search(document.search.query.value);
56 }