function do_onmouseover(obj, idx){
	setEntryAttributes(obj, idx, marker_colors['mouseover']);
	return true;
}

function do_onmouseout(obj, idx){
	resetEntry(obj, idx);
	return true;
}

function do_onmousedown(obj, idx){

	// col = Spalte Hin/Rückflug
	if(obj.id.indexOf('hin')>0){
		col = "hin";
		ccol = "rueck"; // "countercolumn" ggüber liegende Spalte
		ftype_idx = "out";
	}
	else if(obj.id.indexOf('rueck')>0){
		col = "rueck";
		ccol = "hin"; // "countercolumn" ggüber liegende Spalte
		ftype_idx = "return";
	}

	// Checkboxen in der ggü Spalte zurücksetzen
	//
	reset_CBX(ccol, idx);

	// alle Markierungen zurücksetzen
	//
	reset_all();

	// Informationen zum Flugpaar zurücksetzen
	//
	reset_hidden_info_fields();

	// diese cbx checken
	cbx = col+'_'+idx;
	eval('document.form1.'+cbx+'.checked = true;');

	// related_flights in derselben Spalte markieren
	//
	l = eval('related_flights_'+ftype_idx+'[idx].length');
	//alert(l);
	for(i=0;i<l;i++){
		rel_idx = eval('related_flights_'+ftype_idx+'[idx][i]');
		//alert(rel_idx);
		// existiert CBX-Formularobject ?
		if(document.getElementById(col+'_'+rel_idx)){

				// Element mit dem Radiobutton selektieren
			//	highlightCell(col+'_radio_'+rel_idx, marker_colors['selected']);
				// NOTE: new highlighting
				highlightCell('liste_'+col+'_'+rel_idx, marker_colors['font_selected']);
				document.getElementById(col+'_radio_'+rel_idx).className = 'RadioBlue';
				// Zustand speichern
				if(col == "hin") hin[rel_idx] = 1;
				else rueck[rel_idx] = 1;
			}
		}

	// gewählte Zeile markieren
	//
	obj = document.getElementById('liste_'+col+'_'+idx);
	setEntryAttributes(obj, idx, marker_colors['selected']);

	// kombinierbare Flüge (option_idx) in der ggü liegenden Spalte markieren
	//
	l = eval('flight_options_'+ftype_idx+'[idx].length;');
	// markiere kombinierbare Rückflüge
	for (i=0;i<l;i++){
		// exisitiert CBX-Formularobject ?
		if(document.getElementById('liste_'+ccol+'_'+i)!="undefined"){

			option_idx = eval('flight_options_'+ftype_idx+'[idx][i];');

			// Element mit dem Radiobutton selektieren
	//		highlightCell(ccol+'_radio_'+option_idx, marker_colors['selected']);
			// NOTE: new highlighting
			highlightCell('liste_'+ccol+'_'+option_idx, marker_colors['font_selected']);
			document.getElementById(ccol+'_radio_'+option_idx).className = 'RadioBlue';

			// ggü liegende gecheckte Zeile markieren
			//
			if(document.getElementById(ccol+'_'+option_idx)){
				if(eval('document.form1.'+ccol+'_'+option_idx+'.checked') == true){
					obj = document.getElementById('liste_'+ccol+'_'+option_idx);
					setEntryAttributes(obj, option_idx, marker_colors['selected']);
				}
			}

			// Zustand speichern
			if(col == "hin") rueck[option_idx] = 1;
			else hin[option_idx] = 1;
		}
	}


	// ge-checkte Indizes ermitteln
	//
	hin_idx = -1;
	rueck_idx = -1;

	for(i=0;i<flight_options_out.length;i++){
		// existiert CBX-Formularobject ?
		if(document.getElementById('hin_'+i)){
			// checked ?
			if(eval('document.form1.hin_'+i+'.checked') == true){
				hin_idx = i;
			}
		}
	}
	for(i=0;i<flight_options_return.length;i++){
		// existiert CBX-Formularobject ?
		if(document.getElementById('rueck_'+i)){
			// checked ?
			if(eval('document.form1.rueck_'+i+'.checked') == true){
				rueck_idx = i;
			}
		}
	}


	// sind Hin- + Rückflug ausgewählt ?
	// -> Reisedauer und Preis ermitteln
	// und diese Werte sowie die Flugindizes in hidden fields schreiben
	//
	if(hin_idx>=0 && rueck_idx>=0){

		eval('document.form1.selected_out.value='+hin_idx);
		eval('document.form1.selected_return.value='+rueck_idx);

		var diffdays=diffdays_return[rueck_idx]-diffdays_out[hin_idx];
		var price = parseInt(travel_price[hin_idx]) + parseInt(return_travel_price[rueck_idx]);

		eval('document.form1.flight_travel_days.value='+diffdays);
		eval('document.form1.flight_total_price.value='+price);
	}

	// Auswahlzustand (flight_selection_state) setzen
	//
	if(hin_idx>=0 && rueck_idx<0){
		// 2 -> nur Hinflug
		eval('document.form1.flight_selection_state.value=2');
	}
	if(hin_idx<0 && rueck_idx>=0){
		// 3 -> nur Rückflug
		eval('document.form1.flight_selection_state.value=3');
	}
	if(hin_idx>=0 && rueck_idx>=0){
		// 4 -> Hin- und Rückflug
		eval('document.form1.flight_selection_state.value=4');
	}


	// externe custom Funktion aufrufen, die eine Meldung ausgibt
	//
	flight_info();

}


