var KEY_UP=38,KEY_DOWN=40,KEY_ENTER=13,ELEMENT_NODE=1,KEY_ESCAPE=27,KEY_F4=115;function openCombo(a,b,c){a=document.getElementById(b);if(!a.disabled){c=gComboEx=document.getElementById(c);c.style.display=="block"?setStyle(c,"display","none",""):showCombo(a,c);gItemNum=-1;gFocusItem=a;setTimeout("doFocus();",0)}}var g_iField=null,g_cb=null;function showCombo(a,b){g_iField=a;g_cb=b;a.addEventListener("move",function(){realShowCombo()},false);realShowCombo()}
function getY(a){for(var b=0;a!=null;){b+=a.offsetTop;a=a.offsetParent}return b}function getX(a){for(var b=0;a!=null;){b+=a.offsetLeft;a=a.offsetParent}return b}function realShowCombo(){var a=getY(g_iField),b=getX(g_iField);a=a+g_iField.offsetHeight+"px";b=b+"px";g_cb.style.minWidth=g_iField.offsetWidth+"px";setStyle(g_cb,"top",a,"");setStyle(g_cb,"left",b,"");setStyle(g_cb,"display","block","")}var gItemNum=0,gComboEx=null;
function focusCombo(a,b,c){a=a.keyCode;var d=true;c=gComboEx=document.getElementById(c);if(a==KEY_DOWN||a==KEY_F4){c.getAttribute("style.display")=="block"||showCombo(b,c);b=c.childNodes;c=b.length;for(a=0;b[a]!=null&&a<c;){if(b[a].nodeType==ELEMENT_NODE&&b[a].className=="item"){gFocusItem=b[a];break}a++}gItemNum=0;setTimeout("doFocus();",0);d=false}else if(a!=KEY_ENTER)if(a==KEY_ESCAPE)if(b.val!=null&&b.val.length>0)d=true;else{d=false;setStyle(gComboEx,"display","none","");gItemNum=-1}return d}
function focusItem(a,b,c){a=c.val;for(var d=null,e=getItems(b),f=e.length,g=false,h=0;h<f;h++)if(e[h].hasChildNodes()&&e[h].firstChild.nodeValue==a){g=true;d=e[h];gItemNum=h;break}if(!g){d=addItem(b,a,e.length);gItemNum=e.length}if(d!=null){gFocusItem=d;if(gComboEx.getAttribute("style.display")!="block"){a=c.offsetLeft+"px";setStyle(b,"top",c.offsetTop+c.offsetHeight+"px","");setStyle(b,"left",a,"")}else setStyle(b,"display","none","");setStyle(b,"display","block","");setTimeout("doFocus();",0)}}
function addItem(a,b,c){var d=document.createElement("div"),e=typeof b.label!="undefined"?b.label:b;d.val=typeof b.label!="undefined"?b.value:b;d.label=e;if(typeof b.label!="undefined"){d.label=b.label;if(typeof b.image!="undefined"){var f=document.createElement("img");f.src=b.image;f.style.paddingRight="15px";d.appendChild(f);d.img=f.src}}b=document.createTextNode(e);d.appendChild(b);d.setAttribute("tabindex","-1");d.setAttribute("class","item");d.setAttribute("onclick","gItemNum="+c+";");d.setAttribute("onmouseover",
"gFocusItem = this; doFocus();");d.setAttribute("role","listitem");d.style.overflow="hidden";a.appendChild(d);return d}
function doComboNav(a,b,c){var d=a.keyCode,e=true;if(gComboEx==null)gComboEx=b;if(d==KEY_UP||d==KEY_DOWN){e=false;a=0;b=getItems(gComboEx);var f=b.length;if(d==KEY_UP)a=gItemNum-1;else{a=gItemNum+1;if(a==f)a=-1}gItemNum=a;gFocusItem=gItemNum==-1?document.getElementById(c):b[a];setTimeout("doFocus();",0)}else if(d==KEY_ENTER||!a.keyCode&&a.button>=0){b=getItems(gComboEx);d=b[gItemNum];if(d!=null&&d.getAttribute("aria-disabled")!="true"){a=d.label;b=d.val;c=document.getElementById(c);c.value=a;c.val=
b;if(typeof d.img!="undefined"){c.style.background="url("+d.img+") no-repeat 2px 5px";c.style.paddingLeft="25px"}c.onchange&&c.onchange();setStyle(gComboEx,"display","none","");gItemNum=0;gFocusItem=c;setTimeout("doFocus();",0)}}else if(d==KEY_ESCAPE){e=false;setStyle(b,"display","none","");gItemNum=0;gFocusItem=document.getElementById(c);setTimeout("doFocus();",0)}return e}
function getItems(a){var b=[];b=[];a=a.childNodes;for(var c=a.length,d=0;d<c;d++)if(a[d].nodeType==ELEMENT_NODE&&(a[d].getAttribute("class")=="item"||a[d].getAttribute("class")=="item focus"))b[b.length]=a[d];return b}function setStyle(a,b,c,d){var e=false;try{if(a.style&&a.style.setProperty){a.style.setProperty(b,c,d);e=true}}catch(f){alert("exception caught setting style: "+f.message)}if(!e)try{a.style[b]=c;e=true}catch(g){alert("exception caught setting direct style: "+g.message)}return e}
gLastFocusItem=gFocusItem=null;function doFocus(){if(gFocusItem!=null){gFocusItem.focus();if(gLastFocusItem&&gLastFocusItem.className=="item focus")gLastFocusItem.className="item";if(gFocusItem&&gFocusItem.className=="item")gFocusItem.className="item focus";gLastFocusItem=gFocusItem;gFocusItem=null}}
function create_combo(a,b){var c=document.getElementById(a),d=a+"_combo";if(!document.getElementById(d)){c.setAttribute("onkeydown","return focusCombo(event, this, '"+d+"');");c.setAttribute("role","textfield");c.setAttribute("aria-haspopup","true");c.setAttribute("autocomplete","off");c.style.marginRight="0px";var e=c.style.width.replace(/px/,"");if(e=="")try{e=c.ownerDocument.defaultView.getComputedStyle(c,"").width.replace(/px/,"")}catch(f){}e=document.createElement("div");e.setAttribute("role",
"list");e.setAttribute("style","display: none;");e.setAttribute("id",d);e.setAttribute("class","dropStyle");e.setAttribute("onkeydown","return doComboNav(event, this, '"+a+"');");e.setAttribute("onclick","doComboNav(event, this, '"+a+"');");e.style.paddingLeft="6px";e.style.paddingRight="6px";e.style.position="absolute";document.body.appendChild(e);window.addEventListener("click",function(){close_combo(a)},false);for(var g=0;g<b.length;g++)addItem(e,b[g],g);e=document.createElement("img");e.setAttribute("onclick",
"openCombo(event, '"+a+"', '"+d+"'); event.cancelBubble = true;");e.setAttribute("src","images/pwdrop.png");e.setAttribute("valign","middle");typeof g_isopera!="undefined"&&g_isopera&&e.setAttribute("style","position: relative; top: 7px;");c.nextSibling?c.parentNode.insertBefore(e,c.nextSibling):c.parentNode.appendChild(e)}}
function delete_combo_item(a,b){var c=document.getElementById(a+"_combo");if(c)for(var d=getItems(c),e=0;e<d.length;e++)if(d[e].innerHTML==b){for(d.splice(e,1);c.hasChildNodes();)c.removeChild(c.firstChild);for(e=0;e<d.length;e++)addItem(c,d[e].innerHTML,e);break}}function close_combo(a){if(a=document.getElementById(a+"_combo"))if(a.style.display=="block"){setStyle(a,"display","none","");gItemNum=-1}}
function repopulate_combo(a,b){var c=document.getElementById(a+"_combo");if(c){for(;c.hasChildNodes();)c.removeChild(c.firstChild);for(var d=0;d<b.length;d++)addItem(c,b[d],d)}};
