// AU private practice search

var disciplinesShowing = "";


function au_pp_searchPrep() {
	if (!document.getElementById) { return; }
	if (!document.getElementById("specificationHolder")) { return; }
	if (!document.getElementById("searchForm")) { return; }
	var ajax = GetXmlHttpObject();
	if (!ajax) { return; }

	var frm = document.getElementById("searchForm");

	// apply the onClick to the radio buttons
	var inputs = frm.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].getAttribute("type").toLowerCase()=="radio") {
			inputs[i].onclick = function() {
				showDisciplines(this);
			}	
		}
		// change submit button
		if (inputs[i].getAttribute("type").toLowerCase()=="submit") {
			inputs[i].setAttribute("value","Search")
		}
	}
	// set the default location choice (via javascript so that if its turned off, the users option holds when pressing 'Back'
	document.getElementById("searchForm").location[1].checked = true;
	// Show the correct disciplines
	showDisciplines("");
}

function showDisciplines(thisLocation) {
	// get the location choice
	var loc="";
	if (thisLocation=="") {
		for (var i=0; i < document.getElementById("searchForm").location.length; i++) {
			if (document.getElementById("searchForm").location[i].checked) {
				var loc = document.getElementById("searchForm").location[i].value;
			}
		}
	}
	if (loc=="") {
		loc = thisLocation.getAttribute("value");
	}
	// disciplinesShowing tells the script which list is currently loaded - so that when another location is clicked, 
	// the list loads only if necessary. Otherwise selected discipline options will be lost.
	if (disciplinesShowing.indexOf(loc)==-1) {
		if (loc=="1" || loc=="2") {
			disciplinesShowing = "1,2";
		}
		else if (loc=="3" || loc=="4") {
			disciplinesShowing = "3,4";
		}
		// load the list page via ajax
		var spc = GetXmlHttpObject();
		var url="specList.asp?location="+loc;
		url=url+"&randomid="+Math.random();
		spc.onreadystatechange= function() {showDiscChanged(spc)};
		spc.open("GET",url,true);
		spc.send(null);
	}
}

function showDiscChanged(spc) {
	if (spc.readyState==4) {
		if (spc.status==200 || spc.status==304) {
			if (spc.responseText.indexOf("[error]") == -1) {
				// put in the specialisation list
				document.getElementById("specificationHolder").innerHTML = spc.responseText;
				document.getElementById("specificationHolder").style.display="inline"; document.getElementById("specificationHolder").style.display="block"; //Required to stop IE6 from hiding the form
				// If all successful, change the form action URL
				document.getElementById("searchForm").setAttribute("action","results.asp");
			}
		}
		else { alert('Error: '+spc.responseText) }
}
}


// END AU private practice search


