﻿$(document).ready(function() {
	
	$.extend({
	  getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
		  hash = hashes[i].split('=');
		  vars.push(hash[0]);
		  vars[hash[0]] = hash[1];
		}
		return vars;
	  },
	  getUrlVar: function(name){
		return $.getUrlVars()[name];
	  }
	});
	 
	if($('#ui-stepstone-jobsearch-form').length != 0) {
		
		var jobcount = 0;
		var allcount = 0;
		
		/* handle request from other pages */
		if($.getUrlVar('keyword') || $.getUrlVar('location')) {
	
			if($.getUrlVar('keyword')) {
				getkeyword = decodeURIComponent($.getUrlVar('keyword'));
				$('#stepstone-freetext-form #keyword').val(getkeyword);
			} else {
				getkeyword = '';
			}
			
			if($.getUrlVar('location')) {
				getlocation = decodeURIComponent($.getUrlVar('location'));
				$('#stepstone-freetext-form #location').val(getlocation);
			} else {
				getlocation = '';
			}			
			
			loadResults('keyword', 0, checkSearchQueryString('keyword', getkeyword, getlocation));
		}
		
		loadWidgets(0, false);		
		
		$('#stepstone-freetext-form').submit(function() {
			if($('#stepstone-freetext-form #keyword').val() == '' && $('#stepstone-freetext-form #location').val() == '') {
				$('#stepstone-freetext-form #location').after('<div class="steptone-info">Bitte geben Sie zuerst einen Suchbegriff ein.</div>');
				
				return false;
			} else {
				$('.steptone-info').remove();
				jobcount = 0;
				loadResults('keyword', jobcount, checkSearchQueryString('keyword', $('#stepstone-freetext-form #keyword').val(), $('#stepstone-freetext-form #location').val()));
				
				return false;
			}
		});	
		
		$('#stepstone-cat-submit').live('click', function() {
				$('.steptone-info').remove();
				jobcount = 0;
				loadResults('category', jobcount, checkSearchQueryString('category', $('#stepstone-freetext-form #keyword').val(), $('#stepstone-freetext-form #location').val()));
				
				return false;
		});			
		
	}
	
function loadWidgets(wid, parent) {
	$.ajax({
		url: '/wp-content/themes/bewerbung-de/ax.request.php',
		async: true,
		type: 'get',
		data:'method=widgets',
		dataType: 'xml',
		beforeSend: function() {
			$('#ui-jobsearch-sub-bar').toggleClass('loading');	  
		},
		complete: function() {
			$('#ui-jobsearch-sub-bar').toggleClass('loading');  
		},
		success: function(xml) {
			allcount = $(xml).find('WidgetData').length; 
			
			if(allcount > 0) {	
				$('#ui-category-table #ui-categories').empty();
				$('#ui-category-table #ui-postalcodes').empty();
				$.getScript('/wp-content/themes/bewerbung-de/lib/jquery.tinysort.js');
				
				/* load main categories */
				if(parent == false) {
					$(xml).find('WidgetType[name="workfield"] Widget:not([parentid])').each(function(i){
						var wid = $(this).attr('id');
						var wtext = $(this).text();
						
						$('<label rel="'+wid+'">'+wtext+'</label>').appendTo('#ui-category-table #ui-categories');
					});
					
					$('#ui-category-table #ui-categories label').bind('click', function() {
							
						loadWidgets($(this).attr('rel'), true);
					});							
				} else {
					/* load sub categories */
					$(xml).find('WidgetType[name="workfield"] Widget[parentid="'+wid+'"]').each(function(i){
						var wid = $(this).attr('id');
						var wtext = $(this).text();
					
						$('<label for="stcat_'+wid+'"></label>').html('<input type="checkbox" name="categories[]" value="'+wid+'" id="stcat_'+wid+'" class="checkbox" /><span>'+wtext+'</span></label>').appendTo('#ui-category-table #ui-categories');
					});
					
					/* load postalcodes */
					$('<h3>Postleitzahlen</h3>').appendTo('#ui-category-table #ui-postalcodes');
					
					$(xml).find('WidgetType[name="geography"] Widget[parentid="353"]').each(function(i){
						var wid = $(this).attr('id');
						var wtext = $(this).text();
					
						$('<label for="stpostal_'+wid+'"></label>').html('<input type="checkbox" name="postalcodes[]" value="'+wid+'" id="stpostal_'+wid+'" /><span>'+wtext+'</span></label>').appendTo('#ui-category-table #ui-postalcodes');
					});						
					
					$('<div id="category-submit-bar"></div>').html('<input type="submit" value="" name="stepstone-cat-submit" id="stepstone-cat-submit" />').appendTo('#ui-category-body');			
					
				$('#ui-category-table label').tsort();
								
				}
			}
			}
	});
}
		
