5 * Chris Toshok (toshok@ximian.com)
6 * Lluis Sanchez Gual (lluis@novell.com)
7 * Igor Zelmanovich (igorz@mainsoft.com)
9 * (c) 2005 Novell, Inc. (http://www.novell.com)
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * a copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
14 * without limitation the rights to use, copy, modify, merge, publish,
15 * distribute, sublicense, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 function WebForm_AutoFocus (id)
34 var x = WebForm_GetElementById (id);
36 if (x && (!WebForm_CanFocus(x))) {
37 x = WebForm_FindFirstFocusableChild(x);
42 function WebForm_CanFocus(element) {
43 if (!element || !(element.tagName) || element.disabled) {
46 if (element.type && element.type.toLowerCase() == "hidden") {
49 var tagName = element.tagName.toLowerCase();
50 return (tagName == "input" ||
51 tagName == "textarea" ||
52 tagName == "select" ||
53 tagName == "button" ||
57 function WebForm_FindFirstFocusableChild(element) {
58 if (!element || !(element.tagName)) {
61 var tagName = element.tagName.toLowerCase();
62 if (tagName == "undefined") {
65 var children = element.childNodes;
67 for (var i = 0; i < children.length; i++) {
69 if (WebForm_CanFocus(children[i])) {
73 var focused = WebForm_FindFirstFocusableChild(children[i]);
74 if (WebForm_CanFocus(focused)) {
85 function WebForm_ReEnableControls (currForm)
87 if (typeof(currForm.__enabledControlArray) != 'undefined' && currForm.__enabledControlArray != null)
88 __enabledControlArray = currForm.__enabledControlArray;
90 if (typeof(__enabledControlArray) == 'undefined' || __enabledControlArray == null)
93 currForm.__disabledControlArray = new Array();
94 for (var i = 0; i < __enabledControlArray.length; i++) {
95 var c = document.getElementById(__enabledControlArray[i]);
96 if ((typeof(c) != "undefined") && (c != null) && (c.disabled == true)) {
98 currForm.__disabledControlArray[currForm.__disabledControlArray.length] = c;
101 __currForm = currForm
102 setTimeout("WebForm_ReDisableControls (__currForm)", 0);
106 function WebForm_ReDisableControls (currForm)
108 for (var i = 0; i < currForm.__disabledControlArray.length; i++) {
109 currForm.__disabledControlArray[i].disabled = true;
113 // This function is only used in the context of TARGET_J2EE for portlets
114 function PortalWebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm)
117 currForm = WebForm_GetFormFromCtrl (id, currForm);
118 if (url.indexOf ("vmw.action.page=") == 0) {
119 currForm.__NEXTVMWACTIONPAGE.value = url.substring ("vmw.action.page=".length);
120 url = currForm.action;
122 else if (url.indexOf ("vmw.render.page=") == 0)
124 currForm.__NEXTVMWRENDERPAGE.value = url.substring ("vmw.render.page=".length);
129 return WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm);
131 function WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg, currForm)
133 currForm = WebForm_GetFormFromCtrl (id, currForm);
135 if (typeof(SetValidatorContext) == "function")
136 SetValidatorContext (currForm);
138 var validationResult = true;
139 if (pval && typeof(Page_ClientValidate) == "function")
140 validationResult = Page_ClientValidate(vg);
142 if (validationResult && url != null)
143 currForm.action = url;
146 currForm.__doPostBack (id, par);
149 function WebForm_DoCallback (id, arg, callback, ctx, errorCallback, currForm)
151 currForm = WebForm_GetFormFromCtrl (id, currForm);
152 var qs = WebForm_getFormData (currForm) + "__CALLBACKTARGET=" + id + "&__CALLBACKARGUMENT=" + encodeURIComponent(arg);
153 if (currForm["__EVENTVALIDATION"]) qs += "&__EVENTVALIDATION=" + encodeURIComponent(currForm["__EVENTVALIDATION"].value);
154 WebForm_httpPost (currForm.serverURL || document.URL, qs, function (httpPost) { WebForm_ClientCallback (httpPost, ctx, callback, errorCallback, currForm); });
157 function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback, currForm)
159 var doc = httpPost.responseText;
160 if (doc.charAt(0) == "e") {
161 if ((typeof(errorCallback) != "undefined") && (errorCallback != null))
162 errorCallback(doc.substring(1), ctx);
164 var separatorIndex = doc.indexOf("|");
165 if (separatorIndex != -1) {
166 var validationFieldLength = parseInt(doc.substring(0, separatorIndex));
167 if (!isNaN(validationFieldLength)) {
168 var validationField = doc.substring(separatorIndex + 1, separatorIndex + validationFieldLength + 1);
169 if (validationField != "") {
170 var validationFieldElement = currForm["__EVENTVALIDATION"];
171 if (!validationFieldElement) {
172 validationFieldElement = document.createElement("INPUT");
173 validationFieldElement.type = "hidden";
174 validationFieldElement.name = "__EVENTVALIDATION";
175 currForm.appendChild(validationFieldElement);
177 validationFieldElement.value = validationField;
179 if ((typeof(callback) != "undefined") && (callback != null))
180 callback (doc.substring(separatorIndex + validationFieldLength + 1), ctx);
183 if ((typeof(callback) != "undefined") && (callback != null))
189 function WebForm_getFormData (currForm)
192 var len = currForm.elements.length;
193 for (n=0; n<len; n++) {
194 var elem = currForm.elements [n];
195 var tagName = elem.tagName.toLowerCase();
196 if (tagName == "input") {
197 var type = elem.type;
198 if ((type == "text" || type == "hidden" || type == "password" ||
199 ((type == "checkbox" || type == "radio") && elem.checked)) &&
200 (elem.id != "__EVENTVALIDATION")) {
201 qs += elem.name + "=" + encodeURIComponent (elem.value) + "&";
204 else if (tagName == "select") {
205 var selectCount = elem.options.length;
206 for (var j = 0; j < selectCount; j++) {
207 var selectChild = elem.options[j];
208 if (selectChild.selected == true) {
209 qs += elem.name + "=" + encodeURIComponent (elem.value) + "&";
213 else if (tagName == "textarea") {
214 qs += elem.name + "=" + encodeURIComponent (elem.value) + "&";
221 function WebForm_httpPost (url, data, callback)
225 if (typeof XMLHttpRequest != "undefined") {
226 httpPost = new XMLHttpRequest ();
229 httpPost = new ActiveXObject (axName);
231 var clsnames = new Array ("MSXML", "MSXML2", "MSXML3", "Microsoft");
232 for (n = 0; n < clsnames.length && httpPost == null; n++) {
233 axName = clsnames [n] + ".XMLHTTP";
235 httpPost = new ActiveXObject (axName);
236 } catch (e) { axName = null; }
238 if (httpPost == null)
239 throw new Error ("XMLHTTP object could not be created.");
242 httpPost.onreadystatechange = function () { if (httpPost.readyState == 4) callback (httpPost); };
244 httpPost.open ("POST", url, true); // async
245 httpPost.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
246 setTimeout (function () { httpPost.send (data); }, 10);
249 function WebForm_GetFormFromCtrl (id, currForm)
254 // We need to translate the id from ASPX UniqueID to its ClientID.
255 var ctrl = WebForm_GetElementById (id.replace(/\$/g, "_"));
256 while (ctrl != null) {
259 ctrl = ctrl.parentNode;
264 function WebForm_GetElementById (id)
266 return document.getElementById ? document.getElementById (id) :
267 document.all ? document.all [id] :
271 function WebForm_FireDefaultButton(event, target)
273 if (event.keyCode != 13) {
276 if(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")) {
279 var defaultButton = WebForm_GetElementById(target);
280 if (defaultButton && typeof(defaultButton.click) != "undefined") {
281 defaultButton.click();
282 event.cancelBubble = true;
288 function WebForm_SaveScrollPositionSubmit() {
289 this.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX();
290 this.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY();
291 if ((typeof(this.oldSubmit) != "undefined") && (this.oldSubmit != null)) {
292 return this.oldSubmit();
297 function WebForm_SaveScrollPositionOnSubmit() {
298 this.elements['__SCROLLPOSITIONX'].value = WebForm_GetScrollX();
299 this.elements['__SCROLLPOSITIONY'].value = WebForm_GetScrollY();
300 if ((typeof(this.oldOnSubmit) != "undefined") && (this.oldOnSubmit != null)) {
301 return this.oldOnSubmit();
306 function WebForm_RestoreScrollPosition(currForm) {
307 currForm = currForm || theForm;
308 var ScrollX = currForm.elements['__SCROLLPOSITIONX'].value;
309 var ScrollY = currForm.elements['__SCROLLPOSITIONY'].value;
310 if (ScrollX != "" || ScrollY != "")
311 window.scrollTo(ScrollX, ScrollY);
312 if ((typeof(this.oldOnLoad) != "undefined") && (this.oldOnLoad != null)) {
313 return this.oldOnLoad();
318 function WebForm_GetScrollX() {
319 if (window.pageXOffset) {
320 return window.pageXOffset;
322 else if (document.documentElement && document.documentElement.scrollLeft) {
323 return document.documentElement.scrollLeft;
325 else if (document.body) {
326 return document.body.scrollLeft;
331 function WebForm_GetScrollY() {
332 if (window.pageYOffset) {
333 return window.pageYOffset;
335 else if (document.documentElement && document.documentElement.scrollTop) {
336 return document.documentElement.scrollTop;
338 else if (document.body) {
339 return document.body.scrollTop;