+/**********************************************************************
+ Copyright (C) FrontAccounting, LLC.
+ Released under the terms of the GNU General Public License, GPL,
+ as published by the Free Software Foundation, either version 3
+ of the License, or (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+var _focus;
+var _hotkeys = {
+ 'alt': false, // whether is the Alt key pressed
+ 'list': false, // list of all elements with hotkey used recently
+ 'focus': -1 // currently selected list element
+};
+
+function save_focus(e) {
+ _focus = e.name||e.id;
+ var h = document.getElementById('hints');
+ if (h) {
+ h.style.display = e.title && e.title.length ? 'inline' : 'none';
+ h.innerHTML = e.title ? e.title : '';
+ }
+}
+
+function _expand(tabobj) {
+
+ var ul = tabobj.parentNode.parentNode;
+ var alltabs=ul.getElementsByTagName("button");
+ var frm = tabobj.form;
+
+ if (ul.getAttribute("rel")){
+ for (var i=0; i<alltabs.length; i++){
+ alltabs[i].className = "ajaxbutton" //deselect all tabs
+ }
+ tabobj.className = "current";
+ JsHttpRequest.request(tabobj)
+ }
+}
+
+//interface for selecting a tab (plus expand corresponding content)
+function expandtab(tabcontentid, tabnumber) {
+ var tabs = document.getElementById(tabcontentid);
+ _expand(tabs.getElementsByTagName("input")[tabnumber]);
+}
+
+function _set_combo_input(e) {
+ e.setAttribute('_last', e.value);
+ e.onblur=function() {
+ var but_name = this.name.substring(0, this.name.length-4)+'button';
+ var button = document.getElementsByName(but_name)[0];
+ var select = document.getElementsByName(this.getAttribute('rel'))[0];
+ save_focus(select);
+// submit request if there is submit_on_change option set and
+// search field has changed.
+
+ if (button && (this.value != this.getAttribute('_last'))) {
+ JsHttpRequest.request(button);
+ } else if(this.className=='combo2') {
+ this.style.display = 'none';
+ select.style.display = 'inline';
+ setFocus(select);
+ }
+ return false;
+ };
+ e.onkeyup = function(ev) {
+ var select = document.getElementsByName(this.getAttribute('rel'))[0];
+ if(select && select.selectedIndex>=0) {
+ var len = select.length;
+ var byid = this.className=='combo';
+ var ac = this.value.toUpperCase();
+ select.options[select.selectedIndex].selected = false;
+ for (i = 0; i < len; i++) {
+ var txt = byid ? select.options[i].value : select.options[i].text;
+ if (txt.toUpperCase().indexOf(ac) >= 0) {
+ select.options[i].selected = true;
+ break;
+ }
+ }
+ }
+ };
+ e.onkeydown = function(ev) {
+ ev = ev||window.event;
+ key = ev.keyCode||ev.which;
+ if(key == 13) {
+ this.blur();
+ return false;
+ }
+ }
+}
+
+function _update_box(s) {
+ var byid = s.className=='combo';
+ var rel = s.getAttribute('rel');
+ var box = document.getElementsByName(rel)[0];
+ if(box && s.selectedIndex>=0) {
+ var opt = s.options[s.selectedIndex];
+ if(box) {
+ var old = box.value;
+ box.value = byid ? opt.value : opt.text;
+ box.setAttribute('_last', box.value);
+ return old != box.value
+ }
+ }
+}
+
+function _set_combo_select(e) {
+ // When combo position is changed via js (eg from searchbox)
+ // no onchange event is generated. To ensure proper change
+ // signaling we must track selectedIndex in onblur handler.
+ e.setAttribute('_last', e.selectedIndex);
+ e.onblur = function() {
+ var box = document.getElementsByName(this.getAttribute('rel'))[0];
+// if(this.className=='combo')
+// _update_box(this);
+ if ((this.selectedIndex != this.getAttribute('_last'))
+ ||(this.className=='combo' && _update_box(this))
+ )
+ this.onchange();
+ }
+ e.onchange = function() {
+ var s = this;
+ this.setAttribute('_last', this.selectedIndex);
+ if(s.className=='combo')
+ _update_box(s);
+ if(s.selectedIndex>=0) {
+ var sname = '_'+s.name+'_update';
+ var update = document.getElementsByName(sname)[0];
+ if(update) {
+ JsHttpRequest.request(update);
+ }
+ }
+ return true;
+ }
+ e.onkeydown = function(event) {
+ event = event||window.event;
+ key = event.keyCode||event.which;
+ var box = document.getElementsByName(this.getAttribute('rel'))[0];
+ if (box && key == 32 && this.className == 'combo2') {
+ this.style.display = 'none';
+ box.style.display = 'inline';
+ box.value='';
+ setFocus(box);
+ return false;
+ }
+ }
+}
+
+var _w;
+
+function callEditor(key) {
+ var el = document.getElementsByName(editors[key][1])[0];
+ if(_w) _w.close(); // this is really necessary to have window on top in FF2 :/
+ _w = open(editors[key][0]+el.value+'&popup=1',
+ "edit","Scrollbars=0,resizable=0,width=800,height=600");
+ if (_w.opener == null)
+ _w.opener = self;
+ editors._call = key; // store call point for passBack
+ _w.focus();
+}
+
+function passBack(value) {
+ var o = opener;
+ if(value != false) {
+ var back = o.editors[o.editors._call]; // form input bindings
+ var to = o.document.getElementsByName(back[1])[0];
+ if (to) {
+ if (to[0] != undefined)
+ to[0].value = value; // ugly hack to set selector to any value
+ to.value = value;
+ // update page after item selection
+ o.JsHttpRequest.request('_'+to.name+'_update', to.form);
+ o.setFocus(to.name);
+ }
+ }
+ close();
+}
+