/////////////////////////////////////////////////
// save the form in the AutoComplete data store
function subForm(f)
{

	if (parent.ITPContent == null)
		return;

	if (f == "f1") {
		// f = parent.ITPContent.f1;
		f = parent.ITPContent.document.getElementById("f1");
	}
	else if (f == "f2") {
		// f = parent.ITPContent.f2;
		f = parent.ITPContent.document.getElementById("f2");
	}
	else {
		f = parent.ITPContent.document.forms[0];
	}


	//x=window.navigator.plugins.length;
	//alert(x);

	//if(window.external) window.external.AutoCompleteSaveForm(f);

	//version=0;
	//if (navigator.appVersion.indexOf("MSIE")!=-1) {
	//	temp=navigator.appVersion.split("MSIE");
	//	version = parseFloat(temp[1]);
	//}

	//if (version>=5) {
	//	window.external.AutoCompleteSaveForm(f);
	//}

	f.submit();
}
////////////////////////////////////////////////
// submit when enter key
function checkReturnKey(f)
{
	if (window.event && window.event.keyCode==13)
	{
		if(document.forms[0].execInst && document.forms[0].nameState_destination && !(document.forms[0].nameState_origin.value!='identified' || document.forms[0].nameState_destination.value!='identified'))
			document.forms[0].execInst.value='normal';
		preSubmit();
		subForm(f);
	}
	return true;
}

////////////////////////////////////////////////
// train and S-Bahn must have the same value
// set included means for pp options
function preSubmit()
{
	if (document.forms[0].execInst && document.forms[0].nameState_destination && !(document.forms[0].nameState_origin.value!='identified' || document.forms[0].nameState_destination.value!='identified'))
		document.forms[0].execInst.value = 'normal';

	// invert mot for PP
	if (document.forms[0].MOT_0_exclude && document.forms[0].MOT_2_exclude && document.forms[0].MOT_4_exclude && document.forms[0].MOT_5_exclude && document.forms[0].MOT_6_exclude && document.forms[0].MOT_10_exclude) 
		invertMOT();
	else {	
		if (document.forms[0].exclMOT_0)
		{
			if (document.forms[0].exclMOT_0.checked == true)
			{
				document.forms[0].SBahn.value=1;
				document.forms[0].SBahn.name = 'exclMOT_1';
			}
		}
		if (document.forms[0].inclMOT_0)
		{
			if (document.forms[0].inclMOT_0.checked == true)
			{
				document.forms[0].SBahn.value=1;
				document.forms[0].SBahn.name = 'inclMOT_1';
			}
		}
	}
}


////////////////////////////////////////////////
// inverts the mot of personal options to 
// provide exclusion of mot instead of inclusion
function invertMOT () 
{
	if (!document.forms[0].MOT_0_exclude.checked && document.forms[0].inclMOT_0_inactive && document.forms[0].inclMOT_1_inactive) {
		document.forms[0].inclMOT_0_inactive.name = 'inclMOT_0';
		document.forms[0].inclMOT_1_inactive.name = 'inclMOT_1';
	}
	if (!document.forms[0].MOT_2_exclude.checked && document.forms[0].inclMOT_2_inactive) 
		document.forms[0].inclMOT_2_inactive.name = 'inclMOT_2';
	if (!document.forms[0].MOT_4_exclude.checked && document.forms[0].inclMOT_4_inactive) 
		document.forms[0].inclMOT_4_inactive.name = 'inclMOT_4';
	if (!document.forms[0].MOT_5_exclude.checked && document.forms[0].inclMOT_5_inactive) 
		document.forms[0].inclMOT_5_inactive.name = 'inclMOT_5';
	if (!document.forms[0].MOT_6_exclude.checked && document.forms[0].inclMOT_6_inactive) 
		document.forms[0].inclMOT_6_inactive.name = 'inclMOT_6';
	if (!document.forms[0].MOT_10_exclude.checked && document.forms[0].inclMOT_10_inactive) 
		document.forms[0].inclMOT_10_inactive.name = 'inclMOT_10';
}


