$ = function (id) {
	if (typeof(id)!="string") return id;
	return document.getElementById(id);
}

function filterSelect(oSource,oTarget){
	if (oSource == null || oSource.selectedIndex<0) return false;
	id = oSource[oSource.selectedIndex].value
	if (id.indexOf(":")>-1) id = id.split(":")[1];
	options = oTarget.getElementsByTagName("option");
	optionsCache = oTarget._optionsCache.getElementsByTagName("option");
	
	var count = 0;
	var changed = false;
	//move from original to cache
	var selectedVal = "";
	for (var i=0;i<options.length;i++){
		if (options[i].value.indexOf(":")>-1){
			if (options[i].value.indexOf(id+":")!=0){
				options[i].selected = false;
				oTarget._optionsCache.appendChild(options[i])
				changed = true;
				i--;
			}
		}
	}
	//move from cache to original
	for (var i=0;i<optionsCache.length;i++){
		if (optionsCache[i].value.indexOf(id+":")==0){
			
			oTarget.appendChild(optionsCache[i]);
			changed = true;
			i--;	
		}
	}
	
	//removed this line because all is good.
	//if (changed) oTarget.options[0].selected = true;
	if (oTarget.onchange) oTarget.onchange();
}

function registerFilterSelect(sourceId,targetId){
	var source = $(sourceId);
	var target = $(targetId);
	target._optionsCache = target.cloneNode(false);
	target._optionsCache.id = target.id+"OptionsCache";
	var fn = function(){
		filterSelect(source,target);
	}
	source.onchange = fn;
	source.onkeyup = fn;
	fn();
}

function wireForm(elForm){
	var elForm = $(elForm);
	if (elForm) {
    	var fn = function(){
    		var el = document.getElementsByTagName("*");
    		for (var i=0;i<el.length;i++){
    			el[i].style.cursor = "wait";
    		}
    		//elForm.style.cursor = "wait";
    	}
    	if (!elForm.onsubmit) {
    		elForm.onsubmit = fn;
    	}
    }
}
