function init_applicant_filter(){
	var selects = new Array();
	selects[0] = e('filter-select-town');
	selects[1] = e('filter-select-village');
	selects[2] = e('filter-select-fire');
	selects[3] = e('filter-select-school');
	
	var i;
	for(i in selects) {
		selects[i].prev = get_selected(selects[i]);
		
		selects[i].onchange = function() {
			var next = get_selected(this);
			if(next[0]) {
				var count = 0;
				var j;
				for(var j = 1; j < this.prev.length; j++) {
					if((next[j] != this.prev[j]) && next[j]) {
						count++;
					}
				}
				if(count) {
					this.options[0].selected = false;
				}
				else {
					this.options[0].selected = true;
					for(var j = 1; j < this.prev.length; j++) {
						this.options[j].selected = false;
					}
				}
			}
			this.prev = get_selected(this);
		}
	}
}

/**
 * Similar principle to its counter-part in datagrid2.js, only the content panes will be loaded using ajax
 */
function datagrid_tabs_ajax(tab_id, tbody_id, num, col) {
	var tabs = new Array();
	var tbodys = new Array();
	var actions = new Array('notes','activity','residency');
	
	var current = -1;
	
	var close_tab = function(index) {

		rem(tabs[index].parentNode, 'open');
		add(tbodys[0], 'disHide');
	}
	
	var open_tab = function(index) {
		add(tabs[index].parentNode, 'open');
		rem(tbodys[0], 'disHide');
		hr_details(actions[index], num, tbody_id+'0', col);
	}

	for(var i = 0; i < 3; i++) {
		var tab = e(tab_id + i);
		var tbody = e(tbody_id + i);
		
		tbodys[i] = tbody;
		if(tab) {
			tabs[i] = tab;
			tab.i = i;
			tab.act = actions[i];
			tab.onclick = function() {
				this.blur();
				if(current != -1) {
					close_tab(current);
				}
				if(this.i == current) {
					current = -1;
				}
				else {
					open_tab(this.i);
					current = this.i;
				}
				return false;
			}
		}
	}
}

function hr_details(desc, appid, targ, col){
	rem(e(targ), "disHide");
	e(targ).innerHTML= "<tr colspan='"+col+"'><td>loading...</td></tr>";
	var o=new Object();
	o.colspan = col;
	o.ajax=true;
	HTTPPost('/?q=/hr/lists/'+desc+'/'+appid, display_app_info, targ, o);
}


/**
 * AJAX loves callbacks so here it is... displays the info returned
 */
function display_app_info(answer, thing, targ){
	rem(e(targ), "loading");
	e(targ).innerHTML = answer;
}