function handleDDOpen(oDiv) {
	if (!oDiv.getAttribute('listOpened')) {
		handleDDCloseAll();
		if (oDiv.style.zIndex!='1000') {
			oDiv.style.zIndex='1000';
			oDiv.firstChild.style.marginTop=0;
			
			oDiv.style.overflow='auto';
			oDiv.style.height='150px';
			oDiv.setAttribute('oldWidth', oDiv.style.width);
			oDiv.style.width='300px';
			oDiv.scrollTop=document.getElementById(oDiv.getAttribute('selectedId')).offsetTop;
		}
		oDiv.setAttribute('listOpened', true);
		return false;
	} else {
		return true;
	}
}

function handleDDCloseAll() {
	DDs=document.getElementsByTagName('div');
	for (var i=0; i<DDs.length; i++) {
		var curDiv=DDs.item(i);
		if (curDiv.className=='divSelect') {
			handleDDClose(curDiv);
		}
	}
}

function searchParent(o, className) {
	if (o.className==className) {
		return o;
	} else if (o.parentNode!=null && o.parentNode.tagName!=undefined && o.parentNode.tagName.toLowerCase()!='body') {
		return searchParent(o.parentNode, className);
	} else {
		return null;
	}
}

function handleDDClose(oDiv) {
	var oLink=null;
	if (oDiv.getAttribute('selectedId')) {
		oLink=document.getElementById(oDiv.getAttribute('selectedId'));
	} else {
		oLink=document.getElementById(oDiv.id+"_"+0);
	}
	
	oDiv.style.overflow='hidden';
	//alert(oDiv.getAttribute('oldWidth'));
	oDiv.style.width=oDiv.getAttribute('oldWidth');
	oDiv.style.height='18px';
	
	oDiv.firstChild.style.marginTop=(parseInt(oDiv.firstChild.style.marginTop, 10) -oLink.offsetTop)+'px';
	oDiv.style.zIndex='1';
	oDiv.setAttribute('listOpened', null);
}

function divSelectedIndex(idDiv, idx) {
	var oDiv=document.getElementById(idDiv);
	oDiv.firstChild.style.marginTop=(-document.getElementById(idDiv+'_'+idx).offsetTop)+'px';
	oDiv.setAttribute('selectedId', idDiv+'_'+idx);
	if (idx>=0) {
		var selDiv=document.getElementById(idDiv+'_'+idx);
		selDiv.className='selected';
	}
}

function handleBodyOnClick(e) {
	var target;
	if (document.all) {
		target=window.event.srcElement;
	} else {
		target=e.target;
	}

	var oDiv=searchParent(target, "divSelect");
	if (target.className=='linkDropDown') return false;

	if (!oDiv) {
		handleDDCloseAll();
	} else {
		return handleDDOpen(oDiv);
	}

	return true;
}