function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function loadZipMap(){
	sPlz = window.location.search;
	var myPLZ = "";
	myPLZ = sPlz.substring(sPlz.search(/plz=/)+4,99);
	myPLZ = decodeURI(myPLZ.substring(0,myPLZ.search(/&|$/)));	
	if(myPLZ !=""){
		document.rggmsearch.rggmplz.value = myPLZ;
		document.rggmsearch.rggmRadius.value = "20";
		tx_rggooglemap_pi1search(xajax.getFormValues('rggmsearch'));	
	}
}

function loadAddressMap(){
	sPlz = window.location.search;
	var myAddress = "";
	myAddress = sPlz.substring(sPlz.search(/address=/)+8,99);
	myAddress = myAddress.substring(0,myAddress.search(/&|$/));	
	
	var myLNG = "";
	myLNG = sPlz.substring(sPlz.search(/lng=/)+4,99);
	myLNG = myLNG.substring(0,myLNG.search(/&|$/));	
	
	var myLAT = "";
	myLAT = sPlz.substring(sPlz.search(/lat=/)+4,99);
	myLAT= myLAT.substring(0,myLAT.search(/&|$/));
	
	myclick(myAddress,myLNG,myLAT,'tt_address');
}

function schnellsuche_hotel_startseite(){
	$("input[name='hotel_urlaubshotel']").bind("click", function(e){
		var radio_hotel = $("input[name='hotel_urlaubshotel']:checked").attr("value");
		if(radio_hotel =="hotel"){
			var urlaub_hotel = $("#schnellsuche_hotel .formleft").html();
			$("#schnellsuche_urlaubhshotel .formleft").html(urlaub_hotel);
			$("#schnellsuche_urlaubhshotel .send").css("display","block");
			$("#schnellsuche_urlaubhshotel").attr("action",'http://touristik.derpart24.de/booking/derpart/erde/index.php');
			$("#schnellsuche_urlaubhshotel .hidden_formular").attr("value","2");
			$("#schnellsuche_urlaubhshotel .hidden_showresult").attr("value","1");
			$("#schnellsuche_urlaubhshotel .hidden_engine").attr("value","erde");
		}else if(radio_hotel =="stadthotel"){
			var urlaub_stadthotel = $("#schnellsuche_stadthotel .formleft").html();
			$("#schnellsuche_urlaubhshotel .formleft").html(urlaub_stadthotel);
			$("#schnellsuche_urlaubhshotel .send").css("display","none");
		}else{
			var urlaub_ferienwohnung = $("#schnellsuche_ferienwohnung .formleft").html();
			$("#schnellsuche_urlaubhshotel .formleft").html(urlaub_ferienwohnung);
			$("#schnellsuche_urlaubhshotel .send").css("display","block");
			$("#schnellsuche_urlaubhshotel").attr("action",'http://touristik.derpart24.de/booking/ibe_tt/fewo/index.php');
			$("#schnellsuche_urlaubhshotel .hidden_formular").attr("value","4");
			$("#schnellsuche_urlaubhshotel .hidden_showresult").attr("value","2");
			$("#schnellsuche_urlaubhshotel .hidden_engine").attr("value","fewo");
		}
	});
}

function active_map_form(i){
	if($('.map_form'+i).css("visibility") == "hidden"){
		$('.map_form'+i).css("visibility","visible");
	}else{
		$('.map_form'+i).css("visibility","hidden");
	}		
}

function searchbox() {
	if ($('#wunsch-search')) {
		$('#wunsch-search').submit(function(e){
			if ($('#suggest')[0].value == '') {
				alert('Bitte Suchbegriff eingeben!');
				return false;
			}
		});
	}
}

