/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
1
		/*--------------------------------------------------------------------------------
2
			 AJAX Queue
3
		----------------------------------------------------------------------------------*/		
4
5
		var AJAXQueue = new Array;
6
		var AJAXServiceRunning=false;
7
8
		var httpAjax = false;
9
10
		/*--------------------------------------------------------------------------------
11
				AjaxService
12
				
13
				This is the only interface to the AJAX wrapper. This makes the ajax service 
14
				browser agnostic and provides a single interface for all of the services.
15
				
16
				Each service uses a different url and a different parameter layout.
17
								
18
		----------------------------------------------------------------------------------*/
19
20
		function AjaxService(servicename,serviceparam){
21
				
22
				AJAXQueue.push(servicename);
23
				AJAXQueue.push(serviceparam);
24
25
				if(!AJAXServiceRunning){
26
						AJAXServiceRunning=true;
27
						var Aparam=AJAXQueue.pop();
28
						var Aservice=AJAXQueue.pop();
29
						AjaxServiceExec(Aservice,Aparam);
30
				}				
31
		}
32
33
		/*--------------------------------------------------------------------------------
34
				AjaxService
35
				
36
				This is the only interface to the AJAX wrapper. This makes the ajax service 
37
				browser agnostic and provides a single interface for all of the services.
38
				
39
				Each service uses a different url and a different parameter layout.
40
								
41
		----------------------------------------------------------------------------------*/
42
43
		function AjaxServiceExec(servicename,serviceparam){
44
45
			// Parameters are set, initiate AJAX engine
46
		  if (window.XMLHttpRequest) {
47
		  	httpAjax = new XMLHttpRequest();
48
		    if (httpAjax.overrideMimeType) {
49
		    	httpAjax.overrideMimeType('text/xml');
50
		    }
51
		  }else if(window.ActiveXObject){
52
				try{
53
					httpAjax = new ActiveXObject("Msxml2.XMLHTTP");
54
						}catch(e){
55
							try{
56
								httpAjax = new ActiveXObject("Microsoft.XMLHTTP");
57
			        }catch(e){
58
								alert("CouldnŽt build an AJAX instance.");
59
			          return false;
60
							}
61
						}
62
				}
63
				
64
				// Send request to Server and initiate callback.
65
				
66
		    try{
67
					httpAjax.onreadystatechange = getPage;
68
		    }catch(e){
69
//					alert("onreadystatechange didnŽt go well!");
70
					return false;
71
				}try{
72
					httpAjax.open('POST', servicename, true);
73
				  httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
74
		    }catch(e){
75
//					alert("CouldnŽt open url.");
76
		      return false;
77
		    }try{
78
						httpAjax.send(serviceparam);				
79
		    }catch(e){
80
//					alert("CouldnŽt send request.");
81
					return false;
82
				}
83
		   
84
			 return true;
85
86
		}
87
88
		/*--------------------------------------------------------------------------------
89
				getPage
90
91
				This is the AJAX callback function. It detects the invoking service and handles
92
				the reply from each service accordingly.				
93
								
94
		----------------------------------------------------------------------------------*/
95
96
	function getPage() {
97
					
98
		if(httpAjax.readyState == 4){
99
100
				str=httpAjax.responseText;
101
102
				if(AJAXQueue.length>0){
103
						var Aparam=AJAXQueue.pop();
104
						var Aservice=AJAXQueue.pop();
105
						AjaxServiceExec(Aservice,Aparam);
106
				}else{
107
						AJAXServiceRunning=false;				
108
				}
109
				
110
				return true;				
111
		}else{
112
	  		// If any other ready state than prepared, do nothing!
113
	  }
114
	}
115
116