/*
verschiedene Mehthoden 
*/
/*
- returns keyCode of the current even
*/
function getKey(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

/*
Liefert den Wert des selektieren Radiobuttons:obj
obj ist der Name des RadioButtons im Document
*/
function getRadioValue(obj)
			{
				if(!obj) return "";
				
				if(obj.length == undefined)
					if(obj.checked) return obj.value;
					else return "";
				
				for(var i=0; i < obj.length; i++)
				{
					if(obj[i].checked) return obj[i].value;
				}
				return "";
			}
			
/*
Liefert alle Werte einer Mehrfachauswahl zurueck,
verkettet mit dem ampersand fuer einen Link
*/
function getSelectValueChain(obj)
{
	if(!obj) return "";
	
	var chain="";
	var param_name = obj.name ;
	
	for(var i=0; i < obj.length; i++)
	{
		if(obj.options[i].selected)
			chain=chain+'&'+param_name+'='+obj.options[i].value;
	}
	return chain;
}


/*

Liefert alle Werte einer Mehrfachauswahl fuer Checkboxen zurueck,
verkettet mit dem ampersand fuer einen Link
*/
function getCheckedValueChain(paramName)
{
	if(!paramName) return "";
	
	//all Objekte holen mit demselben Paramname
	obj  = document.getElementsByName(paramName);
	
	var chain="";
	var param_name = paramName ;
	
	for(var i=0; i < obj.length; i++)
	{
		if(obj[i].checked)
			chain=chain+'&'+param_name+'='+obj[i].value;
	}
	

	
	return chain;
}

/*

Liefert alle Werte einer Mehrfachansammlung fuer Text-Felder,
verkettet mit dem ampersand fuer einen Link
*/
function getInputValueChain(paramName)
{
	if(!paramName) return "";
	
	//all Objekte holen mit demselben Paramname
	obj  = document.getElementsByName(paramName);
	
	var chain="";
	var param_name = paramName ;
	
	for(var i=0; i < obj.length; i++)
	{
		
			chain=chain+'&'+param_name+'='+obj[i].value;
	}
	

	
	return chain;
}



function fensterOeffnen(adresse,anzeigeId) {
  adresse = adresse+'&anzeige_id='+anzeigeId;
  //jsAnzeigeId = getRadioValue(document.formJobManage.anzeige_id);
  //adresse = adresse+'&anzeige_id='+jsAnzeigeId;
  if (anzeigeId > 0){
  	//von Initial so vorgegeben, oeffnet je nach Browser ein unterschiedlich grosses Fenster
  	//Fenster1 = window.open(adresse, "popup", "width=900,height=auto,left=10,top=0,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1");
 	Fenster1 = window.open(adresse, "popup", "width=900,height=700,left=10,top=0,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1");
 	
 	 Fenster1.focus();
	}
}

/**
Oeffnet ein neues Browserfenster mit Adresse theUrl und Breite width
und Hoehe height. Die Browserfunktionen sind ausgeschaltet, d.h. keine Toolbar.
*/
function hbOpenWindow(theUrl,hbWidth,hbHeight){
	//alert('hbHeight ' + hbHeight);
	//window.open(theUrl, "popup", "width=hbWidth,height=hbHeight,left=10,top=0,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1");
 	paramStr = 'width='+hbWidth+',height='+hbHeight+',left=10,top=0,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1';
 	window.open(theUrl, "popup", paramStr);
} 

/*

Liefert den Wert fuer den Disclaimer: wenn die Checkbox gesetzt ist, wird 1 zurueckgeliefert, 
sonst 0.
*/
function getCheckedDisclaimer(obj)
{
	
	var disclaimerChecked = 0;
	
		if(obj.checked){
			disclaimerChecked = 1;
		}
		else{
		disclaimerChecked = 0;
		}
	
	return disclaimerChecked;
}

//Arrays zum Speichern von Datens?tzen
// Arrays fuer Regionen der Stufe 1, 2 und 3
var Kontinente = new Array();
var Laender = new Array();
var Bezirke = new Array();

// Arrays fuer Fachbereiche der Stufe 1, 2 und 3
var Fachbereiche = new Array();
var Spezialisierungen2 = new Array();
var Spezialisierungen3 = new Array();

// Arrays fuer Branchen der Stufe 1, 2 und 3
var Branchen = new Array();
var Unterbranchen = new Array();
var Unterunterbranchen = new Array();

// Kreiert einen Eintrag, um die Hierarchie aus der Datebank
// in den JavaScript-Objekten abzubilden
// id: ID des Items aus der DB
// name: String, der den Namen der
// Author: MS
function createEintrag(id, name, parentid) {
  var eintrag = new Array();
  eintrag[0] = id;
  eintrag[1] = name;
  eintrag[2] = parentid;
  return eintrag;
}

// Fuegt ein Element child ans Ende eines Arrays parent hinzu
// Author: MS
function append(parent, child) {
  parent[parent.length] = child;
}


// NICHT BENUTZEN, DA VERALTET. EXISTIERT NOCH, 
// WEIL ALTE FUNKTION IN search.html NOCH VERWENDET WIRD
//
// fuelle eine Selektionsbox mit den zugehoerigen Items
//
// id ist die Id des Elternitems
// menuName ist der Name der Selektionsbox, die gef?llt werden soll
// Author: MS
function fuelleSB (id, menuName)
{
	fuelleSB (id, menuName, Laender);
}

// f?lle eine Selektionsbox mit den zugeh?rigen Items
//
// id ist die Id des Elternitems
// menuName ist der Name der Selektionsbox, die gefuellt werden soll
// auswahlArray - Name des Arrays, von dem die Eintraege fuer menuName geholt werden
// Author: MS
function fuelleSB (id, menuName, auswahlArray)
{
	id = parseInt(id);

	for (i=1; i<=menuName.length ; i++) {
		menuName[i] = null;
	}

	counter = 0;

	for (j=0; j<=auswahlArray.length - 1; j++) {
		if (id == auswahlArray[j][2]) {
			menuName[counter] = new Option (auswahlArray[j][1]);
			menuName[counter].value = auswahlArray[j][0];
			counter++;
		}
	}

	menuName[0].selected = true; 
}


// Initialisiert eine Selektionsbox neu
// Author: MS
function initSB(menuName, wert, text)
{
	var i;

	//alert('menuName: '+menuName);
	
	if(menuName.length == 0) {
		menuName[0] = new Option (text);
		menuName[0].value = wert;
		menuName[0].selected = true; 
	}

	else {
		menuName[0].selected = true; 
		for(i=1; i<menuName.length; i++)
			menuName[i].selected = false; 				
	}

}


// L?scht die Eintr?ge in einer Selektionsbox
// Author: MS
function loescheSB(menuName)
{
	var i;

	for (i=menuName.length; i>=0 ; i--) {
		menuName[i] = null;
	}
}


// Nach der Selektion in einer Selektionsbox (der elternSB) werden 
// die Elemente in einer zweiten Selektionsbox (kindSB) bestimmt.
//
// elternSB - Selektionsbox, deren Auswahl die Elemente in kindSB bestimmt
// kindSB - Selektionsbox, die von der Selektion in elternSB gefuellt wird
// auswahlArray - Name des Arrays, von dem dei Eintraege fuer kindSB 
// geholt werden
// selectFirst - true, falls erste Option angeklickt werden sollte,
// sonst false
// Author: MS
function fuelleMultiple(elternSB, kindSB, auswahlArray, selectFirst)
{
	var i, j=0;
	var selektiert = new Array();

	// Die schon im Kind-Selectionsbox selektierten werden gemerkt und erscheinen noch selektiert
	for (i = kindSB.length-1; i>=0 ; i--) {
		if(kindSB.options[i].selected == true) {
			selektiert[j] = kindSB.options[i].value;
			j++;
		}
	}

	loescheSB(kindSB);	

	for(i=0; i < elternSB.length; i++) {
		if(elternSB.options[i].selected == true) {
			//alert(elternSB.options[i].value);
			//if(elternSB.options[i].value != 0) {
				zeigeSB(elternSB.options[i].value, kindSB, auswahlArray, selectFirst);
			//}
		}
	}

	for(i=0; i < kindSB.length; i++)		
		for(j=0; j < selektiert.length; j++)
			if(kindSB.options[i].value == selektiert[j])
				kindSB.options[i].selected = true;

//	initSB(kindSB, 0, \"<---Alles--->\");

}


// F?lle eine Selektionsbox mit Werten aus einem Array
//
// value - Wert, der in die SB hinzugef?gt wird
// kindSB - Selektionsbox, die gef?llt werden soll
// auswahlArray - Array, von dem der Eintrag fuerr die SB kommt
// selectFirst - true, falls erste Option angeklickt werden sollte,
// sonst false
// Author: MS
function zeigeSB(value, kindSB, auswahlArray, selectFirst)
{
	var i;
	var first = true;
	counter = kindSB.length;

	for(i=0; i < auswahlArray.length; i++) {
		if(auswahlArray[i][2] == value) {
			kindSB[counter] = new Option (auswahlArray[i][1]);
			kindSB[counter].value = auswahlArray[i][0];
			if (first && selectFirst) {
				kindSB.options[counter].selected = true;
			}
			first = false;
			counter++;
		}
	}
}


// oeffnet ein neues Fenster mit der angegebenen Datei
// Author: MS
function openwin(myfile){
	winname="Hilfe"
	//winname=myfile
	myfilename= myfile
	params = "width=250,height=200,resizable=1,status=0,scrollbars=1,toolbar=0,location=0,directories=0,menubar=0 ";
	newwin = window.open( myfilename, winname , params)
}

// Funktion, um in der Suchseite bei vorausgewaehlten Werten fuer HAPs
// auf diese zu scrollen
function initSearchForHAPs(){

  //regionid
 for(var i=0; i < document.suchformular.regionid.length; i++){
	 if(document.suchformular.regionid[i].selected){
		document.suchformular.regionid[i].scrollIntoView();
		break;
	 }
  }//for


  //landid
  for(var i=0; i < document.suchformular.landid.length; i++){
	 if(document.suchformular.landid[i].selected){
		document.suchformular.landid[i].scrollIntoView();
		break;
	 }
  }//for

 //bezirkid
  for(var i=0; i < document.suchformular.bezirkid.length; i++){
	 if(document.suchformular.bezirkid[i].selected){
		document.suchformular.bezirkid[i].scrollIntoView();
		break;
	 }
  }//for

  //Fachbereiche
   for(var i=0; i < document.suchformular.funkbzid.length; i++){
	 if(document.suchformular.funkbzid[i].selected){
		document.suchformular.funkbzid[i].scrollIntoView();
		break;
	 }
  }//for

 for(var i=0; i < document.suchformular.spezialbz2id.length; i++){
	 if(document.suchformular.spezialbz2id[i].selected){
		document.suchformular.spezialbz2id[i].scrollIntoView();
		break;
	 }
  }//for

 for(var i=0; i < document.suchformular.spezialbz3id.length; i++){
	 if(document.suchformular.spezialbz3id[i].selected){
		document.suchformular.spezialbz3id[i].scrollIntoView();
		break;
	 }
  }//for

 //Branchen
 for(var i=0; i < document.suchformular.brancheid.length; i++){
	 if(document.suchformular.brancheid[i].selected){
		document.suchformular.brancheid[i].scrollIntoView();
		break;
	 }
  }//for

  for(var i=0; i < document.suchformular.unterbrancheid.length; i++){
	 if(document.suchformular.unterbrancheid[i].selected){
		document.suchformular.unterbrancheid[i].scrollIntoView();
		break;
	 }
  }//for



  //wieder an den Anfang oben scrollen
   document.getElementsByTagName("html")[0].scrollIntoView();
}//function




// Funktion, um in der Suchseite bei vorausgewaehlten Werten fuer HAPs
// auf diese zu scrollen
//die Branchen sind deaktiviert worden, das fuehrt zu einem Fehler in der bisherigen Javascript
//Funktion  deswegen neue Funktion hier
function initSearchForHAPsOhneBranchen(){

  //regionid
 for(var i=0; i < document.suchformular.regionid.length; i++){
	 if(document.suchformular.regionid[i].selected){
		document.suchformular.regionid[i].scrollIntoView();
		break;
	 }
  }//for


  //landid
  for(var i=0; i < document.suchformular.landid.length; i++){
	 if(document.suchformular.landid[i].selected){
		document.suchformular.landid[i].scrollIntoView();
		break;
	 }
  }//for

 //bezirkid
  for(var i=0; i < document.suchformular.bezirkid.length; i++){
	 if(document.suchformular.bezirkid[i].selected){
		document.suchformular.bezirkid[i].scrollIntoView();
		break;
	 }
  }//for

  //Fachbereiche
   for(var i=0; i < document.suchformular.funkbzid.length; i++){
	 if(document.suchformular.funkbzid[i].selected){
		document.suchformular.funkbzid[i].scrollIntoView();
		break;
	 }
  }//for

 for(var i=0; i < document.suchformular.spezialbz2id.length; i++){
	 if(document.suchformular.spezialbz2id[i].selected){
		document.suchformular.spezialbz2id[i].scrollIntoView();
		break;
	 }
  }//for

 for(var i=0; i < document.suchformular.spezialbz3id.length; i++){
	 if(document.suchformular.spezialbz3id[i].selected){
		document.suchformular.spezialbz3id[i].scrollIntoView();
		break;
	 }
  }//for


  //wieder an den Anfang oben scrollen
   document.getElementsByTagName("html")[0].scrollIntoView();
}//function

function Hilfe(File)
	{
      var newWindow = window.open(File, "Hilfe", "width=250,height=300,resizable=yes,scrollbars=yes,toolbar=no,status=yes,directories=no,menubar=no,location=yes")
		newWindow.focus()
	}

//Oeffnet in Fenster fuer das Upload-Fenster
function popupUpload(theURL) { //v2.0
window.open(theURL,'upload','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=630,height=350,dependent=yes,top=50,left=100').focus;
}

//Setzt den Iframe auf die Hoehe des Dokuments, was innerhalb des Iframes
//angezeigt wird: dadurch braucht man den vertikalen Scrollbalken nicht
function iFrameHeight(elementId) {
	
	var h = 0;
	if ( !document.all ) {	
		h = document.getElementById(elementId).contentDocument.height;
		document.getElementById(elementId).style.height = h + 60 + 'px';
	} else if( document.all ) {
		h = document.frames(elementId).document.body.scrollHeight;
		document.all.blockrandom.style.height = h + 20 + 'px';
	}
}//end function


//Setzt den Iframe auf die Hoehe und Breite des Dokuments, was innerhalb des Iframes
//angezeigt wird: dadurch braucht man den vertikalen und horizontalen Scrollbalken nicht
function iFrameHeightAndWidth(elementId) {
	var h = 0;
	var w=0;
	if ( !document.all ) {
		h = document.getElementById(elementId).contentDocument.height;
		document.getElementById(elementId).style.height = h + 60 + 'px';
		//Breite
		w =  document.getElementById(elementId).contentDocument.width;
		document.getElementById(elementId).style.width = w + 60 + 'px';
	} else if( document.all ) {
		h = document.frames(elementId).document.body.scrollHeight;
		document.all.blockrandom.style.height = h + 20 + 'px';
		//Breite
		w =   document.frames(elementId).document.body.scrollWidth;
		document.getElementById(elementId).style.width = w + 20 + 'px';
	}
}//end function


/*
Funktionen fuer progressbar
*/

var progressEnd = 9; // set to number of progress <span>'s.
var progressColor = 'lightgreen'; // set to progress bar color
var progressInterval = 1000; // set to time between updates (milli-seconds)

var progressAt = progressEnd;
var progressTimer;

function progress_clear() {
for (var i = 1; i <= progressEnd; i++) document.getElementById('progress'+i).style.backgroundColor = 'transparent';
progressAt = 0;
}

function progress_update() {
document.getElementById('showbar').style.visibility = 'visible';
progressAt++;
if (progressAt > progressEnd) progress_clear();
else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
progressTimer = setTimeout('progress_update()',progressInterval);
}

function progress_stop() {
clearTimeout(progressTimer);
progress_clear();
document.getElementById('showbar').style.visibility = 'hidden';
}

function hb_progress_update(progessEndNew) {
progressEnd = progessEndNew;
progressAt = progressEnd;
//alert('progressAt: ' +progressAt +' ---- progressEnd: ' +progressEnd);
document.getElementById('showbar').style.visibility = 'visible';
progressAt++;
if (progressAt > progressEnd) progress_clear();
else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
progressTimer = setTimeout('progress_update()',progressInterval);
}

// Funktion, die Link in einem Iframe aufruft
function setIframe(frameName,url){
parent[frameName].location.href = url;
}//end function


/*
Funktionen fuer progressbar
*/

var progressEnd = 9; // set to number of progress <span>'s.
var progressColor = 'lightgreen'; // set to progress bar color
var progressInterval = 1000; // set to time between updates (milli-seconds)

var progressAt = progressEnd;
var progressTimer;

function progress_clear() {
for (var i = 1; i <= progressEnd; i++) document.getElementById('progress'+i).style.backgroundColor = 'transparent';
progressAt = 0;
}

function progress_update() {
document.getElementById('showbar').style.visibility = 'visible';
progressAt++;
if (progressAt > progressEnd) progress_clear();
else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
progressTimer = setTimeout('progress_update()',progressInterval);
}

function progress_stop() {
clearTimeout(progressTimer);
progress_clear();
document.getElementById('showbar').style.visibility = 'hidden';
}

function hb_progress_update(progessEndNew) {
progressEnd = progessEndNew;
progressAt = progressEnd;
//alert('progressAt: ' +progressAt +' ---- progressEnd: ' +progressEnd);
document.getElementById('showbar').style.visibility = 'visible';
progressAt++;
if (progressAt > progressEnd) progress_clear();
else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
progressTimer = setTimeout('progress_update()',progressInterval);
}

// Funktion, die Link in einem Iframe aufruft
function setIframe(frameName,url){
parent[frameName].location.href = url;
}//end function




