﻿
// JScript File
//* * * * * * * * * resources/schedule.en.js starts here  * * * * * * * * * * *//


var rskey_amtime="AM";
var rskey_pmtime="PM";

//used in agency search by city popup
var rskey_noagencyfound='No Agencies Found';
var rskey_searchagencybycity='Search Agencies by City';
var rskey_city='City';
var rskey_go='Go';
var rskey_searchbycitylink='Search';
var rskey_selectacity='Select a City';
//used  in route list
var rskey_routemodelightrail='Light Rail';
var rskey_routemodebus='Bus';
var rskey_routemodetrain='Rail';
var rskey_routemodeferryboat='Ferryboat';
var rskey_routemodeunknown='Unknown';
var rskey_schedulerouteselector="Agency Schedule and Route Selector";
var rskey_routespecificschedule="Schedules";
var rkey_schedules="Schedules";
var rskey_scheduleagencytitle="Schedule and Route Maps";
var rskey_fareagencytitle="Fares";
var rskey_agencyprofileagencytitle="Profile";
var rskey_externalagencytitle="External Website Link";
var rskey_route="Route";
var rskey_routetooltip='Click "..." for full route name';
var rskey_routelistmapcolumnheader="Preview <br/>route map:";
var rskey_routelistschedulecolumnheader="Click route names for schedules:";
//used in agency profile tab
var rskey_agency="Agency";
var rskey_agencyselector="Agency Profile Selector";
var rskey_agencyuploadcontentarea ="Additional Map Files & Info";
var rskey_agencycontent="Agency Content";
var rskey_agencycontentdescription="Information and map files in this dropdown box";
rskey_agencycontentdescription+=" are created by the transit provider, and then uploaded to the";
rskey_agencycontentdescription+=" 511 Transit website.This information is separate from that created by";
rskey_agencycontentdescription+=" 511 Transit (using transit provider data) on this website."
var rskey_selectagencycontenttitle="Select Agency Provided Files";
var rskey_selectagencycontent="Select a File";
var rskey_agencyprofile="Agency Profile";
var rskey_description ='Description';
var rskey_website ='Website';
var rskey_email = 'Email';
var rskey_address = 'Address';
var rskey_serviceaccessibility = 'Service Accessibility';
var rskey_moreinformation ='More Information';
var rskey_mostuptodate1='The most up-to-date contact information';
var rskey_modtuptodate2=' is available on the website for ';
var rskey_agencyuploadnocontentmsg ="No additional map file or downloadable information";
rskey_agencyuploadnocontentmsg+=" has been made available by this transit provider";
//used in fare tab
var rskey_fareselector="Agency Fares Selector";
var rskey_fares="Fares";
var rskey_specificfares="Fares";
var rskey_farefrom ='From';
var rskey_fareto ='To';
var rskey_fareenter="Enter";
var rskey_altfaresearch="search fares by zones"
var rskey_zoneoptionvalue='Select Zone/Station';
var rskey_faretype="Fare Type";
var rskey_fare="Fare";
var rskey_instructions="Instructions";
var rskey_msgfareunavailable="No fares available for selected criteria.";
var rskey_msgselectfromzone="Please choose an origin fare zone from list to process your request.";
var rskey_msgselecttozone="Please choose a destination fare zone from list to process your request.";
var rskey_zonemaptitle='click here to get zone maps';
var rskey_zonemaplink="View Fare Zones Map";
var rskey_zonemapconfirmmsg="This will cause the map to reload and you need to reselect the route line that you are currently looking.Do you want to proceed?";
var rskey_translink="TRANSLINK";

//used in announcement tab
var rskey_announcements="Announcements";
var rskey_routeannouncements="Route Announcements";
var rskey_specificannouncements="Announcements";
var rskey_agencyannouncements ="Agency Announcements";
var rskey_regionalannouncements="Regional Announcements";
var rskey_msgannouncementunavailable="No announcements";
var rskey_scheduleannouncements="Schedule Announcements";
var rskey_moreinfo="More Info";
//used in schedule div
var rskey_displayroutemaplink="Show Route Map and Schedule Selector";
var rskey_schedulefullview="Click here for full view";
var rskey_altclose="Close";
var rskey_printcustomizedschedule="Print Customized Schedule"
var rskey_printcustomizedschedulewithmap="Print Customized Schedule with Map"
var rskey_effective="Effective";
var rskey_effectivedate="Effective Date";
var rskey_between="Between";
var rskey_and= "And"
var rskey_holidayheader ="Holiday Schedule";
var rskey_holidayschedule ="Holiday Schedules";
var rskey_displayraillinediagram="Display Rail Line Info";
var rskey_printschedulewithoutmap="Print Schedule";
var rskey_printschedulewithmap="Print Schedule with Map"
var rskey_printschedulepdf="Print Schedule (pdf)";
var rskey_directions="Direction";
var rskey_type="Type";
var rskey_refreshschedule="Update";
var rskey_customizeschedule="Customized Schedule";
var rskey_showmap="Show Route Map";
var rskey_show="Show";
var rskey_msgscheduleunavailable="No schedules available for selected criteria.";
var rskey_msgscheduleinstruction="Select the stops that you would like to see on your customized schedule";
rskey_msgscheduleinstruction+=" by selecting any of the checkboxes above the stop names. Then enter the From";
rskey_msgscheduleinstruction+=" and To times for the window of time you would like displayed on your schedule.";
var rskey_schedulefrom="From";
var rskey_scheduleto="To";
var rskey_displaycustomizedschedule="Display Customized Schedule";
var rskey_returnredisplayfullschedule="Return and Redisplay Full Schedule";
var rskey_msgschedulecorrecttime="The TIME is invalid -- please correct using the format hh:mm";
var rskey_msgscheduleselectrow="Select 2 or more stop names to include on your customized";
rskey_msgscheduleselectrow+="schedule display, and then click the Display Customized Schedule button again.";
var rskey_routeannounceflasher='There are announcements for this route – please click the “Announcements” link below to view';
var rskey_comingsoon="Coming Soon";
var rskey_closemap="Close Map";
var rskey_selectanotherroute="Select Another Route";
var rskey_clearroutepreview="Clear route line previews";

//used in rail line
var rskey_displayfullschedule="Display Full Schedule";
var rskey_raillinefullview="Click here for full view";
var rskey_station="Station/Stop";
var rskey_busconnection="Bus Connections";
var rskey_railconnection="Rail & Ferry Connections";
var rskey_accessfeatures="Key - Access Features";
var rskey_handicapaccess="Handicap Accessible";
var rskey_elevator="Elevator";
var rskey_escalator="Escalator";
var rskey_phone="TDD Phone";
var rskey_cycling="Cycling";
var rskey_parking="Parking";
var rskey_key="Key";
var rskey_access="Access Features";


//used in map
var rskey_mapheaderforroute="Route";
var rskey_clearmap="Clear Map";
var rskey_routeviewmap="Full View";
var rskey_mapheaderdefault="Locations can be selected by clicking on the map";
var rskey_printmap="Print Map";
var rskey_scheduleroutemap="Schedules and Route Maps";
var rskey_enlargemap="Enlarge map";
var rskey_reducemap="Reduce map";
var rskey_noroutemessage=" ! Map for this route is unavailable";
var rskey_maptimeout="Mapping Application has timed out. Click OK to reload application  or Cancel to disable mapping."
var rskey_mapheaderservicearea = "Service Area";
var rskey_mapheaderfarezone = "Fare Zones";
//used for maptips
var rskey_tel = "Tel:";
var rskey_511 = "511";
var rskey_website = "Website";
var rskey_agencymaptiptitle = "Service Area Boundary";
var rskey_maplegends="View Legend";

//used in help

var rskey_altHelp="Help";
var rskey_scheduleagencylisthelpheader="Agency Schedule and Route Maps Selector";
var rskey_fareagencylisthelpheader="Agency Fares Selector";
var rskey_agenycprofileagencylisthelpheader="Agency Profile Selector";
var rskey_maphelpheader="Help using the maps";
var rskey_routeslisthelpheader="Schedules and Route Maps";
var rskey_schedulelisthelpheader="Route Schedule page";
var rskey_agencyprofilehelpheader="Agency Profile";
var rskey_additionalmapfilehelpheader="Additional Map Files & Info";



//used in printing pages
var rskey_scheduletable="Schedule Table";
var rskey_customizedscheduletable="Customized Schedule Table";
var rskey_printuserselections="User Selections";
var rskey_printagency ="Agency";
var rskey_printroute="Route";

//* * * * * * * * * respources/schedule.en.js ends here  * * * * * * * * * * *//


//* * * * * * * * * datafunctions_schedules.js starts here  * * * * * * * * * * *//

// JScript File
//Global Variable

var glb_routeslist;
var glb_agencyprofile;
var glb_farezones;
var glb_farelist;
var glb_farefromzone;
var glb_faretozone;
var glb_announcement;
var glb_scheduleOptionlist;
var glb_routeSelectedID;
var glb_scheduleStoplist;
var glb_scheduleCustomize;
var glb_scheduleDirection;
var glb_scheduleType;
var glb_scheduleStartStopID;
var glb_scheduleEndStopID;
var glb_railLineDetails;
var glb_schedulefromtime;
var glb_scheduletotime;


//*********************************Starts Here:Reset Data Objects Variables*********************

function resetdataobjects()
{

    glb_routeslist = null;
    glb_agencyprofile = null;
    glb_farezones = null;
    glb_farelist = null;
    glb_routeSelectedID = null;
    glb_farefromzone =null;
    glb_faretozone=null;
    glb_announcement=null;
    glb_scheduleOptionlist = null;
    glb_scheduleStoplist=null;
    glb_scheduleCustomize=null;
    glb_scheduleDirection=null;
    glb_scheduleType=null;
    glb_railLineDetails=null;
    glb_schedulefromtime=null;
    glb_scheduletotime=null;
}

//*********************************Ends Here:Reset Data Objects Variables*********************


//*********************************Starts Here:Agency profile by agencyid *********************
function getAgenciesByCity(city,callbackfunction)
{

     $.ajax({
              type: "GET",
              data: "city=" + city ,
              url: agenciesbycity_servicepath,
              dataType: "json",
              success: function(agencylist)
              {
                  callbackfunction(agencylist);
              },
               
              error:  function () {
                        
                      //alert( "Error While Retrieving Agency profile : ");
                      var referencetext="ServiceError:"+  agenciesbycity_servicepath+"?city="+city;
                      logerror(null,window.location,"datafunctions_schedules.js","getAgenciesByCity",InfoAgenciesByCity,referencetext,city,"")
                      
               }
            });

}
function getAgency(agencyid,callbackfunction)
{
    try
    {
        if(glb_agencyprofile==null||glb_agencyprofile.ID!=agencyid){
        resetdataobjects();
        
              $.ajax({
              type: "GET",
              data: "cid=" + agencyid ,
              url: agencyprofile_servicepath,
              dataType: "json",
              success: function(agencyprofile){
                   SetAgencyProfile(agencyprofile);
                   callbackfunction(agencyprofile);
                  
               
               },
               
              error:  function () {
                        
                      //alert( "Error While Retrieving Agency profile : ");
                      var referencetext="ServiceError:"+  agencyprofile_servicepath+"?cid="+agencyid;
                      logerror(null,window.location,"datafunctions_schedules.js","getAgency",InfoAgency,referencetext,agencyid,"")
                      
               }
            });
          
          }
          else
          {
           callbackfunction(glb_agencyprofile);
          }  
    }
    catch(err)
    {
        logerror(err,window.location,"datafunctions_schedules.js","getAgency",ErrorWWWNonFatal,"",agencyid,"")
    }
    
    
    
}
function SetAgencyProfile(agencyprofile)
 {
    glb_agencyprofile=agencyprofile;
  
 }
 
 function getAgencyLogofilename()
 {
    var str_return=null;
       if(glb_agencyprofile.LogoFileName!=null)
       {
       str_return=glb_agencyprofile.LogoFileName;
       }
   return str_return;
 }
 
 function getAgencyName()
 {
     var str_return=null;
       if(glb_agencyprofile.Name!=null)
       {
       str_return=glb_agencyprofile.Name;
       }
   return str_return;
 }
 function getAgencyAddress()
 {
      var str_return=null;
           if(glb_agencyprofile.Address!=null)
           {
           str_return=glb_agencyprofile.Address;
           }
       return str_return;
 }
 function getAgencyPhone()
 {
      var str_return=null;
           if(glb_agencyprofile.InternalContactInformation!=null)
           {
           str_return=glb_agencyprofile.InternalContactInformation;
           }
       return str_return;
 }
 
 function getAgencyUseExternalInfo()
 {
     var bool_return=null;
   
    if (glb_agencyprofile.UseExternalInfo!=null)
    {
        bool_return=glb_agencyprofile.UseExternalInfo;
    }
   
   return bool_return;
     
  
 }
 
 function getAgencyProfileUrl()
 {
    var str_return=null;
    if (glb_agencyprofile.ProfileURL!=null)
    {
        str_return=glb_agencyprofile.ProfileURL;
    }
   return str_return;
     
  
 }
 
 function getAgencyMainUrl()
 {
 var str_return=null;
    if (glb_agencyprofile.MainURL!=null)
    {
        str_return=glb_agencyprofile.MainURL;
    }
   return str_return;
 }
 function getAgencyID()
 {
    return glb_agencyprofile.ID;
 }
 
 function getRelatedAgency(ID)
 {
    var str_relatedid='';
    if(ID=="AC")
    {
        str_relatedid="AD";
    }
    if(ID=="AD")
    {
        str_relatedid="AC";
    }
    return str_relatedid;
 }
 function getRelatedAgencyName(RelID)
 {
    var str_agencyname='';
    if(RelID=="AC")
    {
        str_agencyname="AC Transit (Local Service)";
    }
    if(RelID=="AD")
    {
        str_agencyname="AC Transit (Transbay service)";
    }
    return str_agencyname;
 }
//*********************************Ends Here:Agency profile by agencyid *********************


//*********************************Starts Here:Routes List by agencyid *********************

function getRoutesList(agencyid,callbackfunction)
{
    try
    {
         if(glb_routeslist==null)
            {
            
             
                 $.ajax({
                  type: "GET",
                  data: "cid=" + agencyid ,
                  url: routeslist_servicepath,
                  dataType: "json",
                  success: function(routeItems){
                     SetRoutesList(routeItems); 
                     callbackfunction(routeItems);
                    
                   },
                  error: function(){
                    // alert( "Error While Retrieving Routes List : ");
                     var referencetext="ServiceError:"+  routeslist_servicepath+"?cid="+agencyid;
                     logerror(null,window.location,"datafunctions_schedules.js","getRoutesList",PagesSchedulesRoutesMaps,referencetext,agencyid,"")
                       
                   }
                });
            }
            else
            {
              callbackfunction(glb_routeslist);
            }
        
    }
    catch(err)
    {
            logerror(err,window.location,"datafunctions_schedules.js","getRoutesList",ErrorWWWNonFatal,"",agencyid,"")
    }
   
   
  
     

}

function getRouteByDesignator(rted,agencyid,callbackfunction)
{


    try
    {
            
             
                 $.ajax({
                  type: "GET",
                  data: "rted="+rted+"&cid=" + agencyid ,
                  url: routesprofile_servicepath,
                  dataType: "json",
                  success: function(route){
                     callbackfunction(route);
                    
                   },
                  error: function(){
                    // alert( "Error While Retrieving Routes List : ");
                     var referencetext="ServiceError:"+  routesprofile_servicepath+"?rted="+rted+"&cid="+agencyid;
                     logerror(null,window.location,"datafunctions_schedules.js","getRouteByDesignator",PagesSchedulesRoutesMaps,referencetext,agencyid,"")
                       
                   }
                });
                        
        
    }
    catch(err)
    {
            logerror(err,window.location,"datafunctions_schedules.js","getRouteByDesignator",ErrorWWWNonFatal,"",agencyid,"")
    }
   


}



function SetRoutesList(routeItems)
 {
    glb_routeslist=routeItems;
 }

 function getSelectedRouteID()
{
    return glb_routeSelectedID;
}

function getSelectedRouteName(routeid)
{
  
  
     var str_return='';
     $(glb_routeslist).each(function(i){
        if(glb_routeslist[i].ID==routeid){
          // str_return= glb_routeslist[i].Designator;
         
            if(glb_routeslist[i].Name!='' && glb_routeslist[i].Name!=null)
            {
              // str_return += " - " + glb_routeslist[i].Name.substring(0,50);
               //str_return += " - " + glb_routeslist[i].Name;
               str_return=glb_routeslist[i].Name;
            }
           //return str_return;
           
        }
     });
    return str_return;
    
    
}
function getSelectedRouteDesignator(routeid)
{
 var str_return=null;
     $(glb_routeslist).each(function(i){
        if(glb_routeslist[i].ID==routeid){
           str_return= glb_routeslist[i].Designator;
           
        }
     });
    return str_return;
}
 
function getRouteModeByRouteID(routeid)
{
    var _routemode='';
   // var _agencymodeAerialTramway = 1 //'TR'//LighRail
   //var _agencymodePublico = 2 //'PB'//Bus
   //var _agencymodePersonalRapidTransit = 3 //'RT'//Bus
   //var _agencymodeOther = 4 //'OR'//Bus
   //var _agencymodeMultimode = 5 //'MM'//Bus
   //var _agencymodeMonorail = 6 //'MO'//Rail
   //var _agencymodeLightRail = 7 //'LR'//Rail
   //var _agencymodeJitney = 8 //'JT'//Bus
   //var _agencymodeInclinedPlane = 9 //'IP'//Unknown
   //var _agencymodeHeavyRail = 10 //'HR//Rail
   //var _agencymodeVanpool = 11 //'VP'//Bus
   //var _agencymodeTrolleybus = 12 //'TB'//Bus
   //var _agencymodeTrain = 13 //'T'//Rail
   //var _agencymodeCableCar = 14 //'CC'//Rail
   //var _agencymodeCommuterRail = 15 //'CR'//Rail;
   //var _agencymodeDemandResponsive = 16 //'DR'//Bus
   //var _agencymodeFerryboat = 17 //'F'//Ferry
   //var _agencymodeDualMode = 18 //'DM'//Unknow
   //var _agencymodeBus = 19 //'B'//Bus
   //var _agencymodeAutomatedGuideway = 20 //'AG'//Unknow
    
    $(glb_routeslist).each(function(i)
    {
        if(glb_routeslist[i].ID==routeid)
        {
          var _dataroutemode =glb_routeslist[i].Mode;
               if(_dataroutemode==1||_dataroutemode==6||_dataroutemode==7||_dataroutemode==10||_dataroutemode==13||_dataroutemode==14||_dataroutemode==15)   
               {
                    _routemode='rail';
               }
               if(_dataroutemode==2||_dataroutemode==3||_dataroutemode==4||_dataroutemode==5||_dataroutemode==8||_dataroutemode==11||_dataroutemode==12||_dataroutemode==16||_dataroutemode==19)   
               {
                    _routemode='bus';
               }
               if(glb_routeslist[i].Mode==17)   
               {
                    _routemode='ferry';
               }
              
         }
     });
    
    return _routemode;
    

}

function getRouteModeByModeID(modeid)
{
    var _routemode='';
        //Bus
       if(modeid=='2'){_routemode=rskey_routemodebus;}
       if(modeid=='3'){_routemode=rskey_routemodebus;}
       if(modeid=='4'){_routemode=rskey_routemodebus;}
       if(modeid=='5'){_routemode=rskey_routemodebus;}
       if(modeid=='8'){_routemode=rskey_routemodebus;}
       if(modeid=='11'){_routemode=rskey_routemodebus;}
       if(modeid=='12'){_routemode=rskey_routemodebus;}
       if(modeid=='16'){_routemode=rskey_routemodebus;}
       if(modeid=='19'){_routemode=rskey_routemodebus;}
       
       //train
       if(modeid=='6'){_routemode=rskey_routemodetrain;}
       if(modeid=='10'){_routemode=rskey_routemodetrain;}     
       if(modeid=='13'){_routemode=rskey_routemodetrain;}
       if(modeid=='14'){_routemode=rskey_routemodetrain;}
       if(modeid=='15'){_routemode=rskey_routemodetrain;}
       
       //Ferry
       if(modeid=='17'){_routemode=rskey_routemodeferryboat;}
        
       //Lightrail
       if(modeid=='1'){_routemode=rskey_routemodelightrail;}
       if(modeid=='7'){_routemode=rskey_routemodelightrail;}
     
       //unknown
       if(modeid=='9'){_routemode=rskey_routemodeunknown;}
       if(modeid=='18'){_routemode=rskey_routemodeunknown;}
       if(modeid=='20'){_routemode=rskey_routemodeunknown;}
        
   return _routemode;

}

function getRouteListDisplayOrder(mode)//this may get from service in future
{
    var _routemodedisplayorder='';
    if(mode=='bus')
    {
        _routemodedisplayorder='2,3,4,5,8,11,12,16,19,6,10,13,14,15,17,1,7,9,18,20'
    }
    
    if(mode=='rail')
    {
        _routemodedisplayorder='6,10,13,14,15,1,7,2,3,4,5,8,11,12,16,19,17,9,18,20'
    }
    
    if(mode=='ferry')
    {
        _routemodedisplayorder='17,2,3,4,5,8,11,12,16,19,6,10,13,14,15,1,7,9,18,20'
    }
    if(mode=='shuttle')
    {
        _routemodedisplayorder='2,3,4,5,8,11,12,16,19,6,10,13,14,15,17,1,7,9,18,20';
    }
     if(mode=='other')
    {
        _routemodedisplayorder='2,3,4,5,8,11,12,16,19,6,10,13,14,15,17,1,7,9,18,20';
    }
    return _routemodedisplayorder;
}

//*********************************Ends Here:Routes List by agencyid *********************


//*********************************Starts Here:Fares Zones by agencyid *********************



function getFares(agencyid,callbackfunction)
{
    try
    {

        if(glb_agencyprofile!=null)
         {
           if(glb_farezones==null&&glb_farelist==null)
             { 
               
                $.ajax({
                  type: "GET",
                  data: "cid=" + agencyid ,
                  url: farezones_servicepath,
                  dataType: "json",
                  success: function(zoneItems){
                       SetFareZones(zoneItems.Zones);
                        if(glb_farezones==''){glb_farezones=null;}
                                               
                           if(glb_farezones!=undefined)
                           {
                            callbackfunction(zoneItems.Zones,null,null,null)
                           }
                           else
                           {
                                if(glb_farelist==null){
                                   getFaresByAgency(agencyid,callbackfunction) 
                                }
                                else
                                {
                
                                  callbackfunction(null,glb_farelist,glb_farefromzone,glb_faretozone);  
                                }
                           }
                       
                       
                       
                   
                   },
                  error: function(){
                     //alert( "Error While Retrieving Fares Zones : ");
                     var referencetext="ServiceError:"+  farezones_servicepath+"?cid="+agencyid;
                     logerror(null,window.location,"datafunctions_schedules.js","getFares",InfoFare,referencetext,agencyid,"")
                   }
                });
             }
             else
             {
                callbackfunction(glb_farezones,glb_farelist,glb_farefromzone,glb_faretozone)
             }
          }   
                 

        }
        catch(err)
        {
                logerror(err,window.location,"datafunctions_schedules.js","getFares",ErrorWWWNonFatal,"",agencyid,"")
        }
                
 //$("#img_ajax_request").show();
  

}
function SetFareZones(zoneItems)
{
   
    glb_farezones=zoneItems;
  
}
function GetFareZones()
{
    return glb_farezones;
}
function SetFareList(farelist)
{
    glb_farelist=farelist;

}
function getFareZoneStationMapTip(agencyid)
{
    var str_return=null;
    if(agencyid == 'BA' || agencyid == 'CT'  )
    {
        str_return=true;
    }
    return str_return;
}
//*********************************Ends Here:Fares Zones by agencyid *********************


//*********************************Starts Here:Fares by agencyid *********************



function getFaresByAgency(agencyid,callbackfunction)
{
    try
    {
        if(glb_farelist==null)
         {
        
          $.ajax({
              type: "GET",
              data: "cid=" + agencyid ,
              url: faresbyagency_servicepath,
              dataType: "json",
              success: function(fareItems){
                      SetFareList(fareItems.Fares);
                      callbackfunction(null,fareItems.Fares,null,null);  
                      
               
               },
              error: function(){
                 //alert( "Error While Retrieving Fares By Agency : ");
                  var referencetext="ServiceError:"+  faresbyagency_servicepath+"?cid="+agencyid;
                  logerror(null,window.location,"datafunctions_schedules.js","getFaresByAgency",InfoFare,referencetext,agencyid,"")
               }
            });
        }
        else
        {
             callbackfunction(null,glb_farelist,null,null); 
        } 
    
    }
    catch(err)
    {
        logerror(err,window.location,"datafunctions_schedules.js","getFaresByAgency",ErrorWWWNonFatal,"",agencyid,"")
    }
     
}

//*********************************Ends Here:Fares by zone ids  *********************



//*********************************Starts Here:Fares by zone ids *********************



function getFaresByZones(fromzoneid,tozoneid,callbackfunction)
{
    try
    {
        if(glb_farefromzone!=fromzoneid||glb_faretozone!=tozoneid)
         {
         
          $.ajax({
              type: "GET",
              data: "FromZone=" + fromzoneid + "&ToZone=" + tozoneid ,
              url: faresbyzones_servicepath,
              dataType: "json",
              success: function(fareItems){
                  SetFareList(fareItems.Fares);
                  glb_farefromzone=fromzoneid;
                  glb_faretozone=tozoneid;
                  callbackfunction(glb_farezones,fareItems.Fares,fromzoneid,tozoneid);
                  
               },
              error: function(){
                 //alert( "Error While Retrieving Fares By Zones : ");
                   var referencetext="ServiceError:"+  faresbyzones_servicepath+"?FromZone=" + fromzoneid + "&ToZone=" + tozoneid;
                  logerror(null,window.location,"datafunctions_schedules.js","getFaresByZones",InfoFare,referencetext,getAgencyID(),"")
               }
            });
        }
        else
        {
            callbackfunction(glb_farezones,glb_farelist,glb_farefromzone,glb_faretozone);
        }
    
    }
    catch(err)
    {
            var referencetext="FromZone:"+fromzoneid+ ",ToZone:"+tozoneid;
            logerror(err,window.location,"datafunctions_schedules.js","getFaresByZones",ErrorWWWNonFatal,referencetext,getAgencyID(),"")
    }
    
     
}

//*********************************Ends Here:Fares by zone ids  *********************

//*********************************Starts Here:Announcements by Agency and Routes  *********************

function getAllAnnouncements(agencyid,routeid,callbackfunction)
{
    try
    {
            if(glb_announcement==null)
            {
                
                $.ajax({
                  type: "GET",
                  data: "type=carrier,route,important,schedule&cid=" + agencyid + "&routeId=" + routeid ,
                  url: annoucements_servicepath,
                  dataType: "json",
                  success: function(announcmentItems){
                      SetAnnouncements(announcmentItems);
                      callbackfunction(announcmentItems) ; 
                      
                   
                   },
                  error: function(){
                     //alert( "Error While Retrieving Announcments By Agencies : ");
                       var referencetext="ServiceError:"+  annoucements_servicepath+"?type=carrier,route,important,schedule&cid=" + agencyid + "&routeId=" + routeid;
                       logerror(null,window.location,"datafunctions_schedules.js","getAllAnnouncements",PagesSchedulesRoutesMaps,referencetext,agencyid,routeid)
                   }
                });
            }
            else
            {
               
                  callbackfunction(glb_announcement) ; 
               
            }

    }
    catch(err)
    {
            logerror(err,window.location,"datafunctions_schedules.js","getAllAnnouncements",ErrorWWWNonFatal,"",agencyid,routeid)
    }
        
}

function SetAnnouncements(announcmentItems)
{
    glb_announcement=announcmentItems;
    
}

function IsRouteAnnouncementsExists()
{
    var  bln_return =false;
    if(glb_announcement!=null)
    {
        if(glb_announcement.route.length>0)
        {
            bln_return=true;
        }
    }
    return bln_return;
}
//*********************************Ends Here:Anoucements  *********************

//*********************************Starts Here:Schedules  *********************

function getSchedules(rte,callbackfunction)
{
    try
    {
        if(glb_routeSelectedID!=rte||glb_scheduleOptionlist==null)
          {
           
            glb_routeSelectedID=rte;
            $.ajax({
              type: "GET",
              data: "rte=" + rte ,
              url: schedules_servicepath,
              dataType: "json",
              success: function(scheduleOptionItems){
                  SetScheduleList(scheduleOptionItems);
                  SetScheduleParam(null,null);
                  callbackfunction(scheduleOptionItems);
                  
               },
              error: function(){
                 //alert( "Error While Retrieving Schedules Directions and Types: ");
                  var referencetext="ServiceError:"+  schedules_servicepath+"?rte=" + rte;
                  logerror(null,window.location,"datafunctions_schedules.js","getSchedules",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),rte) 
               }
            });
           }
           else
           {
            //callbackfunction(glb_routeSelectedID);
            callbackfunction(glb_scheduleOptionlist);
           }
    
    }
    catch(err)
    {
        logerror(err,window.location,"datafunctions_schedules.js","getSchedules",ErrorWWWNonFatal,"",getAgencyID(),rte)
    }
  
  
   
    
}

function getschedulesStop(routeid,dir, type,callbackfunction)
{ 
    try
    {
        if(glb_scheduleDirection!=dir || glb_scheduleType!=type)
        {
          
           
              $.ajax({
                  type: "GET",
                  data: "rte=" + routeid +"&dir=" + dir +"&dayid="+ type ,
                  url: schedulesByStop_servicepath,
                  dataType: "json",
                  success: function(scheduleStopItems){
                      SetScheduleStopList(scheduleStopItems);
                      SetScheduleParam(dir,type);
                      SetRailLineDetails(null);
                      callbackfunction(scheduleStopItems);
                      
                  
                   },
                  error: function(){
                     //alert( "Error While Retrieving STOP Schedules: ");
                     var referencetext="ServiceError:"+  schedulesByStop_servicepath+"?rte=" + routeid +"&dir=" + dir +"&dayid="+ type;
                     logerror(null,window.location,"datafunctions_schedules.js","getschedulesStop",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),routeid) 
                   }
                });
         }
         else
         {
           callbackfunction(glb_scheduleStoplist); 
         }   
    
    }
    catch(err)
    {
            var referencetext="RouteID:"+ routeid + ",Dir:"+ dir + ",daytype:"+ type;
            logerror(err,window.location,"datafunctions_schedules.js","getschedulesStop",ErrorWWWNonFatal,referencetext,getAgencyID(),routeid)
    }
    
}

function getschedulesDataforMap(routeid,dir, type,callbackfunction)
{
    
    try
    {
       
              $.ajax({
                  type: "GET",
                  data: "rte=" + routeid +"&dir=" + dir +"&dayid="+ type ,
                  url: schedulesByStop_servicepath,
                  dataType: "json",
                  success: function(scheduleStopItems){
                      SetScheduleStopList(scheduleStopItems);
                      SetScheduleParam(dir,type);
                      callbackfunction();
                      
                  
                   },
                  error: function(){
                     //alert( "Error While Retrieving STOP Schedules: ");
                     var referencetext="ServiceError:"+  schedulesByStop_servicepath+"?rte=" + routeid +"&dir=" + dir +"&dayid="+ type;
                     logerror(null,window.location,"datafunctions_schedules.js","getschedulesDataforMap",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),routeid) 
                   }
                });
        
    
    }
    catch(err)
    {
            var referencetext="RouteID:"+ routeid + ",Dir:"+ dir + ",daytype:"+ type;
            logerror(err,window.location,"datafunctions_schedules.js","getschedulesStop",ErrorWWWNonFatal,referencetext,getAgencyID(),routeid)
    }

}