// Alle Markierungen zurücksetzen
//
function reset_all(){

//	var hin_len = document.form1.hin.length;
	var hin_len = 35;

	for(i=0;i<=hin_len;i++){
		// exisitiert Formularobject ?
		if(document.getElementById('hin_'+i)){

			hin[i]=0;

			obj = document.getElementById('liste_hin_'+i);
			resetEntry(obj, i);
		}

		// NOTE: new highlighting
		if(document.getElementById('liste_hin_'+i)){
			highlightCell('liste_hin_'+i, marker_colors['font_unselected']);
			document.getElementById('hin_radio_'+i).className = 'RadioUnselect';
		}
		
	}

//	var rueck_len = document.form1.rueck.length;
	var rueck_len = 35;

	for(i=0;i<=rueck_len;i++){
		// exisitiert Formularobject ?
		if(document.getElementById('rueck_'+i)){

			rueck[i]=0;

			obj = document.getElementById('liste_rueck_'+i);
			resetEntry(obj, i);

		}

		// NOTE: new highlighting
		if(document.getElementById('liste_rueck_'+i)){
			highlightCell('liste_rueck_'+i, marker_colors['font_unselected']);
			document.getElementById('rueck_radio_'+i).className = 'RadioUnselect';
		}
	}
}


// Checkboxen in der ggü. liegenden Spalte zurücksetzen
//
function reset_CBX(col,idx){
//	len = eval('document.form1.'+col+'.length;');

	len = 35;

	for(i=0;i<=len;i++){
		// exisitiert CBX Formularobject ?
		if(document.getElementById(col+'_'+i)){

			// related flight in der ggü liegenden Spalte nicht unchecken
			//
			if(col=="rueck"){
				if(!flight_options_out[idx].contains (i)){
					eval('document.form1.'+col+'_'+i+'.checked = false;');
				}
			}
			if(col=="hin"){
				if(!flight_options_return[idx].contains (i)){
					eval('document.form1.'+col+'_'+i+'.checked = false;');
				}
			}
		}
	}
}


// Informationen zum Flugpaar zurücksetzen
//
function reset_hidden_info_fields(){

	document.form1.selected_out.value='';
	document.form1.selected_return.value='';
	document.form1.flight_travel_days.value='';
	document.form1.flight_total_price.value='';

}



// Ermitteln von "related flights" aus der Liste verfügbarer Hin/Rückflüge
//
// init_all : Zwei arrays initialisieren
// dient der Buchführung selektierter Einträge
//
function flight_init_all(){

	related_flights_out = new Array();
	related_flights_return = new Array();

	// related_flights_out (für Hinflüge) aus den möglichen Rückflügen ermitteln
	//
	l = flight_options_out.length;
	for(i=0;i<l;i++){
		if(flight_options_out[i]){
			for(j=0;j<flight_options_out[i].length;j++){
				//alert('j: '+j);
				ret_idx = flight_options_out[i][j];
				//alert('ret_idx: '+ret_idx);
				lr = flight_options_return[ret_idx].length;
				counter=0;
				related_flights_out[i] = new Array();
				for(k=0;k<lr;k++){
					//alert("rel_idx: "+flight_options_return[ret_idx][k]);
					related_flights_out[i][counter] = flight_options_return[ret_idx][k];
					counter++;
				}
			}
		}
	}

	// related_flights_return (für Rückflüge) aus den möglichen Hinflügen ermitteln
	//
	l = flight_options_return.length;
	for(i=0;i<l;i++){
		if(flight_options_return[i]){
			for(j=0;j<flight_options_return[i].length;j++){
				//alert('j: '+j);
				ret_idx = flight_options_return[i][j];
				//alert('j: '+j, 'ret_idx: '+ret_idx);
				lr = flight_options_out[ret_idx].length;
				counter=0;
				related_flights_return[i] = new Array();
				for(k=0;k<lr;k++){
					//alert("rel_idx: "+flight_options_return[ret_idx][k]);
					related_flights_return[i][counter] = flight_options_out[ret_idx][k];
					counter++;
				}
			}
		}
	}

	// Speichern der Zustandes 0 oder 1(=selected) pro Flugrichtung
	hin = new Array();
	rueck = new Array();

	// diese beiden Arrays mit Nullen initialisieren
	//
	for(i=0;i<flight_options_out.length;i++){
		// exisitiert Formularobject ?
		if(document.getElementById('hin_'+i)!="undefined"){
			hin[i] = 0;
		}
	}

	for(i=0;i<flight_options_return.length;i++){
		// exisitiert Formularobject ?
		if(document.getElementById('rueck_'+i)!="undefined"){
			rueck[i] = 0;
		}
	}
}


