var browserIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;

var xmlhttp
var xmlDoc
var showDetailedJourney
var selectedJno

// **************************************************
function loadTemplateReqXml_func(url){ //Load request xml template
	window.status = "LOADING..";
	if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onload = initTemplateReqXml_func
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	} else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		xmlhttp.onreadystatechange=initTemplateReqXml_func
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
}

function initTemplateReqXml_func(){
	if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onreadystatechange=buildReqXML_func;
		xmlDoc.loadXML(xmlhttp.responseText);
	} else if (window.ActiveXObject) { // code for IEx
		if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.onreadystatechange=buildReqXML_func;
			xmlDoc.loadXML(xmlhttp.responseText);
		}
	}	
}

function buildReqXML_func(){
	if (xmlDoc.readyState==4){
		mainXMLObj = xmlDoc.getElementsByTagName('JourneysRequest');
		noChilds = mainXMLObj[0].childNodes.length; // Only 1 tag called 'JourneysRequest'
		for(i=0;i<noChilds;i++){
			if (mainXMLObj[0].childNodes[i].nodeName == "Origin" || mainXMLObj[0].childNodes[i].nodeName == "Destination"){
				x = mainXMLObj[0].childNodes[i].getElementsByTagName('Easting');
				y = mainXMLObj[0].childNodes[i].getElementsByTagName('Northing');
				givenName = mainXMLObj[0].childNodes[i].getElementsByTagName('GivenName');
				JourneyTime = mainXMLObj[0].childNodes[i].getElementsByTagName('JourneyTime');
				if (mainXMLObj[0].childNodes[i].nodeName == "Destination"){
					x[0].firstChild.nodeValue = Math.round(destx);
					y[0].firstChild.nodeValue = Math.round(desty);
					givenName[0].firstChild.nodeValue = destName;
					JourneyTime[0].firstChild.nodeValue = journeyTime;
				} else if (mainXMLObj[0].childNodes[i].nodeName == "Origin"){
					x[0].firstChild.nodeValue = Math.round(originx);
					y[0].firstChild.nodeValue = Math.round(originy);
					givenName[0].firstChild.nodeValue = originName;
					JourneyTime[0].firstChild.nodeValue = journeyTime;
				}
			}

		}
		arrdepXMLObj = xmlDoc.getElementsByTagName('ArrDep');
		arrdepXMLObj[0].firstChild.nodeValue = deparr;
		document.getElementById('xmlrequest').value = xmlDoc.xml;
		//document.forms['xmlrequest'].value = xmlDoc.xml;
		document.forms[0].action="results.asp";
		document.forms[0].method="post";
		document.forms[0].submit();
		window.status = "SENDING...";
	}	
}
// **************************************************

// **************************************************
function loadResponseXml_func(url){ //Load xml doc
	window.status = "LOADING..";
	if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onload = initResponseXml_func
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	} else if (window.ActiveXObject) { // code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		xmlhttp.onreadystatechange=initResponseXml_func
		xmlhttp.open("GET",url,true);
		xmlhttp.send();
	}
}

function initResponseXml_func(){
	if (window.XMLHttpRequest){// code for Mozilla, etc.
		xmlDoc = document.implementation.createDocument("", "", null);
		if (showDetailedJourney==1){xmlDoc.onreadystatechange=viewJdetails_func} else {xmlDoc.onreadystatechange=journeyResults_func};
		xmlDoc.loadXML(xmlhttp.responseText);
	} else if (window.ActiveXObject) { // code for IEx
		if (xmlhttp.readyState==4){// if xmlhttp shows "loaded"			
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");			
			if (showDetailedJourney==1){xmlDoc.onreadystatechange=viewJdetails_func} else {xmlDoc.onreadystatechange=journeyResults_func};			
			xmlDoc.loadXML(xmlhttp.responseText);
			window.status="";
		}
	}	
}
// **************************************************



// **************************************************

