
// telepark.cms 
// (c) by telepark

// open new window
function newWindow(url,name,width,height) {
	fenster = window.open (
	url,
	name, 					// name
	'toolbar=0' 			// tool bar 
	+',location=0' 			// address bar
	+',directories=0' 		// additional bars
	+',status=0' 			// status bar
	+',menubar=0' 			// menu bar
	+',scrollbars=1' 		// scroll bars
	+',resizable=1' 		// window resizable
	+',width=' + width 		// window width in pixels
	+',height=' + height 	// window height in pixels
	);
}

// get focus
function getfocus() {
	self.focus();
}

// create HttpRequest
function createHttpRequest() {
	var xmlhttp;
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
  		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
  										'MSXML2.XMLHTTP.5.0',
  										'MSXML2.XMLHTTP.4.0',
  										'MSXML2.XMLHTTP.3.0',
  										'MSXML2.XMLHTTP',
  										'Microsoft.XMLHTP'
  										);
  		for (var i = 0; i<XmlHttpVersions.length && !xmlhttp; i++) {
  			try {
  				xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
  			}
  			catch(e) {
  			}
  		}
 	}
 	if (!xmlhttp) {
 		alert('Error creating the XMLHttpRequest object.');
 	} else {
		return xmlhttp;
 	}
}

// disable/enable all form fields
function toggleFormFields(status,target) {
	// status
	if (status == "disable") status = true;
	else status = false;
	// toggle input, select and textarea fields
	if (target != "") {
		var mls = target.document.forms;
	}
	else var mls = document.forms;
	for (var j=0; j<mls.length; j++) {
		ml=mls[j];
		var len = ml.elements.length;
		for (var i=0; i<len; i++) {
			var e = ml.elements[i];
			//alert("tagName: " + e.tagName + ", name:" + e.name);
			if (e.tagName == "INPUT" || e.tagName == "SELECT" || e.tagName == "TEXTAREA") {
				e.disabled = status;
			}
		}
	}
}

// loading animation
function loading(f) {
	try {
	// hide
	if (f != true) {
		if (document.getElementById('status')) {
			document.getElementById('status').style.display = 'none';
			toggleFormFields("enable","");
		}
		else if (parent.document.getElementById('status')) {
			parent.document.getElementById('status').style.display = 'none';
			toggleFormFields("enable","parent");
		}
	} 
	// show
	else {
		if (document.getElementById('status')) {
			document.getElementById('status').style.display = 'block';
			toggleFormFields("disable","");
		}
		else if (parent.document.getElementById('status')) {
			parent.document.getElementById('status').style.display = 'block';
			toggleFormFields("disable","parent");
		}
	}
	} catch(e){}
}

// input field restriction
MS_restrict_field = function(formname, id_or_name, chars) {
	var obj = (document.getElementById && document.getElementById(id_or_name) != null)
			  ? document.getElementById(id_or_name) : ((document[formname][id_or_name] != null)
			  ? document[formname][id_or_name] : '');

	if(obj.type == "text" || obj.type == "textarea") {
		obj.timer = "";
		obj.chars = chars;
		obj.onkeypress = obj.onkeydown = function() {
			var self = this;
			controll = function() {
				for(var t='',x=0; x<self.value.length; ++x) {
					if(self.chars.indexOf(self.value.charAt(x))>-1) {
						t += self.value.charAt(x);
					}
				}
				self.value = t;
			};
			this.timer = setTimeout(controll,1);
		};
		obj.onkeyup = function() {
			clearTimeout(this.timer);
		};
	}
};

// PRAKTIKA
// ========

