var Xmlreq = getXMLHTTPRequest();
var req = getXMLHTTPRequest();
var arrFromCity;
var arrToCity;
var arrFMixCodes;
var fMixCodes;
var TcvRb;
var strArrCity;
var TempMixcode =0;
arrFromCity = new Array();
arrToCity = new Array();

function getXMLHTTPRequest() 
{
	try 
	{
		req = new XMLHttpRequest();
	} 
	catch(err1) 
	{
		try 
		{
			req = new ActiveXObject('Msxml2.XMLHTTP');			
		} 
		catch (err2) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (err3) 
			{
				req = false;
			}
		}
	}
	return req;
}

function loadFromCities() 
{
  try
	{
	
	
	if (Xmlreq.readyState == 4) 
		{
			if(Xmlreq.status == 200) 
			{			
				var xml = Xmlreq.responseText;
				//alert(xml);
				if (xml=='') arrFromCity = new Array();			
				else arrFromCity = xml.split(",");			
			}
			/*else
			{
				alert("Xmlreq.status:" + Xmlreq.status);
			}*/
		} 
		else 
		{
			var x;
			x=Xmlreq.readyState;
			//alert('Xmlreq.readyState:' + x);		
		}
    }
    catch(e){alert(e.description);}
}

function loadToCities() 
{	
	try
		{
		if (Xmlreq.readyState == 4) 
		{
			if(Xmlreq.status == 200) 
			{			
				var xml = Xmlreq.responseText;
				if (xml=='') arrToCity = new Array();			
				else arrToCity = xml.split(",");			
			}
			/*else
			{
				alert("Xmlreq.status:" + Xmlreq.status);
			}*/
		} 
		else 
		{
			var x;
			x=Xmlreq.readyState;
			//alert('Xmlreq.readyState:' + x);
			//for (var x=0;x<1000000;x++);
		}
	}
    catch(e){alert(e.description);}	
}

function loadFromCityMixCodes() 
{	
	try
		{
			if (req.readyState == 4) 
			{
				if(req.status == 200) 
				{			
					var xml = req.responseText;
					if (xml=='') arrFMixCodes = new Array();			
					else arrFMixCodes = xml.split(",");			
				}
				/*else
				{
					alert("req.status:" + req.status);
				}*/
			} 
			else 
			{
				var x;
				x=req.readyState;
				//alert('req.readyState:' + x);
				//for (var x=0;x<100000;x++);
			}
	}
    catch(e){alert(e.description);}	
}

// Code added for Browser Compilablity
function ClearTextBoxForBrowserCompitable()
{	try
	{
		document.getElementById('DispstationOUTtxt').value="";
		document.getElementById('DispstationOUTtxt').focus()
		document.getElementById('BookingEngine1').value="";
		document.getElementById('BookingEngine2').value="";
		Check("ClearTextBoxes");	
	}
    catch(e){alert("4   "+ e.description);}	
}

function ClearFromAndToCitiesForBrowserCompitable()
{
	try
	{
		document.getElementById('DispStationIntxt').value="";
		document.getElementById('DispstationOUTtxt').value="";
		document.getElementById('DispStationIntxt').focus();
	}
    catch(e){alert(e.description);}	

}
function ClearTextBoxes(objName)
{
	if (objName == "DispStationIntxt")
	{
		document.getElementById('DispStationIntxt').value="";
		document.getElementById('DispstationOUTtxt').value="";
		//document.getElementById('DispstationOUTtxt').disabled=true;
	}
	else if (objName == "DispstationOUTtxt")
	{
		document.getElementById('DispstationOUTtxt').value="";		
	}
	document.getElementById('BookingEngine1').value="unknown";
	document.getElementById('BookingEngine2').value="unknown";
	Check("ClearTextBoxes");	
}

