if (document.cookie.indexOf("info=")<0)
{
	var info=document.referrer+"@/@"+screen.width+'x'+screen.height;
	document.cookie = "info=" + escape (info);
}

function clearField(fld, vlue) {//Funktion zum loeschen des Initiierungstexts in Suchformularen onClick
  if (fld.value == vlue) fld.value = "";
}

function resetField(fld, vlue) {//Funktion zum setzen des Initiierungstexts in Suchformularen onBlur
  if (fld.value == "") fld.value = vlue;
}

function openHelp(URL){
	var win;
	win=window.open (URL,"hilfe","width=580,height=600,resizable=no,scrollbars=yes");
}

function getLanguageString() {
	var lang = $('#language_string').attr('lang');
	lang = lang.toString();
	if (lang.length > 0) lang = lang+"/";
	return lang;
}
function startSlider() {
 	var lang=getLanguageString();
 	
  $('.ui-slider').slider({
      change: function(event, ui) {
        $(this).parent().children(".weights").val(ui.value);
        var url = "/"+lang+"index.php?ajax=ajax_slider";
        url = url+"&"+($("#quicksearchform").serialize())
        $.get(url, function (text) { $(".fuzzyresult").html(text) });
        
      },
      val: 50
  });
  
  $('.ui-slider').each(function () {
    if ($(this).parent().children(".weights").val() == parseInt($(this).parent().children(".weights").val())) 
      $(this).slider('option', 'value', parseInt($(this).parent().children(".weights").val()));
    else
      $(this).slider('option', 'value', 50);
  });
  
  if ($('#globalslider').val() != parseInt($('#globalslider').val())) 
    $('#slider').slider('option', 'value', 80);
  else 
    $('#slider').slider('option', 'value', parseInt($('#globalslider').val()));
    
  if ($('#globalslider').val() != parseInt($('#globalslider').val())) 
    $('#slider_ex').slider('option', 'value', 50);
  else 
    $('#slider_ex').slider('option', 'value', parseInt($('#globalslider').val()));
  
}

function setJobmemorizerTooltips()
{
	$('.functionLinks a.jobmerker_noaction').tooltip({
		bodyHandler: function() { 
		        return '<img id="tt_arrow" src="/cust/jobstairs/images/tooltip_arrow.gif">'+$(this).parents('.functionLinks').children('.alreadymemorized').val(); 
		},
		showURL: false,
		track: true,
		delay: 0,
		top: -5,
		left: 20
	});	
}

function resetPreviewLinks() {
	$('a.previewJobs').each(function() {
		$(this).removeClass("expanded");
	});
}

function resetLinks(theClass) {
	$('a.'+theClass).each(function() {
		$(this).removeClass("expanded");
		$(this).removeClass("current");
	});
}	
	
function resetToolBlockLinks() {
	$('a.toolBlockLink').each(function() {
		$(this).removeClass("expanded");
	});
}

function resetFunctionlinks() {
	$('div.functionLinks li').each(function() {
		$(this).removeClass("current");
	});
}

