Remove simulation of JSON
[pazpar2-moved-to-github.git] / www / iphone / 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                 document.getElementById("log").innerHTML = message;
39 }
40
41
42 function search(message) {
43         document.search.query.value = message;
44         onFormSubmitEventHandler();
45         return false;
46 }
47
48 function loaded() {
49         callback.init();
50 }
51
52 function onFormSubmit() {
53         return search(document.search.query.value);
54 }