function showBezirkFieldset(val) {
	if(val != '') {
		Effect.Appear('bezirk_div', {duration:0.0});
		Effect.DropOut('krankenhaus_div');
		Effect.DropOut('bewertung_text_div');
		new Ajax.Request(
			'create.php?what=selectBezirkRatingForm&id_bundesland='+val,
			{
				onComplete:	function(t) {
											document.getElementById('bezirk_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('bezirk_select').appendChild(opt);
											}
										},										
				onFailure: 	function(t) { alert('Error');}
			}
		);
	} else {
		Effect.DropOut('bezirk_div');
		Effect.DropOut('krankenhaus_div');
		Effect.DropOut('abteilung_div');
		Effect.DropOut('bewertung_text_div');
	}
}

function createSelectEditRating(what,val) {
	switch(what) {
		case 'bezirk':
			new Ajax.Request(
			'create.php?what=selectBezirkRatingForm&id_bundesland='+val,
			{
				onComplete:	function(t) {
											document.getElementById('bezirk_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('bezirk_select').appendChild(opt);
											}
										},										
				onFailure: 	function(t) { alert('Error');}
			}
		);
		break;
		case 'krankenhaus':
		new Ajax.Request(
			'create.php?what=selectAbteilungRatingForm',
			{
				onComplete:	function(t) {
											document.getElementById('abteilung_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('abteilung_select').appendChild(opt);
											}
										},	
				onFailure: 	function(t) { alert('Error');}
			}
		);		
		break;
	}
}

function showKrankenhausFieldset(val) {
	if(val != '') {
		Effect.Appear('krankenhaus_div', {duration:0.0});
		new Ajax.Request(
			'create.php?what=selectKrankenhausRatingForm&id_bezirk='+val,
			{
				onComplete:	function(t) {
											document.getElementById('krankenhaus_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('krankenhaus_select').appendChild(opt);
											}
										},	
				onFailure: 	function(t) { alert('Error');}
			}
		);		
	} else {
		Effect.DropOut('krankenhaus_div');
		Effect.DropOut('abteilung_div');
		Effect.DropOut('bewertung_text_div');
	}
}

function showAbteilungFieldset(val) {
	if(val != '') {
		Effect.Appear('abteilung_div', {duration:0.0});
		new Ajax.Request(
			'create.php?what=selectAbteilungRatingForm',
			{
				onComplete:	function(t) {
											document.getElementById('abteilung_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('abteilung_select').appendChild(opt);
											}
										},	
				onFailure: 	function(t) { alert('Error');}
			}
		);		
	} else {
		Effect.DropOut('abteilung_div');
		Effect.DropOut('bewertung_text_div');		
	}
}

function showBewertungFieldset(val) {
	if(val != '') {
		Effect.Appear('bewertung_text_div', {duration:0.0});
	} else {
		Effect.DropOut('bewertung_text_div');
	}
}

function setStars(id,typ) {
	var i = 1;
	var path = document.getElementById('star'+id+'_'+typ).src.length;
	if(path <= 63) { // von leer auf voll
		for(i; i <= id; i++) {
			document.getElementById('star'+i+'_'+typ).src = 'images/votingstar_full.png';
		}
		document.getElementById('bewertung_wert_'+typ).value = id;
	} else {
		for(i = 5; i >= id; i--) { // von voll auf leer
			document.getElementById('star'+i+'_'+typ).src = 'images/votingstar.png';
		}
		document.getElementById('bewertung_wert_'+typ).value = id-1;
	}
}

function saveRating () {
	var id_bundesland;
	var id_bezirk;
	var id_krankenhaus;
	var id_abteilung;
	var bewertung_text;
	var bewertung_wert_aufnahme;
	var bewertung_wert_zustand;	
	var bewertung_wert_beratung;	
	
	id_bundesland = document.getElementById('bundesland_select').options[document.getElementById('bundesland_select').selectedIndex].value;
	id_bezirk = document.getElementById('bezirk_select').options[document.getElementById('bezirk_select').selectedIndex].value;
	id_krankenhaus = document.getElementById('krankenhaus_select').options[document.getElementById('krankenhaus_select').selectedIndex].value;
	id_abteilung = document.getElementById('abteilung_select').options[document.getElementById('abteilung_select').selectedIndex].value;			
	bewertung_text = document.getElementById('bewertung_text').value;
	bewertung_wert_aufnahme = document.getElementById('bewertung_wert_aufnahme').value;
	bewertung_wert_zustand = document.getElementById('bewertung_wert_zustand').value;
	bewertung_wert_beratung = document.getElementById('bewertung_wert_beratung').value;	
	
	Effect.BlindUp('rate_form',{duration: 0.0});
	Effect.Appear('loader_div', {duration:0.0});
	
	var url = 'save.php';
	var params = 'id_bundesland='+id_bundesland+'&id_bezirk='+id_bezirk+'&id_krankenhaus='+id_krankenhaus+'&id_abteilung='+id_abteilung+'&bewertung_text='+escape(bewertung_text)+'&bewertung_wert_aufnahme='+bewertung_wert_aufnahme+'&bewertung_wert_zustand='+bewertung_wert_zustand+'&bewertung_wert_beratung='+bewertung_wert_beratung
	
	new Ajax.Request (
		url,
		{	
			method: 'post',
			parameters: params,
			onComplete: function(t) {
										Effect.BlindUp('loader_div',{duration:0.0});
										Effect.Appear('saved_div',{duration:0.0});
									},
			onFailure: function(t) {alert('Error'); }
		}
	);
}

