var xhrObj=false;function showWait(){if(divid){getEl(divid).innerHTML="<img src='images/status.gif'>";}}
var iRemoteProcedure=0;var tRemoteProcedures={};function RemoteProcedure(B,A,C){this.req=null;this.fnOnLoad=null;this.id=++iRemoteProcedure;tRemoteProcedures[this.id]=this;this.timer=null;this.call(B,A,C);}
RemoteProcedure.prototype.call=function(B,A,C){if(xhrObj&&xhrObj.readyState!=0){xhrObj.abort();}
this.fnOnLoad=A;this.fnOnPatience=C;this.timer=window.setTimeout("tRemoteProcedures["+this.id+"].showPatience()",500);var D=(B.indexOf("?")==-1?"?":"&")+"Rand="+Math.random();if(window.XMLHttpRequest){this.req=new XMLHttpRequest();this.req.onreadystatechange=new Function("tRemoteProcedures["+this.id+"].processReqChange()");this.req.open("GET",B+D,true);this.req.send(null);}else{if(window.ActiveXObject){this.req=new ActiveXObject("Microsoft.XMLHTTP");if(this.req){this.req.onreadystatechange=new Function("tRemoteProcedures["+this.id+"].processReqChange()");this.req.open("GET",B+D,true);this.req.send();}}}};RemoteProcedure.prototype.showPatience=function(){this.clearTimeout();if(this.fnOnPatience){this.fnOnPatience();}};RemoteProcedure.prototype.clearTimeout=function(){if(this.timer!=null){window.clearTimeout(this.timer);this.timer=null;}};RemoteProcedure.prototype.processReqChange=function(){if(this.req.readyState==4){this.clearTimeout();if(this.req.status==200||this.req.status==0){if(this.fnOnLoad){this.fnOnLoad(this.req);}}else{alert("Error "+this.req.status+"\n"+this.req.statusText+"\n\n"+this.req.responseText.replace(/\r\n/g,""));}}};function getEl(A){return document.getElementById(A);}
String.prototype.trim=function(A){A=this!=window?this:A;return A.replace(/^\s+/g,"").replace(/\s+$/g,"");};function AutoSuggestControl(B,C){this.fun=B;this.fld=C;var A="fld_"+C+"_name";this.textbox=getEl(A);this.suggestFld=A;var D="div_"+C+"_name";this.layer=getEl(D);this.cur=-1;this.init();}
AutoSuggestControl.prototype.init=function(){var A=this;this.textbox.onkeyup=function(B){if(!B){B=window.event;}
A.handleKeyUp(B);};this.textbox.onkeydown=function(B){if(!B){B=window.event;}
A.handleKeyDown(B);};};AutoSuggestControl.prototype.handleKeyUp=function(oEvent){var iKeyCode=oEvent.keyCode;if(iKeyCode==8||iKeyCode==46){eval("getSearchSuggestions_"+this.fun+"()");}else{if(iKeyCode<32||(iKeyCode>=33&&iKeyCode<46)||(iKeyCode>=112&&iKeyCode<=123)){}else{eval("getSearchSuggestions_"+this.fun+"()");}}};AutoSuggestControl.prototype.handleKeyDown=function(A){if(this.layer.style.display=="block"){switch(A.keyCode){case 38:this.previousSuggestion();break;case 40:this.nextSuggestion();break;case 13:this.hideSuggestions();break;}}};AutoSuggestControl.prototype.nextSuggestion=function(){if(this.layer.style.display=="block"){var B=this.layer.childNodes;if(B.length>0&&this.cur<B.length-1){var A=B[++this.cur];this.highlightSuggestion(A);var V=A.getElementsByTagName('font');if(V[0].childNodes[0].nodeValue!=null)
this.textbox.value=V[0].childNodes[0].nodeValue;if(A.lastChild.nodeValue!=null)
this.textbox.value+=A.lastChild.nodeValue;return false;}}};AutoSuggestControl.prototype.previousSuggestion=function(){var B=this.layer.childNodes;if(B.length>0&&this.cur>0){var A=B[--this.cur];this.highlightSuggestion(A);var V1=A.getElementsByTagName("font");if(V1[0].childNodes[0].nodeValue!=null)
this.textbox.value=V1[0].childNodes[0].nodeValue;if(A.lastChild.nodeValue!=null)
this.textbox.value+=A.lastChild.nodeValue;return false;}};AutoSuggestControl.prototype.highlightSuggestion=function(A){for(var B=0;B<this.layer.childNodes.length;B++){var C=this.layer.childNodes[B];if(C==A){C.className="currentsuggestitem";}else{if(C.className=="currentsuggestitem"){C.className="suggestitem";}}}};AutoSuggestControl.prototype.hideSuggestions=function(){eval("doBlurSuggestions_"+this.fun+"()");this.cur=-1;};AutoSuggestControl.prototype.disable=function(){eval("doBlurSuggestions_"+this.fun+"()");this.textbox.onkeyup=null;};var suggestBox;var suggestCharLenght=3;var arrSearchOptions=new Array();function closedropdown(A){document.getElementById(A).style.display="none";}
function opendropdown(A){document.getElementById(A).style.display="block";}
function doDisableSuggestions(){suggestBox.disable();}
function initSuggestions_FromStation(){suggestBox=new AutoSuggestControl("FromStation","search_options");}
function fldOnBlur_FromStation(C){var D="fld_"+C+"_name";var A="fld_"+C+"_id";var B;B=arrSearchOptions[getEl(D).value.toLowerCase()];if(B){getEl(A).value=B;}else{}}
function doBlurSuggestions_FromStation(){hideSearchOptionsSuggestions_FromStation();}
function getSearchSuggestions_FromStation(){doBlurSuggestions_FromStation();type=1;search_text=getEl("fld_search_options_name").value.trim();if(search_text.length>=suggestCharLenght){process_FromStation(search_text);}else{getEl("div_search_options_name").innerHTML="";}}
function process_FromStation(A){var C="http://bus-tickets.rediff.com/suggest_stats.php?stat="+A;var B=new RemoteProcedure(C,formatSearchOptions_FromStation,showWaitProcess_FromStation);}
function showWaitProcess_FromStation(){getEl("div_search_options_name").innerHTML="<img src='images/loading.gif'/>loading...";}
function formatSearchOptions_FromStation(B){search_text=getEl("fld_search_options_name").value.trim();var n=search_text;if(B.responseText){var A="";actb_hStyle='font-size:14px;font-family:Arial;text-decoration:underline;font-weight:bold';actb_curr=getEl("fld_search_options_name").value.length;retVal=B.responseText;var test_reg=false;keyVal=retVal.split("|");for(i=0;i<keyVal.length;i++){if(keyVal[i].trim()!=""){var tobuild="";myString=new String(keyVal[i]);if(test_reg){var re=new RegExp("^"+search_text,"i");}
else{var re=new RegExp(search_text,"i");}
var p=myString.search(re);var plen=actb_curr;for(j=0;j<p;j++){tobuild+=myString.substr(j,1);}
tobuild+="<font style='"+(actb_hStyle)+"'>";for(m=p;m<plen+p;m++){tobuild+=myString.substr(m,1);}
tobuild+="</font>";for(n=plen+p;n<myString.length;n++){tobuild+=myString.substr(n,1);}
A+='<div class="suggestitem "  onClick="populateSearchField_FromStation(\''+keyVal[i]+"');\" >"+tobuild+"</div>";}}
opendropdown("div_search_options_name");opendropdown("iframe_search_options_name");getEl("div_search_options_name").innerHTML=A+getEl("temp_search_options_footer").innerHTML;getEl("div_search_options_name").style.width=(parseInt(getEl("fld_search_options_name").offsetWidth)-2)+"px";getEl("iframe_search_options_name").style.height=getEl("div_search_options_name").offsetHeight+"px";getEl("iframe_search_options_name").style.width=getEl("div_search_options_name").offsetWidth+"px";}}
function populateSearchField_FromStation(A){getEl("fld_search_options_name").value=A;doBlurSuggestions_FromStation();}
function hideSearchOptionsSuggestions_FromStation(){if(getEl("iframe_search_options_name")){closedropdown("iframe_search_options_name");}
if(getEl("div_search_options_name")){closedropdown("div_search_options_name");}}
function initSuggestions_ToStation(){suggestBox=new AutoSuggestControl("ToStation","search_options2");}
function fldOnBlur_ToStation(C){var D="fld_"+C+"_name";var A="fld_"+C+"_id";var B;B=arrSearchOptions[getEl(D).value.toLowerCase()];if(B){getEl(A).value=B;}else{}}
function doBlurSuggestions_ToStation(){hideSearchOptionsSuggestions_ToStation();}
function getSearchSuggestions_ToStation(){doBlurSuggestions_ToStation();type=1;search_text=getEl("fld_search_options2_name").value.trim();if(search_text.length>=suggestCharLenght){process_ToStation(search_text);}else{getEl("div_search_options2_name").innerHTML="";}}
function process_ToStation(A){var C="http://bus-tickets.rediff.com/suggest_stats.php?stat="+A;var B=new RemoteProcedure(C,formatSearchOptions_ToStation,showWaitProcess_ToStation);}
function showWaitProcess_ToStation(){getEl("div_search_options2_name").innerHTML="<img src='images/loading.gif'/>loading...";}
function formatSearchOptions_ToStation(B){search_text=getEl("fld_search_options2_name").value.trim();var n=search_text;if(B.responseText){var A="";var test_reg=false;retVal=B.responseText;keyVal=retVal.split("|");actb_hStyle='font-size:14px;font-family:Arial;text-decoration:underline;font-weight:bold';actb_curr=getEl("fld_search_options2_name").value.length;for(i=0;i<keyVal.length;i++){if(keyVal[i].trim()!=""){var tobuild="";myString=new String(keyVal[i]);if(test_reg){var re=new RegExp("^"+search_text,"i");}
else{var re=new RegExp(search_text,"i");}
var p=myString.search(re);var plen=actb_curr;for(j=0;j<p;j++){tobuild+=myString.substr(j,1);}
tobuild+="<font style='"+(actb_hStyle)+"'>";for(m=p;m<plen+p;m++){tobuild+=myString.substr(m,1);}
tobuild+="</font>";for(n=plen+p;n<myString.length;n++){tobuild+=myString.substr(n,1);}
A+='<div class="suggestitem "  onClick="populateSearchField_ToStation(\''+keyVal[i]+"');\" >"+tobuild+"</div>";}}
opendropdown("div_search_options2_name");opendropdown("iframe_search_options2_name");getEl("div_search_options2_name").innerHTML=A+getEl("temp_search_options2_footer").innerHTML;getEl("div_search_options2_name").style.width=(parseInt(getEl("fld_search_options2_name").offsetWidth)-2)+"px";getEl("iframe_search_options2_name").style.height=getEl("div_search_options2_name").offsetHeight+"px";getEl("iframe_search_options2_name").style.width=getEl("div_search_options2_name").offsetWidth+"px";}}
function populateSearchField_ToStation(A){getEl("fld_search_options2_name").value=A;doBlurSuggestions_ToStation();}
function hideSearchOptionsSuggestions_ToStation(){if(getEl("iframe_search_options2_name")){closedropdown("iframe_search_options2_name");}
if(getEl("div_search_options2_name")){closedropdown("div_search_options2_name");}}