// DOCUMENT:  Javaskript-Funktionen für die Job-Details
// VERSION:   $Revision: 2.0 $
// DATE:      $Date: 2008-03-26 13:11:13 $
// AUTHOR:    M.Beranek
// COPYRIGHT: M.Beranek


// ---------------------------------------------------------------------------
/* Scroll-Effekt für die Merkliste im Bereich Detailansicht: */
/* ACHTUNG: "mtop" identisch mit "#sub_marker.top" aus "detailansicht.css" */
var mscroll = 0;
var mtop = 0;/*160;*/
var mtop_start = 43; /*54;*/  /*80;*/
var mscroll_min = 0;
var mscroll_max = 26;/*32;*/
	
var tmup;
var tmdn;
// ---------------------------------------------------------------------------
/**
* Merkliste in der Detail-Ansicht eines Jobs nach unten ausfahren.
*/
function scrollMarkerlistDown(){

	marker = xGetElementById("sub_marker");
	if( marker == null ) return;
	
	mtop = mtop_start + mscroll;
	if( mscroll < mscroll_max ){marker.style.top = mtop +"px";}
	++mscroll;
	
	if( mscroll < mscroll_max ){
		if( tmdn != null ){ clearTimeout(tmdn); }
		if( tmup != null ){ clearTimeout(tmup); }
		tmup = setTimeout( "scrollMarkerlistDown();", 10 );
	}
}


// ---------------------------------------------------------------------------
/**
* Merkliste in der Detail-Ansicht eines Jobs nach oben einfahren.
*/
function scrollMarkerlistUp(){

	marker = xGetElementById("sub_marker");
	if( marker == null ) return;
	
	--mscroll;
	if( mscroll >= 0 ){mtop = mtop_start + mscroll;}
	marker.style.top = mtop +"px";
	
	if( mscroll >= 0 ){
		if( tmdn != null ){ clearTimeout(tmdn); }
		if( tmup != null ){ clearTimeout(tmup); }
		tmdn = setTimeout( "scrollMarkerlistUp();", 10 );
	}
}


// ---------------------------------------------------------------------------
/**
* Merkliste positionieren.
*/
function markerlistDown(){
	marker = xGetElementById("sub_marker");
	if( marker == null ) return;
	mtop = mtop_start + mscroll_max;
	marker.style.top = mtop +"px";
}


var mvisible = 0;

// ---------------------------------------------------------------------------
/**
* Merkliste ein- oder ausschalten.
*/
function toggleMarkerList( num, sess ){
	if( mclicked == 1 ){
		showInfoLayer();
		showInfoMarked();
		return;
	}
	setMarkerList();
	jobmerken( num, sess );
	ma = xGetElementById( "markaction" );
	if( ma != null ){
		ma.className = "fadeout";
	}
	ma = xGetElementById( "markaction2" );
	if( ma != null ){
		ma.className = "action_disabled";
	}
	switch( mvisible ){
		case 0: {
			scrollMarkerlistDown();
			mvisible = 1;
			break;
		}
		/* nur aus, nicht einfahren...
		case 1: {
			scrollMarkerlistUp();
			mvisible = 0;
			break;
		}
		*/

	}
}


// ---------------------------------------------------------------------------
var tout;


// ---------------------------------------------------------------------------
/**
* Merkliste erst aus- und anschließend wieder einfahren.
*/
function markerListDownUp(){
	if( tout != null ){ clearTimeout(tout); }
	scrollMarkerlistDown();
	tout = setTimeout( "scrollMarkerlistUp();",2000);
}


// ---------------------------------------------------------------------------
/** 
* "Slide"-Effekt für die Menü- bzw. Navigations- oder Aktiones-Kästen in der 
* Detail-Ansicht bei Veränderung der Fenster-Größe.
*/
function winOnResize() {
	winOnScroll( 300 );
}

// ---------------------------------------------------------------------------
/** 
* "Slide"-Effekt für die Menü- bzw. Navigations- oder Aktiones-Kästen in der 
* Detail-Ansicht bei Veränderung der Scrollbar-Position.
*/
function winOnScroll( slideTime ) {
	
	if( slideTime < 0 ){
		slideTime = 0;
	} else {
		slideTime = 300;
	}
	
	// y1 = Abstand vom oberen Browserfenster bis zum Dokumentenbeginn:
	// y2 = Abstand von container_body bis bis oben
	// y3 = Abstand von container_center bis bis container_body
	// y4 = Abstand von job_detail_01 bis container_center
	
	var y1 = xScrollTop();
	/*
	var y3 = xGetElementById( "container_center" ).offsetTop;
	var y2 = xGetElementById( "container_body" ).offsetTop;
	var y4 = xGetElementById( "job_detail_01" ).offsetTop;
	*/
	var y3 = 0;
	cc = xGetElementById( "container_center" );
	if( cc != null ) y3 = cc.offsetTop;
	
	var y2 = 0;
	cb = xGetElementById( "container_body" );
	if( cb != null ) y2 = cb.offsetTop;
		
	var y4 = 0;
	jd01 = xGetElementById( "job_detail_01" );
	if( jd01 != null ) y4 = jd01.offsetTop;
	
	
	var rand = 120;
	var offset = y1;
	
	if( y1 > y2 + y3 +y4 -rand){
		offset = y2 +y3 +y4 -rand;
	}
	
	y = y1 +y3 +y4 - offset;
	
	// alert( "y1: " + y1 + " | y2: " + y2 + " | y3: " + y3 + " | y4: " + y4 + " | off: " + offset + " y: " + y );
	
	if( y < 0 ) y = 0;
	
	xSlideTo('container_right', 734, y, slideTime);
	// xSlideTo('container_right', ffCorrection, y, slideTime);
	
}