function loadResults(searchtype, count, querystring) {	
	if(searchtype == 'category') {
		$('#stepstone-freetext-form #keyword').val('');
		$('#stepstone-freetext-form #location').val('');
	} else if(searchtype == 'keyword') {
		$('#ui-category-body input:checked').each(function(i){
			$(this).prop('checked', false);
		});		
	}

	$.ajax({
		url: '/wp-content/themes/bewerbung-de/ax.request.php',
		async: true,
		type: 'get',
		data:'method=search'+querystring,
		dataType: 'xml',
		beforeSend: function() {
			if(!$('#ui-category-table').hasClass('closed')) {
				$('#ui-category-table').toggleClass('closed');
			}			
			
			$('#ui-jobsearch-sub-bar').toggleClass('loading');
		},
		complete: function() {
			$('#ui-jobsearch-sub-bar').toggleClass('loading'); 
			$('#ui-load-more-results div').removeClass('loading'); 
		},
		success: function(xml) {	
		$('#ui-load-more-results').remove();
		allcount = $(xml).find('job').length; 
		
		if(allcount > 0) {
			
			if(count == 0) {
			$('#ui-resultlist').empty();
			$('<div class="tbl-head"><div class="tbl-cell">&nbsp;</div><div class="tbl-cell">Stellentitel | Unternehmen</div><div class="tbl-cell">Ort | Datum</div></div>').appendTo('#ui-resultlist'); 
			}
			
			if(count+25 > allcount){
				endcount = allcount;
			} else {
				endcount = count+25;
			}
			
			$(xml).find('job').slice(count, endcount).each(function(i){
				 var jID = $(this).attr('id');
				 var jTitle = $(this).find('title').text();
				 var jLocation = $(this).find('location').text();
				 var jDate = $(this).find('created').text();
				 var jDateSplit = jDate.split('-');
				 var jLink = $(this).find('link').text();
				 var jCompanyLogo = $(this).find('company_logo').text();
				 var jCompany = $(this).find('company_name').text();
				 var jCompanyID = $(this).find('company_id').text();
				
				 $('<div class="job tbl-row '+jobcount+'"></div>').html('<div class="company-logo tbl-cell"><img src="'+jCompanyLogo+'" alt="'+jCompany+'" /></div><div class="job-content tbl-cell"><div class="job-title"><a href="http://www.stepstone.de/5/index.cfm?event=offerView.dspOfferInline&lang=de&rewrite=1&cid=bewerbungde&offerid='+jID+'" target="_blank" title="'+jTitle+'">'+jTitle+'</a></div><div class="company-name">'+jCompany+'</div></div><div class="job-details tbl-cell"><div class="job-location">'+jLocation+'</div><div class="job-date">'+jDateSplit[0]+'.'+jDateSplit[1]+'.'+jDateSplit[2]+'</div></div>').appendTo('#ui-resultlist');
		
				 jobcount++;
				 
				 $("#ui-resultlist div.job:odd").css("background-color", "#d6dfe6");
			});
			
			if(jobcount < allcount) {
				$('#ui-resultlist').after('<div id="ui-load-more-results"><div>Mehr Ergebnisse laden</div></div>');
				
				$('#ui-load-more-results div').bind('click', function() {
					$('#ui-load-more-results div').addClass('loading');
					loadResults(searchtype, jobcount, checkSearchQueryString(searchtype, $('#stepstone-freetext-form #keyword').val(), $('#stepstone-freetext-form #location').val()));
				});	
				
				/* load more results on page end */
				$(window).scroll(function(){
						if($(window).scrollTop() == ($(document).height() - $(window).height()) && jobcount < allcount){	
							$('#ui-load-more-results div').addClass('loading');									
							loadResults(searchtype, jobcount, checkSearchQueryString(searchtype, $('#stepstone-freetext-form #keyword').val(), $('#stepstone-freetext-form #location').val()));
						}
				}); 												
			}
			
		} else {
			$('#ui-resultlist').after('<div class="steptone-info">Es konnten leider keine Jobs gefunden werden.</div>');
		}
		}	 
	});	
}
	
	function checkSearchQueryString(stype, keyword, location) {
		if(stype == 'keyword') {
			if(keyword != '' && location != '') {
				querystring = '&keyword='+encodeURIComponent(keyword)+'&where='+encodeURIComponent(location);
			}
			
			if(keyword != '' && location == '') {
				querystring = '&keyword='+encodeURIComponent(keyword);
			}	
			
			if(keyword == '' && location != '') {
				querystring = '&where='+encodeURIComponent(location);
			}
		}
		
		if(stype == 'category') {
			var categories = $('#ui-categories :checked').map(function() {
				return this.value;
			}).get().join(',');
			
			var postalcodes = $('#ui-postalcodes :checked').map(function() {
				return this.value;
			}).get().join(',');									
			
			var querystring = '&categories='+categories+'&postalcodes='+postalcodes;			
		}
		
		return querystring;						
	}	
	
	$("a.handle_hidden").click(function(event){
                var id = $(this).attr("href");
                if($(id).not(":hidden").length > 0) {
                        $(id).slideUp();
                } else {
                        $(id).slideDown();
                }
                event.preventDefault();
                event.stopPropagation();
                return false;
        });

	/* Cufon init */
	Cufon.replace('.naviButton');
		
  	initStepstoneJobs();
	//initArbeitenDEJobs();

	/* Bugfix fuer IEx bei Hintergrund-Bildern */
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch (e) {}
	
	/* Hack, der jedes erste Bild pro Artikel beseitigt
	 zu loeschen wenn Artikel ueberarbeitet wurden 
	$(".article").each(function(){
		$(this).find("img:first").css("display","none");
	});*/
		
	/* Tabbox */
	if($("#tabnavi").length > 0){
	$("#newPosts").noOutline();
	$("#newPosts").click(function(){
		$("#newPostsDiv").css("display","block");
		$("#top5Div, #tagcloudDiv, #authorDiv").css("display","none");
		$(this).addClass("active");
		$("#top5, #tagcloud, #author").removeClass("active");
		return false;
	});
	$("#top5").noOutline();
	$("#top5").click(function(){
		$("#top5Div").css("display","block");
		$("#newPostsDiv, #tagcloudDiv, #authorDiv").css("display","none");
		$(this).addClass("active");
		$("#newPosts, #tagcloud, #author").removeClass("active");
		return false;
	});
	$("#tagcloud").noOutline();
	$("#tagcloud").click(function(){
		$("#tagcloudDiv").css("display","block");
		$("#newPostsDiv, #top5Div, #authorDiv").css("display","none");
		$(this).addClass("active");
		$("#newPosts, #top5, #author").removeClass("active");
		return false;
	});
	$("#author").noOutline();
	$("#author").click(function(){
		$("#authorDiv").css("display","block");
		$("#top5Div, #tagcloudDiv, #newPostsDiv").css("display","none");
		$(this).addClass("active");
		$("#top5, #tagcloud, #newPosts").removeClass("active");
		return false;
	});
	}
	
	/* Wert fuer Suchfeld setzen */
	var old = "";
	$("#search input, #keyword, #jobsearch").focus(function(){
		if($(this).attr("value") == "Suchbegriff" || $(this).attr("value") == "Stichwortsuche"){
			old = $(this).attr("value");
			$(this).attr("value","");
		}
	});
	$("#search input, #keyword, #jobsearch").blur(function(){
		if($(this).attr("value") == ""){
			$(this).attr("value", old);
		}
	});
	
	/* Teaser auf Start- und Portalseiten komplett verlinken */
	$("#teaser div").click(function(){
		window.location.href = $(this).children("a:first").attr("href");
	});
	
	$("#welcome").click(function(){
	  window.location.href = $(this).find("a.teaser_link").attr("href");
	}).mouseover(function(){
	  $(this).addClass("active");
	}).mouseout(function(){
	  $(this).removeClass("active");
	});
	
  /* Hintergrundbilder (Container und Link) verschieben */
	$("#teaser div").hover(function(){
		$(this).css("background-position", "0px -120px").children("a:first").css("background-position", "0px -13px");
	}, function(){
		$(this).css("background-position", "0px 0px").children("a:first").css("background-position", "0px 0px");
	});

	/* Filterfunktion auf- und zuklappen */
	if($("#filter").length > 0){
		$("#filter h3").click(function(){
			if($(this).text() == "Filterfunktionen ausblenden"){
				$(this).text("Filterfunktionen einblenden");
			}
			else {
				$(this).text("Filterfunktionen ausblenden");				
			}
			$("#filter").toggleClass("close");
			$("#filter form").toggle();
		});
	}
	
	/* Filterfunktion Dropdowns auf- und zuklappen und Verhalten*/
	if($("#filter").length > 0){
		var text = "";
		$(".dropdown").click(function(){
			$(this).next(".dropdownSelect").toggle();
		});
		$(".close").click(function(){
			$(this).parent().parent().hide();
		});
		$(".remove").click(function(){
			$(this).parent().parent().find(":checkbox:checked").each(function(){
				$(this).attr("checked", false);
			});
			$(this).parent().parent().prev().text("Keine Optionen ausgewählt");
		});

	
		var tog = false; 
		$(".dropdownSelect ul li").click(function(){
			if($(this).children(":checkbox").attr("checked") == true){
				$(this).children(":checkbox").attr("checked", false);
			}
			else {
				$(this).children(":checkbox").attr("checked", true);
			}
      
      // Sonderfall "Schulabschluss": hier sollen die vorangegangne Abschluesse auch markieren
      /*$(this).prevAll().each(
        function() {
          trigger("click");
        }
      );*/
      
      // Anzahl der gewaehlten Optionen
      var count_options = $(this).parent().find(":checkbox:checked").length;
      
      // Bezeichner fuer die Selectbox setzen
      var option_name = "Option";
      if ( $(this).parent().parent().attr("id") == "area" ) {
        option_name = (count_options == 1) ? "Berufsfeld" : "Berufsfelder";
      } else if ( $(this).parent().parent().attr("id") == "school" ) {
        option_name = (count_options == 1) ? "Abschluss" : "Abschlüsse";
      }
      
			$(this).parent().parent().prev().text(count_options + " " + option_name + " ausgewählt");
		});	
		$(".dropdownSelect ul li input:checkbox").click(function(){
			if($(this).attr("checked") == true){
				$(this).attr("checked", false);
			}
			else {
				$(this).attr("checked", true);
			}
		});
	}
	
	/* Jobsuche auf Portalseite "Die Jobsuche" */
	if($("#jobsearch").length > 0){
		$("#jobsearchButton").click(function(){
			$("#jobAd li, #jobAdStep li").remove();
      var search_item = encodeURI( $("#jobsearch").attr("value") );
			searchStepstone( search_item );
			searchArbeitenDE( search_item );
			$(".headline").show();
      return false;
		});
	}
		
  /* Filtereinstellungen nach der Suche wieder auswaehlen */
  if (select_tags.length) {
    $("#area input").each(
      function() {
        for ( i=0; i < select_tags.length; i++ ) {
          if( $(this).val() == select_tags[i] ) {
            $(this).parent().trigger("click");
          }
        }
      }
    );
  }
  if (select_schools.length) {
    $("#school input").each(
      function() {
        for ( i=0; i < select_schools.length; i++ ) {
          if( $(this).val() == select_schools[i] ) {
            $(this).parent().trigger("click");
          }
        }
      }
    );
  }
  if (keywords != "") {
    $("#keyword").val(keywords);
  }
  
  $("#filter_pages a").click(
    function() {
      // ID der angeklickten Seite in das hidden field des Formulars schreiben
      $("#filter_page").val( $(this).attr("id").replace(/filter_page_/, "") );
      $("#sendFilter").trigger("click");
      return false;
    }
  );

  
  $("#RES_ID_fb_login_image").hover(function(){
		$(this).attr('src', '/wp-content/themes/bewerbung-de/images/article/button_facebook_hover.gif');
	}, function(){
		$(this).attr('src', '/wp-content/themes/bewerbung-de/images/article/button_facebook.gif');
	});	
  window.setTimeout("changeImage()", 100);
  window.setTimeout("showImage()", 1000);
  
  $("#facebook_connect_button").hover(function(){
		$(this).attr('src', '/wp-content/themes/bewerbung-de/images/article/button_facebook_hover.gif');
	}, function(){
		$(this).attr('src', '/wp-content/themes/bewerbung-de/images/article/button_facebook.gif');
	});	

  $('input[name=fbc_submit_hack]').attr('class', 'facebook_submit').val('');
  
  if ($('input[name=fbc_submit_hack]').length == 1) {
    $('a#logout').attr('href', '#').attr('onClick', 'FBConnect.logout(); return false;');
  }	
	
	if ($('a[name=twcbutton]').text() == '') {
    $('a[name=twcbutton]').parent('p').css('display', 'none');
  }
	
  /* Kommentar-Formular: Validierung */
  $("#commentform #submit").click(
    function() {
      $("#commentform_error").remove();

      // Bei nicht-eingeloggten Usern Noch Name und E-Mail abfragen
      if ($("#commentform #loggedIn").length == 0) {
        // Pflichtfeld Name pruefen
        if ( $("#commentform #author").val().replace(/ /g, "") == ""  ) {
          $("#commentform").append('<div id="commentform_error">* Bitte füllen Sie die erforderlichen Felder korrekt aus.</div>');
          return false;
        }

        // E-Mail-Pruefung
        var email_regex = /^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})$/;
        var check_email = $("#commentform #email").val().search(email_regex);
        if (check_email == -1) {
          $("#commentform").append('<div id="commentform_error">* Bitte tragen Sie eine korrekte E-Mail-Adresse ein.</div>');
          return false;
        }
      }

      // Pflichtfeld Kommentar pruefen
      if ( $.trim( $("#commentform #comment").val() ).length == 0 ) {
        $("#commentform").append('<div id="commentform_error">* Bitte füllen Sie das Kommentarfeld aus.</div>');
        return false;
      }
    }
  );
});//ende document ready

