/*
by milch&zucker AG/ sag
element anzeigen/ausblenden
*/

var jobTimer, curJobAd, blurTimer;
var _offset = new Array();

$(document).ready(function () {
	var inTTActiveArea = false;
});


function switchDisplay(id){
doc=document.getElementById(id);
 if(doc.style.display == 'none')
  doc.style.display = 'block';
 else
  doc.style.display = 'none';
}

function switchDisplayFaq(id){
doc=document.getElementById(id);
 if(doc.style.display == 'none')
  doc.style.display = 'block';
 else
  doc.style.display = 'none';
}

function showSites(){
doc=document.getElementById('other_career_sites');
btc=document.getElementById('career_sites');
 if(doc.style.display == 'none'){
  doc.style.display = 'block';
  btc.className = 'career_sites_open';
}else{
  doc.style.display = 'none';
  btc.className = 'career_sites';
 }
}

function popup(ziel,breite,hoehe,scroller) {
	if (!scroller) var scroller='yes';
	window.open(''+ziel+'','','width='+breite+',height='+hoehe+',scrollbars='+scroller+',resizable=yes');
	}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function check_email(formname,field){
	var content="document."+formname+"."+field+".value";
	var content2=eval(content);

	var nReg=new RegExp("^[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\@[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+(\.[a-zA-Z0-9]+[a-zA-Z0-9\-]*[a-zA-Z0-9]+)*\.[a-zA-Z]{2,3}$");
	result = nReg.test(content2);
	if(result!=false || content2=="")
	{
		return true;
	}
	else
	{
		return false;
	}
}

function displaySitemap(show){
	if (show == 1){
		displayBlurLayer(1);
		doc = document.getElementById('popupLayer');
		doc.style.left = '180px';
		doc.style.top = '100px';
		document.getElementById('popupLayerIframe').src = WMS_CUSTOMER+'/page_popup.php?type=sitemap&language='+lng+'&layer=1';
	}
	else{
		document.getElementById('popupLayer').style.left = '-10000px';
		document.getElementById('popupLayerIframe').src = WMS_CUSTOMER+'/popup_loading.php';
		displayBlurLayer(0);
	}
}
function displayLightBox(show,type,left,top,width,extend){
	if (show == 1){
		displayBlurLayer(1);
		doc = document.getElementById('popupLayer');
		doc_iframe = document.getElementById('popupLayerIframe');
		doc.style.left = left;
		doc.style.top = top;
		doc.style.width = width;
		doc_iframe.style.width = width;
		doc_iframe.src = WMS_CUSTOMER + '/page_popup.php?type='+ type +'&language='+lng+'&layer=1'+extend;
	}
	else if(show == 2){
		document.getElementById('popupLayerIframe').src = WMS_CUSTOMER + '/popup_loading.php';
		displayBlurLayer(0);
	}
	else{
		document.getElementById('popupLayer').style.left = '-10000px';
		document.getElementById('popupLayerIframe').src = WMS_CUSTOMER + '/popup_loading.php';
		displayBlurLayer(0);
	}
}
function displayJobLightBox(show,left,top,jobId,href_name,skinWidth){

	var hasSkin = false;

	if(skinWidth == '' || skinWidth == 'false' || skinWidth == 0){
		skinWidth = '595px';
	}
	else{
		skinWidth = parseInt(skinWidth)+20;//Plus Scrollbalken
		skinWidth = skinWidth.toString() + 'px';
		hasSkin = true;
	}

	doc = document.getElementById('popupLayer');

	if (show == 1){
		displayBlurLayer(1);
		doc.style.left = left;
		doc.style.top = top;
		doc.style.width = skinWidth;
		//document.getElementById('popupLayerIframe').src = WMS_SHORT + 'extern/jobskin_test.php?layer=1';

		if(hasSkin === false){
			document.getElementById('popupClose').style.display = 'none';
			document.getElementById('popupLayerIframe').src = WMS_WWW + '/Job/'+ jobId +'/'+ href_name +'.html';
		}
		else{
			document.getElementById('popupClose').style.display = 'block';
			document.getElementById('popupLayerIframe').src = 'https://myjobs-de.becruiter.net/jobagent/search/default.aspx?jobid='+ jobId;
		}
		document.getElementById('popupLayerIframe').style.width = skinWidth;
	}
	else{
		doc.style.left = '-10000px';
		doc.style.width = skinWidth;
		document.getElementById('popupLayerIframe').src = WMS_CUSTOMER + '/popup_loading.php';
		displayBlurLayer(0);
	}
}

function displayBlurLayer(show){
	if (show == 1){
		/*$('#flashlayer_white object, #flashlayer_white, #weiss, #popupLayer').click(function () {
			displaySitemap(0);
		});*/
		document.getElementById('flashlayer_white').style.left = '0px';
	}
	else{
		document.getElementById('flashlayer_white').style.left = '-10000px';
	}
}

function setJobTimer(jobId,href_name,jobSkinWidth){
	window.clearTimeout(jobTimer);
	window.clearTimeout(blurTimer);
	curJobAd = jobId;
	viewJobDetail();
	jobTimer = window.setTimeout('loadJobDetail('+jobId+',\''+href_name+'\',\''+jobSkinWidth+'\')',750);
}

function deletJobTimer(){
	//window.clearTimeout(jobTimer);
	inTTActiveArea = false;
	blurTimer = window.setTimeout('checkAndHideLayer()',1000);
}


