function CountryesAjaxGenerateResortsList(id) {
	jQuery('img#AjaxLoadAnimation').css('display', 'inline');
	jQuery.ajax({
		type: 'POST',
		cache: false,
		url: GLOBAL_SETTING_SERVER_NAME + 'wp-content/plugins/configurator/ajax/ajax-countryes.php?server_name=' + GLOBAL_SETTING_SERVER_NAME + '&country=' + id + '&action=resorts_list',
		success: function(data) {
			jQuery('select#stepTwoResorts').html(data);
			jQuery('img#AjaxLoadAnimation').css('display', 'none');
		}
	});
}

function CountryesAjaxSaveResortId(id) {
	jQuery('img#AjaxLoadAnimation').css('display', 'inline');
	jQuery.ajax({
		type: 'POST',
		cache: false,
		url: GLOBAL_SETTING_SERVER_NAME + 'wp-content/plugins/configurator/ajax/ajax-countryes.php?server_name=' + GLOBAL_SETTING_SERVER_NAME + '&resort=' + id + '&action=save_options',
		success: function(data) {
			jQuery('img#AjaxLoadAnimation').css('display', 'none');
		}
	});
}

function SaveHotelStars(Star) {
	jQuery('img#AjaxLoadAnimation').css('display', 'inline');
	jQuery.ajax({
		type: 'POST',
		cache: false,
		url: GLOBAL_SETTING_SERVER_NAME + 'wp-content/plugins/configurator/ajax/ajax-countryes.php?server_name=' + GLOBAL_SETTING_SERVER_NAME + '&stars=' + Star + '&action=save_hotel_stars',
		success: function(data) {
			jQuery('img#AjaxLoadAnimation').css('display', 'none');
		}
	});
}

function UnsetHotelStar(Star) {
	jQuery('img#AjaxLoadAnimation').css('display', 'inline');
	jQuery.ajax({
		type: 'POST',
		cache: false,
		url: GLOBAL_SETTING_SERVER_NAME + 'wp-content/plugins/configurator/ajax/ajax-countryes.php?server_name=' + GLOBAL_SETTING_SERVER_NAME + '&stars=' + Star + '&action=unset_hotel_stars',
		success: function(data) {
			jQuery('img#AjaxLoadAnimation').css('display', 'none');
		}
	});
}

function CountryesUpdateResorts(id) { CountryesAjaxGenerateResortsList(id); }
function CountryesSaveResort(id) { CountryesAjaxSaveResortId(id); }

jQuery(document).ready(function() {
	jQuery('select#stepTwoCountryes').change(function() {
		var country_id = jQuery(this).find('option:selected').attr('value');
		CountryesUpdateResorts(country_id);
	});
	
	jQuery('select#stepTwoResorts').change(function() {
		var resort_id = jQuery(this).find('option:selected').attr('value');
		CountryesSaveResort(resort_id);
	});
	
	var country_id = jQuery('select#stepTwoCountryes option:selected').attr('value');
	if(country_id != 0) { CountryesAjaxGenerateResortsList(country_id); }
	
	//Bind Check The Hotel Stars
	jQuery('input[type=checkbox]#luxury').click(function() { if(jQuery(this).attr('checked')) { SaveHotelStars('1'); } else { UnsetHotelStar('1'); } });
	jQuery('input[type=checkbox]#superior').click(function() { if(jQuery(this).attr('checked')) { SaveHotelStars('2'); } else { UnsetHotelStar('2'); } });
	jQuery('input[type=checkbox]#value').click(function() { if(jQuery(this).attr('checked')) { SaveHotelStars('3'); } else { UnsetHotelStar('3'); } });
});
