var AwtFirstPos = 0; var AwtLastPos = 0; var AwtCarrotPos = 0; var AwtSearchWord = null; var AwtObjId = null; var AwtMode = null; var AwtUserInfo = getUserInfo("userid"); if (AwtUserInfo == "") AwtUserInfo = "test1"; function AwtSearch_Form() { if (event.keyCode == 192 && event.ctrlkey == 1) { AwtMode = "CtrlTilt"; } else if (event.keyCode == 32 && event.ctrlkey == 1) { AwtMode = "CtrlSpace"; } else { return; } var ctrl = null; ctrl = document.controls(model.getFocus()); //±×¸®µå¿¡¼­ ÀԷ¹ÞÀº °æ¿ì¿¡´Â ±×¸®µåÀÇ input ¹Ú½º¸¦.. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") { ctrl = document.controls(event.currentTarget).input; } var text = ctrl.currentText; //ij·µ À§Ä¡ Ç¥½Ã AwtCarrotPos = ctrl.selEnd; AwtLastPos = AwtCarrotPos; for ( ; AwtLastPos < text.length; AwtLastPos++) { //alert("lastPos " + AwtLastPos + "-" + text.substr(AwtLastPos, 1)); if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf ) { break; } } if (AwtFirstPos > text.length) AwtFirstPos = 0; AwtFirstPos = AwtLastPos - 1; for ( ; AwtFirstPos >= 0; AwtFirstPos--) { //alert("firstPos " + AwtFirstPos + "-" + text.substr(AwtFirstPos, 1)); if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf ) { AwtFirstPos++; break; } } if (AwtFirstPos < 0) AwtFirstPos = 0; AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos); //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos); if (AwtSearchWord != "") { AwtObjId = ctrl.attribute("id"); xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP'); if (AwtMode == "CtrlSpace") send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //°ø¿ëDB¿¡¼­¸¸ °Ë»ö else if (AwtMode == "CtrlTilt") send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //°³ÀÎDB¿¡¼­¸¸ °Ë»ö } } function AwtSearch_CtrlSpace() { if (event.keyCode == 192 && event.ctrlkey == 1) { AwtMode = "CtrlTilt"; } else if (event.keyCode == 32 && event.ctrlkey == 1) { AwtMode = "CtrlSpace"; } else { return; } var ctrl = null; ctrl = document.controls(event.currentTarget); //±×¸®µå¿¡¼­ ÀԷ¹ÞÀº °æ¿ì¿¡´Â ±×¸®µåÀÇ input ¹Ú½º¸¦.. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") { ctrl = document.controls(event.currentTarget).input; } var text = ctrl.currentText; //ij·µ À§Ä¡ Ç¥½Ã AwtCarrotPos = ctrl.selEnd; AwtLastPos = AwtCarrotPos; for ( ; AwtLastPos < text.length; AwtLastPos++) { //alert(AwtLastPos + "-" + text.substr(AwtLastPos, 1)); if ( text.substr(AwtLastPos, 1) == String.fromCharCode(32) //space || text.substr(AwtLastPos, 1) == String.fromCharCode(9) //tab || text.substr(AwtLastPos, 1) == String.fromCharCode(13) //cr || text.substr(AwtLastPos, 1) == String.fromCharCode(10) //lf ) { break; } } if (AwtFirstPos > text.length) AwtFirstPos = 0; AwtFirstPos = AwtLastPos - 1; for ( ; AwtFirstPos >= 0; AwtFirstPos--) { //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1)); if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf ) { AwtFirstPos++; break; } } if (AwtFirstPos < 0) AwtFirstPos = 0; AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos); //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos); if (AwtSearchWord != "") { AwtObjId = ctrl.attribute("id"); xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP'); if (AwtMode == "CtrlSpace") send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //°ø¿ëDB¿¡¼­¸¸ °Ë»ö else if (AwtMode == "CtrlTilt") send(0, AwtSearchWord, "autocomplete", AwtUserInfo); //°³ÀÎDB¿¡¼­¸¸ °Ë»ö } } function AwtSearch_Space() { if (event.keyCode == 32 && event.ctrlkey != 1 && event.altkey != 1) { AwtMode = "Space"; } else { return; } var ctrl = null; ctrl = document.controls(event.currentTarget); //±×¸®µå¿¡¼­ ÀԷ¹ÞÀº °æ¿ì¿¡´Â ±×¸®µåÀÇ input ¹Ú½º¸¦.. if (document.controls(event.currentTarget).elementName == "xforms:datagrid") { ctrl = document.controls(event.currentTarget).input; } var text = ctrl.currentText; //ij·µ À§Ä¡ Ç¥½Ã AwtCarrotPos = ctrl.selEnd; AwtLastPos = AwtCarrotPos - 1; //°ª AwtFirstPos = AwtLastPos - 1; for ( ; AwtFirstPos >= 0; AwtFirstPos--) { //alert(AwtFirstPos + "-" + text.substr(AwtFirstPos, 1)); if ( text.substr(AwtFirstPos, 1) == String.fromCharCode(32) //space || text.substr(AwtFirstPos, 1) == String.fromCharCode(9) //tab || text.substr(AwtFirstPos, 1) == String.fromCharCode(13) //cr || text.substr(AwtFirstPos, 1) == String.fromCharCode(10) //lf ) { AwtFirstPos++; break; } } if (AwtFirstPos < 0) AwtFirstPos = 0; AwtSearchWord = text.substring(AwtFirstPos, AwtLastPos); //alert(AwtFirstPos + "-" + AwtLastPos + "-" + AwtSearchWord + "--" + AwtCarrotPos); if (AwtSearchWord != "") { AwtObjId = ctrl.attribute("id"); xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP'); send(1, AwtSearchWord, "autocomplete", AwtUserInfo); //°ø¿ëDB¿¡¼­¸¸ °Ë } } function replaceAll(str, org, nxt) { var rstl = ""; for (var i = 0; i < str.length; i++) { if (str.substr(i, 1) == org) rstl = rstl + nxt; else rstl = rstl + str.substr(i, 1); } return rstl; } function SetAwtSelect(awtStr) { if (awtStr == "") return; if (awtStr == AwtSearchWord) return; awtStr = replaceAll(awtStr, "\r", ""); var obj = null; var dotPos = AwtObjId.indexOf("."); var gridId = ''; if (dotPos != -1) { gridId = AwtObjId.substr(0, dotPos); obj = document.controls(gridId); obj = obj.children("input"); } else obj = document.controls(AwtObjId); var first = obj.currentText.substr(0,AwtFirstPos); var last = obj.currentText.substr(AwtLastPos, obj.currentText.length); //alert(AwtFirstPos + "-'" + first + "' len:" + first.length + "****" + AwtLastPos + "-'" + last + "' len:" + last.length); // if (dotPos != -1) { // var grd = document.controls(gridId); // grd.valueMatrix(grd.row, grd.col) = first + awtStr + last; // grd.editCell(); // model.setFocus(gridId); // grd.editCell(); // } else { obj.currentText = first + awtStr + last; // } if (AwtMode == "Space") AwtCarrotPos = AwtCarrotPos - AwtSearchWord.length + awtStr.length; else // if (AwtMode == "CtrlSpace") AwtCarrotPos = AwtFirstPos + awtStr.length; obj.selBegin = AwtCarrotPos; obj.selEnd = AwtCarrotPos; } //////////////////////////// var xmlHttpRequest = null; function send(nOption,strSpell,strFlag,strDomain) { var strPostValue = encodeURI("option="+nOption+"&strSpell="+strSpell+"&strFlag="+strFlag +"&domain=" + strDomain + "&searchCount=" + 1); //ÀÏÄ¡Çϴ°ŠÇѰ³¸¸.. xmlHttpRequest.open('POST', AwtServerUrl, true); xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttpRequest.onreadystatechange = function() { if (xmlHttpRequest.readyState == 4) { switch (xmlHttpRequest.status) { case 404: // alert('¿À·ù: ' + AwtServerUrl + 'ÀÌ Á¸ÀçÇÏÁö ¾ÊÀ½'); break; case 200: OnResult(xmlHttpRequest.responseText.trim()); break; default: // alert('¿À·ù: ' + xmlHttpRequest.responseText); break; } } } xmlHttpRequest.send(strPostValue); } function OnResult(strVal) { nCurrent=0; if (strVal.length > 0) { if (AwtMode == "Space") SetAwtSelect(strVal.replace("¢Ì", "")); else SetAwtSelect(strVal.replace("¢Ì", "")); } } String.prototype.trim = function () { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }