/*********************************************************/
/*  Validierungsfunktion für die Startmaske STA GETS     */
/*********************************************************/
function init_page ()
{
	if (document.forms.startform.rdestt)
	{
		if(document.forms.startform.fromt[1]) {
			document.forms.startform.rdestt.value = document.forms.startform.fromt[1].value;
		}
	}
		
	change_flugart ();
	change_fromt ();
	
	for (i=0 ; i<document.forms.startform.carrt.length; i++)	
	{
		if (document.forms.startform.carrt.options[i].value == document.forms.startform.startcarrt.value)
		{
			document.forms.startform.carrt.selectedIndex = i;
			break;
		}
	}
//	change_backdate(7);
}

function startform_valid (theForm)
{
	if (theForm.flugart[2].checked) // Gabelflug
	{
		theForm.fromt[1].style.backgroundColor = "#ffffff";
		if (theForm.fromt[1].value == "")
		{
			theForm.fromt[1].style.backgroundColor = "#00ffff";
//			alert ("<xsl:value-of select="e:i18n('Bitte gib einen Abflugort an')"/>!");
			alert("\n"+msg[0]+"!");
			theForm.fromt[1].focus();
			return (false);
		}		

		theForm.destt[1].style.backgroundColor = "#ffffff";
		if (theForm.destt[1].value == "")
		{
			theForm.destt[1].style.backgroundColor = "#00ffff";
//		alert ("<xsl:value-of select="e:i18n('Bitte gib ein Reiseziel')"/>!");
			alert("\n"+msg[1]+"!");
			theForm.destt[1].focus();
			return (false);
		}
		theForm.rfromt.style.backgroundColor = "#ffffff";
		if (theForm.rfromt.value == "")
		{
			theForm.rfromt.style.backgroundColor = "#00ffff";
//			alert ("<xsl:value-of select="e:i18n('Bitte gib einen Abflugort an')"/>!");
			alert("\n"+msg[2]+"!");
			theForm.rfromt.focus();
			return (false);
		}
		theForm.rdestt.style.backgroundColor = "#ffffff";
		if (theForm.rdestt.value == "")
		{
			theForm.rdestt.style.backgroundColor = "#00ffff";
//			alert ("<xsl:value-of select="e:i18n('Bitte gib ein Reiseziel')"/>!");
			alert("\n"+msg[1]+"!");
			theForm.rdestt.focus();
			return (false);
		}
		theForm.fromt[0].value = "";		
		theForm.destt[0].value = "";				
	}
	else // Normalflug
	{
		if(theForm.fromt[0] && theForm.fromt[0].type == 'text') {
			theForm.fromt[0].style.backgroundColor = "#ffffff";
			if (theForm.fromt[0].value == "")
			{
				theForm.fromt[0].style.backgroundColor = "#00ffff";
	//			alert ("<xsl:value-of select="e:i18n('Bitte gib einen Abflugort an')"/>!");
				alert("\n"+msg[0]+"!");
				theForm.fromt[0].focus();
				return (false);
			}
		}	
		theForm.destt[0].style.backgroundColor = "#ffffff";
		if (theForm.destt[0].value == "")
		{
			theForm.destt[0].style.backgroundColor = "#00ffff";
//		alert ("<xsl:value-of select="e:i18n('Bitte gib ein Reiseziel')"/>!");
			alert("\n"+msg[1]+"!");
			theForm.destt[0].focus();
			return (false);
		}
		
			
		setItemValue(theForm.fromt[1], "");
		setItemValue(theForm.destt[1], "");
		setItemValue(theForm.rfromt, "");
		setItemValue(theForm.rdestt, "");
			
	}

//  und nun die Datumsbetrachtung

	hd1 = parseInt (parseFloat(theForm.hdate1.value));
	hd3 = parseInt (theForm.hdate2.value/100.);
	hd2 = parseInt (theForm.hdate2.value % 100.);
	hdat = hd3*10000 + hd2*100 + hd1;
		
	if (! teste_datum (hd1,hd2,hd3))
	{
//		alert ("<xsl:value-of select="e:i18n('Dieses Datum gibt es nicht')"/>!");
		alert("\n"+msg[3]+"!");
		theForm.hdate1.focus();
		return (false);
	}
		
	if (hdat < theForm.mindatum.value)
	{
//		alert ("<xsl:value-of select="e:i18n('Du kannst frühestens fliegen ab dem ')"/>"+" "+theForm.mindatumt.value);
		alert("\n"+msg[4]+" "+theForm.mindatumt.value);
		theForm.hdate1.focus();
		return (false);
	}

	if (! theForm.flugart[1].checked)
	{
		rd1 = parseInt (parseFloat(theForm.rdate1.value));
		rd3 = parseInt (theForm.rdate2.value/100.);
		rd2 = parseInt (theForm.rdate2.value % 100.);
		rdat = rd3*10000 + rd2*100 + rd1;

		if (rdat > theForm.maxdatum.value)
		{
//			alert ("<xsl:value-of select="e:i18n('Du kannst nicht später zurückreisen als der ')"/>"+" "+theForm.maxdatumt.value);
			alert("\n"+msg[5]+" "+theForm.maxdatumt.value);
			theForm.rdate1.focus();
			return (false);
		}
		if (! teste_datum (rd1,rd2,rd3))
		{
//			alert ("<xsl:value-of select="e:i18n('Dieses Datum gibt es nicht')"/>!");
			alert("\n"+msg[3]+"!");
			theForm.rdate1.focus();
			return (false);
		}

		if (rdat < hdat)
		{
//			alert ("<xsl:value-of select="e:i18n('Die Rückreise kann nur nach der Abreise erfolgen')"/>!");
			alert("\n"+msg[6]+"!");
			theForm.hdate1.focus();
			return (false);
		}
	}
	
	if (navigator.appName == 'Microsoft Internet Explorer') 
	{
		adult_zahl = parseInt (theForm.adult.value);
		youth_zahl = parseInt (theForm.youth.value);
		student_zahl = parseInt (theForm.student.value);
		child_zahl = parseInt (theForm.child.value);
		infant_zahl = parseInt (theForm.infant.value);
	}
	else
	{
		adult_zahl = parseInt (theForm.adult.options[theForm.adult.selectedIndex].value);
		youth_zahl = parseInt (theForm.youth.options[theForm.youth.selectedIndex].value);
		student_zahl = parseInt (theForm.student.options[theForm.student.selectedIndex].value);
		child_zahl = parseInt (theForm.child.options[theForm.child.selectedIndex].value);
		infant_zahl = parseInt (theForm.infant.options[theForm.infant.selectedIndex].value);
	}

	if (adult_zahl == 0 && youth_zahl == 0 && student_zahl == 0) 
	{
//		alert ("<xsl:value-of select="e:i18n('Du musst mindestens einen Erwachsenen oder einen Jugendlichen als Reiseteilnehmer wählen')"/>!");
		alert("\n"+msg[7]);
		theForm.adult.focus();	
		return (false);
	}
	if (adult_zahl != 0 && (youth_zahl != 0 || student_zahl != 0)) 
	{
//alert ("<xsl:value-of select="e:i18n('Du kannst nicht gleichzeitig Erwachsene und Jugendliche buchen, nimm die Buchung bitte in zwei separaten Buchungsvorgängen vor')"/>!");
		alert("\n"+msg[8]+"\n"+msg[14]);
		theForm.adult.focus();	
		return (false);
	}
	if (youth_zahl != 0 && student_zahl != 0) 
	{
//alert ("<xsl:value-of select="e:i18n('Du kannst nicht gleichzeitig Erwachsene und Jugendliche buchen, nimm die Buchung bitte in zwei separaten Buchungsvorgängen vor')"/>!");
		alert("\n"+msg[8]+"\n"+msg[14]);
		theForm.adult.focus();	
		return (false);
	}
	if (youth_zahl != 0 && (child_zahl+infant_zahl > 0)) 
	{
//alert ("<xsl:value-of select="e:i18n('Du kannst nicht gleichzeitig Jugendliche und Kinder buchen, nimm die Buchung bitte in zwei separaten Buchungsvorgängen vor')"/>!");
		alert("\n"+msg[9]+"\n"+msg[14]);
		theForm.adult.focus();	
		return (false);
	}
	if (student_zahl != 0 && (child_zahl+infant_zahl > 0)) 
	{
//alert ("<xsl:value-of select="e:i18n('Du kannst nicht gleichzeitig Studenten und Kinder buchen, nimm die Buchung bitte in zwei separaten Buchungsvorgängen vor')"/>!");
		alert("\n"+msg[10]+"\n"+msg[14]);
		theForm.adult.focus();	
		return (false);
	}
	
	return (true);
}
function change_fromt ()
{
	if (document.forms.startform.rdestt)
	{
		if(document.forms.startform.fromt[1]) {
			document.forms.startform.rdestt.value = document.forms.startform.fromt[1].value;
		}
	}
}
function change_rfromt ()
{
	if (document.forms.startform.rfromt)
	{
		document.forms.startform.rfromt.value = document.forms.startform.destt[1].value;
	}
}	
function change_flugart ()
{
// bei oneway-Flügen wird das Rückflugsdatum deaktiviert

	if (document.forms.startform.flugart[1].checked)   
	{
		
		document.forms.startform.rdate1.disabled = "true";
		document.forms.startform.rdate2.disabled = "true";
		document.forms.startform.rtime.disabled = "true";
		if (document.forms.startform.rfromt) document.forms.startform.rfromt.disabled = "true";
		if (document.forms.startform.rdestt) document.forms.startform.rdestt.disabled = "true";
		
		anzeigen ("Kalender", 0);
	}
	else
	{
		document.forms.startform.rdate1.disabled = 0;
		document.forms.startform.rdate2.disabled = 0;
		document.forms.startform.rtime.disabled = 0;
		if (document.forms.startform.rfromt) document.forms.startform.rfromt.disabled = 0;
		if (document.forms.startform.rdestt) document.forms.startform.rdestt.disabled = 0;

		anzeigen ("Kalender", 1);
	}

	if (document.forms.startform.flugart[2].checked) 
	{
		anzeigen ("Normalflug", 0);
		anzeigen ("Gabelflug", 1);	
	}
	else
	{
		anzeigen ("Normalflug", 1);
		anzeigen ("Gabelflug", 0);	
	}
}

