function checkFields(){var radtripType,deptCity,arrCity,deptDate,adult,child,infant;var fromcity=document.getElementById("selorigin").value;var tocity=document.getElementById("seldestination").value;deptDate=document.forms[0].departureDate.value;if(fromcity=="0"&&tocity=="0"){alert("Origin and destination cities cannot be left blank");document.getElementById("selorigin").focus();return false;}
if(fromcity=="0"){alert("Origin city cannot be left blank");document.getElementById("selorigin").focus();return false;}
if(tocity=="0"){alert("Destination city cannot be left blank");document.getElementById("seldestination").focus();return false;}
if(fromcity==tocity){alert("Origin and destination cities cannot be same");return false;}
if(!isValidDate(deptDate)){var departureElement=document.getElementById("arrDateOway");alert("Please select the departure date");departureElement.focus();return false;}
if(document.getElementById("emailId")!=null){emailId=document.getElementById("emailId").value;if(emailId!="To get discount coupons later"){if(!checkEmail(emailId)){alert("Please enter a valid email Id !!");document.getElementById("emailId").focus();return false;}}}
var totalPassenger=parseInt(adult)+parseInt(child)+parseInt(infant);if(parseInt(adult)<parseInt(infant)){var departureElement=document.getElementById("selnoOfAdults");alert("Number of infants can not be more than number of adults.");departureElement.focus();return false;}
if(totalPassenger>6){var departureElement=document.getElementById("selnoOfAdults");alert("Total number of passengers exceeded the maximum allowed limit of 6");departureElement.focus();return false;}
var departureElement=document.getElementById("departure");var arrivalElement=document.getElementById("arrival");document.getElementById("defaultsuggestions").style.display='none';updateInterstatial();document.getElementById("body").style.display="none";document.getElementById("header").style.display="none";document.getElementById("footer").style.display="none";document.getElementById("interstatial").style.display="block";document.getElementById("interstatialheading").style.display="block";try{if(document.getElementById("bodybg")){document.getElementById("bodybg").style.background="#e2f4ff";}}
catch(excep){}
document.forms[0].submit();}
function isValidDate(val){var dateVal=getDateFromFormat(val,'dd/MM/yyyy');if(dateVal==0)return false;else return true;}
function updateInterstatial(){var getFromCity=document.forms[0].departure.value.split(',');var fromCity=getFromCity[1];var getToCity=document.forms[0].arrival.value.split(',');var toCity=getToCity[1];document.getElementById("source").innerHTML=fromCity;document.getElementById("destination").innerHTML=toCity;var dep=formatDate(new Date(getDateFromFormat(document.forms[0].departureDate.value,'dd/MM/yyyy')),'dd-MMM-yyyy');document.getElementById("departDateDiv").innerHTML=dep;}
function setSEOParamSource(){var args=getURLArguments(document.location.href);var originDest=args['bus'];var origin;var x=document.getElementById("selorigin");if(originDest!=null&&originDest!=""){var arr=originDest.split("To");origin=arr[0];for(i=0;i<x.length;i++){if(x.options[i].text==origin){document.getElementById("selorigin").value=x.options[i].value;break;}}}else{document.getElementById("selorigin").value="1092,Bangalore";}}
function setSEOParamDest(){var args=getURLArguments(document.location.href);var originDest=args['bus'];var dest;if(originDest!=null&&originDest!=""){var arr=originDest.split("To");dest=arr[1];var y=document.getElementById("seldestination");for(i=0;i<y.length;i++){if(y.options[i].text==dest){document.getElementById("seldestination").value=y.options[i].value;break;}}}else{document.getElementById("seldestination").value="1159,Chennai";}}
function getURLArguments(url){var args={};var query_str=url.substring(url.indexOf('?')+1);var args_arr=query_str.split('&');for(var i=0;i<args_arr.length;i++){var arg_arr=args_arr[i].split('=');args[arg_arr[0]]=unescape(arg_arr[1]);}return args;}
function trim(stringToTrim){return stringToTrim.replace(/^\s+|\s+$/g,"");}
function closebox(){document.getElementById('fade').style.display='none';document.getElementById('box').style.display='none';document.getElementById('filter').style.display='none';document.getElementById("selorigin").style.display="block";document.getElementById("seldestination").style.display="block";document.getElementById("overlay_selorigin").style.display="none";document.getElementById("overlay_seldestination").style.display="none";document.getElementById("footer").disabled=false;document.getElementsByTagName('body')[0].style.overflow='auto';}
function bpclosebox(){bpboxcontent.scrollTop=0;document.getElementById('fade').style.display='none';document.getElementById('bpbox').style.display='none';document.getElementById('bpfilter').style.display='none';document.getElementById("selorigin").style.display="block";document.getElementById("seldestination").style.display="block";document.getElementById("overlay_selorigin").style.display="none";document.getElementById("overlay_seldestination").style.display="none";document.getElementById("footer").disabled=false;document.getElementsByTagName('body')[0].style.overflow='auto';}
function tripType(){document.getElementById('oTrip').checked=true;}
function weekend()
{var weekend=new Date();var weekday=new Array(7);weekday[0]="Sunday";weekday[1]="Monday";weekday[2]="Tuesday";weekday[3]="Wednesday";weekday[4]="Thursday";weekday[5]="Friday";weekday[6]="Saturday";while(weekday[weekend.getDay()]!="Saturday")
{weekend.setDate(weekend.getDate()+1);}
var datedigit=weekend.getDate();var monthdigit=(weekend.getMonth()+1);if(weekend.getDate()<10)
{datedigit="0"+weekend.getDate();}
if(weekend.getMonth()<10)
{monthdigit="0"+(weekend.getMonth()+1);}
var weekendDate=datedigit+"/"+monthdigit+"/"+weekend.getFullYear();return weekendDate;}
function trip(ori,dest){document.getElementById('selorigin').value=ori;document.getElementById('seldestination').value=dest;document.getElementById('RFromDateDispCalBelow').value=weekend();checkFields();}
function clickEmailText()
{var email_text=document.getElementById('emailId').value;if(email_text==""||email_text==null)
document.getElementById('emailId').value="To get discount coupons later";if(email_text=="To get discount coupons later")
document.getElementById('emailId').value="";}
function setEmailText(){document.getElementById('emailId').value="To get discount coupons later";}
function clickEmailText1(){var email_text=document.getElementById('usrMail').value;if(email_text==""||email_text==null)Document.getElementById('usrMail').value="Enter your booking email id";if(email_text=="Enter your booking email id")Document.getElementById('usrMail').value="";}
function setEmailText1(){document.getElementById('usrMail').value="Enter your booking email id";}
function clickPNRText(){var pnrTxt=document.getElementById('mmtPnr').value;if(pnrTxt==""||pnrTxt==null)
document.getElementById('mmtPnr').value="Enter your mmt pnr no";if(pnrTxt=="Enter your mmt pnr no")
document.getElementById('mmtPnr').value="";}
function submitForm(){if(!checkPNR(document.getElementById('mmtPnr').value)){alert("Please enter a valid PNR Number.");return false;}
if(document.getElementById('mmtPnr').value.length<7){alert("Please enter a valid PNR Number.");return false;}
if(!checkPNRPatt(document.getElementById('mmtPnr').value.substring(0,7))){alert("Please enter a valid PNR Number.");return false;}
if(document.getElementById('usrMail').value!=''&&document.getElementById('usrMail').value!=null&&document.getElementById('usrMail').value!='Enter your booking email id'){if(!checkEmail(document.getElementById('usrMail').value)){alert("Please enter a valid Email address");return false;}}
document.getElementById('intlLP').action="http://bustickets.makemytrip.co.in/BusIntegration/busbooking.htm?_flowId=bus-retreive-flow";document.getElementById('userEmail').value=document.getElementById('usrMail').value;document.getElementById('userPnrNo').value=document.getElementById('mmtPnr').value;document.forms[0].submit();}
function checkEmail(emailField){var emailpat=/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;if(!emailpat.test(emailField)){return false;}
return true;}
function checkPNR(pnr){var pnrpat=/^([a-zA-Z0-9])+$/;if(!pnrpat.test(pnr)){return false;}
return true;}
function checkPNRPatt(pnrStr){var pnrPattern='BUS5000';if(pnrStr!=pnrPattern){return false;}
return true;}
function toggleTicketDiv(){var box=document.getElementById('box');var title=document.getElementById('boxtitle');title.innerHTML="Enter your booking details";var content=document.getElementById('retTktBoxContent');content.style.padding="0";var status="<table width='100%' border='0' align='center'><tr><td width='2%'></td><td width='96%'>";status=status+"<table width='100%' border='0' bgcolor='' class='user-info-new style='border-top: thin'><tr><td><strong><font size='1'><br>Please enter your MMT PNR No and Email Address to get your booking details <br></font> </strong></td> </tr><tr><td><b>MakeMyTrip PNR No*: </b><input type='text' id='mmtPnr' name='mmtPnr' value='Enter your mmt pnr no' Style='color:#696969;' size='25' onBlur='clickPNRText();' onFocus='clickPNRText();' /></td> </tr><tr><td>                     <b> Email ID: </b><input type='text'  id='usrMail' name='usrMail' value='Enter your booking email id' size='25' Style='color:#696969;' onBlur='clickEmailText1();' onFocus='clickEmailText1();'/> <input type='image' src='http://www.makemytrip.com/bus-tickets/images/submit.gif'  width='85px' border='0' align='middle' onclick='submitForm();' style='cursor:pointer'/> </td></tr></table>";status=status+"</td><td width='2%'></td></tr></table>";content.innerHTML=status;document.getElementsByTagName('body')[0].style.overflow='hidden';document.getElementById('box').style.display='block';document.getElementById('fade').style.display='block';document.getElementById('circleanim').style.display="block";document.getElementById('circleanim').style.position='absolute';document.getElementById('circleanim').style.left=500;document.getElementById('circleanim').style.top=100;document.getElementById("selorigin").style.display="none";document.getElementById("seldestination").style.display="none";document.getElementById("overlay_selorigin").style.display="block";document.getElementById("overlay_seldestination").style.display="block";}
function goToURL(url){newWin=open(url);}
function signoutFun(){var adj=new Date();document.forms[0].action="signout.do?adj="+adj;document.forms[0].submit();}
var chkRememberLoginFlag="";var userLoginId="";var userLoginPwd="";var userLoginName="";var chkUserLoginSession="";var cookie=document.cookie.split(';');var individual_cookie=new Array();for(var i=0;i<cookie.length;i++){individual_cookie=cookie[i].split(',');for(var j=0;j<individual_cookie.length;j++){loginDtls=individual_cookie[j].split('=');for(var k=0;k<loginDtls.length;k++){if(loginDtls[k].toString()=="chkRememberLoginFlag"||loginDtls[k].toString()==" chkRememberLoginFlag"){chkRememberLoginFlag=loginDtls[k+1];}
if(loginDtls[k].toString()=="chkUserLoginSession"||loginDtls[k].toString()==" chkUserLoginSession"){chkUserLoginSession=loginDtls[k+1];}
if(loginDtls[k].toString()=="userLoginId"||loginDtls[k].toString()==" userLoginId"){userLoginId=loginDtls[k+1];}
if(loginDtls[k].toString()=="userLoginPwd"||loginDtls[k].toString()==" userLoginPwd"){userLoginPwd=loginDtls[k+1];}
if(loginDtls[k].toString()=="userLoginName"||loginDtls[k].toString()==" userLoginName"){userLoginName=loginDtls[k+1];}}}}
function setDate(){deptDate=documentElemnentById("arrDateOway").value;documentElemnentById("departureDate").value=deptDate;}