// reload praktika list (frontend)
function frontendReloadPraktikaList(userid,searchstring) {
	loading(true);
	
	var s = '';
	
	if (!searchstring || searchstring == "undefined" || searchstring == '') {
		if (document.getElementById('searchpraktikum')) {
			s = encodeURI(document.getElementById('searchpraktikum').value);
		}
	}
	else if (searchstring != '') {
		s = encodeURI(searchstring);
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadPraktikaList.php?userid=" + userid + "&searchstring=" + s, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// delete praktikum
function frontendDeletePraktikum(pracid,userid,searchstring,page) {
	loading(true);
	var c = confirm('Möchten Sie dieses Praktikum wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeletePraktikum.php?pracid=" + pracid + "&searchstring=" + searchstring + "&page=" + page, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				if (page && page > 0) frontendReloadPraktikumSearchResults(page);
				else frontendReloadPraktikaList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// toggle Kontaktart
function toggleKontaktart(art) {
	if (art == 1) {
		if (document.getElementById('public_contact') && document.getElementById('anonymous_contact')) {
			document.getElementById('public_contact').style.display = "block";
			document.getElementById('anonymous_contact').style.display = "none";
		}
	}
	else if (art == 2) {
		if (document.getElementById('public_contact') && document.getElementById('anonymous_contact')) {
			document.getElementById('public_contact').style.display = "none";
			document.getElementById('anonymous_contact').style.display = "block";
		}
	}
}

// delete praktikum
function frontendSetPraktikumStatus(pracid,searchstring,newstatus,userid) {
	loading(true);
	if (newstatus == 0) var question = 'Möchten Sie dieses Praktikum wirklich inaktiv setzen?';
	else if (newstatus == 1) var question = 'Möchten Sie dieses Praktikum wirklich aktiv setzen?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetPraktikumStatus.php?pracid=" + pracid + "&userid=" + userid + "&status=" + newstatus + "&searchstring=" + searchstring, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				frontendReloadPraktikaList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// reload praktika list
function frontendReloadPraktikumSearchResults(page) {
	loading(true);

	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadPraktikumSearchResults.php?page=" + page, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle praktika search form
function togglePraktikaSearchForm() {
	if (document.getElementById('extendedSearchForm')) {
		if (document.getElementById('extendedSearchForm').style.display == "block") document.getElementById('extendedSearchForm').style.display = "none";
		else document.getElementById('extendedSearchForm').style.display = "block";
	}
}

// reset page session variable
function resetSessionPage() {
	//alert("resetSessionPage");
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/resetPageSession.php", false);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  //alert(xmlhttp.readyState);
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
			//eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// MARKTPLATZ
// ==========

// reload marktplatz list (frontend)
function frontendReloadMarktplatzList(userid,searchstring) {
	loading(true);
	
	var s = '';
	
	if (!searchstring || searchstring == "undefined" || searchstring == '') {
		if (document.getElementById('searchmarktplatz')) {
			s = encodeURI(document.getElementById('searchmarktplatz').value);
		}
	}
	else if (searchstring != '') {
		s = encodeURI(searchstring);
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadMarktplatzList.php?userid=" + userid + "&searchstring=" + s, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// delete marktplatz
function frontendDeleteMarktplatz(id,userid,searchstring,page) {
	loading(true);
	var c = confirm('Möchten Sie diesen Marktplatzeintrag wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteMarktplatz.php?id=" + id + "&searchstring=" + searchstring + "&page=" + page, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				if (page && page > 0) frontendReloadMarktplatzSearchResults(page);
				else frontendReloadMarktplatzList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// set frontend marktplatz status
function frontendSetMarktplatzStatus(markid,searchstring,newstatus,userid) {
	loading(true);
	if (newstatus == 0) var question = 'Möchten Sie diesen Marktplatzeintrag wirklich inaktiv setzen?';
	else if (newstatus == 1) var question = 'Möchten Sie diesen Marktplatzeintrag wirklich aktiv setzen?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetMarktplatzStatus.php?markid=" + markid + "&userid=" + userid + "&status=" + newstatus + "&searchstring=" + searchstring, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				frontendReloadMarktplatzList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// reload marktplatz list
function frontendReloadMarktplatzSearchResults(page) {
	loading(true);

	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadMarktplatzSearchResults.php?page=" + page, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle marktplatz search form
function toggleMarktplatzSearchForm() {
	if (document.getElementById('extendedSearchForm')) {
		if (document.getElementById('extendedSearchForm').style.display == "block") document.getElementById('extendedSearchForm').style.display = "none";
		else document.getElementById('extendedSearchForm').style.display = "block";
	}
}

function toggleMarktplatzKategorie(id) {
	loading(true);
	for (var i=1; i<=4; i++) {
		if (document.getElementById('angebot_kategorienid_' + i)) {
			document.getElementById('angebot_kategorienid_' + i).style.display = 'none';
		}
	}
	if (document.getElementById('angebot_kategorienid_' + id)) {
		document.getElementById('angebot_kategorienid_' + id).style.display = 'block';
	}
	loading();
}

// BERUFE
// ======

// reload berufe list
function frontendReloadBerufeResults(searchstring) {
	loading(true);
	
	var s = '';
	
	if (!searchstring || searchstring == "undefined" || searchstring == '') {
		if (document.getElementById('searchberuf')) {
			s = encodeURI(document.getElementById('searchberuf').value);
		}
	}
	else if (searchstring != '') {
		s = encodeURI(searchstring);
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadBerufeList.php?searchstring=" + s, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle berufe filter
function frontendToggleBerufeFilter(tid) {
	if (document.getElementById('searchberuf')) var searchstring = document.getElementById('searchberuf').value;
	else var searchstring = "";
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendToggleBerufeFilter.php?tid=" + tid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
			frontendReloadBerufeResults(searchstring);
			}
		}
		catch(e) {
			status = '';
			frontendReloadBerufeResults(searchstring);
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle search area
function toggleSearchArea(area) {
	if (area == 2) {
		if (document.getElementById('extendedSearchLink')) document.getElementById('extendedSearchLink').href="index.php?extendedmarktplatzsearch";
		if (document.getElementById('searchPlace')) document.getElementById('searchPlace').name="marktplatzsearch";
		if (document.getElementById('extendedsearchlabel')) document.getElementById('extendedsearchlabel').innerHTML="Marktplatz";
	}
	else if (area == 1) {
		if (document.getElementById('extendedSearchLink')) document.getElementById('extendedSearchLink').href="index.php?extendedpraktikasearch";
		if (document.getElementById('searchPlace')) document.getElementById('searchPlace').name="praktikasearch";
		if (document.getElementById('extendedsearchlabel')) document.getElementById('extendedsearchlabel').innerHTML="Praktikums";
	}
}

// toggle gueltigkeit (praktika and marktplatz)
function toggleGueltigkeit(mode) {
	if (mode == "unbegrenzt") {
		if (document.getElementById('angebot_gueltigab')) document.getElementById('angebot_gueltigab').value = '';
		if (document.getElementById('angebot_gueltigbis')) document.getElementById('angebot_gueltigbis').value = '';
		if (document.getElementById('praktikum_zeitraum_start')) document.getElementById('praktikum_zeitraum_start').value = '';
		if (document.getElementById('praktikum_zeitraum_ende')) document.getElementById('praktikum_zeitraum_ende').value = '';
	} else if (mode == "datum") {
		if (document.getElementById('angebot_gueltigunbegrenzt') && (document.getElementById('angebot_gueltigab').value!="" || document.getElementById('angebot_gueltigbis').value!="")) {
			document.getElementById('angebot_gueltigunbegrenzt').checked = false;
		}
		if (document.getElementById('praktikum_zeitraum_unbegrenzt') && (document.getElementById('praktikum_zeitraum_start').value!="" || document.getElementById('praktikum_zeitraum_ende').value!="")) {
			document.getElementById('praktikum_zeitraum_unbegrenzt').checked = false;
		}
	}
}

function sortList(order,field,jsfunction,target) {
	var xmlhttp = createHttpRequest();
	target = target + "/toggleSort.php?field=" + field + "&order=" + order;
	xmlhttp.open("GET", target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
			//frontendReloadBerufeResults();
			eval(jsfunction);
			}
		}
		catch(e) {
			status = '';
			eval(jsfunction);
		}
	  }
	}
	xmlhttp.send(null);
}

// PROJEKTBOERSE
// =============

// reload projektboerse list (frontend)
function frontendReloadProjektboerseList(userid,searchstring) {
	loading(true);
	
	var s = '';
	
	if (!searchstring || searchstring == "undefined" || searchstring == '') {
		if (document.getElementById('searchprojektboerse')) {
			s = encodeURI(document.getElementById('searchprojektboerse').value);
		}
	}
	else if (searchstring != '') {
		s = encodeURI(searchstring);
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadProjektboerseList.php?userid=" + userid + "&searchstring=" + s, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// delete projektboerse
function frontendDeleteProjekt(id,userid,searchstring,page) {
	loading(true);
	var c = confirm('Möchten Sie diesen Projekteintrag wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteProjekt.php?id=" + id + "&searchstring=" + searchstring + "&page=" + page, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				if (page && page > 0) frontendReloadProjektboerseSearchResults(page);
				else frontendReloadProjektboerseList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// set frontend projektboerse status
function frontendSetProjektboerseStatus(projid,searchstring,newstatus,userid) {
	loading(true);
	if (newstatus == 0) var question = 'Möchten Sie diesen Projekteintrag wirklich inaktiv setzen?';
	else if (newstatus == 1) var question = 'Möchten Sie diesen Projekteintrag wirklich aktiv setzen?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetProjektboerseStatus.php?projid=" + projid + "&userid=" + userid + "&status=" + newstatus + "&searchstring=" + searchstring, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
				frontendReloadProjektboerseList(userid,searchstring);
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// reload projektboerse list
function frontendReloadProjektboerseSearchResults(page) {
	loading(true);

	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadProjektboerseSearchResults.php?page=" + page, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle marktplatz search form
function toggleProjektboerseSearchForm() {
	if (document.getElementById('extendedSearchForm')) {
		if (document.getElementById('extendedSearchForm').style.display == "block") document.getElementById('extendedSearchForm').style.display = "none";
		else document.getElementById('extendedSearchForm').style.display = "block";
	}
}

// populate textbaustein
function projektboerseTextbausein(text) {
	if (text && text!="" && text!="undefined" && document.getElementById('projekt_text')) {
		document.getElementById('projekt_text').value=decodeURI(text);
	}
}

// home page search
function tippsandtricks(state) {
	var d="block";
	if (state) d="none"
	document.getElementById('search_fields').style.display=d;
	document.getElementById('ttButton').style.display=(d=="block")?"none":"block";
	document.getElementById('praktikaSearchBox').style.paddingBottom=(d=="block")?"5px":"14px";
}

function checkTippsandtricks() {
	var obj=document.getElementById('tipsRadio');
	if (!obj) return true;
	if (obj.checked) {
		window.location.href=ROOT_URL+"Fuer-Schueler/Tipps---Tricks/";
		return false;
	} else {
		return true;
	}
}

function centerSearch() {;
	var obj=document.getElementById('contentTable');
	if (obj) {
		var content=obj.offsetWidth;		
		var m=parseInt((570-content)/2);
		if (m<5) m=5;
		var i=570-(m*2);
		var mF=document.getElementById('main_frame');
		mF.style.marginLeft=m+'px';
		mF.style.marginRight=m+'px';
		mF.style.width=i+'px';
		document.getElementById('navigator_top').childNodes[0].style.width=content+'px';
		document.getElementById('navigator_bottom').childNodes[0].style.width=content+'px';
	} else {
		setTimeout('centerSearch()',50);
	}
}

var hiddenSelects=new Array;

function hideSelects() {
	var popup=document.getElementById("popup");
	if (!popup) return;
	var sels=document.getElementsByTagName("select");
	for (var i=0; i<sels.length; i++) {
		sels[i].style.display="none";
		hiddenSelects.push(sels[i]);
	}
}

function hidePopup() {
	var popup=document.getElementById("popup");
	if (!popup) return;
	popup.style.display="none";
	for (var i=0; i<hiddenSelects.length; i++) {
		hiddenSelects[i].style.display="inline";
	}
	hiddenSelects.length=0;
}

var fenster;

function openWindow(modus,itemtype,iid,module) {
	if (iid==-1) iid = 0;
	
	// 'edit' window
	
	var pre=ROOT_URL+"admin/";
	
	if (modus=='edit') {
		if (itemtype == "art" || itemtype == "far") { 
			url = pre+"pages/editarticle_multilang.php?itemtype=" + itemtype + "&itemid=" + iid;
			if (module!='') url += "&module=" + module;
			width = 750;
			height = 500;
			newArticleWindow(url,iid,width,height);
		}
		else if (itemtype == "fol" || itemtype == "ffo") {
			url = pre+"pages/editfolder.php?itemtype=" + itemtype + "&itemid=" + iid;
			width = 300;
			height = 150;
			newWindow(url,'popup' + iid,width,height);
		}
		else if (itemtype == "mpa") {
			url = pre+"pages/editmenuarticle.php?itemtype=" + itemtype + "&itemid=" + iid;
			width = 360;
			height = 350;
			newWindow(url,'popup' + iid,width,height);
		}
	}
	
}

function newArticleWindow(url,name,width,height) {
	if (typeof(fenster)=="undefined") fenster=new Array;
	fenster[name] = window.open (
	url,
	name, 					// name
	"toolbar=0" 			// tool bar 
	+",dependent=1"			// dependent
	+",location=0" 			// address bar
	+",directories=0" 		// additional bars
	+",status=1" 			// status bar
	+",menubar=0" 			// menu bar
	+",scrollbars=0" 		// scroll bars
	+",resizable=1" 		// window resizable
	+",width=" + width 		// window width in pixels
	+",height=" + height 	// window height in pixels
	);
}

function changeSearch(s) {
	var map=document.getElementById("mapSearchDiv");
	var normal=document.getElementById("praktikaSearchBox");
	if (!map || !normal) return;
	document.cookie="homeSearchTab="+s+";";
	if (s=="map") {
		document.getElementById("map_search").value="1";
		document.getElementById("normalSearchTab").className="searchTabNotSelected";
		document.getElementById("mapSearchTab").className="searchTabSelected";
		document.getElementById("extendedSearchTab").style.display="none";
		normal.style.display="none";
		map.style.position="static";
		map.style.visibility="visible";
	} else {
		document.getElementById("map_search").value="0";
		document.getElementById("normalSearchTab").className="searchTabSelected";
		document.getElementById("mapSearchTab").className="searchTabNotSelected";
		document.getElementById("extendedSearchTab").style.display="block";
		map.style.visibility="hidden";
		map.style.top="-30000px";
		map.style.left="-30000px";
		map.style.position="absolute";
		normal.style.display="block";
	}
}

// jquery tabs
var tabsAPI;
var tabsInterval=-1;
var tabsInitiated=false;
var changeTabsTime=0;
var tabColor="2";
var tabsretry=10;
var tabMenuCol="#333";
var tabMenuSelected="#000";
var tabBorder="#000000";
var tabPadding="10px";

function initTabs() {
	try {
		$("ul.tabs").tabs("div.panes > div", {
				//	effect: 'fade',
					rotate: true	
				}
			);
		tabsAPI=$("ul.tabs").data("tabs");
		$("ul.tabs").each( function(index) {
				this.style.borderColor=tabBorder;
			});
		$("div.panes > div").each( function(index) {
				this.style.borderColor=tabBorder;
				this.style.padding=tabPadding;
			});
		tabsInitiated=true;
		return true;
	} catch(e) {
		tabsInitiated=false;
		return false;
	}
}


function startTabs() {
	try {
		$(document).ready(function() {
			$("ul.tabs a").each(function() {
				$(this).css("background-image","url("+ROOT_URL+"templates/new/images/tabs"+tabColor+".png)");
				$(this).css("color",tabMenuCol);
			});
			if (initTabs() && changeTabsTime>0) {
				tabsInterval=setInterval("changeTab()",changeTabsTime*1000+500);
			}
		});
	} catch(e) {
		tabsretry--;
		if (tabsretry>0) setTimeout("startTabs()",500);
	}
}

function changeTab() {
	if (!tabsInitiated) return;
	tabsAPI.next();
}

startTabs();


//HS-WBW

function allWBW(state) {
	var ins=getElementsByClass('selectionWBW');
	for (var i=0; i<ins.length; i++) {
		ins[i].checked=state;
	}
}

function getSelectedWbw() {
	var ins=getElementsByClass('selectionWBW');
	var tmp='0';
	for (var i=0; i<ins.length; i++) {
		if (ins[i].checked) {
			var tmpid=ins[i].id.split("_");
			tmp+=","+tmpid[1];
		}
	}
	return tmp;
}

function frontendSetWbwStatus(id,newstatus,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	if (newstatus == 0) var question = 'Dieser Beitrag ist aktiv. Möchten Sie ihn inaktiv setzen?';
	else if (newstatus == 1) var question = 'Dieser Beitrag ist inaktiv. Möchten Sie ihn aktivieren und damit zur Veröffentlichung nach dem Wettbewerb freischalten?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetWbwStatus.php?id=" + id + "&userid=" + userid + "&status=" + newstatus, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function frontendDeleteWbw(id,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var c = confirm('Möchten Sie dieses Wettbewerben wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteWbw.php?id=" + id + "&userid=" + userid, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function reloadWbwList() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadWbw.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

function openWbwPage(page) {
	var h=window.location.href;
	if (h.indexOf('/projektboerse/')!=-1) {
		h=h.split('/projektboerse/');
		h=h[0]+"/P-Seminar/";
	}
	if (h.indexOf('#')!=-1) {
		h=h.split('#');
		h=h[0];
	}
	h=h.split("?");
	h=h[0];
	if (h.indexOf("stark-fuer-den-beruf")!=-1) h="/stark-fuer-den-beruf/";
	if (!page) {
		window.location.href=h;
		return;
	}
	window.location.href=h+"?"+page;
}

function pdfUpdateProgress(e,queueID,fileObj,data) {
	if (document.getElementById('wbw_pdf').value!='' && document.getElementById('wbw_pdf').value!=fileObj.name) document.getElementById('wbwIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWbwFiles.php?pdf='+document.getElementById('wbw_pdf').value;
	var w=parseInt(152*data.percentage/100);
	document.getElementById('pdfUploadProgress').style.width=w+'px';
	document.getElementById('pdfUploadedImage').style.visibility='hidden';
	document.getElementById('pdfUploadDiv').title='';
	document.getElementById('pdfUploadUploader').title='';
	document.getElementById('wbw_pdf').value='';
	//if (data.percentage==100) pdfUploadComplete(e,queueID,fileObj);
	return false;
}

function bildUpdateProgress(e,queueID,fileObj,data) {
	if (document.getElementById('wbw_bild').value!='' && document.getElementById('wbw_bild').value!=fileObj.name) document.getElementById('wbwIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWbwFiles.php?bild='+document.getElementById('wbw_bild').value;
	var w=parseInt(152*data.percentage/100);
	document.getElementById('bildUploadProgress').style.width=w+'px';
	document.getElementById('bildUploadedImage').style.visibility='hidden';
	document.getElementById('bildUploadDiv').title='';
	document.getElementById('bildUploadUploader').title='';
	document.getElementById('wbw_bild').value='';
	//if (data.percentage==100) bildUploadComplete(e,queueID,fileObj);
	return false;
}

var maxfilesize="";

function showError(event,queueID,fileObj,errorObj) {
	var m=errorObj.type+': '+errorObj.info;
	if (errorObj.type=="File Size") {
		m="Dateien dürfen maximal "+maxfilesize+"gross sein.";
	}
	alert(m);
}

function pdfUploadComplete(e,queueID,fileObj,response,data) {
	document.getElementById('pdfUploadProgress').style.width='152px';
	document.getElementById('pdfUploadedImage').style.visibility='visible';
	document.getElementById('pdfUploadDiv').title=fileObj.name;
	document.getElementById('pdfUploadUploader').title=fileObj.name;
	document.getElementById('wbw_pdf').value=fileObj.name;
	uploadedFile=true;
	return true;
}

function pdfUploadExists() {
	var val=document.getElementById('wbw_pdf').value;
	if (val!='') {
		document.getElementById('pdfUploadProgress').style.width='152px';
		document.getElementById('pdfUploadedImage').style.visibility='visible';
	} else {
		document.getElementById('pdfUploadProgress').style.width='0px';
		document.getElementById('pdfUploadedImage').style.visibility='hidden';
	}
	document.getElementById('pdfUploadDiv').title=val;
	document.getElementById('pdfUploadUploader').title=val;
}

function bildUploadExists() {
	var val=document.getElementById('wbw_bild').value;
	if (val!='') {
		document.getElementById('bildUploadProgress').style.width='152px';
		document.getElementById('bildUploadedImage').style.visibility='visible';
	} else {
		document.getElementById('bildUploadProgress').style.width='0px';
		document.getElementById('bildUploadedImage').style.visibility='hidden';
	}
	document.getElementById('bildUploadDiv').title=val;
	document.getElementById('bildUploadUploader').title=val;
}

function bildUploadComplete(e,queueID,fileObj,response,data) {
	document.getElementById('bildUploadProgress').style.width='152px';
	document.getElementById('bildUploadedImage').style.visibility='visible';
	document.getElementById('bildUploadDiv').title=fileObj.name;
	document.getElementById('bildUploadUploader').title=fileObj.name;
	if (response.indexOf('Invalid')==-1) document.getElementById('wbw_bild').value=response;
	uploadedFile=true;
	return true;
}

function pdfFileExists() {
}

function bildFileExists() {
}

var uploadedFile=false;

function removeFiles() {
	if (remove && uploadedFile) {
		document.getElementById('wbwIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWbwFiles.php';
		alert('Die hochgeladenen Dateien werden entfernt');
	}
}

//W-SEMINAR Upload f-ons
function frontendSetWsmStatus(id,newstatus,userid) {
	var tmpQ = id;

	if (id==0) {
		id=getSelectedWbw();
		if(id == 0) return;
		var tmpQ = (id.split(',').length > 2 ?  "plural" : 0);
	}
	
	loading(true);
	if (newstatus == 0) {
		if(tmpQ == "plural") {
			var question = 'Möchten Sie diese Wettbewerbe inaktiv setzen?';
		}
		else {
			var question = 'Möchten Sie diesen Wettbewerb inaktiv setzen?';
		}
	}
	else if (newstatus == 1) {
		if(tmpQ == "plural") {
			var question = 'Möchten Sie diese Wettbewerbe aktiv setzen und diese damit zur Veröffentlichung freigeben?';
		}
		else {
			var question = 'Möchten Sie diesen Wettbewerb aktiv setzen und ihn damit zur Veröffentlichung freigeben?';
		}
	}
	
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "http://www.sprungbrett-bayern.de/admin/modules/sprungbrett/ajax/frontendSetWsmStatus.php?id=" + id + "&userid=" + userid + "&status=" + newstatus, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function frontendDeleteWsm(id,userid) {
	var text = 'Möchten Sie diesen Wettbewerb wirklich löschen?';
	if (id==0) { 
		id=getSelectedWbw();
		var tmp = id.split(",");
		if(tmp.length > 2) {
			var text = 'Möchten Sie diese Wettbewerbe wirklich löschen?';
		}
	}
	var c = confirm(text);
	loading(true);
	
	
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteWsm.php?id=" + id + "&userid=" + userid, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function reloadWsmList() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadWsm.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

function wsmPdfUpdateProgress(e,queueID,fileObj,data) {
	if (document.getElementById('wsm_pdf').value!='' && document.getElementById('wsm_pdf').value!=fileObj.name) document.getElementById('wsmIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWsmFiles.php?pdf='+document.getElementById('wsm_pdf').value;
	var w=parseInt(152*data.percentage/100);
	document.getElementById('pdfUploadProgress').style.width=w+'px';
	document.getElementById('pdfUploadedImage').style.visibility='hidden';
	document.getElementById('pdfUploadDiv').title='';
	document.getElementById('pdfUploadUploader').title='';
	document.getElementById('wsm_pdf').value='';
	//if (data.percentage==100) pdfUploadComplete(e,queueID,fileObj);
	return false;
}

function wsmBildUpdateProgress(e,queueID,fileObj,data) {
	if (document.getElementById('wsm_bild').value!='' && document.getElementById('wsm_bild').value!=fileObj.name) document.getElementById('wsmIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWsmFiles.php?bild='+document.getElementById('wsm_bild').value;
	var w=parseInt(152*data.percentage/100);
	document.getElementById('bildUploadProgress').style.width=w+'px';
	document.getElementById('bildUploadedImage').style.visibility='hidden';
	document.getElementById('bildUploadDiv').title='';
	document.getElementById('bildUploadUploader').title='';
	document.getElementById('wsm_bild').value='';
	//if (data.percentage==100) bildUploadComplete(e,queueID,fileObj);
	return false;
}

function wsmPdfUploadComplete(e,queueID,fileObj,response,data) {
	document.getElementById('pdfUploadProgress').style.width='152px';
	document.getElementById('pdfUploadedImage').style.visibility='visible';
	document.getElementById('pdfUploadDiv').title=fileObj.name;
	document.getElementById('pdfUploadUploader').title=fileObj.name;
	document.getElementById('wsm_pdf').value=fileObj.name;
	setTimeout("wsmPlaceRemoveOptionPdf()",2000);
	return true;
}

function wsmPdfUploadExists(del) {
	if(del) {
		document.getElementById('wsm_pdf').value='0';
		document.getElementById('pdfUploadProgress').style.display='none';
		document.getElementById('pdfUploadedImage').style.visibility='hidden';
		document.getElementById('pdfUploadedImageDelete').style.visibility='hidden';
		document.getElementById('pdfUploadDiv').title="";
		document.getElementById('pdfUploadUploader').title="";
		return;
	}
	var val=document.getElementById('wsm_pdf').value;
	if (val!='') {
		document.getElementById('pdfUploadProgress').style.width='152px';
		document.getElementById('pdfUploadedImage').style.visibility='visible';
		document.getElementById('pdfUploadDiv').title=val;
		document.getElementById('pdfUploadUploader').title=val;
		setTimeout("wsmPlaceRemoveOptionPdf()",2000);
	}
}

function wsmBildUploadExists(del) {
	if(del) {
		//wsm_bild
		document.getElementById('wsm_bild').value= "0";
		document.getElementById('bildUploadProgress').style.display='none';
		document.getElementById('bildUploadedImage').style.visibility='hidden';
		document.getElementById('bildUploadedImageDelete').style.visibility='hidden';
		document.getElementById('bildUploadDiv').title="";
		document.getElementById('bildUploadUploader').title="";
		return;
	}
	var val=document.getElementById('wsm_bild').value;
	if (val!='') {
		document.getElementById('bildUploadProgress').style.width='152px';
		document.getElementById('bildUploadedImage').style.visibility='visible';
		document.getElementById('bildUploadDiv').title=val;
		document.getElementById('bildUploadUploader').title=val;
		setTimeout("wsmPlaceRemoveOption()",2000);
	}
}


function wsmBildUploadComplete(e,queueID,fileObj,response,data) {
	document.getElementById('bildUploadProgress').style.width='152px';
	document.getElementById('bildUploadedImage').style.visibility='visible';
	document.getElementById('bildUploadDiv').title=fileObj.name;
	document.getElementById('bildUploadUploader').title=fileObj.name;
	setTimeout("wsmPlaceRemoveOption()",2000);
	if (response.indexOf('Invalid')==-1) document.getElementById('wsm_bild').value=response;
	
	return true;
}

function wsmPlaceRemoveOption() {
	document.getElementById('bildUploadedImage').style.visibility='hidden';
	document.getElementById('bildUploadedImageDelete').style.visibility='visible';
	
}

function wsmPlaceRemoveOptionPdf() {
	document.getElementById('pdfUploadedImage').style.visibility='hidden';
	document.getElementById('pdfUploadedImageDelete').style.visibility='visible';
}



function wsmRemoveFiles() {
	if (remove) document.getElementById('wsmIframe').src=ROOT_URL+'admin/modules/sprungbrett/ajax/deleteWsmFiles.php';
}

//*****

function isFilled(obj) {
	if (obj.type=="checkbox") return obj.checked;
	if (obj.value.replace(/^\s+|\s+$/g, '')!="") return true;
	return false;
}

function isFilledSelect(obj) {
	for (var i = 0; i < obj.options.length; i++){
	 if (obj.options[i].selected==true){
	     return true;
	     break;
	 }
	}
	return false;
}

function in_array(find,ar) {
	var ret=false;
	for (var i=0; i<ar.length; i++) {
		if (ar[i]==find) {
			ret=true;
			break;
		}
	}
	return ret;
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value=limitField.value.substring(0, limitNum);
	}
}

function openWbwInfo(id) {
	document.getElementById(id).style.display="block";
	if (document.getElementById("pdfUploadUploader")) document.getElementById("pdfUploadUploader").style.visibility="hidden";
	if (document.getElementById("bildUploadUploader")) document.getElementById("bildUploadUploader").style.visibility="hidden"
}

function equalHeights(id1,id2) {
	var obj1=document.getElementById(id1);
	var obj2=document.getElementById(id2);
	if (!obj1 || !obj2 || !obj1.offsetHeight || !obj2.offsetHeight) {
		setTimeout("equalHeights('"+id1+"','"+id1+"')",50);
		return;
	}
	var h1=obj1.offsetHeight;
	var h2=obj2.offsetHeight;
	var h=0;
	if (h1>h2) {
		h=h1;
	} else {
		h=h2;
	}
	obj1.style.height=h+'px';
	obj2.style.height=h+'px';
}

/*function saveNotizenAct() {
	var t= (new Date).getTime();
	var notiz = document.getElementById('mainNotiz').value;
	if(!notiz) return;
	notiz = encodeURIComponent(notiz);
	var sel = document.getElementById('trget_groups');
	var targetGroup = sel.options[sel.selectedIndex].value;
	
	var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "http://sprungbrett-bayern.de/admin/modules/sprungbrett/ajax/saveNotizen.php?notizen=" + notiz + "&group=" + targetGroup + "&t=" + t, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
				  var x = document.getElementById('wall');
				  x.innerHTML = xmlhttp.responseText;
				  //loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
}
*/
function setInSchoolYearOnly(el) {
	
	
	if(el.checked == true) { var chbox = "yes" }
	else {var chbox = "no" };
	
	location.href = 'http://www.sprungbrett-bayern.de/w-seminar?search&actuel=yes&chbox=' + chbox;
	//var xmlhttp = createHttpRequest();
	
	//var xmlhttp = createHttpRequest();
		//xmlhttp.open("GET", "http://www.sprungbrett-bayern.de/admin/modules/sprungbrett/ajax/refineWSeminarSearch.php?actuel=yes&chbox=" + chbox, true);
		
	
}

// Technik-Projekte
function frontendSetTPStatus(id,newstatus,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var m1='Dieses Projekt ist aktiv. Möchten Sie es inaktiv setzen?';
	var m2='Dieses Projekt ist inaktiv. Möchten Sie es aktivieren und damit zur Veröffentlichung freischalten?';
	if (id.indexOf(",")!=-1) {
		var tmp=id.split(",");
		var tmp2=0;
		for (var i=0; i<tmp.length; i++) {
			if (tmp[i]!="" && tmp[i]!="0") tmp2++;
		}
		if (tmp2>1) {
			m1='Diese Projekte sind aktiv. Möchten Sie sie inaktiv setzen?';
			m2='Diese Projekte sind inaktiv. Möchten Sie sie aktivieren und damit zur Veröffentlichung freischalten?';
		}
	}
	if (newstatus == 0) var question = m1;
	else if (newstatus == 1) var question = m2;
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetTPStatus.php?id=" + id + "&userid=" + userid + "&status=" + newstatus, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function frontendDeleteTP(id,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var pl="s";
	var pl2="ist";
	if (id.indexOf(",")!=-1) {
		var tmp=id.split(",");
		var tmp2=0;
		for (var i=0; i<tmp.length; i++) {
			if (tmp[i]!="" && tmp[i]!="0") tmp2++;
		}
		if (tmp2>1) {
			pl=""
			pl2="sind";
		}
	}
	var c = confirm('Möchten Sie diese'+pl+' Projekte wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteTP.php?id=" + id + "&userid=" + userid, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function reloadTPList() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadTP.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

//P-Seminar
function frontendSetPSStatus(id,newstatus,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var m1='Dieses Projekt ist aktiv. Möchten Sie es inaktiv setzen?';
	var m2='Dieses Projekt ist inaktiv. Möchten Sie es aktivieren und damit zur Veröffentlichung freischalten?';
	if (id.indexOf(",")!=-1) {
		var tmp=id.split(",");
		var tmp2=0;
		for (var i=0; i<tmp.length; i++) {
			if (tmp[i]!="" && tmp[i]!="0") tmp2++;
		}
		if (tmp2>1) {
			m1='Diese Projekte sind aktiv. Möchten Sie sie inaktiv setzen?';
			m2='Diese Projekte sind inaktiv. Möchten Sie sie aktivieren und damit zur Veröffentlichung freischalten?';
		}
	}
	if (newstatus == 0) var question = m1;
	else if (newstatus == 1) var question = m2;
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetPSStatus.php?id=" + id + "&userid=" + userid + "&status=" + newstatus, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function frontendDeletePS(id,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var pl="s";
	var pl2="ist";
	if (id.indexOf(",")!=-1) {
		var tmp=id.split(",");
		var tmp2=0;
		for (var i=0; i<tmp.length; i++) {
			if (tmp[i]!="" && tmp[i]!="0") tmp2++;
		}
		if (tmp2>1) {
			pl=""
			pl2="sind";
		}
	}
	var c = confirm('Möchten Sie diese'+pl+' Projekte wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeletePS.php?id=" + id + "&userid=" + userid, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function reloadPSList() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadPS.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

var currentSortBy="";
var currentSortOrd="";

function paginate(page) {
	var xmlhttp = createHttpRequest();
	var s="";
	if (currentSortBy!="" && currentSortOrd!="") s="&sortby="+currentSortBy+"&sortorder="+currentSortOrd;
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/paginate.php?page="+page+s+"&t="+Math.random(), true);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				paginateSortable(currentSortBy,currentSortOrd);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

function paginateSortable(d,s) {
	if (typeof(d)=="undefined") d="";
	if (typeof(s)=="undefined") s="ASC";
	var obj=document.getElementById("wbwList");
	if (!obj) return;
	var children = obj.getElementsByTagName('table');
	if (children.length==0) return;
	var table=children[0];
	children=table.getElementsByTagName('th');
	if (children.length==0) return;
	for (var i=0; i<children.length; i++) {
		if (!children[i].id) continue;
		children[i].onclick=paginateSort;
		children[i].style.cursor="pointer";
		if (d!="" && children[i].id==d) sorted(children[i],d,s); 
	}
}

function sorted(obj,d,s) {
	if (typeof(s)=="undefined") s="ASC";
	s=s.toLowerCase();
	obj.className+=" "+s;
	currentSortBy=d;
	currentSortOrd=s;
}

function paginateSort() {
	if (!this.id) return;
	var s="ASC";
	var id=this.id;
	if (this.className.indexOf("asc")!=-1) s="DESC";
	if (this.className.indexOf("desc")!=-1) s="ASC";
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/paginate.php?sortby="+id+"&sortorder="+s+"&t="+Math.random(), true);
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				paginateSortable(id,s);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

function removePDF(mod,id) {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteUFile.php?file=pdf&mod="+mod+"&id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function removeBild(mod,id) {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeleteUFile.php?file=bild&mod="+mod+"&id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

var firstWarning=false;
var sesschkInterval=-1;
var fwarningminutes=6;
var fwarningtime=fwarningminutes*60;

function currtime() {
	var n=new Date;
	return n.getTime()/1000;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function checkSession() {
	sessionLeft=sessionTime-(currtime()-sessionStart);
	var mins=parseInt(sessionLeft/60);
	if (!firstWarning && sessionLeft<=fwarningtime) {
		firstWarning=true;
		alert("Sie werden in "+mins+" Minuten automatisch ausgeloggt. Bitte speichern Sie alle noch offenen Arbeiten ab und loggen Sie sich erneut ein.");
		/*var n=currtime();
		if (confirm('Achtung! Sie werden in '+mins+' Minuten automatisch ausgeloggt, bitte schliessen Sie alle offenen Vorgänge ab OR CLICK OK TO ENTER LOGIN DATA AGAIN WITHOUT CLOSING YOUR WORK')) {
			document.getElementById('lbox_shadow').style.height=getDocHeight()+"px";
			document.getElementById('lbox_shadow').style.display="block";
			document.getElementById('relogin').style.display="block";
		}*/
		return checkSession();
	}
	if (sessionLeft<=0) {
		var d=new Date;
		firstWarning=false;
		clearInterval(sesschkInterval);
		//alert('Sie sind um '+parseInt(sessionTime/60)+' Minuten automatisch ausgeloggt worden. Bitte loggen Sie sich erneut in sprungbrett ein.');
		alert("Sie wurden nun automatisch ausgeloggt. Bitte loggen Sie sich erneut ein.");
		var h=window.location.href;
		window.location.href=h;
	}
}

function closeRelogin() {
	document.getElementById('lbox_shadow').style.display="none";
	document.getElementById('relogin').style.display="none";
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function jsRestartSession() {
	sessionLeft=sessionTime-(currtime()-sessionStart);
	if (sesschkInterval>-1) clearInterval(sesschkInterval);
	if (readCookie(cookieName)) return;
	if (sessionLeft<=0) return; 
	if (sessionLeft<(fwarningtime-61)) {
		firstWarning=true;
	} else {
		firstWarning=false;
	}
	sesschkInterval=setInterval('checkSession()',60000);
}

//new praktika
function frontendSetPrakStatus(id,newstatus,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	if (newstatus == 0) var question = 'Dieses Praktikum ist aktiv. Möchten Sie es inaktiv setzen?';
	else if (newstatus == 1) var question = 'Dieses Praktikum ist inaktiv. Möchten Sie es aktivieren?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendSetPrakStatus.php?id=" + id + "&userid=" + userid + "&status=" + newstatus, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function frontendDeletePrak(id,userid) {
	if (id==0) id=getSelectedWbw();
	loading(true);
	var c = confirm('Möchten Sie dieses Praktikum wirklich löschen?');
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendDeletePrak.php?id=" + id + "&userid=" + userid, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}	
}

function reloadPrakList() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "admin/modules/sprungbrett/ajax/frontendReloadPrak.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				document.getElementById('wbwList').innerHTML=xmlhttp.responseText;
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);	
}

function openOnlineApply(praktikaId) {
	var div = document.createElement('div');
	div.id = 'apply_form_div';
	div.style.position = 'absolute';
	div.style.display = 'none';
	div.zIndex = '5555';
	div.style.backgroundColor = 'white';
	div.style.overflow = 'hidden';
	div.style.width = '440px';
	//div.style.height = '530px';
	div.style.minHeight = '550px';
	div.style.border = '6px solid #c2c2c4';
	div.style.marginTop = '10px';
	div.style.marginLeft = '10px';
	div.style.paddingBottom = '15px';
	var containerDiv = document.getElementById('mainbody');
	//containerDiv.appendChild(div);
	$(containerDiv).prepend(div);
	div.style.display = 'block';
	div.innerHTML = '<p style="font-size:13px; margin-top:20px; margin-left:20px;">Formular wird geladen...</p>';
	$(div).data('praktika_id',praktikaId);
	
	ajaxCallAsync(ROOT_URL + "admin/modules/sprungbrett/ajax/frontendGetPraktikaApplyForm.php",{'praktikaId' : praktikaId},function(data) {
		    if(data == -1)  {
		    	closeApplyForm();
		    	return;
		    }
			$(div).html(data);
	});
	
}

function closeApplyForm() {
	var containerDiv = document.getElementById('mainbody');
	var applyFormDiv = document.getElementById('apply_form_div');
	containerDiv.removeChild(applyFormDiv);
}

function apply_form_uploadify_OnProgress() {
	
}

function apply_form_uploadify_FileExists() {
	
}

function apply_form_uploadify_showError() {
	
}

function apply_form_uploadify_UploadComplete(event,queueID,fileObj,response,data) {

	var div = $('div[id$="'+queueID+'"]').closest('div[id^="uploadifyQueye"]');
	$(div).css('background-color','#ffdd00');
	//alert(div);
	//alert(response);
	var ret = jQuery.parseJSON(response);
	$(div).data('pdf_obj',ret.name);
	//alert(ret.name);
	var divId = $(div).attr('id');
	var msgId = $(div).attr('id') + "_msg";
	$("#" + msgId).html('<div style="position:relative; margin-top:6px; margin-bottom:-6px;"><img  src="'+ ROOT_URL+'templates/new/images/apply_praktika_checked.png" />&nbsp;&nbsp;<img style="cursor:pointer;" src="'+ ROOT_URL+'templates/new/images/apply_praktika_remove.png" onclick="applyFormRemoveFile(\''+divId+'\')" /></div>');
	//return true;
}

function apply_form_uploadify_OnSelect(event, ID, fileObj) {
	var byteSize = Math.round(fileObj.size / 1024 * 100) * .01;
	if(byteSize > 2000) {
		//this.uploadifyClearQueue();
		if(event.data.queueID == 'uploadifyQueye1') {
			$('#anschreibenUpload').uploadifyClearQueue();
		}
		else if(event.data.queueID == 'uploadifyQueye2') {
			$('#lebenslaufUpload').uploadifyClearQueue();
		}
		else if(event.data.queueID == 'uploadifyQueye3') {
			$('#zeugnisseUpload').uploadifyClearQueue();
		}
		
		showSizeError();
		return false;
		
	}
	
	$("#" + event.data.queueID + "_msg").html('<div style="position:relative; margin-top:3px; margin-bottom:-3px;">...bitte warten</div>');
	$("#" + event.data.queueID).css('background-color','#e6c401');
}

function showSizeError() {
	var heightOfCont = $("#apply_form_div").height();
	var div = document.createElement('div');
	div.id = 'size_error';
	div.style.position = 'absolute';
	div.style.display = 'none';
	div.zIndex = '5777';
	div.style.backgroundColor = 'white';
	div.style.overflow = 'hidden';
	div.style.width = '230px';
	div.style.height = '17px';
	div.style.padding = '5px';
	div.style.border = '2px solid #c2c2c4';
	
	//div.style.marginTop = '340px';
	div.style.marginTop = (heightOfCont - 210) + "px";
	div.style.marginLeft = '120px';
	var containerDiv = document.getElementById('apply_form_div');
	$(containerDiv).prepend(div);
	div.style.display = 'block';
	div.innerHTML = 'Ihr PDF-Dokument ist größer als 2MB.';
	
	setTimeout(function() {$('#size_error').remove()},5000)
	
}

function applyFormRemoveFile(queId) {
	$("#" + queId).css('background-color','#e6c401');
	$("#" + queId).data('pdf_obj','');
	$("#" + queId + "_msg").html('&nbsp;');
}

function sendApplyForm() {
	
	var query  = {}, val, emptyFields = [];
	var fields = new Array('apply_email','apply_vorname','apply_nachname');
	for(var i in fields) {
		$("#" + fields[i] + "_caption").css('color','black');
		val = $("#" + fields[i]).val();
		val = $.trim(val);
		query[fields[i]] = val;
		if(!val) {
			emptyFields.push(fields[i]);
		}
	}
	
	if(emptyFields.length > 0) {
		for(var i in emptyFields) {
			$('#' + emptyFields[i] + "_caption").css('color','red');
		}
		//alert('Please enter all fields');
		return;
	}
	
	query['apply_mitteilung'] = $('#apply_mitteilung').val();
	
	query['praktikaId'] = $('#apply_form_div').data('praktika_id');

	query['file1'] = '';
	query['file2'] = '';
	query['file3'] = '';
	//var files = [];
	if($('#uploadifyQueye1').data('pdf_obj')) {
		query['file1'] = $('#uploadifyQueye1').data('pdf_obj');
	}
	if($('#uploadifyQueye2').data('pdf_obj')) {
		query['file2'] = $('#uploadifyQueye2').data('pdf_obj');
	}
	if($('#uploadifyQueye3').data('pdf_obj')) {
		query['file3'] = $('#uploadifyQueye3').data('pdf_obj');
	}
	
	ajaxCallAsync(ROOT_URL + "admin/modules/sprungbrett/ajax/frontendSendPraktikaApplyForm.php",query,function(data) {
			try {
				var ret = jQuery.parseJSON(data);
				if(ret.error) {
					if(ret.error == 'email_format') {
						$('#apply_email_caption').css('color','red');
						return;
					}
				}
			}
			catch(e) {}
			showSuccInfo();
	});
	
}

function showSuccInfo() {
	//var div = document.createElement('div');
	 if (document.images) {
	     var img = new Image();
		 img.src = "http://sprungbrett-bayern.de/templates/new/images/bbw-logo-360.png";
	 }
	$('#apply_form_div').css('min-height','300px'); 
	$('#apply_form_div').css('height','300px');
	$('#apply_form_div').html('<div style="margin-top:10px; width:100%; text-align:center"><center><img width="360" height="123" src="http://sprungbrett-bayern.de/templates/new/images/bbw-logo-360.png" /></center><br/><span style="font-weight:bold; font-size:14px;">Deine Bewerbung ist unterwegs.</span><br/><br/>Schön, dass Du <i>sprungbrett</i> Bayern dafür genutzt hast.<br/><br/>Wenn Du magst, erzähl Deinen Freunden/innen davon.<br/><br/><a href="javascript:closeApplyForm()" style="color:black; text-decoration:underline;">Fenster schließen<a></div>');
	
}

function ajaxCallAsync(scriptURI,query, callback,timeout) {
	var t = (new Date()).getTime();
	query['t'] = t;
	
	if(typeof timeout == "undefined")
		timeout = 360000;
	
	this.url = scriptURI;
	var _this = this;
	ajaxAlv = $.ajax({
		    type: "post",
		    data: query,
		    cache : false,
		    timeout : timeout,
			url: _this.url+'?t=' + t,
			success: function(data) {
				if(typeof callback == 'function')
					callback(data);
		    }
	});
}