function GetMixCode(city)
{
  try
   {
	//alert(city);
		if ( city!='')
		{
			var url;		
			//url="http://www.railkey.com/tickets//includes/GetP2PData.asp?type=2&input=&AFF=" + AFF + "&fromcity=" + city;//&cacheclear=true";
			url="/includes/GetP2PData.asp?type=2&input=&AFF=" + AFF + "&fromcity=" + city;//&cacheclear=true";
			//alert(url);
			//alert("readystate  "+req.readyState );				
			arrFMixCodes =new Array();
			req.open("GET", url, false);
			//req.onreadystatechange = loadFromCityMixCodes;
			req.send(null);
			if(req.status == 200) 
				{			
				var xml = req.responseText;
				//window.status ="Mixcodes for "+ city +"    " +xml;
				//alert("responseText  :"+xml);
				if (xml=='') arrFMixCodes = new Array();			
				else arrFMixCodes = xml.split(",");			
				}        		 		
		}
	}
    catch(e){alert(e.description);}
}

function isAvailableRoute(Source,Target,RouteCode)
{
  try
   {	
		if (Source!='' && Target!='' && RouteCode!='')
		{
			var url,Result;			
			url="/includes/GetP2PData.asp?type=7&input=&AFF=" + AFF + "&fromcity=" + Source + "&tocity=" + Target + "&mixcode=" + RouteCode;//&cacheclear=true";
			//alert(url);
			req.open("GET", url, false);			
			req.send(null);
			if(req.status == 200) 
			{			
				var xml = req.responseText;
				if (xml=='') Result=0;			
				else Result=xml;
				//window.status = " FromCity  :" + Source + " tCity :" + Target + " Mixcode: " + RouteCode;
				if (Result==1) return true;
				else return false;
			}
		}
	}
    catch(e){alert(e.description);}
}

function GetBlockedRoutes(FromCity,ToCity)
{
  try
   {
	//alert(city);
		if ( FromCity!='' && ToCity!='')
		{
			var url;		
			//url="http://www.railkey.com/tickets//includes/GetP2PData.asp?type=2&input=&AFF=" + AFF + "&fromcity=" + city;//&cacheclear=true";
			url="/includes/GetP2PData.asp?type=4&input=&fromcity=" + FromCity + "&tocity=" + ToCity;//&cacheclear=true";
			//alert("readystate  "+req.readyState );				
			arrFMixCodes =new Array();
			req.open("GET", url, false);
			//req.onreadystatechange = loadFromCityMixCodes;
			req.send(null);
			if(req.status == 200) 
				{			
				var xml = req.responseText;
				//window.status =url;
				//alert("responseTextblocked  :"+xml);
				if (xml!='') return xml;
				else return 0;			
				}        		 		
		}
	}
    catch(e){alert(e.description);}
    return 0;
}
function GetTcvRbValidRailCode(FromCity,ToCity)
{
try
   {
	//alert(city);
	if ( FromCity!='' && ToCity!='')
	{
		var url;		
		//url="/includes/GetP2PData.asp?type=5&input=&fromcity=" + FromCity + "&tocity=" + ToCity;
		url="/includes/GetP2PData.asp?type=6&input=&fromcity=" + FromCity + "&tocity=" + ToCity;
		//alert(url);		
		//alert("readystate  "+req.readyState );		
		req.open("GET", url, false);
		//req.onreadystatechange = loadFromCityMixCodes;
		req.send(null);			
		if(req.status == 200) 
			{			
			var xml = req.responseText;			
			//alert("responseText  :"+req.responseText);
			if (xml!='') return xml;
			else return 0;			
			}        		 		
	}
  }
    catch(e){alert(e.description);}
    return 0;
}	

function GetMixCodeType(MixCode)
{
	try
	{
		if (MixCode==1) return "amtrak";
		else if (MixCode==2) return "elgar";
		else if (MixCode==3) return "ukopentickets";
		else if (MixCode==4) return "railbest";
		else if (MixCode==5) return "swan";
		else if (MixCode==6) return "tcv";
		else return "unknown";		
	}
    catch(e){}	
}

