/*
	/scripts/enquirySelects.php?mode=country&country=france
	/scripts/enquirySelects.php?mode=region&country=france&region=paris
*/

function _getSelect(mode, country, region){

	var _url = "/scripts/enquirySelects.php";
	_url += "?mode=" + escape(mode);
	_url += "&country=" + escape(country);
	_url += "&region=" + escape(region);

	var _html = $.ajax({ type: "GET", url: _url, dataType: "html", async: false }).responseText;
	
	//$('.fetchingSelect').remove();
	
	if(mode == 'country'){
		$('input#enquiryForm_country, select#enquiryForm_country').remove();
		$('label[for="enquiryForm_country"]').after(_html);
		$('select#enquiryForm_country').change(function(){
			_getSelect('region', _getCurrentCountry(), _getCurrentRegion());
		});
		_getSelect('region', _getCurrentCountry(), _getCurrentRegion());
	}
	
	if(mode == 'region'){
		$('input#enquiryForm_region, select#enquiryForm_region').remove();
		$('label[for="enquiryForm_region"]').after(_html);
	}
	
}

function _getCurrentCountry(){
	return $('#enquiryForm_country').val();
}

function _getCurrentRegion(){
	return $('#enquiryForm_region').val();
}

$(document).ready(function(){
	// If we're on step 2
	if($('input[name="next_step"]').val() == 3){
		$('input#enquiryForm_country, input#enquiryForm_region').css('display','none');
		_getSelect('country', _getCurrentCountry(), '');
	}
});