function SetScheduleList(schedulelist)
{
    glb_scheduleOptionlist=schedulelist;
}
function getScheduleParams()
{
    return glb_scheduleOptionlist;
}
function SetScheduleParam(dir,type)
{

    if(dir!=null&&type!=null)
    {
    
        glb_scheduleDirection=dir;
        glb_scheduleType=type;
        glb_scheduleStartStopID=glb_scheduleStoplist.StopTripList[0].StopID;
        glb_scheduleEndStopID=glb_scheduleStoplist.StopTripList[glb_scheduleStoplist.StopTripList.length-1].StopID;
    }
    else
    {
        glb_scheduleDirection=null;
        glb_scheduleType=null;
        glb_scheduleStartStopID=null;
        glb_scheduleEndStopID=null;
    }    
}

function getScheduleDirection()
{
    return glb_scheduleDirection;
}

function getScheduleDayType()
{
    return glb_scheduleType;
}
function SetScheduleStopList(scheduleStopItems)
{
    glb_scheduleStoplist = scheduleStopItems;
}

function getScheduleStartStop()
{
  
    return  glb_scheduleStartStopID;

}

function getScheduleEndStop()
{
  return glb_scheduleEndStopID;
  
}

function getStopName(stopid)
{
     for(var property in glb_scheduleStoplist.Stops)
        {
           if(property==stopid)
           {
            return glb_scheduleStoplist.Stops[property] ;
           } 
        }
} 
function getCustomizeSchedule(routeid,dir, type,stopids,fromtime,totime,callbackfunction)
{ 

    try
    {
        
          $.ajax({
              type: "GET",
              data: "rte=" + routeid +"&dir=" + dir +"&dayid="+ type+"&stops=" +stopids + "&fromtime="+ fromtime + "&totime="+ totime ,
              url: schedulescustomize_servicepath,
              dataType: "json",
              success: function(scheduleStopItems){
                  SetCustomizeScheduleList(scheduleStopItems)
                  SetCustomizeTime(fromtime,totime)
                  callbackfunction(scheduleStopItems);
                  
              
               },
              error: function(){
                 //alert( "Error While Retrieving Customize Schedules: ");
                  var referencetext="ServiceError:"+  schedulescustomize_servicepath+"?rte=" + routeid +"&dir=" + dir +"&dayid="+ type+"&stops=" +stopids + "&fromtime="+ fromtime + "&totime="+ totime ;
                  logerror(null,window.location,"datafunctions_schedules.js","getCustomizeSchedule",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),routeid) 
               }
            });
    
    }
    catch(err)
    {
            var referencetext="RouteID:"+ routeid + ",Dir:"+ dir + ",daytype:"+ type;
            referencetext += ",StopIDs:"+ stopids + ",FromTime:"+ fromtime + ",ToTime:"+ totime;
            logerror(err,window.location,"datafunctions_schedules.js","getCustomizeSchedule",ErrorWWWNonFatal,referencetext,getAgencyID(),routeid)
    }
      
       
  
}
function SetCustomizeScheduleList(schedulelist)
{
    glb_scheduleCustomize=schedulelist;
}

function SetCustomizeTime(fromtime,totime)
{
    glb_schedulefromtime=fromtime;
    glb_scheduletotime=totime;
}
function getCustomizeFromTime()
{
    return glb_schedulefromtime;
}
function getCustomizeToTime()
{
     return glb_scheduletotime;
}

//*********************************Ends Here:Schedules  *********************

//*********************************Rail Line Diagram **********************

function getRailLine()
{
return glb_railLineDetails;
}
 
function getRailLineDetails(rte,dir,callbackfunction)
{
    try
    {
        if(glb_routeSelectedID!=rte || glb_scheduleDirection!=dir||glb_railLineDetails==null)
          {
          
            glb_routeSelectedID=rte;
            glb_scheduleDirection=dir
            $.ajax({
              type: "GET",
              data: "rte=" + glb_routeSelectedID +"&dir=" + glb_scheduleDirection,
              url: railLine_servicepath,
              dataType: "json",
              success: function(railLineDetails){
                  SetRailLineDetails(railLineDetails);
                  callbackfunction(railLineDetails);
                   
               },
              error: function(){
                 //alert( "Error While Retrieving Rail Line Information: ");
                 var referencetext="ServiceError:"+  railLine_servicepath+"?rte=" + glb_routeSelectedID +"&dir=" + glb_scheduleDirection;
                 logerror(null,window.location,"datafunctions_schedules.js","getRailLineDetails",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),rte) 
               }
            });
           }
           else
           {
                callbackfunction(glb_railLineDetails);
           }
    }
    catch(err)
    {
            var referencetext="RouteID:"+ rte + ",Dir:"+ dir 
            logerror(err,window.location,"datafunctions_schedules.js","getRailLineDetails",ErrorWWWNonFatal,referencetext,getAgencyID(),rte)
    }
  
}

function SetRailLineDetails(railLineDetails)
{
    glb_railLineDetails=railLineDetails;
}

//*********************************Help From Resource Starts Here **********************
function getHelp(resourceids,lang,callbackfunction)
{
    try
    {
        $.ajax({
          type: "GET",
          data: "resourceids=" + resourceids+"&lang="+lang ,
          url: "gethelp.aspx",
          dataType: "text",
          success: function(helptext){
             callbackfunction(helptext)
           },
          error: function(){
             //alert( "Error While Retrieving Help:");
              
           }
        });
    
    }
    catch(err)
    {
        var referencetext="Help:"+  resourceids +",language:"+lang ;
        logerror(err,window.location,"datafunctions_schedules.js","getHelp",ErrorWWWNonFatal,referencetext,"","")
    }    
     
     
}


//*********************************Help From Resource Ends Here **********************

//* * * * * * * * * datafunctions_schedules.js ends here  * * * * * * * * * * *//