function ShowElgarOptions(show)
{	
//alert("ShowElgarOptions");
	try
	{
		var controlstyle,k;
		var divVisible;
		if(navigator.appName.indexOf("Microsoft") > -1){ 
		controlstyle = "block";}
		else{
		controlstyle = 'table-row'; 
		}
		if (!show) controlstyle ="none";		
		
		//trTicket.style.display = controlstyle;
		if (document.getElementById('ticket').value=="RT")
		{
			document.getElementById('trReturn').style.display = controlstyle;
			document.getElementById('trReturn1').style.display = controlstyle;
			document.getElementById('Swantext').style.display = controlstyle;
			//trReturn.style.display = controlstyle;
			//trReturn1.style.display = controlstyle;
			//Swantext.style.display=controlstyle;
		}
		else
		{
			
			document.getElementById('trReturn').style.display = "none";
			document.getElementById('trReturn1').style.display = "none";
			document.getElementById('Swantext').style.display = "none";
			document.getElementById('Swantext_test').style.display = "none";
			
			//trReturn.style.display = "none";
			//trReturn1.style.display = "none";
			//Swantext.style.display="none";
			//Swantext_test.style.display="none";
			
		}
		
		
		document.getElementById('trPassengers').style.display = controlstyle;
		document.getElementById('trTicket').style.display = controlstyle;
		
		//trPassengers.style.display=controlstyle;
		//trTicket.style.display = controlstyle;
		
		
		if(TempMixcode==2)
		{	
			while(document.getElementById("AD").length)
			{
				document.getElementById("AD").remove(0);
				document.getElementById("SE").remove(0);
				document.getElementById("CH").remove(0);
				document.getElementById("YU").remove(0);
			}			
			for( k=0;k<7;k++)
			{		
				document.getElementById("AD").options[k] = new Option(k,k);
				document.getElementById("SE").options[k] = new Option(k,k);
				document.getElementById("CH").options[k] = new Option(k,k);
				document.getElementById("YU").options[k] = new Option(k,k);
			}
		}
	}
    catch(e){alert("ShowElgarOptions    "+e.description);}	
}
function hideSwanText()
{

document.getElementById('Swantext_test').style.display = "none";
//Swantext_test.style.display="none";

}
function ShowSwanOptions(show)

{ 
//alert("ShowSwanOptions");
var k;
	try
		{
	
		
		document.getElementById("chkRailPass").checked = false;
		document.getElementById("chkFixed").checked = false;
		//window.status ="ShowSwanOptions			:"+show;
		if(navigator.appName.indexOf("Microsoft") > -1)
			{ controlstyle = "block"; }
		else
			{controlstyle = 'table-row'; }
		
		
		if (!show)
		{
			
			//document.getElementById( 'trRailPass' ).setAttribute( 'style', 'display:none' );
			//document.getElementById( 'Swantext' ).setAttribute( 'style', 'display:none' );
			//document.getElementById( 'Swantext_test' ).setAttribute( 'style', 'display:none' );

		        document.getElementById('trRailPass').style.display='none';
		        document.getElementById('Swantext').style.display='none';
		        document.getElementById('Swantext_test').style.display='none';
			//trRailPass.style.display="none";
			//Swantext.style.display="none";
			//Swantext_test.style.display="none";
			
		}	
		else
		{	
		       
		        document.getElementById('trRailPass').style.display=controlstyle;
		        document.getElementById('Swantext').style.display=controlstyle;
			//trRailPass.style.display=controlstyle;
			//Swantext.style.display=controlstyle;
			
			if(TempMixcode==5)
			{		
				while(document.getElementById("AD").length)
				{
					document.getElementById("AD").remove(0);
					document.getElementById("SE").remove(0);
					document.getElementById("CH").remove(0);
					document.getElementById("YU").remove(0);
				}				
				for(k=0;k<=36;k++)
				{		
					document.getElementById("AD").options[k] = new Option(k,k);
					document.getElementById("SE").options[k] = new Option(k,k);
					document.getElementById("CH").options[k] = new Option(k,k);
					document.getElementById("YU").options[k] = new Option(k,k);
				}
			}
		}	
	}
	catch(e){alert("ShowSwanOptions		:" + e.description);}	
}