///////////////////////////////////////////////
// button up and down from date
function dateUpDown(upOrDown)
{
	var tag;
	var monat;
        var jahr;

        tag = document.forms[0].itdDateDay.value;
        monat = document.forms[0].itdDateMonth.value;
        jahr = document.forms[0].itdDateYear.value;

		//  because of bug in all browsers except opera (see http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604)
		if (jahr.substr(0,1) == '0') {
			jahr = jahr.substr(1,1);
		}
		var jahrIntWert = parseInt(jahr);

        if (jahrIntWert >= 0 && jahrIntWert <= 75)
        { jahrIntWert = 2000 + jahrIntWert; }
        else
        {
            if (jahrIntWert > 75 && jahrIntWert <= 99)
            { jahrIntWert = 1900 + jahrIntWert; }
        }

        monat = monat - 1;

        heute = new Date(jahrIntWert, monat, tag);
        var millisecunden = heute.getTime();

        if (upOrDown == 'up')
        { millisecunden = millisecunden + (24*60*60*1000); }

        if (upOrDown == 'down' )
        { millisecunden = millisecunden - (24*60*60*1000); }

        heute.setTime(millisecunden);

        tag = heute.getDate();
        if (tag > 0 && tag < 10)
        { tag = "0"+tag; }

        monat = heute.getMonth() + 1;
        if (monat > 0 && monat < 10)
        { monat = "0"+monat; }

        jahr = ""+heute.getFullYear();
        jahr = jahr.substr(2,2);

        document.forms[0].itdDateDay.value = tag;
        document.forms[0].itdDateMonth.value = monat;
        document.forms[0].itdDateYear.value = jahr;
}

////////////////////////////////////////////////
// return formated time
function showtime1( hour, minute )
{
	if (hour < 10) {
		hour = "0" + hour;
	}
	else {
		hour = hour;
	}
	if (minute < 10) {
		minute = "0" + minute;
	}
	else {
		minute = minute;
	}

	document.forms[0].itdTimeHour.value = hour;
	document.forms[0].itdTimeMinute.value = minute;

}

////////////////////////////////////////////////
// return formated date
function showdate1( year, month, date )
{
	if (date < 10){
		date = "0" + date;
	}
	else {
		date = date;
	}
	if (month < 10){
		month = "0" + month;
	}
	else {
		month = month;
	}

	if (year < 10){
		year = "0" + year;
	}
	else {
		year = "" + year;
		year = year.substr(2,2);
	}

	document.forms[0].itdDateYear.value = year;
	document.forms[0].itdDateMonth.value = month;
	document.forms[0].itdDateDay.value = date;
}

/////////////////////////////////////////////////////////////////////////////////////////
// close Java Applet and open XSLT Map
function openXSLTMapFormJavaApplet()
{
	if (window.opener)
	{
		window.opener.document.forms[0].itdLPxx_java.value='0';
		window.opener.document.forms[0].command.value="mapRequest_" + window.opener.odvMapRequest.mapUsage ;
		window.opener.document.forms[0].submit();
	}
	window.close()
}


/////////////////////////////////////////////////////////////////////////////////////////
// for TTB the map opens in form 1, not in form 0
function openTTBMap () {
	if(!document.forms[1]) {
		document.forms[0].itdLPxx_openMap.value='true';
		document.forms[0].itdLPxx_mdvMap_ttb.value='5604318:817669:TEL5';
		document.forms[0].execInst.value='verifyOnly';
		document.forms[0].submit();
	}
	else {
		document.forms[1].itdLPxx_openMap.value='true';
		document.forms[1].itdLPxx_mdvMap_ttb.value='5604318:817669:TEL5';
		document.forms[1].execInst.value='verifyOnly';
		document.forms[1].submit();
	}
}

function closeTTBMap() {
	if(!document.forms[1]) {
		document.forms[0].itdLPxx_mdvMap_ttb.value='';
		document.forms[0].execInst.value='verifyOnly';
		document.forms[0].submit();
	}
	else {
		document.forms[1].itdLPxx_mdvMap_ttb.value='';
		document.forms[1].execInst.value='verifyOnly';
		document.forms[1].submit();
	}
}


///////////////////////////////////////////////////////////////////////
// This function toggles the optimised walking.
function toggleOptimisedWalking(active) {
	if (document.getElementById('useProxFootSearch')) {
		if (active)
			document.getElementById('useProxFootSearch').value = '1';
		else
			document.getElementById('useProxFootSearch').value = '0';
	}
}