//* * * * * * * * * renderingfunctions_schedules.js starts here  * * * * * * * * * * *//

    // JScript File

    //constants
    var agency_logo_path="http://transit.511.org/static/providers/logos/";
    var agency_logo_maxwidth="200";
    var agency_logo_maxheight="165"
    var routeannoucement_flasher_path="http://images.transit.511.org/RUI/images/warning.gif"
    var validate_zonesselection=true;    
    var glb_customizedstopids;
    var glb_allstopids;
    var schedulenostopchar="--:--";
    //var schedulepdfprintlink="http://newmdvtest:mdv4test@80.154.30.149/newmdvtest/XSLT_REQUEST?itdLPxx_routeID="
    var schedulepdfprintlink="http://tripplanner.transit.511.org/mtc/XSLT_REQUEST?itdLPxx_routeID="
    var schedulemaindivid; 
    var blnannounceflashershown;
    var blnfromraillinebookmark;
    var bln_showroutecheckbox=true;
    var glb_routemaplist='';
    var glb_routemapcounter=0;
    //********************************* Starts Here:Schedules/Index.aspx  *********************


    //*********************************Starts Here:Rendering Routes List *********************

    function renderRoutesList(routesList,container_div,schedulescallback,hidecallback)
    {
        try
        {       
               //yz: 3294#
                var routelistdiv = document.getElementById("div_routesPanel");
                routelistdiv.scrollTop = 0;
                 
                glb_routemaplist='';
                glb_routemapcounter=0;
                $("#"+ container_div).empty();
                hideroutefullview();
                var route_text=''; 
                var routelength;
                var designatorlength;
                var previousroute_mode='';
                var presentroute_mode=''
                var mode_count=0;
                var modeids='';
                var _breaktag="<br>";
               
                $("<div id='div_routehelp' style='width:95%;text-align:right;padding:0 4px 0 0;'>"+
                "<a id='print_routes' href='javascript:void(0);'><b>Print</b></a>&nbsp;&nbsp;<a id='a_routelisthelp' href='javascript:void(0);' title='"+ rskey_altHelp +"'><img src='http://images.transit.511.org/RUI/images/help.jpg'"+
                "alt='Help' width='16' height='17' /></a></div>").appendTo("#"+ container_div);
                $("#a_routelisthelp").unbind("click").bind("click",
                function(event)
                {
                    function render_help(helpitem)
                    {
                        renderhelp(helpitem,rskey_routeslisthelpheader,event.pageX,event.pageY,"a_routelisthelp");
                    }
                    getHelp("routeslist","en",render_help);
                });    
               $("#print_routes").unbind("click").bind("click",function()
               {
                   window.open("printroutes.aspx?cid="+getAgencyID() ,null,MapWindowParams); 
               });
                
                var relatedagencyid=getRelatedAgency(getAgencyID());
                if(relatedagencyid!='')
                {
                
	                var related_text=getRelatedAgencyName(relatedagencyid)+ " " + rskey_routespecificschedule;
                  $("<span><a class='locRelatedItem' id='a_relatedroutelink' title='Click here to get "+  related_text +"' href='javascript:void(0);'>"+ 
                  related_text+ "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>").insertBefore("#print_routes");
                 
                    $("#a_relatedroutelink").unbind("click").bind("click",function()
                    {
                        appendtourl("m1=S&m2=" + glb_agency_mode + "&cid=" + relatedagencyid,true);
                    });

                  $(_breaktag).appendTo("#"+ container_div);
                }
                
               
                 $(routesList).each(function(i)
                 {
                  
                 
                  presentroute_mode=getRouteModeByModeID(routesList[i].Mode);
                  if(previousroute_mode!=presentroute_mode)
                  { 
                    mode_count++;
                    _breaktag="";
                    if(previousroute_mode!=''){_breaktag="<br></br>"};
                    $("<div id='div_routemode_"+ routesList[i].Mode +"'></div>").appendTo("#" +container_div);
                    $("<span id='span_routemode_"+ routesList[i].Mode+"' class='routeListModeHeader'>" +_breaktag+ presentroute_mode +"</span>").appendTo("#div_routemode_" +routesList[i].Mode);
                    previousroute_mode=presentroute_mode;
                    if(modeids=='')
                    {
                       modeids= routesList[i].Mode;
                    }
                    else
                    {
                       modeids+= "," + routesList[i].Mode;
                    }
                    if(bln_showroutecheckbox)
                    {
                         
                         if(i==0)
                         {
                          $("<div id='div_routecolumnheader' style='display:block'><span class='routeListColumnLabels'><br>"+rskey_routelistmapcolumnheader+"<span style='padding-left:50px'>&nbsp;</span>"+rskey_routelistschedulecolumnheader+"<br></span></div>").insertAfter("#div_routehelp");
                         }
                       
                    }
                    
                  }
                  
                   var route_checkboxhtml="";
                   var route_hiddencolorhtml="";
                   
                   if(bln_showroutecheckbox)
                    {
                       
                        route_checkboxhtml="&nbsp;<input style='cursor:default;' type='checkbox' id='chk_"+ routesList[i].ID + "' OnClick=showrouteslistmap('chk_"+routesList[i].ID+"','"+routesList[i].ID  +"','"+ glb_agency_id +"')>&nbsp;";
                        route_hiddencolorhtml="<div id='div_routecolorindicator_"+ routesList[i].ID+"' style='display:none; width:10px;height:8px;background-color:white'>&nbsp;&nbsp;&nbsp;&nbsp;</div>";
                        $("#routeslistmaplink").html("<a href='javascript:void(0);' id='a_routeslistmaplink' OnClick=clearroutelistmap()>"+ rskey_clearroutepreview +"</a>");
                        $("#routeslistmaplink").show();
                        $("#extSite").attr("style","font-size:10px;position:relative;left:190px;top:4px;width:290px;height:13px;");
                    }
                    else
                    {
                        $("#routeslistmaplink").hide();
                        $("#extSite").attr("style","font-size:10px;position:relative;left:190px;top:8px;width:290px;height:13px;");
                    }
                    if(routesList[i].Name!='' && routesList[i].Name!=null)
                    {
                            routelength= parseInt(routesList[i].Designator.length,10)+ 7 + parseInt(routesList[i].Name.length,10);
                            
                            if(routelength>65)
                            { 
                                
                                route_text = "<b>"+ $.trim(routesList[i].Designator) + "</b> - " + $.trim(routesList[i].Name) ;
                                route_text=route_text.substring(0,65) + " <a href='javascript:void(0);' title='"+ rskey_routetooltip+" ' style='text-decoration:none' "+
                                           "id='rt_" + routesList[i].ID +"_link_more'>...</a>";
                                $("<span class='locItem'>"+route_hiddencolorhtml+route_checkboxhtml+"<a id='rt_" + routesList[i].ID  + "_link' href='javascript:void(0);' style='text-decoration:none'>" + route_text  + "</a></span>").appendTo("#div_routemode_" + routesList[i].Mode);
                                 //$("#rt_" + routesList[i].ID  + "_link").attr("title",routesList[i].Name);
                                 $("#rt_" + routesList[i].ID  + "_link_more").unbind("click").bind("click",function(event)
                                    {
                                        showroutefullview(routesList[i].Name,rskey_route + " - " + $.trim(routesList[i].Designator),event.pageX,event.pageY);
                                        
                                    });
        //                            .unbind("mouseout").bind("mouseout",function(){
        //                                setTimeout ('$("#div_routes_description").hide();',250); 
        //                              });
                            }
                            else
                            {
                                 
                                 route_text = "<b>" + routesList[i].Designator + "</b> - " + routesList[i].Name;
                                 $("<span class='locItem'>"+route_hiddencolorhtml+route_checkboxhtml+"<a id='rt_" + routesList[i].ID  + "_link' href='javascript:void(0);' style='text-decoration:none'>" + route_text  + "</a></span>").appendTo("#div_routemode_" + routesList[i].Mode);
                            }
                            
                           
                          
                   } 
                   else
                   {
                        $("<span class='locItem'>"+route_hiddencolorhtml+route_checkboxhtml+"<a id='rt_" + routesList[i].ID  + "_link' href='javascript:void(0);' style='text-decoration:none'><b>" + routesList[i].Designator  + "</b></a></span>").appendTo("#div_routemode_" + routesList[i].Mode);
                   }
                   
                  
                   
                   $("#rt_" + routesList[i].ID  + "_link").unbind("click").bind("click",function()
                   {
                      
                      
                       closebusy();
                       $("#div_routes_description").hide();
                                                  
                       $("#" + container_div).find("a").attr("style","text-decoration:none");
                       $(this).attr("style","text-decoration:underline");
                       hidecallback();
                     
                       if(getSelectedRouteID()!=routesList[i].ID)
                        {
                             SetAnnouncements(null);
                        }              
                        bln_showroutecheckbox=false;
                        schedulescallback(routesList[i].ID,"","","");
                    });

                   
              });
              //if more than one mode is present than call the display divs based on mode order
               if(mode_count>1)
               {
                   listroutebymodeorder(modeids,container_div);
               }
               else
               {
                //hide the mode display if only one mode
                 $("#span_routemode_"+ modeids).hide();
               }
             
        
            
        
        
        }
        catch(err)
        {
         
          
           logerror(err,window.location,"renderingfunctions_schedules.js","renderRoutesList",ErrorWWWNonFatal,"",getAgencyID(),"")
        }
       
    }
    
   
    function listroutebymodeorder(modeids,container_div)
    {
        try
        {
        
               var routemode_order=getRouteListDisplayOrder(getagencymode());
               var prev_divid='';
               var present_divid='';
               if(routemode_order!='')
               {
                   var arr_routemodeorder=routemode_order.split(",");
                   var arr_modeids=modeids.split(",");
                    for(var idx=0;idx<arr_routemodeorder.length;idx++)
                     {
                         for(var jdx=0;jdx<arr_modeids.length;jdx++)
                         {
                            if(arr_routemodeorder[idx]==arr_modeids[jdx])
                            {
                                if(prev_divid=='')//make this div as first div in routelist
                                {
                                    prev_divid="div_routemode_" + arr_modeids[jdx];
                                   // $("#"+ prev_divid).prependTo("#"+ container_div); 
                                    $("#"+ prev_divid).insertAfter("#div_routecolumnheader"); 
                                    $("#span_routemode_"+ arr_modeids[jdx]).html(getRouteModeByModeID(arr_modeids[jdx]));
                                   
                                }
                                else
                                {
                                    present_divid= "div_routemode_" + arr_modeids[jdx];
                                    $("#"+ present_divid).insertAfter("#"+prev_divid);
                                    prev_divid=present_divid;
                                    $("#span_routemode_"+ arr_modeids[jdx]).html("<br></br>"+ getRouteModeByModeID(arr_modeids[jdx]));
                                   
                                }
                            break;    
                            }
                         }
                     }
               }
        
        
        
        }
        catch(err)
        {
           logerror(err,window.location,"renderingfunctions_schedules.js","listroutebymodeorder",ErrorWWWNonFatal,"",getAgencyID(),"")
        }
        
       
    }
    
    
    function hyperlinkselectedroute(routeid)
    {
        $("#rt_" + routeid +"_link").attr("style","text-decoration:underline");
    }

    function showroutefullview(strdescription,headertext,tPosX,tPosY)
    {
        try
        {

            $("body").find("#div_routes_description").remove();
            tPosX = tPosX +50;
            tPosY = tPosY-30 ;
            var routedescription_html='';
           
            routedescription_html="<div id='div_routes_description' style='position:absolute;z-index:888881'>";
            routedescription_html+="<table class='routepopupkeyTable' cellspacing='0'><tr><td class='boxTop'></td></tr>";
            routedescription_html+="<tr>";
            routedescription_html+="<td class='contentBox'>";
            routedescription_html+="<div class='closeBox' style='padding-right: 4px;'>";
            routedescription_html+="<a id='a_routesdescription_contentfullviewclose'  style='z-index:888888' href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
            routedescription_html+="</div><h1 class='ScheduleAnnounceHeader'>" + headertext+"</h1>";
            routedescription_html+="<div class='boxDivider'></div>" ;
            routedescription_html+="<div id='div_routesdescription_fullviewdata' class='routepopupListingdiv' ></div>"
            routedescription_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
            $(routedescription_html).appendTo("body")
            $('#div_routes_description').css({top: tPosY, left:tPosX});
            
            $("<table  width='100%' id='tbl_routesdescriptionfullview'  cellpadding='3'><tr><td colspan='2' width='100%'>&nbsp;</td></table>").appendTo("#div_routesdescription_fullviewdata");
            $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='routepopupdetail'>"+ strdescription +"</span>"+
            "</td></tr>").appendTo("#tbl_routesdescriptionfullview");
           
            
            $("#a_routesdescription_contentfullviewclose").unbind("click").bind("click",function()
            {
                //$("#div_annoucement_contentfullview").hide();
                hideroutefullview();
            });

        }
        catch(err)
        {
  	      	logerror(err,window.location,"renderingfunctions_schedules.js","showroutefullview",ErrorWWWNonFatal,headertext,getAgencyID(),"")
        }
          
          
       
          
    }
    
     function hideroutefullview()
     {
         $("body").find("#div_routes_description").remove();
     }
    
    //*********************************End Here:Rendering Routes List *********************


    //*********************************Starts Here: Rendering Agency Profile *********************

    function renderAgencyProfile(agencyprofile,container_div,closecallback)
    {
        try
        {
            
            
                var img_tag='';
                var imgPreview ;
                  if(agencyprofile.LogoFileName!=null&&agencyprofile.LogoFileName!='')
                  {
                           
                   img_tag="<img class='agencyImg' id='img_agencylogo' src='" + agency_logo_path  + agencyprofile.LogoFileName + "'  style='display:none' align='right'  border='0' alt='" + agencyprofile.Name + "'>";

                  } 

                $("#" + container_div).find("#div_agency_profile").remove();
                $("<div id='div_agency_profile'></div>").appendTo("#" + container_div);
                $("<div class='agencyDetailScroll' id='div_agency_profiledetial'><table width='98%' border='0' cellspacing='0' cellpadding='0'>" +
                "<tr><td class='agencyHeader'>&nbsp;</td>" +
                "<td class='agencyUtilities' align='right'><div class='helpIconDiv'>" +
                "<a id='a_agencyprofilehelp' href='javascript:void(0);' title='"+ rskey_altHelp +"'><img src='http://images.transit.511.org/RUI/images/help.jpg' alt='"+ rskey_altHelp+"'  border='0' /></a></div></td>"+
                "</tr><tr><td colspan='2' class='profiletopContent'><p class='agencyBlurb'>"+ img_tag + agencyprofile.Description +
                "</p></td></tr></table></div>").appendTo("#div_agency_profile");
                
                $("#a_agencyprofilehelp").unbind("click").bind("click",
                function(event)
                {
                    function render_help(helpitem)
                    {
                        renderhelp(helpitem,rskey_agencyprofilehelpheader,event.pageX,event.pageY,"a_agencyprofilehelp");
                    }
                    getHelp("agencyprofile","en",render_help);
                });    
                
                
                    

                $("<table id='agency_profile_table' cellspacing='1' ></table>").addClass("agencyBlurb").appendTo("#div_agency_profiledetial");
                  if(agencyprofile.Email!=null)
                  { 
                    $("<tr><td><p>&nbsp;</p></td><td valign='top'><b>" + rskey_email + ":</b></td><td valign='top'><a  href='mailto:" + agencyprofile.Email + "'>" + agencyprofile.Email+ "</a></td></tr>").appendTo("#agency_profile_table");
                  }
                  
                  
                  if(agencyprofile.Address!=null)
                  { 
                    $("<tr><td><p>&nbsp;</p></td><td valign='top'><b>"+ rskey_address +":</b></td><td valign='top'>" + agencyprofile.Address+ "</td></tr>").appendTo("#agency_profile_table");
                  }
                  
                  if(agencyprofile.AccessibilityInformation!=null)
                  { 
                    $("<tr><td><p>&nbsp;</p></td><td  style='vertical-align:top;'><b>"+ rskey_serviceaccessibility +":</b></td><td valign='top'>" + agencyprofile.AccessibilityInformation+ "</td></tr>").appendTo("#agency_profile_table");
                  }
                  
                 if(agencyprofile.ContactURL!=null)
                  { 
                    $("<tr><td><p>&nbsp;</p></td><td valign='top'><b>"+rskey_moreinformation +":</b></td><td valign='top'><a target='_new' href='" + agencyprofile.ContactURL  + "'>"+ rskey_mostuptodate1 +"</a>"+ rskey_modtuptodate2 + agencyprofile.Name + " .</td></tr>").appendTo("#agency_profile_table");
                  }
                 


               
                 
                if(agencyprofile.MainURL!=null)
                {
                $("<div id='agencyBottomLink'><a target='_new' href="+ agencyprofile.MainURL +" >" + agencyprofile.Name +
                " " + rskey_agency + " "+ rskey_website +"</a></div>").appendTo("#div_agency_profile");
                }
                
                
                function resizeimage(controlid,maxwidth,maxheight)
                {
                
                    var max_width=maxwidth;
                    var max_height=maxheight;
                    var img_width;
                    var img_height;
                  
                   
                   
                    if (imgPreview.width > 0)
                    {
                       
                        img_width=imgPreview.width;
                        if(parseInt(img_width,10)>parseInt(max_width,10))
                        {
                           resizewidth(controlid,max_width); 
                        }
                    }
                    else
                    {
                     
                    imgPreview.onload = function()
                        {
                            img_width=imgPreview.width;
                            
                            if(parseInt(img_width,10)>parseInt(max_width,10))
                            {
                               resizewidth(controlid,max_width); 
                            }  
                        };
                    }
                    
                    if (imgPreview.height > 0)
                    {
                        img_height=imgPreview.height;
                        if(parseInt(img_height,10)>parseInt(max_height,10))
                        {
                           resizeheight(controlid,max_height); 
                        }
                    }
                    else
                    {
                    imgPreview.onload = function()
                        {
                            img_height=imgPreview.height;
                            if(parseInt(img_height,10)>parseInt(max_height,10))
                            {
                               resizeheight(controlid,max_height); 
                            }  
                        };
                    }
                    
                    
                    
                   function resizewidth(controlid,_width)
                   {
                        $("#" +controlid).attr("width",_width);
                       
                   } 
                   
                   function resizeheight(controlid,_height)
                   {
                    $("#" +controlid).attr("height",_height);
                   }
                }
                
                
              // check if agency logo exist call resizeimage 
                if(img_tag!='')
                {
                    imgPreview = new Image();
                    imgPreview.src =  agency_logo_path  + agencyprofile.LogoFileName;
                    if (imgPreview.width > 0)
                    {
                        
                        resizeimage("img_agencylogo", agency_logo_maxwidth,agency_logo_maxheight); 
                        $("#img_agencylogo").show(); 
                    }
                    else
                    {
                        imgPreview.onload=function()
                        {
                        
                             resizeimage("img_agencylogo", agency_logo_maxwidth,agency_logo_maxheight); 
                             $("#img_agencylogo").show();
                        };
                    }
                    
                   
                }
                
                
               


        }
        catch(err)
        {
  	      	 logerror(err,window.location,"renderingfunctions_schedules.js","renderAgencyProfile",ErrorWWWNonFatal,"",getAgencyID(),"")
        }
        
    }

    function hideagencyprofile()
    {
        hidecontrolheader("AgencyProfile");
        $("#div_agency_profile").hide();
        $("#tbl_agencyprofile_dummy").hide();
    } 
    
   //*********************************Starts Here: Rendering Agency Service Area *********************
    function renderAgencyServiceArea(agencyprofile,container_div,showcallback,hidecallback)
    {
        try
        {

                $("#" + container_div).empty();
                var option_html='';
                
                for(var property in agencyprofile.AuxiliaryFileNames)
                {
                 
                  option_html +="<option value='"+ property +"'>" + agencyprofile.AuxiliaryFileNames[property] + "</option>"
                }
          
                if(option_html!='')
                {
                 showcallback();
                 $("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" +
                 "<tr><td colspan='2' class='agencyServiceAreaUtilities'><a id='a_additionalmapfileinfohelp' href='javascript:void(0);' title='"+ rskey_altHelp +"' ><img src='http://images.transit.511.org/RUI/images/help.jpg'"+
                 "alt='"+ rskey_altHelp +"' border='0' /></a></td></tr><tr>" +
                 "<td colspan='2' class='agencyServiceAreaprofileContent'><p class='agencyServiceAreaBlurb'>" +
                 rskey_agencycontentdescription +
                 "</p><table width='90%' border='0' cellspacing='0' cellpadding='0'><tr><td class='agencyServiceAreaUploadHeader'>" +
                 rskey_selectagencycontenttitle + "</td><td width='205' align='left'><select id='dd_agencyservicemap' class='agencyServiceAreaListMenu'>"+ 
                 "<option value=''>"+rskey_selectagencycontent+"</option>" + option_html +  "</select></td></tr></table>"+
                 "</td></tr></table>").appendTo("#" +container_div);
                 
                    $("#dd_agencyservicemap").unbind("change").bind("change",function()
                    {
                       if($(this).val()!='')
                       {
                            window.open("http://www.transit.511.org/static/providers/maps/"+ $(this).val());
                       }     
                    });
                }
                else
                {
                  //hidecallback();  
                   showcallback();
                  $("<table width='100%' border='0' cellspacing='0' cellpadding='0'>" +
                 "<tr><td colspan='2' class='agencyServiceAreaUtilities'><a id='a_additionalmapfileinfohelp' href='javascript:void(0);' title='"+ rskey_altHelp +"'><img src='http://images.transit.511.org/RUI/images/help.jpg'"+
                 "alt='"+ rskey_altHelp +"' border='0' /></a></td></tr><tr>" +
                 "<td colspan='2' class='agencyServiceAreaprofileContent'><p class='norecordstyle'>" +
                  rskey_agencyuploadnocontentmsg +"</p>").appendTo("#" +container_div);
                }
                
                $("#a_additionalmapfileinfohelp").unbind("click").bind("click",
                function(event)
                {
                    function render_help(helpitem)
                    {
                        renderhelp(helpitem,rskey_additionalmapfilehelpheader,event.pageX,event.pageY,"a_additionalmapfileinfohelp");
                    }
                    getHelp("additionalmapinfo","en",render_help);
                });    
                
        }
        catch(err)
        {
  	      	logerror(err,window.location,"renderingfunctions_schedules.js","renderAgencyServiceArea",ErrorWWWNonFatal,"",getAgencyID(),"")
        }
    
    
            
    }
    
   //*********************************Ends Here: Rendering Agency Service Area *********************


    //*********************************Starts Here: Rendering Fares *********************

    function renderFares(farezone,farelist,container_div,fromzoneid,tozoneid)
    {
        try
        {
        
                var div_id=container_div +"div_fares_list" ;
                var tbl_id=div_id +"fares_table";
                renderFareHeader(container_div,div_id,tbl_id); 
                if(farezone!=undefined)
                {
                    if(farezone.length>0)
                    {
                        
                        renderFareZones(farezone,fromzoneid,tozoneid,div_id,tbl_id); 
                    }
                }

                 if(farelist!=undefined)
                {
                  
                    renderFareList(farelist,div_id,tbl_id); 
                }
        


        }
        catch(err)
        {
  	        logerror(err,window.location,"renderingfunctions_schedules.js","renderFares",ErrorWWWNonFatal,"",getAgencyID(),"")
        }
        
        
        
       

    }


    function renderFareHeader(container_div,div_id,tbl_id)
    {

        $("#" + container_div).find("#" + div_id).remove();
        $("<div id='" + div_id + "' class='faredataScroller' ></div>").appendTo("#" + container_div);
         var relatedagencyid=getRelatedAgency(getAgencyID());
           if(relatedagencyid!='')
            {
            
                var related_text=getRelatedAgencyName(relatedagencyid)+ " " + rskey_fares;
              $("<div id='div_relatedfarelink' style='width:95%;text-align:right;font-weight:bold;padding:0 10px 0 0;'>"+
              "<span ><br><a  class='locRelatedItem' id='a_relatedfarelink' title='Click here to get "+  related_text +"' href='javascript:void(0);'>"+ 
              related_text+ "</a></span>&nbsp;&nbsp&nbsp;&nbsp<a id='print_fare' href='javascript:void(0);'>Print</a>"+
              "</div>").appendTo("#"+ div_id);
              
                $("#a_relatedfarelink").unbind("click").bind("click",function()
                {
                    
                    appendtourl("m1=F&m2=" + glb_agency_mode + "&cid=" + relatedagencyid,true);
                });

              
            }
           else
            {
            
             $("<div id='div_relatedfarelink' style='width:95%;text-align:right;font-weight:bold;padding:0 10px 0 0;'>"+
              "<br><a id='print_fare' href='javascript:void(0);'>Print</a>"+
              "</div>").appendTo("#"+ div_id);
            }
        $("<table id='"+ tbl_id + "'  width='100%' border='0' cellpadding='0' cellspacing='0' class='fareSelectorContainer' ></table>").appendTo("#" + div_id)
        $("#print_fare").unbind("click").bind("click",function()
                {
                    
                    var qry_string="cid="+  getAgencyID();
                   
                    if(GetFareZones()!=null)
                    {
                      if(validatezone(div_id)==true)
                      {
                        qry_string+= "&fromzone="+  $("#"+ div_id + "fare_from_zone").val()+ "&tozone="+$("#"+ div_id + "fare_to_zone").val(); 
                      }
                      else
                      {
                        return false;
                      }
                       
                        
                        
                    }
                    
                    window.open("printfares.aspx?"+qry_string ,null,MapWindowParams); 
                });
    }

    function renderFareZones(farezone,fromzoneid,tozoneid,div_id,tbl_id)
    {
       try
        {
            $("<tr id='" + tbl_id + "fare_zoneselector_tr'><td class='lstMenuCol'><strong>"+rskey_farefrom+":</strong>"+
            "<select id='" + div_id + "fare_from_zone' class='lstMenuType'></select></td><td class='lstMenuCol'><strong>"+rskey_fareto+
            ":</strong><select id='"+ div_id +"fare_to_zone' class='lstMenuType'></select></td></tr>").appendTo("#"+ tbl_id);
            $("<td align='left'><table class='enterBtnWidget' border='0' cellspacing='0' cellpadding='0'>" +
            "<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center'>"+
            "<a href='javascript:void(0);' style='text-decoration:none' class='BtnWidget_alink' id='"+ div_id+ "btn_fare_go'>"+rskey_fareenter+"</a></td>" +
            "<td class='BtnWidget_right'>&nbsp;</td></tr></table></td>").appendTo("#" + tbl_id +"fare_zoneselector_tr");



            var option_html;

            $(farezone).each(function(i)
            {
            option_html= "<option value='" + farezone[i].ZoneId + "'>" + farezone[i].ZoneName + "</option>";
            $(option_html).appendTo("#"+ div_id +"fare_from_zone");
            $(option_html).appendTo("#"+ div_id +"fare_to_zone");
            });

            option_html= "<option value='0'>" + rskey_zoneoptionvalue +"</option>";
            $(option_html).appendTo("#"+ div_id +"fare_from_zone");
            $(option_html).appendTo("#"+ div_id +"fare_to_zone");
            if(fromzoneid!='')
            {
            $("#"+ div_id +"fare_from_zone").val(fromzoneid);

            }

            if(tozoneid!='')
            {
            $("#"+ div_id +"fare_to_zone").val(tozoneid);

            }


            $("#"+ div_id +"btn_fare_go").unbind("click").bind("click",function()
            {

              if(validatezone(div_id)==true)
              {
               
                function render_faresbyzone(farezone_object,farelist_object,fromzoneid,tozoneid)
                {
                  renderFareList(farelist_object,div_id,tbl_id);
                 }
               
                 getFaresByZones($("#"+div_id +"fare_from_zone").val(),$("#"+ div_id +"fare_to_zone").val(),render_faresbyzone)

              }
              
             
             
            });
        
        }
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","renderFareZones",ErrorWWWNonFatal,"",getAgencyID(),"")
        }  
    
           
    }

    function renderFareList(farelist,div_id,tbl_id)
    {
        try
        {
             $("#" + tbl_id).find("[id='tr_"+ tbl_id +"_tblfarelist']").remove();
             $("#"+ div_id ).find("p").filter(".norecordstyle").remove();
             if(farelist.length>0)
             { 

              $("<tr id='tr_"+tbl_id+"_tblfarelist' ><td colspan='3'><table id='"+ tbl_id +"_tblfarelist' width='100%' cellspacing='0' cellpadding='0' class='fareDataTable ' ></table></td></tr>").appendTo("#"+ tbl_id);
              $("<tr><td align='left' valign='top' class='fareHeader'><strong>"+rskey_faretype+"</strong></td><td align='left' valign='top' class='fareHeader'><strong>"+rskey_fare+"</strong></td><td align='left' valign='top' class='fareHeader'><strong>"+rskey_instructions+"</strong></td></tr>").appendTo("#"+tbl_id+"_tblfarelist");
              $(farelist).each(function(i)
              {
                   $("<tr><td  align='left'  valign='top' width='50%' class='fareDataCell'>" + farelist[i].CategoryDesc + "</td><td align='left' valign='top' width='10%' class='fareDataCell'>" + farelist[i].FarePriceDesc + "</td><td align='left' valign='top' width='40%' class='fareDataCell'>" + farelist[i].FareInstruction + "</td></tr>").appendTo("#"+tbl_id+"_tblfarelist");
               }); 
                         
             }
             else
             {
               
                $("<p class='norecordstyle'>&nbsp;" + rskey_msgfareunavailable  + "</p>").appendTo("#"+ div_id );
             }
        }
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","renderFareList",ErrorWWWNonFatal,"",getAgencyID(),"")
        } 
        
             

    }

    function validatezone(div_id)
    {
        if(validate_zonesselection==true)
        {   
         if($("#"+div_id+ "fare_from_zone").val()=='0')
            {
                alert(rskey_msgselectfromzone);
                $("#fare_from_zone").focus();
                return false;
            }
         if($("#"+div_id+"fare_to_zone").val()=='0')
            {
               alert(rskey_msgselecttozone);
               $("#fare_to_zone").focus();
               return false;
            }
           return true; 
        }
        else
        {
        return true;
        }      
    }


    //*********************************Ends Here: Rendering Fares *********************


    //*********************************Starts Here: Rendering Announcement *********************

    function renderAllAnnouncement(allannouncement,container_div,span_header)
    {
      try
        {
        
            $("#" + container_div).find("#div_annoucement_list").remove();
            //$("#" + container_div).find("#div_regionalannouncelink").remove();
            $("<div id='div_annoucement_list' class='announcementScroller'></div>").appendTo("#"+ container_div);
        //    $("<div id='div_regionalannouncelink' class='announcementBottomLink'>"+
        //    "<a href='javascript:void(0)'>" + rskey_regionalannouncements +"</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>").appendTo("#"+ container_div);
                var routesannoucement_exist=false;
                if(allannouncement!=null)
                {
                     //Routes Announcements starts here
                     var routeannoucement_header=rskey_routeannouncements +" - " + getSelectedRouteDesignator(getSelectedRouteID());
                     $("<table  width='100%' ><tr><td width='3%'>&nbsp;</td><td  class='announcementtypeheader' >"+ routeannoucement_header+"</td></tr></table>").appendTo("#div_annoucement_list");
                     if(allannouncement.route.length>0||allannouncement.schedule.length>0)
                       { 
                            if(allannouncement.route.length>0){routesannoucement_exist=true;}
                            
                             $("<table  width='100%' id='tbl_routeannouncement'  cellpadding='3'></table>").appendTo("#div_annoucement_list");
                             $(allannouncement.route).each(function(i)
                              {
                                 if(allannouncement.route[i].Announcement.Title!=null)
                                   {
                                        if(allannouncement.route[i].Announcement.Content!=null)
                                         {
                                             $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementsubheader'><a id='Rannoucement_more" + i  + "' href='javascript:void(0);' style='text-decoration:none'>"+ $.trim(allannouncement.route[i].Announcement.Title) +
                                             "&nbsp;<b>...</b></a></span></td></tr>").appendTo("#tbl_routeannouncement");
                                             
                                                $("#Rannoucement_more" + i).unbind("click").bind("click",function(event)
                                                {
                                                  
                                                    var strTitle=allannouncement.route[i].Announcement.Title;
                                                    if(strTitle!=''&&strTitle!=null)
                                                    {
                                                        strTitle=replacecharacter(strTitle,",","~");
                                                    }
                                                    var strContent=allannouncement.route[i].Announcement.Content;
                                                    if(strContent!=''&&strContent!=null)
                                                    {
                                                        strContent=replacecharacter(strContent,",","~");
                                                    }
                                                    
                                                    ShowContentFullView(strTitle,strContent,allannouncement.route[i].Announcement.URL,event.pageX,event.pageY,routeannoucement_header);
                                                 });
                                                 //.unbind("mouseout").bind("mouseout",function(){setTimeout ('$("#div_annoucement_contentfullview").hide();', 500);});       
                                         }
                                         else
                                         {
                                            if(allannouncement.route[i].Announcement.URL!=null)
                                               {
                                                  $("<tr><td width='5%'>&nbsp;&nbsp;</td><td>"+ 
                                                 "<span class='announcementsubheader'><a   style='text-decoration:none' href='" +  allannouncement.route[i].Announcement.URL+ "' target='_blank'> "+$.trim(allannouncement.route[i].Announcement.Title)+"&nbsp;<b>...</b></a></span>" + 
                                                 "</td></tr>").appendTo("#tbl_routeannouncement");
                                               }
                                               else
                                               {
                                                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td><span class='announcementsubheader'>"+ $.trim(allannouncement.route[i].Announcement.Title) +"</span>"+
                                                    "</td></tr>").appendTo("#tbl_routeannouncement");
                                               }
                                         }
                                   }
                                   
                              }); 
                              
                              //Schedule level announcements
                              $(allannouncement.schedule).each(function(i)
                              {
                                 if(allannouncement.schedule[i].Announcement.Title!=null)
                                   {
                                        if(allannouncement.schedule[i].Announcement.Content!=null)
                                         {
                                             $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementsubheader'><a id='Sannoucement_more" + i  + "' href='javascript:void(0);' style='text-decoration:none'>"+ $.trim(allannouncement.schedule[i].Announcement.Title) +
                                             "&nbsp;<b>...</b></a></span></td></tr>").appendTo("#tbl_routeannouncement");
                                             
                                                $("#Sannoucement_more" + i).unbind("click").bind("click",function(event)
                                                {
                                                  
                                                    var strTitle=allannouncement.schedule[i].Announcement.Title;
                                                    if(strTitle!=''&&strTitle!=null)
                                                    {
                                                        strTitle=replacecharacter(strTitle,",","~");
                                                    }
                                                    var strContent=allannouncement.schedule[i].Announcement.Content;
                                                    if(strContent!=''&&strContent!=null)
                                                    {
                                                        strContent=replacecharacter(strContent,",","~");
                                                    }
                                                    
                                                    ShowContentFullView(strTitle,strContent,allannouncement.schedule[i].Announcement.URL,event.pageX,event.pageY,routeannoucement_header);
                                                 });
                                                 //.unbind("mouseout").bind("mouseout",function(){setTimeout ('$("#div_annoucement_contentfullview").hide();', 500);});       
                                         }
                                         else
                                         {
                                            if(allannouncement.schedule[i].Announcement.URL!=null)
                                               {
                                                  $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'>"+ 
                                                 "<span class='announcementsubheader'><a   style='text-decoration:none' href='" +  allannouncement.schedule[i].Announcement.URL+ "' target='_blank'>"+$.trim(allannouncement.schedule[i].Announcement.Title)+"&nbsp;<b>...</b></a></span>" + 
                                                 "</td></tr>").appendTo("#tbl_routeannouncement");
                                               }
                                               else
                                               {
                                                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span class='announcementsubheader'>"+ $.trim(allannouncement.schedule[i].Announcement.Title) +"</span>"+
                                                    "</td></tr>").appendTo("#tbl_routeannouncement");
                                               }
                                         }
                                   }
                                   
                              }); 
                       }
                       else
                       {
                            $("<table width='100%'><tr><td width='3%'>&nbsp;</td><td width='97%'><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_annoucement_list");
                        
                       }
                       
                       //Agency Announcements starts here
                       
                       $("<table  width='100%' ><tr><td width='3%'>&nbsp;&nbsp;</td><td  class='announcementtypeheader' >"+ rskey_agencyannouncements +"</td></tr></table>").appendTo("#div_annoucement_list");
                      if(allannouncement.carrier.length>0)
                       {
                             $("<table  width='100%' id='tbl_carrierannouncement'  cellpadding='3'></table>").appendTo("#div_annoucement_list");
                             $(allannouncement.carrier).each(function(i)
                              {
                                 if(allannouncement.carrier[i].Announcement.Title!=null)
                                   {
                                        if(allannouncement.carrier[i].Announcement.Content!=null)
                                         {
                                             $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementsubheader'><a id='Aannoucement_more" + i  + "' href='javascript:void(0);' style='text-decoration:none'>"+ $.trim(allannouncement.carrier[i].Announcement.Title) +
                                             "&nbsp;<b>...</b></a></span></td></tr>").appendTo("#tbl_carrierannouncement");
                                             
                                                $("#Aannoucement_more" + i).unbind("click").bind("click",function(event)
                                                {
                                                  
                                                    var strTitle=allannouncement.carrier[i].Announcement.Title;
                                                    if(strTitle!=''&&strTitle!=null)
                                                    {
                                                        strTitle=replacecharacter(strTitle,",","~");
                                                    }
                                                    var strContent=allannouncement.carrier[i].Announcement.Content;
                                                    if(strContent!=''&&strContent!=null)
                                                    {
                                                        strContent=replacecharacter(strContent,",","~");
                                                    }
                                                    ShowContentFullView(strTitle,strContent,allannouncement.carrier[i].Announcement.URL,event.pageX,event.pageY,rskey_agencyannouncements);
                                                 });
                                                 //.unbind("mouseout").bind("mouseout",function(){setTimeout ('$("#div_annoucement_contentfullview").hide();', 500);});       
                                         }
                                         else
                                         {
                                            if(allannouncement.carrier[i].Announcement.URL!=null)
                                               {
                                                  $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'>"+ 
                                                 "<span class='announcementsubheader'><a  style='text-decoration:none' href='" +  allannouncement.carrier[i].Announcement.URL+ "' target='_blank'>"+$.trim(allannouncement.carrier[i].Announcement.Title)+"&nbsp;<b>...</b></a></span>" + 
                                                 "</td></tr>").appendTo("#tbl_carrierannouncement");
                                               }
                                               else
                                               {
                                                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span class='announcementsubheader'>"+ $.trim(allannouncement.carrier[i].Announcement.Title) +"</span>"+
                                                    "</td></tr>").appendTo("#tbl_carrierannouncement");
                                               }
                                         }
                                   }
                                   
                              }); 
                       }
                       else
                       {
                            $("<table width='100%'><tr><td width='3%'>&nbsp;</td><td width='97%'><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_annoucement_list");
                       }
                       
                         //Regional Announcements starts here
                       
                      if(allannouncement.important.length>0)
                       {
                             $("<table  width='100%' ><tr><td width='3%'>&nbsp;&nbsp;</td><td  class='announcementtypeheader' >"+ rskey_regionalannouncements +"</td></tr></table>").appendTo("#div_annoucement_list");
                             $("<table  width='100%' id='tbl_regionalannouncement'  cellpadding='3'></table>").appendTo("#div_annoucement_list");
                             $(allannouncement.important).each(function(i)
                              {
                                 if(allannouncement.important[i].Announcement.Title!=null)
                                   {
                                        if(allannouncement.important[i].Announcement.Content!=null)
                                         {
                                             $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementsubheader'><a id='Iannoucement_more" + i  + "' href='javascript:void(0);' style='text-decoration:none'>"+ $.trim(allannouncement.important[i].Announcement.Title) +
                                             "&nbsp;<b>...</b></a></span></td></tr>").appendTo("#tbl_regionalannouncement");
                                             
                                                $("#Iannoucement_more" + i).unbind("click").bind("click",function(event)
                                                {
                                                  
                                                    var strTitle=allannouncement.important[i].Announcement.Title;
                                                    if(strTitle!=''&&strTitle!=null)
                                                    {
                                                        strTitle=replacecharacter(strTitle,",","~");
                                                    }
                                                    var strContent=allannouncement.important[i].Announcement.Content;
                                                    if(strContent!=''&&strContent!=null)
                                                    {
                                                        strContent=replacecharacter(strContent,",","~");
                                                    }
                                                    ShowContentFullView(strTitle,strContent,allannouncement.important[i].Announcement.URL,event.pageX,event.pageY,rskey_regionalannouncements);
                                                 });
                                                 //.unbind("mouseout").bind("mouseout",function(){setTimeout ('$("#div_annoucement_contentfullview").hide();', 500);});       
                                         }
                                         else
                                         {
                                            if(allannouncement.important[i].Announcement.URL!=null)
                                               {
                                                  $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'>"+ 
                                                 "<span class='announcementsubheader'><a  style='text-decoration:none' href='" +  allannouncement.important[i].Announcement.URL+ "' target='_blank'>"+$.trim(allannouncement.important[i].Announcement.Title)+"&nbsp;<b>...</b></a></span>" + 
                                                 "</td></tr>").appendTo("#tbl_regionalannouncement");
                                               }
                                               else
                                               {
                                                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span class='announcementsubheader'>"+ $.trim(allannouncement.important[i].Announcement.Title) +"</span>"+
                                                    "</td></tr>").appendTo("#tbl_regionalannouncement");
                                               }
                                         }
                                   }
                                   
                              }); 
                       }
                       
                }
                else
                {
                        
                        $("<table width='100%'><tr><td class='announcementtypeheader'>"+rskey_routeannouncements +" - " + getSelectedRouteDesignator(getSelectedRouteID())+"</td></tr></table>").appendTo("#div_annoucement_list");
                        $("<table width='100%'><tr><td width='100%'><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_annoucement_list");
                        
                       $("<table  width='100%' ><tr><td>&nbsp;</td><td  class='announcementtypeheader' >"+ getAgencyName() +" " + rskey_agencyannouncements +"</td></tr></table>").appendTo("#div_annoucement_list");
                        $("<table width='100%'><tr><td width='100%'><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_annoucement_list");
                }

                var headerhtml=' ';
                if(routesannoucement_exist==true)
                {
                 headerhtml= "<img src='" + routeannoucement_flasher_path + "'/ height='12px'>  ";

                }

                $("#" + span_header).html(headerhtml + getAgencyName() + " " + rskey_specificannouncements);

                
                
        
        } 
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","renderAllAnnouncement",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        } 

    
    }







    function ShowContentFullView(strtitle,strcontent,strurl,tPosX,tPosY,headertext)
    {


        
        try
        {
                var strTitle=strtitle;
                if(strTitle!=''&&strTitle!=null)
                {
                   strTitle =replacecharacter(strTitle,"~",",");
                }
                var strContent=strcontent;
                if(strContent!=''&&strContent!=null)
                {
                   strContent =replacecharacter(strContent,"~",",");
                }
               
               
                $("body").find("#div_annoucement_contentfullview").remove();
                tPosX = tPosX-15 ;
                tPosY = tPosY-35 ;
                var announcment_html='';
               
                announcment_html="<div id='div_annoucement_contentfullview' style='position:absolute;z-index:999999'>";
                announcment_html+="<table class='announcekeyTable' cellspacing='0'><tr><td class='boxTop'></td></tr>";
                announcment_html+="<tr>";
                announcment_html+="<td class='contentBox'>";
                announcment_html+="<div class='closeBox' style='padding-right: 4px;'>";
                announcment_html+="<a id='a_annoucement_contentfullviewclose'  style='z-index:999991' href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
                announcment_html+="</div><h1 class='ScheduleAnnounceHeader'>" + headertext+"</h1>";
                announcment_html+="<div class='boxDivider'></div>" ;
                announcment_html+="<div id='div_annoucement_fullviewdata' class='SchedulesannouncementListingdiv' ></div>"
                announcment_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
                $(announcment_html).appendTo("body")
                $('#div_annoucement_contentfullview').css({top: tPosY, left:tPosX});
                
                $("<table  width='100%' id='tbl_announcementfullview'  cellpadding='3'><tr><td colspan='2' width='100%'>&nbsp;</td></table>").appendTo("#div_annoucement_fullviewdata");
                $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementpopupsubheader'>"+ strTitle +"</span>"+
                "</td></tr>").appendTo("#tbl_announcementfullview");
                if(strContent!=null){
                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  id='spanannounce_content' class='announcementpopupContent'>"+ strContent +"</span>"+
                    "</td></tr>").appendTo("#tbl_announcementfullview");  
                }    
                
               if(strurl!=null)
                {
                   
                    $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%' style='text-align:right'><span  class='announcementpopupContent'>"+
                    "<a id='a_content_moreinfo' href='"+ strurl +"' target='_blank'>"+ rskey_moreinfo +"</a></span>"+
                    "&nbsp;</td></tr>").appendTo("#tbl_announcementfullview");  
                }    
                
                $("#a_annoucement_contentfullviewclose").unbind("click").bind("click",function()
                {
                   $("body").find("#div_annoucement_contentfullview").remove();
                });
                $("#a_content_moreinfo").unbind("click").bind("click",function()
                { 
                    $("body").find("#div_annoucement_contentfullview").remove();
                });
                
                 $("#spanannounce_content").find("a").removeAttr("target").attr("target","_blank");
                
        
        }
       
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","ShowContentFullView",ErrorWWWNonFatal,strtitle,getAgencyID(),getSelectedRouteID())
        } 
        
        
    }

    //*********************************Ends Here: Rendering Annoucement *********************

    //*********************************Starts Here: Rendering Schedule *********************
    
    //render Schedule Header and attach events 
    function renderScheduleList(schedulelist,dir,type,customize,container_div,mode,closecallback,raillinecallback,showmapcallback)
    {
        try
        {
            if(!IsScheduleValid(schedulelist,dir,type))
            {
                $("#" + container_div).find("#div_schedules_list").empty().remove();
                $("<div id='div_schedules_list' class='schedulesListingsOuterBorderBox'>"+
                "<table width='100%'><tr><td style='text-align:center'>"+rskey_msgscheduleunavailable + " </td></tr>"+
                "</table></div>").appendTo("#"+ container_div); 
                return false
            }
            
            var routemode=getRouteModeByRouteID(getSelectedRouteID());
            if(routemode!='')
            {
                mode=routemode;
            }
            
            var _selectedstopids='';
            var _selectedstopnames='';
            glb_customizedstopids='';
            var _localcustomize=customize;
            var _redisplaymap=true;
            blnannounceflashershown=false;
            schedulemaindivid=container_div;
            $("#" + container_div).find("#div_schedules_list").empty().remove();
            $("#" + container_div).find("#div_footerannouncment_list").empty().remove();
            $("<div id='div_schedules_list' class='schedulesListingsOuterBorderBox'></div>").appendTo("#" + container_div);
           
            $("<table id='tbl_helpanduparrow' width='100%' ><tr><td id='td_helpanduparrow' style='width:100%;text-align:right;'></td></tr></table>").appendTo("#div_schedules_list");
           
            $("<div id='div_schedule_listclose' style='float:right;text-align:bottom;padding-top:7px;'><a id='a_schedule_list_close' href='javascript:void(0)' title='"+ rskey_closemap +"'>"+
            "<img src='http://images.transit.511.org/RUI/fw/btn_scheduleuparrow.gif' alt='"+ rskey_schedulefullview +"'  /></a>"+
            "&nbsp;<a id='a_schedule_list_closemap' href='javascript:void(0);' style='text-decoration:none'>"+rskey_closemap+"</a>&nbsp;&nbsp;&nbsp;&nbsp;</div>").appendTo("#td_helpanduparrow");
            
            $("<div id='div_schedulelisthelp' style='float:right;text-align:top;'>"+
            "<a id='a_schedulelisthelp' href='javascript:void(0);' title='"+ rskey_altHelp +"'><img src='http://images.transit.511.org/RUI/images/help.jpg'"+
            "alt='Help' align='top' width='16' height='20' /></a>"+
            "</div>").insertBefore("#div_schedule_listclose");
            
             $("<div id='div_schedulelistotherroute' style='display:none;float:right;text-align:bottom;padding-top:7px;'>"+
            "&nbsp;<a id='a_schedulelistotherroute' href='javascript:void(0);' title='Select Another Route'>"+rskey_selectanotherroute+"</a>&nbsp;&nbsp;&nbsp;"+
            "</div>").insertBefore("#div_schedule_listclose")

            $("#a_schedulelisthelp").unbind("click").bind("click",
            function(event)
            {
                function render_help(helpitem)
                {
                    renderhelp(helpitem,rskey_schedulelisthelpheader,event.pageX-350,event.pageY-150,"a_schedulelisthelp");
                }
                getHelp("schedulelist","en",render_help);
            }); 
            
            

            $("<table  style='vertical-align:top;'><tr><td style='vertical-align:top;'><img id='img_mode_icon' src='http://images.transit.511.org/RUI/fw/transport_icons_flush/iconBus.png' alt='Bus' align='absmiddle'" +
            " style='margin-right: 10px;' /></td><td valign='top'><h1 class='schedulesHeading' >" + getSelectedRouteDesignator(getSelectedRouteID()) + " - (" + getAgencyName() + ") " + getSelectedRouteName(getSelectedRouteID()) + "</h1></td></tr></table>").appendTo("#div_schedules_list");
            $(renderScheduleInstruction()).appendTo("#div_schedules_list");
            $("#img_mode_icon").attr("src","http://images.transit.511.org/RUI/fw/transport_icons_flush/" + getModeImage(mode));
            $("#img_mode_icon").attr("alt", mode);
            $("<table id='tbl_schedule_header'  cellpadding='3' class='schedulesListingsHeadingTable'></table>").appendTo("#div_schedules_list"); 
            $("<tr id='tr_schedule_holiday_row' class='noTopPad'><td style='padding-left: 60px;'><span id='span_type'></span>&nbsp;"+ rskey_effective + ""+
            " <span id='span_date'></span>&nbsp;-&nbsp;<span id='span_direction'></span>&nbsp;<span id='span_customizetime_label'></span></td></tr>").appendTo("#tbl_schedule_header"); 
            $("<td><div id='holidaySchedulesBox'><br><table class='HolidaykeyTable' cellspacing='0'><tr><td class='boxTop'></td></tr>" +
            "<tr><td class='contentBox'><div class='closeBox' style='padding-right: 4px;'>" +
            "<a href=javascript:toggleLayer('holidaySchedulesBox')><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' />" +
            "</a></div><h1><b>" + getAgencyName().substring(0,28)  + " "+ rskey_holidayheader +"</b></h1><div class='boxDivider'></div>" +
            "<div id='div_holiday_data' class='holidaySchedulesListingTable'></div></td></tr><tr><td class='boxBtm'></td>" +
            "</tr></table></div><a id='a_holiday_display' href=javascript:toggleLayer('holidaySchedulesBox') style='display:none'>" +rskey_holidayschedule +"" + 
            "</a>&nbsp;&nbsp; <a id='a_route_annoucement' class='smallGrayLink' href='javascript:void(0)';>"+rskey_announcements+"</a></td>").appendTo("#tr_schedule_holiday_row");
            $("<td style='padding-left: 45px;'><a id='a_rail_line_diagram' href='javascript:void(0);' class='smallGrayLink'>"+ rskey_displayraillinediagram +"</a>" +
            "<span>&nbsp;&nbsp;&nbsp;</span><a id='a_print_customize' href='javascript:void(0);' style='display:none' class='smallGrayLink'>"+rskey_printcustomizedschedule+"</a></td>").appendTo("#tr_schedule_holiday_row");
            $("<td rowspan='2' style='vertical-align: top;'><a id='a_print_schedulewithmap' href='javascript:void(0);' class='smallGrayLink'>"+rskey_printschedulewithmap+"</a><br />"+
            "<a id='a_print_schedulewithoutmap' href='javascript:void(0);'  class='smallGrayLink'>" +rskey_printschedulewithoutmap +""+
            "<br /><a id='a_print_schedulewithpdf'  href='javascript:void(0);' class='smallGrayLink' style='display:none;'>"+rskey_printschedulepdf+"</a></td>").appendTo("#tr_schedule_holiday_row");

            $("#div_holiday_data").html("<p align='center'><b>"+ rskey_comingsoon +"</b></p>");				

            $("<tr id='tr_schedule_selector' ><td><table cellpadding='4' class='refreshScheduleTable'><tr>" +
            "<td class='refreshScheduleTableCell1'><strong>"+rskey_directions+":</strong>&nbsp;" +	
            "<select id='direction_select' onChange='ValidateDays(this)' style='width:80px;' class='borderSelect paddedSelect'>" +
            "</select></td><td class='refreshScheduleTableCell2'><strong>"+rskey_type+":</strong>&nbsp;" +
            "<select id='type_select' onChange='ValidateDir(this)' style='width:90px;'class='borderSelect paddedSelect'>" +		
            "</select></td><td class='refreshScheduleTableCell2'><table width='100%' height='23px' border='0' cellspacing='0' cellpadding='0'>" +
            "<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center'><a id='btn_refresh_schedule' href='javascript:void(0)' class='BtnWidget_alink'>"+rskey_refreshschedule+"</a>" +
            "</td><td class='BtnWidget_right'>&nbsp;</td></tr></table></td><tr></table></td><td><table id='tbl_btn_customize_schedule' width='142px' height='23px' border='0' cellspacing='0' cellpadding='0'>" + 
            "<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center' ><a id='btn_customize_schedule' style='text-decoration:none' href='javascript:void(0)' " + 
            " class='BtnWidget_alink'>"+rskey_customizeschedule+"</a></td><td class='BtnWidget_right'>&nbsp;</td></tr></table></td>" +
            "<td id='td_schedule_stopsonmap' style='padding:5px;height: 32px;' >"+
            "&nbsp;<table id='tbl_btn_showmap' width='138px' height='23px' border='0' cellspacing='0' cellpadding='0' style='display:none'>" + 
            "<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center' ><a id='btn_showroutemap' style='text-decoration:none' href='javascript:void(0)' " + 
            " class='BtnWidget_alink'>"+rskey_showmap+"</a></td><td class='BtnWidget_right'>&nbsp;</td></tr></table>"+
            "<span id='span_showstopslabel_schedule' style='display:none'><strong>"+rskey_show+": </strong></span><select id='dd_stop_map'  style='width:200px;display:none' class='borderSelect paddedSelect'>" +	
            "</select><span>&nbsp;&nbsp;&nbsp;</span></td></tr>").appendTo("#tbl_schedule_header");
            $(renderScheduleCustomizeSelector()).appendTo("#div_schedules_list");
            
            
            
            //Render Directions
            var option_html;
            $(schedulelist.Directions).each(function(i)
            {

               option_html= "<option value='" + schedulelist.Directions[i].split(":")[0] + "'>" + schedulelist.Directions[i].split(":")[1] + "</option>";
               $(option_html).appendTo("#direction_select");
               
            });
            //Render Day Types
            for(var property in schedulelist.DayTypes)
            {
                option_html= "<option value='" + property + "'>" +schedulelist.DayTypes[property] + "</option>";
                $(option_html).appendTo("#type_select");
            }
           
            if(dir!='')
            {
                $("#direction_select").val(dir);
            }
            if(type!='')
            {
               $("#type_select").val(type);
            }
            
        //Make Day type default selection
            if(schedulelist.DaySelected!=''&&type=='')
             {
                   
                    $("#type_select").val(schedulelist.DaySelected);
             }
             
        // if Directions is more than one make the called for valid directions for default day type

            if($(schedulelist.Directions).size()>1&&dir=='')
            {
            var selected=false;
            var type_value=$("#type_select").val();
                $(glb_scheduleOptionlist.ValidDayDir[type_value]).each(function(j)
                {
                   if(selected==false)
                   {
                    $(schedulelist.Directions).each(function(i)
                    {
                       if(selected==false)
                       {
                            if(schedulelist.Directions[i].split(":")[0]==glb_scheduleOptionlist.ValidDayDir[type_value][j])
                            {
                               $("#direction_select").val(schedulelist.Directions[i].split(":")[0]);
                                selected=true;
                               
                            }
                       } 
                    });
                   } 
                });
            }

           
            
            function render_stoplist(scheduleStopItems_obj)
            {
                
                    $("#tr_schedule_selector").show();
                    $("#tr_schedule_holiday_row").show();
                    $("#tbl_schedule_instruction").hide();
                    $("#a_print_customize").hide();
                    
                   renderstopsdropdown(scheduleStopItems_obj);
                   renderschedulesstoplist(scheduleStopItems_obj,"div_schedules_list",false);
                   if(_selectedstopids!='')
                   {
                    ShowOnlyCustomizedStops(_selectedstopnames);
                    $("#tbl_schedule_customizeselector").show();
                    $("#a_print_customize").show();
                   }
                   else
                   {
                     $("#tbl_schedule_customizeselector").hide();
                   }
                   
                   
                    //if customization is bookmarked
                    if(_localcustomize==1)
                    {
                        $("#tr_stop_checkboxes").attr("style","");
                        $("#tr_stop_checkboxes").addClass("checkboxRow");
                        $("#tr_stop_checkboxes").show();
                        $("#tr_schedule_selector").hide();
                        $("#tr_schedule_holiday_row").hide();
                        $("#tbl_schedule_instruction").show();
                        $("#tbl_schedule_customizeselector").show();
                        $("#txt_fromtimehr").show();
                        $("#txt_fromtimemin").show();
                        $("#span_fromtimesep").show();
                        $("#txt_totimehr").show();
                        $("#txt_totimemin").show();
                        $("#span_totimesep").show();
                        $("#dd_fromtime").show();
                        $("#dd_totime").show();
                        $("#span_schedule_fromtime").show();
                        $("#span_schedule_totime").show();
                        $("#tbl_btn_getcustomize_schedule").show();
                        $("#btn_getcustomize_schedule").show();
                        presetcustomizetime(); 
                        $("#btn_customize_schedule").hide();
                        hidescheduleannounceflasher();
                    }                    
                    else
                    {
                        
                            if(_redisplaymap==true&&ismapvisible()==true)
                            {  
                              
                                loadroutemap();
                            }
                        
                           
                       
                    }
               
            }

           if($("#direction_select").val()!=''&&$("#type_select").val()!='')
            { 
              
                  rendereffectivedate();
                  if(mode!='rail')
                  {
                    $("#a_rail_line_diagram").hide();
                  }
                 
                  getschedulesStop(getSelectedRouteID(),$("#direction_select").val(),$("#type_select").val(),render_stoplist);  
                  
            }
            
            $("#btn_refresh_schedule").unbind("click").bind("click",function()
            {
                
                rendereffectivedate();
                clearscheduleform();
                $("#tbl_schedule_customizeselector").hide();
                $("#span_customizetime_label").hide()
                _redisplaymap=true;
                appendtourl("m1=S&m2="+ mode + "&routeid="+getSelectedRouteID()+"&dir="+$("#direction_select").val()+"&type="+$("#type_select").val()+"&cid="+ getAgencyID(),true);
               
            });
            
            $("#btn_customize_schedule").unbind("click").bind("click",function()
              {   
                      _redisplaymap=false;
                    appendtourl("m1=S&m2="+ mode + "&routeid="+getSelectedRouteID()+"&dir="+$("#direction_select").val()+"&type="+$("#type_select").val()+"&customize=1"+ "&cid="+ getAgencyID(),true);
             });
         
         
            $("#btn_redisplay_schedule").unbind("click").bind("click",function()
            { 
                
                $("#btn_redisplay_schedule").appendTo("#td_schedule_bottomreturnfullschedule");
                $("#tbl_schedule_instruction").hide();
                $("#tbl_schedule_customizeselector").hide();
                $("#tr_stop_checkboxes").hide();
                $("#tr_schedule_holiday_row").show();
                $("#tr_schedule_selector").show();
                $("#a_print_customize").hide(); 
                $("#tbl_btn_showmap").insertBefore("#span_showstopslabel_schedule");
                if(ismapenable()==true)
                {
                    if(ismapvisible()==true)
                    {
                        $("#a_print_schedulewithmap").show();
                        $("#a_print_schedulewithmap").text(rskey_printschedulewithmap);
                        $("#a_print_schedulewithmap").insertBefore("#a_print_schedulewithoutmap");
                        $("<br>").insertBefore("#a_print_schedulewithoutmap");
                        
                               $("#a_print_schedulewithmap").unbind("click").bind("click",function()
                                {
                                     
                                     var patterntext;
                                     patterntext=$("#span_type").text() + " - " + $("#span_direction").text() + " - " +  rskey_effectivedate +":"+ $("#span_date").text();
                                    // window.open("printschedule.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&fromstop="+getScheduleStartStop()+"&tosstop="+getScheduleEndStop()+"&mode="+mode+"&withmap=1&customize=0&patterntext="+patterntext,null,MapWindowParams); 
                                    map_loadprintroutemap(getAgencyID(),getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),"1","","0",patterntext,"","");
                                    
                                });
                    }
                   
                }
                
                $("#a_print_schedulewithoutmap").show();
                //$("#a_print_schedulewithpdf").show();
                //$("#a_print_schedulewithpdf").hide();
                _selectedstopids='';
                _selectedstopnames='';
                glb_customizedstopids='';
                clearscheduleform();
                rendereffectivedate();
                $("#dd_stop_map").val("0");
                $("#tbl_btn_customize_schedule").show();
                $("#btn_customize_schedule").show();
                $("#span_customizetime_label").hide();
              
                _localcustomize='';
                _redisplaymap=true;
               getschedulesStop(getSelectedRouteID(),$("#direction_select").val(),$("#type_select").val(),render_stoplist);

            });


            $("#btn_getcustomize_schedule").unbind("click").bind("click",function(event){
                var tPosX = event.pageX; 
                var tPosY = event.pageY;
              
                 if(validateschedulesearch(tPosX,tPosY)==true)
                 {
                      $("#dd_stop_map").val("0");
                     var objreturn=rendercustomizeschedule("div_schedules_list");
                      _selectedstopids=objreturn[0];
                      _selectedstopnames=objreturn[1];
                       $("#a_print_customize").show();
                       $("#a_print_schedulewithoutmap").hide();
                      // $("#a_print_schedulewithpdf").hide();
                       $("#txt_fromtimehr").hide();
                       $("#txt_fromtimemin").hide();
                       $("#span_fromtimesep").hide();
                       $("#txt_totimehr").hide();
                       $("#txt_totimemin").hide();
                       $("#span_totimesep").hide();
                       $("#dd_fromtime").hide();
                       $("#dd_totime").hide();
                       $("#span_schedule_fromtime").hide();
                       $("#span_schedule_totime").hide();
                       $("#tbl_btn_customize_schedule").hide();
                       $("#btn_getcustomize_schedule").hide();
                       $("#tbl_btn_getcustomize_schedule").hide();
                       $("#tr_schedule_selector").show();
                       $("#tr_schedule_holiday_row").show();
                       $("#tbl_schedule_instruction").hide();
                       $("#btn_redisplay_schedule").appendTo("#td_schedule_stopsonmap");
                       $("#btn_redisplay_schedule").show();
                       $("#tbl_schedule_customizeselector").hide();
                       
                       $("#tbl_btn_showmap").insertBefore("#tbl_btn_customize_schedule");
                   
                 }
            });
           
            $("#a_schedule_list_close").unbind("click").bind("click",function()
            {
                $("#div_routesannounce_flasher").hide();
                $("#div_routeschedule_announcment").hide();
                $("#" + container_div).hide();
                closecallback();
                $("#div_schedulelistotherroute").show();
            });
            
            $("#a_schedule_list_closemap").unbind("click").bind("click",function()
            {
                $("#div_routesannounce_flasher").hide();
                $("#div_routeschedule_announcment").hide();
                $("#" + container_div).hide();
                closecallback();
                $("#div_schedulelistotherroute").show();
            });
            $("#a_schedulelistotherroute").unbind("click").bind("click", function()
            {
            bindschedulefullviewtabclick();
            });
       
           if(!ismapvisible())
           {
            
               $("#a_schedule_list_close").hide();
               $("#div_schedule_listclose").hide();
               hidemaplegend();
               $("#div_schedulelistotherroute").show();
           }
           else
           {
             showscheduleuparrow();
             $("#div_schedulelistotherroute").hide();
           }
           if(ismapvisible())
           {
                
                hidebuttonshowmaplink();
           }
           else
           {
              
                showbuttonshowmaplink();
           }
             
            $("#btn_showroutemap").unbind("click").bind("click",function()
            {
               $("#div_schedulelistotherroute").hide();
               hidebuttonshowmaplink();
               showmapcallback();
              
               
               
            });
            
            
        
            $("#a_schedule_instructclose").unbind("click").bind("click",function()
            {
             
              $("#tbl_schedule_instruction").hide();
              $("#tr_schedule_selector").show();
              $("#tr_schedule_holiday_row").show();
              $("#btn_customize_schedule").show();
              $("#tbl_btn_customize_schedule").show();
            });



            $("#a_rail_line_diagram").unbind("click").bind("click",function()
            {
                $("#"+ container_div).hide();
                raillinecallback(getSelectedRouteID(),$("#direction_select").val(),$("#type_select").val());
            });

            if($("#a_print_customize").is(":hidden"))
            {
             
                $("#a_print_schedulewithmap").unbind("click").bind("click",function()
                {
                     
                     var patterntext;
                     patterntext=$("#span_type").text() + " - " + $("#span_direction").text() + " - " +  rskey_effectivedate +":"+ $("#span_date").text();
                    // window.open("printschedule.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&fromstop="+getScheduleStartStop()+"&tosstop="+getScheduleEndStop()+"&mode="+mode+"&withmap=1&customize=0&patterntext="+patterntext,null,MapWindowParams); 
                    map_loadprintroutemap(getAgencyID(),getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),"1","","0",patterntext,"","");
                    
                });
            }
            $("#a_print_schedulewithoutmap").unbind("click").bind("click",function()
            {
                var patterntext;
                patterntext=$("#span_type").text() + " - " + $("#span_direction").text() + " - " +  rskey_effectivedate +":"+ $("#span_date").text();
                window.open("printschedulewithoutmap.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&withmap=0&customize=0&patterntext="+patterntext,null,MapWindowParams); 
            });
