﻿var selectUI = function(o){
		
		this.uid = o.uid;
		this.items = o.items;
		this.values = o.values;
		this.menu = null;
		this.width = o.width;
		this.height = o.height;
		this.autoScroll = o.autoScroll;
		
		this.hiddenID = o.hiddenID;
		this.creatMenu();
	}
selectUI.prototype = {
		
		//创建下拉菜单面版
		creatMenu : function(){
				if($(this.uid+'menu')){
					$(this.uid+'menu').style.display='block';
					return false;
					}
				if(!$(this.uid).onclick)	
				this.menu = document.createElement("div");
				document.body.appendChild(this.menu);
				this.menu.id = this.uid+'menu';
				this.menu.className = 'selectUI';
				this.creatItems();
				
			},
		//创建下拉菜单选项
		creatItems : function(){
				var i;
				var o = this;
				for (var i = 0;i<this.items.length;i++){
					var aItem = document.createElement("a");
					this.menu.appendChild(aItem);
					aItem.href = 'javascript:;';
					aItem.innerHTML = '&nbsp;'+this.items[i];
					aItem.onclick = function(){o.setValue.call(o,this)};
					}
				
				this.setPosition.call(this);	
			},
		//回填选值	
		setValue : function(o){
				$(this.uid).innerHTML = o.innerHTML.replace('&nbsp;','');
				$(this.uid).parentNode.parentNode.className  = $(this.uid).parentNode.parentNode.className;
				var ho = $(this.hiddenID)
				for(var i=0;i<this.items.length;i++){
					
					if($(this.uid).innerHTML.replace("<a>","").replace("</a>","")==this.items[i]){
					ho.value = this.values[i];
					Search.adSearch();
					break;
					}
				}
				
			},
		//计算位置并且设置位置
		setPosition : function(){
				var theElement = $(this.uid);
				var selectedPosX = 0;
				if(!isIE)selectedPosX = -1;
				var selectedPosY = $(this.uid).offsetHeight;
				while (theElement != null) {
					selectedPosX += theElement.offsetLeft;
					selectedPosY += theElement.offsetTop;
					theElement = theElement.offsetParent;
				}
				this.menu.style.top=selectedPosY +'px';
				this.menu.style.left=selectedPosX +'px';
				
				this.close.call(this);
			},
		show : function(){
				this.menu.style.display = 'block';
				this.isShow = true;
			},
		close : function(){
				this.menu.style.display = 'none';
			},
		isShow : true,	
		winclose : function(){
				if(!this.isShow)this.menu.style.display = 'none';
				this.isShow = false;
			}	
		
	}	
function isIE() {
		if (!window.ActiveXObject)
			return false;
		try {
			new ActiveXObject("Microsoft.XMLDOM");
			return true;
		} catch (err) {
			return false;
		}
	}	