// ---------------------------------------------------------------------------
/**
* "Slide"-Effekt initialisieren.
*/
function initAnimation(){
	
	var cr = xGetElementById( "container_right" );
	winOnScroll( -1 )
	cr.style.visibility = "visible";
	
	
	xAddEventListener(window, 'resize', winOnResize, false);
	xAddEventListener(window, 'scroll', winOnScroll, false);
}


var mclicked = 0;
// ---------------------------------------------------------------------------
/**
* Anzahl der gemerkten Jobs in der Merkliste aktualisieren.
*/
function setMarkerList(){
	
	if( mclicked == 0 ){
		
		// DOM-Elemente:
		el1 = xGetElementById( "merkliste" );
		el2 = xGetElementById( "merkjobs" );
		
		if( el1 == null ) return;
		if( el2 == null ) return;
		
		// Anzahl:
		el1.innerHTML = ++remembered;
		
		// Einheit:
		if( remembered == 1 )
			el2.innerHTML = jobs_singular;
		else
			el2.innerHTML = jobs_plural;
		
		// Zustand:
		mclicked = 1;
		
	}
}


// ---------------------------------------------------------------------------
/**
* Merkliste initialisieren.
*/
function initMarkerList(){
	el = xGetElementById( "merkliste" );
	if( el == null ) return;
	el.innerHTML = remembered;	
}





/******************************************************************************/
/* Fehlende Angaben bei gesetzen Filtern:                                     */
/******************************************************************************/


//------------------------------------------------------------------------------
/**
* Ein-/Ausblend-Effekte für Haarfarbe.
*/
function checkSelectedHaircolor(){
	
	dropDownElement = xGetElementById( "id_hair_color" );
	inputElement    = xGetElementById( "id_hair_oth"   );
	
	if( document.missing.hair_color ){
		if( document.missing.hair_color.options[ document.missing.hair_color.options.selectedIndex ].value == 999 ){
			
			if( dropDownElement != null ){
				dropDownElement.className = "inp_select_half";
			}
			
			if( inputElement != null ){
				inputElement.style.display = "inline";
				inputElement.style.visibility = "visible";
			}
			
			document.missing.hair_oth.focus();
			
		} else {
		
			if( dropDownElement != null ){
				dropDownElement.className = "inp_select_wide";
			}
			
			if( inputElement != null ){
				inputElement.style.visibility = "hidden";
				inputElement.style.display = "none";
			}
			
		}
	}
}


//------------------------------------------------------------------------------
/**
* Ein-/Ausblend-Effekte für PKW/Kombi.
*/
function checkSelectedPKW(){
	
	inputElement    = xGetElementById( "id_pkw_kombi_label"   );
	
	if( document.missing.own_pkw ){
		if( document.missing.own_pkw.options[ document.missing.own_pkw.options.selectedIndex ].value == 1 ){
			
			document.missing.pkw_kombi.disabled = false;
			
			if( inputElement != null ){
				inputElement.className = "checkbox_select_text";
			}
			
		} else {
			
			document.missing.pkw_kombi.checked  = false;
			document.missing.pkw_kombi.disabled = true;
			
			if( inputElement != null ){
				inputElement.className = "checkbox_select_text_disabled";
			}
			
		}
	}
}


//------------------------------------------------------------------------------
/**
* Ein-/Ausblend-Effekte für Sprachen und Sprach-Qualitäten.
*/
function checkSelectedLanguage( lang ){
	
	dropDownElement = null;
	inputElement    = null;
	langValue       = 0;
	
	if( document.missing.l01 == null ){ return }
	if( document.missing.l02 == null ){ return }
	if( document.missing.l03 == null ){ return }
	if( document.missing.l04 == null ){ return }
	if( document.missing.l05 == null ){ return }
	
	switch( lang ){
		case 1:{
			dropDownElement = xGetElementById( "id_lang_01" );
			inputElement    = xGetElementById( "id_lang_01t" );
			langValue       = document.missing.l01.value;
			break;
		}
		case 2:{
			dropDownElement = xGetElementById( "id_lang_02" );
			inputElement    = xGetElementById( "id_lang_02t" );
			langValue       = document.missing.l02.value;
			break;
		}
		case 3:{
			dropDownElement = xGetElementById( "id_lang_03" );
			inputElement    = xGetElementById( "id_lang_03t" );
			langValue       = document.missing.l03.value;
			break;
		}
		case 4:{
			dropDownElement = xGetElementById( "id_lang_04" );
			inputElement    = xGetElementById( "id_lang_04t" );
			langValue       = document.missing.l04.value;
			break;
		}
		case 5:{
			dropDownElement = xGetElementById( "id_lang_05" );
			inputElement    = xGetElementById( "id_lang_05t" );
			langValue       = document.missing.l05.value;
			break;
		}
	}
	
	
	if( langValue == 999 ){
		
		if( dropDownElement != null ){
			dropDownElement.className = "inp_select_lang_half";
		}
		
		if( inputElement != null ){
			inputElement.className = "inp_lang_visible";
		}
		
	} else {
		
		if( dropDownElement != null ){
			dropDownElement.className = "inp_select_lang";
		}
		
		if( inputElement != null ){
			inputElement.className = "inp_lang_hidden";
		}
		
	}
	
	
}




