/**
 * Class to represent a wrapper around Ptv function calls
 *
 * $Id: ptvWrapper.js,v 1.11 2009/02/23 05:55:12 vpulla Exp $
 */


var ptvWrapper = new PtvWrapper()
function PtvWrapper()
{
   /**
    * Function to convert a coordinate in smart unit from current coordinate in lat
    * & long
    * @param {longitude:xxxx,latitude:yyy} in this format
    */
   this.getSmartCoordinate=function getSmartCoordinate(geoCode)
   {
      var tempCoord = {x:0, y:0};
      tempCoord.x = geoCode.longitude * conf_smartUnitToGeoFactor;
      tempCoord.y = geoCode.latitude * conf_smartUnitToGeoFactor;
         
      var coordAsSmartUnit=
             com.ptvag.webcomponent.map.CoordUtil.geoDecimal2SmartUnit(tempCoord);
   
      return coordAsSmartUnit; 
   };
   
   /**
    * Function to convert a coordinate from smart units to real long & lat
    */
   this.getRealCoordinate=function getRealCoordinate(smartUnitGeoCode)
   {
      var geoCode=
             com.ptvag.webcomponent.map.CoordUtil.smartUnit2GeoDecimal(smartUnitGeoCode);
             
      geoCode.x /= conf_smartUnitToGeoFactor;
      geoCode.y /= conf_smartUnitToGeoFactor;
   
      return geoCode;
   };
   
   
   /**
    * Function responsible for loading map, the new map required authentication
    * prior to retrieving the map. Once logged in, invoke the function 
    * "onSuccessFunction" which is passed in as an attribute
    */
   this.redirectAfterLogin=function redirectAfterLogin(onSuccessFunction)
   {
      var loginService = new com.ptvag.mnp.ajax.LoginService();
      loginService.isLoggedIn(
               function loggedIn()
               {
                  eval(""+onSuccessFunction);
               });
   };
   
   /**
    * Function to load the map automatically into the div container with id 
    * specified by parameter "mapContainer"
    * @param mapContainer: The id of the div element which shall contain the 
    *                      actual map
    */
   this.loadMapAfterLogin=function loadMapAfterLogin(mapContainer)
   {
      var loginService = new com.ptvag.mnp.ajax.LoginService();
      loginService.isLoggedIn(
         function loggedIn()
         {
            MapUtils.loadMap(mapContainer);    
         }
      );
      
   }
   
   /**
    * Dispose of the map when done
    */
   this.disposeMap=function disposeMap() 
   {
      if(map != null)
         map.dispose();
   }
}

