Marked	=	"#FAA";
var TNArray	=	new	Array();
function checkCount( TF, ID ) {
	if( TD1 = get( "cnt_" + ID + "_1" ) ) {
		if( TD2 = get( "cnt_" + ID + "_2" ) ) {
			Cnt	=	0;
			TF.style.backgroundColor	=	"";
			if( Check = parseInt( TF.value ) ) {
				if( Check < 0 ) {
					TF.style.backgroundColor	=	Marked;
				}
				else {
					Cnt	=	Check;
				}
			}
			else {
				if( TF.value != "" && TF.value != "0" ) {
					TF.style.backgroundColor	=	Marked;
				}
			}
			TD1.innerHTML	=	Cnt;
			TD2.innerHTML	=	Cnt;
		}
	}
	calulatePrice();
}

function calulatePrice() {
	Erg	=	0;
	for( i=1; i<6; i++ ) {
		if( Check = get( "anzahl_" + i ) ) {
			if( Cnt = parseInt( Check.value ) ) {
				Erg	+=	Cnt * Price[ i ];
//				alert( Cnt + " * " + Price[ i ] + " = " + ( Cnt * Price[ i ] ) );
			}
		}
	}
	if( Tage > 1 || PPPGleich && SPInk ) {
		EZ	=	0;
		if( Check = get( "anzahl_0" ) ) {
			if( Cnt = parseInt( Check.value ) ) {
				DZ	=	Cnt;
				get( "room_0_1" ).innerHTML	=	get( "room_0_2" ).innerHTML	=	Cnt;
				Erg	+=	Cnt * Room[ 0 ];
			}
		}
		if( Check = get( "einzelzimmer" ) ) {
			if( Cnt = parseInt( Check.value ) ) {
				EZ	=	Cnt;
				get( "room_1_1" ).innerHTML	=	get( "room_1_2" ).innerHTML	=	Cnt;
				Erg	+=	Cnt * Room[ 1 ];
			}
		}
		if( Check = get( "mehrbettzimmer" ) ) {
			if( Cnt = parseInt( Check.value ) ) {
				MZ	=	Cnt;
				get( "room_2_1" ).innerHTML	=	get( "room_2_2" ).innerHTML	=	Cnt;
				Erg	+=	Cnt * Room[ 2 ];
			}
		}
	}
	
	if( Check = get( "leihrad" ) ) {
		if( Cnt = parseInt( Check.value ) ) {
			get( "typ2_leihrad_1" ).innerHTML	=	get( "typ2_leihrad_2" ).innerHTML	=	Cnt;
			Erg	+=	Cnt * Leihrad;
		}
	}
	if( Check = get( "ohne_rad" ) ) {
		if( Cnt = parseInt( Check.value ) ) {
			get( "typ2_ohne_1" ).innerHTML	=	get( "typ2_ohne_2" ).innerHTML	=	Cnt;
			Erg	-=	Cnt * OhneRad;
		}
	}
	
	if( Sel = get( "rrv" ) ) {
		RRV_Price	=	0;
		if( Sel.selectedIndex == 0 ) {
			RRV_Price	=	calculateRRV( Erg );
//			Erg	+= RRV_Price;
		}
		if( RRVTD = get( "price_rrv" ) ) {
			if( Sel.options[Sel.selectedIndex].value == "1" ) {
				RRVTD.innerHTML	=	"Ja";
			}
			else {
				RRVTD.innerHTML	=	"Nein";
			}
//			RRVTD.innerHTML	=	formatCurrency( RRV_Price );
		}
	}
	if( Total = get( "price_total" ) ) {
		Total.innerHTML	=	formatCurrency( Erg );
	}

}

function calculateRRV( Gesamt ) {
	for( i=0; i<RRV.length; i++ ) {
		if( Gesamt <= RRV[ i ][ 0 ] ) {
			return	RRV[ i ][ 1 ];
		}
	}
	return	RRV[ RRV.length - 1 ][ 1 ];
}

