5 * Chris Toshok (toshok@ximian.com)
6 * Lluis Sanchez Gual (lluis@novell.com)
8 * (c) 2005 Novell, Inc. (http://www.novell.com)
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 function WebForm_AutoFocus (id)
33 var x = WebForm_GetElementById (id);
35 if (x && (!WebForm_CanFocus(x))) {
36 x = WebForm_FindFirstFocusableChild(x);
41 function WebForm_CanFocus(element) {
42 if (!element || !(element.tagName) || element.disabled) {
45 if (element.type && element.type.toLowerCase() == "hidden") {
48 var tagName = element.tagName.toLowerCase();
49 return (tagName == "input" ||
50 tagName == "textarea" ||
51 tagName == "select" ||
52 tagName == "button" ||
56 function WebForm_FindFirstFocusableChild(element) {
57 if (!element || !(element.tagName)) {
60 var tagName = element.tagName.toLowerCase();
61 if (tagName == "undefined") {
64 var children = element.childNodes;
66 for (var i = 0; i < children.length; i++) {
68 if (WebForm_CanFocus(children[i])) {
72 var focused = WebForm_FindFirstFocusableChild(children[i]);
73 if (WebForm_CanFocus(focused)) {
84 function wasControlEnabled (id)
86 if (typeof (__enabledControlArray) == 'undefined')
89 for (var i = 0; i < __enabledControlArray.length; i ++) {
90 if (id == __enabledControlArray[i])
97 function WebForm_ReEnableControls (currForm)
99 currForm = currForm || theForm;
100 if (typeof (currForm) == 'undefined')
103 for (var i = 0; i < currForm.childNodes.length; i ++) {
104 var node = currForm.childNodes[i];
105 if (node.disabled && wasControlEnabled (node.id))
106 node.disabled = false;
110 function WebForm_DoPostback (ctrl, par, url, apb, pval, tf, csubm, vg)
112 if (pval && typeof(Page_ClientValidate) == "function" && !Page_ClientValidate(vg))
115 var form = WebForm_GetFormFromCtrl (ctrl);
120 __doPostBack (ctrl, par);
123 function WebForm_GetFormFromCtrl (id)
125 // We need to translate the id from ASPX UniqueID to its ClientID.
126 var ctrl = WebForm_GetElementById (id.replace(/:/g, "_"));
127 while (ctrl != null) {
130 ctrl = ctrl.parentNode;
135 function WebForm_GetElementById (id)
137 return document.getElementById ? document.getElementById (id) :
138 document.all ? document.all [id] :
142 function WebForm_FireDefaultButton(event, target)
144 if (event.keyCode != 13) {
147 if(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")) {
150 var defaultButton = WebForm_GetElementById(target);
151 if (defaultButton && typeof(defaultButton.click) != "undefined") {
152 defaultButton.click();
153 event.cancelBubble = true;