function showJobDetail(jobId,href_name,jobSkinWidth){

	var RESOURCE_help = '';
	if(lng == 1)
	{
		RESOURCE_help = 'Klicken Sie hier, um den Layer zu schliessen!';
	}
	else
	{
		RESOURCE_help = 'Please click outside this window to close.';
	}

	$('.tooltip').fadeOut();
	var url = WMS_WWW + '/wms/extern/jobsearch_detail_ajax.php';
	pars = '&jobId='+ jobId +'&action=layer';

	try {
		$.ajax({
	    	type: "POST",
	    	url: url,
	    	data: pars,
	    	async: false,
	    	success: function(opt){
	    	}
	    });

	} catch(e) {alert('error in showJobDetail()');}

	displayJobLightBox(1,'180px','100px',jobId,href_name,jobSkinWidth);
	if ($.support.style) // is a modern browser (!ie)
		setTimeout('bindTTMouseover();',800);
	else
		$('#flashlayer_white').attr({alt: RESOURCE_help , title: RESOURCE_help });
}


function loadJobDetail(jobId,href_name,jobSkinWidth){
	var url = WMS_WWW +'/wms/extern/jobsearch_detail_ajax.php';
	pars = '&jobId='+jobId+'&url='+href_name+'&jobSkinWidth='+jobSkinWidth+'&action=detail';

	try {
		$.ajax({
	    	type: "POST",
	    	url: url,
	    	data: pars,
	    	async: false,
	    	success: function(opt){

	    		if(opt != ''){
	    			$('#detailInner').html(opt);
	    		}
	    	}
	    });
	} catch(e) {alert('error in getStandardBox()');}
}


function viewJobDetail(){
	$('#detailInner').html('<br/><img src="'+WMS_SHORT+'images/ajax_loading.gif"/><div class="clearer">&nbsp;</div><br/>');
	setMouseOut();

	$('.tooltip').children('.tooltipArrow').removeClass('ttRight');

	var offset = $('#jobad_'+curJobAd).offset();

	if ((offset["top"]+$('.tooltip').outerHeight())<= $(document).height())
		$('.tooltip').css('top',(offset["top"]-45)+'px');
	else {
		$('.tooltip').css('top',(offset["top"]-$('.tooltip').outerHeight()+128+'px'));
		$('.tooltip').addClass("ttTop");
	}

	if (offset["left"] > $('.tooltip').outerWidth())
		$('.tooltip').css('left',(offset["left"]-$('.tooltip').outerWidth()-4)+'px');
	else {
		$('.tooltip').children('.tooltipArrow').addClass('ttRight');
		$('.tooltip').css('left',(offset["left"]+5)+'px');
	}
	$('.tooltip').fadeIn();
}


function updateTooltipPosition()
{
	//var offset = $('#jobad_'+curJobAd).offset();
	var offset = new Array();
	offset["left"] = _offset["left"]
	offset["top"] = _offset["top"]

	if ((offset["top"]+$('.tooltip').outerHeight())<= $(document).height())
		$('.tooltip').css('top',(offset["top"]-10)+'px');
	else {
		$('.tooltip').css('top',(offset["top"]-$('.tooltip').outerHeight()+128+'px'));
		$('.tooltip').addClass("ttTop");
	}

	if (offset["left"] > $('.tooltip').outerWidth())
	{
		$('.tooltip').css('left',(offset["left"]-$('.tooltip').outerWidth()-30)+'px');
		$('.tooltip').children('.tooltipArrow').removeClass('ttRight');
	}
	else
	{
		$('.tooltip').children('.tooltipArrow').addClass('ttRight');
		$('.tooltip').css('left',(offset["left"]+30)+'px');
	}
}

function bindTTMouseover()
{
	var RESOURCE_help = '';

	if(lng == 1)
	{
		RESOURCE_help = 'Klicken Sie hier, um den Layer zu schlie&szlig;en!';
	}
	else
	{
		RESOURCE_help = 'Please click outside this window to close.';
	}


	$('#flashlayer_white').mousemove(function (e) {
		_offset["left"] = e.pageX;
		_offset["top"] = e.pageY;

		updateTooltipPosition();
	});

	$('.tooltip').css("z-index",10005);

	$('#detailInner').html(RESOURCE_help);
	$('.tooltip').children('.tooltipArrow').removeClass('ttRight');

	updateTooltipPosition();

	$('#flashlayer_white').mouseover(function () {
		if ($('.tooltip').css("display") == "none")
		{
			$('.tooltip').addClass("layerNote");
			setTimeout(function () {
				$('.tooltip').fadeIn();
			}, 100);
		}
	});

	$('#popupLayer').mouseover(function () {
		$('.tooltip').fadeOut();
		setTimeout(function () {
			$('.tooltip').removeClass("layerNote");
		}, 200)
	});
}

function checkAndHideLayer() {
	if (!inTTActiveArea)
		$('.tooltip').hide();
}

function setMouseOut() {
	$('#lb_'+curJobAd+', .tooltip').mouseout(function () {
		inTTActiveArea = false;
		window.setTimeout('checkAndHideLayer()',250);
	});

	$('#lb_'+curJobAd+' *, .tooltip *').mouseover(function () {
		inTTActiveArea = true;
	});
}


function enhancedView(postingId,href_name,jobSkinWidth){
	parent.enhancedViewLoad(postingId,href_name,jobSkinWidth);
}