function showtime() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

dateText = "";
dayValue = now.getDay();
if (dayValue == 0)
    dateText += "Sunday";
else if (dayValue == 1)
    dateText += "Monday";
else if (dayValue == 2)
    dateText += "Tuesday";
else if (dayValue == 3)
    dateText += "Wednesday";
else if (dayValue == 4)
    dateText += "Thursday";
else if (dayValue == 5)
    dateText += "Friday";
else if (dayValue == 6)
    dateText += "Saturday";

monthValue = now.getMonth();
dateText += ", "
if (monthValue == 0)
    dateText += "January";
if (monthValue == 1)
    dateText += "February";
if (monthValue == 2)
    dateText += "March";
if (monthValue == 3)
    dateText += "April";
if (monthValue == 4)
    dateText += "May";
if (monthValue == 5)
    dateText += "June";
if (monthValue == 6)
    dateText += "July";
if (monthValue == 7)
    dateText += "August";
if (monthValue == 8)
    dateText += "September";
if (monthValue == 9)
    dateText += "October";
if (monthValue == 10)
    dateText += "November";
if (monthValue == 11)
    dateText += "December";
	
dateValue = now.getDate();
dateText = dateText+" "+dateValue+", ";
yearValue = now.getYear();
if (yearValue < 1000)
yearValue+=1900

dateText = dateText+" "+yearValue;


//var timeValue = "" + ((hours >12) ? hours -12 :hours);
var timeValue = hours;
var timerID;
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
//timeValue += (hours >= 12) ? " P.M." : " A.M."
timeValue = dateText+" "+timeValue;
document.getElementById("time").innerHTML = timeValue;
timerID = setTimeout("showtime()",1000);
}

function appendOptionLast(id,valNames)
{
  var elSel = document.getElementById(id);
  if(typeof(valNames)=="undefined")
  {
	var elOptNew = document.createElement('OPTION');
	elOptNew.value = "";
	elOptNew.text = "No entry found";
	try {
		elSel.options.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
	catch(e) {
		elSel.options.add(elOptNew); // IE only
	}
	document.getElementById("submit").disabled=true;
  }
  else
  {
	  if(valNames.length > 0)
	  {
			var valNames = valNames.split("__");
			if(valNames.length > 0)
			{
				for(i in valNames)
				{
					var valName = valNames[i].split("_");
					var elOptNew = document.createElement('OPTION');
				    elOptNew.value = valName[0];
					elOptNew.text = valName[1];
					try {
						elSel.options.add(elOptNew, null); // standards compliant; doesn't work in IE
					}
					catch(e) {
						elSel.options.add(elOptNew); // IE only
					}
				}
			}
			else
				removeOptions(id);
	  }
	  else
		removeOptions(id);
		document.getElementById("submit").disabled=false;
  }
}

function removeOptions(id)
{
  var elSel = document.getElementById(id);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
      elSel.remove(i);
  }
}

function chngAirport(transport,rtrn)
{
	document.getElementById("submit").disabled=true;
	if(typeof(transport) == "undefined")
		return false;
	if((typeof(rtrn) != "undefined") && (rtrn=='rtrn'))
		var	rtrn = true;
	else
		var rtrn = false;
	xmlHttp = GetXmlHttpObject();
	
	if(!(xmlHttp) || (xmlHttp == null))
	{
	 alert('Ajax object not supported');
	 return false;
	}
	
	xmlHttp.onreadystatechange = function() { stateChanged("airport"); }
	var url = "ajxBookingBox.php?transportId="+transport;
	url += "&sid="+Math.random();
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	if(!rtrn)
		removeOptions("airport");
	else
		removeOptions("rtrnAirport");
	if(xmlHttp.responseText!="")
	{
		if(!rtrn)
		{
			appendOptionLast("airport",xmlHttp.responseText);
			var airportId=document.getElementById('airport').options[document.getElementById('airport').selectedIndex].value;
			chngStation(airportId);
		}
		else
		{
			appendOptionLast("rtrnAirport",xmlHttp.responseText);
			var airportId=document.getElementById('rtrnAirport').options[document.getElementById('rtrnAirport').selectedIndex].value;
			chngStation(airportId,"rtrn");
		}
	}
	else
	{
		if(!rtrn)
		{
			appendOptionLast("airport");
			appendOptionLast("station");
			appendOptionLast("persons");
		}
		else
		{
			appendOptionLast("rtrnAirport");
			appendOptionLast("rtrnStation");
			appendOptionLast("rtrnPersons");
		}
	}
}

