blob: 0739c71bd1224497056db6dc9f5a7229ec85f46e [file] [log] [blame]
Felix Meschbergerca29a962008-05-16 11:59:32 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19/* shuts down server after [num] seconds */
20function shutdown(num, formname, elemid) {
21 var elem;
22 var canCount = document.getElementById;
23 if (canCount) {
24 elem = document.getElementById(elemid);
25 canCount = (typeof(elem) != "undefined" && typeof(elem.innerHTML) != "undefined");
26 }
27 var secs=" second";
28 var ellipsis="...";
29 if (num > 0) {
30 if (num != 1) {
31 secs+="s";
32 }
33 if (canCount) {
34 elem.innerHTML=num+secs+ellipsis;
35 }
36 setTimeout('shutdown('+(--num)+', "'+formname+'", "'+elemid+'")',1000);
37 } else {
38 document[formname].submit();
39 }
40}
41
42/* aborts server shutdown and redirects to [target] */
43function abort(target) {
44 top.location.href=target;
45}
46
47/* checks if values of [pass1] and [pass2] match */
48function checkPasswd(form, pass0, pass1, pass2) {
49 var check = false;
50 check = (form[pass0].value != form[pass1].value);
51 if (!check) {
52 alert("Old and new password must be different.");
53 form[pass1].value="";
54 form[pass2].value="";
55 form[pass1].focus();
56 }
57 check = (form[pass1].value == form[pass2].value);
58 if (!check) {
59 alert("Passwords did not match. Please type again.");
60 form[pass1].value="";
61 form[pass2].value="";
62 form[pass1].focus();
63 }
64 return check;
65}
66
67/* displays a date in the user's local timezone */
68function localDate(time) {
69 var date = time ? new Date(time) : new Date();
70 document.write(date.toLocaleString());
71}
72
73/* shows the about screen */
74function showAbout() {
75// Temporarily disabled, as thee is no about.html page (fmeschbe, 20070330)
76// var arguments = ABOUT_VERSION+";"+ABOUT_JVERSION+";"+ABOUT_MEM+";"+ABOUT_USED+";"+ABOUT_FREE;
77// if (window.showModalDialog) {
78// window.showModalDialog("about.html", arguments, "help: no; status: no; resizable: no; center: yes; scroll: no");
79// } else {
80// aboutWin = window.open("about.html?a="+arguments, "about", "width=500,height=420,modal,status=no,toolbar=no,menubar=no,personalbar=no");
81// }
82}
83
84//-----------------------------------------------------------------------------
85// Ajax Support
86
87// request object, do not access directly, use getXmlHttp instead
88var xmlhttp = null;
89function getXmlHttp() {
90 if (xmlhttp) {
91 return xmlhttp;
92 }
93
94 if (window.XMLHttpRequest) {
95 xmlhttp = new XMLHttpRequest();
96 } else if (window.ActiveXObject) {
97 try {
98 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
99 } catch (ex) {
100 try {
101 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
102 } catch (ex) {
103 }
104 }
105 }
106
107 return xmlhttp;
108}
109
110function sendRequest(/* String */ method, /* url */ url, /* function */ callback) {
111 var xmlhttp = getXmlHttp();
112 if (!xmlhttp) {
113 return;
114 }
115
116 if (xmlhttp.readyState < 4) {
117 xmlhttp.abort();
118 }
119
120 if (!method) {
121 method = 'GET';
122 }
123
124 if (!url) {
125 url = document.location;
126 } else if (url.charAt(0) == '?') {
127 url = document.location + url;
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000128 }
Felix Meschbergerca29a962008-05-16 11:59:32 +0000129
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000130 priv_callback = callback;
131
Felix Meschbergerca29a962008-05-16 11:59:32 +0000132 xmlhttp.open(method, url);
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000133
134 // set If-Modified-Since way back in the past to prevent
135 // using any content from the cache
136 xmlhttp.setRequestHeader("If-Modified-Since", new Date(0));
137
Felix Meschbergerca29a962008-05-16 11:59:32 +0000138 xmlhttp.onreadystatechange = handleResult;
Felix Meschbergerca29a962008-05-16 11:59:32 +0000139 xmlhttp.send(null);
140
141}
142
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000143var priv_callback = null;
144
Felix Meschbergerca29a962008-05-16 11:59:32 +0000145function handleResult() {
146 var xmlhttp = getXmlHttp();
147 if (!xmlhttp || xmlhttp.readyState != 4) {
148 return;
149 }
150
151 var result = xmlhttp.responseText;
152 if (!result) {
153 return;
154 }
155
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000156 var theCallBack = priv_callback;
157 priv_callback = null;
158
159 if (theCallBack) {
160 try
161 {
162 var obj = eval('(' + result + ')');
163 theCallBack(obj);
164 }
165 catch (e)
166 {
167 // error evaluating response, don't care ...
168 }
Felix Meschbergerca29a962008-05-16 11:59:32 +0000169 }
170}