// gibt eine Zahl mit Tausendertrennzeichen aus (Währungsformatierung)
function formatCurrency( Price ) {
	PriceString	=	"";
	if( Price != "" ) {
		NewPrice	=	parseFloat( Price );
		Rest		=	Math.round( ( NewPrice - parseInt( NewPrice ) ) * 100 );
/*		if( ( NewPrice * 100 ) % 100 != 0 ) {
			Rest	=	parseInt( ( NewPrice * 100 ) % 100 );
		}*/
//		NewPrice	=	parseInt( ( NewPrice * 100 - Rest ) / 100 );
		NewPrice	=	Math.round( NewPrice - Rest / 100 );
		TmpStr		=	NewPrice.toString();
		for( t=0; t<TmpStr.length; t++ ) {
			PriceString	=	TmpStr.charAt( TmpStr.length - t - 1 ) + PriceString;
			if( t % 3 == 2 && t < TmpStr.length - 1 ) {
				PriceString	=	"." + PriceString;
			}
		}
		if( Rest > 0 ) {
			RestString	=	Rest.toString();
			if( Rest < 10 ) {
				RestString	=	"0" + RestString;
			}

			PriceString	+=	"," + RestString;
		}
	}
	if( PriceString == "" ) {
		PriceString	=	"0";
	}
	return PriceString + " &euro;";
}

