  var newAutocompleter = '';
  var radsearch = 1;
  if (!sid)  var sid = 0;
  if (!land) var land = 'AT';
  if (!loadMsg) var loadMsg = 'Abfrage l&auml;uft, bitte warten';
  // var prefix = $('prefix').value;
  // var prefix = ($('prefix')) ? $('prefix').value : '';
  // alert(prefix);
  var orientation = '';
  var prefix = '';
  var ort = '';
  var plz = '';
  var km = '';
  // var tActive = $('tActive').value;
  // var prefix = ($('tActive')) ? $('tActive').value : '';
  var tActive = '';
  var gtc = 0;
  // var tActive = 0;
  // alert("Diese Datei: " + this.document.URL);
  /*new PeriodicalExecuter(function(pe) {
    // $('orientation').innerHTML = 'Trace: loadMsg = '+loadMsg+' |  land = '+land+' | km = '+km+' | tActive = '+ tActive +' | gtc = '+ gtc+' | ort = '+ort+' | plz = '+plz+' | prefix = '+prefix+' | ortplz = '+$('ortplz').value;
  }, .5);*/

  // init
  $(document).ready(function() {
    offsetSM = ($('#SiteContainer')) ? "-"+$('#navi').offset().left+" 0" : "0 0";
    // alert(offsetSM);
    $('#searchmsg').position({
      // of: $( "#ortplz" ),
      of: $( "#ortplz" ),
	  my: "left top",
	  at: "left top",
	  offset: offsetSM,
	  collision: "fit"
	});

    loadMsg = loadMsg + ' <img src="images/buttons/ui-anim_basic_16x16.gif" alt="" />';

    /*$(document).everyTime(1000,function() {
      trc = '';
      trc = trc + "tActive: " + $('#tActive').val() + "<br />";
      trc = trc + "ortID:   " + $('#ortID').val() + "<br />";
      trc = trc + "ort:     " + $('#ort').val() + "<br />";
      trc = trc + "plz:     " + $('#plz').val() + "<br />";
      trc = trc + "prefix:  " + $('#prefix').val() + "<br />";
      trc = trc + "km:      " + $('#km').val() + "<br />";
      $("#trace").html(trc);
	}, 0);*/

    $("#ortplz").click(function() {
      $('#tActive').val(0);
      $('#searchmsg').hide();
      $(this).val($('#prefix').val());
      $(this).autocomplete( "search" );
    });

    function log( message ) {
      /*$( "<div/>" ).text( message ).prependTo( "#log" );
	  $( "#log" ).attr( "scrollTop", 0 );*/
      alert(message);
	}

    $("#ortplz").autocomplete({
      delay: 500,
      minLength: 2,
      source: "../template_v2/inc/get_suggest.php?land="+land+"&callback=?",
      //define select handler
      select: function( event, ui ) {
        // alert("prefix="+ui.item.prefix);
        $('#tActive').val(1);
        $('#ortID').val(ui.item.id);
        $('#ortplz').val(ui.item.value);
        $('#ort').val(ui.item.value);
        $('#plz').val(ui.item.plz);
        $('#prefix').val(ui.item.prefix);
        getTourCount();
      }
    })
    .data( "autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li></li>" )
  	  .data( "item.autocomplete", item )
	  .append( "<a>" + item.value + "<span>PLZ: " + item.plz + "</span></a>" )
	  .appendTo( ul );
	};

    $("#ortplz").keypress(function (event) {
      if (event.keyCode == 13){
        alert(enterMsg);
        $(this).autocomplete( "search" );
        return false;
      }
    });
  });

  function setLand(L){
    land = L;
    $('#curland').attr( 'src', '../template_geoc/images/icons/'+L+'.png');
    $('#tActive').val(0);
    $('#searchmsg').hide();
    $("#ortplz").autocomplete( "option" , "source" , "../template_v2/inc/get_suggest.php?land="+land+"&callback=?" )
    $('#ortplz').val('');
    $('#prefix').val('');
  }

  function reportError(request){
    alert('Mit dem Request ging was schief :(\n' + request);
  }
  function getTourCount(){
    gtc++;
    km    = $('#km').val();
    ortID = $('#ortID').val();
    ort   = $('#ort').val();
    plz   = $('#plz').val();
    var url    = '../template_v2/inc/radial_tours.php';
    var params   = 'sid='+sid+'&ortID='+ortID+'&ort='+ort+'&plz='+plz+'&km='+km+'&kid='+kid+'&lang=de';
    // alert(params);
    $.ajax({
      type: "POST",
      url: '../template_v2/inc/radial_tours.php',
      data: params,
      beforeSend: function(){
        $('#searchmsg').html( loadMsg ).show();
      },
      success: function(msg){
        if(msg == 'submit'){
          // $('#searchmsg').html( msg );
          $('#tActive').val(1);
          $('#radsearch').submit();
        }else{
          // $('#searchmsg').html( msg ).show();
          $('#searchmsg').html( msg );
        }
      }
    });
  }
  $( "#km_slider" ).slider({
    change: function(event, ui) {
      if($('#tActive').val()==1) getTourCount();
    }
  });
  /*
  function setPrefix(){
    $('ortplz').stopObserving('click');
    $('km-value').stopObserving('mouseup');
    // $('autocomplete_choices').hide();
    tActive = 0;
    $('ortplz').value = prefix;
    newAutocompleter.activate();
  }
  function processChoice(selection, id){
    $('ortplz').observe('click', setPrefix);
//    if(event) event.cancelBubble = true;
    sel = selection.value.split('PLZ: ');
    ort = sel[0].replace(/\s+$/g,'');
    plz = sel[1];
    tActive = 1;
    // $('km').observe('change', getTourCount);
    if(tActive==1) $('km-value').observe('mouseup', getTourCount);
    (id!=0) ? getTourCount() : prefix = $('prefix').value;
  }
  function hideMsg(){
    $('autocomplete_choices').hide();
    $('km-value').stopObserving('click');
  }
  posAutocomplete();
  processChoice($('ortplz'), 0);
  */