/* Ausgelagerte Funktionen: */

function changeImage() {
	$('#RES_ID_fb_login_image').attr('src', '/wp-content/themes/bewerbung-de/images/article/button_facebook.gif');
}

/* Facebook Connect Button einblenden */
function showImage() {
	$('#RES_ID_fb_login_image').css('visibility', 'visible');
}

/* Tickerfunktion fuer Neue Jobs Box, Jobs von stepstone.de */
var oldJobs = [$([]), $([]), $([])];
var count = 0;
function getStepstoneJobs() {
	$.ajax({
		type: "GET",
		url: "/?jobs_uri=http://www.stepstone.de/services/search/index.cfm?lang=de%26amount=5%26api_key=5329AC9709F8A4BCD293D82D18DFC5",
		success: function(result){
			count = 0;
			//$("#newJobs ul .load").remove();
			
			$(result).find("job").each(function(){
				
				//alert(oldJobs[0].attr("id")+" und "+$(this).attr("id"));
				
				if(oldJobs[0].equals($(this))){
					//alert("gleich");					
					return false;
				}
				else {
					//alert("ungleich");
					oldJobs[count] = $(this);
					count++;
					
					var title = $(this).children("title").text();
					if(title.length > 35){
						title = title.substr(0, 35)+" [...]";
					}
					var link = $(this).children("link").text();
					link = link.replace(/cid=.*?&/g,"cid=bewerbungde&");
					$("#newJobs ul").append(
					"<li style='display: none;'><a href='" + link + "' target='_blank' title='"+ $(this).children("title").text() +"'>" + title + "</a></li>"
					);
				}				
			});
			for (var i = 0; i < count; i++) {
				$("#newJobs ul li:first").slideUp(1000,function(){
          $("#newJobs ul li:first").remove();
				});
				$("#newJobs ul li:hidden:first").slideDown(1000);
			}
		}
	});
}

