	var xmlHttp;
	
	//URL to processing page
    var requestURL = getRootPath() + '/DesktopModules/JourneyPlannerResults/PrepareJPMapping.aspx?';
    var faresURL = getRootPath() + '/DesktopModules/JourneyPlannerResults/GetFares.aspx?'
    var updatesURL = getRootPath() + '/DesktopModules/JourneyPlannerResults/getJPUpdates.aspx?'
    
    var JourneyID;
    var TripKey;
    var JourneyCounter;
    
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
    var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
    var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
    //netscape, safari, mozilla behave the same???
    var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
    

    function prepareJPMapping(journeyID, tripKey, stat_id, tabid, quickid, maprequesttype){
    
		//alert('PJP');
		
        test = new Date();
		var sYear = test.getFullYear();
		var sMonth = test.getMonth() + 1;
		if(sMonth < 10)
		{
			sMonth = "0" + sMonth;
		}
		//alert(sMonth);
		var sDay = test.getDate();
		var sHours = test.getHours();
		var sMinutes = test.getMinutes();
		var sMilliseconds = test.getMilliseconds();
		var requestTimestamp = Date.UTC(sYear,sMonth,sDay,sHours,sMinutes,sMilliseconds);//get the date string
		JourneyID = journeyID;
        TripKey = tripKey;
        
        //alert(stat_id);
		
        if (stat_id > 0){
            //Append the parameters to the requestURL
            var url = requestURL + 'stat_id=' + stat_id + '&strtabid=' + tabid + '&quickid=' + quickid + 
            '&maprequesttype=' + maprequesttype + '&requestTimestamp=' + requestTimestamp;
            
            //alert(url);
            
            //Create the xmlHttp object to use in the request
            //stateChangeHandler will fire when the state has changed, i.e. data is received back
            // This is non-blocking (asynchronous)
            xmlHttp = GetXmlHttpObject(stateChangeHandler);
            
            //Send the xmlHttp get to the specified url
            xmlHttp_Get(xmlHttp, url);
        }
        else {
            
        }
    }
    
    function getFare(JourneyCount, JourneyDate, TripKey0, TripStart0, TripEnd0, TripKey1, TripStart1, TripEnd1, TripKey2, TripStart2, TripEnd2, TripKey3, TripStart3, TripEnd3, TripKey4, TripStart4, TripEnd4, TripKey5, TripStart5, TripEnd5)
    {
		JourneyCounter = JourneyCount;
		var fURL = faresURL + 'JDate=' + JourneyDate + '&TripKey0=' + TripKey0 + '&TripStart0=' + TripStart0 + '&TripEnd0=' + TripEnd0 
							+ '&TripKey1=' + TripKey1 + '&TripStart1=' + TripStart1 + '&TripEnd1=' + TripEnd1 
							+ '&TripKey2=' + TripKey2 + '&TripStart2=' + TripStart2 + '&TripEnd2=' + TripEnd2 
							+ '&TripKey3=' + TripKey3 + '&TripStart3=' + TripStart3 + '&TripEnd3=' + TripEnd3 
							+ '&TripKey4=' + TripKey4 + '&TripStart4=' + TripStart4 + '&TripEnd4=' + TripEnd4 
							+ '&TripKey5=' + TripKey5 + '&TripStart5=' + TripStart5 + '&TripEnd5=' + TripEnd5;
		//alert(fURL);
		document.getElementById("farediv_" + JourneyCount).innerHTML = "<span class='SubHead'><img src='" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/loading5.gif'>&nbsp;&nbsp;Retrieving Fares information .. please wait.</span>"
		document.getElementById("btn_" + JourneyCount).style.display = "none";
		//document.getElementById("btn_" + JourneyCount).onclick = "none";
		//Create the xmlHttp object to use in the request
        //stateChangeHandler will fire when the state has changed, i.e. data is received back
        // This is non-blocking (asynchronous)
        xmlHttp = GetXmlHttpObject(faresChangeHandler);
        
        //Send the xmlHttp get to the specified url
        xmlHttp_Get(xmlHttp, fURL);
	}
	
	
	function getJPServiceUpdates(theDate, theTrips)	
	{
		if (typeof(theTrips) == "undefined")
		{
			//
		}
		else
		{
			document.getElementById("dvUpdates").innerHTML = "<span class=\"NormalRed\"><img src=\"" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/warning.gif\" hspace=\"4\">Retrieving Service Updates, Interuptions and changes for the services below.</span>";
			//alert(theTrips);
			var suURL = updatesURL + 'theDate=' + theDate + '&theTrips=' + theTrips + '&theSummary=False';
			//alert(suURL);
			//Show a Message 'please wait retrieving Service Updates' or something
			xmlHttp = GetXmlHttpObject(suChangeHandler);
	        
			//Send the xmlHttp get to the specified url
			xmlHttp_Get(xmlHttp, suURL);
        }
	}
    
   
    //stateChangeHandler will fire when the state has changed, i.e. data is received back
    // This is non-blocking (asynchronous)
    function stateChangeHandler()
    {
        //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        {
            //
            var response = xmlHttp.responseText;
            //alert(response);
            if(response == "Success")
            {
				if(TripKey == 0)
				{
					windowURL = getRootPath() + '/DesktopModules/JourneyPlannerMap/TripDetailFrame.aspx?JourneyID=' + JourneyID
				}
				else
				{
					windowURL = getRootPath() + '/DesktopModules/JourneyPlannerMap/TripDetailFrame.aspx?JourneyID=' + JourneyID + '&IsService=' + TripKey
				}
				
				map.resizeTo(800,600);
				//map.setText('Dunnit');
				map.location.href = windowURL;
				map.focus();
            }
            else
            {
				map.setText("<br/><br/><span class=\"NormalRed\"  onClick=\"Javascript:window.close();\">Mapping is currently unavailable.<br/>Please try again later.<br/>Click here to close window.</span>");
            }
        }       
    }
    // Uncomment this function and comment out the one above for debugging
   /* function stateChangeHandler()
    {
        //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
           	if (xmlHttp.status == 200)
			{
				alert('Success!');
			}
			else if (xmlHttp.status == 404)
			{
				alert('Page Not Found!');
			}
			else if (xmlHttp.status == 500)
			{
				alert('Page Error: 500');
			}
        }				
    }*/    
    function faresChangeHandler()
    {
        //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        {
            //
            var response = xmlHttp.responseText;
            if(response == "Failed")
            {
				document.getElementById("farediv_" + JourneyCounter).innerHTML = "<span class='NormalRed'>There was a Problem Retrieving Fares information .. please try again later.</span>"
            }
            else
            {
				document.getElementById("farediv_" + JourneyCounter).innerHTML = response;
				document.getElementById('tog_' + JourneyCounter).style.display="inline";
            }
        }              
    }
    
    function suChangeHandler()
    {
        //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
        {
            
            /*var response = xmlHttp.responseText;
            alert(response);*/
            JPR_setUpdates(xmlHttp.responseXML.documentElement);
        }              
    }
    
    function JPR_setUpdates(serviceNode)
    {
		try
		{
			var sus = serviceNode.getElementsByTagName('CHANGE');
			//Are  there any interuptions
			if (sus.length > 0)
			{
				//alert(sus.length);
				//alert(document.forms[0].elements.length);
				for (var i = 0; i < sus.length; i++)
				{
					var theTab;
					var theModule;
					//var tk = sus[i].childNodes[0].text;
					var tk = sus[i].getElementsByTagName("TRIPKEY")[0].firstChild.nodeValue;
					//tLoc.getElementsByTagName("Display")[0].firstChild.nodeValue;
					//alert(tk);
					var tp = sus[i].getElementsByTagName("TYPE")[0].firstChild.nodeValue;//sus[i].childNodes[1].text;
					var type
					if (tp == "I")
					{
						type = "Service Interruption";
						theTab = getDisruptionsTab();
						theModule = getDisruptionsModule();
					}
					else
					{
						type = "Service Change";
						theTab = getChangesTab();
						theModule = getChangesModule();
					}
					var tb = sus[i].getElementsByTagName("TABID")[0].firstChild.nodeValue;//sus[i].childNodes[2].text;
					var sd = sus[i].getElementsByTagName("STARTDATE")[0].firstChild.nodeValue;//sus[i].childNodes[3].text;
					var ed = sus[i].getElementsByTagName("ENDDATE")[0].firstChild.nodeValue;//sus[i].childNodes[4].text;
					var ttl = sus[i].getElementsByTagName("TTL")[0].firstChild.nodeValue;//sus[i].childNodes[5].text;
					var cmt = sus[i].getElementsByTagName("CMT")[0].firstChild.nodeValue;//sus[i].childNodes[6].text;
					
					//var str = document.getElementById("SI_" + tk).innerHTML;
					var msg = "<table bgcolor=#FFFFFF width=100% height=100%><tr><td class=Normal colspan=2><img src=" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/" + tp + ".gif ></td></tr><tr><td class=SubSubHead>Title:</td><td class=Normal>" + ttl + "</td></tr><tr><td class=SubSubHead>Start Date:</td><td class=Normal>" + sd + "</td></tr><tr><td class=SubSubHead>End Date:</td><td class=Normal>" + ed + "</td></tr><tr><td class=Normal colspan=2>Click on the icon to read more..</td></tr></table>";
					//alert (msg);
					
					var str = "<table><tr><td class=\"NormalRed\"><a href=\"" + getRootPath() + "/Default.aspx?Tabid=" + theTab + "&newsid" + theModule + "=" + tb + "\" target=\"_blank\"><img src=\"" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/warning.gif\" hspace=\"4\" border=\"0\" onmouseover=\"writetxt('" + msg + "')\" onmouseout=\"writetxt(0)\"></a></td><td class=\"NormalRed\">&nbsp;" + ttl + "&nbsp;</td></table>";
					
					var control = document.getElementsByName("SI_" + tk);
					//alert("SI_" + tk);
					//alert(control.length);
					//alert(control
					//control.innerHTML = str;
					for(var k = 0; k < control.length; k++)
					{
						var rt = control[k].innerHTML;
						control[k].innerHTML = rt + str;
					}
					
					//alert(str);
				}
				document.getElementById("dvUpdates").innerHTML = "<span class=\"NormalBold\"><img src=\"" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/warning.gif\" hspace=\"4\">There are Service Updates, Interuptions or Changes for the services listed. Move your mouse over the icons below for details.</span>";
			}
			else
			{
				//Show message saying ... No Interuptions
				//alert('None');
				document.getElementById("dvUpdates").innerHTML = ""
			}
		}
		catch(er)
		{
			//Show message saying ...
			document.getElementById("dvUpdates").innerHTML = "<span class=\"NormalRed\"><img src=\"" + getRootPath() + "/DesktopModules/JourneyPlannerResults/images/warning.gif\" hspace=\"4\">There was a problem retrieving Service Updates, Interuptions and changes for the services below are not displayed.</span>";
		}
    }
    
    function toggleFares(faredivName, Journey)
    {
		if ( document.getElementById(faredivName).style.display=="none" )
		{
			document.getElementById(faredivName).style.display="block";
			document.getElementById('tog_' + Journey).src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/HideFare.gif";
		}
		else
		{
			document.getElementById(faredivName).style.display="none";
			document.getElementById('tog_' + Journey).src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
		}
    }
    
    function toggleOptions(faredivName, Journey)
    {
		if ( document.getElementById(faredivName).style.display=="none" )
		{
			document.getElementById(faredivName).style.display="block";
			document.getElementById('optShow_' + Journey).src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif";
		}
		else
		{
			document.getElementById(faredivName).style.display="none";
			document.getElementById('optShow_' + Journey).src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif";
		}
    }
    
    function toggleAllOptions(tog)
    {
		try
		{
			if(tog == "Expand")
			{
				document.getElementById("optionsdiv_1").style.display="block";
				document.getElementById('optShow_1').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif"
				document.getElementById("optionsdiv_2").style.display="block";
				document.getElementById('optShow_2').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif"
				document.getElementById("optionsdiv_3").style.display="block";
				document.getElementById('optShow_3').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif"
				document.getElementById("optionsdiv_4").style.display="block";
				document.getElementById('optShow_4').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif"
				document.getElementById("optionsdiv_5").style.display="block";
				document.getElementById('optShow_5').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Collapse.gif"
			}
			else
			{
				document.getElementById("optionsdiv_1").style.display="none";
				//document.getElementById("farediv_1").style.display="none";
				document.getElementById('optShow_1').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif"
				//document.getElementById('tog_1').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
				document.getElementById("optionsdiv_2").style.display="none";
				//document.getElementById("farediv_2").style.display="none";
				document.getElementById('optShow_2').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif"
				//document.getElementById('tog_2').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
				document.getElementById("optionsdiv_3").style.display="none";
				//document.getElementById("farediv_3").style.display="none";
				document.getElementById('optShow_3').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif"
				//document.getElementById('tog_3').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
				document.getElementById("optionsdiv_4").style.display="none";
				//document.getElementById("farediv_4").style.display="none";
				document.getElementById('optShow_4').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif"
				//document.getElementById('tog_4').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
				document.getElementById("optionsdiv_5").style.display="none";
				//document.getElementById("farediv_5").style.display="none";
				document.getElementById('optShow_5').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Expand.gif"
				//document.getElementById('tog_5').src = getRootPath() + "/DesktopModules/JourneyPlannerResults/images/Fare.gif";
			}
		}
		catch(e)
		{
			alert(e);
		}		
    }

    // XMLHttp send GET request
    function xmlHttp_Get(xmlhttp, url) {
        xmlhttp.open('GET', url, true);
        xmlhttp.send(null);
    }

    function GetXmlHttpObject(handler) {
        var objXmlHttp = null;    //Holds the local xmlHTTP object instance

        //Depending on the browser, try to create the xmlHttp object
        if (is_ie){
            //The object to create depends on version of IE
            //If it isn't ie5, then default to the Msxml2.XMLHTTP object
            var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
            
            //Attempt to create the object
            try{
                objXmlHttp = new ActiveXObject(strObjName);
                objXmlHttp.onreadystatechange = handler;
            }
            catch(e){
            //Object creation errored
                //alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
                return;
            }
        }
        //else if (is_opera){
            //Opera has some issues with xmlHttp object functionality
            //alert('Opera detected. The page may not behave as expected.');
            //return;
       // }
        else{
            // Mozilla | Netscape | Safari | Opera
            objXmlHttp = new XMLHttpRequest();
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler;
        }
        
        //Return the instantiated object
        return objXmlHttp;
    }
    
    //Returns the node text value 
	function GetInnerText (node)
	{
		//alert('TOK');
		return (node.textContent || node.innerText || node.text) ;
	}