File indexing completed on 2024-05-19 05:01:19

0001 function labelsForIdsInFrame(frm) {
0002   var labelList = frm.document.getElementsByTagName("label");
0003   var res = new Object;
0004   for (var i = 0; i < labelList.length; i++) {
0005     var l = labelList[i];
0006     if (l.htmlFor != '') {
0007       var obj = frm.document.getElementById(l.htmlFor);
0008       if (obj) {
0009         res[obj.id] = l.textContent;
0010       }
0011     }
0012   }
0013   return res;
0014 }
0015 
0016 function findFormsRecursive(wnd, existingList, path, findLabels){
0017       findFormsInFrame(wnd, existingList, path, findLabels);
0018       var frameList = wnd.frames;
0019       for(var i = 0; i < frameList.length; ++i) {
0020           var newPath = path.concat(i);
0021           findFormsRecursive(frameList[i], existingList, newPath, findLabels);
0022       }
0023   }
0024 
0025   function findFormsInFrame(frm, existingList, path, findLabels){
0026       var url = frm.location;
0027       var formList;
0028       try{ formList = frm.document.forms; }
0029       catch(e){
0030         return;
0031       }
0032       var labelsForIds;
0033       if (findLabels) {
0034         labelsForIds = labelsForIdsInFrame(frm);
0035       }
0036       if (formList.length > 0) {
0037           for (var i = 0; i < formList.length; ++i) {
0038               var inputList = formList[i].elements;
0039               if (inputList.length < 1) {
0040                   continue;
0041               }
0042               var formObject = new Object;
0043               formObject.url = url;
0044               formObject.name = formList[i].name;
0045               if (typeof(formObject.name) != 'string') {
0046                   formObject.name = String(formList[i].id);
0047               }
0048               formObject.index = String(i);
0049               formObject.elements = new Array;
0050               for (var j = 0; j < inputList.length; ++j) {
0051                   var element = objectFromElement(inputList[j]);
0052                   if (element == null) {
0053                     continue;
0054                   }
0055                   if (findLabels && element.id) {
0056                     var l = labelsForIds[element.id];
0057                     if (l != '') {
0058                       element.label = l;
0059                     }
0060                   }
0061                   formObject.elements.push(element);
0062               }
0063               if (formObject.elements.length > 0) {
0064                   formObject.framePath = path;
0065                   existingList.push(JSON.stringify(formObject));
0066               }
0067           }
0068       }
0069   }
0070 
0071 function findFormsInWindow(findLabels){
0072     var forms = new Array;
0073     findFormsRecursive(window, forms, [], findLabels);
0074     return forms;
0075 }
0076 
0077 //Creates an object with information about the given input element
0078 //
0079 // This function returns null in the following cases:
0080 // - the element is not an input element
0081 // - the element has neither a name nor an id
0082 //
0083 //The returned object has the following entries:
0084 //- id: the id of the element
0085 //- name: the name of the element or its id if the name is undefined
0086 //- type: the type of the input element
0087 //- value: the value of the element
0088 //- readonly: whether the element is read-only or not
0089 //- disabled: whether the element is disabled or not
0090 //- autocompleteAllowed: whether autocomplete is allowed for the element
0091 function objectFromElement(el) {
0092     if (el.type != 'text' && el.type != 'email' && el.type != 'password') {
0093       return null;
0094     }
0095     var obj = new Object;
0096     obj.id = String(el.id);
0097     obj.name = el.name;
0098     if (typeof(obj.name) != 'string' || obj.name.length == 0) {
0099         obj.name = obj.id;
0100     }
0101     if (obj.name.length == 0) {
0102         return null;
0103     }
0104     obj.type = el.type;
0105     obj.value = String(el.value);
0106     obj.readonly = Boolean(el.readOnly);
0107     obj.disabled = Boolean(el.disabled);
0108     obj.autocompleteAllowed = el.autocomplete != 'off';
0109     return obj;
0110 }
0111 
0112 //Fills a single element in a form
0113 //Arguments:
0114 //path: the frame path
0115 //form: the name of the form the element to fill belongs to
0116 //element: the name of the element to fill
0117 //value: the value to insert
0118 function fillFormElement(path, form, element, value){
0119     var frm = window;
0120     if (path === "") {
0121       path = [];
0122     } else {
0123       path = [path];
0124     }
0125     for(var i=0; i < path.length; ++i) frm=frm.frames[i];
0126     if (frm.document.forms[form] && frm.document.forms[form].elements[element]){
0127         frm.document.forms[form].elements[element].value=value;
0128     }
0129 }