function Kalender()
{
	posleft = 250;
	postop = 150;
	
	if (document.forms.startform.flugart[0].checked) ftype = document.forms.startform.flugart[0].value;
	if (document.forms.startform.flugart[1].checked) ftype = document.forms.startform.flugart[1].value;
	if (document.forms.startform.flugart[2].checked) ftype = document.forms.startform.flugart[2].value;

	href = document.forms.startform.cal_url.value + "&mode=14&direction=1" + "&unique_id=" + document.forms.startform.unique_id.value + "&flugart=" + ftype + "&hdate1=" + document.forms.startform.hdate1.value + "&hdate2=" + document.forms.startform.hdate2.value + "&rdate1=" + document.forms.startform.rdate1.value + "&rdate2=" + document.forms.startform.rdate2.value + "&mindatum=" + document.forms.startform.mindatum.value + "&maxdatum=" + document.forms.startform.maxdatum.value;

	neu = open (href,"","width=380,height=250,resizable=no,menubar=no,toolbar=no,status=no,scrollbars=no,left=" + posleft + ",top=" + postop);
}

function RegionOeffnen(typ) 
{
	href = document.forms.startform.cal_url.value + "&mode=10" + "&unique_id=" + document.forms.startform.unique_id.value + "&direction=" + String(typ);
	neu = open (href,"RegionFenster","width=600,height=350,resizable=1,toolbar=0,scrolling=yes,scrollbars=1,location=0");

	window.neu.focus(); 
} 


function change_backdate (offset)
{
//  Kunde wünscht, dass bei Auswahl des Hinflugdatums das Rückflugdatum automatisch
//  um <offset> Tage später vorgesetzt wird.

	htag = parseInt (parseFloat(document.startform.hdate1.value));
	hjahr = parseInt (document.startform.hdate2.value / 100.);
	hmonat = parseInt (document.startform.hdate2.value % 100.);
	
	rdate = calc_datum_diff (hjahr*10000+hmonat*100+htag,offset);

	rtag = parseInt (rdate % 100);
	rmon = parseInt (rdate / 100.);

	document.startform.rdate1.selectedIndex =  rtag-1; 
	for (i=0 ; i<document.startform.rdate2.length ; i++)
	{
		if (parseInt(parseFloat(document.startform.rdate2.options[i].value)) == rmon)
		{
			document.startform.rdate2.selectedIndex = i;
			break;
		}
	}		

	return (true);	
}

function setItemValue(item, value) {
	
	if(item && item.type == 'select-one') {
		item.options[item.options.selectedIndex].value = value;
	}
	else if(item) {
		item.value = value;
	}
	
	return (true);	

} 
