function setFormAttribute(form, name, value) {
if (form.mergeAttributes) {
var dummy = document.createElement("form");
dummy[name] = value;
form.mergeAttributes(dummy, false);
} else
form.setAttribute(name, value);
};
function getFormAttribute(form, name) {
var result = null;
if(document.all) {
var attrs = form.attributes;
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (attr.nodeName == name) {
result = attr.nodeValue;
break;
}
}
} else {
result = form.getAttribute(name);
}
return result;
};
function wait(bw) {
document.body.style.cursor = bw != false ? "wait" : "default";
};
function setTab(newTab) {
if(document.readyState && document.readyState != 'complete') {
return;
}
var form = document.forms[0];
form.activeTab.value = newTab;
var rc = form.onsubmit();
if (rc == false) return false;
wait();
form.submit();
var popWindow = !isSelfLocationReplace(form);
if(typeof(document.readyState) == "undefined" && !popWindow) {
document.readyState = "loading";
}
if(!popWindow)
disableControl()
};
function isSelfLocationReplace(form) {
var target = getFormAttribute(form, "target");
return !target || target == "_self"
};
function setURL(newUrl, newForm) {
if(document.readyState && document.readyState != 'complete') {
return;
}
var form = newForm || document.forms[0];
var popWindow = !isSelfLocationReplace(form);
if(newUrl) {
setFormAttribute(form, "action", newUrl);
}
if(!document.readyState && !popWindow) {
document.readyState = "loading";
}
if(!popWindow) {
disableControl();
wait();
}
form.submit()
};
function o$SSz() {
return true;
try {
var s = document.selection.createRange().parentElement().tagName;
return (s == 'INPUT' || s == 'TEXTAREA');
} catch(e){
}
};
function on$2u() {
return true;
};
function onvalidate(){return true}
function disableControl() {
var inputs = document.getElementsByTagName("INPUT");
var len;
for(var i = 0, len = inputs.length; i < len; i++)
if(inputs[i].type == "button")
inputs[i].disabled = true;
var images = document.getElementsByTagName("IMG");
for(var i = 0, len = images.length; i < len; i++)
if(images[i].src.indexOf("1.gif") == -1 && Math.min(images[i].offsetHeight, images[i].offsetWidth) > 10) {
current = images[i];
var j = 0;
while(j++ < 3 && current && current.nodeName != "BODY" && current.nodeName != "HTML" && !current.onclick) {
current = current.parentNode;
}
if(current && current.nodeName != "BODY" && current.nodeName != "HTML" && current.onclick) {
current.onclick = "";
}
}
};
/* keep this code synchronized with js/FrameController.jsp */ function getBodyOffsetHeight() {
var maxHeight;
var body = document.body;
if(false) {
maxHeight = body.offsetHeight;
} else {
maxHeight = 0;
for(var i = 0; i < body.childNodes.length; i++) {
var child = body.childNodes[i];
if(child.nodeName != "#text")
maxHeight = Math.max(maxHeight, child.offsetTop + child.offsetHeight);
}
}
return maxHeight;
};
/* $Id: prefocus.js 96044 2010-02-23 08:16:34Z gof $ */
/**
* In order to minimize user actions to prepare form content editing once after the document is loaded this function
* finds the first focusable element in the form and sets focus to it (We have made an exception to cases when the first
* focusable element is an HTML SELECT one and the browser in use is MS IE which supports mousewheel there. Before
* begin of editing a document impatient customers scrolling the page [say, just to see contents of the form] break the currently
* applied selection to a selected choice field, so in such cases in order the selection from breaking we have to set * focus to the parent block element of the SELECT one so that pressing TAB key would cause to moving focus to the * select element).
*
* @param f the form to use. Optional parameter, if missing the first form of the document is used.
*/
function prefocus(f) {
if(prefocus.disabled) return;
// if a form is not passed we will use the first form of the document
f = f || document.forms[0];
// getting the form elements collection
var items = f.elements;
var res; // element's availability check result as boolean

  for(var i = 0; i < items.length; i++) {
    var item = items[i];
    // check if the element conforms to search conditions for the first editable element
    res = item && (
      item.nodeName == "SELECT" || item.nodeName == "TEXTAREA" ||
               (item.nodeName == "INPUT" && (
                 item.type == "text" ||
                 item.type == "password" ||
                 (item.type == "radio" && item.checked) ||
                 item.type == "checkbox"
               ))

      ) && !item.disabled && item.tabIndex >= 0 && !item.readOnly && !isElementHidden(item);
      
      if(res) {
        // making the exception to the HTML SELECT under IE due to support mousewheel and habit to roll the wheel
        if(document.all && item.nodeName == "SELECT") {

          /**
           * searches for the closest parent block element whose state is currently visible
           * @param initial parent element to begin
           * @return the closest visible and focusable parent element
           */
          function getParentBlockElement(selectElement) {
            var el = selectElement.parentNode; 
            var blockElements = "|TD|TR|TABLE|DIV|BODY|HTML|";
            while(el && (blockElements.indexOf("|" + el.nodeName + "|") == -1 || isElementHidden(el))) {
              el = el.parentNode;
            }
            return el;
          }

          var parentElement = getParentBlockElement(item);
          if(parentElement) { // Generally speaking, the parentElement should be, otherwise it's a strange document structure
// the condition check is here only just in case.
parentElement.focus();
}
} else {
try {
item.focus();
// make a selection if it's an text edit box (when method select() is implemented)
            if(item.select) item.select();
          } catch(ee) {}
        }
        // imspite of being the element focused we need to see the top of the form. I was asked for applying this algorithm
        window.scrollTo(0, 0);
        break;
      }
  }
  if(!res) {
    // let's try to find a navigation button or something like
var types = "|button|image|submit|";
for(var i = 0; i < items.length; i++) {
var item = items[i];
res = item.nodeName == "INPUT" && types.indexOf("|" + item.type + "|") != -1 && !item.disabled && !isElementHidden(item);
if(res) {
item.focus();
break;
}
}
}
// if there's no appropriate element then there's nothing else to do - set focus to the body
if(!res) window.focus();
};
/**
* checks if the element passed is currently invisible
* @param oElem the element whose state we need to detect, not null
* @return boolean whether the element is invisible
*/
function isElementHidden(oElem) {
var cElem = oElem;
var style;
while(cElem && cElem.nodeName != "BODY") {
style = document.defaultView.getComputedStyle(cElem, '');
if(style.visibility == "hidden" || style.display == "none") return true;
cElem = cElem.parentNode;
}
return false;
};
/**
* it supplements uncompatible environment with the method to rerieve currentStyle object that to provide cross-browser usage
*/
if(!document.defaultView) document.defaultView = {};
if(!document.defaultView.getComputedStyle) {
document.defaultView.getComputedStyle = function(elem) {
return elem.currentStyle
}
};
function disableAutoFocus() { prefocus.disabled = true };
try {
window.addEventListener("scroll", disableAutoFocus, false);
} catch(e) {
window.attachEvent("onscroll", disableAutoFocus);
}