function ShowRailbestOptions(show)
{
	if (show){
		if(navigator.appName.indexOf("Microsoft") > -1){ 
			trFare.style.display = "block";}
		else{
			//trFare.style.display = "table-row";
			document.getElementById('trFare').style.display = "table-row";
			}
	}
	else
	{
	  //trFare.style.display = "none";
	  
	  document.getElementById('trFare').style.display = "none";
	
	}  
	
}
function showControls(show){}
function showControls1(show)
{
	var controlstyle;
	if(navigator.appName.indexOf("Microsoft") > -1){ 
	controlstyle="block";}
	else{
	controlstyle = 'table-row'; 
	}
	if (!show) controlstyle = "none";

        document.getElementById('trClass').style.display = controlstyle;
        document.getElementById('trLeave').style.display = controlstyle;
        
	//trClass.style.display=controlstyle;
	//trLeave.style.display=controlstyle;
	
	
	
	if (!show)
	{
		ShowElgarOptions(show);
		ShowRailbestOptions(show);
		ShowSwanOptions(show);
	}
	else Check("showControls");
	if (show)
	{
	//	if (document.getElementById("DispstationOUTtxt").value!='') document.getElementById('class').focus();
	}
}

/*function Check()
{		
	try
	{
	var fCity,tCity,Type;
	fCity=document.getElementById('DispStationIntxt');
	tCity=document.getElementById('DispstationOUTtxt');
	type1=document.getElementById('BookingEngine1');
	type2=document.getElementById('BookingEngine2');
	ShowElgarOptions(false);
	ShowRailbestOptions(false);
	if (fCity!=null && tCity!=null && type1!=null && type2!=null)
	{
		if (fCity.value == '' || tCity.value == '')
		{
			ShowElgarOptions(false);
			ShowRailbestOptions(false);
		}
		else
		{
			//alert(fCity.value +' '+ tCity.value + ' ' + type.value);
			if (fCity.value != '' && tCity.value != '' && ((type1.value=='elgar' && type2.value=='elgar') || (type1.value=='swan' && type2.value=='swan')))
			{
				ShowElgarOptions(true);
				//ShowRailbestOptions(true);
				var seladults;
				seladults = document.getElementById('AD');
				if (seladults!=null)
				{
					seladults.options[1].selected=true;
				}
			}
			else if (fCity.value != '' && tCity.value != '' && type1.value=='railbest' && type2.value=='railbest')
			{
				ShowRailbestOptions(true);
			}
		}
	}
	else
	{
		ShowElgarOptions(false);
		ShowRailbestOptions(false);
	}
 }
 catch(e){alert(e.description);}
}*/

function Check(msg)
{	//window.status="Check: " + msg;
	try
	{
	var fCity,tCity,Type;
	fCity=document.getElementById('DispStationIntxt');
	tCity=document.getElementById('DispstationOUTtxt');
	type1=document.getElementById('BookingEngine1');
	type2=document.getElementById('BookingEngine2');
	ShowSwanOptions(false);
	ShowElgarOptions(false);
	ShowRailbestOptions(false);
	if (fCity!=null && tCity!=null && type1!=null && type2!=null)
	{
		if (fCity.value == '' || tCity.value == '')
		{
			ShowElgarOptions(false);
			ShowRailbestOptions(false);
			ShowSwanOptions(false);
		}
		else
		{
			//alert(fCity.value +' '+ tCity.value + ' ' + type.value);
			if (fCity.value != '' && tCity.value != '' && ((type1.value=='elgar' && type2.value=='elgar') || (type1.value=='swan' && type2.value=='swan')))
			{
				if ((type1.value=='swan' && type2.value=='swan'))
				{
					ShowSwanOptions(true);
				}
				ShowElgarOptions(true);
				//ShowRailbestOptions(true);
				var seladults;
				seladults = document.getElementById('AD');
				if (seladults!=null)
				{
					seladults.options[1].selected=true;
				}
			}
			else if (fCity.value != '' && tCity.value != '' && ((type1.value=='railbest' && type2.value=='railbest') || TcvRb==0))
			{
				ShowRailbestOptions(true);
			}
		}
	}
	else
	{
		ShowElgarOptions(false);
		ShowRailbestOptions(false);
	}
 }
 catch(e){alert(e.description);}
}

