var http = null;

function evalScripts(scripts)
{	try
	{	if(scripts != '')	
		{	var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
	       	                         if (scripts !== null) script += arguments[1] + '\n';
 	        	                        return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
			}
		return false;
	}
	catch(e)
	{	
		alert(e)
	}
	return false;
}

function catalog(rubrick) {
	request3();
	
	var poststr = 'spalte='+rubrick;
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/suche_katalog_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function detail() {
	request3();
	
	var poststr = 'spalte='+document.getElementById('spalte').value;
	//var a = ['qualifikation', 'praktikumsart', 'studienrichtung', 'branche', 'berufsfeld', 'beschaeftigung', 'position', 'zeitraum', 'dauer', 'land', 'bundesland', 'grossraum'];
	//for(var i = 0; i < a.length; i++) if(document.getElementById("'"+a[i]+"'").value != '') poststr += document.getElementById("'"+a[i]+"'").value;//poststr += '&'+a[i];
	if(document.getElementById('qualifikation').value != '') poststr += '&qualifikation='+document.getElementById('qualifikation').value;
	if(document.getElementById('praktikumsart').value != '') poststr += '&praktikumsart='+document.getElementById('praktikumsart').value;
	if(document.getElementById('studienrichtung').value != '') poststr += '&studienrichtung='+document.getElementById('studienrichtung').value;
	if(document.getElementById('branche').value != '') poststr += '&branche='+document.getElementById('branche').value;
	if(document.getElementById('berufsfeld').value != '') poststr += '&berufsfeld='+document.getElementById('berufsfeld').value;
	if(document.getElementById('beschaeftigung').value != '') poststr += '&beschaeftigung='+document.getElementById('beschaeftigung').value;
	if(document.getElementById('position').value != '') poststr += '&position='+document.getElementById('position').value;
	if(document.getElementById('zeitraum').value != '') poststr += '&zeitraum='+document.getElementById('zeitraum').value;
	if(document.getElementById('dauer').value != '') poststr += '&dauer='+document.getElementById('dauer').value;
	if(document.getElementById('land').value != '') poststr += '&land='+document.getElementById('land').value;
	if(document.getElementById('bundesland').value != '' && document.getElementById('bundesland').value != '%') poststr += '&bundesland='+document.getElementById('bundesland').value;
	if(document.getElementById('grossraum').value != '' && document.getElementById('grossraum').value != '%') poststr += '&grossraum='+document.getElementById('grossraum').value;
	//alert(poststr);
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/suche_detail_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function extended(art) {
	request3();
	//alert(art);
	var poststr = 'suchwahl='+art;
	//alert(poststr);
	
	http.onreadystatechange = update_ext;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/suche_erweitert_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
}

function filter(bereich,searchname) {
	request3();
	if (!http) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	//document.getElementById('category').value = bereich;
	
	var poststr = 'suche='+document.getElementById('suche').value+'&spalte='+bereich+'&sortierung='+document.getElementById('sort').value+'&firmenid='+document.getElementById('firmenid').value;
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/'+searchname+'_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function option(id) {
	request3();
	
	var poststr = 'spalte='+document.getElementById('bereich').value+'&suche='+id;
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/suche_katalog_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function page(i,searchname) {
	request3();
	if (!http) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	
	var poststr = 'suche='+document.getElementById('suche').value+'&spalte='+document.getElementById('bereich').value+'&sortierung='+document.getElementById('sort').value+'&page='+i+'&firmenid='+document.getElementById('firmenid').value;
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/'+searchname+'_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function search(string,searchname) {
	request3();
	var poststr = 'suche=' + string;

	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/'+searchname+'_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
}

function sort(column,searchname) {
	request3();
	if (!http) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	
	var poststr = 'suche='+document.getElementById('suche').value+'&spalte='+document.getElementById('bereich').value+'&sortierung='+column;
	
	http.onreadystatechange = update;
	http.open('POST', window.location.protocol + '//' + window.location.host + '/home/stellen/'+searchname+'_update.phtml', true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	return false;
}

function alertContents() {
	if (http.readyState == 4) {
		if (http.status == 200) {
			//alert(http.responseText);
			
			/*var id = http.responseText;
			
			result = http.responseText;
			
			var data = http.responseText.split('+++#+++');

			var section = data[0] + '_rg_display_section';
			var regular = data[0] + '_rg';
			var edit = data[0] + '_hv';
			var editImage = data[0] + '_editImage';
			var replaceText = document.getElementById(data[0]).value;
	
			document.getElementById(section).innerHTML = replaceText.replace(/\n/g, '<br />') + '<br /><img src="/gifs/bcenter/bearbeiten.gif" alt="bearbeiten" />';
			document.getElementById(regular).style.display = '';
			document.getElementById(edit).style.display = 'none';*/
			/*var data = http.responseText.split('+++#+++');
			document.getElementById('template'+data[0]).style.border = '2px solid #FFFFFF';
			document.getElementById('template'+data[1]).style.border = '2px solid #7FD7F7';
			//alert(data[2]);
			//alert(type);
			document.getElementById('cat').value = data[2];
			document.getElementById('submit').style.display = '';*/
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function request3() {
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http = new XMLHttpRequest();
		if (http.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http.overrideMimeType('text/xml');
			http.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}
	}
	if (!http) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
}

function update() {
	if (http.readyState == 4) {
		if (http.status == 200) {
			document.getElementById('result').innerHTML = http.responseText;
		    //evalScripts( http.responseText );
		} else {
			alert('There was a problem with the request.');
			//alert(http.status);
		}
		return false;
	}
}


function update_ext() {
	if (http.readyState == 4) {
		if (http.status == 200) {
			document.getElementById('result').innerHTML = http.responseText;
		    //evalScripts( http.responseText );
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function show(type) {
	// Art des Praktikums
	document.getElementById('internship').style.display = 'none';
	if(type != '1') document.getElementById('praktikumsart').options[0].selected = true;
	// Studienrichtung
	document.getElementById('study').style.display = 'none';
	if(type != '1' && type != '2') document.getElementById('studienrichtung').options[0].selected = true;
	// Art der Anstellung und Position
	document.getElementById('job').style.display = 'none';
	if(type != '5') {
		document.getElementById('beschaeftigung').options[0].selected = true;
		document.getElementById('position').options[0].selected = true;
	}
	// Datum
	document.getElementById('date').style.display = '';
	// Dauer
	document.getElementById('duration').style.display = '';
	
	switch (type) {
		case '1': // Praktikum
			document.getElementById('internship').style.display = ''; // nur hier
			document.getElementById('study').style.display = '';
			break;
		case '2': // Bachelor- / Masterarbeit
			document.getElementById('study').style.display = '';
			document.getElementById('date').style.display = 'none'; // nur hier
			document.getElementById('zeitraum').options[0].selected = true;
			break;
		case '4': // Ausbildung
			document.getElementById('duration').style.display = 'none';
			document.getElementById('dauer').options[0].selected = true;
			break;
		case '5': // Berufseinstieg
			document.getElementById('job').style.display = ''; // nur hier
			document.getElementById('duration').style.display = 'none';
			document.getElementById('dauer').options[0].selected = true;
			break;
		default:
			break;
	}
}