function rebindFunctionLinks()
{
	$('#datumundtitel').click(function () {
		$('.searchresult h4, .teaser_result_list').toggle();
		$('.searchresult').toggleClass("justDateTitle");
	});

  $('div.functionLinks a.forward').each(function() {
    var me = $(this);
		$(this).click(function() {
			if ($(this).parents('.searchresult').children('.forwardplaceholder').html() != '') {
				resetFunctionlinks();
				$(this).parents('.searchresult').children('.forwardplaceholder').html('');
			} else {		
				$('.moreOptionsCont').remove();
				$('a.forward').parent().removeClass('current');
				$('a.moreOptions').parent().removeClass('current');
				$('#weiterleiten').remove();
				$(this).parent().addClass('current');
				
			 	var lang=getLanguageString();
				var curartikelid = me.parents('.searchresult').children('.jobadid').val();
				// HIER MUSS NOCH DIE ENTSPRECHENDE ARTIKELID EINGETRAGEN WERDEN
				$('#weiterleiten #JobID').val(curartikelid);
				//$.get("/index.php?ajax=ajax_forward&jobID=", function (text){
				//	$(this).parent().parent().parent().parent().children('.forwardplaceholder').append(text);
				$.get("/"+lang+"index.php?ajax=ajax_forward&jobID="+me.parents('.searchresult').children('.jobadid').val(), function (text){
                    me.parents('.searchresult').children('.forwardplaceholder').append(text);
	        });
			}
		});							
	});
	
  	$('div.functionLinks a.moreOptions').each(function() {
    var me = $(this);		
		$(this).click(function() {
			if ($(this).parents('.searchresult').children('.moreOptionsplaceholder').html() != '') {
				resetFunctionlinks();
				$(this).parents('.searchresult').children('.moreOptionsplaceholder').html('');
			} else {
			  var appendtext="";
				$('.moreOptionsCont').remove();
				$('a.forward').parent().removeClass('current');
				$('a.moreOptions').parent().removeClass('current');
				$('.formular').remove();
				$(this).parent().addClass('current');

			 	var lang=getLanguageString();
				
				var companyid = $(this).parents('.searchresult').children('.companyid').val();
				$.get("/"+lang+"index.php?ajax=ajax_more&orgaid="+parseInt(companyid)+"&"+decodeURI($("#lastsearchcriterions").serialize())+"&"+decodeURI($(this).parents('.searchresult').children('.resultinformation').serialize()), function (text){
				  me.parents('.searchresult').children('.moreOptionsplaceholder').append(text);
        			});
			}
		});							
	});

	var ajaxmatchidle = true;
	$('a.matching').each(function() {					
		$(this).click(function() {
		  if (ajaxmatchidle) {
  			if ($(this).parents('.searchresult').children('.relevanceplaceholder').html() != '') {
  				$(this).parents('.searchresult').children('.relevanceplaceholder').html('');
  			} else {
  				$('.relevance').remove();
  				//$(this).parents('.searchresult').children('.relevanceplaceholder').append(relevanceDiv);
  
  				var me = $(this).parents('.searchresult');	
          var jobadkey = me.children('.jobadkey').val();
          ajaxmatchidle = false;
				 	var lang=getLanguageString();
  				$.get("/"+lang+"index.php?ac=ajax_match_score&jobadkey="+escape(jobadkey), function (text){
  				  me.children('.relevanceplaceholder').append(text);
  				  ajaxmatchidle = true;
  				  
  				  $('.relevance a').click(function () {
  					 $('.relevance').remove();
  				  });
          });
  			}
  		}
		});							
	});
	
  $('a.previewJobs').each(function() {					
		$(this).click(function() {
			resetPreviewLinks();
			if ($(this).parent().children('.previewJobsPlaceholder').html() != '') {
				$(this).parent().children('.previewJobsPlaceholder').html('');
			} else {
				$('.previewJobsCont').remove();
				$('a.toChannelDetail').remove();
				
				var me = $(this).parent();
				var channelid = me.children('.jobchannelpid').val();
			 	var lang=getLanguageString();
				$.get("/"+lang+"index.php?ac=ajax_channels&channelid="+parseInt(channelid)+"&page=1&hits=5", function (text){
				  me.children('.previewJobsPlaceholder').append(text);
        });
        $(this).toggleClass("expanded");
			}
		});	
	});

	$('a.occupatarea').each(function () {
		$(this).click(function() {
			resetLinks('occupatarea');
			if ($(this).parent().parent().children('.previewJobsPlaceholder').html() != '') {
				$(this).parent().parent().children('.previewJobsPlaceholder').html(''); 
			} else {
				$('.previewJobsCont').remove(); 
				$('a.toChannelDetail').remove();
				var me = $(this).parent().parent();
				var companyid = me.children('.companyid').val();
				var channelid = $('#jobchannelcompany').children('.jobchannelpid').val();
			 	var lang=getLanguageString();
				$.get("/"+lang+"index.php?ac=ajax_channels&channelid="+parseInt(channelid)+"&companyid="+parseInt(companyid)+"&page=1&hits=5", function (text){
				  me.children('.previewJobsPlaceholder').append(text);
        });
        $(this).toggleClass("expanded");
			}
		});
	});
	
	$('a.companyarea').each(function () {
		$(this).click(function() {
			resetLinks('companyarea');
			if ($(this).parent().parent().children('.previewJobsPlaceholder').html() != '') {
				$(this).parent().parent().children('.previewJobsPlaceholder').html('');
			} else {
				$('.previewJobsCont').remove(); 
				$('a.toChannelDetail').remove();
				var me = $(this).parent().parent();
				var companyid = me.children('.companyid').val();
			 	var lang=getLanguageString();
				$.get("/"+lang+"index.php?ac=ajax_cjo&companyid="+parseInt(companyid), function (text){
				  me.children('.previewJobsPlaceholder').append(text);
        });$(this).toggleClass("expanded");				
			}
		});
	});

	$('a.companyjobs').each(function () {
		$(this).click(function() {
			resetLinks('companyjobs');
			if ($(this).parent().parent().children('.previewJobsPlaceholder').html() != '') {
				$(this).parent().parent().children('.previewJobsPlaceholder').html('');
			} else {
				$('.previewJobsCont').remove(); 
				$('a.toChannelDetail').remove();
				var me = $(this).parent().parent();
				var companyid = me.children('.companyid').val();
				var channelid = $('#jobchannelcompany').children('.jobchannelpid').val();
			 	var lang=getLanguageString();
				$.get("/"+lang+"index.php?ac=ajax_channels&channelid="+parseInt(channelid)+"&companyid="+parseInt(companyid)+"&page=1&hits=5", function (text){
				  me.children('.previewJobsPlaceholder').append(text);
        });
        $(this).toggleClass("expanded");				
			}
		});
	});
}

