
DropDownMenuPoint=function(x,y){this.x=x;this.y=y;}
DropDownMenuPoint.prototype={x:0,y:0}
DropDownMenuUtils=function(){}
DropDownMenuUtils.notNull=function(value,paramName){if(value==null)
throw Error("The parameter '"+paramName+"' cannot be null or empty.");}
DropDownMenuUtils.notNullOrEmpty=function(value,paramName){if(value==null||value.toString().length==0)
throw Error("The parameter '"+paramName+"' cannot be null or empty.");}
DropDownMenuUtils.addHandler=function(element,eventName,handler){DropDownMenuUtils.notNull(element,"element");DropDownMenuUtils.notNullOrEmpty(eventName,"eventName");DropDownMenuUtils.notNull(handler,"handler");if(window.addEventListener)
element.addEventListener(eventName,handler,true);else
element.attachEvent("on"+eventName,handler);}
DropDownMenuUtils.removeHandler=function(element,eventName,handler){DropDownMenuUtils.notNull(element,"element");DropDownMenuUtils.notNullOrEmpty(eventName,"eventName");DropDownMenuUtils.notNull(handler,"handler");if(window.addEventListener)
element.removeEventListener(eventName,handler,true);else
element.dettachEvent("on"+eventName,handler);}
DropDownMenuUtils.applyInstance=function(instance,method){DropDownMenuUtils.notNull(instance,"instance");DropDownMenuUtils.notNull(method,"method");return function(){return method.apply(instance,arguments);};}
DropDownMenuUtils.throwException=function(clause,message){if(clause)throw Error(message);}
DropDownMenuUtils.findElement=function(id,parentElement){DropDownMenuUtils.notNullOrEmpty(id,"id");if(parentElement==null)
return document.getElementById(id);else
return parentElement.getElementById(id);}
DropDownMenuUtils.getElementPosition=function(element){DropDownMenuUtils.notNull(element,"element");var x=0,y=0,e=element;do{x+=e.offsetLeft;y+=e.offsetTop;}while(e=e.offsetParent);return new DropDownMenuPoint(x,y);}
DropDownMenuUtils.addElementAt=function(parent,element,index){DropDownMenuUtils.notNull(parent,"parent");DropDownMenuUtils.notNull(element,"element");DropDownMenuUtils.notNull(index,"index");if(parent.childNodes.length!=0)
parent.insertBefore(element,parent.childNodes[index]);else
parent.appendChild(element);}
DropDownMenuUtils.clearChildNodes=function(element){DropDownMenuUtils.notNull(element,"element");for(var i=0;i<element.childNodes.length;i++){element.removeChild(element.childNodes[i]);}}
DropDownMenuItems=function(){}
DropDownMenuItems.prototype={innerList:new Array(),each:function(fn){DropDownMenuUtils.notNull(fn,"fn");for(var i=0;i<this.innerList.length;i++){fn.apply(this,[i,this.innerList[i]]);}},add:function(tag,text,selected){DropDownMenuUtils.notNullOrEmpty(tag,"tag");DropDownMenuUtils.notNullOrEmpty(text,"text");this.innerList.push({tag:tag,text:text,selected:selected});},remove:function(tag){DropDownMenuUtils.notNullOrEmpty(tag,"tag");this.each(function(index,item){if(item.tag==tag)
this.innerList.splice(index,1);});},clear:function(){this.innerList.splice(0,this.innerList.length);},get:function(tag){DropDownMenuUtils.notNullOrEmpty(tag,"tag");var res=null;this.each(function(index,item){if(item.tag==tag)
res=item;});return res;}}
DropDownMenu=function(){this._initialized=false;this._targetElement=null;this._popupMenu=null;this._hiddenField=null;this._timerID=null;this._beginHideTimeout=function(){window["__HideCallback"]=DropDownMenuUtils.applyInstance(this,function(){this.hide();});this._timerID=window.setTimeout("__HideCallback()",this.hideDuration);}}
DropDownMenu.prototype={items:new DropDownMenuItems(),menuClass:new String(),menuItemClass:new String(),selectedMenuItemClass:new String(),targetElementID:new String(),click:null,hideDuration:1000,hiddenFieldID:new String(),clearSelected:function(){this.items.each(function(index,item){item.selected=false;});},getSelectedItem:function(){var selectedItem=null;this.items.each(function(index,item){if(item.selected)
selectedItem=item;});return selectedItem;},verifyMultipleSelect:function(){var count=0;this.items.each(function(index,item){if(item.selected)
count++;});DropDownMenuUtils.throwException(count>1,"The DropDownMenu control cannot have multiple selected items.");},init:function(){DropDownMenuUtils.addHandler(window,"load",DropDownMenuUtils.applyInstance(this,function(e){DropDownMenuUtils.throwException(this.targetElementID==null||this.targetElementID.length==0,"The targetElementID is required.");this._targetElement=DropDownMenuUtils.findElement(this.targetElementID);DropDownMenuUtils.throwException(this._targetElement==null,"The element '"+this.targetElementID+"' could not be found.");DropDownMenuUtils.addHandler(this._targetElement,"click",DropDownMenuUtils.applyInstance(this,function(e){this.show();}));DropDownMenuUtils.addHandler(this._targetElement,"mouseout",DropDownMenuUtils.applyInstance(this,function(e){this._beginHideTimeout();}));DropDownMenuUtils.throwException(this.hiddenFieldID==null||this.hiddenFieldID.length==0,"The hiddenFieldID is required.");this._hiddenField=DropDownMenuUtils.findElement(this.hiddenFieldID);DropDownMenuUtils.throwException(this._hiddenField==null,"The element '"+this.hiddenFieldID+"' could not be found.");if(this._hiddenField!=null&&this._hiddenField.value.length>0){var item=this.items.get(this._hiddenField.value);if(item!=null){this.clearSelected();item.selected=true;}}
this.createElements();this._initialized=true;}));},createItems:function(){DropDownMenuUtils.clearChildNodes(this._popupMenu);var popupMenuItems=document.createElement("ul");with(popupMenuItems){style.margin=0;style.padding=0;style.listStyleType="none";}
this.items.each(DropDownMenuUtils.applyInstance(this,function(index,item){var newItem=document.createElement("li");var newLink=document.createElement("a");with(newLink){if(!item.selected){href="javascript:void(0)";if(this.menuItemClass!=null&&this.menuItemClass.length>0)className=this.menuItemClass;}
else{if(this.selectedMenuItemClass!=null&&this.selectedMenuItemClass.length>0)className=this.selectedMenuItemClass;}
innerHTML=item.text;}
DropDownMenuUtils.addHandler(newLink,"click",DropDownMenuUtils.applyInstance(this,function(e){if(this.click!=null)this.click(index,item);this.clearSelected();item.selected=true;this.createItems();this.hide();this._hiddenField.value=item.tag;}));newItem.appendChild(newLink);popupMenuItems.appendChild(newItem);}));this._popupMenu.appendChild(popupMenuItems);},createElements:function(){if(this._initialized)return;this.verifyMultipleSelect();this._popupMenu=document.createElement("span");with(this._popupMenu){style.display="none";style.position="absolute";style.zIndex=1000;style.direction="rtl";if(this.menuClass!=null&&this.menuClass.length>0)className=this.menuClass;DropDownMenuUtils.addHandler(this._popupMenu,"mouseover",DropDownMenuUtils.applyInstance(this,function(){window.clearTimeout(this._timerID);}));DropDownMenuUtils.addHandler(this._popupMenu,"mouseout",DropDownMenuUtils.applyInstance(this,function(e){this._beginHideTimeout();}));}
this.createItems();DropDownMenuUtils.addElementAt(document.body,this._popupMenu,0);},ensureInit:function(){if(!this._initialized)
this.init();},show:function(){this.ensureInit();var position=DropDownMenuUtils.getElementPosition(this._targetElement);with(this._popupMenu){style.display="block";style.left=(position.x+this._targetElement.offsetWidth)-this._popupMenu.offsetWidth+"px";style.top=(this._targetElement.offsetHeight+position.y)+"px";}
DropDownMenuUtils.addHandler(document.body,"click",DropDownMenuUtils.applyInstance(this,function(e){var target=e.target?e.target:e.srcElement;if(target!=this._targetElement)
this.hide();}));},hide:function(){this.ensureInit();with(this._popupMenu){style.display="none";style.left=0;style.top=0;}}}