//This is a script to work with the location include.
//It uses JQuery
//Rock on...


function location_attach_onchange_event() {
	$('.location_selector select').change( 
										function(e) {
											update_location(this);					 
										}
										);

}

function update_location(el) {
	var url 	= '/ajax/ajax_location.php';
	var data 	= {'id':el.value, 'el_id': $(el).parent().attr('id'), 'max_depth':  $(el).parent().children('input.max_depth').val()};
	$.get( url, data, function(data, textStatus) {
		refresh_location(data,textStatus, $(el).parent());		
		if ( typeof custom_location_onchange == 'function' ) {
			custom_location_onchange(el);
		}
		});
	}

function refresh_location(data, textStatus, el) {
	$(el).html(data);
	location_attach_onchange_event();
}

$(document).ready(function () {
    	location_attach_onchange_event();
});

