/*
<s cript type="text/javascript" src="javascript/functions.js"></script>
<s cript type="text/javascript" src="javascript/notification.js"></script>	
<s cript type="text/javascript" src="javascript/amhcontrols.js"></script>
*/

/* 
-------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>      Global init, include, etc.      <<<<<<<<<<<<<<<<<<<<<<<
-------------------------------------------------------------------------
*/

var nn = document.layers ? true : false; 
var ie = document.all ? true : false; 

/*document.write('<scr'+'ipt type="text/javascript" src="ckeditor/ckeditor.js" ></scr'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="overlibmws/overlibmws.js" ></scr'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="overlibmws/overlibmws_modal.js" ></scr'+'ipt>');*/

var temp_onLoad;
if( window.onload ) {
    temp_onLoad = window.onload;
}

window.onload = function() 
{
	if( temp_onLoad ) {
        temp_onLoad();
    }
	
	InitPage();
}	

	
/* 
-------------------------------------------------------------------------
>>>>>>>>>>>>>>>>      Init page, popup handling     <<<<<<<<<<<<<<<<<<<<<<<
-------------------------------------------------------------------------
*/

function InitPage()
{
  /* Register popups */
  var divs=$$('.dtinfo', '.drinfo');
  for(i=0;i<divs.length;i++)
  {
    divs[i].observe('mouseout',hideOverlay);
  }

  /* Visibility info */
  divs=$$('.dtvis_public','.dtvis_outer','.dtvis_inner','.dtvis_private','.dtvis_reg');
  for(i=0;i<divs.length;i++)
  {
		divs[i].observe('mouseout',hideOverlay);
		divs[i].observe('mouseover',visibilityInfo);
		divs[i].observe('click', changeVisibility);
  }
  
  /* Normal table control icon */
  if (typeof showpropinfo == 'function')
  {
	  var divs=$$('.drprop');
	  for(i=0;i<divs.length;i++)
	  {
		    divs[i].observe('mouseout',hideOverlay);
			divs[i].observe('mouseover',showpropinfo);	
	  }
  }
  
  if (typeof showproperties == 'function')
  {
	  var divs=$$('.drprop');
	  for(i=0;i<divs.length;i++)
	  {
			divs[i].observe('click', showproperties);
	  }
  }
  
  if (typeof showmod == 'function')
  {
	  var divs=$$('.drmod');
	  for(i=0;i<divs.length;i++)
	  {
		    divs[i].observe('mouseout',hideInteractive);
			divs[i].observe('mouseover',showmodinfo);		
			divs[i].observe('click', showmod);
	  }
  }
  
  /* Msg board control icon */
  var divs=$$('.drprof');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('mouseout',hideOverlay);
		divs[i].observe('mouseover',showprofinfo);
  }
  
  var divs=$$('.drmsg');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('mouseout',hideOverlay);
		divs[i].observe('mouseover',showmsginfo);
  }
  
  if (typeof showmsgeval == 'function')
  {
	 var divs=$$('.drmsgeval');
	  for(i=0;i<divs.length;i++)
	  {
		    divs[i].observe('mouseout',hideOverlay);
			divs[i].observe('mouseover',showmsgevalinfo);
			divs[i].observe('click', showmsgeval);
	  }
  }
  
  var divs=$$('.evalIdx');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('mouseout',hideOverlay);
		divs[i].observe('mouseover',showevalidxinfo);
  }
  
  var divs=$$('.drcite');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('mouseout',hideOverlay);
		divs[i].observe('mouseover',showciteinfo);
  }
  
   if ($('dataform')!=null&&(typeof validate == 'function'))
      Event.observe('dataform', 'submit', validate);
	  
  if (typeof initAjax == 'function')
      initAjax();
	    	
  if ($('hall')!=null)
  {
	    $('hall').observe('mouseout',hidemenu);
		$('hall').observe('mouseover',showmenu);
		
		$('hm_prose').observe('mouseout',hidemenu);
		$('hm_poem').observe('mouseout',hidemenu);
		$('hm_photo').observe('mouseout',hidemenu);
		$('hm_pic').observe('mouseout',hidemenu);
		$('hm_other').observe('mouseout',hidemenu);
		
		$('hm_prose').observe('mouseover',showmenu);
		$('hm_poem').observe('mouseover',showmenu);
		$('hm_photo').observe('mouseover',showmenu);
		$('hm_pic').observe('mouseover',showmenu);
		$('hm_other').observe('mouseover',showmenu);
  }
  
  /*Navibar*/
  if ($('navbar')!=null)
  {
	$('navbar').observe('mouseover',showNavBar);	
	$('navbar').observe('mouseout',hideNavBarWithDelay);		
  }
  if ($('navpin')!=null)
  {	
	$('navpin').observe('mouseover',shownavpin);
	$('navpin').observe('mouseout',hideOverlay);		
	$('navpin').observe('click',changenavpin);	
  }    
  updatenavstate();
    
  if (typeof InitPageEx == 'function')
      InitPageEx();
	  
  if (typeof InitCustomControls == 'function')
      InitCustomControls();
	  
  if ($('focus')!=null)
	scrollToElement($('focus'));	  
	  
  if ($('confirmmsg')!=null)
  {
	overlib($('confirmmsg').innerHTML, CENTER,MIDX,0,MIDY,0,WRAP,WRAPMAX,500, STICKY, CLOSECLICK, CLOSETEXT,'x',CAPTION, 'Üzenet', TIMEOUT, 1000);
  }
}