/* Stepstone Jobs beim laden der Seite holen */
function initStepstoneJobs() {
	$.ajax({
		type: "GET",
		url: "/?jobs_uri=http://www.stepstone.de/services/search/index.cfm?lang=de%26amount=5%26api_key=5329AC9709F8A4BCD293D82D18DFC5",
		success: function(result){

			$("#newJobs ul .load").remove();
			$(result).find("job").each(function(){
				
				oldJobs[count] = $(this);
				count++;
				var title = $(this).children("title").text();
				if(title.length > 35){
					title = title.substr(0, 35)+" [...]";
				}
				var link = $(this).children("link").text();
				link = link.replace(/cid=.*?&/g,"cid=bewerbungde&");
				$("#newJobs ul").append(
				"<li><a href='" + link + "' target='_blank' title='"+ $(this).children("title").text()  +"'>" + title + "</a></li>"
				);
        // Copyright-Position anpassen (sonst IEx-Problem)
        $("#copyright").css("bottom", "55px");
			});
			$("#newJobs div").css("height","150px");
		}
	});	
}

/* arbeiten.de Jobs beim laden der Seite holen */
function initArbeitenDEJobs() {
$.ajax({
	type: "GET",
	url: "/?jobs_uri=http%3A%2F%2Fwww.arbeiten.de%2Flistings%2Findex.step%3Fcid%3Dbewerbungde&type=text/plain&encode=iso-8859-1&imgrepl=1",
	success: function(result){
		$("#newJobs ul .load").remove();
		$(result).find(".job-title-list h3").each(function(){
			var longLinkText = $(this).children("a:first").text();
			if(longLinkText.length > 35){
				var linkText = longLinkText.substr(0, 35)+" [...]";
				$(this).children("a:first").text(linkText);
			}
			$("#newJobs ul").append("<li>"+ $(this).html().replace(/href="/, 'target="_blank" title="'+ longLinkText +'" href="http://www.arbeiten.de') +"</li>");
		});
		$("#newJobs div").css("height","150px");
	}
	});
}

/* Tickerfunktion fuer Neue Jobs Box, Jobs von arbeiten.de */
function scrollArbeitenDeJobs() {
		$("#newJobs ul li:first").slideUp(1000,function(){
			$("#newJobs ul li:last").after($("#newJobs ul li:first"));
			$("#newJobs ul li:last").css("display", "block");
		});
}

/* Stepstone Jobs in JQuery Objekten vergleichen */
$.fn.equals = function(compareTo) {
	if (!compareTo || !compareTo.length || this.length!=compareTo.length){
		return false;
	}
	else {
		if(this.attr("id") == compareTo.attr("id")) {
			return true;
		}
		else {
			return false;
		}
	}
};

/* Outline bei Mausklick nicht anzeigen */
$.fn.noOutline = function() {
	$(this).mousedown(function(){
		$(this).css("outline","none");
	});
	$(this).mouseup(function(){
		$(this).removeAttr("style");
		$(this).blur();
	});
	return false;
};

function searchStepstone(terms) {
var terms = terms;
$.ajax({
	type: "GET",
	url: "/?jobs_uri=http://www.stepstone.de/services/search/index.cfm?lang=de%26amount=5%26api_key=5329AC9709F8A4BCD293D82D18DFC5%26keyword="+terms,
	success: function(result){
		$(result).find("job").each(function(){
			var link = $(this).children("link").text();
			link = link.replace(/cid=.*?&/g,"cid=bewerbungde&");
			$("#jobAdStep").append(
        "<li><a href='" + link + "' target='_blank' title='"+ $(this).children("title").text()  +"'>" + $(this).children("title").text() + "</a></li>"
			);
		});
    
    // falls keine Ergebnisse gefunden wurden, entsprechenden Hinweis ausgeben
    if ( $("#jobAdStep").html() == "" ) {
      $("#jobAdStep").append("<li>Hier konnten leider keine Ergebnisse gefunden werden.</li>");
    }
	}
	});
}


/* arbeiten.de Suche */
function searchArbeitenDE(terms) {
var terms = terms;
var counter = 0;
$.ajax({
	type: "GET",
	url: "/?jobs_uri=http%3A%2F%2Fwww.arbeiten.de%2Flistings%2Flist.step%3Farbeiten_als%3D"+ terms +"%26search%3Dnow%26cid%3Dbewerbungde&type=text/plain&encode=iso-8859-1&imgrepl=1",
	success: function(result){
		$(result).find(".job-title-list h3").each(function(){
			if (counter == 5){ return false; }
			counter++;
			$("#jobAd").append("<li>"+
			$(this).html().replace(/href="/, 'target="_blank" href="http://www.arbeiten.de')+"</li>");
		});

    // falls keine Ergebnisse gefunden wurden, entsprechenden Hinweis ausgeben
    if ( $("#jobAd").html() == "" ) {
      $("#jobAd").append("<li>Hier konnten leider keine Ergebnisse gefunden werden.</li>");
    }
	}
	});
}

