// JavaScript Document

var selectBox = new Object();
	//array especial que guarda os objectos criados pelo user
	selectBox.cache = new Array();
	selectBox.style = function()
	{
		this.border = false;
		this.borderTop = false;
		this.borderBottom = false;
		this.borderLeft = false;
		this.borderRight = false;
		this.backgroundColor = false;
		this.backgroundImage = false;
		this.backgroundRepeat = false;
		this.backgroundPosition = false;
		this.textAlign = false;
		this.fontSize = false;
		this.font = false;
		this.width = false;
		this.height = false;
		this.position = 'static';
		this.textDecoration = false;
		this.color = false;
		this.top = false;
		this.left = false;
		this.right = false;
		this.bottom = false;
		this.cursor = false;
		this.zIndex = false;
		this.display = false;
		this.overflow = false;
		this.padding = false;
		this.paddingTop = false;
		this.paddingBottom = false;
		this.paddingLeft = false;
		this.paddingRight = false;
		this.margin = 0;
		this.marginTop = false;
		this.marginBottom = false;
		this.marginLeft = false;
		this.marginRight = false;
		this.listStyle = false;
		this.usefloat = false;
		this.scaleUnit = 'px';
		this.cssText = false;
		this.html = function()
		{
			var s = (this.cssText?this.cssText:'');
			if(this.backgroundImage) s+='background-image:url('+this.backgroundImage+');';
			if(this.backgroundRepeat) s+='background-repeat:'+this.backgroundRepeat+';';
			if(this.backgroundPosition) s+='background-position:'+this.backgroundPosition+';';
			if(this.usefloat) s+='float:'+this.usefloat+';';
			if(this.listStyle) s+='list-style:'+this.listStyle+';';
			if(this.borderTop) s+='border-top:'+this.borderTop+';';
			if(this.borderBottom) s+='border-bottom:'+this.borderBottom+';';
			if(this.borderLeft) s+='border-left:'+this.borderLeft+';';
			if(this.borderRight) s+='border-right:'+this.borderRight+';';
			if(this.padding) s+='padding:'+this.padding+';';
			if(this.paddingTop) s+='padding-top:'+this.paddingTop+this.scaleUnit+';';
			if(this.paddingBottom) s+='padding-bottom:'+this.paddingBottom+this.scaleUnit+';';
			if(this.paddingLeft) s+='padding-left:'+this.paddingLeft+this.scaleUnit+';';
			if(this.paddingRight) s+='padding-right:'+this.paddingRight+this.scaleUnit+';';
			if(this.margin) s+='margin:'+this.margin+';';
			if(this.marginTop) s+='margin-top:'+this.marginTop+this.scaleUnit+';';
			if(this.marginBottom) s+='margin-bottom:'+this.marginBottom+this.scaleUnit+';';
			if(this.marginLeft) s+='margin-left:'+this.marginLeft+this.scaleUnit+';';
			if(this.marginRight) s+='margin-right:'+this.marginRight+this.scaleUnit+';';
			if(this.display) s+='display:'+this.display+';';
			if(this.overflow) s+='overflow:'+this.overflow+';';
			if(this.zIndex) s+='z-index:'+this.zIndex+';';
			if(this.font) s+='font-family:'+this.font+';';
			if(this.border) s+='border:'+this.border+';';
			if(this.backgroundColor) s+='background-color:'+this.backgroundColor+';';
			if(this.textAlign) s+='text-align:'+this.textAlign+';';
			if(this.fontSize) s+='font-size:'+this.fontSize+this.scaleUnit+';';
			if(this.width) s+='width:'+this.width+this.scaleUnit+';';
			if(this.height) s+='height:'+this.height+this.scaleUnit+';';
			if(this.position) s+='position:'+this.position+';';
			if(this.textDecoration) s+='text-decoration:'+this.textDecoration+';';
			if(this.color) s+='color:'+this.color+';';
			if(this.top) s+='top:'+this.top+this.scaleUnit+';';
			if(this.left) s+='left:'+this.left+this.scaleUnit+';';
			if(this.right) s+='right:'+this.right+this.scaleUnit+';';
			if(this.bottom) s+='bottom:'+this.bottom+this.scaleUnit+';';
			if(this.cursor) s+='cursor:'+this.cursor+';';
			return s;
		}
	}
	selectBox.obj = function(prefix)
	{
		
		//defini&ccedil;&otilde;es gerais da componente;
		this.prefix=prefix;
		this.className = '';
		this.cache = new Array();
		
		this.content = new Object();
		this.content.style = new selectBox.style();
		
		this.editableContent = new Object();
		this.editableContent.defaultValue = '';
		this.editableContent.style = new selectBox.style();
		
		this.content.style.borderColor = '#7F9DB9';
		this.content.style.border = '1px solid '+this.content.style.borderColor;
		this.content.style.color = '#000000';
		this.content.style.backgroundColor = '#ffffff';
		this.content.style.height = 200;
		this.content.style.font='Times New Roman';
		this.content.style.fontSize=12;
		this.content.style.fontWeight='normal';
		this.content.style.margin = '0px';
		
		this.style = new selectBox.style();
		this.style.height='0px';
		this.style.overColor='#8BBBED';
		//this.style.overColor='#ff0000';
		this.style.selectedColor='#CDE4FC';
		this.style.borderColor='#7F9DB9';
		this.style.backgroundColor='#ffffff';
		this.style.font='Times New Roman';
		this.style.fontSize=12;
		this.style.fontWeight='normal';
		//this.style.border='1px solid '+this.style.borderColor;
		this.style.width = 0;
		this.style.color = '#000000';
		
		
		this._focus_ = {
			style:new selectBox.style()
		}
		
		this._focus_.style.cssText = 'font-size:1px;height:1px;cursor:default;border:0px;background-color:transparent;';
		
		this.tab = {
			style:new selectBox.style()
		}
		this.tab.style.cssText = 'background-color:#0066CC;color:#ffffff;';
		
		
		this.relativePath = '';
		this.showIndex = false;
		this.showIndexNavigation = 0;
		this.showValueFirst = false;
		
		this.htmlFormat = false;
		this.name = '';
		this.value = '';
		this.valueText = '';
		this.scrollvalue = 0;
		this.indexSearchedValue = 0;
		
		// settings de controle da componente;
		this.cache=Array();
		this.cache['selectedIndexContent'] = '&nbsp;';
		this.cache['selectedRealIndex'] = '&nbsp;';
		
		this.core = {
			previous:false,
			current:false,
			realindex:false,
			index:false
		}
		
		//objecto que vai guardar todas as rows que introduzir na componente
		this.data = {
			parent:this,
			content:[],
			contentIndex:[],
			style:new selectBox.style(),
			html:function(html,id)
			{
				var html = '<div style="text-align:left;padding:0px;margin:0px;padding-left:2px;font-family:'+this.parent.content.style.font+';font-size:'+this.parent.content.style.fontSize+'px;font-weight:'+this.parent.content.style.fontWeight+';">'+html+'</div>';
				return html;
			}
		}
			
		this.state='hidden';
		this.headHTML='';
		this.contentHTML='';
		this.ArrowImage=null;
		this.resumeonclick = true;
		this.resumeonDblClick = false;
		this.searchValue = false;
		this.editable = false;
		this.HTMLcontentObjs = new Object();
		
		this.onChange = function(){};
		this.onclick = function(){};	
		this.onmouseover = function(){};
		this.onmouseout = function(){};
		this.onmouseup = function(){};
		this.onmousedown = function(){};
		this.onClear = function(){};
		this.onDropStart = function(){};
		this.onDropEnd = function(){};
		this.onLift = function(){};
		this.onSelect = function(){};
		
		this.eventClearTrigger = false;
		
		this.method = new Object();
		this.method.innerHTML = false;
		this.method.ADDinnerHTML = false;
		this.method.createElement = false;
		this.method.documentWrite = true;
		this.method.targetHTML = false;
		
		this.method.check = function()
		{
			if(this.innerHTML)
			{
				this.createElement = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.ADDinnerHTML)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.createElement = false;
			} else
			if(this.createElement)
			{
				this.innerHTML = false;
				this.documentWrite = false;
				this.ADDinnerHTML = false;
			} else
			if(this.documentWrite)
			{
				this.innerHTML = false;
				this.createElement = false;
				this.ADDinnerHTML = false;
			}
		}
		this.method.writeHTML = function(html)
		{
			if(this.innerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML = html;
			} else
			if(this.ADDinnerHTML)
			{
				var target = document.body;
				if(this.targetHTML)
				{
					var obj = document.getElementById(this.targetHTML);
					if(obj) target = obj;
				}
				target.innerHTML+=html;
			} else
			if(this.createElement)
			{
				var div = document.createElement(div);
					document.body.appendChild(div);
					div.innerHTML = html;
			} else
			if(this.documentWrite)
			{
				document.write(html);
			}
		}
		
		this.replaceStr = function(str,rexp,subs)
		{
			if(!str)return false;
			var result = String(str);
			while(result.search(rexp) != -1){result = result.replace(rexp,subs);}
			return result;
		}
		this.add=function(content)
		{
			var regexp = new RegExp("\"|'","gi");
			if(typeof content == 'string') content = content.replace(regexp,"'");
			this.data.content.push(content);
			this.data.contentIndex.push(this.data.content.length);
			//this.getdivwidth(content);
		}
		this.addIndex = function(content,index)
		{
			if(!index && index != 0) return false;
			var regexp = new RegExp("\"|'","gi");
			if(typeof content == 'string') content = content.replace(regexp,"'");
			this.data.content.push(content);
			this.data.contentIndex.push(index);
			//this.getdivwidth(content);
		}
		this.getdivwidth = function(obj)
		{
			var span=document.createElement("SPAN");
			document.body.appendChild(span);
			span.innerHTML = obj;
			var width = span.offsetWidth;
			if(width > this.style.width) this.style.width = width;
			span.parentNode.removeChild(span);
		}
		this.verifyindex = function(a,b)
		{
			var index_a = null,index_b = null;
			for(x=0;x<this.data.length;x++){if(a == x) index_a = i;}
			for(x=0;x<this.data.length;x++){if(b == x) index_b = i;}
			if(Number(index_a) == Number(index_b))return true; else return false;
		}
		this.transformObjectToHTML = function(obj)
		{
			//var regexp = /'/g;
			var regexp = new RegExp("'","gi");
			var div = document.createElement('DIV');
				document.body.appendChild(div);
				div.appendChild(obj);
			var html = div.innerHTML;
				obj.parentNode.removeChild(obj);
				div.parentNode.removeChild(div);	
			//return html.replace(regexp,"&quot;");	
			return html;
		}
		this.getRelativePath = function(script)
		{
			var scripts = document.getElementsByTagName('SCRIPT');
			if(!scripts) return false;
			var regexp = new RegExp(script,"gi");
			for(var i = 0; i<scripts.length; i++)
			{
				if(String(scripts.item(i).src).match(regexp))
					this.relativePath = scripts.item(i).src.replace(regexp,'');
			}
		}
		
		//creates the selectBox for the first time
		this.create=function()
		{	
			if (this.relativePath == '')
				this.getRelativePath('selectBox.js');
			this.method.check();
			
			var regexp = new RegExp("\"|'","gi");
			var browser = selectBox.browser();
			var value = this.data.content[this.core.current]?this.data.content[this.core.current]:'';	
	
			var s = '<table id="'+this.prefix+'_selectBoxTable" style="background-color:'+this.style.backgroundColor+';border-width:1px;border-style:solid;border-color:'+this.style.borderColor+';height:'+this.style.height+';padding-right:1px;" cellpadding="0" cellspacing="0">';
					s+= '<tr style="vertical-align:middle">';
						s+= '<td id="'+this.prefix+'_selectedIndex" style="background-color:'+this.style.backgroundColor+';padding-left:2px;overflow:hidden">';

							s+= this.editable?'<input style="width:'+this.style.width+'px;padding:0px;margin:0px;border:0px;font-family:'+this.content.style.font+';font-size:'+this.content.style.fontSize+'px;font-weight:'+this.content.style.fontWeight+';" type="text" value="'+value+'" onblur="selectBox.cache[\''+this.prefix+'\'].updateEditValue(this);selectBox.cache[\''+this.prefix+'\'].onBlurTab();"  onfocus="selectBox.cache[\''+this.prefix+'\'].onFocusTab();" />':'<div style="text-align:left;padding:0px;margin:0px;width:'+this.style.width+'px;overflow:hidden;color:'+this.style.color+';font-family:'+this.style.font+';font-size:'+this.style.fontSize+'px;font-weight:'+this.style.fontWeight+';" onclick="selectBox.cache[\''+this.prefix+'\'].visibility();">'+value+'</div>';
						
						s+= '</td>';
						s+= '<td><div id="'+this.prefix+'_selectBoxButton" style="margin:0px;padding:0px;margin-top:1px;background-image:url('+this.relativePath+'combo.gif);width:15px;height:19px;background-repeat:no-repeat;cursor:pointer;" onclick="selectBox.cache[\''+this.prefix+'\'].visibility()" onmouseover="selectBox.cache[\''+this.prefix+'\'].swapOverArrowImg(this)" onmouseout="selectBox.cache[\''+this.prefix+'\'].swapArrowImg(this)"></div></td>';
					s+= '</tr>';
				s+= '</table>';
					
			this.headHTML = s;
			
			var bottomvisibility = 'border-bottom:0px solid '+this.content.style.borderColor+';';
			//var widthoffset = 10;
			var moz_bottomvisible = 'border-bottom:1px solid '+this.content.style.borderColor+';';
			
			//if(browser == 'IE') widthoffset = 18; 
			//if(browser == 'OPERA') widthoffset = 18;
			if(browser == 'MOZ' && this.state == 'hidden' ) moz_bottomvisible = 'border-bottom:0px solid '+this.content.style.borderColor;
			if(browser == 'OPERA' && this.state == 'hidden' ) moz_bottomvisible = 'border-bottom:0px solid '+this.content.style.borderColor;

			var s = '',bgcolor = '';		
			if(this.state == 'visible')
			{
				//eval('selectBox.cache[\''+this.prefix+'\'].onDropStart(selectBox.cache[\''+this.prefix+'\']);');
				this.onDropStart(this);
				
				s+= '<div onscroll="selectBox.getscrollvalue.get(this,\''+this.prefix+'\')" style="margin:0px;padding:0px;position:absolute;border:0px;border:1px solid '+this.content.style.borderColor+';margin-top:-1px;background-color:#ffffff;width:'+(this.style.width+(browser=='IE'?19:18))+'px;">';
				s+= '<table id="'+this.prefix+'_selectBoxContentTable" cellpadding="0" cellspacing="0" border="0" width="100%">';
					
				for(var x=0;x<this.data.content.length;x++)
				{	
					if(x == this.showIndex) bgcolor='background-color:'+this.style.selectedColor; else bgcolor = '';
					s+= '<tr onmouseover="selectBox.cache[\''+this.prefix+'\'].eventMouseOverContent(this)" onclick="selectBox.cache[\''+this.prefix+'\'].eventSelectIndex('+x+')" style="cursor:pointer;'+bgcolor+';">';
						s+= '<td>'+this.data.html(this.data.content[x])+'</td>';
					s+= '</tr>';
				}
				s+= '</table></div>';
					
			} else {
					s+= '';
					if(selectBox.cache[this.prefix])
						//eval('selectBox.cache[\''+this.prefix+'\'].onLift(selectBox.cache[\''+this.prefix+'\']);');
						this.onLift(this);
				}
			
			this.contentHTML = s;
			this.outputHTML(); 
			
			var obj = document.getElementById(this.prefix);
			if(obj) return obj; else return false; 
			
			
		}
		
		//print the selectBox in the html
		this.outputHTML=function()
		{
			selectBox.cache[this.prefix] = this;
			var s = this.headHTML+this.contentHTML;
			var div = document.getElementById(this.prefix);
		
			if(!div) 
			{
				var html = '<div id="'+this.prefix+'" style="width:'+this.style.width+'px;margin:0px;padding:0px;'+(selectBox.browser()=='MOZ'?'margin-right:20px;':'')+'">';
					html+= '<div id="selectbox_'+this.prefix+'_table">'+s+'</div>';
					html+= (!this.editable?'<div style="height:0px;position:absolute;margin-top:-1px;"><input id="selectbox_'+this.prefix+'_focus" onfocus="selectBox.cache[\''+this.prefix+'\'].onFocusTab();" onblur="selectBox.cache[\''+this.prefix+'\'].onBlurTab();" type="button" style="'+this._focus_.style.html()+'" /></div>':'')
				html+= '</div>';
				
				this.method.writeHTML(html);
				//document.writeln((!this.editable?'<span><input id="selectbox_'+this.prefix+'_focus" onfocus="selectBox.cache[\''+this.prefix+'\'].onFocusTab();" onblur="selectBox.cache[\''+this.prefix+'\'].onBlurTab();" type="text" name="'+this.name+'" value="" style="'+this._focus_.style.html()+'" /></span>':''));
				//document.writeln(html+(!this.editable?'<input id="selectbox_'+this.prefix+'_focus" onfocus="selectBox.cache[\''+this.prefix+'\'].onFocusTab();" onblur="selectBox.cache[\''+this.prefix+'\'].onBlurTab();" type="text" name="'+this.name+'" value="" style="'+this._focus_.style.html()+'" />':''));
				var input = document.getElementById('selectbox_'+this.prefix+'_focus');
				if(input && selectBox.cache[this.prefix]) input.onkeydown = selectBox.cache[this.prefix].keydown; 
			
			} else {div.firstChild.innerHTML=s;}
			
			var obj = document.getElementById(this.prefix+'_selectBoxContentTable');
			if(obj && this.state == 'visible')
			{
				obj = obj.parentNode;
				if(parseInt(obj.offsetHeight)>this.content.style.height)
				{
					obj.style.height = this.content.style.height + 'px';
					obj.style.overflow = 'auto';
					var value = selectBox.getscrollvalue.value[this.prefix];
					obj.scrollTop = value;
					var width = parseInt(obj.offsetWidth);
					obj.firstChild.style.width = (width - 19) + 'px';
				}
			}
			if(this.contentHTML != '')
			{		
				//eval('selectBox.cache[\''+this.prefix+'\'].onDropEnd(selectBox.cache[\''+this.prefix+'\']);');
				this.onDropEnd(this);
				if(this.searchValue)this.focusInput();
			
			}
			
			this.getOptionsHeight(this.showIndex);
			if(this.core.previous != this.core.current) this.onChange(this);
			this.core.previous = this.core.current;
			this.showIndexNavigation = this.showIndex;
			selectBox.cache[this.prefix] = this;
			if(this.eventClearTrigger) this.onClear(this);
		}
		this.index = function(index)
		{
			this.state='hidden';
			this.showIndex = index;
			//this.data.content[this.core.current] 
			this.core.current = index;
			this.create();
		}
		this.selectIndexOnly = function(index)
		{
			this.state='visible';
			this.showIndex = index;
			this.create();
		}
		this.indexStatic = function(index)
		{
			this.state='hidden';
			this.showIndex = index;
		}
		this.arrayIndex = function(index)
		{
			var i = this.data.contentIndex.index(index);
			this.index(i);
		}
		this.getContent = function(index)
		{
			var content = this.data.content;
			var i = this.data.contentIndex.index(index);
			return content[i];
		}
		this.clear = function(index)
		{
			if(!index)
			{
				this.data.content = new Array();
				this.data.contentIndex = new Array();
				this.core.current = -1;
				this.showIndex = false;
				this.eventClearTrigger = true;
			} else {
				if(this.data.content[index])
				{
					this.data.content = this.data.content.erase(index);
					this.data.contentIndex = this.data.contentIndex.erase(index);
				}
				this.eventClearTrigger = true;
				this.visibility();
				this.visibility();
			}
		}
		this.clearByIndex = function(index)
		{
			if(!index) return false;
			var i = this.data.contentIndex.index(index);
			if(this.data.content[i])	
			{
				this.data.content = this.data.content.erase(i);
				this.data.contentIndex = this.data.contentIndex.erase(i);
			}
			this.state = 'visible';
			this.visibility();
		}
		this.updateEditValue = function(obj_)
		{	
			var access = false;
			
			if(obj_.value == '') return false;
			if(this.data.content[-1] != obj_.value) access = true;
			
			this.data.content[-1] = obj_.value;
			this.showIndex = -1;
			this.value = -1;
			this.valueText = obj_.value;
			
			this.core.current = -1;
			this.core.previous = -1;
	
			if(access) this.onChange(this);
			this.state='hidden';
			
			this.create();
		}
		this.showEditValue = function()
		{	
			this.data.content[-1] = this.valueText;
			this.core.current = -1;
			this.showIndex = -1;
			this.create();
		}
		
		this.eventMouseOverContent=function(div)
		{
			if(!this.cache['MouseOver'])
				this.cache['MouseOver'] = new Object();
			var mem = this.cache['MouseOver'];
			
			if(mem.obj) mem.obj.style.backgroundColor = mem.objColor;
				
				mem.obj = div;
				mem.id = div.id;
				mem.objColor = div.style.backgroundColor;
			this.showIndexNavigation = div.rowIndex;	
			div.style.backgroundColor = this.style.overColor;	
		}
		
		this.eventSelectIndex=function(id)
		{	
			if(this.core.previous == id) return false;
			
			this.showIndex = id;
			this.state='hidden';
			this.value = this.data.contentIndex[id];
			this.valueText = this.data.content[id];
			
			this.core.current = id;
			this.onSelect(this);
			this.create();
		}
		
		this.visibility=function()
		{	
		
			var div = document.getElementById(this.prefix);
			if(!div) return false;
			
			if(this.state=='visible') 
				this.state='hidden'; 
					else {
						this.state='visible';
					}
			var input = document.getElementById('selectbox_'+this.prefix+'_focus');
			//if(input) input.focus();		
			var obj = document.getElementById(this.prefix+'_selectedIndex');		
			if(!obj) return false;
			var width = obj.offsetWidth;
			this.create();
		}
		this.tabstylecss = false;
		this.onFocusTab = function()
		{
			var obj = document.getElementById(this.prefix+'_selectedIndex').firstChild;
			this.tabstylecss = obj.style.cssText;
			obj.style.cssText = this.tabstylecss+';'+this.tab.style.html();			
		}
		
		
		this.onBlurTab = function()
		{
			var obj = document.getElementById(this.prefix+'_selectedIndex').firstChild;
				obj.style.cssText = this.tabstylecss;
			this.state = 'visible';
		}
		this.getOptionsHeight = function(index)
		{

				var obj = document.getElementById(this.prefix+'_selectBoxContentTable');
				if(!obj) return false;
				var table = new selectBox.tableDomFunctions(obj);
					table.check();
				var height = 0;
				for(var i=0;i<=index;i++)
				{
					if(table.get(i,0))
						height = height + parseInt(table.get(i,0).parentNode.offsetHeight);
				}
				var d = parseInt(obj.parentNode.offsetHeight);
				
				if(height >= this.content.style.height) obj.parentNode.scrollTop = height - this.content.style.height;
					else obj.parentNode.scrollTop = 0;
					
		}
		this.focusInput = function()
		{
			/*var obj = document.getElementById('selectbox_'+this.prefix+'_focus');
			if(!obj) return false;
			var dom = this;
				obj.onkeydown = function(e)
				{
					var ev = window.event?window.event:e;
					var letter = String.fromCharCode(ev.keyCode);
					var value = false;
					var firstletter = new RegExp('^'+letter,'i');
					var access = false;

					dom.data.content.internalCounter = dom.indexSearchedValue;
					while(value = dom.data.content.next())
					{
						if(String(value).match(firstletter)) {access = true;break;}
					}
					if(access)
					{
						dom.indexSearchedValue = dom.data.content.internalCounter;
						dom.selectIndexOnly(dom.data.content.internalCounter-1);
						dom.getOptionsHeight(dom.data.content.internalCounter-1);
					
					} else {
						
						dom.data.content.internalCounter = 0;
						access = false
						while(value = dom.data.content.next())
						{
							if(String(value).match(firstletter)) {access = true;break;}	
						}
						if(access)
						{	
							dom.indexSearchedValue = dom.data.content.internalCounter;
							dom.selectIndexOnly(dom.data.content.internalCounter-1);
							dom.getOptionsHeight(dom.data.content.internalCounter-1);
							
						} else {
							dom.getOptionsHeight(-1);
							dom.data.content.internalCounter = 0;
							dom.indexSearchedValue = 0;
						}
						
					}
					
				}
				obj.focus();
			return obj;	*/
		}
		this.blurInput = function()
		{
			var obj = document.getElementById('selectbox_'+this.prefix+'_focus');
				obj.blur();
			return obj;	
		}
		this.swapOverArrowImg=function(obj){obj.style.backgroundImage = 'url('+this.relativePath+'combo_over.gif)';}
		this.swapArrowImg=function(obj){obj.style.backgroundImage = 'url('+this.relativePath+'combo.gif)';}
		this.keydown = function(e)
		{
			if (!e) var e = window.event;
				if (e.keyCode) code = e.keyCode;
					else if (e.which) code = e.which;
			
			var obj = e.srcElement?e.srcElement:e.target;
			var splited = obj.id.split('_');
			var dom = selectBox.cache[splited[1]];
			var obj = document.getElementById(dom.prefix+'_selectBoxContentTable');
			var table = new selectBox.tableDomFunctions(obj);
			if(code == 32) 
			{
				if(dom.state == 'visible') 
				{
					dom.index(dom.showIndexNavigation);
					dom.state = 'visible';
				}
				dom.visibility();
			}
			if(code == 9)
			{
				dom.state = 'visible';
				dom.visibility();
			}
			if(code == 13)
			{
				dom.index(dom.showIndexNavigation);
				e.keyCode = 9;
			}
			
			if(code == 38)
			{
				if(dom.showIndexNavigation == 0) return true;
				dom.showIndexNavigation--;
				var td = table.get(dom.showIndexNavigation,0);
				var tr = td?td.parentNode:false;
				if(tr) dom.eventMouseOverContent(tr);
				dom.getOptionsHeight(dom.showIndexNavigation);
				return true;
			} else if(code == 40)
					{
						if(dom.showIndexNavigation == (dom.data.content.length - 1)) return true;
						dom.showIndexNavigation++;
						var td = table.get(dom.showIndexNavigation,0);
						var tr = td?td.parentNode:false;
						if(tr) dom.eventMouseOverContent(tr);
						dom.getOptionsHeight(dom.showIndexNavigation);
						return true;
					} 
			
			
			
			
			var ev = window.event?window.event:e;
			var letter =  String.fromCharCode(code);
			var value = false;
			var firstletter = new RegExp('^'+letter,'i');
			var access = false;

			dom.data.content.internalCounter = dom.indexSearchedValue;
			while(value = dom.data.content.next())
			{
				if(String(value).match(firstletter)) {access = true;break;}
			}
			if(access)
			{
				dom.indexSearchedValue = dom.data.content.internalCounter;
				dom.selectIndexOnly(dom.data.content.internalCounter-1);
				dom.getOptionsHeight(dom.data.content.internalCounter-1);
			
			} else {
				
				dom.data.content.internalCounter = 0;
				access = false
				while(value = dom.data.content.next())
				{
					if(String(value).match(firstletter)) {access = true;break;}	
				}
				if(access)
				{	
					dom.indexSearchedValue = dom.data.content.internalCounter;
					dom.selectIndexOnly(dom.data.content.internalCounter-1);
					dom.getOptionsHeight(dom.data.content.internalCounter-1);
					
				} else {
					//dom.getOptionsHeight(-1);
					dom.data.content.internalCounter = 0;
					dom.indexSearchedValue = 0;
				}
				
			}
		}
	}
	
	selectBox.getscrollvalue = new Object();
	selectBox.getscrollvalue.value = new Array();
	selectBox.getscrollvalue.get = function(obj,prefix)
	{
		
		selectBox.getscrollvalue.value[prefix] = obj.scrollTop;
		selectBox.cache[prefix].focusInput();
	}
	selectBox.tempfunc = null;
	
	//sets the visibility property of the content data
	
	
	selectBox.tableDomFunctions = function(obj)
	{
		this.root = obj;
		this.element = false;
		this.colgroup = false;
		this.tbody = false;
		this.notWhitespace = /\S/
		
		this.check = function()
		{
			if(!this.root) return false;
			if(this.root.nodeName != 'TABLE') return false;

			if(this.root.firstChild.nodeName == 'COLGROUP')
			{
				this.colgroup = this.root.firstChild;
				if(this.root.firstChild.nextSibling.nodeName ==  'TBODY')
				{
					this.tbody = this.root.firstChild.nextSibling;
					this.element = this.root.firstChild.nextSibling.firstChild;
				}
			}
			if(this.root.firstChild.nodeName == 'TBODY')
			{
				this.tbody = this.root.firstChild;
				this.element = this.root.firstChild.firstChild;
			}
		}
		this.get = function(row,col)
		{
			this.check();
			var y = 0;
			while(y < row && this.element){this.element = this.element.nextSibling;y++;}
			
			if(this.node(this.element,col)) return this.node(this.element,col); 
					else return false;
		}
		this.node = function(obj,index)
		{
			if(!obj) return false;
			var obj = obj.firstChild?obj.firstChild:false;
			if(index == 0) return obj;
			var x = 0;
			while(x < index){obj = obj.nextSibling;x++;}
			return obj;
		}
		this.cleanWhitespace = function(node) 
		{	  
			  for (var x = 0; x < node.childNodes.length; x++) {
				var childNode = node.childNodes[x]
				if ((childNode.nodeType == 3)&&(!this.notWhitespace.test(childNode.nodeValue))) {
			// that is, if it's a whitespace text node
				  node.removeChild(node.childNodes[x])
				  x--
				}
				if (childNode.nodeType == 1) {
			// elements can have text child nodes of their own
				  this.cleanWhitespace(childNode)
				}
			  }
		}
	}
	
	selectBox.browser = function() 
	{
		var browser = new String(navigator.appName);
		if(browser.match('Microsoft Internet Explorer')) return String('IE');
		if(browser.match('Netscape')) return String('MOZ');
		if(browser.match('Opera')) return String('OPERA');
	}
	