function showpropinfo(event)
{
	showinfo("Tulajdonságok megváltoztatása");
}

function showmodinfo(event)
{
	var parentDiv = event.element();
	if (!parentDiv.className.endsWith("Active"))
		parentDiv.className=parentDiv.className+"Active";
	showinfo("Moderálási kérelem");
}

function showprofinfo(event)
{
	showinfo("A hozzászólás/kritikaíró adat- lapjának megtekintése", 190);
}

function showmsginfo(event)
{
	showinfo("Személyes üzenet küldése");
}

function showmsgevalinfo(event)
{
	showinfo("A hozzászólás/kritika értékelése");
}

function showevalidxinfo(event)
{
	showinfo("A hozzászólás/kritika jelenlegi értékelése (-2 és +2 közti skálán)");
}

function showciteinfo(event)
{
	showinfo("Idézet / válasz");
}

function hideInteractive(event)
{
	var parentDiv = event.element();
	if (parentDiv.className.endsWith(parentDiv.className,"Active"))
		parentDiv.className=parentDiv.className.sub("Active","");
	nd();
}

function hideOverlay(event)
{
	nd();
}

function visibilityInfo(event)
{
	var parentDiv = event.element();
	if (parentDiv.className =="dtvis_private")
	    showinfo("Ez az adat titkos, kattints, hogy megváltoztasd.");
	else
	if (parentDiv.className =="dtvis_outer")
		showinfo("Ezt az adatot a külső kör tagjai láthatják, kattints, hogy megváltoztasd.",160);
	else
	if (parentDiv.className =="dtvis_inner")
		showinfo("Ezt az adatot a belső kör tagjai láthatják, kattints, hogy megváltoztasd.", 160);
	else	
	if (parentDiv.className =="dtvis_reg")
	    showinfo("Ezt az adatot minden regisztrált tag láthatja, kattints, hogy megváltoztasd.", 190);
	else
    	showinfo("Ez az adat publikus, mindenki láthatja (regisztráció nélkül is!), kattints, hogy megváltoztasd.");
}

function changeVisibility(event)
{
	var parentDiv = event.element();
	if (parentDiv.className =="dtvis_public")
	{
		parentDiv.className ="dtvis_reg";
		parentDiv.childNodes[0].value=1;
	}
	else
	if (parentDiv.className =="dtvis_reg")
	{
		parentDiv.className ="dtvis_outer";
		parentDiv.childNodes[0].value=2;
	}
	else
	if (parentDiv.className =="dtvis_outer")
	{
		parentDiv.className ="dtvis_inner";
		parentDiv.childNodes[0].value=3;
	}
	else
	if (parentDiv.className =="dtvis_inner")
	{
		parentDiv.className ="dtvis_private";
		parentDiv.childNodes[0].value=4;
	}
	else
	{
		parentDiv.className ="dtvis_public";
		parentDiv.childNodes[0].value=0;
	}
	
	hideOverlay(event);
	visibilityInfo(event);
}



/* 
-------------------------------------------------------------------------
>>>>>>>>>>>>>>>>      General purpose functions     <<<<<<<<<<<<<<<<<<<<<<<
-------------------------------------------------------------------------
*/