$(document).ready(function () {
/*  $('.previewJobsCont').hide();*/

  $('a').click(function () {
    $(this).blur();
  });	
	
	startSlider();
	
	if (typeof $.prototype.tooltip == 'function'){
    $('.searchresult h3 a').each(function (){
      var ttCont = $(this).parents('.searchresult').children('.tooltipContent');
      if (ttCont.length > 0)
        $(this).tooltip({
    			bodyHandler: function() { 
    			        return '<img id="tt_arrow" src="/cust/jobstairs/images/tooltip_arrow.gif">'+ttCont.html();
    			},
    			showURL: false,
    			track: true,
    			delay: 0,
    			top: -5,
    			left: 20
    		});
      });
    }
		$('.h5Snippet a').each(function (){
		  //var ttCont = $(this).parents('.searchresult').children('.tooltipSnippet');
      if ($(this).parents('.snippet').attr("id") != "newssnippet")
		    //if (ttCont.length > 0)
    			$(this).tooltip({
    			bodyHandler: function() { 
    			        return '<img id="tt_arrow" src="/cust/jobstairs/images/tooltip_arrow.gif">'+$(this).next().html();
    			},
    			showURL: false,
    			track: true,
    			delay: 0,
    			top: -5,
    			left: 20
  		  });
		});
		
    setJobmemorizerTooltips();
	
	/** searchresult */
	var weiterleitenDiv = '';
	
	var moreOptionsDiv = '';
		
	var relevanceDiv = '';

  // initial bind functionLinks
	rebindFunctionLinks();
		
	/** jobchannels */
	var previewJobsDiv = '';
	var previewBerufsfelderDiv = '';
	
	$('a.toolBlockLink').each(function() {					
		$(this).click(function() {
			if ($(this).parent().children('.toolBlockPlaceholder').html() != '') {
				resetToolBlockLinks();
				$(this).parent().children('.toolBlockPlaceholder').html('');
			} else {
				$(this).parent().children('.toolBlockPlaceholder').append(previewJobsDiv);
				resetToolBlockLinks();
				$(this).toggleClass("expanded");
			}
		});	
	});
	
	/** login seite */
	$('a.loginMask').click(function () {
		if ($(this).parent().next().css("display") != 'none') {
			$(this).parent().next().hide();
		} else {
			$('a.loginMask').parent().next().hide();
			$(this).parent().next().show();
			resetLinks('loginMask');
			$(this).toggleClass("current");
		}
	});
	
	/** application form */
	$("a.minimize").click(function () {
		$(this).parent().next().toggle();
		$(this).toggleClass("expand");
	});

  /** faq */
	$('.faq').hide();
	$(".faq_list h3 a").click(function () {
		$(this).parent().next().toggle();
	});
	
});

