
if (typeof String.prototype.trim != 'function')
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

/* submit the form */
function submitEFAForm(){

	var form = document.forms[0];

	if($('type_rop') || $('type_ttb')){
		form = document.forms[1];
	}

	form.submit();

}

    
function checkLineSelection(){

	if (document.forms[0].dmLineSelection) {
		document.forms[0].dmLineSelectionAll.value = 0;
	}
	if (document.forms[0].dmLineSelection && document.forms[0].dmLineSelection.value == 'all') {
		document.forms[0].dmLineSelectionAll.value = 1;
	}
	
	if (document.forms[0].lineSelIndex && document.forms[0].lineSelIndex.value == 'all') {
		document.forms[0].ppLineSelectionAll.value = 1;
	}
	
	document.forms[0].submit();
};


function checkSelectWidth(id){

	var width = document.getElementById(id).offsetWidth;
						
	if (width <= 596){
		document.getElementById(id).parentNode.style.overflowX='hidden';
		document.getElementById(id).style.width='596px';
	}
};

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;
	var jahrIntWert = jahr;


	if (jahrIntWert >= 0 && jahrIntWert <= 75){ 
		jahrIntWert = 20 + jahrIntWert; 
	}
	else{
	    if (jahrIntWert > 75 && jahrIntWert <= 99){ 
	    	jahrIntWert = 19 + parseInt(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;

};

function messagePlaceEmpty(errorMessage)
{
	alert(errorMessage);
	return false;
};


function getStringLengthOfPlace(usage){
	if(document.getElementsByName("place_" + usage)[0]){
	var placeValue = document.getElementsByName("place_" + usage)[0].value;
	var placeValueLength = placeValue.length;

	return placeValueLength;
	}
};

function callCheckPlaceOfOdv(errorMessage){
	var originPlaceStringLength = getStringLengthOfPlace("origin");
	var destinationPlaceStringLength = getStringLengthOfPlace("destination");
	
	var stateOrigin = document.forms[0].placeState_origin.value;
	var stateDestination = document.forms[0].placeState_destination.value;

	if (!(originPlaceStringLength > 0) && stateOrigin!='list' && stateOrigin!='identified' && stateDestination!='list' && stateDestination!='identified')
	{
		messagePlaceEmpty(errorMessage);
	}

	else if (!(destinationPlaceStringLength > 0) && stateOrigin!='list' && stateOrigin!='identified' && stateDestination!='list' && stateDestination!='identified')
	{
		messagePlaceEmpty(errorMessage);
	}
	else{
		document.forms[0].submit();
	}
};


function checkNotify(){			

	if(document.forms[0].notifyViaSMS.checked && document.forms[0].notifyViaEMail.checked){
		document.forms[0].notificationType.value=6;
		document.forms[0].notifyViaSMS.value='SMS';
		document.forms[0].notifyViaEMail.value='EMail';
	}

	else if(document.forms[0].notifyViaSMS.checked){
		document.forms[0].notificationType.value=4;
		document.forms[0].notifyViaSMS.value='SMS';
	}

	else if(document.forms[0].notifyViaEMail.checked){
		document.forms[0].notificationType.value=2;
		document.forms[0].notifyViaEMail.value='EMail';
	}
	else{
		document.forms[0].notificationType.value=0;
	}

};


function checkReturnKey(e)
{	
	var keyCode = 0;	
	if(window.event) keyCode = window.event.keyCode;
	else keyCode = e.keyCode;	
	
	 if ((window.event || e) && keyCode==13)
	{		
		document.forms[0].submit();		
	}

} 

function displayRequiredInputHint(style){

	if(document.getElementById('requiredInputField'))document.getElementById('requiredInputField').style.display=style;

	if(document.getElementById('requiredInputField2'))document.getElementById('requiredInputField2').style.display=style;
}

function displaySelectedLine(mapType, request){

	var coord= document.getElementById('coord').value;

	document.getElementById('mapsDiv').style.display='';
	
	onLoadMapHandler(mapType , 'rop');

	document.getElementById('submitLines').style.display='none';
	document.getElementById('overviewBox').style.display='none';
	
	document.getElementById('mapHeader').style.display='none';
	document.getElementById('printButton').style.display='';
	
	document.getElementById('newMapHeader').innerHTML='Verlauf der Linie ' + document.forms[0].lineSelIndexBox.options[document.forms[0].lineSelIndexBox.selectedIndex].innerHTML;
	
	
	mdvJpMaps[mapType +':rop'].mapIt(this.id, 3, document.forms[0].lineSelIndexBox.value.split('_')[0], coord);

	document.getElementById('lineSelection').style.display='none';
}

// this function select or deselect the noElevationSummary in subject to noElevationProfile
function checkElevationSummary(obj){

	if(obj.checked== true && obj.id=='formSettingsNoHills2'){
		document.forms[0].noElevationSummary.value= 1;
	}
	else{
		document.forms[0].noElevationSummary.value= 0;
	}
}

// function to set the date to next monday
function setDateToMonday(){

	if(document.forms[0].itdDate){
		var mydate = new Date();
		var nextDate = '';				

		nextDate = new Date(mydate.getFullYear(),mydate.getMonth(),mydate.getDate()+(8-mydate.getDay()));				
		document.forms[0].itdDate.value = nextDate.getFullYear() + formatdate(nextDate.getMonth() + 1) + formatdate(nextDate.getDate());
	}
}

// this function format the date
function formatdate(value)
{
	var myval = new String(value);

	if(myval.length < 2) myval = "0" + myval;
	return myval;
};

//this function check the content of the feedback fields 
function checkFeedback(){

	var errBox = document.getElementById('feedbackError');
	var message = '';
	var mailAdd = document.getElementById('addEmailAddress').value.trim();
	var expr = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{1,}\.){0,}[a-zA-Z0-9-]{2,}(\.[a-zA-Z]{2,4}){1,2}$/;
	
	if(document.getElementById('itdMPxx_Feedback').value.trim()==''){
		message += 'Bitte geben Sie eine Meldung ein.<br/>'
	}
	
	if(!expr.exec(mailAdd)){
		message += 'Bitte geben Sie eine korrekte E-Mail Adresse ein.<br/>'
	}
	
	if(message!=''){
		errBox.style.display=''; 
		errBox.innerHTML = message;
		return false
	}
	else{
		errBox.style.display='none'; 
		errBox.innerHTML ='';
		document.forms[0].submit()
	}
}


function resizeMap(maptype){

	var mh = $("mdvMap_" +maptype).getSize().y;
	var myh=(mh > 300)?264:560;
	
	$("mdvMap_" +maptype).set('tween',{duration: 500, transition: Fx.Transitions.linear}).tween('height', myh+"px");
	
	var time=(mh > 300)?500:100;
	
	window.setTimeout(
	function(){
		if(mdvJpMaps['tube:'+ maptype]){
			mdvJpMaps['tube:'+ maptype].setViewport(myh);
		}
		else if(mdvJpMaps['aerial:'+ maptype]){
			mdvJpMaps['aerial:'+ maptype].setViewport(myh);
		}
		else if(mdvJpMaps['city:'+ maptype]){
			mdvJpMaps['city:'+ maptype].setViewport(myh);
		}
		else{
			mdvJpMaps['navteq:'+ maptype].setViewport(myh);
		}
	},time)
}


function tmi(obj) //toggles map image
{
	obj.src=(obj.src.test("icon.arrow.up.gif"))?obj.src.replace(/icon.arrow.up.gif/, "icon.arrow.down.gif"):obj.src.replace(/icon.arrow.down.gif/, "icon.arrow.up.gif");
}

function checkPhoneNum(){

	var phoneNum = $('formRegisterNotifySMSNr').value;

	if(phoneNum==''){
		$('errorPhoneNum').style.display='none';
		return true;
	}
	else if(isNaN(phoneNum) || phoneNum.substring(0,1) ==0 || phoneNum.length < 5 || phoneNum.length > 14){
		$('errorPhoneNum').style.display='';
		
		if($('oMsg')){
			$('oMsg').style.display='none';
		}
		return false;
	}
	else{
		$('errorPhoneNum').style.display='none';
		return true;
	}
}