var comboboxEl = null;
var popEl = null;

function comboboxShow(el) {
	comboboxEl = el;
	
	comboboxShowPopup();
	
	if (event!=null) {
		event.returnValue = false;
		event.cancelBubble = true;
	}		
}

function comboboxShowPopup() {
	//if (popEl==null) {
		popEl = window.createPopup();
	//}
	
	//get hidden table
	var dataEl = comboboxEl.nextSibling.children[0];
	
	if (dataEl!=null) {
		if (dataEl.comboboxData!=null) {
			var txtVal = comboboxEl.rows[0].cells[0].children[0].value;
			
			var dupeEl = dataEl.cloneNode(true);
			var dupeSel = dupeEl.rows[0].cells[0].children[0];
			
			/*
			===============================
			FILTERING
			===============================
			var x = 0;
			while(x<dupeSel.options.length) {
				if (dupeSel.options[x].value.toLowerCase().indexOf(txtVal.toLowerCase()) == -1) {
					dupeSel.options.remove(x);
				}
				else {
					x++;
				}
				
			}
			===============================
			*/
			
			dupeEl.rows[0].cells[0].children[0].value = txtVal;
			dupeEl.rows[0].cells[0].children[0].onchange = 'parent.window.execScript(\'comboboxUpdate("\'+this.value+\'");\')';
				
			popEl.document.write('<html><head><link rel=\'stylesheet\' type=\'text/css\' href=\'style/combobox.css\'><style type=\'text/css\'>BODY { margin: 0 0 0 0; padding: 0 0 0 0; border: 0 0 0 0; } TABLE { font-size: 10px; } </style></head><body scroll=\"no\">'+dupeEl.outerHTML+'</body></html>');
			//popEl.document.close();
	
			popEl.document.body.style.border = 'none';
			//popEl.document.recalc();
			
			popEl.show(getRealLeft(comboboxEl)+2, getRealTop(comboboxEl)+comboboxEl.offsetHeight+1-document.body.scrollTop, 200, 136, document.body);
			
		}
	}
}

function comboboxUpdate(text) {	
	comboboxEl.rows[0].cells[0].children[0].value = text;
	
	if (popEl!=null) {
		if (popEl.isOpen) {
			popEl.hide();
		}
	}	
}
