var MV_dropDownDiv = null; var MV_dropDownList= null; var MV_MaxVisible = 3; var MV_MaxSaved = 50; var MV_SuggestionCount = 0; var close_img = "images/close.gif"; var enable = true; function saveValue(fieldName,value) { if(this.enable) { var expireDate = new Date(); expireDate.setTime(expireDate.getTime() + (30 * 24 * 60 * 60 * 1000)); // Expire in one month if(!exist(fieldName,value)) { var countOfValues = getCount(fieldName); if(countOfValues != null) { countOfValues++; }else { countOfValues = 1; } var curPos = getPos(fieldName); if(curPos != null) { curPos++; }else { curPos = 1; } if(curPos == MV_MaxSaved) curPos = 1; setCookie(fieldName+"["+curPos+"]",value,expireDate); setCookie("countOf_"+fieldName,countOfValues,expireDate); setCookie("curPosOf_"+fieldName,curPos,expireDate); } } } function getCount(fieldName) { var count = getCookie("countOf_"+fieldName); if(count!= null) { return count; }else { return 0; } } function getPos(fieldName) { var count = getCookie("curPosOf_"+fieldName); if(count!= null) { return count; }else { return 0; } } function getAllValues(fieldName) { var list = ""; var count = getCount(fieldName); for(i=1;i<=count;i++) { if(getCookie(fieldName+"["+i+"]")!=null) { list+=getCookie(fieldName+"["+i+"]")+" | "; } } return list; } function exist(fieldName,phrase) { var count = getCount(fieldName); for(i=1;i<=count;i++) { if(getCookie(fieldName+"["+i+"]")!=null && getCookie(fieldName+"["+i+"]").toUpperCase()==phrase.toUpperCase()) { return true; } } return false; } function getValuesByBegin(fieldName,begin) { var list = ""; var count = getCount(fieldName); for(i=1;i<=count;i++) { if(getCookie(fieldName+"["+i+"]")!=null && getCookie(fieldName+"["+i+"]").toUpperCase().startsWith(begin.toUpperCase())) { list+=getCookie(fieldName+"["+i+"]")+","; } } return list; } function MV_OnLoad(form) { if (!isMSIE) { if (form) form.setAttribute ("autocomplete", "off" ); } } function MV_IsActive() { if (MV_dropDownDiv != null) { return (MV_dropDownDiv.style.visibility == "visible"); } return false; } function KeyUp(name) { if(this.enable) { if(event.keyCode == 13) { }else { var editCtrl = window.document.getElementById(name); if(editCtrl.value.length>0) { var variants = getValuesByBegin(name,editCtrl.value); if(variants.length>0) { var dropDownHtml = MV_GenerateDropDownHtml(name,editCtrl.value); MV_NewDropDown(editCtrl,dropDownHtml); }else { MV_HideDropDown(editCtrl); } }else { MV_HideDropDown(editCtrl); } } } } function MV_GenerateDropDownHtml(fieldName,begin) { var count = getCount(fieldName); html ="
"; var countAdd = 0; for(var i=1;i<=count;i++) { if(getCookie(fieldName+"["+i+"]")!=null && getCookie(fieldName+"["+i+"]").toUpperCase().startsWith(begin.toUpperCase())) { html += ""; countAdd ++; //if(countAdd==MV_MaxVisible) break; } } MV_SuggestionCount = countAdd; html += "
"+MV_FormatListItem(getCookie(fieldName+"["+i+"]"),begin)+"
Click here to close
"; return html; } // add a class to an element function MV_AddElementClass(element, className) { if(element && element.className.indexOf (className) == -1) element.className += " " + className; } // remove a class from an element function MV_RemoveElementClass(element, className) { if ( element == null ) return; var loc = element.className.indexOf (className); if ( loc == -1 ) return; element.className = element.className.substring ( 0, loc ) + element.className.substring (loc + className.length + 1); } // check for a class on an element function MV_ElementHasClass ( element, className ) { return ( element && ( element.className.indexOf (className) != -1 )); } function MV_MenuItem_onMouseDown(element,editCtrl,value) { MV_RemoveElementClass(element, "mv_menuitem_selected" ); MV_AddElementClass (element, "mv_menuitem_selected"); editCtrl = document.getElementById (editCtrl); editCtrl.value = value; MV_HideDropDown(editCtrl) } function MV_MenuItem_onMouseOver(element) { if ( !MV_ElementHasClass(element, "mv_menuitem_selected" )) MV_AddElementClass(element, "mv_menuitem_over"); } function MV_MenuItem_onMouseOut(element) { MV_RemoveElementClass(element,"mv_menuitem_over"); } function MV_FormatListItem(text,begin) { return ""+text.substring(0,begin.length)+""+text.substring(begin.length); } var MV_updateTimer = null; var MV_updateEditCtrl; var MV_updateState; function MV_KickNewDropDown( editCtrl, state ) { if ( MV_updateTimer != null ) clearTimeout (MV_updateTimer); MV_updateEditCtrl = editCtrl; MV_updateTimer = setTimeout ( "MV_HandleNewDropDown()", 10 ); // fast typers will kill this } function MV_NewDropDown(editCtrl,dropDownHtml) { //if editCtrl is string if (typeof editCtrl == "string") editCtrl = document.getElementById (editCtrl); //if editCtrl not found or value is empty if (editCtrl == null || editCtrl.value.length == 0 ) { return; } MV_HideDropDown(editCtrl); MV_ShowDropDown(editCtrl,dropDownHtml); } function MV_HideDropDown(editCtrl) { if (MV_dropDownDiv != null) { MV_dropDownDiv.parentNode.removeChild(MV_dropDownDiv); MV_dropDownDiv.style.visibility = "hidden"; MV_dropDownDiv = null; MV_dropDownList = null; } } function MV_ShowDropDown(editCtrl,html) { if(editCtrl == null && MV_dropDownList != null) { editCtrl = window.document.getElementById ( MV_dropDownList.getAttribute ( "editCtrlID" )); } //create div if(MV_dropDownDiv == null) { // the select box is placed in a div so it can have z-index=1 and be hidden MV_dropDownDiv = window.document.createElement("div"); MV_dropDownDiv.style.position = "absolute"; MV_dropDownDiv.style.zIndex = 1; MV_dropDownDiv.style.visibility = "hidden"; MV_dropDownDiv.style.fontSize = "0.9em"; } editCtrl.parentNode.insertBefore (MV_dropDownDiv, editCtrl.nextSibling); if (MV_dropDownList == null ) { MV_dropDownList = window.document.createElement("div"); MV_dropDownList.className = "MV_menu"; MV_dropDownList.id = "MV_select"; MV_dropDownList.onclick = MV_Menu_onClick; MV_dropDownList.onmousedown = MV_Menu_onMouseDown; MV_dropDownList.unselectable = "on"; MV_dropDownList.style.width = editCtrl.offsetWidth; MV_dropDownDiv.appendChild(MV_dropDownList); } /* var option = MV_dropDownList.childNodes[index]; if ( option == null ) { option = window.document.createElement("div"); option.className = "MV_menuitem"; option.onmousedown = MV_MenuItem_onMouseDown; option.onmouseover = MV_MenuItem_onMouseOver; option.onmouseout = MV_MenuItem_onMouseOut; MV_dropDownList.appendChild(option); } else // remove hiliting for recycled items MV_RemoveElementClass ( option, "MV_menuitem_selected" ); option.value = suggestions[ index ][ 0 ]; option.text = suggestions[ index ][ 1 ]; // force everything onto one line: option.innerHTML = "" + suggestions[ index ][ 2 ] + ""; */ //Scrolling if(MV_SuggestionCount <= MV_MaxVisible) { MV_dropDownList.style.height = "auto"; if(isGecko) MV_dropDownList.style.overflow = "hidden"; MV_dropDownList.style.overflowY = "hidden"; }else { MV_dropDownList.style.height = "70px"; if(isGecko) MV_dropDownList.style.overflow = "-moz-scrollbars-vertical"; MV_dropDownList.style.overflowY = "scroll"; } /* MV_MakeElementTreeUnselectable ( MV_dropDownList ); MV_dropDownList.setAttribute("selectedIndex", selectedIndex); MV_Menu_SelectItem (MV_dropDownList, 0); MV_dropDownList.style.visibility = "visible"; MV_dropDownList.setAttribute("selectedIndex", selectedIndex); */ MV_dropDownList.style.visibility = "hidden"; MV_dropDownList.innerHTML = html; MV_dropDownList.style.display = "none"; MV_dropDownList.style.display = ""; MV_dropDownList.style.visibility = "visible"; // Place the drop down directly beneath the edit control. // Update this regularly, as the TEXTAREA can grow and shrink. var left= window.document.body.clientLeft - MV_dropDownList.offsetLeft; // TODO: this actually fails on Moz, but the default layout saves us var top = editCtrl.offsetHeight + window.document.body.clientTop - MV_dropDownList.offsetTop; var parent = editCtrl; do { left += parent.offsetLeft; top += parent.offsetTop; parent = parent.offsetParent; } while (parent != null); MV_dropDownDiv.style.left = left; MV_dropDownDiv.style.top = top; MV_dropDownDiv.style.display = "none"; MV_dropDownDiv.style.display = ""; MV_dropDownDiv.style.visibility = "visible"; // make the drop down width a function of the editCtrl width if (MV_dropDownList.offsetWidth < editCtrl.offsetWidth) { MV_dropDownList.style.posWidth = editCtrl.offsetWidth; } MV_dropDownList.setAttribute("editCtrlID",editCtrl.id); } //string addons function strtrim() { return this.replace(/^\s+/,'').replace(/\s+$/,''); } String.prototype.trim = strtrim; String.prototype.startsWith = function(sStart) { return (this.substr(0,sStart.length)==sStart); } function MV_Menu_onClick() { } function MV_Menu_onMouseDown() { } //test methods function fillExampleCookie(name) { saveValue(name,"vovik"); saveValue(name,"vladimir"); saveValue(name,"svetik"); saveValue(name,"sanek"); saveValue(name,"sanek123"); saveValue(name,"sanek"); saveValue(name,"sanek 64"); saveValue(name,"sanek 64_2005"); }