function findMixCode(FromMixCode,ToMixCode)
{
	//alert("FromMixCode    "+FromMixCode);
	//alert("ToMixCode      "+ToMixCode);
	fCity=document.getElementById('DispStationIntxt');
	tCity=document.getElementById('DispstationOUTtxt');
	
		var mixCode;
		mixCode=0;
		var found=new Array();
		var arrOrder=new Array(1,3,5,2,6,4,7,8);		
		if (ToMixCode.length != 0 && FromMixCode.length!=0)
		{		
			for (var i =0;i< FromMixCode.length; i++)
				for (var j =0; j< ToMixCode.length; j++)
				{
					if (FromMixCode[i]== ToMixCode[j]) 
						found.push(FromMixCode[i]);
				}
			
			if (found.length>0 && found.length==1)
			{
				mixCode=found[0];
				//Swan Logic
				//alert(isAvailableRoute(fCity.value,tCity.value,"5"));
				if (mixCode==5)	if (isAvailableRoute(fCity.value,tCity.value,"5")==false) mixCode=0;
				//End of Swan Logic
			}
			if (found.length>=2)
				mixCode =0;				
				for (var i =0;i< arrOrder.length; i++)
				{				
					for (var j =0; j< found.length; j++)
					{	
						if (arrOrder[i]==found[j])
						{
							mixCode=found[j];														
							//Swan Logic
							//if (mixCode==5) alert(isAvailableRoute(fCity.value,tCity.value,"5"));
							if (mixCode==5)	if (isAvailableRoute(fCity.value,tCity.value,"5")==false) mixCode=0;							
							//End of Swan Logic
						}
						if (mixCode!=0) break;
					}	
					if (mixCode!=0) break;
				}
		}
	var conBlocked;
	conBlocked = document.getElementById("BlockedRoute");
	if (conBlocked!=null) conBlocked.value="false";
	//if (mixCode==6)
	//if (1==1)
	//{
		var code,ToCity,FromCity;
		FromCity =document.getElementById("DispStationIntxt").value;
		ToCity =document.getElementById("DispstationOUTtxt").value;		
		code=GetBlockedRoutes(FromCity,ToCity);
		
		//window.status ="The Final MixCode is  :" +mixCode;
		if (code!=0 && mixCode!=5)
		{
			if (conBlocked!=null) conBlocked.value="true";
			mixCode=code;
			
		}
	//}
	document.getElementById("JourneyType").options[0].text ="Ticket + Seat Reservation";	
	if ((mixCode == 4 || mixCode == 6) && (conBlocked.value != "true"))
	{
		
		
		TcvRb=GetTcvRbValidRailCode(fCity.value,tCity.value);		
		if (TcvRb == 0)
		{
			document.getElementById("RailCode").value = "true";
			mixCode=6;
			document.getElementById("JourneyType").options[0].text ="Ticket Only";
		}
		else if (TcvRb == 1)
		{	
			document.getElementById("RailCode").value = "true";
			mixCode=4;
			document.getElementById("JourneyType").options[0].text ="Ticket Only";
		}
	}
	window.status="mixcode: " + mixCode;
	TempMixcode =mixCode;
	return mixCode;
}
function ToCityMixCode()
{	
try
	{
	var MixCode,MixCodeType;
	var FromMixCode,ToMixCode,MixCode;	
	ToCity =document.getElementById("DispstationOUTtxt").value;
	
	//alert('fMixCodes: ' + fMixCodes);	
	if (fMixCodes!=null && fMixCodes!=0) FromMixCode = fMixCodes.split(",");
	else
	{
		FromCity =document.getElementById("DispStationIntxt").value;
		arrFMixCodes=new Array();
		GetMixCode(FromCity);
		if (arrFMixCodes!=null && arrFMixCodes.length!=0) 
		{
			FromMixCode =arrFMixCodes;
			fMixCodes = arrFMixCodes.join(",");
		}
		else FromMixCode = new Array();
	}	
	GetMixCode(ToCity);
	
	ToMixCode = new Array();
	if (arrFMixCodes!=null && arrFMixCodes.length!=0) ToMixCode = arrFMixCodes;	
	ToMixCode.sort();
	FromMixCode.sort();
	//alert("FromMixCode  " + FromMixCode);
	//alert("ToMixCode  " + ToMixCode);
	MixCode = findMixCode(FromMixCode,ToMixCode);
	//alert("MixCode    " + MixCode);
	MixCodeType = GetMixCodeType(MixCode);
	//alert(MixCodeType);

	document.getElementById('BookingEngine1').value=MixCodeType;
	document.getElementById('BookingEngine2').value=MixCodeType;
	Check("ToCityMixCode");
	}
	catch (e){alert(e.description);}
}