function journeyResults_func(){	
	if (xmlDoc.readyState==4){
		if (document.getElementById('jplanresults').childNodes[0]){//If table already exists in the div object labelled "jplanresults" then remove it
			tabObj = document.getElementById('jplanresults').childNodes[0];
			document.getElementById('jplanresults').removeChild(tabObj);
		}
		var showresults=1;
		msg = "error"
		journeysXMLObj = xmlDoc.getElementsByTagName('Journey');
		noJs = journeysXMLObj.length;		
		if (noJs < 1){
			if (xmlDoc.getElementsByTagName('Message').length > 0){
				msg = xmlDoc.getElementsByTagName('Message')[0].firstChild.nodeValue;
			}		
			var container = document.createElement('SPAN');
			container.setAttribute('className','warning');
			if (browserIE){container.setAttribute('className','warning')} else {container.setAttribute('class','warning')}
			cellData = document.createTextNode(msg);
			container.appendChild(cellData);
			document.getElementById('errors').appendChild(container);
		} else {		
			var newEl = document.createElement('TABLE');
			newEl.setAttribute('cellPadding',2);
			newEl.setAttribute('cellSpacing',0);
			newEl.setAttribute('width',700);
			newEl.setAttribute('ID','tabjpresults');
			var body = document.createElement('TBODY'); // IE requires that TBODY be added otherwise table will not work
			newEl.appendChild(body);

			var row = document.createElement('TR');
			row.setAttribute('className','trhead');
			if (browserIE){row.setAttribute('className','trhead')} else {row.setAttribute('class','trhead')}

			var container = document.createElement('TD');
			cellData = document.createTextNode("Route:");
			container.appendChild(cellData);
			row.appendChild(container);

			var container = document.createElement('TD');
			cellData = document.createTextNode("Depart:");
			container.appendChild(cellData);
			row.appendChild(container);

			var container = document.createElement('TD');
			cellData = document.createTextNode("Arrive:");
			container.appendChild(cellData);
			row.appendChild(container);

			var container = document.createElement('TD');
			cellData = document.createTextNode("Duration:");
			container.appendChild(cellData);
			row.appendChild(container);

			var container = document.createElement('TD');
			cellData = document.createTextNode("Interchanges:");
			container.appendChild(cellData);
			row.appendChild(container);

			var container = document.createElement('TD');
			row.appendChild(container);		

			body.appendChild(row);

			if (noJs > 5){
				noJs = 5;//Limit journey results
			}
			buscount=0;	
			for (j=0;j<noJs;j++){
				legsXMLObj = journeysXMLObj[j].childNodes;
				noLegs = legsXMLObj.length;		

				var row = document.createElement('TR');
				row.setAttribute('bgColor','#FEF2F3');
				var container = document.createElement('TD');
				container.setAttribute('align','center');

				var boldobj = document.createElement('B');
				cellData = document.createTextNode((j+1));
				boldobj.appendChild(cellData);
				container.appendChild(boldobj);

				row.appendChild(container);

				busCoords = ""

				durationVal = "";
				lastAlightTime = "";
				gotFirstWalk=0;
				gotFirstBus=0;
				startTime=""
				firstBusStartTime = journeyArrDepTime;
				firstWalkDuration = 0;
				endTime = 0;
				for (l=0;l<noLegs;l++){					
					if (legsXMLObj[l].childNodes.length > 0){
						if (legsXMLObj[l].childNodes[0].attributes != null){
							mode = legsXMLObj[l].childNodes[0].attributes[0].value;
						} else if (legsXMLObj[l].childNodes[1].attributes != null){
							mode = legsXMLObj[l].childNodes[1].attributes[0].value;
						} else {
							mode = "none"
						}
						xmlLegBoard = legsXMLObj[l].getElementsByTagName('LegBoard');
						xmlLegAlight = legsXMLObj[l].getElementsByTagName('LegAlight');												
					} else {
						mode = "none";
					}
					if (mode.toLowerCase() == "bus"){
						startTimeArr = (xmlLegBoard[0].getElementsByTagName('TimetabledTime').length > 0)?xmlLegBoard[0].getElementsByTagName('TimetabledTime'):xmlLegBoard[0].getElementsByTagName('TimetabledDepartureTime');
						startTime = startTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);

						if (gotFirstBus == 0){
							firstBusStartTime = startTime;
							gotFirstBus=1;
						} else {
							startTime = endTime;
						}

						endTimeArr = (xmlLegAlight[0].getElementsByTagName('TimetabledTime').length > 0)?xmlLegAlight[0].getElementsByTagName('TimetabledTime'):xmlLegAlight[0].getElementsByTagName('TimetabledArrivalTime');
						endTime = endTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);

						legDuration = minusTimes_func(endTime, startTime);
						ServiceNo = (legsXMLObj[l].getElementsByTagName('ServiceNumber').length > 0)?legsXMLObj[l].getElementsByTagName('ServiceNumber')[0].firstChild.nodeValue:"na";				
						OperatorName = legsXMLObj[l].getElementsByTagName('OperatorName')[0].firstChild.nodeValue;
						AlightName = xmlLegAlight[0].getElementsByTagName('Name')[0].firstChild.nodeValue;

						ServiceDestination = (legsXMLObj[l].getElementsByTagName('ServiceDestination').length > 0)?legsXMLObj[l].getElementsByTagName('ServiceDestination')[0].getElementsByTagName('Name'):"";
						ServiceDestinationName = (ServiceDestination.length > 0)?ServiceDestination[0].firstChild.nodeValue:"";

						BoardInterchangeTime = (xmlLegBoard[0].getElementsByTagName('InterchangeTime').length > 0)?xmlLegBoard[0].getElementsByTagName('InterchangeTime')[0].firstChild.nodeValue:"";
						AlightInterchangeTime = (xmlLegAlight[0].getElementsByTagName('InterchangeTime').length > 0)?xmlLegAlight[0].getElementsByTagName('InterchangeTime')[0].firstChild.nodeValue:"";

					} else if (mode.toLowerCase() == "walk"){				
						legDuration = (legsXMLObj[l].getElementsByTagName('TypicalDuration').length > 0)?formatDuration_func(legsXMLObj[l].getElementsByTagName('TypicalDuration')[0].firstChild.nodeValue):"";				
						if (gotFirstWalk == 0){
							//startTime = minusTimes_func(startTime, legDuration);
							//firstWalkTime = startTime;
							firstWalkDuration = legDuration;
							gotFirstWalk=1;
						} else {
							startTime = endTime;
						}
						endTime = addTimes_func(startTime, legDuration);				
					}
				}

				var container = document.createElement('TD');
				cellData = document.createTextNode(minusTimes_func(firstBusStartTime, firstWalkDuration));
				container.appendChild(cellData);
				row.appendChild(container);

				var container = document.createElement('TD');
				cellData = document.createTextNode(endTime);
				container.appendChild(cellData);
				row.appendChild(container);

				var container = document.createElement('TD');
				d1 = lastAlightTime.replace(":00","");
				d2 = startTime;
				dt1 = new Date("January 1, 2000 "+endTime);
				dt2 = new Date("January 1, 2000 "+startTime);
				dt1.setTime(dt1-dt2)		
				cellData = document.createTextNode(timesAddZero_func(dt1.getHours())+":"+timesAddZero_func(dt1.getMinutes()));
				cellData = document.createTextNode(minusTimes_func(endTime,(minusTimes_func(firstBusStartTime, firstWalkDuration))));
				container.appendChild(cellData);
				row.appendChild(container);

				var container = document.createElement('TD');

				for (l=0;l<noLegs;l++){					
					if (legsXMLObj[l].childNodes.length > 0){
						if (legsXMLObj[l].childNodes[0].attributes != null){
							mode = legsXMLObj[l].childNodes[0].attributes[0].value;
						} else if (legsXMLObj[l].childNodes[1].attributes != null){
							mode = legsXMLObj[l].childNodes[1].attributes[0].value;
						} else {
							mode = "none"
						}
					} else {
						mode = "none";
					}					
					if (mode == "bus"){
						buscount++;
					}
					if (mode != "none"){
						var icon = document.createElement('IMG');
						icon.setAttribute('src',getMode_func(mode));
						icon.setAttribute('border',0);
						icon.setAttribute('alt',mode);
						container.appendChild(icon);			
					}
				}
				row.appendChild(container);
				var container = document.createElement('TD');

				var anchor = document.createElement('A');
				anchor.setAttribute('href','javascript:gotoJourney_func('+j+')');
				//anchor.setAttribute('onClick','viewJdetails_func('+j+')');
				cellData = document.createTextNode("> details");
				anchor.appendChild(cellData);
				container.appendChild(anchor);			

				row.appendChild(container);

				body.appendChild(row);			
			}	
			document.getElementById('jplanresults').appendChild(newEl);			
		}
	}
}