function reiseziel_region(){
  if(document.getElementById("uh_regionen")){
    regiontmp = document.getElementById("uh_regionen").cloneNode(true);
    regiontmp.style.display = 'none';
    regiontmp.id = 'regiontmp';
    $('#uh_reiseziel').bind("change", function(event) {
      document.getElementById("uh_regionen").innerHTML = '';
      var reisezeil_selected = $('#uh_reiseziel option:selected')[0].value;
      var roptions = regiontmp.getElementsByTagName("OPTION");
      var oRegExp = new RegExp("\\|" + reisezeil_selected + "$");
      for (var i=0; i<roptions.length; i++) {
        var ropt = roptions[i];
        if (oRegExp.test(ropt.value)) document.getElementById("uh_regionen").appendChild(ropt);
      }
    });
  }
  if(document.getElementById("uh_regionen1")){
    regiontmp1 = document.getElementById("uh_regionen1").cloneNode(true);
    regiontmp1.style.display = 'none';
    regiontmp1.id = 'regiontmp1';
    $('#uh_reiseziel1').bind("change", function(event) {
      document.getElementById("uh_regionen1").innerHTML = '';
      var reisezeil_selected = $('#uh_reiseziel1 option:selected')[0].value;
      var roptions = regiontmp1.getElementsByTagName("OPTION");
      var oRegExp = new RegExp("\\|" + reisezeil_selected + "$");
      for (var i=0; i<roptions.length; i++) {
        var ropt = roptions[i];
        if (oRegExp.test(ropt.value)) document.getElementById("uh_regionen1").appendChild(ropt);
      }
    });
  }
}

function updateSearchBlogPlz(){
	if(document.getElementById("suche-plz")){
	   $("#suche-plz").bind("keyup", function(e){
	    var plz = $('#suche-plz').attr("value");
	    if((typeof plz == "undefined") || (plz.length > 1)){      
	      var hidden_sword = $('#hidden-sword').attr("value");
	      var search_sorting = $('#search_sorting option:selected').attr("value");
	      $('#suche-plz').attr("disabled",true);
	      $('.search_output').html('<p style="background-color:#FFFFFF;padding-left: 250px;"><img src="fileadmin/template/img/laden.gif" /></p>');
	      $.get("/suche/ajax-suche.html", { sword: hidden_sword, search_sorting: search_sorting, action : "2" , filter_plz : plz }, 
	       function(data){
	          $('.tx-dietzksearchblog-pi1-browsebox table').hide();
	          var data_output = data.split("<!-- ###SEARCH_OUTPUT###-->");
	          if(data_output[1]){
	            $('.search_output').html(data_output[1]);
	          }else{
	            $('.search_output').html('<p> Es wurde kein Treffer gefunden. Bitte wählen Sie andere PLZ aus.</p><br />');
	          }
	          $('#suche-plz').attr("disabled",false);
	          $('#suche-plz').removeAttr("disabled");
	          $('#suche-plz').focus();
	      }, "text");
	     }    
	  });
	}
}
 
function addLinkTargets() { 
  var oLinks = document.getElementsByTagName("a"); 
  for (var i=0; i < oLinks.length; i++) { 
    if (oLinks[i].className.search(/window_extern/) != -1) { 
      oLinks[i].setAttribute('target', '_blank'); 
    }
    if (oLinks[i].className.search(/external-link-new-window/) != -1) { 
      oLinks[i].setAttribute('target', '_blank'); 
    }
    if (oLinks[i].className.search(/external-link/) != -1) { 
      oLinks[i].setAttribute('target', '_blank'); 
    }
    if (oLinks[i].className.search(/internal-link/) != -1) { 
      oLinks[i].setAttribute('target', '_top'); 
    }
    if (oLinks[i].className.search(/internal-link-new-window/) != -1) { 
      oLinks[i].setAttribute('target', '_blank'); 
    }
    if (oLinks[i].className.search(/window_top/) != -1) { 
      oLinks[i].setAttribute('target', '_top'); 
    }
    if (oLinks[i].getAttribute("href", 0) == "http://www.seerenaden.de/derpart") { 
      oLinks[i].setAttribute('target', '_blank');
    }    
  }
  var formLinks = document.getElementsByTagName("form");
  for (var i=0; i < formLinks.length; i++) {
    if (formLinks[i].className.search(/window_top/) != -1) { 
      formLinks[i].setAttribute('target', '_top'); 
    }
  }
};

jQuery().ready(function(){
  searchbox();
  reiseziel_region();
  updateSearchBlogPlz();
  addLinkTargets();
});