﻿// JavaScript Document

function startIBBSelect(){
	var Me =this
	if (!window.document.selectIBBS) 	window.document.selectIBBS = new Array();
	if(!this.inIndex) this.inIndex =  window.document.selectIBBS.length
	 window.document.selectIBBS[this.inIndex] = this
	 
	var ancors = this.getElementsByTagName("A")
	var divs  =  this.getElementsByTagName("DIV")
	var listHold = divs[1]
	
	var ulObj =  this.getElementsByTagName("UL")[0]
	this.ulObj = ulObj
	this.options = ulObj.getElementsByTagName("LI")
	var inp =  this.getElementsByTagName("INPUT")[0]
	var trigger = divs[0]
	var textHolder = trigger.childNodes[0]
	var openImage =  trigger.childNodes[1]
	this.selectedIndex = 0
	
	Me.onChange = ""
	inp.indexOf = -1
	var timerSec = 0
	var timer
	var status = "close"
	var s,t
	
	this.unselectable="no"
	textHolder.unselectable="no"
	myDir = window.getComputedStyle?window.getComputedStyle(Me,null).getPropertyValue('direction') : Me.currentStyle.direction
	
	
	for(i=0;i<ancors.length; i++)ancors[i].onclick = aOnclick
	
	this.startMe1= function(){
		textHolder.style.direction = myDir
		for(i=0;i<ancors.length; i++)ancors[i].onclick = aOnclick
		//alert(window.document.selectIBBS[ Me.inIndex ])
		textHolder.style.width = (this.offsetWidth - openImage.offsetWidth-5) + "px"
		textHolder.style.height =this.offsetHeight + "px"
		if(myDir=="rtl"){
			textHolder.style.right = "0px"
			openImage.style.left = "0px"
			listHold.style.right = "-1px"
			textHolder.style.textAlign ="right"
			
		} else{
			listHold.style.left = "0px"
			textHolder.style.left = "0px"
			openImage.style.right = "1px"
			textHolder.style.textAlign ="left"
		}
		textHolder.style.visibility = "visible"
		openImage.style.visibility = "visible"
		listHold.style.top = this.offsetHeight + "px"
		Me.options = ulObj.getElementsByTagName("LI")
		for (i=0 ;i<Me.options.length; i++){
			
			Me.options[i].onclick = onClickLi
			Me.options[i].nvalue = Me.options[i].title
			Me.options[i].title = ""
			Me.options[i].indexOf = i
			Me.options[i].style.width = (this.offsetWidth-10) + "px"
			if(Me.options[i].className=='selected')	this.selectedIndex = i
		}
		this.listener(false)
		
		trigger.onmousedown = openMe
		listHold.style.width = (this.offsetWidth) + "px"
		trigger.style.cursor = "pointer"
		
	}
	function aOnclick() {
		
		return false;
	}
	function onClickLi(){
		Me.selectedIndex = this.indexOf
		listHold.style.display = "none"
		Me.style.zIndex=1000
		status = "close"
		timer = 0
		
		//parent.selectedIndex= this.indexOf
	}
	
	STR = "window.document.selectIBBS["+ Me.inIndex +"].startMe1()"
	clearTimeout(s)
	s = setTimeout(STR, 200)
	this.listener = function(change){
		
		if (inp.indexOf != this.selectedIndex){
			if(window.document.body. textContent){
				textHolder.textContent =Me.options[ this.selectedIndex].textContent
			}else{
				textHolder.innerText = Me.options[ this.selectedIndex].innerText
			}
			
			inp.value = Me.options[ this.selectedIndex].nvalue
			inp.indexOf = this.selectedIndex
			if(change){
					
				if(Me.onChange!="")
					Me.onChange(Me.options[ this.selectedIndex].nvalue, inp.indexOf )	
			}
			
		}
		
		clearTimeout(s)
		
		s = setTimeout("window.document.selectIBBS["+ Me.inIndex +"].listener(true)", 60)	
	}
	function openMe(){
		if (status == "close"){
			listHold.style.display = "block"
			Me.style.zIndex=1100
			status = "open"
		}else{
			listHold.style.display = "none"
			status = "close"
			Me.style.zIndex=1000
			timer = 0
		}
	}
	this.onmouseover = function(){ 
		timer = 0
		
	}
	
	
	this.onmouseout = function(){
		if (status =="open"){
			timer  = 1
			startTimer()	
		}
	}
	function startTimer(){
		if (timer>0){
			if(timer == 4){
				status = "close"
				listHold.style.display = "none"
				Me.style.zIndex=1000
			}else{
				timer++
				clearTimeout(t)
				t = setTimeout(startTimer, 100)
				
			
			}
		
		}
	
	}
	
}