/* 
dhtml ComboBoxes
created by : Maarten Dekker, Michael Sgaier 08-2006
 */

function cmb_closeAll() {
	 for(var i=0;i<_arCombos.length;i++) 
	 {
	 	var obj = document.getElementById('cmb_popup_' + _arCombos[i]);
	 	if (!obj) return;
		obj.className = obj.className.replace('_show', '_hide');
		obj.parentNode.style.zIndex = 2;
	}
}
function cmb_showPopup(combo, showMe) {
	// ! first check if its not allready open
	var obj = document.getElementById('cmb_popup_' + combo);
	var show = (showMe != false) && (obj) && (obj.className.search(/_hide$/i) >= 0);
	// now close all
	cmb_closeAll();
	// and open clicked when needed
	if (!obj) return;
	if (show) {
		obj.className = obj.className.replace('_hide', '_show');
		obj.parentNode.style.zIndex = 3;
	} else {
		obj.className = obj.className.replace('_show', '_hide');
		obj.parentNode.style.zIndex = 2;
	}
}
function cmb_showCustom(combo, showMe) {
	// ! first check if its not allready open
	var obj = document.getElementById('cmb_custom_' + combo);
	if (obj) {
		var show = ((showMe != false) && obj);
		obj.style.display = show ? 'block' : 'none';
		if (show) obj.firstChild.focus();
	}
}
function cmb_setComboValue(combo,value) {
	var objVal = document.getElementById(combo);
	if (objVal) objVal.value = value;
}
function cmb_setComboLabel(combo,label) {
	var objLabel = document.getElementById('cmb_input_' + combo);
	if (objLabel) objLabel.innerHTML = label;
}
function cmb_selectOption(combo,value,label,func) {
	cmb_setComboValue(combo,value);
	cmb_setComboLabel(combo,label);
	cmb_showPopup(combo,false);
	cmb_showCustom(combo,(value == '__custom'));	
	if (func != undefined && window[func]) {
		window[func](value);
	}
}
function cmb_escapeClick(e)
// clicks outside comboboxes
{	
	if (isInternetExplorer()) e = window.event;
	var target = (isInternetExplorer()) ? e.srcElement : e.target;	
	if (!target.id || !target.id.match(/^cmb_/i))
	{
		cmb_closeAll();
		e.cancelBubble = true;
	}
}
var _arCombos = new Array();
document.onclick = anyClick; //cmb_escapeClick;