function chngStation(airport,rtrn)
{
	document.getElementById("submit").disabled=true;
	if(typeof(airport) == "undefined")
		return false;
	if((typeof(rtrn) != "undefined") && (rtrn=='rtrn'))
		var	rtrn = true;
	else
		var rtrn = false;
	xmlHttp = GetXmlHttpObject();
	
	if(!(xmlHttp) || (xmlHttp == null))
	{
	 alert('Ajax object not supported');
	 return false;
	}
	
	xmlHttp.onreadystatechange = function() { stateChanged("station"); }
	var url = "ajxBookingBox.php?airportId="+airport;
	url += "&sid="+Math.random();
	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	if(rtrn)
		removeOptions("rtrnStation");
	else
		removeOptions("station");

	if(xmlHttp.responseText!="")
	{
		if(rtrn)
		{
			appendOptionLast("rtrnStation",xmlHttp.responseText);
			var stationId=document.getElementById('rtrnStation').options[document.getElementById('rtrnStation').selectedIndex].value;
			chngPersons(stationId,"rtrn");
		}
		else
		{
			appendOptionLast("station",xmlHttp.responseText);
			var stationId=document.getElementById('station').options[document.getElementById('station').selectedIndex].value;
			chngPersons(stationId);
		}
	}
	else
	{
		if(rtrn)
		{
			appendOptionLast("rtrnStation");
			appendOptionLast("rtrnPersons");
		}
		else
		{
			appendOptionLast("station");
			appendOptionLast("persons");
		}
	}
}

function chngPersons(station,rtrn)
{
	document.getElementById("submit").disabled=true;
	if(typeof(station) == "undefined")
		return false;
	if((typeof(rtrn) != "undefined") && (rtrn=='rtrn'))
		var	rtrn = true;
	else
		var rtrn = false;
	if(!rtrn)
		var airportId=document.getElementById('airport').options[document.getElementById('airport').selectedIndex].value;
	else
		var airportId=document.getElementById('rtrnAirport').options[document.getElementById('rtrnAirport').selectedIndex].value;
	xmlHttp = GetXmlHttpObject();
	
	if(!(xmlHttp) || (xmlHttp == null))
	{
	 alert('Ajax object not supported');
	 return false;
	}
	
	xmlHttp.onreadystatechange = function() { stateChanged("persons"); }
	var url = "ajxBookingBox.php?arprtId="+airportId+"&stationId="+station;
	url += "&sid="+Math.random();
	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	
	if(!rtrn)
		removeOptions("persons");
	else
		removeOptions("rtrnPersons");
	if(xmlHttp.responseText!="")
	{
		if(!rtrn)
		{
			appendOptionLast("persons",xmlHttp.responseText);
			var rates=document.getElementById('persons').options[document.getElementById('persons').selectedIndex].value;
			chngRate(rates);
		}
		else
		{
			appendOptionLast("rtrnPersons",xmlHttp.responseText);
			var rates=document.getElementById('rtrnPersons').options[document.getElementById('rtrnPersons').selectedIndex].value;
			chngRate(rates,"rtrn");
		}
	}
	else
	{
		if(!rtrn)
			appendOptionLast("persons");
		else
			appendOptionLast("rtrnPersons");
	}
}

function chngRate(rates,rtrn)
{
	if(typeof(rtrn) != "undefined")
		var	rtrn = true;
	else
		var rtrn = false;
	var rates = rates.split("#");
	var rateId = rates[0];
	var rate = rates[1];
	if((typeof(rateId) == "undefined") || isNaN(rateId) || rateId<1 ||(typeof(rate) == "undefined") || isNaN(rate) || rate<1)
		document.getElementById("submit").disabled=true;
	else
	{
		if(rtrn)
		{
			document.getElementById("returnRate").innerHTML=rate;
			document.getElementById("returnRateId").value=rateId;
		}
		else
		{
			document.getElementById("submit").disabled=false;
			document.getElementById("viewRate").innerHTML=rate;
			document.getElementById("submit").name=rateId;
		}
	}
}

function stateChanged(type)
{
 if(xmlHttp.readyState==3)
 {
	document.getElementById(type).innerHTML="<option>Loading...</option>";
	return false;
 }
 else if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
 {
  if(xmlHttp.responseText == "")
  {
	appendOptionLast(type);
  }
 }
}

function GetXmlHttpObject()
{
	var xmlHttp = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{
	 //Internet Explorer Newer Version
	 try
	 {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch(e)
	 {
		//Internet Explorer Older Version
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			return false;
		}
	 }
	}
	return xmlHttp;
}