function formatDuration_func(duration){
	durArr = duration.substr(2,20).split("H");
	h = durArr[0];
	m = durArr[1].replace("M", "");
	return h+":"+m;
}

function addTimes_func(time1, time2){ // Times are in format xx:xx e.g: 00:12 is 12 minutes
	dt1 = new Date("January 1, 2000 "+time1);
	dt2 = new Date("January 1, 2000 "+time2);
	dt1.setTime(dt1.getTime()+dt2.getTime());
	return timesAddZero_func(dt1.getHours())+":"+timesAddZero_func(dt1.getMinutes());
}

function minusTimes_func(time1, time2){ // Times are in format xx:xx e.g: 00:12 is 12 minutes
	dt1 = new Date("January 1, 2000 "+time1);
	dt2 = new Date("January 1, 2000 "+time2);
	dt1.setTime(dt1.getTime()-dt2.getTime());
	return timesAddZero_func(dt1.getHours())+":"+timesAddZero_func(dt1.getMinutes());
}

function timesAddZero_func(no){
	if (String(no).length < 2){
		return "0"+no;
	} else {
		return no;
	}
}

function getMode_func(mode){
	imgsrc = ""
	if (mode == "walk"){
		imgsrc="images/icon-walk.gif";
	} else if (mode == "bus"){
		imgsrc="images/icon-buses.gif";
	} else if (mode == "rail"){
		imgsrc="images/icon-rail.gif";
	}
	return imgsrc;
}