function changeZustiegsort( Sel ) {
	if( Sp = get( "zo_text" ) ) {
		Sp.innerHTML	=	Sel.options[ Sel.selectedIndex ].text;
		if( Sel.selectedIndex > 0 ) {
			Sel.style.backgroundColor	=	"";
		}
	}
}
function showalldivs() {
	for( i=0; i<4; i++ ) {
		if( div = get( "booking" + i ) ) {
			div.style.display		=	"block";
			get( "bkimg" + i ).src	=	"/img/content/book_open.gif";
		}
	}
}
VisibleBook	=	0;
function changeBook( Nr ) {
	Op	=	false;
	if( Div = get( "booking" + Nr ) ) {
		if( Div.style.display == "none" ) {
			Div.style.display	=	"block";
			get( "bkimg" + Nr ).src	=	"/img/content/book_close.gif";
			VisibleBook	=	Nr;
			Op	=	true;
		}
		else {
			Div.style.display	=	"none";
			get( "bkimg" + Nr ).src	=	"/img/content/book_open.gif";
		}
	}
	if( Nr > 0 && Op ) {
		for( i=0; i<Nr; i++ ) {
			if( Div = get( "booking" + i ) ) {
				Div.style.display	=	"none";
				get( "bkimg" + i ).src	=	"/img/content/book_open.gif";
			}
		}
	}
}
function gotoBook( Nr ) {
	for( i=Nr; i<4; i++ ) {
		if( Div = get( "booking" + i ) ) {
			Div.style.display	=	"none";
			get( "bkimg" + i ).src	=	"/img/content/book_open.gif";
		}
	}
	changeBook( Nr );
}
function checkBuchung() {
	Err	=	false;
	ErrorMessage	=	"";
	Muss	=	Array( "name", "forename", "street", "hnr", "p.c.", "town", "phone_private", "email" );
	for( i=0; i<Muss.length; i++ ) {
		if( TF = get( Muss[ i ] ) ) {
			if( TF.value == "" ) {
				Err	=	true;
				TF.style.backgroundColor	=	Marked;
			}
			else {
				TF.style.backgroundColor	=	"";
				if( Muss[ i ] == "email" ) {
					if( checkMail( TF.value ) ) {
						TF.style.backgroundColor	=	"";
					}
					else {
						Err	=	true;
						TF.style.backgroundColor	=	Marked;
						ErrorMessage	+=	FormFailure[ "falsche_email" ] + "\n";
					}
				}
			}
		}
		else {
			alert( FormFailure[ "critical_error" ] );
			return	false;
		}
	}
	if( Sel = get( "zustiegsort" ) ) {
		if( Sel.selectedIndex == 0 ) {
			Sel.style.backgroundColor	=	Marked;
			Err	=	true;
			ErrorMessage	+=	FormFailure[ "zustiegsort_fehlt" ] + "\n";
		}
		else {
			Sel.style.backgroundColor	=	"";
		}
	}
	else {
		alert( FormFailure[ "critical_error" ] );
		return false;
	}
	if( CB = get( "gsc" ) ) {
		if( ! CB.checked ) {
			ErrorMessage	+=	FormFailure[ "agbs_nicht_akzeptiert" ] + "\n";
			Err	=	true;
			CB.style.backgroundColor	=	Marked;
		}
		else {
			CB.style.backgroundColor	=	"";
		}
	}
	else {
		alert( FormFailure[ "critical_error" ] );
		return false;
	}
	if( TF = get( "gutscheincode" ) ) {
		if( TF.value.length != 4 && TF.value.length != 0 ) {
			ErrorMessage	+=	FormFailure[ "gutscheincode_falsch" ] + "\n";
			Err	=	true;
			TF.style.backgroundColor	=	Marked;
		}
	}
	Teilnehmer	=	0;
	TNCheck	=	false;
	for( i=0; i<6; i++ ) {
		if( TF = get( "anzahl_" + i ) ) {
			if( ! isNaN( TF.value ) && ! TF.value == "" ) {
				Teilnehmer += parseInt( TF.value );
				if( i == 0 ) {
					if( Teilnehmer > 0 ) {
						TNCheck	=	false;
						TF.style.backgroundColor	=	"";
					}
					else {
						TF.style.backgroundColor	=	Marked;
					}
				}
			}
			if( i == 0 ) {
				break;
			}
		}
	}
	if( Teilnehmer <= 0 ) {
		Err	=	true;
		ErrorMessage	+=	FormFailure[ "keine_teilnehmer" ] + "\n";
	}
	else {
		if( Tage > 1 ) {
			TNCheck	=	false;
			for( i=0; i<Teilnehmer; i++ ) {
				if( TF = get( "teilnehmer_" + i + "_0" ) ) {
					if( TF2 = get( "teilnehmer_" + i + "_1" ) ) {
						if( TF.value == "" || TF2.value == "" ) {
							if( !TNCheck ) {
								TNCheck	=	true;
								Err	=	true;
								ErrorMessage	+=	FormFailure[ "nicht_alle_teilnehmer_eingetragen" ] + "\n";
							}
							if( TF.value == "" ) {
								TF.style.backgroundColor	=	Marked;
							}
							else {
								TF.style.backgroundColor	=	"";
							}
							if( TF2.value == "" ) {
								TF2.style.backgroundColor	=	Marked;
							}
							else {
								TF2.style.backgroundColor	=	"";
							}
						}
					}
				}
			}
		}
	}
	if( Err ) {
		showalldivs();
		alert( FormError + "\n" + ErrorMessage );
		return	false;
	}
	return	true;
}
function jetztbuchen( ID ) {
	if( ID > 0 ) {
		location.href	+=	"&bid=" + ID;
	}
}
function checkGutschein() {
	Err	=	false;
	ErrorMessage	=	"";
	Muss	=	Array( "b_name", "b_forename", "b_street", "b_hnr", "b_p.c.", "b_town", "amount", "name", "forename", "street", "hnr", "p.c.", "town", "phone_private", "email", "Sicherheitscode" );
	for( i=0; i<Muss.length; i++ ) {
		if( TF = get( Muss[ i ] ) ) {
			if( TF.value == "" ) {
				Err	=	true;
				TF.style.backgroundColor	=	Marked;
			}
			else {
				TF.style.backgroundColor	=	"";
				if( Muss[ i ] == "email" ) {
					if( checkMail( TF.value ) ) {
						TF.style.backgroundColor	=	"";
					}
					else {
						Err	=	true;
						TF.style.backgroundColor	=	Marked;
						ErrorMessage	+=	FormFailure[ "falsche_email" ] + "\n";
					}
				}
			}
		}
		else {
			alert( FormFailure[ "critical_error" ] );
			return	false;
		}
	}
	if( TF = get( "amount" ) ) {
		if( isNaN( parseInt( TF.value ) ) ) {
			ErrorMessage	+=	FormFailure[ "not_a_number" ];
			TF.style.backgroundColor	=	Marked;
			Err	=	true;
		}
	}
	if( Err ) {
		showalldivs();
		alert( FormError + "\n" + ErrorMessage );
		return	false;
	}
	return	true;
}
function checkMultipleJourney() {
	Err	=	false;
	ErrorMessage	=	"";
	Muss	=	Array( "abfahrt", "a_uhrzeit", "rueckkehr", "r_uhrzeit", "abfahrtsort", "fahrtziel", "name", "forename", "street", "hnr", "p.c.", "town", "phone_day", "email", "Sicherheitscode" );
	Kann	=	Array( "b_name", "b_forename", "b_street", "b_hnr", "b_p.c.", "b_town", "b_phone_private", "b_email" ); // wenn eins davon ausgefüll ist, müssen alle ausgefüllt sein
	for( i=0; i<Muss.length; i++ ) {
		if( TF = get( Muss[ i ] ) ) {
			if( TF.value == "" || ( i < 4 ) && ( TF.value == "Datum" || TF.value == "Uhrzeit" ) ) {
				Err	=	true;
				TF.style.backgroundColor	=	Marked;
			}
			else {
				TF.style.backgroundColor	=	"";
				if( Muss[ i ] == "email" ) {
					if( checkMail( TF.value ) ) {
						TF.style.backgroundColor	=	"";
					}
					else {
						Err	=	true;
						TF.style.backgroundColor	=	Marked;
						ErrorMessage	+=	FormFailure[ "falsche_email" ] + "\n";
					}
				}
			}
		}
		else {
			alert( FormFailure[ "critical_error" ] );
			return	false;
		}
	}
	Kanncheck	=	false;
	for( i=0; i<Kann.length; i++ ) {
		if( TF = get( Kann[ i ] ) ) {
			if( TF.value != "" ) {
				Kanncheck	=	true;
				break;
			}
		}
	}
	if( Kanncheck ) {
		for( i=0; i<Kann.length; i++ ) {
			if( TF = get( Kann[ i ] ) ) {
				if( TF.value == "" ) {
					TF.style.backgroundColor	=	Marked;
					Err	=	true;
				}
			}
		}
	}
	// Oderabfragen für Gruppen- / Schülerreisen
	if( TF = get( "personen" ) ) {
		if( TF.value == "" ) {
			TF.style.backgroundColor	=	Marked;
			Err	=	true;
		}
	}
	if( TF = get( "schueler" ) )  {
		if( TF.value == "" ) {
			TF.style.backgroundColor	=	Marked;
			Err	=	true;
		}
	}
	if( TF = get( "lehrer" ) )  {
		if( TF.value == "" ) {
			TF.style.backgroundColor	=	Marked;
			Err	=	true;
		}
	}
	if( TF = get( "school" ) ) {
		if( TF.value == "" ) {
			TF.style.backgroundColor	=	Marked;
			Err	=	true;
		}
	}
	if( Err ) {
		showalldivs();
		alert( FormError + "\n" + ErrorMessage );
		return	false;
	}
	return	true;

}
function checkOnload() {
	for( j=0; j<6; j++ ) {
		if( TF = get( "anzahl_" + j ) ) {
			checkCount( TF, j );
		}
	}
}
function createTeilnehmer() {
	if( Tage > 1 ) {
		if( Div = get( "TEILNEHMER") ) {
			TN	=	0;
			if( TF = get( "anzahl_0" ) ) {
				if( TF.value != "" ) {
					TN	+=	parseInt( TF.value );
				}
			}
			else {
				for( i=1; i<6; i++ ) {
					if( TF = get( "anzahl_" + i ) ) {
						if( TF.value != "" ) {
							TN	+=	parseInt( TF.value );
						}
					}
				}
			}
			HTML	=	"";
			saveTeilnehmerTmp();
			if( TN > 0 ) {
				HTML	+=	"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"FORM\">";
				HTML	+=		"<tr>";
				HTML	+=			"<td>&nbsp;</td>";
				HTML	+=			"<td style=\"font-weight:bold;padding-left:6px;\"><div style=\"display:block;float:left;width:182px;\">Vorname</div>Nachname</td>";
				HTML	+=		"</tr>";
				for( i=0; i<TN; i++ ) {
					Name0	=	Name1	=	"";
					if( TNArray.length > i ) {
						Name0	=	TNArray[ i ][ 0 ];
						Name1	=	TNArray[ i ][ 1 ];
					}
					HTML	+=	"<tr>"
					HTML	+=		"<td class=\"td1\">" + ( i + 1 ) + ". Teilnehmer<u>*</u>:</td>";
					HTML	+=		"<td><input type=\"text\" name=\"teilnehmer_" + i + "_0\" id=\"teilnehmer_" + i + "_0\" class=\"small\" value=\"" + Name0 + "\" onChange=\"markTF(this)\">";
					HTML	+=		"<input type=\"text\" name=\"teilnehmer_" + i + "_1\" id=\"teilnehmer_" + i + "_1\" class=\"small\" value=\"" + Name1 + "\" onChange=\"markTF(this)\"></td>";
					HTML	+=	"</tr>"
				}
				HTML	+=	"</table>";
			}
			Div.innerHTML	=	HTML;
		}
	}
}
function saveTeilnehmerTmp() { // Teilnehmer, die gerade eingetragen sind zwischenspeichern
	Counter	=	0;
	while( TF = get( "teilnehmer_" + Counter + "_0" ) ) {
		if( TF2 = get( "teilnehmer_" + Counter + "_1" ) ) {
			TNArray[ Counter ]	=	Array( TF.value, TF2.value );
		}
		Counter++;
	}
}