function saveRatingDirect () {
	var id_bundesland;
	var id_bezirk;
	var id_krankenhaus;
	var id_abteilung;
	var bewertung_text;
	var bewertung_wert_aufnahme;
	var bewertung_wert_zustand;
	var bewertung_wert_beratung;
		
	id_bundesland = document.getElementById('id_bundesland').value;
	id_bezirk = document.getElementById('id_bezirk').value;
	id_krankenhaus = document.getElementById('id_krankenhaus').value;
	id_abteilung = document.getElementById('abteilung_select').options[document.getElementById('abteilung_select').selectedIndex].value;			
	bewertung_text = document.getElementById('bewertung_text').value;
	bewertung_wert_aufnahme = document.getElementById('bewertung_wert_aufnahme').value;
	bewertung_wert_zustand = document.getElementById('bewertung_wert_zustand').value;
	bewertung_wert_beratung = document.getElementById('bewertung_wert_beratung').value;		
	
	Effect.BlindUp('rate_form',{duration: 0.0});
	Effect.Appear('loader_div', {duration:0.0});
	
	var url = 'save.php';
	var params = 'id_bundesland='+id_bundesland+'&id_bezirk='+id_bezirk+'&id_krankenhaus='+id_krankenhaus+'&id_abteilung='+id_abteilung+'&bewertung_text='+escape(bewertung_text)+'&bewertung_wert_aufnahme='+bewertung_wert_aufnahme+'&bewertung_wert_zustand='+bewertung_wert_zustand+'&bewertung_wert_beratung='+bewertung_wert_beratung
	
	new Ajax.Request (
		url,
		{	
			method: 'post',
			parameters: params,
			onComplete: function(t) {
										Effect.BlindUp('loader_div',{duration:0.0});
										Effect.Appear('saved_div',{duration:0.0});
									},
			onFailure: function(t) {alert('Error'); }
		}
	);
}

function checkField(id) {
	var val = document.getElementById(id).value;
	var field = document.getElementById(id);
	var ok = 'images/ok.png';
	var nok = 'images/nok.png';
	switch(id) {
		case 'username':
			if(val.length > 1 && val.indexOf(' ') == -1) {
				new Ajax.Request(
					'check.php?field=username&val='+val,
					{
						onComplete: function (t) {
							if(t.responseText == 'false') {
								document.getElementById(id+'_img').src = nok;
							} else {
								document.getElementById(id+'_img').src = ok;			
							}
						},
						onFailure: function (t) { alert('Error'); }
					}
				);
				document.getElementById(id+'_img').src = ok;
			} else {
				document.getElementById(id+'_img').src = nok;
			}
		break;
		case 'password': 
			if(val.length > 1 && val.indexOf(' ') == -1) {
				document.getElementById(id+'_img').src = ok;
				if(val != document.getElementById('password2').value) {
					document.getElementById('password2_img').src = nok;
				}
				
			} else {
				document.getElementById(id+'_img').src = nok;
			}
		break;
		case 'password2':
			if(val.length > 1 && val.indexOf(' ') == -1 && val == document.getElementById('password').value) {
				document.getElementById(id+'_img').src = ok;
			} else {
				document.getElementById(id+'_img').src = nok;
			}
		break;
		case 'email':
			if(val.length > 0) {
				var at = val.indexOf('@');
				var point = val.indexOf('.',at);
				var komma = val.indexOf(',');
				var leer = val.indexOf(' ');
				if(at > 0 && at != -1 && point != -1 && komma == -1 && leer == -1) {
					document.getElementById(id+'_img').src = ok;
				} else {
					document.getElementById(id+'_img').src = nok;
				}
				
			} else {
				document.getElementById(id+'_img').src = nok;
			}
		break;
	}
}

function checkRegistry() {
	var ok = 'images/ok.png';
	var nok = 'images/nok.png';
	var username = document.getElementById('username_img').src.indexOf(nok);
	var password = document.getElementById('password_img').src.indexOf(nok);
	var password2 = document.getElementById('password2_img').src.indexOf(nok);
	var email = document.getElementById('email_img').src.indexOf(nok);
	if(username == -1 && password == -1 && password2 == -1 && email == -1) {
		return true;
	} else {
		alert('Du musst alle Felder (richtig) ausf'+unescape('%FC')+'llen');
		return false;
	}
}

function editRating() {
	return true;
}

function createSelectCatalog(what,val) {
	switch(what) {
		case 'bezirk':
			new Ajax.Request(
			'create.php?what=selectBezirkRatingForm&id_bundesland='+val,
			{
				onComplete:	function(t) {
											document.getElementById('bezirk_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('bezirk_select').appendChild(opt);
											}
										},										
				onFailure: 	function(t) { alert('Error');}
			}
		);
		break;
		case 'krankenhaus':
		new Ajax.Request(
			'create.php?what=selectAbteilungRatingForm',
			{
				onComplete:	function(t) {
											document.getElementById('abteilung_select').options.length = null;
											var opts = t.responseText.split(',');
											var i;
											var opt;
											var opttext;
											for(i = 0; i < opts.length; i+=2) {
												opt = document.createElement('option');
												opttext = document.createTextNode(unescape(opts[i+1]));
												opt.appendChild(opttext);
												opt.setAttribute('value',opts[i])	;
												document.getElementById('abteilung_select').appendChild(opt);
											}
										},	
				onFailure: 	function(t) { alert('Error');}
			}
		);		
		break;
	}
}