function gotoJourney_func(jno){
	document.forms[0].jno.value=jno;
	document.forms[0].action="resultview.asp";
	document.forms[0].method="post";
	document.forms[0].submit();
	//location.href = "resultview.asp?jno="+jno;
}





function viewJdetails_func(jno){
	if (xmlDoc.readyState==4){
		//alert("jno="+jno);
		if (document.getElementById('jplanresults').childNodes[0]){
			tabObj = document.getElementById('jplanresults').childNodes[0];
			document.getElementById('jplanresults').removeChild(tabObj);
		}

		selectedJData = ""

		if (!jno){
			jno = selectedJno;
		}

		var newEl = document.createElement('TABLE');
		newEl.setAttribute('cellPadding',2);
		newEl.setAttribute('cellSpacing',0);
		newEl.setAttribute('border',0);
		newEl.setAttribute('width',700);
		newEl.setAttribute('ID','tabjpdetails');
		var body = document.createElement('TBODY'); // IE requires that TBODY be added otherwise table will not work
		newEl.appendChild(body);

		var row = document.createElement('TR');
		if (browserIE){row.setAttribute('className','trhead')} else {row.setAttribute('class','trhead')}

		var container = document.createElement('TD');
		cellData = document.createTextNode("");
		container.appendChild(cellData);
		row.appendChild(container);

		var container = document.createElement('TD');
		cellData = document.createTextNode("Time:");
		container.appendChild(cellData);
		row.appendChild(container);

		var container = document.createElement('TD');
		cellData = document.createTextNode("Details for result ("+jno+"):");
		container.appendChild(cellData);
		row.appendChild(container);

		var container = document.createElement('TD');
		cellData = document.createTextNode("Maps:");
		container.appendChild(cellData);
		row.appendChild(container);

		var container = document.createElement('TD');
		cellData = document.createTextNode("Duration:");
		container.appendChild(cellData);
		row.appendChild(container);

		body.appendChild(row);

		journeysXMLObj = xmlDoc.getElementsByTagName('Journey');
		noJs = journeysXMLObj.length;
		var endTime=""

		gotFirstBus = 0;
		gotFirstWalk = 0;
		mode = "none";
		//var startTime="00:00";
		for (j=0;j<noJs;j++){
			if (jno == j){
				legsXMLObj = journeysXMLObj[j].childNodes;
				noLegs = legsXMLObj.length;
				for (l=0;l<noLegs;l++){
					if(legsXMLObj[l].childNodes.length > 0){
						legDuration = (legsXMLObj[l].childNodes.length > 0)?legsXMLObj[l].getElementsByTagName('TypicalDuration'):0;
						mode = (legsXMLObj[l].firstChild.attributes != null)?legsXMLObj[l].firstChild.attributes[0].value:"none";
						if (mode == "none"){
							mode = (legsXMLObj[l].childNodes[1].attributes != null)?legsXMLObj[l].childNodes[1].attributes[0].value:"none";
						}
					}
					if (mode.toLowerCase() == "bus" && gotFirstBus != 1){
						gotFirstBus=1;
						busBoardtime = legsXMLObj[l].getElementsByTagName('LegBoard');
						startTimeArr = busBoardtime[0].getElementsByTagName('TimetabledTime');
						if (startTimeArr.length > 0){
							startTime = startTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);
							firstBusTime = startTime;
						} else {
							startTimeArr = busBoardtime[0].getElementsByTagName('TimetabledDepartureTime');
							startTime = startTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);
						}
					}
				}
			}
		}
		var lastRow = "";
		for (j=0;j<noJs;j++){
			if (jno == j){
				legsXMLObj = journeysXMLObj[j].childNodes;
				noLegs = legsXMLObj.length;
				buscount=0;
				firstBusTime=0;
				firstWalkDuration=0;
				for (l=0;l<noLegs;l++){
					if(legsXMLObj[l].childNodes.length > 0){
						legDuration = (legsXMLObj[l].childNodes.length > 0)?legsXMLObj[l].getElementsByTagName('TypicalDuration'):0;
						mode = (legsXMLObj[l].firstChild.attributes != null)?legsXMLObj[l].firstChild.attributes[0].value:"none";
						if (mode == "none"){
							mode = (legsXMLObj[l].childNodes[1].attributes != null)?legsXMLObj[l].childNodes[1].attributes[0].value:"none";
						}					
						var row = document.createElement('TR');
						if (lastRow == "white"){
							row.setAttribute('bgColor','#FEF2F3');
							lastRow = "pink"
						} else {
							row.setAttribute('bgColor','#FFFFFF');
							lastRow = "white"
						}
						
						xmlLegBoard = legsXMLObj[l].getElementsByTagName('LegBoard');
						xmlLegAlight = legsXMLObj[l].getElementsByTagName('LegAlight');
						if (mode.toLowerCase() == "bus"){
							startTimeArr = (xmlLegBoard[0].getElementsByTagName('TimetabledTime').length > 0)?xmlLegBoard[0].getElementsByTagName('TimetabledTime'):xmlLegBoard[0].getElementsByTagName('TimetabledDepartureTime');
							startTime = startTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);

							endTimeArr = (xmlLegAlight[0].getElementsByTagName('TimetabledTime').length > 0)?xmlLegAlight[0].getElementsByTagName('TimetabledTime'):xmlLegAlight[0].getElementsByTagName('TimetabledArrivalTime');
							endTime = endTimeArr[0].firstChild.nodeValue.split("T")[1].substr(0,5);

							legDuration = minusTimes_func(endTime, startTime);
							ServiceNo = legsXMLObj[l].getElementsByTagName('ServiceNumber')[0].firstChild.nodeValue;
							OperatorName = legsXMLObj[l].getElementsByTagName('OperatorName')[0].firstChild.nodeValue;
							AlightName = xmlLegAlight[0].getElementsByTagName('Name')[0].firstChild.nodeValue;

							ServiceDestination = (legsXMLObj[l].getElementsByTagName('ServiceDestination').length > 0)?legsXMLObj[l].getElementsByTagName('ServiceDestination')[0].getElementsByTagName('Name'):"";
							ServiceDestinationName = (ServiceDestination.length > 0)?ServiceDestination[0].firstChild.nodeValue:"";

							BoardInterchangeTime = (xmlLegBoard[0].getElementsByTagName('InterchangeTime').length > 0)?xmlLegBoard[0].getElementsByTagName('InterchangeTime')[0].firstChild.nodeValue:"";
							AlightInterchangeTime = (xmlLegAlight[0].getElementsByTagName('InterchangeTime').length > 0)?xmlLegAlight[0].getElementsByTagName('InterchangeTime')[0].firstChild.nodeValue:"";

							var bus1id = (xmlLegBoard[0].getElementsByTagName('NaPTANID').length > 0)?xmlLegBoard[0].getElementsByTagName('NaPTANID')[0].firstChild.nodeValue:"";
							var bus2id = (xmlLegAlight[0].getElementsByTagName('NaPTANID').length > 0)?xmlLegAlight[0].getElementsByTagName('NaPTANID')[0].firstChild.nodeValue:"";

							buscount++;
						} else if (mode.toLowerCase() == "walk"){
							legDuration = formatDuration_func(legsXMLObj[l].getElementsByTagName('TypicalDuration')[0].firstChild.nodeValue);
							if (gotFirstWalk == 0){
								startTime = minusTimes_func(startTime, legDuration);
								firstWalkDuration = legDuration;
								gotFirstWalk=1;
							} else {
								startTime = endTime;
							}
							endTime = addTimes_func(startTime, legDuration);
						}

						x1 = (xmlLegBoard[0].getElementsByTagName('Easting').length > 0)?xmlLegBoard[0].getElementsByTagName('Easting')[0].firstChild.nodeValue:0;
						y1 = (xmlLegBoard[0].getElementsByTagName('Northing').length > 0)?xmlLegBoard[0].getElementsByTagName('Northing')[0].firstChild.nodeValue:0;
						x2 = (xmlLegAlight[0].getElementsByTagName('Easting').length > 0)?xmlLegAlight[0].getElementsByTagName('Easting')[0].firstChild.nodeValue:0;
						y2 = (xmlLegAlight[0].getElementsByTagName('Northing').length > 0)?xmlLegAlight[0].getElementsByTagName('Northing')[0].firstChild.nodeValue:0;

						goFromTxt = xmlLegBoard[0].getElementsByTagName('Name')[0].firstChild.nodeValue;
						goToTxt = xmlLegAlight[0].getElementsByTagName('Name')[0].firstChild.nodeValue;	

						var container = document.createElement('TD');
						
						cellData = document.createTextNode(startTime);
						container.appendChild(cellData);
						var brtag = document.createElement('BR');
						container.appendChild(brtag);

						var anchor = document.createElement('A');
						var icon = document.createElement('IMG');
						icon.setAttribute('src',getMode_func(mode));
						icon.setAttribute('border',0);
						icon.setAttribute('alt',mode);
						anchor.appendChild(icon);
						container.appendChild(anchor);

						var brtag = document.createElement('BR');
						container.appendChild(brtag);
						cellData = document.createTextNode(endTime);
						container.appendChild(cellData);

						row.appendChild(container);
						
						// *************
						var container = document.createElement('TD');
						container.setAttribute('align','center');
						container.setAttribute('valign','top');
						container.setAttribute('width','45');
						//var anchor = document.createElement('A');
						//var icon = document.createElement('IMG');
						if (l == 0){
							if (browserIE){container.setAttribute('className','tdstart')} else {container.setAttribute('class','tdstart')}
							//icon.setAttribute('src','images/block_start.gif');
							//icon.setAttribute('alt',"START");
						} else if (l == (noLegs-1)){
							if (browserIE){container.setAttribute('className','tdend')} else {container.setAttribute('class','tdend')}
							//icon.setAttribute('src','images/block_end.gif');
							//icon.setAttribute('alt',"END");
						} else {
							if (browserIE){container.setAttribute('className','tdchange')} else {container.setAttribute('class','tdchange')}
							//icon.setAttribute('src','images/block_change.gif');
							//icon.setAttribute('alt',"CHANGE");
						}
						//icon.setAttribute('border',0);						
						//anchor.appendChild(icon);
						//container.appendChild(anchor);
						
						//cellData = document.createTextNode("-");
						//container.appendChild(cellData);
						row.appendChild(container);
						// *************						

						var container = document.createElement('TD');
						var btag = document.createElement('B');
						cellData = document.createTextNode(goFromTxt);
						btag.appendChild(cellData);
						container.appendChild(btag);
						var brtag = document.createElement('BR');
						container.appendChild(brtag);
						if (mode.toLowerCase() == "bus"){
							cellData = document.createTextNode("Take bus "+ServiceNo+" ("+OperatorName+")");
							container.appendChild(cellData);
							var brtag = document.createElement('BR');
							container.appendChild(brtag);
							cellData = document.createTextNode("Destination: "+ServiceDestinationName);
							/*
							container.appendChild(cellData);
							var brtag = document.createElement('BR');
							container.appendChild(brtag);
							cellData = document.createTextNode("Get off at : "+AlightName);
							*/
						} else {
							cellData = document.createTextNode("Walk to "+goToTxt);
						}
						container.appendChild(cellData);
						row.appendChild(container);

						var container = document.createElement('TD');
						
						/*var anchor = document.createElement('A');
						anchor.setAttribute('href','http://www.multimap.com/map/browse.cgi?client=public&X='+x1+'&Y='+y1+'&width=700&height=400&gride='+x1+'&gridn='+y1+'&srec=0&coordsys=gb&db=pc&pc=&zm=0&scale=5000');
						anchor.setAttribute('target', '_blank');
						cellData = document.createTextNode("startmap 1");
						anchor.appendChild(cellData);
						container.appendChild(anchor);
						
						var txtnode = document.createTextNode(' ');
						container.appendChild(txtnode);*/
						
						var anchor = document.createElement('A');
						anchor.setAttribute('href',"javascript:openWindow_func('/client/openmap.asp?design=/designs/owen.xml&w=765&h=420&eastern="+x1+"&northern="+(y1*-1)+"&zoom=200', 'popup', 0, 0, 765, 420, 0)");
						cellData = document.createTextNode("startmap");
						anchor.appendChild(cellData);
						container.appendChild(anchor);						

						var brtag = document.createElement('BR');
						container.appendChild(brtag);

						/*var anchor = document.createElement('A');
						anchor.setAttribute('href','http://www.multimap.com/map/browse.cgi?client=public&X='+x2+'&Y='+y2+'&width=700&height=400&gride='+x2+'&gridn='+y2+'&srec=0&coordsys=gb&db=pc&pc=&zm=0&scale=5000');
						anchor.setAttribute('target', '_blank');
						cellData = document.createTextNode("endmap");
						anchor.appendChild(cellData);
						container.appendChild(anchor);
						
						var txtnode = document.createTextNode(' ');
						container.appendChild(txtnode);*/
						
						var anchor = document.createElement('A');
						anchor.setAttribute('href',"javascript:openWindow_func('/client/openmap.asp?design=/designs/owen.xml&w=765&h=420&eastern="+x2+"&northern="+(y2*-1)+"&zoom=200', 'popup', 0, 0, 765, 420, 0)");
						cellData = document.createTextNode("endmap");
						anchor.appendChild(cellData);
						container.appendChild(anchor);							
						

						row.appendChild(container);

						var container = document.createElement('TD');
						cellData = document.createTextNode(legDuration);
						container.appendChild(cellData);
						row.appendChild(container);

						body.appendChild(row);

						selectedJData += "&leg"+l+"Duration="+legDuration;
						selectedJData += "&leg"+l+"x1="+x1;
						selectedJData += "&leg"+l+"y1="+y1;
						selectedJData += "&leg"+l+"x2="+x2;
						selectedJData += "&leg"+l+"y2="+y2;
						selectedJData += "&leg"+l+"startTime="+startTime;
						selectedJData += "&leg"+l+"endTime="+endTime;
						selectedJData += "&leg"+l+"boardName="+goFromTxt;
						selectedJData += "&leg"+l+"alightName="+goToTxt;
						selectedJData += "&leg"+l+"mode="+mode;
						if (mode == "bus"){
							selectedJData += "&leg"+l+"OperatorName="+OperatorName;
							selectedJData += "&leg"+l+"ServiceNo="+ServiceNo;
							selectedJData += "&leg"+l+"ServiceDestination="+ServiceDestinationName;
							selectedJData += "&leg"+l+"bus1id="+bus1id;
							selectedJData += "&leg"+l+"bus2id="+bus2id;
						}
					}

				}
				selectedJData += "&nolegs="+noLegs;
				selectedJData += "&totalduration="+minusTimes_func(endTime, minusTimes_func(firstBusTime,firstWalkDuration));
			}
			document.getElementById('jplanresults').appendChild(newEl);
			//prompt("", document.getElementById('jplanresults').innerHTML);
		}	
	}	
}

