function load_file_in_div(filename,div) {
	ajax_include(filename,div);
}
function ajax_include(url, target) {
  document.getElementById(target).innerHTML = '<img src="../../images/icons/indicator.gif" alt="getting data" />';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ajax_write_content(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}
function ajax_write_content(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" Ajax error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}
/* -------------------------------------------------------------------------------------------- */
function stat_open_window(stat_url) {
	var screenWidth = screen.availWidth*90/100;
	var screenHeight = screen.availHeight*80/100;
	var posLeft = (screen.availWidth - screenWidth)/2;
	var posTop = (screen.availHeight - screenHeight)/4;
	var wndwStatResults = window.open(stat_url,"wndwStatResults","scrollbars,toolbar=yes,status,titlebar,menubar=yes,resizable,height="+screenHeight+",width="+screenWidth+",screenX=0,screenY=0,left="+posLeft+",top="+posTop);
	wndwStatResults.focus();
}
/* -------------------------------------------------------------------------------------------- */
function onclick_stat_year() {
	stat_year = getCheckedValue(document.frm_statistics.stat_year);
	if (stat_year >= 2010) {
		load_file_in_div('stat_type_2.htm','fldset_type'); // bevat dashboard
		//load_file_in_div('stat_type.htm','fldset_type');
		window.location.hash = "page_bottom";
	} else {
		load_file_in_div('stat_type.htm','fldset_type');
		window.location.hash = "page_bottom";
	}
}
function onclick_stat_type(stat_type) {
	document.getElementById('fldset_detail').innerHTML = '';
	switch (stat_type) {
		case 'yearexpenses':
			stat_year = getCheckedValue(document.frm_statistics.stat_year);
			if (stat_year != false) {
				stat_open_window(stat_year + '/yearexpenses/yearexpenses_per_gov_' + stat_year + '.htm');
				document.getElementById('fldset_detail').innerHTML = '';
			}			
			break;
		case 'yearexpenses_dep':
			stat_year = getCheckedValue(document.frm_statistics.stat_year);
			if (stat_year != false) {
				stat_open_window(stat_year + '/yearexpenses/yearexpenses_per_gov_per_dep_' + stat_year + '.htm');
				document.getElementById('fldset_detail').innerHTML = '';
			}			
			break;
		case 'governmentgroup':
			load_file_in_div('stat_' + stat_type + '.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'nnr':
			load_file_in_div('stat_' + stat_type + '.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'overview':
			load_file_in_div('stat_pensiontype.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'overview_dep':
			load_file_in_div('stat_pensiontype.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'reason':
			load_file_in_div('stat_' + stat_type + '.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'graph':
			load_file_in_div('stat_' + stat_type + '.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
		case 'dashboard':
			load_file_in_div('stat_' + stat_type + '.htm','fldset_detail');
			window.location.hash = "page_bottom"
			break;
	}
}
function onclick_stat_governmentgroupcd() {
	governmentgroupcd = getCheckedValue(document.frm_statistics.stat_governmentgroupcd);
	if (governmentgroupcd == 'all') {
		load_file_in_div('stat_pensiontype.htm','fldset_governmentcd');		
	} else {
		load_file_in_div('stat_government_' + governmentgroupcd + '.htm','fldset_governmentcd');
	}
	window.location.hash = "page_bottom"
}
function onclick_stat_governmentcd() {
	load_file_in_div('stat_pensiontype.htm','fldset_pensiontype');
	window.location.hash = "page_bottom"
}
function onclick_stat_reason_governmentgroupcd() {
	governmentgroupcd = getCheckedValue(document.frm_statistics.stat_reason_governmentgroupcd);
	if (governmentgroupcd == 'all') {
		document.getElementById('fldset_governmentcd').innerHTML = '';
		show_stat_results();
	} else {
		load_file_in_div('stat_reason_government_' + governmentgroupcd + '.htm','fldset_governmentcd');
	}
	window.location.hash = "page_bottom"
}
function onclick_stat_reason_governmentcd() {
	show_stat_results();
}
function onclick_stat_nnr() {
	load_file_in_div('stat_pensiontype.htm','fldset_pensiontype');
	window.location.hash = "page_bottom"
}
function onclick_stat_pensiontype() {
	load_file_in_div('stat_career.htm','fldset_career');
	window.location.hash = "page_bottom"
}
function onclick_stat_career() {
	show_stat_results();
}
function onclick_stat_graph() {
	show_stat_results();
}
function onclick_stat_dashboard() {
	show_stat_results();
}
function show_stat_results() {
	stat_year = getCheckedValue(document.frm_statistics.stat_year);
	stat_type = getCheckedValue(document.frm_statistics.stat_type);
	stat_nnr = getCheckedValue(document.frm_statistics.stat_nnr);
	stat_governmentgroupcd = getCheckedValue(document.frm_statistics.stat_governmentgroupcd);
	stat_governmentcd = getCheckedValue(document.frm_statistics.stat_governmentcd);
	stat_reason_governmentgroupcd = getCheckedValue(document.frm_statistics.stat_reason_governmentgroupcd);
	stat_reason_governmentcd = getCheckedValue(document.frm_statistics.stat_reason_governmentcd);
	stat_pensiontype = getCheckedValue(document.frm_statistics.stat_pensiontype);
	stat_career = getCheckedValue(document.frm_statistics.stat_career);
	stat_graph = getCheckedValue(document.frm_statistics.stat_graph);
	stat_dashboard = getCheckedValue(document.frm_statistics.stat_dashboard);
	//
	if (stat_type == 'overview') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + '_count_pnr_' + stat_pensiontype + '_all_all_' + stat_career + '_' + stat_year + '.htm';
	} else if (stat_type == 'overview_dep') {
		$url = stat_year + '/' 
			  + 'overview' + '/'
			  + stat_type + '_count_pnr_' + stat_pensiontype + '_all_all_' + stat_career + '_' + stat_year + '.htm';
	} else if (stat_type == 'graph') {
		if (stat_year < 2010) {
			$url = stat_year + '/' 
				  + stat_type + '/'
				  + stat_graph + '.htm';
		} else {
			$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_graph + '.html';			
		}
	} else if (stat_type == 'dashboard') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_dashboard + '.html';
	} else if (stat_type == 'reason' && stat_reason_governmentgroupcd == 'all') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + '_all_all.htm';
	} else if (stat_type == 'reason') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + '_' + stat_reason_governmentgroupcd + '_' + stat_reason_governmentcd + '.htm';
	} else if (stat_type == 'nnr') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + stat_nnr + '_' + stat_pensiontype + '_' + stat_career + '_' + stat_year + '.htm';
	} else if (stat_governmentgroupcd == 'all') {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + '_' + stat_pensiontype + '_' + stat_governmentgroupcd + '_all_' + stat_career + '_' + stat_year + '.htm';
	} else {
		$url = stat_year + '/' 
			  + stat_type + '/'
			  + stat_type + '_' + stat_pensiontype + '_' + stat_governmentgroupcd + '_' + stat_governmentcd + '_' + stat_career + '_' + stat_year + '.htm';
	}
	//alert($url);
	//
	stat_open_window($url);
}