/** application form functions */
function navigateApplicationForm(page,ac) {
	$('#page').val(page);
	$('#ac').val(ac);
	$('#formular05').submit();
}

function navigateApplicationFormMatrix(page,ac) {
	$.get("/inc/ajax_set_matrix_page.php", {matrix_page_id: page}, function(){navigateApplicationForm(page,ac)} );
}

function cancelApplicationForm() {
	$('#ac').val('statuspage');
	$('#formular05').submit();
	// todo: woanders hinleiten?
}

function cancelApplicationFormFromJobAd()
{
	//window.close();
	cancelApplicationForm();
}

function viewPreview() {
	$('#ac').val('application');
	$('#todo').val('preview');
	$('#formular05').submit();
}

function sendApplication(todo,page,ac) {
	$('#ac').val(ac);
	$('#page').val(page);
	$('#todo').val(todo);
	$('#formular05').submit();
}

function sendCandidateData(page,ac) {
	$('#ac').val(ac);
	$('#page').val(page);
	$('#todo').val('send');
	$('#formular05').submit();
}

function saveCandidateData(page,ac) {
	$('#ac').val(ac);
	$('#page').val(page);
	$('#todo').val('save');
	$('#formular05').submit();
}

/** flash functions */
function sendToRegion()
{
	var comboBox = document.forms['regionCombo'].region;
	var regValue = comboBox.options[comboBox.selectedIndex].value;
	
	thisMovie("jobLocator").sendToRegion(regValue);
}	

function sendToCountry()
{
	var comboBox = document.forms['countryCombo'].country;
	var regValue = comboBox.options[comboBox.selectedIndex].value;
	
	thisMovie("jobLocator").sendToCountry(regValue);
}

function mouseClickHandler(currentLevel,currentRegion,currentCountry,currentArea)
{
	//document.forms["formOutput"].output.value += "MouseClick Event: " + currentLevel + "," + currentRegion + "," + currentCountry + "," + currentArea  + "," + "\n";
}

function geoSearchHandler(param0, param1, param2, param3)
{
//alert("Search Event: " + param0 + "," + param1 + "," + param2 + "," + param3  + "\n");
 var lang=getLanguageString();
 $.get("/"+lang+"index.php?ac=geo_search&globalslider=80&p0="+escape(param0)+
      "&p1="+escape(param1)+"&p2="+escape(param2)+"&p3="+escape(param3)+"&scal="+$('#geo_funktion').val()+"&scel="+$('#geo_einstieg').val(), 
      function (text) { $("#realcontent").html(text); rebindFunctionLinks(); });

}


function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[movieName];
	} 
	else
	{
		return document[movieName];
	}
}

function setJobRSS(tmp)
{
	var a=window.open('/inc/jobrss_abo.php', 'Zweitfenster', 'width=800, height=600, scrollbars=yes, status=yes ,toolbar=no, menubar=no, resizable=yes');
}

function changeJobRSS(tmp)
{
	var a=window.open('/inc/jobrss_abo.php?jobabo_id='+parseInt(tmp), 'Zweitfenster', 'width=800, height=600, scrollbars=yes, status=yes ,toolbar=no, menubar=no, resizable=yes');
}


  $('div.functionLinks a.forwardSite').each(function() {
    var me = $(this);
		$(this).click(function() {
			if ($(this).parents('#contentEnd').children('.forwardplaceholder').html() != '') {
				resetFunctionlinks();
				$(this).parents('#contentEnd').children('.forwardplaceholder').html('');
			} else {		
				$('#weiterleiten').remove();
				$(this).parent().addClass('current');

				var url = location.href;
			 	var lang=getLanguageString();
				$.get("/"+lang+"index.php?ajax=ajax_forward&siteurl="+escape(url), function (text){
                    me.parents('#contentEnd').children('.forwardplaceholder').append(text);
	        });
			}
		});							
	});

