Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 1 | /* |
| 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 */ |
| 20 | function 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] */ |
| 43 | function abort(target) { |
| 44 | top.location.href=target; |
| 45 | } |
| 46 | |
| 47 | /* checks if values of [pass1] and [pass2] match */ |
| 48 | function 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 */ |
| 68 | function localDate(time) { |
| 69 | var date = time ? new Date(time) : new Date(); |
| 70 | document.write(date.toLocaleString()); |
| 71 | } |
| 72 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 73 | //----------------------------------------------------------------------------- |
| 74 | // Ajax Support |
| 75 | |
| 76 | // request object, do not access directly, use getXmlHttp instead |
| 77 | var xmlhttp = null; |
| 78 | function getXmlHttp() { |
| 79 | if (xmlhttp) { |
| 80 | return xmlhttp; |
| 81 | } |
| 82 | |
| 83 | if (window.XMLHttpRequest) { |
| 84 | xmlhttp = new XMLHttpRequest(); |
| 85 | } else if (window.ActiveXObject) { |
| 86 | try { |
| 87 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
| 88 | } catch (ex) { |
| 89 | try { |
| 90 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
| 91 | } catch (ex) { |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return xmlhttp; |
| 97 | } |
| 98 | |
| 99 | function sendRequest(/* String */ method, /* url */ url, /* function */ callback) { |
| 100 | var xmlhttp = getXmlHttp(); |
| 101 | if (!xmlhttp) { |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (xmlhttp.readyState < 4) { |
| 106 | xmlhttp.abort(); |
| 107 | } |
| 108 | |
| 109 | if (!method) { |
| 110 | method = 'GET'; |
| 111 | } |
| 112 | |
| 113 | if (!url) { |
| 114 | url = document.location; |
| 115 | } else if (url.charAt(0) == '?') { |
| 116 | url = document.location + url; |
Felix Meschberger | 0704b05 | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 117 | } |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 118 | |
Felix Meschberger | 0704b05 | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 119 | priv_callback = callback; |
| 120 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 121 | xmlhttp.open(method, url); |
Felix Meschberger | 0704b05 | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 122 | |
| 123 | // set If-Modified-Since way back in the past to prevent |
| 124 | // using any content from the cache |
| 125 | xmlhttp.setRequestHeader("If-Modified-Since", new Date(0)); |
| 126 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 127 | xmlhttp.onreadystatechange = handleResult; |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 128 | xmlhttp.send(null); |
| 129 | |
| 130 | } |
| 131 | |
Felix Meschberger | 0704b05 | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 132 | var priv_callback = null; |
| 133 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 134 | function handleResult() { |
| 135 | var xmlhttp = getXmlHttp(); |
| 136 | if (!xmlhttp || xmlhttp.readyState != 4) { |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | var result = xmlhttp.responseText; |
| 141 | if (!result) { |
| 142 | return; |
| 143 | } |
| 144 | |
Felix Meschberger | 0704b05 | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 145 | var theCallBack = priv_callback; |
| 146 | priv_callback = null; |
| 147 | |
| 148 | if (theCallBack) { |
| 149 | try |
| 150 | { |
| 151 | var obj = eval('(' + result + ')'); |
| 152 | theCallBack(obj); |
| 153 | } |
| 154 | catch (e) |
| 155 | { |
| 156 | // error evaluating response, don't care ... |
| 157 | } |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 158 | } |
| 159 | } |