function refresh_homes() {
	var type = document.getElementById('home_type').value;
	refresh_homes_list(type);
}

function refresh_homes_list(type) {

	// show loading spinner
	show_loading_spinner('homes_list');
	
	if (!type) var type = 0;
	
	var url = getBase() + 'inc/homes_list.php?type=' + escape(type);
	
	// unhighlight all radios in options list
	var options_list = document.getElementById('home_types');
	// get all rows in the parent DIV
	var options_list_inputs = options_list.getElementsByTagName('input');
	// remove class from all
	for (var i = 0; i < options_list_inputs.length; i++) {
	
		option_list_input = options_list_inputs[i];
		
		console.log(option_list_input.getAttribute('type'));
		
		if (option_list_input.getAttribute('type').value == 'radio') {
			// uncheck
			option_list_input.checked = false;
		}	
		
	}
	
	doAjaxRequest(url);
	
	function doAjaxRequest(url) {	
		// setup the ajax object, define the response handler and send the data
		http = createAjaxObject();
		http.open('GET', url);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}
	
	function handleResponse() {
		if (http.readyState == 4) {
		
			document.getElementById('homes_list').innerHTML = http.responseText;
			
			var home_type_id = 'home_types_' + type;
			if (document.getElementById(home_type_id)) {
				document.getElementById(home_type_id).checked = true;
			}
		}
	}
	
	return false;
	
}

function get_profile(id) {

	if (!document.getElementById('profile_list')) { return false; }
	if (!document.getElementById('get_profile')) { return false; }

	if (!id) id = 0;
	
	// show loading spinner
	show_loading_spinner('get_profile');

	// if not set, set to 1st in list
	if (!id) id = document.getElementById('first_profile_id').value;
	
	var url = getBase() + 'inc/get_profile.php?id=' + escape(id);

	// unhighlight all names in list
	var profile_list = document.getElementById('profile_list');
	// get all rows in the parent DIV
	var profile_rows = profile_list.getElementsByTagName('div');
	// remove class from all
	for (var i = 0; i < profile_rows.length; i++) {
		profile_row = profile_rows[i];
		// remove class
		profile_row.className = profile_row.className.replace(/selected/g,'');
	}
	
	doAjaxRequest(url);
	
	function doAjaxRequest(url) {	
		// setup the ajax object, define the response handler and send the data
		http = createAjaxObject();
		http.open('GET', url);
		http.onreadystatechange = handleResponse;
		http.send(null);
	}
	
	function handleResponse() {
		if (http.readyState == 4) {
			document.getElementById('get_profile').innerHTML = http.responseText;
			// highlight name in list
			document.getElementById('profile_row_' + id).className += ' selected';
		}
	}
	
	return false;
	
}

function show_loading_spinner(element_id) {
	if (!document.getElementById(element_id)) { return false; }
	document.getElementById(element_id).innerHTML = '<p><img src="' + getBase() + 'images/loading.gif" alt="" /></p>';
}

function textResizingOptions() {

	if (document.getElementById('textsize_small') && 
		document.getElementById('textsize_medium') && 
		document.getElementById('textsize_large')) {

		document.getElementById('textsize_small').innerHTML = 'A';
		document.getElementById('textsize_medium').innerHTML = 'A';
		document.getElementById('textsize_large').innerHTML = 'A';
	}
}

addLoadEvent(textResizingOptions);
addLoadEvent(get_profile);