function editor(name, size, mode, maxmin, skin, trySave)
{   	
	var conf="AMHBasic";
	if (mode!=null)
	{
		if (mode=="admin")
			conf = "AMHAdmin";
		if (mode=="news")
			conf = "AMHNews";
	}
	var heightExp=(size*50).toString()+"px";
	
	CKEDITOR.on( 'instanceReady', function( ev )
     {
           if ($('focus')!=null)
				scrollToElement($('focus'));	  
     });
	 var skinFile='../design/'+skin+'/editor.css';
	CKEDITOR.replace(name,
    {
		width: '100%',
		height: heightExp,
		skin : 'office2003',
		toolbar: conf,
		contentsCss: skinFile,
		filebrowserUploadUrl : 'newsupload.php',
		filebrowserBrowseUrl : 'browsepic.php'
	});
	
	if (maxmin)
	{
		var editor = CKEDITOR.instances[name];
		editor.on( 'key', function( evt ){
			$(name+"_counter").innerHTML= evt.editor.getData().replace(/<[^>]*>|\s/g, '').length;
			}, editor.element.$ );
	}
		 
	if (trySave)
	{
		CkEditorInstanceName=name;
		Event.observe($(name).form, 'submit', checkForm);	
	}	
	
	
	CKEDITOR.instances[name].on( 'paste', function( evt )
			{
				var data = evt.data,
					mswordHtml;
	
				mswordHtml = data[ 'html' ];
				if (!( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) )
				{				
					mswordHtml=mswordHtml.replace(/(style=\"[^\"]*\")/g,"");
					mswordHtml=mswordHtml.replace(/(class=\"[^\"]*\")/g,"");
					mswordHtml=mswordHtml.replace(/(<script=[>]*\/>)/g,"");		
					data[ 'html' ]=mswordHtml;
				}
			});
}

var CkEditorInstance="";

function checkForm(submissionEvent)
{    	
	try
				{					
					var trySaveClipboard=false;
					if (CKEDITOR.env.ie)
					{
						var doc = CKEDITOR.instances[CkEditorInstanceName].document,						
						body = doc.getBody();
						var	enabled = false;
						var onExec = function()
						{
							enabled = true;
						};

						body.on( 'copy', onExec );
						doc.$.execCommand( 'SelectAll');
						doc.$.execCommand( 'copy' );
						body.removeListener( 'copy', onExec );
						trySaveClipboard= enabled;
					}
					else
					{						
						CKEDITOR.instances[CkEditorInstanceName].document.$.execCommand( 'SelectAll');
						trySaveClipboard=CKEDITOR.instances[CkEditorInstanceName].document.$.execCommand( 'copy' );
					}
				}
				catch( e )
				{					
					trySaveClipboard=false;
				}
				
	if (!trySaveClipboard)
		alert("Sajnos nem sikerült automatikusan a vágólapra másolni a szöveget.\r\nEllenőrizd a böngésző beállításait!");
}

function showinfo(text, width)
{
	if (width==null) width="210";
	overlib(text,WRAP,WRAPMAX,width);
}

function addProfile(userid,nick)
{
	//for ajax only
	return "<a href=\"profile.php?id="+userid+"\">"+ nick +"</a>";
}

function scrollToElement(element)
{
	var pos = element.cumulativeOffset();
	$('cnt').scrollTop=pos[1];
}

var reloadTimer=null;
var reloadAddress=null;
function redirect(url, timeout, replace)
{
	if (replace!=null)
	{
		if (timeout)
			timedReload("document.location.href='"+url+"'",timeout); 
		else
			timedReload("document.location.href='"+url+"'",5000); 
	}
	else
	{
		if (timeout)
			timedReload("document.location.replace('"+url+"')",timeout); 
		else
			timedReload("document.location.replace('"+url+"')",5000); 
	}
}

function fastredirect(url, replace)
{
	if (replace!=null)
		timedReload("document.location.href='"+url+"'",1000); 
	else
		timedReload("document.location.replace('"+url+"')",1000); 
}

function goback(counter, timeout)
{
	if (timeout)
		timedReload("window.history.go(-"+counter+")",timeout); 
	else
		timedReload("window.history.go(-"+counter+")",5000); 
}

function timedReload(url, time)
{
	reloadTimer=setTimeout(url, time); 
	reloadAddress=url;
}

function showmenu(event)
{
	if (hallMenuTimer!=null)
	{
		clearTimeout(hallMenuTimer);
		hallMenuTimer=null;
	}
		
	hallMenuTimer= setTimeout("showmenuEx()",700); 
}

var hallMenuTimer=null;
var menuVisible=false;

function hidemenu(events)
{
	if (hallMenuTimer!=null)
	{
		clearTimeout(hallMenuTimer);
		hallMenuTimer=null;
	}
	
	if (hallMenuTimer==null)
		hallMenuTimer= setTimeout("hidemenuEx()",600); 
}

function showmenuEx()
{		
	menuVisible=true;
	var pos = $('hall').cumulativeOffset();
	var scroll = $('hall').cumulativeScrollOffset();
	pos[0]=pos[0]-scroll[0];
	pos[1]=pos[1]-scroll[1];
	
	var width = $('hall').getWidth();
	var height = $('hall').getHeight();

	$('hm_prose').style.display="block";
	$('hm_prose').style.top =(pos[1])+"px";;
	$('hm_prose').style.left = (pos[0]-32)+"px";;
	
	$('hm_poem').style.display="block";
	$('hm_poem').style.top = (pos[1]-30)+"px";;
	$('hm_poem').style.left = (pos[0]-14)+"px";;
	
	$('hm_photo').style.display="block";
	$('hm_photo').style.top = (pos[1]-36)+"px";;
	$('hm_photo').style.left = (pos[0]+width/2-18)+"px";;
	
	$('hm_pic').style.display="block";
	$('hm_pic').style.top = (pos[1]-30)+"px";;
	$('hm_pic').style.left = (pos[0]+width-24)+"px";;
	
	$('hm_other').style.display="block";
	$('hm_other').style.position = "absolute";
	$('hm_other').style.top = pos[1]+"px";
	$('hm_other').style.left = (pos[0]+width)+"px";;

	clearTimeout(hallMenuTimer);
		hallMenuTimer=null;	
}

function hidemenuEx()
{
	$('hm_prose').style.display="none";	
	$('hm_poem').style.display="none";
	$('hm_photo').style.display="none";
	$('hm_pic').style.display="none";		
	$('hm_other').style.display="none";	
	clearTimeout(hallMenuTimer);
	hallMenuTimer=null;
	menuVisible=false;
}

function updatemenu(events)
{
	// TODO: update menu when it is visible and we scroll the page
	if (menuVisible)
		showmenuEx();
}



/* 
------------------------------------------------------
>>>>>>>>>>>>>>>>     Navbar functions     <<<<<<<<<<<<<<<<<<<<<<<
------------------------------------------------------
*/

function showNavBar(events)
{
	if (navBarTimer!=null)
		clearTimeout(navBarTimer);
		
	$('navbar').style.width="120px";
	$('navmenu').style.display="block";
	$('navthumb').style.display="none";
}

var navBarTimer=null;
var navAlwayson=false;

function hideNavBarWithDelay(events)
{
	if (!navAlwayson)
		navBarTimer=setTimeout("hideNavBar()",300);
}

function hideNavBar()
{
	$('navbar').style.width="20px";
	$('navmenu').style.display="none";
	$('navthumb').style.display="block";
}

function shownavpin(event)
{
	if ($('navpin').className=="dyn")
		showinfo("Az Navipanel dinamikusan jelenik meg. Kattints, hogy megváltoztasd!");
	else
		showinfo("Az Navipanel mindig látszik. Kattints, hogy megváltoztasd!");
}

function changenavpin(event)
{
	if ($('navpin').className=="dyn")
	{
		$('navpin').className="stat";
		updatenavstate();
		shownavpin(null);
	}
	else
	{
		$('navpin').className="dyn";
		updatenavstate();
		shownavpin(null);
	}	
	
	new Ajax.Request("updater.php?mode=navpin");
}

function updatenavstate()
{
	if ($('navpin')!=null)
	{
		hideOverlay(null);		
		navAlwayson=$('navpin').className!="dyn";
		if ($('navpin').className=="dyn")
		{
			$('cnt').className="";
			$('contentblock').style.paddingLeft="20px";
			hideNavBar();
		}
		else
		{
			$('navbar').style.width="120px";
			$('navmenu').style.display="block";
			$('navthumb').style.display="none";
			$('cnt').className="navshift";
			$('contentblock').style.paddingLeft="0px";
		}
	}
}


























function mod(id)
{
  overlib('<div class="confirmpopup"><center>Biztosan törlöd?<br>'+
		'<input type="button" value="Igen" onClick="mod2('+id+')">'+
		'<input type="button" value="Nem" onClick="cClick()"></div>', 
		OFFSETX, -10, OFFSETY, 15, STICKY, CAPTION, 'Jóváhagyás', MODAL, NOCLOSE, MODAL);
}

function report(id)
{
  overlib('<div class="confirmpopup"><center>Biztosan jelented?<br>'+
		'<input type="button" value="Igen" onClick="report2('+id+')">'+
		'<input type="button" value="Nem" onClick="cClick()"></div>', 
		OFFSETX, -10, OFFSETY, 15, STICKY, CAPTION, 'Jóváhagyás', NOCLOSE, MODAL);
}





var temp_f;
if( window.onload ) {
    temp_f = window.onload;
}

window.onload = function() 
{
	if( temp_f ) {
        temp_f();
    }
	
	var url = "notifications.php";
	var pars = "";				
			new Ajax.PeriodicalUpdater('footerblock', 
			url, { method: 'get', frequency: 60, decay: 2, parameters: pars, 
			insertion: notification});
}	
	
function notification(element, originalRequest)
{	
	if (originalRequest!='[""]')
	{
		if (reloadTimer!=null)
			clearTimeout(reloadTimer);
			
		overlib(originalRequest.evalJSON(true), CENTER,MIDX,0,MIDY,0,WRAP,WRAPMAX,500,STICKY,CLOSECLICK, CLOSETEXT,'x',CAPTION, 'Üzenet', MODAL);
	}
}

function reloadtimer()
{
	if (reloadAddress!=null)
		timedReload(reloadAddress, 1000);
}


function InitCustomControls()
{  
   var divs=$$('.ddlv');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('click',togglelist);
  }
  
  var divs=$$('.dropdown dd ul li');
  for(i=0;i<divs.length;i++)
  {
	    divs[i].observe('click',selectitem);
  }
  
  var divs=$$('.dropdown dd');
  for(i=0;i<divs.length;i++)
  {
	   divs[i].style.display="none";
  }
 
  Event.observe(document,'keypress',keyproc);
  Event.observe(document,'keydown',keyproc2);  
  Event.observe(document,'click', closeddl);
    
  //Set init value
   var divs=$$('.dropdown');
   		for(i=0;i<divs.length;i++)
		{		
			var currValue= divs[i].childNodes[0].value;
			var currName= divs[i].childNodes[0].name;			
			var itemList = divs[i].childNodes[divs[i].childNodes.length-1].childNodes[0].childNodes;
			var itemSelected = false;			
			if (currValue !=-1)
			{			
				for(j=0;j<itemList.length;j++)
					if (itemList[j]!=undefined&&itemList[j].childNodes.length>1)
					{
						if (itemList[j].childNodes[0].value == currValue)
						{
							$("_"+currName).innerHTML= itemList[j].childNodes[1].data;
							itemSelected=true;
							break;
						}				
					}
			}
					
			if (!itemSelected&&itemList[0].childNodes[1]!=undefined)
			{
				//No item selected, first item will be
				$("_"+currName).innerHTML= itemList[0].childNodes[1].data;
				divs[i].childNodes[0].value=itemList[0].childNodes[0].value;
			}
		}
}

function refreshalldropdown()
{
	var divs=$$('.dropdown');
   	for(i=0;i<divs.length;i++)
	{	
			var currValue= divs[i].childNodes[0].value;
			var currName= divs[i].childNodes[0].name;			
			var itemList = divs[i].childNodes[divs[i].childNodes.length-1].childNodes[0].childNodes;
			var itemSelected = false;			
			if (currValue !=-1)
			{			
				for(j=0;j<itemList.length;j++)
					if (itemList[j]!=undefined&&itemList[j].childNodes.length>1)
					{
						if (itemList[j].childNodes[0].value == currValue)
						{
							$("_"+currName).innerHTML= itemList[j].childNodes[1].data;
							itemSelected=true;
							break;
						}				
					}
			}
					
			if (!itemSelected&&itemList[0].childNodes[1]!=undefined)
			{
				//No item selected, first item will be
				$("_"+currName).innerHTML= itemList[0].childNodes[1].data;
				divs[i].childNodes[0].value=itemList[0].childNodes[0].value;
			}
	}
}

function closeddl(event)
{
	var ancestors=event.element().ancestors();
	for(i=0;i<ancestors.length;i++)
	{
		if (ancestors[i].className=="dropdown")
			return;
	}
	
	var divs=$$('.dropdown dd');
	for(j=0;j<divs.length;j++)
	{		
		divs[j].style.display="none";
		activeList=null;
	}
}

function togglelist(event)
{
		list = event.element().up().up().nextSiblings();
		for (var i=0;i<list.length;i++)
			if (list[i].tagName=="DD")
			{
				ddtoggle(list[i]);	
				return;
			}
}

var lastKey="";
var activeList=null;
function keyproc(event)
{
  //no acitve list -> nothing to do   
  if (activeList==null) return;
    
  if (event.keyCode == Event.KEY_ESC)
  {
	lastKey = "";
  }
  else if (event.keyCode == Event.KEY_BACKSPACE)
  {
	lastKey = lastKey.substr(0, lastKey.length-1);	
  }
  else
  {
    if (event.charCode ==undefined)
	{		
		if (event.keyCode == 0) return;	
		lastKey += String.fromCharCode(event.keyCode).toLowerCase();			
	}
	else
	{
		if (event.charCode == 0) return;	
		lastKey += String.fromCharCode(event.charCode).toLowerCase();	
	}
  }
  
  $("_"+activeList.up().childNodes[0].name).innerHTML=lastKey;
  event.stop();
  
  updatefilter(activeList);
}

function updatefilter(list)
{  
			//TODO: save and fix width
					
			//iterate through the list items			
			var itemlist=list.childNodes[0].childNodes;

			for(j=0;j<itemlist.length;j++)
			{			
				if (itemlist[j]!=undefined&&itemlist[j].childNodes.length>1)
				{				
					if (lastKey!=""&&!itemlist[j].childNodes[1].data.toLowerCase().startsWith(lastKey))
					{
						itemlist[j].style.display="none";
						//break;
					}
					else
					{
						itemlist[j].style.display="block";
					}
				}
			}
}

function keyproc2(event)
{
    //Hack for IE
	if (event.keyCode==8)
	{			
		  if (activeList==null) return;
		  
		lastKey = lastKey.substr(0, lastKey.length-1);	
		$("_"+activeList.up().childNodes[0].name).innerHTML=lastKey;
		event.stop();
		updatefilter(activeList);
	}
}

function selectitem(event)
{
    var liItem = event.element();
	
	var fieldname=liItem.up().up().up().childNodes[0].name;	
	$("_"+fieldname).innerHTML=liItem.childNodes[1].data;
	lastKey ="";
	$(fieldname).value = liItem.childNodes[0].value;
	ddtoggle(liItem.up().up());
	
	var changeFunc= liItem.up().up().up().childNodes[1].value;
	if (changeFunc != undefined)
	{
				eval(changeFunc);
	}
}

function ddtoggle(item)
{
	if (item.style.display=="block")
	{
		item.style.display="none";
		lastKey = "";
		
		var itemList = item.childNodes[0].childNodes;
		for(j=0;j<itemList.length;j++)
				if (itemList[j]!=undefined&&itemList[j].childNodes.length>1)
					if (itemList[j].className.indexOf("sel")>=0)
						itemList[j].className=itemList[j].className.substr(0, itemList[j].className.length-3);
						
		activeList = null;
	}
	else
	{
		 //hide others
		 var divs=$$('.dropdown dd');
		for(i=0;i<divs.length;i++)
		{		
			divs[i].style.display="none";
		}
	
		item.style.display="block";
		lastKey = "";
		updatefilter(item);
						
		//Set selected
		if (item.up().childNodes[0].value!="")
		{
			var currValue= item.up().childNodes[0].value;
			var itemList = item.childNodes[0].childNodes;
			for(j=0;j<itemList.length;j++)
				if (itemList[j]!=undefined&&itemList[j].childNodes.length>1)
					if (itemList[j].childNodes[0].value == currValue)
					{
						itemList[j].className+="sel";
						
						//scrollTo	
						var pos = itemList[j].cumulativeOffset();
						var pos2=item.cumulativeOffset();
						item.childNodes[0].scrollTop=pos[1]-pos2[1];
						break;
					}
					
			activeList = item;
		}
	}
}











