function checkEmailForm()
{
	var mail = document.forms['tripRequest'].addEmailAddress.value;
	var expression = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{1,}\.){0,}[a-zA-Z0-9-]{3,}(\.[a-zA-Z]{2,4}){1,2}$/;
	if(!expression.exec(mail))
	{
		alert('Please enter a valid e-mail address');
	}
	else if(document.forms['tripRequest'].itdMPxx_Feedback.value.length < 1)
	{
		alert('Please enter your feedback');
	}	
	else
	{
		document.forms['tripRequest'].submit();
	}
}

function checkDepArr(obj)
{
	depObj = document.getElementById('deparr_dep');
	arrObj = document.getElementById('deparr_arr');
	if (depObj && arrObj && obj)
	{
		if (obj.value=='dep')
		{
			arrObj.style.display = 'none';
			depObj.style.display = 'inline';
		}
		else
		{
			arrObj.style.display = 'inline';
			depObj.style.display = 'none';
		}
	}
}

function checkReturnKey(event)
{
	if(window.event)
	{
		if (window.event.keyCode==13)
		{
			if(document.forms['tripRequest'])
				document.forms['tripRequest'].submit();
			else if(document.forms[1])
				document.forms[1].submit();
		}
		else
		{
			window.event.returnValue=true;
		}
	}
	else if(event)
	{
		if (event.keyCode==13)
		{
			if(document.forms['tripRequest'])
				document.forms['tripRequest'].submit();
			else if(document.forms[1])
				document.forms[1].submit();
		}
	}
}

function JPFocus()
{
	nameState_origin = document.getElementById('nameState_origin');
	nameState_destination = document.getElementById('nameState_destination');
	
	name_origin = document.getElementById('name_origin');
	name_destination = document.getElementById('name_destination');
	
	// Give focus to origin input field by default.
	if (name_origin && nameState_origin && nameState_origin.value != 'identified')
	{
		name_origin.focus();
	}
	
	else if (name_destination && nameState_destination && nameState_destination.value != 'identified')
	{
		name_destination.focus();
	}

}

window.onload = JPFocus;


/* Date and time for the website template */

function getDateTime()
{
	var today = new Date();
	var day = today.getDay();
	var month = today.getMonth();
	var date = today.getDate();
	var year = today.getFullYear();
	var hours = today.getHours();
	var minutes = today.getMinutes();
	var AM_PM;
	
	if(hours < 12) 
		AM_PM = "am";
	else {
		AM_PM = "pm";
		hours -= 12;
	}
	if (hours == 0)
			hours = 12;
	
	return dayString[day] + " " + monthString[month] + " " + date + " " + year + " " + hours + ":" + format(minutes) + " " + AM_PM;
}

function format(z) {
	return (z<10)?"0"+z:z;
}


