
/**
 * This class defines the OrganisationArea Selection feature of the
 * YachtSearch system that allows you to drill to down to the second level area
 * to refine your search to a more specific location.
 *
 * Author: peterl
 */
IDBSYachtSearch.OrganisationAreaSelect = {

	initialise: function (context) {

		/**
		 * Without "var" this variable will be assigned to the Prototype not the Instance of the Prototype.
		 * i.e. In PHP speak, it will assign to the Class definition rather than the Object instantiation.
		 * 
		 * Author: peterl
		 */
		var organisationArea = $("#organisation_area_id", context);		 
		var organisationAreaSecondLevel = $("#organisation_area_id_2", context);
		var organisationAreaThirdLevel = $("#organisation_area_id_3", context);
	
		/**
		 * On change of the top level area select box, call the selectOrganisationArea method to 
		 * load the second level data and show the second level box.
		 *
		 * Author: peterl
		 */
		organisationArea.change(function() {
			organisationAreaThirdLevel.css("display", "none");
			organisationAreaSecondLevel.css("display", "none");
			IDBSYachtSearch.OrganisationAreaSelect.selectOrganisationArea(organisationArea, organisationAreaSecondLevel, $('#organisation_area_id_second_selected').val());
		});
		
		organisationAreaSecondLevel.change(function() {
			organisationAreaThirdLevel.css("display", "none");													
			IDBSYachtSearch.OrganisationAreaSelect.selectOrganisationArea(organisationAreaSecondLevel, organisationAreaThirdLevel, $('#organisation_area_id_third_selected').val());
		});
		
		
		/**
		 * Check initial state of the organisation area and if is set to some area (insted of empty) 
		 *
		 * Author: waldemarm
		 */		
		if($("#organisation_area_id :selected", context).val()!=''){
			organisationArea.trigger('change');
			
		}
		
	}
	
};

IDBSYachtSearch.OrganisationAreaSelect.selectOrganisationAreaLastNode = function(){
		if($("#organisation_area_id_second :selected").val()!=''){
			$('#organisation_area_id_2').trigger('change');;
		}	
}

