//////////////////////////////////////////////////////////////////////////////

function initialiseDropdowns(selected) {
	
	var careType = document.searchForm.careType.options[document.searchForm.careType.options.selectedIndex].value;
	var county = document.searchForm.county.options[document.searchForm.county.options.selectedIndex].value;
	var town = document.searchForm.town.options[document.searchForm.town.options.selectedIndex].value;
	var url = 'search_form.php?refreshing=1&selected=' + selected + '&careType=' + careType + '&county=' + county + '&town=' + town;
	loadURL(url, 'box');
}

//////////////////////////////////////////////////////////////////////////////

function loadURL(destination, elementID) {
	
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) { /* do nothing */ }
	
	element = elementID;
	xmlhttp.onreadystatechange = triggered;
	xmlhttp.open("GET", destination, true);
	xmlhttp.send(null);
}

//////////////////////////////////////////////////////////////////////////////

function triggered() {
  	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    
		if( xmlhttp.responseText && (xmlhttp.responseText !='') ) {
			try {	
				document.getElementById(element).innerHTML = xmlhttp.responseText;
			}
			catch(e) {
				// IE fails unless we wrap the string in another element.
				var wrappingDiv = document.createElement('div');
				wrappingDiv.innerHTML = xmlhttp.responseText;
				document.getElementById(element).appendChild(wrappingDiv);
			}
		}
	}
}

//////////////////////////////////////////////////////////////////////////////

function validateForm(formID) {

	var town = document.forms['form_' + formID].town.options[document.forms['form_' + formID].town.options.selectedIndex].value;
	if( town == 0 ) {
		alert('Please select a town');
		return false;
	
	} else return true;
}

//////////////////////////////////////////////////////////////////////////////