function FromCityMixCode()
{
	try
	{
		FromCity =document.getElementById("DispStationIntxt").value;			
		//alert(FromCity);
		var MixCode,MixCodeType;
		if (FromCity!='') GetMixCode(FromCity);
		else arrFMixCodes = new Array();
		if (arrFMixCodes.length==0) fMixCodes=0;		
		else fMixCodes = arrFMixCodes.join(",");
		//alert("arrFMixCodes: " + arrFMixCodes);		
		oTextbox1 = new AutoSuggestControl(document.getElementById('DispstationOUTtxt'), new ToCitySuggestions());
	}
	catch(e) { a=e;}
}

function FromCitySuggestions() 
{		
	this.states=new Array();
}

FromCitySuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,bTypeAhead /*:boolean*/)
{
	try
	{
	var aSuggestions = [];
	var sTextboxValue = oAutoSuggestControl.textbox.value;
	var ch,rest
	ch=sTextboxValue.substring(0,1);
	ch=ch.toUpperCase();
	rest=sTextboxValue.substring(1);								
	sTextboxValue = ch + rest;								
	if (sTextboxValue.length == 1)
	{									
		var Found;
		Found=false;
		if (this.states.length > 0)
			if (ch==this.states[0].substring(0,1)) Found = true;
			
		if (!Found)
		{										
			var url;			
						
			//url="http://www.railkey.com/tickets//includes/GetP2PData.asp?type=1&input=" + ch + "&AFF=" + AFF;//&cacheclear=true";
			url="/includes/GetP2PData.asp?type=1&input=" + ch + "&AFF=" + AFF;//&cacheclear=true";
			
			
			//sendRequest(url,&loadFromCities);						
			arrFromCity=new Array();			 
			Xmlreq.open("GET", url, false);
			//Xmlreq.onreadystatechange = loadFromCities;			
			Xmlreq.send(null);
			/*if (xml=='') arrFromCity = new Array();			
			else arrFromCity = xml.split(",");	*/
			if (Xmlreq.readyState == 4) 
					{
						if(Xmlreq.status == 200) 
						{			
							var xml = Xmlreq.responseText;
							//alert(xml);
							if (xml=='') arrFromCity = new Array();			
							else arrFromCity = xml.split(",");			
						}
						
					} 
					
			//for (var x=0;x<1000000;x++);			
			this.states = new Array();
			for (var i=0; i < arrFromCity.length; i++) 
			{
			//this.states.push(arrFromCity[i]);
			//if (aSuggestions.length <= 15) aSuggestions.push(arrFromCity[i]);
			   this.states.push(arrFromCity[i].replace("$$$",","));
			   	if (aSuggestions.length <= 15) aSuggestions.push(arrFromCity[i].replace("$$$",","));										
			}
		}
		else
		{										
			for (var i=0; i < this.states.length; i++)
			{
				aSuggestions.push(this.states[i]);
				if (aSuggestions.length > 15) break;
			}
		}								
	}
	if (sTextboxValue.length > 1)
	{
		//search for matching states												
		for (var i=0; i < this.states.length; i++) {

			strArrCity=this.states[i];
					
			strArrCity=strArrCity.toUpperCase();
											
			if (strArrCity.indexOf(sTextboxValue.toUpperCase()) == 0)
			{       
				aSuggestions.push(this.states[i]);
			}

			/*if (this.states[i].indexOf(sTextboxValue) == 0)
			{
				aSuggestions.push(this.states[i]);
			}*/

			if (aSuggestions.length > 15) break;
		}
	}
	//provide suggestions to the control
	//alert(aSuggestions);
	// = aSuggestions.length + " Cities found";								
	oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
	}
	catch(e){ a=e;}
};


