// JavaScript Document
$(document).ready(function() 
{	
	var url_1 = 'http://apps.acu.edu.au/~trevorg/pathways/';//used for the image
	var url_2 = 'http://www.acu.edu.au/international/study_options/interface';//used for ajax calls
	var dodgey = document.getElementById('lang').value;
	// Hide Submit button for AJAX form
	$("#submit-btn").hide();

	// Once the country has been selected trigger query
	$("#country").change(function() {
				
			// 0 = Please select we need it to ignore that
			if ($("#country").val() != 0) {

				// Clear results just in case
				$("#results").html("");
				// Show a nice loading message
				$("#educationresults").html('<p><img src="' + url_1 + 'images/ajax-loader.gif" width="32" height="32" /> Loading...</p>');
				
				// Run the query
				$.post( url_2 + "?lang=" + dodgey + "&method=education_list", {country: $("#country").val()}, 

				// Output the results to the screen
				function(output) { 
					$("#educationresults").html(output);
					
					// Once trigger is clicked request another Query
					$("#getResult").click(function() { 
						
						// Show a nice loading message
						$("#results").html('<p><img src="' + url_1 + 'images/ajax-loader.gif" width="32" height="32" /> Loading...</p><hr />');

			// Run the query
			$.post( url_2 + "?lang=" + dodgey + "&method=get_results", {country: $("#country").val(), education: $("#education").val(), ielts: $("#ielts").val(), course: $("#course").val()}, 
			function(output) { 
			
				// Output the results to the screen
				$("#results").html(output);
				
				// Append a <hr /> to make it look nice
				$("#results").append("<hr />");
				
				return false;
			});
						 
			});

			});	
		
		// Don't run the form
		return false;

		// If it does = 0 empty the two AJAX divs
		} else { $("#results").html(""); $("#educationresults").html(""); }

	});

});