// JavaScript Document

function doit(id,url,pars) {
	

	var MyAjax = new Ajax.Updater(id, url, {method: 'get', parameters: pars});
	
	return false;
}

function is_number(a_string) {
tc = a_string.charAt(0);
	if (tc == "0" || tc == "1" || tc == "2" || tc == "3" ||	tc == "4" || tc == "5" || tc == "6" || tc == "7" || tc == "8" || tc == "9") {
	return true;
	} 
	else {
	return false;
	   }
}


function checkCode(code) {
	if(code.length == 6) {
		doit('hinweis','ajax.php','mode=checkCode&code=' + code);
	}
	else {
		$('hinweis').innerHTML = '';
	}
}

function checkSchulnote(note) {
	if(note > 6 || note < 1 || !is_number(note)) {
		$('hinweis_note').innerHTML = "Bitte eine Zahl von 1 bis 6 eingeben"
		$('abschicken').disabled = "disabled";
	}
	else {
		$('hinweis_note').innerHTML = "";
		$('abschicken').disabled = "";
	}
	
}

function checkFragebogen(mitrot) {
	$('feld_hinweis').innerHTML = "";
	var error = false;

	if($('note').value < 1 || $('note').value > 6) {
		error = true;
		if(mitrot) $('feld_note').style.backgroundColor = '#FF0000';
	}
	else {

		$('feld_note').style.backgroundColor = '#fff';
	}
	
	// Einzelne Radios
	for(var i=1; i <= 17; i++) {
		if($('wichtig_'+i+'_0').checked || $('wichtig_'+i+'_1').checked || $('wichtig_'+i+'_5').checked) {
			$('feld_w_'+i+'_0').style.backgroundColor = '#FFA743';
			$('feld_w_'+i+'_1').style.backgroundColor = '#FFA743';
			$('feld_w_'+i+'_5').style.backgroundColor = '#FFA743';
		}
		else {
			if(mitrot) {
				$('feld_w_'+i+'_0').style.backgroundColor = '#FF0000';
				$('feld_w_'+i+'_1').style.backgroundColor = '#FF0000';
				$('feld_w_'+i+'_5').style.backgroundColor = '#FF0000';
			}
			error = true;
		}
		if($('leistung_'+i+'_1').checked || $('leistung_'+i+'_2').checked || $('leistung_'+i+'_3').checked ||$('leistung_'+i+'_4').checked) {
			$('feld_l_'+i+'_4').style.backgroundColor = '#FF7400';
			$('feld_l_'+i+'_3').style.backgroundColor = '#FF7400';
			$('feld_l_'+i+'_2').style.backgroundColor = '#FF7400';
			$('feld_l_'+i+'_1').style.backgroundColor = '#FF7400';
		}
		else {
			if(mitrot) {
				$('feld_l_'+i+'_4').style.backgroundColor = '#990000';
				$('feld_l_'+i+'_3').style.backgroundColor = '#990000';
				$('feld_l_'+i+'_2').style.backgroundColor = '#990000';
				$('feld_l_'+i+'_1').style.backgroundColor = '#990000';			
			}
			error = true;
		}
		
		
		
	}
	if(error){
		if(mitrot) $('feld_hinweis').innerHTML = "Bitte füllen Sie noch alle roten Felder aus.";
		return false;
	}
	else
		return true;
		
	
}