function ToCitySuggestions()
{		
	this.states = new Array();
}

ToCitySuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,bTypeAhead /*:boolean*/) 
{
	try
	{
	var aSuggestions = [];
	var sTextboxValue = oAutoSuggestControl.textbox.value;
	var ch,rest;
	ch=sTextboxValue.substring(0,1);
	rest=sTextboxValue.substring(1);
	ch=ch.toUpperCase();
	//alert(ch);
	sTextboxValue = ch + rest;		
	//alert(sTextboxValue);
	if (sTextboxValue.length == 1)
	{									
		var Found;		
		Found=false;
		if (this.states.length > 0)
			if (ch==this.states[0].substring(0,1)) Found = true;
			
		if (Found==false)
		{										
			var url;
			if (fMixCodes==null) FromCityMixCode();
			//window.status="fMixCodes: " + fMixCodes;
			//alert(fMixCodes);
			//alert("Populating To Cities");			
			//url="http://www.railkey.com/tickets//includes/GetP2PData.asp?type=3&input=" + ch + "&AFF=" + AFF + "&fmixcodes=" + fMixCodes;//&cacheclear=true";
			url="/includes/GetP2PData.asp?type=3&input=" + ch + "&AFF=" + AFF + "&fmixcodes=" + fMixCodes;//&cacheclear=true";
			//alert(url);					
			arrToCity=new Array();
			this.states = new Array();
			//xmlreq = getXMLHTTPRequest();			
			Xmlreq.open("GET", url, false);
			//Xmlreq.onreadystatechange = loadToCities;
			Xmlreq.send(null);
			//alert(XMLreq.status);
			if(Xmlreq.status == 200) 
		    {			
	     			var xml = Xmlreq.responseText;
				if (xml=='') arrToCity = new Array();			
				else arrToCity = xml.split(",");			
        	}
			//alert(arrToCity);
			for (var i=0; i < arrToCity.length; i++) 
			{
				this.states.push(arrToCity[i].replace("$$$",","));
				if (aSuggestions.length <= 15)aSuggestions.push(arrToCity[i].replace("$$$",","));
			}
		}
		else
		{										
			for (var i=0; i < this.states.length; i++)
			{
				aSuggestions.push(this.states[i]);
				if (aSuggestions.length > 15) break;
			}
		}								
	}
	if (sTextboxValue.length > 1)
	{
		//search for matching states												
		for (var i=0; i < this.states.length; i++) {

			strArrCity=this.states[i];
			
			strArrCity=strArrCity.toUpperCase();
								
			if (strArrCity.indexOf(sTextboxValue.toUpperCase()) == 0)
			{       
				aSuggestions.push(this.states[i]);
			}
			/*if (this.states[i].indexOf(sTextboxValue) == 0)
			{       
				aSuggestions.push(this.states[i]);
			}*/

			if (aSuggestions.length > 15) break;
		}
	}
	/*if (sTextboxValue.length > 0){
		//search for matching states
		for (var i=0; i < this.states.length; i++) {
			if (this.states[i].indexOf(sTextboxValue) == 0)
			{
				aSuggestions.push(this.states[i]);
			}
		}
	}*/
	//provide suggestions to the control
	//window.status = aSuggestions.length + " Cities found";
	oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
	}
	catch(e){ a=e;}
};