//            $("#a_print_schedulewithpdf").unbind("click").bind("click",function()
//            {
//               window.open(schedulepdfprintlink + getSelectedRouteID()); 
//            });
          
        
            $("#a_route_annoucement").unbind("click").bind("click",function(event)
            {
                $("#div_routesannounce_flasher").hide();
                renderRouteAnnouncements(event);   
            });
        
            if(ismapenable()==true)
            {
                if(ismapvisible()==true)
                {
                    $("#a_print_schedulewithmap").show();
                }
                else
                {
                    $("#a_print_schedulewithmap").hide();
                }
            }
            else
            {
                $("#a_print_schedulewithmap").hide();
            }

        
        
        }
        catch(err)
        {
           
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderScheduleList",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }    
            
    }


    //render Schedule data
    function renderschedulesstoplist(scheduleStopItems_obj,container_div,customize)
    {
        try
        {
        
            $("#" + container_div).find("#div_schedule_data").empty().remove();
            $("#" + container_div).find("#tbl_customizeheader").remove();
            if(customize==true)
            {
                $("<table id='tbl_customizeheader' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><h1 class='schedulesHeading'>"+rskey_customizeschedule+"</h1></td></tr></table>").appendTo("#"+container_div);
            }
           
            $("<div id='div_schedule_data' style='width: 920px; height:550px;overflow:auto;'></div>").appendTo("#" + container_div);
            $("<table id='tbl_schedule_data' cellpadding='0' cellspacing='0' border='0' align='center' class='schedulesListingTable'></table>").appendTo("#div_schedule_data");
            $("<tr id='tr_stop_checkboxes' style='display:none'></tr>").appendTo($("<thead></thead>").appendTo("#tbl_schedule_data"));  
            $("<tbody>").appendTo("#tbl_schedule_data");
            $("<tr class='topBorderRow'><td id='td_schedule_red_row' colspan='" + scheduleStopItems_obj.StopTripList.length + "'></td></tr>").appendTo("#tbl_schedule_data");     
               
                var stoplist_html;
                var rowstoplist_html;
                var stoplist_header;
                var clstsring='';
                clstsring=''  ;
                
                if(scheduleStopItems_obj.StopTripList.length>0)
                {
                    stoplist_html = renderScheduleCheckboxes(scheduleStopItems_obj);
                    $(stoplist_html).appendTo("#tr_stop_checkboxes");
                    stoplist_header = renderScheduleStopsHeader(scheduleStopItems_obj);
                    //stoplist_html=stoplist_header;
                
                        if(scheduleStopItems_obj.StopTripList[0].StopTimings.length>0)
                        {
                         var row_count=1;
                         var show_row;
                        //
                         $(scheduleStopItems_obj.StopTripList[0].StopTimings).each(function(i)
                            {
                                show_row=false;
                                if(row_count>20)
                                {
                                   // stoplist_html +=stoplist_header;
                                    row_count=1;
                                }
                                stoplist_html = "<tr>";
                                $(scheduleStopItems_obj.StopTripList).each(function(j)
                                {
                                    
                                    if(scheduleStopItems_obj.StopTripList[j].StopTimings[i].toLowerCase()!=schedulenostopchar)
                                    {
                                        show_row=true;
                                    }
                                    
                                    stoplist_html += "<td" + clstsring + ">"; 
                                    stoplist_html += formatstoptime(scheduleStopItems_obj.StopTripList[j].StopTimings[i]).toLowerCase();
                                    stoplist_html += "</td>"; 
                                     if(clstsring=='')
                                      {
                                           clstsring=" class='altCol'";
                                      }
                                      else
                                      {
                                           clstsring=''  ;
                                      }   
                                });
                                stoplist_html += "</tr>";
                                clstsring=''  ;
                              if(show_row==true)
                              {
                                if(row_count==1)
                                {
                                    $(stoplist_header).appendTo("#tbl_schedule_data"); 
                                }
                               row_count++;
                               $(stoplist_html).appendTo("#tbl_schedule_data"); 
                              } 
                              stoplist_html ="";
                            });
                           $("</tbody>").appendTo("#tbl_schedule_data"); 
                          }
                        else
                        {
                            
                             stoplist_html += "<tr><td style='text-align:center' colspan='" + $(scheduleStopItems_obj.StopTripList).length + "'>";
                             stoplist_html += rskey_msgscheduleunavailable + " </td></tr>"
                             $(stoplist_html).appendTo("#tbl_schedule_data"); 
                             $("</tbody>").appendTo("#tbl_schedule_data");
                             if(!customize){DisableScheduleLinks();}
                        }
                    
                        if(ismapenable()==true)
                        {
                            if(ismapvisible()) hyperlinkstopsheader();
                        }    
                 
                }
                else
                {
                    
                         stoplist_html += "<tr><td style='text-align:center'>";
                         stoplist_html += rskey_msgscheduleunavailable + " </td></tr>"
                         $(stoplist_html).appendTo("#tbl_schedule_data"); 
                         $("</tbody>").appendTo("#tbl_schedule_data"); 
                         if(!customize){DisableScheduleLinks();}
                         
                }
               
                if(!ismapvisible()&&!customize)
                {
                  
                    if(blnannounceflashershown==false)
                    {
                        renderFooterAnnouncements(schedulemaindivid,true);
                    }
                    else
                    {
                        renderFooterAnnouncements(schedulemaindivid,false);
                    }    
                    
                }
                else
                {
                    renderFooterAnnouncements(schedulemaindivid,false);
                }
                
                
           
        
        }
        catch(err)
        {
             var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderschedulesstoplist",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        } 
       
        
    }
    
    function DisableScheduleLinks()
    {
        
        $("#btn_customize_schedule").unbind("click").removeAttr("href");
        $("#a_print_schedulewithoutmap").unbind("click").removeAttr("href");
        $("#a_print_schedulewithmap").unbind("click").removeAttr("href");
       
    }
    //check whether routeid,dir,day type from bookmarking is valid or not
    function IsScheduleValid(schedulelist,dir,type)
    {
       
        if(getSelectedRouteDesignator(getSelectedRouteID())==null){return false;}
        if(schedulelist==undefined){return false;}
        if(schedulelist.Directions.length==0){return false;}
       
        if(dir!='')
        {
        
            var _direxists=false;   
            $(schedulelist.Directions).each(function(i)
             {
               
                if($.trim(schedulelist.Directions[i].split(":")[0])==$.trim(replacecharacter(dir,'%20','')))
                {
                    _direxists=true;   
                }
             });
             if(_direxists==false){return false;} 
        }     
       
        var _daytypexists=false;   
        for(var property in schedulelist.DayTypes)
        {
           
            if(type!='')
            {
               
                if(type==property){_daytypexists=true;break;}
                
            }
            else
            {
                 _daytypexists=true;
            }
           
        }
        if(_daytypexists==false){return false;}
        
       
      return true;   
    }
    //render Schedule Stops Header 

    function renderScheduleStopsHeader(scheduleStopItems_obj)
    {
        try
        {
            var clstsring='';
            var stoplist_html = "<tr id='tr_schedule_stopsheader'>"
            
            $(scheduleStopItems_obj.StopTripList).each(function(i)
                {
                  
                    stoplist_html += "<th " + clstsring + ">"; 
                    stoplist_html += scheduleStopItems_obj.StopTripList[i].StopName ; 
                    stoplist_html += "</th>"; 
                    
                    if(clstsring=='')
                    {
                        clstsring="class='altCol'";
                    }
                    else
                    {
                        clstsring=''  ;
                    }
                 });
            stoplist_html += "</tr>";
        return  stoplist_html;   
        }
        catch(err)
        {
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderScheduleStopsHeader",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        } 
       
      
             

    }
    
    //render Schedule Stops check boxes

    function renderScheduleCheckboxes(scheduleStopItems_obj)
    {
            
        try
        {
            var clstsring='';
            var stoplist_html='';
            glb_allstopids='';
            $(scheduleStopItems_obj.StopTripList).each(function(i)
                {
                  
                    stoplist_html +="<td style='text-align:center'"+ clstsring+"><input type='checkbox'  id='chk_schedule'/>";
                    stoplist_html +="<input type='hidden' id='hdn_stopid' value='" +  scheduleStopItems_obj.StopTripList[i].StopID +"~" + replacecharacter(scheduleStopItems_obj.StopTripList[i].StopName,"'","$") + "'/>" ;
                    stoplist_html +="</td>";
                    if(clstsring=='')
                    {
                        clstsring="class='altCol'";
                    }
                    else
                    {
                        clstsring=''  ;
                    }
                    if(glb_allstopids=='')
                    {
                        glb_allstopids =  scheduleStopItems_obj.StopTripList[i].StopID;
                    }
                    else
                    {
                        glb_allstopids += ","+ scheduleStopItems_obj.StopTripList[i].StopID;
                    }
                 });
                setallstops(glb_allstopids);
                return  stoplist_html;  
        
        }
         catch(err)
        {
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderScheduleCheckboxes",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }
            
              
    }

    //render Schedule Instruction Box
    function renderScheduleInstruction()
    {
        var instructiontable_html='';
        instructiontable_html="<table id='tbl_schedule_instruction' cellpadding='0' style='display:none' cellspacing='0' class='schedulesInstructionBox'>";
        instructiontable_html+="<tr><td class='boxTop'></td></tr><tr><td class='contentBox'>";
        //instructiontable_html+="<div class='closeBox'><a href='javascript:void(0);' id='a_schedule_instructclose' ><img src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+rskey_altclose+"' /></a></div>";
        instructiontable_html+="<div class='contentPadBox'>" + rskey_msgscheduleinstruction + "</div>";
        instructiontable_html+="</td></tr><tr><td class='boxBtm'></td></tr></table>";
        return instructiontable_html;
      

    }
    function renderRouteAnnounceFlasher(announcement_object)
    {
         
        try
        {
            blnannounceflashershown=true; 
            if(announcement_object!=null)
             {
                           
                 if(announcement_object.route.length>0)
                 { 
                        var announcmentflasher_html;
                        $("body").find("#div_routesannounce_flasher").remove();
                        $("<div id='div_routesannounce_flasher' class='routeAnnounceFlasher'></div>").appendTo("body");
                        announcmentflasher_html="<table class='announceFlasherkeyTable'  cellspacing='0'><tr><td class='boxTop'></td></tr>";
                        announcmentflasher_html+="<tr>";
                        announcmentflasher_html+="<td class='contentBox' >";
                        announcmentflasher_html+="<div class='closeBox' style='padding-right: 4px;'>";
                        announcmentflasher_html+="<a id='a_route_announcementflasherclose'  href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
                        announcmentflasher_html+="</div>";
                        announcmentflasher_html+="<div class='boxDivider'></div>" ;
                        announcmentflasher_html+="<div class='announceFlasherInfodiv' ><b>"+rskey_routeannounceflasher+"</b></div>"
                        announcmentflasher_html+="</td></tr><tr><td class='boxBtm'></td></tr></table>"
                        $(announcmentflasher_html).appendTo("#div_routesannounce_flasher");
                        $("#div_routesannounce_flasher").show();
                        $("#a_route_announcementflasherclose").unbind("click").bind("click",function()
                        {
                             $("#div_routesannounce_flasher").hide();
                        });
                        
                  }   
            
            }
            
        }
        catch(err)
        {
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderRouteAnnounceFlasher",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }
             
             
             
             
         
    }
    
    
    
    function renderRouteAnnouncements(event)
    {
        
        try
        {
            $("body").find("#div_routeschedule_announcment").remove();
            var tPosX = event.pageX-15 ;
            var tPosY = event.pageY+15 ;
            var announcment_html='';
           
            announcment_html="<div id='div_routeschedule_announcment' style='position:absolute;'>";
            announcment_html+="<table class='announcekeyTable' cellspacing='0'><tr><td class='boxTop'></td></tr>";
            announcment_html+="<tr>";
            announcment_html+="<td class='contentBox'>";
            announcment_html+="<div class='closeBox' style='padding-right: 4px;'>";
            announcment_html+="<a id='a_route_annoucementclose'  href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
            announcment_html+="</div><h1 class='ScheduleAnnounceHeader'>" +rskey_routeannouncements +" - " + getSelectedRouteDesignator(getSelectedRouteID()) +" </h1>";
            announcment_html+="<div class='boxDivider'></div>" ;
            announcment_html+="<div id='div_routeannoucement_data' class='SchedulesannouncementListingdiv' ></div>"
            announcment_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
            $(announcment_html).appendTo("body")
            $('#div_routeschedule_announcment').css({top: tPosY, left:tPosX});
            
            function render_routeannoucement(announcement_object)
            {
                 if(announcement_object!=null)
                 {
                   //Routes Announcements starts here
                  
                    if(announcement_object.route.length>0|| announcement_object.schedule.length>0)
                    { 
                   
                    
                     $("<table  width='100%' id='tbl_schedulerouteannouncement'  cellpadding='3'><tr><td colspan='2' width='100%'>&nbsp;</td></table>").appendTo("#div_routeannoucement_data");
                    
                         //Route level announcements
                         $(announcement_object.route).each(function(i)
                          {
                             if(announcement_object.route[i].Announcement.Title!=null)
                               {
                                    if(announcement_object.route[i].Announcement.Content!=null)
                                     {
                                         $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementpopupsubheader'>"+ $.trim(announcement_object.route[i].Announcement.Title) +"</span>"+
                                         "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                         
                                         $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span id='span_rannounce_content"+i+"' class='announcementpopupContent'>"+ $.trim(announcement_object.route[i].Announcement.Content) +"</span>"+
                                         "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                         
                                         $("#span_rannounce_content"+ i).find("a").removeAttr("target").attr("target","_blank");   
                                     }
                                     else
                                     {
                                        if(announcement_object.route[i].Announcement.URL!=null)
                                           {
                                              $("<tr><td>&nbsp;&nbsp;</td><td>"+ 
                                             "<span class='announcementsubheader'><a  class='announcementpopupsubheaderlink' href='" +  announcement_object.route[i].Announcement.URL+ "' target='_blank'> "+ $.trim(announcement_object.route[i].Announcement.Title) +"</a></span>" + 
                                             "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                           }
                                           else
                                           {
                                                $("<tr><td>&nbsp;&nbsp;</td><td><span class='announcementpopupsubheader'>"+ $.trim(announcement_object.route[i].Announcement.Title) +"</span>"+
                                                "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                           }
                                     }
                               }
                               
                          }); 
                    
                          //Schedule level announcements
                          
                          $(announcement_object.schedule).each(function(i)
                          {
                             if(announcement_object.schedule[i].Announcement.Title!=null)
                               {
                                    if(announcement_object.schedule[i].Announcement.Content!=null)
                                     {
                                         $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span  class='announcementpopupsubheader'>"+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</span>"+
                                         "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                         
                                         $("<tr><td width='5%'>&nbsp;&nbsp;</td><td width='95%'><span id='span_sannounce_content"+i+"' class='announcementpopupContent'>"+ $.trim(announcement_object.schedule[i].Announcement.Content) +"</span>"+
                                         "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                          
                                         $("#span_sannounce_content"+ i).find("a").removeAttr("target").attr("target","_blank");     
                                     }
                                     else
                                     {
                                        if(announcement_object.schedule[i].Announcement.URL!=null)
                                           {
                                              $("<tr><td>&nbsp;&nbsp;</td><td>"+ 
                                             "<span class='announcementsubheader'><a  class='announcementpopupsubheaderlink' href='" +  announcement_object.schedule[i].Announcement.URL+ "' target='_blank'> "+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</a></span>" + 
                                             "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                           }
                                           else
                                           {
                                                $("<tr><td>&nbsp;&nbsp;</td><td><span class='announcementpopupsubheader'>"+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</span>"+
                                                "</td></tr>").appendTo("#tbl_schedulerouteannouncement");
                                           }
                                     }
                               }
                               
                          });
                          
                    }
                    else
                    {
                       $("<table width='100%'><tr><td width='100%'><br><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_routeannoucement_data");
                    }
                 }   
                 else
                 {
                   
                    $("<table width='100%'><tr><td width='100%'><br><p class='norecordstyle'>" + rskey_msgannouncementunavailable + "</p></td></tr></table>").appendTo("#div_routeannoucement_data");
                 }
            }
            
            
            getAllAnnouncements(getAgencyID(),getSelectedRouteID(),render_routeannoucement);
            
            
            $("#a_route_annoucementclose").unbind("click").bind("click",function()
            {
                $("body").find("#div_routeschedule_announcment").remove();
               
            });
        
        
        }
         catch(err)
        {
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderRouteAnnouncements",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }
        
        
        
        
    }
    
    function renderFooterAnnouncements(container_div,blnflash)
    {
        try
        {
        
             $("#" + container_div).find("#div_footerannouncment_list").empty().remove();
             function render_footerannoucement(announcement_object)
             {
                
               if(blnflash==true)
                {
                    
                     renderRouteAnnounceFlasher(announcement_object);
                }
               
             
                  if(announcement_object.schedule.length>0)
                    { 
                      $("<div id='div_footerannouncment_list' class='schedulesListingsOuterBorderBox'></div>").appendTo("#" + container_div);
                      $("<table  width='100%'  id='tbl_footerannouncement'  cellpadding='0'><tr><td colspan='2' width='100%'>&nbsp;</td></table>").appendTo("#div_footerannouncment_list");
                      
                          $(announcement_object.schedule).each(function(i)
                          {
                             if(announcement_object.schedule[i].Announcement.Title!=null)
                               {
                                    if(announcement_object.schedule[i].Announcement.Content!=null)
                                     {
                        
                                                 $("<tr><td width='1%'>&nbsp;-</td><td width='99%'><span  class='announcementsubheader'>"+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</span>"+
                                                 "&nbsp;<a id='Sannoucement_more" + i  + "' href='javascript:void(0);' style='text-decoration:none'><b>...</b></a></td></tr>").appendTo("#tbl_footerannouncement");
                                                 
                                                    $("#Sannoucement_more" + i).unbind("click").bind("click",function(event)
                                                    {
                                                      
                                                        var strTitle=announcement_object.schedule[i].Announcement.Title;
                                                        if(strTitle!=''&&strTitle!=null)
                                                        {
                                                            strTitle=replacecharacter(strTitle,",","~");
                                                        }
                                                        var strContent=announcement_object.schedule[i].Announcement.Content;
                                                        if(strContent!=''&&strContent!=null)
                                                        {
                                                            strContent=replacecharacter(strContent,",","~");
                                                        }
                                                        ShowContentFullView(strTitle,strContent,announcement_object.schedule[i].Announcement.URL,event.pageX,event.pageY,rskey_scheduleannouncements);
                                                     });
                                                    
                                     }
                                     else
                                     {
                                        if(announcement_object.schedule[i].Announcement.URL!=null)
                                           {
                                              $("<tr><td>&nbsp;-&nbsp;</td><td>"+ 
                                             "<span class='announcementsubheader'><a  class='announcementsubheaderlink' href='" +  announcement_object.schedule[i].Announcement.URL+ "' target='_blank'> "+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</a></span>" + 
                                             "</td></tr>").appendTo("#tbl_footerannouncement");
                                           }
                                           else
                                           {
                                                $("<tr><td>&nbsp;&nbsp;</td><td><span class='announcementsubheader'>"+ $.trim(announcement_object.schedule[i].Announcement.Title) +"</span>"+
                                                "</td></tr>").appendTo("#tbl_footerannouncement");
                                           }
                                     }
                               }
                               
                          });
                    }
                 
             }
             
              getAllAnnouncements(getAgencyID(),getSelectedRouteID(),render_footerannoucement);
        }
        catch(err)
        {
            var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
            logerror(err,window.location,"renderingfunctions_schedules.js","renderFooterAnnouncements",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }
        
        
    }
    //render Schedule Time Selection table
    function renderScheduleCustomizeSelector()
    {
        try
        {
            var stoplist_html='';
            stoplist_html="<table id='tbl_schedule_customizeselector' style='display:none' border='0' cellpadding='3' class='schedulesListingsHeadingTable'>";
            stoplist_html+="<tr class='minimalTopPad'>";
            stoplist_html+="<td class='refreshScheduleTableCell2' ><span id='span_schedule_fromtime'><strong>"+ rskey_schedulefrom+":&nbsp;</strong></span>";
            stoplist_html+="<input id='txt_fromtimehr'  maxlength='2' type='text' class='timeInput borderInput'/><span id='span_fromtimesep'><strong>:</strong></span><input maxlength='2' id='txt_fromtimemin'  type='text' class='timeInput borderInput'/>";
            stoplist_html+=" <select id='dd_fromtime' class='borderSelect paddedSelect'>";
            stoplist_html+="<option value='AM'>"+rskey_amtime+"</option>";
            stoplist_html+="<option value='PM'>"+rskey_pmtime +"</option>";
            stoplist_html+="</select></td>";
            stoplist_html+="<td class='refreshScheduleTableCell2'><span id='span_schedule_totime'><strong>"+rskey_scheduleto+":&nbsp;</strong></span>";
            stoplist_html+="<input id='txt_totimehr' maxlength='2' type='text' class='timeInput borderInput' /><span id='span_totimesep'><strong>:</strong></span><input maxlength='2' id='txt_totimemin' type='text' class='timeInput borderInput' />";
            stoplist_html+=" <select id='dd_totime' class='borderSelect paddedSelect'>";
            stoplist_html+="<option value='AM'>"+rskey_amtime+"</option>";
            stoplist_html+="<option value='PM'>"+rskey_pmtime +"</option>";
            stoplist_html+="</select></td>";
            stoplist_html+="<td class='refreshScheduleTableCell2' width='40%'><table width='100%' id='tbl_btn_getcustomize_schedule' height='23px' border='0' cellspacing='0' cellpadding='0'><tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center'>";
            stoplist_html+="<a href='javascript:void(0);' id='btn_getcustomize_schedule' class='BtnWidget_alink'>"+rskey_displaycustomizedschedule+"</a></td><td class='BtnWidget_right'>&nbsp;&nbsp;</td></tr></table></td>";
            stoplist_html+="<td id='td_schedule_bottomreturnfullschedule' width='100%' style='text-align: right;'><a href='javascript:void(0);' id='btn_redisplay_schedule'>";
            stoplist_html+= rskey_returnredisplayfullschedule+"</a></td>";
            stoplist_html+="</tr>";
            stoplist_html+="</table>";
            return stoplist_html;
        
        }
         catch(err)
        {
            
            logerror(err,window.location,"renderingfunctions_schedules.js","renderScheduleCustomizeSelector",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
    
       
    }

    
    //Show only customized stops  

    function ShowOnlyCustomizedStops(selectedstopname)
    {
        
        try
        {
            var $table=$("#tbl_schedule_data");
            var _headerrows = $table.find('thead > tr').get();
            var stopname;
            var stopids='';
            var arr_selected=selectedstopname.split("~");
            var bln_show=false;

             $.each(_headerrows,function()
             {
                var _cells= $(this).find('td').get();
                $.each(_cells,function(i) 
                {
                    if(selectedstopname!='')
                    {
                      stopname=$(this).find("input:hidden").val().split("~")[1];
                      
                      bln_show=false;
                          for(idx=0;idx<=arr_selected.length-1;idx++)
                          {
                            if(arr_selected[idx].toUpperCase()==stopname.toUpperCase())
                            {
                                bln_show=true;
                                if(stopids=='')
                                {
                                    stopids=$(this).find("input:hidden").val().split("~")[0];
                                }
                                else
                                {
                                    stopids +="," + $(this).find("input:hidden").val().split("~")[0];
                                }
                                break;
                            }
                          }
                           if(bln_show==false)
                           {
                             $("#tbl_schedule_data").find('tr').each(function()
                             {
                                $(this).find("td:eq(" + i + ")").hide();
                                $(this).find("th:eq(" + i + ")").hide();
                             });
                             
                           }
                    }
                    else
                    {
                         $("#tbl_schedule_data").find('tr').each(function()
                             {
                                $(this).find("td:eq(" + i + ")").show();
                                $(this).find("th:eq(" + i + ")").show();
                             });
                    }
                    
                });
              }); 
              $("#td_schedule_red_row").show(); 
               
               if(stopids!='')
                {
                  
                    setcustomizedstops(stopids);
                    loadcustomizedstopsonmap(stopids);
                }
        
        }
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","ShowOnlyCustomizedStops",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
        
        
     
    }


    //Render Effective date , direction and type
    function rendereffectivedate()
    {
        $("#span_direction").html($("#direction_select :selected").text());
        $("#span_type").html($("#type_select :selected").text());
        var now=new Date();
        var dateFormat=now.getMonth()+1 + "/" + now.getDate() + "/" + now.getFullYear() ; 
        $("#span_date").html(dateFormat);
    }
   
    //Render Stops Drop Down For Maps
   function renderstopsdropdown(scheduleStopItems_obj)
    {
        try
        {
                $("#dd_stop_map").empty();
                for(var property in scheduleStopItems_obj.Stops)
                {
                    option_html= "<option value='" + property + "'>" +scheduleStopItems_obj.Stops[property] + "</option>";
                    $(option_html).appendTo("#dd_stop_map");
                }
                //Appending this element at last for i.e 6.0
                $("<option value='0'>Select Stops On Map</option>").appendTo("#dd_stop_map");
             
               
               

                $("#dd_stop_map").unbind("change").bind("change",function()
                {
                    if ($("#dd_stop_map").val()!=0)
                    {
                        loadselectedstopsonmap($("#dd_stop_map").val());
                    }
                });  
        
        }
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","renderstopsdropdown",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
       
       
    }


   //Render Valid day type based on Direction
    function ValidateDays(Dirselect)
    {
        try
        {
            var option_html;
            var selected_Day = $("#type_select").val();
            var selected=false;
            $('#type_select').empty(); 
            $(glb_scheduleOptionlist.ValidDirDay[Dirselect.value]).each(function(i){

                        option_html= "<option value='" ;
                        option_html += glb_scheduleOptionlist.ValidDirDay[Dirselect.value][i] ;
                        option_html += "'";
                        
                        if(selected_Day == glb_scheduleOptionlist.ValidDirDay[Dirselect.value][i] )
                        {
                           selected=true;
                        }
                        
                         option_html += ">" + glb_scheduleOptionlist.DayTypes[glb_scheduleOptionlist.ValidDirDay[Dirselect.value][i]] + "</option>";
                        $(option_html).appendTo("#type_select");
                        option_html ="";
                        });
            if(selected)
            {
                $("#type_select").val(selected_Day);
            }
         
            
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","ValidateDays",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
    

        
    //rendereffectivedate();

    }
    
     //Render Valid direction based on day type
    function ValidateDir(DaySelect)
    {
        try
        {
            var option_html;
            var selected_Dir = $("#direction_select").val();
            var selected=false;
            $('#direction_select').empty(); 
            $(glb_scheduleOptionlist.ValidDayDir[DaySelect.value]).each(function(i){
                option_html= "<option value='" ;
                option_html += glb_scheduleOptionlist.ValidDayDir[DaySelect.value][i] ;
                option_html += "'";
                if(selected_Dir == glb_scheduleOptionlist.ValidDayDir[DaySelect.value][i])
                {
                    selected=true;
                }
                option_html += ">" + getValidDirectionName(glb_scheduleOptionlist.ValidDayDir[DaySelect.value][i]) + "</option>";
                $(option_html).appendTo("#direction_select");
                option_html ="";
                
                });
            if(selected)
            {
                $('#direction_select').val(selected_Dir);
            }
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","ValidateDir",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
        
        
    //rendereffectivedate();
    }

     //get direction name based
    function getValidDirectionName(dir)
    {
        try
        {
            var dirname=dir;
            var objparams= getScheduleParams();
            $(objparams.Directions).each(function(i)
            {
                if(objparams.Directions[i].split(":")[0]==dir)
                {
                    dirname=objparams.Directions[i].split(":")[1];

                }
            });
            return dirname;
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","getValidDirectionName",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
        
    }

 //render customize schedule
    function rendercustomizeschedule(container_div)
    {
            try
            {
            
                var $table=$("#tbl_schedule_data");
                var _headerrows = $table.find('thead > tr').get();
                var _fromval='';
                var _toval='';
                var _selectedstopids='';
                var _selectedstopnames='';
                

                if($("#txt_fromtimehr").val()!=''||$("#txt_fromtimemin").val()!='')
                {
                    _fromval=convertto24hours(formatstoptime($.trim($("#txt_fromtimehr").val()+":"+ $("#txt_fromtimemin").val()) + $("#dd_fromtime").val()));
                }   
                if($("#txt_totimehr").val()!=''||$("#txt_totimemin").val()!='')
                {
                     _toval=convertto24hours(formatstoptime($.trim($("#txt_totimehr").val()+":"+ $("#txt_totimemin").val()) + $("#dd_totime").val()));

                }    
             
                $.each(_headerrows,function()
                {
                    var _cells= $(this).find('td').get();
                    $.each(_cells,function(i) 
                    {
                        if($(this).find("input").attr("checked")!=null)
                        {
                             
                                  if(_selectedstopids=='')
                                   {
                                     _selectedstopids=$(this).find("input:hidden").val().split("~")[0];
                                     _selectedstopnames=$(this).find("input:hidden").val().split("~")[1];
                                   }
                                   else
                                   {
                                     _selectedstopids +="," + $(this).find("input:hidden").val().split("~")[0];
                                     _selectedstopnames += "~" + $(this).find("input:hidden").val().split("~")[1];
                                   }
                        }
                   });    
                });     
                
                showcustomizetimelabel();
                
                var retarray=new Array(_selectedstopids,_selectedstopnames)
                //call map functions 
                //loadroutemap();
                if(_selectedstopids!='')
                {
                    setcustomizedstops(_selectedstopids);
                    //need to be uncommented when we implement map with customization
                    loadcustomizedstopsonmap(_selectedstopids);
                }
                

                    
                    function render_customizeschedule(scheduleStopItems_obj)
                    {
                        renderschedulesstoplist(scheduleStopItems_obj,container_div,true);
                        $("#a_print_customize").unbind("click").bind("click",function()
                           {
                                var patterntext;
                                patterntext=$("#span_type").text() +  " - " +  $("#span_direction").text() + " - " + rskey_effectivedate +":"+ $("#span_date").text();
                                patterntext+= " " +$("#span_customizetime_label").text();
                                window.open("printschedulewithoutmap.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&withmap=0&customize=1&patterntext="+patterntext+"&stopids="+_selectedstopids+"&fromtime="+_fromval +"&totime="+_toval,null,MapWindowParams); 
                           });
                        
                    }
                    getCustomizeSchedule(getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),_selectedstopids,_fromval,_toval,render_customizeschedule);
                
               
                   if(ismapvisible()==true)
                    {
                        
                        $("#a_print_schedulewithmap").insertAfter("#a_print_customize");
                        $("#a_print_schedulewithmap").text(rskey_printcustomizedschedulewithmap);
                        $("<span>&nbsp;&nbsp;</span>").insertBefore("#a_print_schedulewithmap");
                        $("#a_print_schedulewithmap").show();
                        
                        $("#a_print_schedulewithmap").unbind("click").bind("click",function()
                        {
                             
                            var patterntext;
                            patterntext=$("#span_type").text() +  " - " +  $("#span_direction").text() + " - " + rskey_effectivedate +":"+ $("#span_date").text();
                            patterntext+= " " +$("#span_customizetime_label").text();
                            map_loadprintroutemap(getAgencyID(),getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),"1",_selectedstopids,"1",patterntext,_fromval,_toval);
                            //window.open("printschedulewithoutmap.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&withmap=0&customize=1&patterntext="+patterntext+"&stopids="+_selectedstopids+"&fromtime="+_fromval +"&totime="+_toval,null,MapWindowParams); 
                            
                        });
                    } 
                    else
                    {
                         $("#a_print_schedulewithmap").hide();
                    }
            return retarray;
            
            }
            catch(err)
            {
                
                var referencetext="RouteID:"+ getSelectedRouteID() + ",Dir:"+ $("#direction_select").val() + ",daytype: "+ $("#type_select").val();
                referencetext += ",FromTime:"+ _fromval + ",ToTime:"+ _toval;
                logerror(err,window.location,"renderingfunctions_schedules.js","rendercustomizeschedule",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
            }
            
            
            
            
    }





    //hyperlinking stops name for mapping
    function hyperlinkstopsheader()
    {

        try
        {
        
             $("#tbl_schedule_data").find("tr[id='tr_stop_checkboxes']").each(function()
                {


                    $.each($(this).find('td').get(),function(i) 
                    {
                   
                       
                         $("#tbl_schedule_data").find("tr[id='tr_schedule_stopsheader']")
                         .find("th:eq(" + i + ")")
                         .html("<a style='text-decoration:none' id='a_stoplinkcontrol_"+i+"'OnClick='javascript:loadselectedstopsonmap(" + 
                         $(this).find("input:hidden").val().split("~")[0] +");'" +
                         " href='javascript:void(0)'>"+ replacecharacter($(this).find("input:hidden").val().split("~")[1],"$","'") +"</a>");
                    });
                    
                });
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","hyperlinkstopsheader",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
        
       

  
    }
    
    function removehyperlinkstopsheader()
    {

        try
        {
                $("#tbl_schedule_data").find("tr[id='tr_stop_checkboxes']").each(function()
                {


                    $.each($(this).find('td').get(),function(i) 
                    {
                       
                         $("#tbl_schedule_data").find("tr[id='tr_schedule_stopsheader']")
                         .find("th:eq(" + i + ")")
                         .html($(this).find("input:hidden").val().split("~")[1] +"");
                    });
                    
                });
        
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","removehyperlinkstopsheader",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
       
     
    }
    function setfocusonstoplink()
    {  
        try
        {
            if(!$("#div_schedule").is(":hidden"))
             {
                 if($("#a_stoplinkcontrol_0").attr("id")!=undefined)
                 {
                    $("#a_stoplinkcontrol_0").focus();
                 }   
             }   
        
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","setfocusonstoplink",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
         
           
    }

 

    // format the time point stops
    function formatstoptime(strtime)
    {  
        try
        {
            var str_return=strtime;
            if(strtime.indexOf('A')>=1)
            {

            timearr=strtime.split("A");
            str_return="00" + $.trim(timearr[0]) + " AM";
            str_return=str_return.substring(str_return.length,str_return.length-8);
            }
            else if(strtime.indexOf('P')>=1)
            {
            timearr=strtime.split("P"); 
            str_return="00" + $.trim(timearr[0])  + " PM";
            str_return=str_return.substring(str_return.length,str_return.length-8);
            }
            return str_return;
        
        }
         catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","formatstoptime",ErrorWWWNonFatal,strtime,getAgencyID(),getSelectedRouteID())
        }
        
        
        
        
    }


    //Validate the schedule search 
    function validateschedulesearch(tPosX,tPosY)
    {

        try
        {
            if($("#txt_fromtimehr").val()!=""||$("#txt_fromtimemin").val()!="")
            {
            var fromminutes;
            var fromhr;
            //$("#txt_fromtimehr").val( $("#txt_fromtime").val().replace(";",":"));
                if($("#txt_fromtimemin").val()!="")
                {
                  fromminutes = "00" +  $.trim($("#txt_fromtimemin").val()); 
                  fromminutes=fromminutes.substring(fromminutes.length,fromminutes.length-2);
                  
                }
                else
                {
                   fromminutes = "00" ; 
                }
                if($("#txt_fromtimehr").val()!="")
                {
                  fromhr = "00" + $.trim($("#txt_fromtimehr").val()); 
                  fromhr=fromhr.substring(fromhr.length,fromhr.length-2);
                  
                }
                else
                {
                     fromhr = "00" ;
                }

                if(invalidTime(fromhr +":" + fromminutes + $("#dd_fromtime").val().toLowerCase())==true)
                {
                    alert(rskey_msgschedulecorrecttime);
                    $("#txt_fromtimehr").focus();
                    return false;
                }
                else
                {
                    $("#txt_fromtimemin").val(fromminutes);
                    $("#txt_fromtimehr").val(fromhr);
                }
            }


                if($("#txt_totimehr").val()!=""||$("#txt_totimemin").val()!="")
                {
                        var tominutes;
                        var tohr;
                    //$("#txt_fromtimehr").val( $("#txt_fromtime").val().replace(";",":"));
                        if($("#txt_totimemin").val()!="")
                        {
                          tominutes = "00" +  $.trim($("#txt_totimemin").val()); 
                          tominutes=tominutes.substring(tominutes.length,tominutes.length-2);
                          
                        }
                        else
                        {
                           tominutes = "00" ; 
                        }
                        if($("#txt_totimehr").val()!="")
                        {
                          tohr = "00" +  $.trim($("#txt_totimehr").val()); 
                          tohr=tohr.substring(tohr.length,tohr.length-2);
                          
                        }
                        else
                        {
                             tohr = "00" ;
                        }

                        if(invalidTime(tohr +":" + tominutes + $("#dd_totime").val().toLowerCase())==true)
                        {
                            alert(rskey_msgschedulecorrecttime);
                            $("#txt_totimehr").focus();
                            return false;
                        }
                        else
                        {
                            $("#txt_totimemin").val(tominutes);
                            $("#txt_totimehr").val(tohr);
                        }
                 }

            if($("#tr_stop_checkboxes").find("input").filter("[@checked]").length<2)
            {
                alert(rskey_msgscheduleselectrow);
                $("#tr_stop_checkboxes").focus();
                return false;

            };
            return true;
        
        
        }
        catch(err)
        {
            logerror(err,window.location,"renderingfunctions_schedules.js","validateschedulesearch",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
        
        
        
    }
    
    //clear the time selection
    function clearscheduleform()
    {
      $("#txt_fromtimehr").val("");
      $("#txt_fromtimemin").val("");
      $("#txt_totimehr").val("");
      $("#txt_totimemin").val("");
      $("#dd_fromtime").val("AM");
      $("#dd_totime").val("AM");
      
    }
   
   //get the roundedtime near quarter hr
    function getRoundedtime(curr_hour,curr_min)
    {
        try
        {
               var a_p = "";
               if(curr_min==0)
                {
                   curr_min="0";
                }
                else if(curr_min>0 && curr_min<=15)
                {
                    curr_min="15";
                }
                else if(curr_min>15 && curr_min<=30)
                {
                    curr_min="30";
                }
                else if(curr_min>30 && curr_min<=45)
                {
                    curr_min="45";
                }
                else
                {
                  curr_min= "00";  
                  
                }
               
                if(curr_min=="00")
                {
                 curr_hour = parseInt(curr_hour)+1;
                }
                

                if (curr_hour < 12)
                   {
                   a_p = "AM";
                   }
                else
                   {
                   a_p = "PM";
                   }
                if (curr_hour == 0)
                   {
                   curr_hour = 12;
                   }
                if (curr_hour > 12)
                   {
                   curr_hour = parseInt(curr_hour) - 12;
                   }
                curr_hour= "00" + curr_hour
                curr_hour=curr_hour.substring(curr_hour.length,curr_hour.length-2);
               
                curr_min= "00" + curr_min
                curr_min=curr_min.substring(curr_min.length,curr_min.length-2);
               
               return curr_hour +":" +  curr_min + ":" + a_p;
        
        
        }
        catch(err)
        {
            var referencetext=curr_hour +":"+ curr_min;
            logerror(err,window.location,"renderingfunctions_schedules.js","getRoundedtime",ErrorWWWNonFatal,referencetext,getAgencyID(),getSelectedRouteID())
        }
           
           
          
    }
    
    //preset the customize time
    function presetcustomizetime()
    {
           var rounded_time;
           var now = new Date();
           var curr_min = now.getMinutes();
           var curr_hour = now.getHours();
           rounded_time=getRoundedtime(curr_hour,curr_min);
           rounded_time=rounded_time.split(":");
           $("#txt_fromtimehr").val(rounded_time[0]);
           $("#txt_fromtimemin").val(rounded_time[1]);
           $("#dd_fromtime").val(rounded_time[2]);
           curr_min += 120;           // Add 120 minutes to the time
           now.setMinutes(curr_min); // Reset to new value
           curr_min = now.getMinutes();
           curr_hour = now.getHours();
           rounded_time=getRoundedtime(curr_hour,curr_min);
           rounded_time=rounded_time.split(":");
           $("#txt_totimehr").val(rounded_time[0]);
           $("#txt_totimemin").val(rounded_time[1]);
           $("#dd_totime").val(rounded_time[2]);
   
    }
    
    //show the customize time label
    function showcustomizetimelabel()
    {
        var _fromval='';
        var _toval='';
       
        if($("#txt_fromtimehr").val()!=''||$("#txt_fromtimemin").val()!='')
        {
        _fromval=$.trim($("#txt_fromtimehr").val()+":"+ $("#txt_fromtimemin").val()) + " " +  $("#dd_fromtime").val();
        }   
        if($("#txt_totimehr").val()!=''||$("#txt_totimemin").val()!='')
        {
        _toval=$.trim($("#txt_totimehr").val()+":"+ $("#txt_totimemin").val()) +" " +$("#dd_totime").val();

        }    
       if($("#txt_fromtimehr").val()!=''&&$("#txt_fromtimemin").val()!='')
       {
         $("#span_customizetime_label").html(rskey_between  + " " +  _fromval  + " " + rskey_and  + " " + _toval);
         $("#span_customizetime_label").show();
       }  
    }

    
    //show schedule up arrow for full view
    function showscheduleuparrow()
    {
       
        $("#a_schedule_list_close").show();
        $("#div_schedule_listclose").show();
    }
    
    function hidescheduleuparrow()
    {
       
        $("#a_schedule_list_close").hide();
        $("#div_schedule_listclose").hide();
        showbuttonshowmaplink();
    }
     //show the stops drop down for mappping
    function displayprintschedulewithmap()
    {

        if(ismapenable()==true)
        {
            if(ismapvisible()==true)
            {
           
               // $("#a_print_schedulewithmap").show();
                if(!$("#a_print_customize").is(":hidden"))
                {
                  
                    $("#a_print_schedulewithmap").show();
                    $("#a_print_schedulewithmap").insertAfter("#a_print_customize");
                    $("<span>&nbsp;&nbsp;</span>").insertBefore("#a_print_schedulewithmap");
                    $("#a_print_schedulewithmap").text(rskey_printcustomizedschedulewithmap);
                    
                    $("#a_print_schedulewithmap").unbind("click").bind("click",function()
                        {
                             
                            var patterntext;
                            patterntext=$("#span_type").text() +  " - " +  $("#span_direction").text() + " - " + rskey_effectivedate +":"+ $("#span_date").text();
                            patterntext+= " " +$("#span_customizetime_label").text();
                            map_loadprintroutemap(getAgencyID(),getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),"1",getcustomizedstops(),"1",patterntext,getCustomizeFromTime(),getCustomizeToTime());
                            //window.open("printschedulewithoutmap.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&withmap=0&customize=1&patterntext="+patterntext+"&stopids="+_selectedstopids+"&fromtime="+_fromval +"&totime="+_toval,null,MapWindowParams); 
                            
                        });
                } 
                else
                {
                    
                    $("#a_print_schedulewithmap").show();
                    $("#a_print_schedulewithmap").text(rskey_printschedulewithmap);
                    $("#a_print_schedulewithmap").insertBefore("#a_print_schedulewithoutmap");
                    $("<br>").insertBefore("#a_print_schedulewithoutmap");
                    $("#a_print_schedulewithmap").unbind("click").bind("click",function()
                        {
                             
                             var patterntext;
                             patterntext=$("#span_type").text() + " - " + $("#span_direction").text() + " - " +  rskey_effectivedate +":"+ $("#span_date").text();
                            // window.open("printschedule.aspx?cid=" + getAgencyID() + "&routeid=" + getSelectedRouteID() + "&dir=" + getScheduleDirection() + "&daytype=" + getScheduleDayType()+ "&fromstop="+getScheduleStartStop()+"&tosstop="+getScheduleEndStop()+"&mode="+mode+"&withmap=1&customize=0&patterntext="+patterntext,null,MapWindowParams); 
                            map_loadprintroutemap(getAgencyID(),getSelectedRouteID(),getScheduleDirection(),getScheduleDayType(),"1","","0",patterntext,"","");
                            
                        });
                }
            }
            else
            {
                $("#a_print_schedulewithmap").hide();
            }
        }
        else
        {
            $("#a_print_schedulewithmap").hide();
        }

    }
    //show the stops drop down for mappping
    function showstopsonmapsearch()
    {

      if(ismapenable()==true)
      {
        $("#span_showstopslabel_schedule").show();
        $("#dd_stop_map").show();
      }  
    }
    //show the stops drop down for mappping
    function hidestopsonmapsearch()
    {

       $("#span_showstopslabel_schedule").hide();
       $("#dd_stop_map").hide();
        
    }
   
   //hide the announcements links 
   function hidescheduleannoucementlink()
   {
    $("#a_route_annoucement").hide();
    $("#div_routeschedule_announcment").hide();
    $("#div_routesannounce_flasher").hide();
   }
   
   function hidebuttonshowmaplink()
   {
       
        $("#tbl_btn_showmap").hide();
   }
   function showbuttonshowmaplink()
   {
        $("#tbl_btn_showmap").show();
   }
   
   //hide the announcements links 
   function showscheduleannoucementlink()
   {
        $("#a_route_annoucement").show();
    
   }
   function hidescheduleannounceflasher()
   {
        $("#div_routesannounce_flasher").hide();
   }
   function hideprintschedulewithmap()
   {
         $("#a_print_schedulewithmap").hide();
   }
     //reset the stops drop down for mappping
    function resetstopsdropdownsearch()
    {
      $("#dd_stop_map").val("0");   
    }

    function setcustomizedstops(stopids)
    {
        glb_customizedstopids=stopids;
    } 

    function getcustomizedstops()
    {
        return glb_customizedstopids;
    } 
    

    function getallstops()
    {
        return glb_allstopids;
    }
    function setallstops(stopids)
    {
        glb_allstopids =stopids;;
    }
    
    function getSelectedDirectionName()
    {
        
        return $("#direction_select").find("option:selected").text();
        
    }
    function getSelectedDirectionID()
    {
       return $("#direction_select").val();
    }
    function getSelectedDayTypeID()
    {
        return $("#type_select").val();
    }
    //*********************************Ends Here: Rendering Schedule *********************


    function IsRouteValid(routeid)
    {
       
        if(getSelectedRouteDesignator(routeid)==null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    
    function renderRailLineDiagram(railLineDetails_obj,container_div,raillineclosecallback,raillinefullviewcallback)
    {
        try
        {
        
        if(!IsRouteValid(getSelectedRouteID()))
            {
                $("#" + container_div).find("#railLines_Div").empty().remove();
                $("<div id='railLines_Div' class='schedulesListingsOuterBorderBox'>"+
                "<table width='100%'><tr><td style='text-align:center'>Route not found.</td></tr>"+
                "</table></div>").appendTo("#"+ container_div); 
                return false;
            }
            
        
        
        
            $("#"+ container_div).find("#railLines_Div").empty();
            $("<div class='closeBox' style='display:none' id='div_rail_line_listup'><a id='a_rail_line_up' href='javascript:void(0)'><img src='http://images.transit.511.org/RUI/fw/btn_scheduleuparrow.gif' alt='"+ rskey_raillinefullview +"' /></a>&nbsp;<a id='a_rail_line_upclosemap' href='javascript:void(0);' style='text-decoration:none'>"+rskey_closemap+"</a></div>").appendTo("#railLines_Div");
             // $("<div class='closeBox'><a id='a_rail_line_close' href='javascript:void(0);'><img src='http://images.transit.511.org/RUI/fw/btnX_11pxSquare.gif' alt='Close' /></a></div>").appendTo("#railLines_Div");
            $("<table id='railLinesHeading' cellpadding='3' class='railLinesHeadingTable' cellspacing='0'></table>").appendTo("#railLines_Div");

    var headertableHTML = "<tr>";
    headertableHTML += "<td style='vertical-align: top;'><img src='http://images.transit.511.org/RUI/fw/transport_icons_flush/iconRail.png' alt='Rail' align='absmiddle' style='margin-right: 10px;' id='img_mode_icon'/></td>";
    headertableHTML += "<td><h1 class='schedulesHeadingRailLine'>";
    //headertableHTML += railLineDetails_obj.RailRouteName;
    headertableHTML += getSelectedRouteDesignator(getSelectedRouteID()) + " - (" + getAgencyName() + ") " + getSelectedRouteName(getSelectedRouteID()) ;
    //headertableHTML += "</h1></td><td style='text-align: right;'><a id='a_rail_line_close_2' href='javascript:void(0);' class='cssButtonBlue'>Display Full Schedule</a></td>";
    headertableHTML += "</h1>";
    headertableHTML += "</td><td style='text-align: right;'>" 
    headertableHTML +="<table><tr><td><table id='tbl_btn_railshowmap' width='138px' height='23px' border='0' cellspacing='0' cellpadding='0' style='display:none'>" 
    headertableHTML +="<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center' ><a id='btn_showroutemapfromrail' style='text-decoration:none' href='javascript:void(0)' "
    headertableHTML +=" class='BtnWidget_alink'>"+rskey_showmap+"</a></td><td class='BtnWidget_right'>&nbsp;</td></tr></table></td>"
    headertableHTML +="<td><table width='100%' height='23px' border='0' cellspacing='0' cellpadding='0'>" 
    headertableHTML +="<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center' >"
    headertableHTML +="<a id='a_rail_line_close_2' style='text-decoration:none' href='javascript:void(0);' class='BtnWidget_alink'>"+rskey_displayfullschedule+"</a>"
    headertableHTML +="</td><td class='BtnWidget_right'>&nbsp;</td></tr></table></td>" 
    headertableHTML +="</tr></table></td>"
    headertableHTML += "</tr>";
    $(headertableHTML).appendTo("#railLinesHeading");

            $("<table id='railLines' cellpadding='0' class='railLinesTable' cellspacing='0'></table>").appendTo("#railLines_Div");

            var railLinesHeaderHTML = "<tr class='topBorderRow'><td colspan='6'></td></tr><tr><th>"+rskey_station+"</th><th>"+rskey_busconnection+"</th><th>"+rskey_railconnection+" </th><th><div id='accessKeyBox'><table class='keyTable' cellspacing='0'><tr><td class='boxTop'></td>";
            railLinesHeaderHTML += "</tr><tr>";
            railLinesHeaderHTML += "<td class='contentBox'><div class='closeBox' style='padding-right: 4px;'><a href=\"javascript:toggleLayer('accessKeyBox');\"><img src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' title='Close' /></a></div>";
            railLinesHeaderHTML += "<h1>"+rskey_accessfeatures+"</h1>";
            railLinesHeaderHTML += "<div class='boxDivider'></div>";
            railLinesHeaderHTML += "<table cellpadding='0' class='accessKeyTable' cellspacing='0'>";
            railLinesHeaderHTML += "<tr>";
            railLinesHeaderHTML += "<td><img src='http://images.transit.511.org/RUI/fw/iconHandicapAccess.gif' title='"+rskey_handicapaccess+"' /></td>";
            railLinesHeaderHTML += "<td><strong>"+rskey_handicapaccess+"</strong></td>";
            railLinesHeaderHTML += "</tr><tr>";
            railLinesHeaderHTML += "<td><img src='http://images.transit.511.org/RUI/fw/iconElevator.gif' title='Elevator' /></td>";
            railLinesHeaderHTML += "<td><strong>"+rskey_elevator+"</strong></td>";
            railLinesHeaderHTML += "</tr><tr>";
            railLinesHeaderHTML += "<td><img src='http://images.transit.511.org/RUI/fw/iconEscalator.gif' title='Escalator' /></td>";
            railLinesHeaderHTML += "<td><strong>"+rskey_escalator+"</strong></td>";
            railLinesHeaderHTML += "</tr><tr>";
            railLinesHeaderHTML += "<td><img src='http://images.transit.511.org/RUI/fw/iconPhone.gif' title='TDD Phone' /></td>";
            railLinesHeaderHTML += "<td><strong>"+rskey_phone+"</strong></td>";
            railLinesHeaderHTML += "</tr></table>";
            railLinesHeaderHTML += "</td>";
            railLinesHeaderHTML += "</tr><tr>";
            railLinesHeaderHTML += "<td class='boxBtm'></td></tr></table>";
            railLinesHeaderHTML += "</div>";
            railLinesHeaderHTML += ""+rskey_access+" (<a href=\"javascript:toggleLayer('accessKeyBox');\">"+rskey_key+"</a>) </th>";
            railLinesHeaderHTML += "<th>"+rskey_cycling+"</th>";
            railLinesHeaderHTML += "<th class='rightCell'>"+rskey_parking+"</th>";
            railLinesHeaderHTML += "</tr>";

            $(railLinesHeaderHTML).appendTo("#railLines");

            var railLinescell1;
            var railLinescell2;
            var railLinescell3;
            var railLinescell4;
            var railLinescell5;
            var railLinescell6;
            
            $(railLineDetails_obj.RailStation).each(function(i){
                railLinescell1='';
                railLinescell2='';
                railLinescell3='';
                railLinescell4='';
                railLinescell5='';
                railLinescell6='';
            
                $("<tr id='rw_"+i+"' ></tr>" ).appendTo("#railLines");
                //railLinesHTML = "<tr>";
                if(i==0)
                {
                    railLinescell1 += "<td class='stationCell firstStation' width='10%'>";
                }
                else if(i == railLineDetails_obj.RailStation.length-1)
                {
                    railLinescell1 += "<td class='stationCell lastStation' width='10%'>";
                }
                else
                {
                    railLinescell1 += "<td class='stationCell' width='10%'>";
                }
                railLinescell1 += railLineDetails_obj.RailStation[i].StationName;
                               
                railLinescell1 += "<wbr/></td>";
                
                $(railLinescell1).appendTo("#rw_"+i);
                
                railLinescell2 += "<td width='20%'><span>";
                            
               
                var connectionNum = 0;  
                

                    
            if(railLineDetails_obj.RailStation[i].BusConnections.length == undefined)
            {
                railLinescell2 += "&nbsp;";
            }
        
            railLinescell2 += railLineDetails_obj.RailStation[i].BusCellHTML;
        
        
            railLinescell2 += "</span></td>";
            
            $(railLinescell2).appendTo("#rw_"+i);
            
            railLinescell3 += "<td class='railConnectionsCell' width='20%'>";
            if(railLineDetails_obj.RailStation[i].RailConnections.length == undefined)
            {
                railLinescell3 += "&nbsp;";
            }
            
            
            connectionNum = 0;


            railLinescell3 += railLineDetails_obj.RailStation[i].RailCellHTML;
            railLinescell3 += "</td>";
            
            $(railLinescell3).appendTo("#rw_"+i);
            
            var hasAnyaccess=false;
            railLinescell4 += "<td class='accessFeaturesCell' width='20%'>";
            if (railLineDetails_obj.RailStation[i].AccessFeatues.HasWheelChairAccess)
            {
                railLinescell4 += "<img src='http://images.transit.511.org/RUI/fw/iconHandicapAccess.gif' title='Handicap Accessible' />";
                hasAnyaccess = true;
            }
            else
            {
                  railLinescell4 += "<p>&nbsp;</p>";
            }

            if (railLineDetails_obj.RailStation[i].AccessFeatues.HasElevator)
            {
                railLinescell4 += "<img src='http://images.transit.511.org/RUI/fw/iconElevator.gif' title='Elevator' />";
                hasAnyaccess = true;
            }     
            
            if (railLineDetails_obj.RailStation[i].AccessFeatues.HasEscalator)
            {
                railLinescell4 += "<img src='http://images.transit.511.org/RUI/fw/iconEscalator.gif' title='Escalator' />";
                hasAnyaccess = true;
            }
                    
            if (railLineDetails_obj.RailStation[i].AccessFeatues.HasTTYPhone)
            {
                railLinescell4 += "<img src='http://images.transit.511.org/RUI/fw/iconPhone.gif' title='TDD Phone' /></td>";
                hasAnyaccess = true;
            }
            
            if(!hasAnyaccess)
            {
                railLinescell4 += "<p>No Information Available</p>";
            }
                    
            $(railLinescell4).appendTo("#rw_"+i);
                    
            railLinescell5 += "<td width='15%'>";
                    
                    //railLinescell5 += "<strong>Bike Station Info: </strong><br />";
                    //railLinescell5 += "Hours: ";
                    //railLinescell5 += railLineDetails_obj.RailStation[i].CyclingDetail.OpenTime;
                    //railLinescell5 += ":00";
                    //railLinescell5 += "am-";
                    //railLinescell5 += railLineDetails_obj.RailStation[i].CyclingDetail.CloseTime;
                    //railLinescell5 += ":00";
                    //railLinescell5 += "pm";
                    //railLinescell5 += "<br />";
                    //railLinescell5 += "Info: ";
                    //if(railLineDetails_obj.RailStation[i].CyclingDetail.Info != null)
                    //{
                    //    railLinescell5 += railLineDetails_obj.RailStation[i].CyclingDetail.Info;
		            //    railLinescell5 += "<br />";
                    //}
               
               if(railLineDetails_obj.RailStation[i].CyclingDetail.RackSpaces==0 && railLineDetails_obj.RailStation[i].CyclingDetail.Lockers ==0)
               {
                 railLinescell5 += "No Bike Rack Spaces or Lockers Provided";
               }
               else
               {

                    railLinescell5 += "<strong>";
                    railLinescell5 +="Bike Rack Spaces:";
                    railLinescell5 +="</strong> ";
                    railLinescell5 += railLineDetails_obj.RailStation[i].CyclingDetail.RackSpaces;
                    railLinescell5 +="<br />";
                    railLinescell5 +="<strong>Lockers:</strong> ";
                    railLinescell5 += railLineDetails_obj.RailStation[i].CyclingDetail.Lockers;
                    if(railLineDetails_obj.RailStation[i].CyclingDetail.LockesFee >0)
                    {
                        railLinescell5 +=" (fee charged)";
                    }
                    railLinescell5 +="<br />";
                    railLinescell5 +="<strong>Bike Station:</strong> ";
                    if(railLineDetails_obj.RailStation[i].CyclingDetail.HasBikeStation)
                    {
                        railLinescell5 +=" Yes";
                    }
                    else
                    {
                        railLinescell5 +=" No";
                    }
                }
                railLinescell5 +="</td>";
                    
                $(railLinescell5).appendTo("#rw_"+i);
               
               railLinescell6 += "<td width='15%'>" 
               if(railLineDetails_obj.RailStation[i].ParkingDetail.ParkingSpace==0 && railLineDetails_obj.RailStation[i].ParkingDetail.AccessibleSpace ==0 && railLineDetails_obj.RailStation[i].ParkingDetail.CarpoolingSpace )
               {
                 railLinescell6 += "No Parking Provided";
               }
               else
               {
               
                railLinescell6 += "<strong>";
                railLinescell6 +="Parking Spaces:";
                railLinescell6 +="</strong> ";
                railLinescell6 +=railLineDetails_obj.RailStation[i].ParkingDetail.ParkingSpace;
                railLinescell6 +="<br />";
                railLinescell6 += "<strong>";
                railLinescell6 +="Accessible Spaces:";
                railLinescell6 +="</strong> :";
                railLinescell6 +=railLineDetails_obj.RailStation[i].ParkingDetail.AccessibleSpace;
                railLinescell6 +="<br />";
                railLinescell6 += "<strong>";
                railLinescell6 += "Car Pooling Spaces:";
                railLinescell6 += "</strong> ";
                railLinescell6 += railLineDetails_obj.RailStation[i].ParkingDetail.CarpoolingSpace;
                railLinescell6 += "<br />";
                railLinescell6 += "<strong>";
                //railLinescell6 += "Car Sharing Spaces:";
                //railLinescell6 += "</strong> ";
                //railLinescell6 += railLineDetails_obj.RailStation[i].ParkingDetail.CarsharingSpace;
                //railLinescell6 += "</td>";
               }
               railLinescell6 += "</td>";
               $(railLinescell6).appendTo("#rw_"+i);
                
             });
             
             
             
             
             $("#a_rail_line_up").unbind("click").bind("click",function()
             {
               // $("#" + container_div ).hide();
                raillinefullviewcallback();
                $("#tbl_btn_railshowmap").show();
             });
             $("#a_rail_line_upclosemap").unbind("click").bind("click",function()
             {
               // $("#" + container_div ).hide();
                raillinefullviewcallback();
                $("#tbl_btn_railshowmap").show();
             });
             

            $("#a_rail_line_close_2").unbind("click").bind("click",function()
             {
                $("#" + container_div ).hide();
                
                 if(blnfromraillinebookmark==true)
                 { 
                     
                      blnfromraillinebookmark=false;
                      appendtourl("m1=S&m2="+ glb_agency_mode + "&routeid="+ getSelectedRouteID() +"&dir="+ getScheduleDirection() +"&type="+getScheduleDayType()+"&cid="+ glb_agency_id,true);
                    
                 }
                 else
                 {
                   
                    raillineclosecallback();
                   
                 }
               
//                 if(!ismapvisible())
//                 {
//                    hidebuttonshowmaplink();
//                 } 
//                 else
//                 {
//                    showbuttonshowmaplink();
//                 }  
             });
             
              if(!ismapvisible())
               {
                   hideraillineuparrow();
                   $("#tbl_btn_railshowmap").show();
               }
               else
               {
                 showraillineuparrow();
                 $("#tbl_btn_railshowmap").hide();
               }
            
            $("#btn_showroutemapfromrail").unbind("click").bind("click",function()
             {
                $("#tbl_btn_railshowmap").hide();
               
                if(getScheduleDayType()!=undefined )
                {                
                  
                    showmapcallback();
                   
                 } 
                 else
                 {
                    
                    renderScheduleDataForMap();
                 }
                    
             });
                
            
        }
        catch(err)
        {
           logerror(err,window.location,"renderingfunctions_schedules.js","renderRailLineDiagram",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
   

    }

    function renderScheduleDataForMap()
    {
   
        function renderScheduleMapData()
        {            
           
            showmapcallback();
            blnfromraillinebookmark=true;
        }
        
        function renderScheduleDirDaytypeMapData(_routeid,scheduleOptionItems_obj)
        {
            
            var _dir;            
            var _daytype;
            
            _dir=scheduleOptionItems_obj.Directions[0].split(":")[0];
            _daytype=scheduleOptionItems_obj.ValidDirDay[_dir][0];
            
            
            getschedulesDataforMap(_routeid,_dir,_daytype,renderScheduleMapData);
        }
        
         var routeid;
         var dir;
         var daytype;   
        
         
       var param_array=getqueryparam();
       if(param_array!=null)
        {

         
              for(j=0;j<param_array.length;j++)
              {
                     var param=param_array[j].split("=");
                     if(param[0]=='routeid')
                     {
                         routeid=param[1];
                     }
                     if(param[0]=='dir')
                     {
                         dir=param[1];
                     }
                     if(param[0]=='type')
                     {
                         daytype=param[1];
                     }
                     
              }   
            
            if(dir==null)
            {
                
                getdirdaytypeDataforMap(routeid,renderScheduleDirDaytypeMapData);
            }
            else
            {
                  getschedulesDataforMap(routeid,dir,daytype,renderScheduleMapData);
            }
            
           
          }        
       
    }
    
    
    
function getdirdaytypeDataforMap(routeid,callbackfunction)
{ 
     
    if(glb_routeSelectedID!=routeid||glb_scheduleOptionlist==null)
      {
       
        glb_routeSelectedID=routeid;
        $.ajax({
          type: "GET",
          data: "rte=" + routeid ,
          url: schedules_servicepath,
          dataType: "json",
          success: function(scheduleOptionItems){
                    
              callbackfunction(routeid,scheduleOptionItems);
              
           },
          error: function(){
         
             //alert( "Error While Retrieving Schedules Directions and Types: ");
              var referencetext="ServiceError:"+  schedules_servicepath+"?rte=" + routeid;
              logerror(null,window.location,"datafunctions_schedules.js","getSchedules",PagesSchedulesRoutesMaps,referencetext,getAgencyID(),routeid) 
           }
        });
       }
       else
       {
        
            callbackfunction(glb_scheduleOptionlist);
       }
    
}


    function showrailconnectorschedule(routeid,agencyid,mode)
    {

        appendtourl("m1=S&m2="+mode+"&routeid="+routeid+"&cid="+agencyid ,true);
    }
    
    function hideraillineuparrow()
    {
        
        $("#div_rail_line_listup").hide();
    }
    function showraillineuparrow()
    {
        $("#div_rail_line_listup").show();
    }

function renderhelp(helpitem,headeritem,Xpos,Ypos,callingelementid)
{
    try
    {
        $("body").find("#div_schedule_help").remove();
            var help_html='';
            var tPosX=Xpos;
            var tPosY=Ypos;
            help_html="<div id='div_schedule_help' style='z-index:1099999;position:absolute;'>";
            help_html+="<table class='helpTable' cellspacing='0'><tr><td class='boxTop'></td></tr>";
            help_html+="<tr>";
            help_html+="<td class='contentBox'>";
            help_html+="<div class='closeBox' style='padding-right: 4px;'>";
            help_html+="<a id='a_helpclose'  href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
            help_html+="</div><a id='a_help_start' href='javacript:void(0);' title='Pop up help window start'></a><h1 class='helpHeader'>"+headeritem+"</h1>";
            help_html+="<div class='boxDivider'></div>" ;
            help_html+="<div id='div_schedule_help_data' class='helpTableListingdiv' >"+ helpitem +"</div><a id='a_help_end' href='javacript:void(0);' title='End of help Close Help Window'></a>"
            help_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
            $(help_html).appendTo("body")
            $('#div_schedule_help').css({top: tPosY, left:tPosX});
            $("#a_help_start").focus();
            $("#a_helpclose").unbind("click").bind("click",
            function()
            {
                $("body").find("#div_schedule_help").remove();
                $("#"+ callingelementid).focus();
            });
            
            $("#a_help_end").unbind("click").bind("click",
            function()
            {
                $("body").find("#div_schedule_help").remove();
                $("#"+ callingelementid).focus();
            });
    }
    catch(err)
        {
            var referencetext="Help:"+  headeritem;
            logerror(err,window.location,"renderingfunctions_schedules.js","renderhelp",ErrorWWWNonFatal,referencetext,"","")
        }
    
    
    
       // $("#div_schedule_help").draggable();
}

//********************************* Ends Here:Schedules/Index.aspx  *********************

//* * * * * * * * * renderingfunctions_schedules.js ends here  * * * * * * * * * * *//

//* * * * * * * * * controlfunctions_schedules.js starts here  * * * * * * * * * * *//
// JScript File
    // Prototype functions starts here
    var targetBox;
    var imgName;
    function buildAcc()
    {
        document.getElementById('routeListRow').style.display = "block";
        document.getElementById('fareListRow').style.display = "block";
        document.getElementById('annoucementListRow').style.display = "block";
        document.getElementById('agencyServiceAreaRow').style.display = "block";
        document.getElementById('faresBoxfareListRow').style.display = "block";
        document.getElementById('agencyBoxagenycyProfileRow').style.display = "block";
    }
 // collapse all panels  *setup loops by el name - fix
    function fireAcc(panel)
    {
   
        document.getElementById('agencySelectorPanel').style.display = "none";
        document.getElementById('routeListPanel').style.display = "none";
        document.getElementById('fareListPanel').style.display = "none";
        document.getElementById('annoucementListPanel').style.display = "none";
        document.getElementById('agencyServiceAreaPanel').style.display = "none";
        document.getElementById('fares_databox').style.display = "none";
        document.getElementById('agencyprofile_databox').style.display = "none";

        document.getElementById('agencySelectorAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#agencySelectorAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
       
        document.getElementById('routesListAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#routesListAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
       
        document.getElementById('fareListAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#fareListAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
        
        document.getElementById('annoucementListAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#annoucementListAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
         
        document.getElementById('agencyServiceAreaAjaxbar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#agencyServiceAreaAjaxbar").removeClass("openAjaxBar").addClass("closedAjaxBar");
       
        document.getElementById('fareBoxAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif')
        $("#fareBoxAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
        
        document.getElementById('agencyProfileAjaxBar').setAttribute('background','http://images.transit.511.org/RUI/images/accClosed.gif');
        $("#agencyProfileAjaxBar").removeClass("openAjaxBar").addClass("closedAjaxBar");
        
       
        // restore
        document.getElementById(panel).style.display = "block";
        document.getElementById(panel).parentNode.setAttribute('background','http://images.transit.511.org/RUI/images/accOpen.gif');
        $("#"+ panel).parent().removeClass("closedAjaxBar").addClass("openAjaxBar");
        //called to reduce or enlarge data div heights based on map size.
        AnimateDataContainers();
    }
    // hide content & restore images  *setup loops by el name - fix
    function fireSubTabs(targetBox,imgName) 
    {
    
        document.getElementById('busContent').style.display = "none";
        document.getElementById('railContent').style.display = "none";
        document.getElementById('ferryContent').style.display = "none";
        document.getElementById('shuttlesContent').style.display = "none";
        document.getElementById('otherContent').style.display = "none";
        document.getElementById('busBtn').setAttribute('src','http://images.transit.511.org/RUI/images/busBtnOff.jpg');
        document.getElementById('railBtn').setAttribute('src','http://images.transit.511.org/RUI/images/railBtnOff.jpg');
        document.getElementById('ferryBtn').setAttribute('src','http://images.transit.511.org/RUI/images/ferryBtnOff.jpg');
        document.getElementById('shuttlesBtn').setAttribute('src','http://images.transit.511.org/RUI/images/shuttlesBtnOff.jpg');
        document.getElementById('otherBtn').setAttribute('src','http://images.transit.511.org/RUI/images/otherBtnOff.jpg');

        // display content
        document.getElementById(targetBox).style.display = "block";
        document.getElementById(imgName).setAttribute('src','http://images.transit.511.org/RUI/images/'+imgName+'On.jpg');
        $("#a_agencylisthelp").appendTo("#td_"+ targetBox+"_help");
    }


    // hide main content layers  *setup loops by el name - fix
    function showBox(targetBox,imgName)
    {
    
        document.getElementById('schedulesBox').style.display = "none";
        document.getElementById('faresBox').style.display = "none";
        document.getElementById('agencyBox').style.display = "none";

        // restore button states
        document.getElementById('schedulesBtn').setAttribute('src','http://images.transit.511.org/RUI/images/schedulesBtnOff.gif');
        document.getElementById('faresBtn').setAttribute('src','http://images.transit.511.org/RUI/images/faresBtnOff.gif');
        document.getElementById('agencyBtn').setAttribute('src','http://images.transit.511.org/RUI/images/agencyBtnOff.gif');

        // display content

        document.getElementById(targetBox).style.display = "block";
        document.getElementById(imgName).setAttribute('src','http://images.transit.511.org/RUI/images/'+imgName+'On.gif');
  }


    // TEMP init build

    function initialView()
    {
       
        setMasterPageActiveSection("a_scheduleroute_mastertab");
        showBox('schedulesBox','schedulesBtn');
        fireAcc('agencySelectorPanel');
        fireSubTabs('busContent','busBtn');
//        $("#a_routeview_map").unbind("click").bind("click",function()
//        {
//             
//             hideAllMapPopups();
//             resetstopsdropdownsearch();
//             //$("#span_mapheader").hide();
//             map_restoreroutemap();
//        });
//         $("#a_print_map").unbind("click").bind("click",function()
//        {
//             map_loadprintmap();
//        });
//         $("#a_maphelp").unbind("click").bind("click",function()
//        {
//             loadmaphelp();
//        });
        
    }
    
    //call for full view of map
    function initandrestoreRouteEvents()
    {
             hideAllMapPopups();
             resetstopsdropdownsearch();
             //$("#span_mapheader").hide();
             map_restoreroutemap();
    }
    // Prototype functions ends here








    //*********************************Starts Here:Schedule Page functions*********************
    var agencies_container_name;
    var agencies_tab_mode;
    var glb_agency_id;
    var glb_agency_mode;
    var show_allcontainers;
    var highlight_mapcalled=false;
    var routemap_called=false;
    var blnShowAgencyMapTip=false;
    var bln_routefromrted=false;
    //used for map
    var glb_selectedstops;
    //********************************* Starts Here: Page load Functions *********************
    function setpageresourcetext()
    {
        $("#a_routeview_map").text(rskey_routeviewmap);
       // $("#span_mapheader").html(rskey_mapheaderdefault);
        $("#a_print_map").text(rskey_printmap);
        
        $("#span_agencyselector_header").text(rskey_schedulerouteselector);
        //showAgencySearchByCityLink("S");
       // $("#a_display_routemap").text(rskey_displayroutemaplink);
       
    }
    
    // Code For Agency Search By City Starts here
            function showAgencySearchByCityLink(tabmode)
            {
                  
               $("#span_agencyselector_header").remove("#span_agency_search"); 
               var linkstyle;
               if(tabmode=='A')
               {
                    linkstyle='margin:0px 0px 0px 246px;width:100%;text-align:right'
               }
               else if(tabmode=='S')
               {
                    linkstyle='margin:0px 0px 0px 160px;width:100%;text-align:right'
               }
               else if(tabmode=='F')
               {
                    linkstyle='margin:0px 0px 0px 253px;width:100%;text-align:right'
               }
                $("<span id='span_agency_search' style='"+linkstyle+"'>"+
                "<a id='a_searchagencybycity' href='javascript:void(0);' style='text-decoration:none'>"+rskey_searchbycitylink+"</a></span>").appendTo("#span_agencyselector_header");
                $("#a_searchagencybycity").unbind("click").bind("click",function()
                {
                    load_agencysearch(tabmode)
                });
            }
            
            function load_agencysearch(tabmode)
            {
                $("body").find("#div_agency_searchwindow").remove();
                    var Search_html='';
                    
                      var offset = $("#span_agencyselector_header").offset();
                      var tPosX= offset.left;
                      var tPosY;
                      if(tabmode=='S')
                      {
                        tPosY= offset.top+25;
                      }
                      else if(tabmode=='A')
                      {
                        tPosY= offset.top+20;
                      }  
                       else if(tabmode=='F')
                      {
                        tPosY= offset.top+20;
                      }  
                    
                    //$("#agencySelectorPanel")
                    
                   // var tPosX=Xpos;
                   // var tPosY=Ypos;
                    Search_html="<div id='div_agency_searchwindow' style='z-index:1099991;position:absolute; margin-top:2px;'>";
                    Search_html+="<table class='AgencySearchTable' cellspacing='0' cellspacing='0'><tr><td class='boxTop'></td></tr>";
                    Search_html+="<tr>";
                    Search_html+="<td class='contentBox'>";
                    Search_html+="<div class='closeBox' style='padding-right: 4px;'>";
                    Search_html+="<a id='a_searchagencyclose'  href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
                    Search_html+="</div><h1 class='AgencySearchHeader'>"+rskey_searchagencybycity+"</h1>";
                    Search_html+="<div class='boxDivider'></div>" ;
                    Search_html+="<div id='div_searchagency_form' class='AgencySearchListingdiv' >";
                    Search_html+="<table><tr><td>&nbsp;<b>"+rskey_city+":</b>&nbsp;</td>";
                    Search_html+="<td><Select id='dd_agencycity_list' class='lstMenuType' style='width:180px'></Select></td>";
                    
                    Search_html+="<td><table class='enterBtnWidget' border='0' cellspacing='0' cellpadding='0'>" ;
                    Search_html+="<tr><td class='BtnWidget_left'>&nbsp;</td><td class='BtnWidget_center'>";
                    Search_html+="<a href='javascript:void(0);' style='text-decoration:none' class='BtnWidget_alink' id='btn_agencysearch_go'>"+rskey_go+"</a></td>"; 
                    Search_html+="<td class='BtnWidget_right'>&nbsp;</td></tr></table>";
                    Search_html+="</td></tr></table>";
                    Search_html+="</div>"
                    Search_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
                    $(Search_html).appendTo("body")
                    var citiesList=getCitiesList();
                    for(idx=0;idx<citiesList.length;idx++)
                    {
                          $("<option value='" + citiesList[idx] + "'>" + citiesList[idx] + "</option>").appendTo("#dd_agencycity_list");
                    }
                    $("<option value=''>"+rskey_selectacity+"</option>").appendTo("#dd_agencycity_list");
                    
                    $('#div_agency_searchwindow').css({top: tPosY, left:tPosX});
                  
                    $("#a_searchagencyclose").unbind("click").bind("click",
                    function()
                    {
                        $("body").find("#div_agency_searchwindow").remove();
                    });
                    
                    
                    $("#btn_agencysearch_go").unbind("click").bind("click",function()
                    {
                        $("#div_searchagency_form").find("#tbl_searchagencies_list").remove();
                        if($("#dd_agencycity_list").val()!="")
                        {
                    
                            function renderAgenciesList(objAgencies)
                            {
                               
                                $("<table width='100%' id='tbl_searchagencies_list'></table>").appendTo("#div_searchagency_form");
                                if(objAgencies.length==0)
                                {
                                    $("<tr><td><br><p align='center'>"+rskey_noagencyfound+"</p></td></tr>").appendTo("#tbl_searchagencies_list");
                                }
                                else
                                {
                                    $("<tr><td colspan='2' width='100%'><br></td></tr>").appendTo("#tbl_searchagencies_list");
                                    var bln_AcTransitListed=false;
                                    $(objAgencies).each(function(i)
                                    {
                                        if(objAgencies[i].CarrierID=='AC'||objAgencies[i].CarrierID=='AD')
                                        {
                                           if(bln_AcTransitListed==false)
                                           {
                                             $("<tr><td width='2%'>&nbsp;&nbsp;</td><td width='98%' class='AgencySearchedListLinks'>"+
                                             "<a class='AgencySearchedListLinks' href='javascript:void(0);' OnClick=LinkedSearchedAgency('"+tabmode+"','AC')>AC Transit</a>"+
                                             " (<a href='javascript:void(0);' class='AgencySearchedListLinks' OnClick=LinkedSearchedAgency('"+tabmode+"','AC')>Local</a> & "+
                                             "<a href='javascript:void(0);' class='AgencySearchedListLinks' OnClick=LinkedSearchedAgency('"+tabmode+"','AD')>Transbay</a>)"+ 
                                             "</td></tr>").appendTo("#tbl_searchagencies_list");
                                             bln_AcTransitListed=true;
                                            
                                           } 
                                           
                                        }
                                        else
                                        {
                                            $("<tr><td width='2%'>&nbsp;&nbsp;</td><td width='98%'><a class='AgencySearchedListLinks' href='javascript:void(0);' OnClick=LinkedSearchedAgency('"+tabmode+"','" + objAgencies[i].CarrierID  +"')>"+ objAgencies[i].CarrierName +"</a></td></tr>").appendTo("#tbl_searchagencies_list");
                                        }    
                                    });
                                    
                                   
                                }
                            }
                            getAgenciesByCity($("#dd_agencycity_list").val(),renderAgenciesList)
                        }    
                        
                    });
                    
            }
            
            function LinkedSearchedAgency(tabmode,cid)
            {
               
               function linkedAgency(agencyprofile_object)
               {
                 if(getAgencyUseExternalInfo()!=null && getAgencyUseExternalInfo()==true)
                 {
                    if(getAgencyProfileUrl()!=null)
                    {
                    
                      linkexternalagencies(getAgencyProfileUrl()); 
                      return false;
                    }
                 }
                 else
                 {
                    appendtourl("m1="+tabmode+"&m2=" + getAgencyDisplayMode(cid) + "&cid=" + cid,true);
                    //window.location.href="../schedules/index.aspx?#m1="+ tabmode + "&m2="+ getAgencyDisplayMode(cid)+ "&cid="+ cid;
                 }

               }
               getAgency(cid,linkedAgency);
               HideAgencySearchByCity();
            }
            function HideAgencySearchByCity()
            {
                $("body").find("#div_agency_searchwindow").remove();
            }
     // Code For Agency Search By City Starts here
    
    
    //load the tab based on the mode from query string
    function load_schedulepage()
    {
        
        setMasterPageActiveSection("a_scheduleroute_mastertab");
        bindtabclicks();
        setpageresourcetext();
        hidemaplegendlink();
        hideroutepreviewmaplegend();
        // $("#a_routeview_map").unbind("click").bind("click",function(){clearmapclick();});
        var param_array= getqueryparam();
         
         if(param_array!=null)
         {
       
            for(j=0;j<param_array.length;j++)
            {
                 var param=param_array[j].split("=");
               
                 if(param[0]=='m1')
                 { 
                   switch (param[1]) 
                       {
                      
                            case "S" : 
                                      agencies_tab_mode="S";
                                      loadscheduletab();
                                       
                            break;
                            case "F" : 
                                       agencies_tab_mode="F";                                          
                                       loadfaretab();
                            break;
                            case "A" : 
                                      agencies_tab_mode="A";
                                      loadagencyprofiletab();
                            break;
                           
                        }
                  break;  
                 }
            }
         }
       
    }

    //load the schedule tab      
    function loadscheduletab()
    {
        $("#a_tab_schedule").unbind("click");
        showBox('schedulesBox','schedulesBtn');

        $("#a_tab_fare").unbind("click").bind("click", function()
                  {showBox('faresBox','faresBtn');loadfaretab();});

        $("#a_tab_profile").unbind("click").bind("click", function()
        {showBox('agencyBox','agencyBtn');loadagencyprofiletab();});


        loadfromhistory("S");
        $("#span_agencyselector_header").text(rskey_schedulerouteselector);
        //showAgencySearchByCityLink("S");
        //HideAgencySearchByCity();
         $("#fare_commute").hide();
         hidecommuterewardpopup();
    }

    //load the fare tab  
    function loadfaretab()
    {
        showBox('faresBox','faresBtn');
        loadfromhistory("F");
        $("#span_agencyselector_header").text(rskey_fareselector);
        //showAgencySearchByCityLink("F");
        //HideAgencySearchByCity();
         $("#fare_commute").show();
         $("#a_fare_commute").unbind("click").bind("click",
                function(event)
                {
                    showcommuterewards(event.pageX,event.pageY);
                });
    }

    //load the agency profile tab        
    function loadagencyprofiletab()
    {
    
      showBox('agencyBox','agencyBtn');
      loadfromhistory("A");
      $("#span_agencyselector_header").text(rskey_agencyselector);
       //showAgencySearchByCityLink("A");   
     // HideAgencySearchByCity(); 
      $("#fare_commute").hide();
     hidecommuterewardpopup();


    }

    //load the specfic tab based on mode when back and forward button clicked          
    function loadfromhistory(tabmode)
    {

        var param_array=getqueryparam();
        var bln_routechecked=false;
       if(param_array!=null)
        {

          var mode='';
          var modechanged;
              for(j=0;j<param_array.length;j++)
              {
                     var param=param_array[j].split("=");
                     if(param[0]=='m1')
                     {
                           if(param[1]!=tabmode&&param_array.length==2)
                            {
                               modechanged=true;
                            }
                     }
                     if(param[0]=='m2')
                     {
                            mode=param[1];
                            fireAcc('agencySelectorPanel');
                           
                            loadagencies(param[1],tabmode); 
                            if(modechanged==true)
                            {
                              
                                appendtourl("m1="+tabmode+"&m2="+mode,true);
                            }
                        
                     }
                    if(tabmode=='S')
                    {
                         bln_showroutecheckbox=true;
                        //Added to skip the checking of cid when routeid present
                        if(hasRouteInfoInUrl()&&bln_routechecked==false)
                           {
                             bln_showroutecheckbox=false;
                                if(j==2)
                                {
                                    bln_routechecked=true;
                                    if(param[0]=='cid')
                                    {
                                      
                                        continue;
                                    }
                                }    
                           } 
                          if(param[0]=='routeid')
                            { 
                                loadroutefromhistory(param[1]);
                                break;
                            }
                            if(param[0]=='rted')
                            {
                                
                                loadroutefromhistorybyrted(param[1]);
                                break;
                            }
                        
                    } 
               
                     if(param[0]=='cid')
                     {
                         
                        if(mode==''){mode='bus';}                                              
                         
                             if(glb_agency_id!=param[1])
                                {
                                  
                                
                                         function renderbymode(agencyprofile_object)
                                         {
                                             
                                             if(agencies_tab_mode=='S'){
                                                  loadroutes(param[1],mode,true);
                                                 
                                              } 
                                            else if(agencies_tab_mode=='F'){
                                                  
                                                 loadfares(true);
                                                 
                                                 }
                                            else if(agencies_tab_mode=='A'){
                                               
                                                  loadagencyprofile(param[1]);
                                                
                                            }
                                              loadagencyservicearea(param[1],agencies_tab_mode);
                                         }
                                          
                                        getAgency(param[1],renderbymode);
                                        glb_agency_id=param[1];
                                        
                                        
                                    
                                }
                                else
                                {
                                    
                                       if(tabmode=='S')
                                        {
                                            loadroutes(param[1],mode,true);
                                            
                                        } 
                                        else if(tabmode=='F')
                                        { 
                                            
                                            loadfares(true);
                                            
                                        }
                                        else if(tabmode=='A')
                                        {
                                            loadagencyprofile(param[1]);
                                           
                                        }
                                        loadagencyservicearea(param[1],tabmode);
                                }
                       
                            agencies_animateselectedlink(param[1],mode);
                            break;
                     }  
               
              }
        } 
        else
        {
           
            if(tabmode==''||tabmode=='S')
            {
              loadagencies("bus","S"); 
              appendtourl("m1=S&m2=bus",true);
            }
            else if(tabmode=='F')
            {
                loadagencies("bus","F"); 
                appendtourl("m1=F&m2=bus",true);
            }
            else if(tabmode=='A')
            {
               
                loadagencies("bus","A"); 
                appendtourl("m1=A&m2=bus",true);
            }
              
              
        } 
    }
 
    function hasRouteInfoInUrl()
    {
      var strReturn =false;
      var param_array=getqueryparam();
      for(var idx=0;idx<param_array.length;idx++)
          {
                 var param=param_array[idx].split("=");
                 if(param[0]=='routeid'||param[0]=='rted')
                 {
                    strReturn=true;
                    break;
                 }
          }      
     return strReturn;
    }
    
 
    //Binds click events to tabs
    function bindtabclicks()
    {
        $("#a_tab_schedule").attr("href","javascript:void(0);").unbind("click").bind("click", function()
        {showBox('schedulesBox','schedulesBtn');loadscheduletab();});

        $("#a_tab_fare").attr("href","javascript:void(0);").unbind("click").bind("click", function()
        {showBox('faresBox','faresBtn');loadfaretab();});

        $("#a_tab_profile").attr("href","javascript:void(0);").unbind("click").bind("click", function()
        {showBox('agencyBox','agencyBtn');loadagencyprofiletab();});

    }


    // load the routes and schedules from history based on rted
    function loadroutefromhistorybyrted(rted)
    {
  
        var param_array=getqueryparam();
        var agencyid;
        for(var j=0;j<param_array.length;j++)
        { 
        var param=param_array[j].split("=");
            if(param[0]=='cid')
            {
             agencyid=param[1];
             getAgency(param[1],loadroutebydesignator);
             break; 
            }

        }
        
        function appendRouteIdFromRted(objroute)
        {
            
           if(objroute!=undefined)
           {
                if(objroute.ID!=undefined)
                {
                   
                    if(checkexistinquerystring("routeid=" + objroute.ID)==false&&bln_routefromrted==false)
                    {
                       var _requestmode="";
                       if(glb_agency_mode=="")
                       {
                          _requestmode=getAgencyDisplayMode(agencyid);
                       }
                       else
                       {  
                            _requestmode=glb_agency_mode;
                       }
                        bln_routefromrted=true;
                        appendtourl("m1=S&m2="+ _requestmode + "&routeid="+objroute.ID+"&cid="+agencyid,true);
                        
                    }    
                }
                else
                {
                    appendtourl("m1=S&m2=bus",true);
                }
           }
           else
           {
             appendtourl("m1=S&m2=bus",true);
           }
            
            
        }
        function loadroutebydesignator()
        {
           
            if(agencyid!=undefined)
            {
                
                getRouteByDesignator(rted,agencyid,appendRouteIdFromRted);
                
            }
            else
            {
                appendtourl("m1=S&m2=bus",true);
                
            }
            
        }
        
        

    
    }

    //load the routes and schedules from history 

    function loadroutefromhistory(routeid)
    {
       
        var param_array=getqueryparam();
        var agencyid;
        for(j=0;j<param_array.length;j++)
        { 
        var param=param_array[j].split("=");
            if(param[0]=='cid')
            {
             agencyid=param[1];
             getAgency(param[1],loadallroutes);
             break; 
            }

        }

        function loadallroutes()
        {
            getRoutesList(agencyid,loadschedulefromhistory);
        }

        function loadschedulefromhistory()
        {
            loadroutes(agencyid,glb_agency_mode,false);
            loadagencyservicearea(agencyid,"S");
            $("#faresBox").hide();
            $("#agencyBox").hide();

            if(show_allcontainers==true)
            {
                 $("#tbl_master_container").show();
                 $("#div_master_container").show();
                 $("#td_map_container").show();
                 $("#tbl_tab_bottom").attr("style","display:none");
                 $("#tbl_tab_container").insertBefore("#div_master_container");
                 loadfares(false);
                 loadannouncements(agencyid,routeid);
                 $("#div_schedule").show();
                 $("#rail_Div").hide();
                // $("#a_display_routemap").hide();
                // $("#img_display_routemap").hide();

            }
            else
            {
              
                $("#tbl_tab_bottom").show();
                $("#tbl_tab_container").appendTo("#div_tab_bottom");  
                $("#div_master_container").hide();
                $("#td_map_container").hide();
                //$("#a_display_routemap").show();
                //$("#img_display_routemap").show();
//                $("#a_display_routemap").unbind("click").bind("click",function()
//                {
//                    displayroutemapclick(true);
//                });
           }  
           
           
            var param_array=getqueryparam();
            var dir='';
            var type='';
            var customize='';
            var showrailline='';
            for(j=0;j<param_array.length;j++)
            { 
                var param=param_array[j].split("=");
                if(param[0]=='dir')
                {
                  dir=param[1];
                  
                }
                if(param[0]=='type')
                {
                  type=param[1];
                }
                if(param[0]=='customize')
                {
                  customize=1;  
                }
                if(param[0]=='showrailline')
                {
                  showrailline=1;  
                }
             }
             if(showrailline==1)
             {
                hideSchedules();
                loadRailLineDetails(routeid,dir,type);
             }
             else
             {
                 loadSchedules(routeid,dir,type,customize); 
                  
             }    
      
        }
    }

    //********************************* Ends Here: Page load Functions *********************



    //********************************* Starts Here:Agencies List Control Functions *********************


    // Show/Hide different tabs,animate links and attach events to controls 
    function loadagencies(mode,tabmode)
    {
        if(glb_agency_id==undefined)
        {
            //log the system load map
            logevent(window.location,"controlfunctions_schedules.js","loadagencies",SystemCoverageMap,"","","");
        }
        
        $("#tbl_master_container").show();
        $("#div_master_container").show();
        $("#td_map_container").show();
        $("#tbl_tab_bottom").attr("style","display:none");
        $("#tbl_tab_container").insertBefore("#div_master_container"); 
        bindtabclicks();
        setpageresourcetext();
        $("#tbl_master_container").show();
        $("#fareListRow").hide();
        //$("#img_display_routemap").hide();
//        $("#a_display_routemap").hide().unbind("click").bind("click",function()
//        {
//            displayroutemapclick(true);
//        });
        hideSchedules();
        hideRoutes();
        hideFares();
        hideAnnouncements();
        hideAgencyServiceArea();
        hideRailLineDiagram();
        hidemaplegendlink();
        hideroutepreviewmaplegend();
        agencies_tab_mode=tabmode;
        if(glb_agency_mode==undefined){glb_agency_mode='';}

        if(glb_agency_mode!=mode)
        {
            glb_agency_mode=mode;
            agencies_displaybymode(mode);
            $("#a_routeview_map").hide();

        }

        if(tabmode=='S')
        {
            if($("#agencySelectorRow").parent().parent().attr("id")!="tbl_schedule_agencyselector")
            {
            $("#agencySelectorRow").insertBefore("#routeListRow");
            }  
           
            $("#a_agencylisthelp").unbind("click").bind("click",
            function(event)
            {
                function render_help(helpitem)
                {
                    renderhelp(helpitem,rskey_scheduleagencylisthelpheader,event.pageX,event.pageY,"a_agencylisthelp");
                }
                getHelp("schedulerouteselectoragencieslist","en",render_help);
            });  
            
            loadmaphelp("scheduleselector");
                 
        }
        else if(tabmode=='F')
        {
            $("#agencySelectorRow").insertBefore("#faresBoxfareListRow");
            $("#faresBoxfareListRow").hide();
            showFares();
            
            $("#a_agencylisthelp").unbind("click").bind("click",
            function(event)
            {
                function render_help(helpitem)
                {
                    renderhelp(helpitem,rskey_fareagencylisthelpheader,event.pageX,event.pageY,"a_agencylisthelp");
                }
                getHelp("fareselectoragencieslist","en",render_help);
            });    
            
            loadmaphelp("fareselector");
        }
        else if(tabmode=='A')
        {
            $("#agencySelectorRow").insertBefore("#agencyBoxagenycyProfileRow");
            $("#agencyBoxagenycyProfileRow").hide();
            showAgencyProfile();
            $("#a_agencylisthelp").unbind("click").bind("click",
            function(event)
            {
                function render_help(helpitem)
                {
                    renderhelp(helpitem,rskey_agenycprofileagencylisthelpheader,event.pageX,event.pageY,"a_agencylisthelp");
                }
                getHelp("agencyprofileselectoragencieslist","en",render_help);
            });
            loadmaphelp("agencyprofileselector");    
        }  
        
        setagencytitleattribute();
        
  
    }

    //display the agency selector based on mode and called the animate links for that mode
    function agencies_displaybymode(mode)
    {
        switch (mode) 
        {
        case "bus" :  
                     fireSubTabs('busContent','busBtn');
                     agencies_animatelink('tbl_routes_bus',mode);
                     
        break;
        case "rail" : 
                     fireSubTabs('railContent','railBtn');
                     agencies_animatelink('tbl_routes_rail',mode);

        break;
        case "ferry" : 
                     fireSubTabs('ferryContent','ferryBtn');
                     agencies_animatelink('tbl_routes_ferry',mode);

        break;
        case "shuttle" : 
                     fireSubTabs('shuttlesContent','shuttlesBtn');
                     agencies_animatelink('tbl_routes_shuttle',mode);

        break
        case "other" :
                     fireSubTabs('otherContent','otherBtn'); 
                     agencies_animatelink('tbl_routes_other',mode);
        break;

        default : 
                     fireSubTabs('busContent','busBtn');
                     agencies_animatelink('tbl_routes_bus',mode);
        }


        agencies_attachmodeclicks();


    }

    //attached click event for sub tabs(bus,rail...)
    function agencies_attachmodeclicks()
    {
        agencies_modeclick('ui_routes_bus','tbl_routes_bus','bus');
        agencies_modeclick('ui_routes_rail','tbl_routes_rail','rail');
        agencies_modeclick('ui_routes_ferry','tbl_routes_ferry','ferry');
        agencies_modeclick('ui_routes_shuttles','tbl_routes_shuttle','shuttle');
        agencies_modeclick('ui_routes_other','tbl_routes_other','other');
    }
    //called for when mode(bus,rail.....) is clicked
    function agencies_modeclick(modelinkid,tblid,mode)
    {

        $("#" + modelinkid).attr("href","javascript:void(0);").bind("click",function()
        {
            
            if(glb_agency_mode!=mode)
             {
                
                //agencies_hideothercontrols();
                glb_agency_mode=mode;
                //glb_agency_id='';
                //resetdataobjects();
                 agencies_animatelink(tblid,mode)
//                if(checkexistinquerystring("m1="+agencies_tab_mode)==false||checkexistinquerystring("m2=" + mode)==false)
//                {
//                     appendtourl("m1=" + agencies_tab_mode +"&m2=" + mode,true);
//                }     
//                $("#a_routeview_map").hide();
//                $("#span_mapheader").hide();
                
             }
        });
       
    }


    // animate the agency selectors links and bind the event based on  mode
    function agencies_animatelink(tblid,mode)
    {
  
        $("#" + tblid).find("a").attr("style","FONT-STYLE:NORMAL;TEXT-DECORATION:None;");
        $("#" + tblid).find("a").filter("[@href]")
        .bind("click",function()
        {
          if($(this).attr("href")!='javascript:void(0);')
          {
             var strurl=$(this).attr("href");
             $(this).removeAttr("href");
             linkexternalagencies(strurl);
             //$(this).attr("href","javascript:void(0);"); 
             $(this).attr("href",strurl);
             return false;
          }

        });


        $("#" + tblid).find("a").not("[@href]").attr("href","javascript:void(0);")
        .unbind("click")
        .bind("click",function()
        {
            if($(this).attr("id")!=undefined)                 
                {   
                            bln_showroutecheckbox=true;
                            resetdataobjects();
                            var agency_localid=$(this).attr("id").split(":")[1];
                            var agency_element=$(this);
                            show_allcontainers=false;
                            agencies_animateselectedlink(agency_localid,mode);     
                            function renderbymode(agencyprofile_object)
                            {
                                         //if agency needs to link to external url
                                        
                                             if(getAgencyUseExternalInfo()!=null && getAgencyUseExternalInfo()==true)
                                             {
                                                if(getAgencyProfileUrl()!=null)
                                                {
                                                
                                                 $(agency_element).attr("style","FONT-STYLE:NORMAL;TEXT-DECORATION:UNDERLINE;");
                                                  linkexternalagencies(getAgencyProfileUrl()); 
                                                  return false;
                                                }
                                             }
                                         
                                             if(agencies_tab_mode=='S'){
                                              
                                                loadroutes(agency_localid,mode,true);
                                                
                                              } 
                                            else if(agencies_tab_mode=='F'){
                                                  loadfares(true);
                                                  
                                                 }
                                            else if(agencies_tab_mode=='A'){
                                                loadagencyprofile(agency_localid);
                                                 }
                              }
                           
                             getAgency(agency_localid,renderbymode);
                             glb_agency_id=agency_localid;


                    }

            });
        
    }


    // set the agency title to agency text and tab mode
    function setagencytitleattribute()
    {
        var tite_text;
        if(agencies_tab_mode=='S')
        {
            tite_text=rskey_scheduleagencytitle;
        }
        else if(agencies_tab_mode=='F')
        {
            tite_text=rskey_fareagencytitle;
        }
        else if(agencies_tab_mode=='A')
        {
            tite_text=rskey_agencyprofileagencytitle;
        }
        
          assigntitle('tbl_routes_bus');
          assigntitle('tbl_routes_rail');
          assigntitle('tbl_routes_ferry');
          assigntitle('tbl_routes_shuttle');
          assigntitle('tbl_routes_other'); 
          $("#a_agencylisthelp").attr("title",rskey_altHelp);
            function assigntitle(tblid)
            {
                $("#"+ tblid).find("a").not("[@href]").each(function(i)
                {
                    $(this).attr("title",$(this).text() +" "+ tite_text);
                });
              
               $("#"+ tblid).find("a").filter("[@href]").each(function(i)
                {
                   if ($(this).parent().text().indexOf("*")>0)
                   {
                    $(this).attr("title",$(this).text() +" "+ rskey_externalagencytitle);
                   }
                   else
                    {
                        $(this).attr("title",$(this).text() +" "+ tite_text);
                    }    
                  
                });  
            
            } 
    }

    //link the external agency
    function linkexternalagencies(strurl)
    {
        
         var backurl=window.location.href.split("#")[0] + "#m1=S&m2="+  glb_agency_mode ;
         if(strurl.indexOf("&")>0)
         {
            strurl=replacecharacter(strurl,"&","%26");
         }
        if(strurl.indexOf("#")>0)
         {
            strurl=replacecharacter(strurl,"#","%23");
         }
         if(backurl.indexOf("&")>0)
         {
            backurl=replacecharacter(backurl,"&","%26");
         }
        if(backurl.indexOf("#")>0)
         {
            backurl=replacecharacter(backurl,"#","%23");
         }
         var exist_url= "../frames/external.aspx?url=" + strurl;
         var external_url=  exist_url + "&backurl=" + backurl;
         window.location.href=external_url;
         return false; 
    }

    //set the agency mode
    function setagencymode(mode)
    {
        glb_agency_mode=mode;
    }
    //set the agency mode
    function getagencymode()
    {
        return glb_agency_mode;
    }
    //animate the selected link of agency selector 
    function agencies_animateselectedlink(agencyid,mode)
    {

        var tblid;
        switch (mode) 
        {
            case "bus" :  
                         tblid='tbl_routes_bus';
            break;
            case "rail" : 
                         tblid='tbl_routes_rail';
            break;
            case "ferry" : 
                         tblid='tbl_routes_ferry';
            break;
            case "shuttle" : 
                         tblid='tbl_routes_shuttle';
            break
            case "other" :
                         tblid='tbl_routes_other';
            break;
           
            default : 
                        tblid='tbl_routes_bus';
        }

        $("#" + tblid).find("a").each(function(i)
        { 

             if($(this).attr("style").toUpperCase().indexOf("NORMAL")>1)
             {
                $(this).attr("style","FONT-STYLE:NORMAL;TEXT-DECORATION:NONE;");
             }
             else
             {
                $(this).attr("style","FONT-STYLE:ITALIC;TEXT-DECORATION:NONE;");
             }

            if($(this).attr("id")!=null)
            { 
               var id=$(this).attr("id").split(":")[1];
               if(id==agencyid)
               {
               
                      
                     if($(this).attr("style").toUpperCase().indexOf("NORMAL")>1)
                     {
                        $(this).attr("style","FONT-STYLE:NORMAL;TEXT-DECORATION:UNDERLINE;");
                     }
                     else
                     {
                       
                        $(this).attr("style","FONT-STYLE:ITALIC;TEXT-DECORATION:UNDERLINE;");
                     }  
               }
             
            }
        }); 
    }


    //********************************* Starts Here:Routes List Control Functions *********************

    //load routes and hide other controls and call highlightagencymap functions
    function loadroutes(agencyid,mode,callmap)
    {


        function render_routes(routes_object)
        {
             fireAcc("routeListPanel");
             $("#fareListRow").hide();
             hideFares();
             hideAnnouncements();
             hideAgencyProfile();
             hideRailLineDiagram();
             hidemaplegendlink();
             hidemaplegendlink();
             glb_agency_id=agencyid;
             if(checkexistinquerystring("m1=S")==false||checkexistinquerystring("cid=" + agencyid)==false)
             {
              
                appendtourl("m1=S&m2=" + mode + "&cid=" + agencyid,true);
                
             }  
             else
             {
                hideAllMapPopups();
                renderRoutesList(routes_object,"td_routes_list",loadSchedules,showschedulefullview);
                if(callmap==true)
                {
                    $("#a_routeview_map").hide();                 
                    loadhighlightagencymap(agencyid,mode);
                   // $("#span_mapheader").hide();
                   setmapheadertext(getAgencyName() + " - " +  rskey_mapheaderservicearea)
                   
                } 
                
                logevent(window.location,"controlfunctions_schedules.js","loadroutes",PagesSchedulesRoutesMaps,"",getAgencyID(),"");
             } 
        }
        $("#routeListRow").show(); 
        $("#span_route_header").text(getAgencyName() + " "+ rskey_routespecificschedule);
        //$("#span_route_subheader").html("&nbsp;&nbsp;" + getAgencyName() + " "+ rkey_schedules);
        $("#extSite").empty();
        if(getAgencyMainUrl()!=null)
        {
           $("<a href='" +  getAgencyMainUrl() + "' target='_blank' style='position:absolute;right:40px;'>" + getAgencyName() + " "+ rskey_website+ "</a>").appendTo("#extSite");
        }
   
             
        getRoutesList(agencyid,render_routes);
        glb_selectedstops='';

    }




    //********************************* Ends Here:Routes List Control Functions*********************

 //********************************* Starts Here:Agency Service Area Control Functions*********************
 function loadagencyservicearea(agencyid,tabmode)
    {
    
        function render_agencyservicearea(agency_object)
        {
           renderAgencyServiceArea(agency_object,"agencyServiceAreaPanel",showAgencyServiceArea,hideAgencyServiceArea);
            $("#span_agencyservice_header").text(getAgencyName() + " - "+ rskey_agencyuploadcontentarea);
             if(tabmode=='S')
                {
               
                    $("#routeListRow").insertAfter("#agencySelectorRow"); 
                    $("#fareListRow").insertAfter("#routeListRow"); 
                    $("#annoucementListRow").insertAfter("#fareListRow"); 
                    $("#agencyServiceAreaRow").insertAfter("#annoucementListRow"); 
                }
                else if(tabmode=='F')
                {
                    $("#agencyServiceAreaRow").insertAfter("#faresBoxfareListRow"); 
                }
                else if(tabmode=='A')
                {
                    $("#agencyServiceAreaRow").insertAfter("#agencyBoxagenycyProfileRow"); 
                }
        }
       getAgency(agencyid,render_agencyservicearea);
    }

 //********************************* Ends Here:Agency Service Area Functions Control Functions*********************





    //*********************************Starts Here: Fares Load functions*********************
    //load fares and hide other controls and call fares map functions
    function loadfares(fareonly) 
    {

        function render_fares(farezone_object,farelist_object,fromzoneid,tozoneid)
        {
        
               hideAllMapPopups();
                if(fareonly==true)
                { 
                    bln_showroutecheckbox=true;
                    showFares();
                    $("#fares_databox").show();
                    hideAgencyProfile();
                    fireAcc("fares_databox");
                    $("#faresBoxfareListRow").show();
                    $("#fareListRow").hide();
                    $("#a_tab_schedule").unbind("click").bind("click", function(){showBox('schedulesBox','schedulesBtn');loadscheduletab();});
                    $("#a_tab_fare").unbind("click");
                    $("#a_tab_profile").unbind("click").bind("click", function(){showBox('agencyBox','agencyBtn');loadagencyprofiletab();});
                    $("#span_agencyselector_header").text(rskey_fareselector);
                    //showAgencySearchByCityLink("F");
                    $("#tbl_master_container").show();
                    $("#div_master_container").show();
                    $("#td_map_container").show();
                    $("#tbl_tab_container").insertBefore("#div_master_container"); 
                    hideRoutes();
                    hideAnnouncements();
                    hideSchedules();
                    hideRailLineDiagram();
                    hidemaplegendlink();
                    hidemaplegendlink();
                    $("#span_faredata_header").html(getAgencyName() + " "+ rskey_fares); 
                    if((checkexistinquerystring("m1=F")==false||checkexistinquerystring("cid=" + glb_agencyprofile.ID)==false)&&fareonly==true)
                       {
                         
                                appendtourl("m1=F&m2=" + glb_agency_mode + "&cid=" + glb_agency_id,true);
                          
                       } 
                       else
                       {
                          
                          $("#fareListPanel").find("#zonemaplink").remove();
                          renderFares(farezone_object,farelist_object,"fares_databox",fromzoneid,tozoneid); 
                            
                          $("#a_routeview_map").hide();
                           if(farezone_object!=undefined)
                             {
                                loadhighlightfarezonesmap(glb_agency_id);
                                setmapheadertext(getAgencyName() + " - " +  rskey_mapheaderfarezone)
                             }
                             else
                             { 
                                loadhighlightagencymap(glb_agency_id,glb_agency_mode)
                                //loadzoomtoagencymap(glb_agency_id,glb_agency_mode); 
                                setmapheadertext(getAgencyName() + " - " +  rskey_mapheaderservicearea)
                             }
                             //setmapheadertext(rskey_fares+"-"+ getAgencyName());
                                
                               
                               var _translinkhtml="<a id='fareTransLink' href='../translink.aspx'>"+rskey_translink+"&reg;</a>"; 
                               var _agencylinkurl="";




                               if(getAgencyMainUrl()!=null)
                                {
                                    _agencylinkurl="<a id='fareAgencyWebSiteLink' href='" +  getAgencyMainUrl() + "' target='_blank' >" + getAgencyName() + " "+ rskey_website+ "</a>&nbsp;&nbsp;";

                                }
                               
                               $("#fares_databox").find("#div_fairbottomlink").remove();
                               $("<div id='div_fairbottomlink' style='width:100%;'><table style='width:100%;'><tr>"+
                               "<td id='td_faretranslink'width='50%'>"+_translinkhtml+"</td>"+
                               "<td id='td_fareagencylink' style='width:50%;text-align:right;'>"+_agencylinkurl+"</td>"+
                               "</tr></table></div>").appendTo("#fares_databox");
                            
                              logevent(window.location,"controlfunctions_schedules.js","loadfares",InfoFare,"",getAgencyID(),""); 
   
                       }
                     
                }
                else
                {
                    
                    $("#fareListRow").show();
                    $("#faresBox").hide();
                    $("#span_fare_header").html(getAgencyName() + " "+ rskey_specificfares);
                    renderFares(farezone_object,farelist_object,"fareListPanel",fromzoneid,tozoneid);
                   
                    // $("#fareListPanel").find("#zonemaplink").remove();
                    
                      var _translinkhtml="<a id='fareTransLink' href='../translink.aspx'>"+rskey_translink+"&reg;</a>";  
                     
                      var _zonemaplink="";
                      if(farezone_object!=undefined)
                        {
                           
                           _zonemaplink="<a id='zoneMapLink' href='javascript:void(0);'"+
                           " Onclick='ZoneMapLinkClick();' title='"+rskey_zonemaptitle+"'>"+rskey_zonemaplink+"</a>&nbsp;&nbsp;";
                        }     
                    
                     $("#fareListPanel").find("#div_fairbottomlink").remove();
                     $("<div id='div_fairbottomlink' style='width:100%;'><table style='width:100%;'><tr>"+
                     "<td id='td_faretranslink'width='50%'>"+_translinkhtml+"</td>"+
                     "<td id='td_fareagencylink' style='width:50%;text-align:right;'>"+_zonemaplink+"</td></tr></table></div>").appendTo("#fareListPanel");
                       
                       
                }
         }

        getFares(glb_agency_id,render_fares);

    }

    function ZoneMapLinkClick()
    {
        if(confirm(rskey_zonemapconfirmmsg))
        {
           appendtourl("m1=F&m2=" + glb_agency_mode + "&cid=" + glb_agency_id,true);
        }
    }



    //*********************************Ends Here: Fares Load functions*********************



    //*********************************Starts Here: Agency Profile functions*********************
    //load agency profile and hide other controls and call zoomtoagencymap function

    function loadagencyprofile(agencyid)
    {



        function render_agencyprofile(agencyprofile_object)
        { 
           
                showAgencyProfile();
                showAgencyDataSection();
                $("#agencyprofile_databox").show();
                fireAcc("agencyprofile_databox");
            
               if(agencyprofile_object!=null)
               {
                    bln_showroutecheckbox=true;
                    $("#tbl_master_container").show();
                    $("#div_master_container").show();
                    $("#td_map_container").show();
                    $("#tbl_tab_container").insertBefore("#div_master_container"); 
                    $("#agencyBoxagenycyProfileRow").show();    
                    hideRoutes();
                    hideFares();
                    hideAnnouncements();
                    hideSchedules(); 
                    hideRailLineDiagram();
                    $("#span_agencyselector_header").text(rskey_agencyselector);
                   // showAgencySearchByCityLink("A");
                    $("#span_agencyprofile_header").html(rskey_agencyprofile +"-" + getAgencyName()); 
                    
                   
                   if(checkexistinquerystring("m1=A")==false||checkexistinquerystring("cid=" + glb_agency_id)==false)
                   { 
                          
                            appendtourl("m1=A&m2=" + glb_agency_mode + "&cid=" + glb_agency_id,true);
                           
                           
                   }
                   else
                   {
                          hideAllMapPopups();
                          hidemaplegendlink();
                          hidemaplegendlink();
                          renderAgencyProfile(agencyprofile_object,"agencyprofile_databox",hideAgencyDataSection);
                          $("#a_routeview_map").hide();
                          loadzoomtoagencymap(glb_agency_id,glb_agency_mode);
                         // setmapheadertext(rskey_agencyprofile+ "-"+ getAgencyName());
                          setmapheadertext(getAgencyName() + " - " +  rskey_mapheaderservicearea)
                     
                      logevent(window.location,"controlfunctions_schedules.js","loadagencyprofile",InfoAgency,"",getAgencyID(),"");   
                   }
                }
        }

        if(glb_agency_id!=undefined)
        {
              $("#a_tab_schedule").unbind("click").bind("click", function(){showBox('schedulesBox','schedulesBtn');loadscheduletab();});
              $("#a_tab_fare").unbind("click").bind("click", function(){showBox('faresBox','faresBtn');loadfaretab();});
              $("#a_tab_profile").unbind("click");
              $("#tbl_master_container").show();
              getAgency(agencyid,render_agencyprofile);
              glb_agency_id=agencyid;
        }

    }


    //*********************************Ends Here: Agency Profile functions*********************

    //***********************************Starts Here: Schedule Load functions*********************

    //load schedules  based on routeid 
    function loadSchedules(routeid,dir,type,customize)
    {

        hideAllMapPopups();
        function render_schedules(scheduleOptionItems_obj)
        {
            
             if(checkexistinquerystring("routeid=" + routeid)==false)
             {
                
                appendtourl("m1=S&m2="+ glb_agency_mode + "&routeid="+routeid+"&cid="+glb_agency_id,true);
                
             }
             else
             {
               
                map_showlegends();
                hyperlinkselectedroute(routeid);
                renderScheduleList(scheduleOptionItems_obj,dir,type,customize,'div_schedule',glb_agency_mode,schedulefullviewclick,loadRailLineDetails,showmapcallback);

                if(!show_allcontainers)
                {
                    routemap_called=false;
                     
                     hidestopsonmapsearch();
                    
                      
                        $("#a_tab_schedule").attr("href","javascript:void(0);").unbind("click").bind("click", function()
                        {bindschedulefullviewtabclick()});
                      
                        $("#tbl_tab_bottom").show();
                        $("#tbl_tab_container").appendTo("#div_tab_bottom");  
                        $("#div_master_container").hide();
                        $("#td_map_container").hide();
                       // $("#a_display_routemap").show();
                        //$("#img_display_routemap").show();
                }
                else
                {
                    showstopsonmapsearch();
                    hidescheduleannoucementlink();
                    
                    
                } 
                showSchedules();
                
                var referencetext="RouteID:"+ routeid + ",Dir:"+ getSelectedDirectionID() + ",daytype: "+ getSelectedDayTypeID();
                logevent(window.location,"controlfunctions_schedules.js","loadSchedules",InfoSchedule,referencetext,getAgencyID(),routeid);   
             }   
        }
        
        getSchedules(routeid,render_schedules);
        glb_selectedstops='';
    }

    // bind the schedule and route tab on full schedule view page
    function bindschedulefullviewtabclick()
    {
        //        $("#tbl_master_container").show();
        //        $("#div_master_container").show();
        //        $("#td_map_container").show();
        //        $("#tbl_tab_bottom").attr("style","display:none");
        //        $("#tbl_tab_container").insertBefore("#div_master_container"); 
        //        $("#div_schedule").hide();
        //        $("#rail_Div").hide();
        //        //$("#a_display_routemap").hide();
        //       // $("#img_display_routemap").hide();
        //        hidescheduleannoucementlink();
        //        hideAnnouncements();
        //        hidemaplegendlink();
        //        $("#fareListRow").hide();
        //        hideManageMapLink();
        //        if(!highlight_mapcalled)
        //        {
        //            loadhighlightagencymap(getAgencyID(),glb_agency_mode);
        //        }   
               
        
         appendtourl("m1=S&m2=" + glb_agency_mode + "&cid=" + glb_agency_id,true);
        
    }

    // funtion to get image based on mode
    function getModeImage(mode)
    {


        var imgname;
        switch (mode) 
        {
            case "bus" :  
                     imgname="iconBus.png";   
                         
            break;
            case "rail" : 
                    imgname="iconRail.png";   
            break;
            case "ferry" : 
                    imgname="iconFerry.png";   
            break;
            case "shuttle" : 
                    imgname="iconShuttles.png";                      

            break
            case "other" :
                    imgname="iconOther.png";             
            break;

            default : 
               
        }

        return imgname;
    }

    // function which shows/hide the controls from schedule full view
    function showschedulefullview()
    {


        if(show_allcontainers==true)
        {
            $("#tbl_master_container").show();
            $("#div_master_container").show();
            $("#td_map_container").show();
            loadfares(false);
            if(getSelectedRouteID()!=null)
            {
                loadannouncements(glb_agency_id,getSelectedRouteID());
            }  
             
        }
        else
        {
            //$("#a_display_routemap").show();
           // $("#img_display_routemap").show();
            //$("#tbl_master_container").hide();
            $("#div_master_container").hide();
            $("#td_map_container").hide();
            $("#tbl_tab_container").appendTo("#div_tab_bottom");
     }
    }   

    // Called when schedule full view is closed or display route map link is clicked   
    function displayroutemapclick(blncallmap)
    {

        show_allcontainers=true;
        $("#tbl_master_container").show();
        $("#div_master_container").show();
        $("#td_map_container").show();
        $("#tbl_tab_bottom").attr("style","display:none");
        $("#tbl_tab_container").insertBefore("#div_master_container"); 
        showstopsonmapsearch();
        hidescheduleannoucementlink();
        loadfares(false);
        if(getSelectedRouteID()!=null)
        {
           loadannouncements(glb_agency_id,getSelectedRouteID());
           
        } 
        if(ismapenable()==true)
        {
            hyperlinkstopsheader();
        }  
        
        if(blncallmap==true)
        {
            if(routemap_called==false)
            {
               
                routemap_called=true;
               
                if(getcustomizedstops()!='' && getcustomizedstops()!=undefined)
                {
                
                     //needs to be uncommented when we implement customized stops on map
                     loadcustomizedstopsonmap(getcustomizedstops());
                }
                else
                { 
                    
                    loadroutemap();
                }
            }
               
           
        }
          
       displayprintschedulewithmap();
       showscheduleuparrow();
       if(!$("#rail_Div").is(":hidden"))
       {
            $("#rail_Div").show();
            showraillineuparrow();
            $("#div_schedule").hide();
       }
       else
       {
            
            $("#div_schedule").show();
            $("#rail_Div").hide();
       }
       
       
       
       
      
    
    }
    function schedulefullviewclick()
    {

        show_allcontainers=false;
        $("#tbl_tab_bottom").show();
        $("#tbl_tab_container").appendTo("#div_tab_bottom");  
        $("#div_master_container").hide();
        $("#td_map_container").hide();
        //$("#a_display_routemap").show();
       // $("#img_display_routemap").show();
        showSchedules();
        hidescheduleuparrow();
        hidestopsonmapsearch();
        $("#a_tab_schedule").attr("href","javascript:void(0);").unbind("click").bind("click", function()
        {bindschedulefullviewtabclick()});
        showscheduleannoucementlink();
        renderRouteAnnounceFlasher();
        hideprintschedulewithmap();
        removehyperlinkstopsheader();
        hideAllMapPopups();
//        $("#a_display_routemap").unbind("click").bind("click",function()
//        {
//            displayroutemapclick(false);
//            showManageMapLink();
//        });
    }

    function showmapcallback()
    {
        
        displayroutemapclick(true);
       
    }
    
    function railinefullviewclick()
    {       
        show_allcontainers=false;
        $("#tbl_tab_bottom").show();
        $("#tbl_tab_container").appendTo("#div_tab_bottom");  
        $("#div_master_container").hide();
        $("#td_map_container").hide();
       // $("#a_display_routemap").show();
        //$("#img_display_routemap").show();
        $("#rail_Div").show();
        hideraillineuparrow();
        $("#a_tab_schedule").attr("href","javascript:void(0);").unbind("click").bind("click", function()
        {bindschedulefullviewtabclick()});
        hideAllMapPopups();
//        $("#a_display_routemap").unbind("click").bind("click",function()
//        {
//            displayroutemapclick(false);
//            showManageMapLink();
//        });
    }
  




    //***********************************Ends Here: Schedule Load functions*********************

    //*********************************Starts Here: Annoucements functions*********************

    function loadannouncements(agencyid,routeid)
    {

        function render_announcement(announcement_object)
        {
           showAnnouncements();
           renderAllAnnouncement(announcement_object,"annoucementListPanel","span_annoucement_header");
           if(IsRouteAnnouncementsExists())
           {
                fireAcc("annoucementListPanel");
           }
            logevent(window.location,"controlfunctions_schedules.js","loadannouncements",PagesSchedulesRoutesMaps,"",getAgencyID(),getSelectedRouteID());
        }
       
     getAllAnnouncements(agencyid,routeid,render_announcement);
    }   

    //*********************************Ends Here: Annoucements functions*********************

    //*********************************Starts Here: Railline Diagram functions*********************                             
                       
    function loadRailLineDetails(routeid,dir,type)
    {
     if(checkexistinquerystring("showrailline=1")==false)
     {
       appendtourl("m1=S&m2="+ glb_agency_mode + "&routeid="+routeid+"&dir="+dir+"&type="+type+"&cid="+ glb_agency_id +"&showrailline=1",true);
     }
     else
     {
        function render_RailLineDiagram(railLineDetails)
        {
            hideSchedules();
            showRailLineDiagram();
            renderRailLineDiagram(railLineDetails,'rail_Div',raillinecloseclick,railinefullviewclick);
            
            if(!show_allcontainers)
            {
                $("#a_tab_schedule").attr("href","javascript:void(0);").unbind("click").bind("click", function()
                {bindschedulefullviewtabclick()});
            }    
                      
            
            var referencetext="RouteID:"+ routeid + ",Dir:" + dir;
            logevent(window.location,"controlfunctions_schedules.js","loadRailLineDetails",InfoRailLine,referencetext,getAgencyID(),getSelectedRouteID());
        }
        hyperlinkselectedroute(routeid);
        map_showlegends();
        getRailLineDetails(routeid,dir,render_RailLineDiagram);
     }
      //passed as called back for rail line close
        function raillinecloseclick()
        {
            //$("#div_schedule").show();
          
            if(show_allcontainers==false||show_allcontainers==null)
            {
              
                 if(dir!=''&&type!='')
                 {
                    appendtourl("m1=S&m2="+ glb_agency_mode + "&routeid="+routeid+"&dir="+dir+"&type="+type+"&cid="+ glb_agency_id,true);
                 }
                 else
                 {
                    appendtourl("m1=S&m2="+ glb_agency_mode + "&routeid="+routeid+"&cid="+glb_agency_id ,true);
                 }
                
                
            }
            else
            {
               
                $("#div_schedule").show();
                if(!ismapvisible())
                {
                    showbuttonshowmaplink();
                    $("#div_schedulelistotherroute").show();
                }
                else
                {
                    hidebuttonshowmaplink();
                    $("#div_schedulelistotherroute").hide();
                }
               
            }    
        }
        
    }

    //*********************************Ends Here: Railline Diagram functions*********************    



    //*********************************Starts Here: Show/Hide function starts here*********************    



    function hideSchedules()
    {
     $("#div_schedule").hide();
     hidescheduleannoucementlink();

    } 
    function showSchedules()
    {
        $("#div_schedule").show();
    }

    function hideRoutes()
    {
        $("#routeListRow").hide();
    }

    function hideFares()
    {
        $("#faresBox").hide();
        $("#fares_databox").hide();
    }
    function showFares()
    {
        $("#faresBox").show();
    }

    function hideAnnouncements()
    {
        $("#annoucementListRow").hide();
    }

    function showAnnouncements()
    {
        $("#annoucementListRow").show();
    }

    function hideAgencyServiceArea()
    {
        $("#agencyServiceAreaRow").hide();
    }

    function showAgencyServiceArea()
    {
        $("#agencyServiceAreaRow").show();
    }

    function hideAgencyProfile()
    {

        $("#agencyBox").hide();
        $("#agencyprofile_databox").hide();
    }
    function showAgencyProfile()
    {
       $("#agencyBox").show();
    }
    function hideAgencyDataSection()
    {
        $("#agencyBoxagenycyProfileRow").hide();
    }

    function showAgencyDataSection()
    {
        $("#agencyBoxagenycyProfileRow").show();
    }

    function hideRailLineDiagram()
    {
        $("#rail_Div").hide();
    }

    function showRailLineDiagram()
    {
        $("#rail_Div").show();
    }
    function agencies_hideothercontrols()
    {
        hideSchedules();
        hideRoutes();
        hideFares();
        hideAnnouncements();
        hideAgencyProfile();
        hideRailLineDiagram();
        hideAgencyServiceArea();
    }

    //*********************************Ends Here: Show/Hide function starts here*********************    


    //*********************************Starts Here: Map Control functions*********************

    function loadmaphelp(helpfor)
    {
      
     
       function render_maphelp(helpitem)
        {
            if(helpfor=='scheduleselector')
                 {
                    maphelpheader=rskey_maphelpheader;
                   
                 }
                 if(helpfor=='fareselector')
                 {
                    maphelpheader=rskey_maphelpheader + "-Fares";
                   
                 }
                 if(helpfor=='agencyprofileselector')
                 {
                    maphelpheader=rskey_maphelpheader;
                   
                 }
            renderhelp(helpitem,maphelpheader,xpos,ypos,"a_maphelp");
        }
        
           var xpos;
           var ypos;
           var maphelpheader;
          
           $("#td_maphelp").empty();
           $("<a id='a_maphelp' href='javascript:void(0);'  >"+
           "<img src='http://images.transit.511.org/RUI/fw/iconHelp.gif' title='Help' /></a>").appendTo("#td_maphelp");
           
           $("#a_maphelp").unbind("click").bind("click",
           function(event)
           {
                 xpos=event.pageX-350;
                 ypos=event.pageY;
                 
                 if(helpfor=='scheduleselector')
                 {
                    maphelpheader=rskey_maphelpheader;
                    getHelp("maphelpschedule","en",render_maphelp);
                 }
                 if(helpfor=='fareselector')
                 {
                    maphelpheader=rskey_maphelpheader + "Fares";
                    getHelp("maphelpfare","en",render_maphelp);
                 }
                 if(helpfor=='agencyprofileselector')
                 {
                    maphelpheader=rskey_maphelpheader;
                    getHelp("maphelpagency","en",render_maphelp);
                 }
              
                
           });
           
    }
    function loadzoomtoagencymap(agencyid,mode)
    { 
        try
        {
            if(ismapenable()==true)
            {
                unbindmapdivevents();
                hideManageMapLink();
                map_zoomtoagency(agencyid,mode);
                logevent(window.location,"controlfunctions_schedules.js","loadzoomtoagencymap",MapAgency,"",agencyid,"");
            }   
        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadzoomtoagencymap",ErrorWWWNonFatal,"",agencyid,"")
        }
        
         
    }


    function loadhighlightagencymap(agencyid,mode)
    {
      try
        {
            if(ismapenable()==true)
            { 
            
                unbindmapdivevents();
                hideManageMapLink();
                map_highlightagency(agencyid,mode);
                highlight_mapcalled=true;
                logevent(window.location,"controlfunctions_schedules.js","loadhighlightagencymap",MapAgency,"",agencyid,"");
             }  
        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadhighlightagencymap",ErrorWWWNonFatal,"",agencyid,"")
        }
        
         
    }
    
    //called from schedules/index.aspx.cs to show agency map bubble
    function showAgencyMapTip()
    {
        if(blnShowAgencyMapTip==true)
        {
            var _agencymaptipbody="";
            if(getAgencyAddress()!=null)
            {
                _agencymaptipbody=getAgencyAddress();
            }
            if(getAgencyPhone()!=null)
            {
                _agencymaptipbody+="<br></br><br></br><b>" + rskey_tel + " " + rskey_511 + "</b><br/>";
                if(getAgencyMainUrl() != "")
                _agencymaptipbody+= "<a href=\'" +  getAgencyMainUrl() + "\' >" + rskey_website + " </a>";
            }
           
        }
   }
   
    function loadhighlightfarezonesmap(agencyid)
    {
        try
        {
            
              if(ismapenable()==true)
                {
                    unbindmapdivevents();
                    hideManageMapLink();
                    map_highlightfarezones(agencyid);
                    function ShowStationMapTips(agencyid)
                            {
                                $("#mapBoxShort").unbind("mouseup").bind("mouseup",function(event)
                                {  
                                        CloseAllMaptips();
                                });
                            
                            }
                        if(getFareZoneStationMapTip(agencyid))
                        {
                           ShowStationMapTips(agencyid);
                        }
                       else
                       {
                      
                           unbindmapdivevents();
                       }
                       
                       logevent(window.location,"controlfunctions_schedules.js","loadhighlightfarezonesmap",MapFarezones,"",agencyid,"");
                 } 
        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadhighlightfarezonesmap",ErrorWWWNonFatal,"",agencyid,"")
        }
        
        
      
      
    }  

    function loadroutemap()
    { 
        try
        {
            
            
            if(ismapenable()==true)
                {
                    if(ismapvisible()==true)
                    {
                       
                        unbindmapdivevents();
                        showManageMapLink();//9.2 to 9.3 call after map is called
                        $("#a_routeview_map").show();
                        var mode=getRouteModeByRouteID(getSelectedRouteID());
                        if(mode=='')
                        {
                            mode=glb_agency_mode;
                        }
                        map_highlightrouteandstops(getSelectedRouteID(),getScheduleDayType(),getScheduleDirection(),mode,getScheduleStartStop(),getScheduleEndStop()); 
                        //showManageMapLink(); 9.3 test                     
                        setmapheadertext(getAgencyName() + " "+rskey_mapheaderforroute +" " + getSelectedRouteDesignator(getSelectedRouteID()) + " - " +  getSelectedDirectionName());   
                        function ShowStopMapTips()
                        {
                                
                             $("#mapBoxShort").unbind("click").bind("click",function(event)
                                {
                                         CloseAllMaptips();
                                 });
                         }
                        
                        ShowStopMapTips();
                        logevent(window.location,"controlfunctions_schedules.js","loadroutemap",MapRoute,"",getAgencyID(),getSelectedRouteID());
                    } 
                }    
             
        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadroutemap",ErrorWWWNonFatal,"",getAgencyID(),getSelectedRouteID())
        }
      
    }
  
    function loadselectedstopsonmap(stopid)
    {
        
        try
        {
              if(ismapenable()==true)
                {
                   var mode=getRouteModeByRouteID(getSelectedRouteID());
                   if(mode==undefined)mode=glb_agency_mode;
                    //map_highlightstop(stopid,glb_agency_mode,getScheduleStartStop(),getScheduleEndStop());
                    map_highlightstop(getSelectedRouteID(), getScheduleDayType(), getScheduleDirection(),mode,getScheduleStartStop(),getScheduleEndStop(),stopid,getAgencyName())
                    logevent(window.location,"controlfunctions_schedules.js","loadroutemap",MapRoute,"Stop:" + stopid ,getAgencyID(),getSelectedRouteID());
                }    

        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadselectedstopsonmap",ErrorWWWNonFatal,"Stop:"+ stopid,getAgencyID(),getSelectedRouteID())
        }
      
    }

    function loadcustomizedstopsonmap(stopids)
    {
        try
        {
            if(ismapenable()==true)
            {
                if(ismapvisible()==true)
                {
                    unbindmapdivevents();
                    $("#a_routeview_map").show();
                   
                    if (stopids!='')
                    {
                      var startStopId;
                      var endStopId;
                      var otherStopIds='';
                      var arrStopids;
                      arrStopids=stopids.split(",");
                      startStopId=arrStopids[0];
                      endStopId=arrStopids[arrStopids.length-1];
                      for(var idx=0;idx<arrStopids.length;idx++)
                      {
                            if(startStopId!=arrStopids[idx]&&endStopId!=arrStopids[idx])
                            {
                                if(otherStopIds=='')
                                {
                                    otherStopIds=arrStopids[idx];
                                }
                                else
                                {
                                    otherStopIds+=','+ arrStopids[idx];
                                }
                            }
                      }
                     
                      map_highlightrouteandcustomisedstops(getSelectedRouteID(), getScheduleDayType(), getScheduleDirection(), glb_agency_mode, startStopId, endStopId, otherStopIds);   
                    }
                     
                   
                       
                        function ShowStopMapTips()
                        {
                                
                             $("#mapBoxShort").unbind("click").bind("click",function(event)
                                {
                            
                                           CloseAllMaptips();
                                });
                           
                         
                      }
                        
                        ShowStopMapTips();
                 
                    logevent(window.location,"controlfunctions_schedules.js","loadcustomizedstopsonmap",MapRoute,"Stops:" + stopids ,getAgencyID(),getSelectedRouteID());
                }   
            }  
        
        }
        catch(err)
        {
            logerror(err,window.location,"controlfunctions_schedules.js","loadcustomizedstopsonmap",ErrorWWWNonFatal,"Stops:"+ stopids,getAgencyID(),getSelectedRouteID())
        }
        
          
    }



    function setmapheadertext(headertext)
    {
      if(ismapenable()==true)
        {  
            $("#span_mapheader").show();
            $("#span_mapheader").html("<b>"+ headertext +"<b>");
            
        }    
    }
    function getmapheadertext()
    {
    
        return  $("#span_mapheader").text();
    }

    function clearmapclick()
    {
        if(ismapenable()==true)
        {  
            $("#span_mapheader").hide();
            map_restoremap();
        }    
    }
    
    function hideAllMapPopups()
    {
       
        CloseAllMaptips();
      
    }

    function ismapvisible()
    {
    return show_allcontainers;
    }
    
    function ismapenable()
    {
        return enable_mapping;
    }
    
    function EnlargeMap()
    {
      if(ismapenable()==true)
        {  
     
           
            
            $("#div_manage_map").attr("style","margin-top: 462px;z-index:700;");
            $("#a_enlarge_map").hide();
            $("#a_reduce_map").show();
            AnimateDataContainers()
            $("#mapBoxShort").attr("style","vertical-align: top; height: 483px")
            map_changemapsize(484,482);
            $("#a_reduce_map").unbind("click").bind("click",function()
            {
                  ReduceMap();
            });
            $("#a_enlarge_map").unbind();
        }    
    }
    function showManageMapLink()
    {
       if(ismapenable()==true)
        { 
          
                $("#div_manage_map").show();
                $("#a_enlarge_map").text(rskey_enlargemap).hide();
                $("#a_reduce_map").text(rskey_reducemap).hide();
                ReduceMap();
                setfocusonstoplink(); 
                
         }   
    }
    
    function ReduceMap()
    {
       if(ismapenable()==true)
        {         
                              
            $("#div_manage_map").attr("style","margin-top: 320px;z-index:700;");
            $("#a_enlarge_map").show();
            $("#a_reduce_map").hide();
            AnimateDataContainers();
            $("#mapBoxShort").attr("style","vertical-align: top; height:340px"); 
            map_changemapsize(484,340);
            $("#a_enlarge_map").unbind("click").bind("click",function()
                {
                  EnlargeMap();
                });
            $("#a_reduce_map").unbind();  
            return false;
         }   
    }
    
    function hideManageMapLink()
    {
       if(ismapenable()==true)
        {   
         
            $("#a_enlarge_map").unbind();
            $("#a_reduce_map").unbind();
            $("#div_manage_map").hide();
            $("#a_enlarge_map").hide();
            $("#a_reduce_map").hide();
            AnimateDataContainers(); 
            
            $("#mapBoxShort").attr("style","vertical-align: top; height: 482px")
            map_changemapsize(484,482);
        }    
    }
    
    function AnimateDataContainers()
    {
        if(!($("#div_manage_map").is(":hidden")))
        {
           if(!($("#a_enlarge_map").is(":hidden")))//show reduce heights
           {
                 $("#tbl_routlistsubtable").removeClass("routeListSubTable").addClass("routeListSubTableReduce");
                 $("#div_routesPanel").removeClass("routesPanel").addClass("routesPanelReduce");   
                 $("#agencyServiceAreaPanel").removeClass("agencyServiceAreaPanel").addClass("agencyServiceAreaPanelReduce"); 
                 $("#annoucementListPanel").removeClass("annoucePanel").addClass("annoucePanelReduce"); 
                 $("#div_annoucement_list").removeClass("announcementScroller").addClass("announcementScrollerReduce"); 
                 $("#fareListPanel").removeClass("farePanel").addClass("farePanelReduce"); 
                 $("#fareListPaneldiv_fares_list").removeClass("faredataScroller").addClass("faredataScrollerReduce");
           }
           else //show enlarge heights
           {
                 $("#tbl_routlistsubtable").removeClass("routeListSubTableReduce").addClass("routeListSubTable");
                 $("#div_routesPanel").removeClass("routesPanelReduce").addClass("routesPanel");   
                 $("#agencyServiceAreaPanel").removeClass("agencyServiceAreaPanelReduce").addClass("agencyServiceAreaPanel"); 
                 $("#annoucementListPanel").removeClass("annoucePanelReduce").addClass("annoucePanel"); 
                 $("#div_annoucement_list").removeClass("announcementScrollerReduce").addClass("announcementScroller"); 
                 $("#fareListPanel").removeClass("farePanelReduce").addClass("farePanel"); 
                 $("#fareListPaneldiv_fares_list").removeClass("faredataScrollerReduce").addClass("faredataScroller"); 
           }
        }
        else
        {
                 $("#tbl_routlistsubtable").removeClass("routeListSubTableReduce").addClass("routeListSubTable");
                 $("#div_routesPanel").removeClass("routesPanelReduce").addClass("routesPanel");   
                 $("#agencyServiceAreaPanel").removeClass("agencyServiceAreaPanelReduce").addClass("agencyServiceAreaPanel"); 
                 $("#annoucementListPanel").removeClass("annoucePanelReduce").addClass("annoucePanel"); 
                 $("#div_annoucement_list").removeClass("announcementScrollerReduce").addClass("announcementScroller"); 
                 $("#fareListPanel").removeClass("farePanelReduce").addClass("farePanel"); 
                 $("#fareListPaneldiv_fares_list").removeClass("faredataScrollerReduce").addClass("faredataScroller"); 
        }
    }
           
    
    function unbindmapdivevents()
    {
        $("#mapBoxShort").unbind("click");
        $("#mapBoxShort").unbind("mousedown")
    }
    
    
    function map_showlegends()
    {
           $("#td_maplegend").show();
           $("#td_maplegend").empty();
           $("<a id='a_map_legend' href='javascript:void(0);'  >"+ rskey_maplegends +"</a>").appendTo("#td_maplegend");
           $("#a_map_legend").unbind("click").bind("click",function(event)
           {
                var clsName="MaplegendLink";
                if($.browser.msie && $.browser.version=="6.0")
                    clsName="IE6MaplegendLink";
                $("body").find("#div_map_legend").remove();
                var tPosX = event.pageX-400;
                var tPosY = event.pageY-20 ;
                $("<div id='div_map_legend' class='"+clsName+"'>"+
                "<br><div class='closeBox' style='padding-right: 15px;'>"+
                "<a id='a_map_legendclose'  style='z-index:888888' href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>"+
                "</div></div>").appendTo("body");
                $("#div_map_legend").css({top: tPosY, left:tPosX});
                
                $("#a_map_legendclose").unbind("click").bind("click",function()
                {
                    hidemaplegend();
                });
            
           });
            
            
 
    }
    
    function hidemaplegendlink()
    {
       $("#td_maplegend").hide();  
    }
    function hidemaplegend()
    {
        $("#div_map_legend").hide();
    }
    
    function showrouteslistmap(controlid,route_id,agencyid)
    {
         
     
      
      var route_mode='';
      var route_color='';
      var route_string='';
      var route_touncheck='';
      var route_colorindicator_style='display:none; width:10px;height:8px;background-color:white';
      var routemaplist=glb_routemaplist.split(';');
      if($("#"+ controlid).is(":checked"))
      {
         if(glb_routemapcounter>3)
         {
         
            if(!(window.confirm("Already requests are in process do you want to proceed?")))
            {
                $("#"+ controlid).removeAttr("checked");
                return false;
            }
         }
         glb_routemapcounter++;
         
         $("#txt_counter").val(glb_routemapcounter);
          route_mode=getRouteModeByRouteID(route_id)
          route_string=route_id +'~'+ route_mode;
         
          
           switch (routemaplist.length) 
               {
                                    
                    case 1 : 
                           route_color=getUnusedColor();    
                           glb_routemaplist=route_string +'~'+ route_color +';';
                           
                               
                    break;
                    case 2 : 
                           route_color=getUnusedColor();    
                           glb_routemaplist=glb_routemaplist + route_string +'~'+ route_color +';';
                           
                    break;
                    case 3 : 
                           route_color=getUnusedColor();    
                           glb_routemaplist=glb_routemaplist + route_string +'~'+ route_color +';';
                           
                    break;
                    case 4 : 
                           route_color=routemaplist[0].split('~')[2];    
                           glb_routemaplist=routemaplist[1]+ ';'+ routemaplist[2]+';' + route_string +'~'+ route_color +';';
                           route_touncheck=routemaplist[0].split('~')[0];
                           $("#td_routes_list").find("div").find("span").find("#chk_"+ route_touncheck).removeAttr("checked");
                           $("#td_routes_list").find("div").find("span").find("#div_routecolorindicator_"+route_touncheck).attr("style",route_colorindicator_style); 
                    break;
                   
                }
         
          route_colorindicator_style= 'display:inline; width:10px;height:8px;background-color:'+route_color;     
          $("#td_routes_list").find("div").find("span").find("#div_routecolorindicator_"+route_id).attr("style",route_colorindicator_style); 
         
      }
      else
      {
       
        if(glb_routemapcounter!=null)
            if(glb_routemapcounter>0)
                glb_routemapcounter--;
           
        //remove the entry from glb_routemaplist
        glb_routemaplist='';
        $("#td_routes_list").find("div").find("span").find("#div_routecolorindicator_"+route_id).attr("style",route_colorindicator_style); 
        for(idx=0;idx<routemaplist.length;idx++)
        {
            if(routemaplist[idx].split('~')[0]!=route_id)
            {
                 if(glb_routemaplist=='')
                 {
                    glb_routemaplist=glb_routemaplist + routemaplist[idx];
                 }
                 else
                 {
                    glb_routemaplist=glb_routemaplist + ';'+ routemaplist[idx]
                 }
            }
        }
       
      }
      if(glb_routemaplist!='' && glb_routemaplist!=null)
      {
        var routelist_data=glb_routemaplist.substring(0,glb_routemaplist.length-1);
        map_highlightagencyandroute(agencyid,routelist_data);
        showroutepreviewmaplegend();
      }
      else
      {
        hideroutepreviewmaplegend();
        loadhighlightagencymap(agencyid,glb_agency_mode)
      }
      
      
      function getUnusedColor()
      {
       var route_colorlist="#006019^#E73D00^#6A3523";
         //var route_colorlist="#006019^#E73D00^#C27300";
         var str_color="#006019";
         var bln_colorfound=false;
         if(glb_routemaplist!='')
         {
            var routelist=glb_routemaplist.split(';');
            route_colorlistarray=route_colorlist.split('^');
            for (colidx=0;colidx<route_colorlistarray.length;colidx++)
            {
                bln_colorfound=false;
                for(idx=0;idx<routelist.length;idx++)
                {
                    var colorlist=routelist[idx].split('~');
                    var color_used=colorlist[2];
                    if(color_used==route_colorlistarray[colidx])
                    {
                        bln_colorfound=true;
                        break;
                    }
                }
                if(bln_colorfound==false)
                {
                    str_color=route_colorlistarray[colidx];
                    break;
                }
                
             }
         }
       
        return str_color;
      }
   }
    function hideroutepreviewmaplegend()
    {
         $("#div_routepreview_maplegend").attr("style","display:none");
    }
    function showroutepreviewmaplegend()
    {
         
         $("#div_routepreview_maplegend").attr("style","display:block");
    }
    function clearroutelistmap()
    {
         glb_routemaplist='';
         glb_routemapcounter=0;
         $("#td_routes_list").find("div").find("span").find("input:checkbox").removeAttr("checked");
         $("#td_routes_list").find("div").find("span").find("div").attr("style","display:none; width:10px;height:8px;background-color:white"); 
         hideroutepreviewmaplegend();
         loadhighlightagencymap(glb_agency_id,glb_agency_mode)
    }
    //*********************************Ends Here: Map Control functions*********************

function showcommuterewards(xpos,ypos)
{

    $("body").find("#div_commutereward_popup").remove();
            var reward_data='You can receive tax benefits, free transit passes and even cold hard';
            reward_data+=' cash by NOT driving alone in your car. Many employers, counties and'; 
            reward_data+=' local jurisdictions offer incentives to commuters who take transit or';
            reward_data+=' rideshare, so ask at work. Or, click <a href="http://rideshare.511.org/rideshare_rewards/" target="_blank"><b>here</b></a> for a list of rewards'; 
            reward_data+=' and incentives available from public agencies throughout the Bay Area.';
            var reward_html='';
            var tPosX=xpos;
            var tPosY=ypos-40;
            reward_html="<div id='div_commutereward_popup' style='z-index:1099998;position:absolute;'>";
            reward_html+="<table class='commuterewardTable' cellspacing='0'><tr><td class='boxTop'></td></tr>";
            reward_html+="<tr>";
            reward_html+="<td class='contentBox'>";
            reward_html+="<div class='closeBox' style='padding-right: 4px;'>";
            reward_html+="<a id='a_rewardclose'  href='javascript:void(0);'><img  src='http://images.transit.511.org/RUI/fw/btnX_9pxSquare.gif' alt='"+ rskey_altclose +"' /></a>";
            reward_html+="</div><a id='a_reward_start' href='javacript:void(0);' title='Commute Rewards & Incentives window start'></a><h1 class='commuterewardHeader'>Commute Rewards & Incentives</h1>";
            reward_html+="<div class='boxDivider'></div>" ;
            reward_html+="<div id='div_commutereward_data' class='commuterewardListingdiv' >"+ reward_data +"</div><a id='a_reward_end' href='javacript:void(0);' title='End of Commute Rewards & Incentives Close Commute Rewards & Incentives Window'></a>"
            reward_html+="</td></tr><tr><td class='boxBtm'></td></tr></table></div>"
            $(reward_html).appendTo("body")
            $('#div_commutereward_popup').css({top: tPosY, left:tPosX});
            $("#a_reward_start").focus();
            $("#a_rewardclose").unbind("click").bind("click",
            function()
            {
                $("body").find("#div_commutereward_popup").remove();
                
            });
            
            $("#a_reward_end").unbind("click").bind("click",
            function()
            {
                $("body").find("#div_commutereward_popup").remove();
                
            });
}
function hidecommuterewardpopup()
{
    $("body").find("#div_commutereward_popup").remove();
}
//* * * * * * * * * controlfunctions_schedules.js ends here  * * * * * * * * * * *//
