
var gPDFURL = "/pdf/";
var gContextPath = "/public";
var gPremuimBusServicePath = gContextPath + "/ptp/en/premium_bus_service.html";
var gArrivalTimePath = gContextPath + "/ptp/en/getting_around/bus_arrival_time.html";
var gDomainName = "http://" + window.location.hostname;
var gCarParkDetail = "/publish/carPark/";

function doGotoURL(url)
{
  if (url.length > 0)
  {
    document.location = url;
    return;
  } 
}

function doIFrameResize(id)
{
  var a = navigator.userAgent;
  var isSF = (a.indexOf("Safari") > 0) ? true : false;
  var isIE = (a.indexOf("MSIE") > 0) ? true : false;
  
  var time;
  var delay = 200;

  var docHeight = (isIE) ? document.body.scrollHeight + 4 : document.body.offsetHeight;
  var docHeight = (isSF) ? docHeight + 20 : docHeight;

  //alert("docHeight:" + docHeight);

  if (docHeight == null || docHeight <= 10)
  {
    var func = "doIFrameResize('"+ id +"')";
    time = setTimeout(func, delay);    
  } 
  else 
  {  
    if (time)
      clearTimeout(time);
    
    try
    {
      if (isIE)
        window.parent.document.getElementById(id).style.height = docHeight;
      else 
        window.parent.document.getElementById(id).height = docHeight;
    } catch(e)
    {
     //alert(e);  
    }
  }
}

function doPopUp(url, name, option, width, height)
{
  if (!name) name= "_popup";  
  if (!option) option = "menubar=0,scrollbars=1,status=1,resizable=1";
  if (!width) width = 700;
  if (!height) height = 500;

  var w = window.open(url, name, "width=" + width + ",height=" + height + "," + option);
  if (w) 
    w.focus();
}

function doPrint(url)
{
//  var w = window.open(url, "_print");
//  if (w) 
//    w.focus();
  window.print();
}

function doMapGoto(latitude, longtitude)
{
  objSrcMarker.showOnMap(4, longtitude, latitude);
}

function doViewMRT (stationCode)
{ 
    if( stationCode.indexOf("EW") != -1 || 
        stationCode.indexOf("NE") != -1 || 
        stationCode.indexOf("NS") != -1 ||
        stationCode.indexOf("CC") != -1)
        stationCode =  stationCode.trim().substring(0,3);
    else
        stationCode =  stationCode.trim().substring(0,2);
        
    doPopUp(gDomainName + gPDFURL + "mrtlrt/" + stationCode + '.pdf', "_mrt", "status=yes,toolbar=no,menubar=no,location=no", 1024, 768);
}

function doViewBusRoute(serviceno, direction, routeseq, busstopcode)
{ 
    if (-1 != serviceno.lastIndexOf("#"))
      serviceno = serviceno.replace("#","C");
     	
    doPopUp(gDomainName + gPDFURL + "busstops/"  + busstopcode + "/" + serviceno + "_" + direction + "_" + routeseq + "_" + busstopcode + ".pdf", "_bus", "status=yes,toolbar=no,menubar=no,location=no", 1024, 768);
}

// for KML javascript
function doViewBusIndex (serviceno, direction, routeseq, busstopcode)
{ 
  doViewBusRoute(serviceno, direction, routeseq, busstopcode)
}

function doViewFareTable()  
{ 
   doPopUp(gDomainName + gPDFURL + 'roadIndex/fare.pdf', "_fare", "status=yes,toolbar=no,menubar=no,location=no", 1024, 768);
}

function doViewRoadIndex (busstopCode)
{ 
   doPopUp(gDomainName + gPDFURL + 'roadIndex/' + busstopCode + '.pdf', "_road", "status=yes,toolbar=no,menubar=no,location=no", 1024, 768);
}
 
function doShowPremium (busServiceNo)
{ 
  var myurl = gPremuimBusServicePath + "?qs_premiumbusservice=" +  busServiceNo ;
  window.location.replace(myurl); 
}

function doShowArrivalTime(busstop, busservice)
{
  var myurl = gArrivalTimePath + "?bus_stop=" +  busstop + "&bus_service=" + busservice;
  window.location.replace(myurl); 
}

function doViewCarParkDetail(carParkNum)
{
  var html = gDomainName + gCarParkDetail+carParkNum+".html";
//	doPopUp(gDomainName + gCarParkDetail +html, "_carpark", "status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes", 420, 400);
var ss = document.getElementById('carparkD');
var carparkDetail;
carparkDetail = '<div> <iframe src ='+html;
carparkDetail+=' width="320" height="160" align="left" >';
carparkDetail+=  '<p>Your browser does not support iframes.</p></iframe>';
ss.innerHTML = carparkDetail;

if(ss.style.display=='none'){
 ss.style.display = 'block';
}

}