// Vorauswahl beim Reload der Flugauswahl Seite
//
function init_selection(hin_idx, rueck_idx){

	if(hin_idx>=0 && rueck_idx>=0){

		if (document.getElementById('liste_hin_'+hin_idx)) {
			hin_obj = document.getElementById('liste_hin_'+hin_idx);
			do_onmousedown(hin_obj, hin_idx);
		}

		if ( document.getElementById('liste_rueck_'+rueck_idx)) {
			rueck_obj = document.getElementById('liste_rueck_'+rueck_idx);
			do_onmousedown(rueck_obj, rueck_idx);
		}
	}
}


function resetEntry(obj, idx){

	if(!obj){
		return;
	}

	var attr_color;

	// ganze Zeile demarkieren
	//
	setEntryAttributes(obj, idx, marker_colors['unselected']);

	// Die Zelle mit dem Radiobutton markieren
	//
	if(obj.id.indexOf('hin')>0){
		if(hin[idx]==1){
		//	attr_color = marker_colors['selected'];
		//	highlightCell('hin_radio_'+idx, attr_color);

			// NOTE: new highlighting
			highlightCell('liste_hin_'+idx, marker_colors['font_selected']);
			if(eval('document.form1.hin_'+idx+'.checked') == true){
				setEntryAttributes(obj, idx, marker_colors['selected']);
			}
		}
	}

	if(obj.id.indexOf('rueck')>0){
		if(rueck[idx]==1){
		//	attr_color = marker_colors['selected'];
		//	highlightCell('rueck_radio_'+idx, attr_color);

			// NOTE: new highlighting
			highlightCell('liste_rueck_'+idx, marker_colors['font_selected']);

			if(eval('document.form1.rueck_'+idx+'.checked') == true){
				setEntryAttributes(obj, idx, marker_colors['selected']);
			}

		}
	}
	return true;
}


function setEntryAttributes(theRow, theRowNum, theColor){

	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if (!theRow) {

		return false;
	}

	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	}
	else {
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	// var currentColor = null;
	// var newColor     = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined'
		&& typeof(theCells[0].getAttribute) != 'undefined') {
		// currentColor = theCells[0].getAttribute('bgcolor');
		domDetect    = true;
	}
	// 3.2 ... with other browsers
	else {
		// currentColor = theCells[0].style.backgroundColor;
		domDetect    = false;
	} // end 3

	// 5. Sets the new color...
	if (theColor) {
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', theColor, 0);
			} // end for
		}
		// 5.2 ... with other browsers
		else {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = theColor;
			}
		}
	} // end 5

	return true;
} // end of the 'setPointer()' function




// Highlight einer einzelnen Zelle anhand der DOM-ID
//
function highlightCell(id, theColor){

//	theCell = document.getElementById(id);
//	theCell.setAttribute('bgcolor', color, 0);

	// NOTE: new highlighting
	if (!document.getElementById(id)) {
		return false;
	}

	theRow = document.getElementById(id);

	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	}
	else {
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;

	for (c = 0; c < rowCellsCnt; c++) {
		theCells[c].style.color = theColor;
	}
	//theCells[0].style.backgroundColor = '#000099';


	return true;
}



/////////////////////////////////////////////////////////////////////////////

// Hilfsfunktionen

/////////////////////////////////////////////////////////////////////////////


// Nachrüsten von "in_array" für Javascript
//
Array.prototype.contains = function (elem) {
	var i;
	for (i = 0; i < this.length; i++) {
		if (this[i] == elem) {
			return true;
		}
	}
	return false;
};
