var nHideComboBox = ''; var nFilterComboBox = ''; var aComboBoxStdHandlers=new Array(); var aComboBoxes=new Array(); var oComboBoxFrame = null; function comboBoxRegister(cName, cUrl, eUrlParams) { aComboBoxes[cName] = { url: cUrl, urlParams: eUrlParams }; if (!oComboBoxFrame) { oComboBoxFrame = iframe('BachComboBoxFrame'); oComboBoxFrame.src = '/onyma/main/null.htms'; } } function comboBoxDraw(cID, cValue, cURL, cUrlParams, cOnChange) { var otbl, otr, otd=new Array(), obutt, octrl, i, oimg, oret, oframe; oimg = imgTag(oLabels.imgPath+'/flt.gif',0); otd[0] = tdTag('', [oimg], '', '', 'center'); delete oimg; otr = trTag(otd); for (i in otd) delete otd[i]; otbl = tableTag([otr], '', 0, '100%', 0, 0, 0, '100%'); otbl.style.height = '100%'; delete otr; octrl = txtTag(cID,cValue,'comboBoxInputField',32,2000); octrl.setAttribute('onkeyup','comboBoxTextBoxKeyUp(event,this,\''+cURL+'\',\''+cUrlParams+'\');'); octrl.setAttribute('onkeydown','comboBoxTextBoxKeyDown(event,this,\''+cURL+'\',\''+cUrlParams+'\');'); otd[0] = tdTag('', [octrl]); delete octrl; obutt = buttonTag('button'+cID,'v','small'); eval('obutt.onclick=function () { comboBoxServerRequest(\''+cID+'\', 1); }; '); otd[1] = tdTag('', [obutt]); delete odiv; otr = trTag(otd); for (i in otd) delete otd[i]; otbl=tableTag([otr], 'Outside'+cID, 0, '', 0, 0); otbl.className = 'comboboxOutside'; delete otr; octrl = selectTag('List'+cID); octrl.size = 2; octrl.style.display = 'none'; octrl.style.position = 'absolute'; if (cOnChange) octrl.setAttribute('onchange', cOnChange); oret = [otbl, octrl]; comboBoxRegister(cID, cURL, cUrlParams); return oret; } function comboBoxFindTextBox(oList, cListName) { var j; if (!oList) return ''; if (oList.id == cListName) { return oList; } if (oList.childNodes) { for (i = 0; i < oList.childNodes.length; i++) { return comboBoxFindTextBox(oList.childNodes[i], cListName); } } } function comboBoxRename(oList, cListName, cNewListName) { var aListParams = new Array('', 'Outside', 'List', 'button'), i, j; if (!oList) return; for (j = 0; j < aListParams.length; j++) { if (oList.id == aListParams[j] + cListName) { oList.id = oList.name = aListParams[j] + cNewListName; if (aListParams[j] == 'button') { eval('oList.onclick=function () { comboBoxServerRequest(\''+cNewListName+'\',1); }; '); } } } for (i = 0; i < oList.childNodes.length; i++) { comboBoxRename(oList.childNodes[i], cListName, cNewListName); } } function comboBoxFictiveLayer(cShow) { } function isComboBox(cListName) { if (aComboBoxes[cListName]) return 1; return 0; } function comboBoxParamsRename(cListName, cNewListName) { aComboBoxes[cNewListName] = aComboBoxes[cListName]; aComboBoxes[cNewListName].urlParams.replace(new RegExp(cListName, 'g'), cNewListName); } function comboBoxClone(cListName, cNewListName) { var otbl = getItemByID('Outside' + cListName), oelm, oNewList = new Array(); if (otbl) { oNewList[0] = otbl.cloneNode(true); comboBoxRename(oNewList[0], cListName, cNewListName); if (oelm = getItemByID('List' + cListName)) { oNewList[1] = oelm.cloneNode(true); oNewList[1].name = oNewList[1].id = 'List' + cNewListName; if (oNewList[1].length == 2) oNewList[1].options[1].selected = true; } } comboBoxParamsRename(cListName, cNewListName); return oNewList; } function comboBoxShowValuesList(cListName) { var oOutside = getItemByID('Outside'+cListName), oList = getItemByID('List'+cListName); var oTextBox = getItemByID(cListName), n, cFunc = '', oFrame = oComboBoxFrame, nDelta; var odiv = getItemByID('tabsBodyLayer'), nScrollTop = 0, cLn, cLn1, i, nHeight, nMaxHeight; if (!oOutside || !oList) return; if (odiv && NN) nScrollTop = odiv.scrollTop; oList.style.display = ''; oList.style.position = 'absolute'; nMaxHeight = document.body.clientHeight / 2 - 20; nHeight = 5; for (i = 0; i < oList.length; i++) { if (0) nHeight+= oList.options[i].offsetHeight; nHeight+= 20; } oList.style.height = (nHeight > 0 && nHeight < nMaxHeight) ? nHeight : nMaxHeight; oList.style.width = oOutside.offsetWidth; if (0) { oList.style.left = objTrueLeft(oOutside); oList.style.top = objTrueTop(oOutside) + oOutside.offsetHeight - nScrollTop; if (parseInt(oList.style.top) > document.body.clientHeight / 2) { oList.style.top = objTrueTop(oOutside) - parseInt(oList.style.height) - nScrollTop; } } oList.style.zIndex = '50'; if (!oFrame.parentNode) oList.parentNode.appendChild(oFrame); oFrame.style.position = 'absolute'; oFrame.style.left = oList.style.left; oFrame.style.top = oList.style.top; oFrame.style.width = oList.style.width; oFrame.style.height = oList.style.height; oFrame.style.zIndex = '45'; if (0) oFrame.style.display = ''; if (oTextBox.form) { oTextBox.form.onsubmit=function () { return false; }; } if (!aComboBoxStdHandlers[cListName]) { cFunc = ''; if (oList.onchange) { cFunc = oList.onchange.toString(); if (n = cFunc.indexOf('{')) { cFunc = cFunc.substr(n); } cFunc = cFunc.replace('this','getItemByID(\''+oTextBox.name+'\')'); } aComboBoxStdHandlers[cListName] = { onChange: cFunc }; cFunc = ''; if (oTextBox.onblur) { cFunc = oTextBox.onblur.toString(); if (n = cFunc.indexOf('{')) { cFunc = cFunc.substr(n); } cFunc = cFunc.replace('this','getItemByID(\''+oTextBox.name+'\')'); } aComboBoxStdHandlers[cListName].onBlur = cFunc; } cLn = cListName.replace(new RegExp('\'','g'), '\\\\\\\''); cLn1 = cListName.replace(new RegExp('\'','g'), '\\\''); eval('oList.onfocus = function () { if (nHideComboBox) window.clearTimeout(nHideComboBox); };'); eval('oList.onblur = function () { nHideComboBox=window.setTimeout(\'comboBoxHideValuesList(\\\''+cLn+'\\\')\',10); }; '); eval('oTextBox.onfocus = function () { if (nHideComboBox) window.clearTimeout(nHideComboBox); };'); eval('oTextBox.onblur = function () { if (nFilterComboBox) window.clearTimeout(nFilterComboBox); nHideComboBox=window.setTimeout(\'comboBoxHideValuesList(\\\''+cLn+'\\\')\',10); ' + aComboBoxStdHandlers[cListName].onBlur + '}; '); oTextBox.setAttribute('onchange', ''); eval('oList.onchange = function () { var c,oTextBox=getItemByID(\''+cLn1+'\'); if (oTextBox && this.options && this.options.selectedIndex>=0 && this.options[this.options.selectedIndex]) oTextBox.value=this.options[this.options.selectedIndex].text;' + aComboBoxStdHandlers[cListName].onChange +';}; '); eval('oList.onclick = function () { this.onchange(); comboBoxHideValuesList(\''+cLn1+'\'); };'); oTextBox.focus(); } function comboBoxHideValuesList(cListName) { var oList = getItemByID('List'+cListName), oTextBox = getItemByID(cListName); var oFrame = oComboBoxFrame; if (!oList) return; if (oTextBox.form) { oTextBox.form.onsubmit=function () { return true; }; } oList.style.display = 'none'; oFrame.style.display = 'none'; } function comboBoxSetListIndex(oList, nIndex) { if (!oList) return; if (nIndex < 0) oList.options.selectedIndex = 0; else if (nIndex > oList.options.length) oList.options.selectedIndex = oList.options.length - 1; else oList.options.selectedIndex = nIndex; if (oList.style.display == 'none') oList.style.display = ''; } function comboBoxXMLRequestHandler(oXml, oParams) { var orow, oList = getItemByID('List'+oParams.list), oTextBox = getItemByID(oParams.list), nShowFlag = 1; if (oList && oTextBox) { orow = oXml.firstChild; oList.length = 0; while (orow) { oList.options[oList.length++] = new Option(orow.getAttribute('text'),orow.getAttribute('value')); orow = orow.nextSibling; } if (oList.length == 1) { if (oXml.firstChild.getAttribute('text') == oTextBox.value) { oList.value = oXml.firstChild.getAttribute('value'); if (!oParams.butt) nShowFlag = 0; } } else if ((oList.length == 0) && !oParams.butt) { nShowFlag = 0; } if (nShowFlag || oParams.butt) { comboBoxShowValuesList(oParams.list); } else { comboBoxHideValuesList(oParams.list); } if (nFilterComboBox) window.clearTimeout(nFilterComboBox); if (oList.length == 0) { if (oTextBox.value = 'Wait, please') oTextBox.value = ''; oTextBox.style.fontStyle = 'italic'; } else oTextBox.style.fontStyle = ''; oTextBox.style.background = '#fefefe'; oTextBox.value = oParams.oldValue; oTextBox.focus(); } } function comboBoxKeyDownHandler(e) { var evn = e; if (evn.keyCode == 13 || evn.keyCode == 10) return false; } function comboBoxSetValue(cCtrlName, cValue) { var oList; if (oList = getItemByID(cCtrlName)) oList.value = cValue; } function comboBoxServerRequest(cCtrlName, nButton) { var oCtrl = getItemByID(cCtrlName), cUrlParams, cval; if (!oCtrl || !aComboBoxes[cCtrlName]) return; if (!aComboBoxes[cCtrlName].url) return; cUrlParams = 'filter='+oCtrl.value; if (aComboBoxes[cCtrlName].urlParams) eval('cUrlParams+=\'&\'+'+aComboBoxes[cCtrlName].urlParams+';'); oCtrl.style.background = '#cccccc'; cval = oCtrl.value; oCtrl.value = 'Wait, please'; // top.location = aComboBoxes[cCtrlName].url + '?' + cUrlParams; xmlRequest.startQuery(aComboBoxes[cCtrlName].url, cUrlParams, comboBoxXMLRequestHandler, { oldValue:cval, list:oCtrl.name, butt: nButton }, comboBoxFictiveLayer); } function comboBoxTextBoxKeyDown(e, oCtrl, cUrl, eUrlParams) { if (nFilterComboBox) window.clearTimeout(nFilterComboBox); } function comboBoxTextBoxKeyUp(e, oCtrl, cUrl, eUrlParams) { var evn = e, oTxt = getItemByID(oCtrl.name), oList = getItemByID('List'+oCtrl.name), cUrlParams, i; var cpCtrlName; return; if (oList) { if (oTxt.value && oList.length == 0) return; if (evn.keyCode == 36) // Home { comboBoxSetListIndex(oList, 0); return; } else if (evn.keyCode == 35) // End { comboBoxSetListIndex(oList, oList.length - 1); return; } else if (evn.keyCode == 33) // Page up { comboBoxSetListIndex(oList, oList.options.selectedIndex - 15); return; } else if (evn.keyCode == 34) // Page down { comboBoxSetListIndex(oList, oList.options.selectedIndex + 15); return; } else if (evn.keyCode == 40) // Key down { comboBoxSetListIndex(oList, oList.options.selectedIndex + 1); return; } else if (evn.keyCode == 38) // Key up { comboBoxSetListIndex(oList, oList.options.selectedIndex - 1); return; } else if (evn.keyCode == 27) // Escape { oCtrl.value = ''; comboBoxHideValuesList(oCtrl.name.replace(new RegExp('\'','g'), '\\\'')); return; } else if (evn.keyCode == 13 || evn.keyCode == 10) // Enter { if (oList.onchange) oList.onchange(); comboBoxHideValuesList(oCtrl.name); return false; } else if (evn.keyCode == 9) // Tab { return; } } if (xmlRequest) { cpCtrlName= '\'' + oCtrl.name.replace(new RegExp('\'','g'), '\\\'') + '\''; nFilterComboBox = window.setTimeout('comboBoxServerRequest('+cpCtrlName+',\'\')', 1000); } }