+/*
+ Find closest element in neighbourhood and set focus.
+ dir is arrow keycode.
+*/
+function move_focus(dir, e0, neighbours)
+{
+ var p0 = element_pos(e0);
+ var t;
+ var l=0;
+ for(var i=0; i<neighbours.length; i++) {
+ var e = neighbours[i];
+ var p = element_pos(e);
+ if (p!=null && (e.className=='menu_option' || e.className=='printlink'
+ || e.className == 'repclass_link' || e.className == 'repopts_link')) {
+ if (((dir==40) && (p.y>p0.y)) || (dir==38 && (p.y<p0.y))
+ || ((dir==37) && (p.x<p0.x)) || ((dir==39 && (p.x>p0.x)))) {
+ var l1 = (p.y-p0.y)*(p.y-p0.y)+(p.x-p0.x)*(p.x-p0.x);
+ if ((l1<l) || (l==0)) {
+ l = l1; t = e;
+ }
+ }
+ }
+ }
+ if (t)
+ setFocus(t);
+ return t;
+}
+
+var __isGecko = navigator.userAgent.match(/gecko/i); // i.e. Gecko or KHTML, like Gecko ;)
+//returns the absolute position of some element within document
+function element_pos(e) {
+ var res = new Object();
+ res.x = 0; res.y = 0;
+ if (e !== null) {
+ res.x = e.offsetLeft;
+ res.y = e.offsetTop;
+ var offsetParent = e.offsetParent;
+ var parentNode = e.parentNode;
+
+ while (offsetParent !== null && offsetParent.style.display != 'none') {
+ res.x += offsetParent.offsetLeft;
+ res.y += offsetParent.offsetTop;
+ // the second case is for IE6/7 in some doctypes
+ if (offsetParent != document.body && offsetParent != document.documentElement) {
+ res.x -= offsetParent.scrollLeft;
+ res.y -= offsetParent.scrollTop;
+ }
+ //next lines are necessary to support FireFox problem with offsetParent
+ if (__isGecko) {
+ while (offsetParent != parentNode && parentNode !== null) {
+ res.x -= parentNode.scrollLeft;
+ res.y -= parentNode.scrollTop;
+
+ parentNode = parentNode.parentNode;
+ }
+ }
+ parentNode = offsetParent.parentNode;
+ offsetParent = offsetParent.offsetParent;
+ }
+ }
+ // parentNode has style.display set to none
+ if (parentNode != document.documentElement) return null;
+ return res;
+}
+
+function string_contains(haystack, needle) {
+ var words = haystack.split(' ');
+ return words.indexOf(needle) > -1;
+}