$(document).ready(function(){
	$('a[rel*=external]').click(linkExternal);
	$('#search select').change(searchReload);
});

function linkExternal(){
	window.open(this.href);
	return false;
}

function searchReload(){
	var typ = $('#typ option:selected').val();
	var subtyp = ($(this).attr('id') == 'typ') ? 0 : $('#subtyp option:selected').val();

	var loc_0 = $('#loc_0').val();
	if ($(this).attr('id') == 'loc_0' || $('#loc_0').val() == 0) {
		var loc_1 = 0;
		var loc_2 = 0;
		var loc_3 = 0;
		var loc_4 = 0;
	} else {
		var loc_1 = $('#loc_1').val();
		if ($(this).attr('id') == 'loc_1' || $('#loc_1').val() == 0) {
			var loc_2 = 0;
			var loc_3 = 0;
			var loc_4 = 0;
		} else {
			var loc_2 = $('#loc_2').val();
			if ($(this).attr('id') == 'loc_2' || $('#loc_2').val() == 0) {
				var loc_3 = 0;
				var loc_4 = 0;
			} else {
				var loc_3 = $('#loc_3').val();
			}
		}
	}
	
	var status = ($('#status').length) ? $('#status option:selected').val() : 0;
	$.get(HOME_URL + "xml", {
		typ: typ,
		subtyp: subtyp,
		loc_0: loc_0,
		loc_1: loc_1,
		loc_2: loc_2,
		loc_3: loc_3,
		loc_4: loc_4,
		status: status
	},
		function(data){
			$(data).find('select').each(function(){
				$("#" + $(this).attr('id')).html($(this).text());
				if ($(this).attr('disabled')) {
					$("#" + $(this).attr('id')).attr('disabled', 'disabled');
				} else {
					$("#" + $(this).attr('id')).removeAttr('disabled');
				}
			});
		}
	);
}

function popup(url,name,windowWidth,windowHeight){
  myleft=(screen.width)?(screen.width-windowWidth)/2:100;
  mytop=(screen.height)?(screen.height-windowHeight)/2:100;
  properties = "scrollbars=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+mytop+",left="+myleft;
  winPop = window.open(url,name,properties)
  if(winPop)return false;
}

