/*
  (C) by KSI media sp. z o.o. ( www.ksimedia.pl )  
  Description : GPS EditBox class.
  Author      : MS
  Create date : 2010-08-22
  Comment     :
*/

function classEditBox_gps ()
{

  this.updateValues = function ( name )
  {
    var tmp ;
    var o ;
    var latLng ;
    tmp = ExtComponents.getValue ( name ) ;
    if ( tmp == '' )
    {
      document.getElementById ( 'vis_'+name ).value = ' - dowolny - ' ;
    }
    else
    {
      tmp = tmp.split ( ';' ) ;    
      if ( tmp.length == 3 ) 
      {
        o = '[' + tmp[0].substr ( 0,5 ) + ',' + tmp[1].substr ( 0,5 ) + '] +/- ' + tmp[2] + 'km'  ;
        ExtComponents.setValue ( 'gps_r_'+name, tmp[2] ) ;
        try
        {
          latLng = new google.maps.LatLng ( tmp[0], tmp[1] ) ;
          GoogleMaps.deleteOverlays ( name+'_gm' ) ;
          GoogleMaps.addMarker ( name+'_gm', latLng ) ;
          GoogleMaps.addCircle ( name+'_gm', latLng, tmp[2], '#ee4422' ) ;
        }
        catch(err)
        {
          //alert ( 'jeszcze nie ma' );
        }
      }
      else
      {
        o = '' ;
      }
      document.getElementById ( 'vis_'+name ).value = o ;
    }
  }
  
  this.mapClick = function ( name )
  {
    var p ;
    var name_obj ;    
    name_obj = name.substr(0,name.length-3);
    if ( GoogleMaps.lastEvent [ name ] == undefined )
    {
      var latLng ;
      var tmp ;
      tmp = ExtComponents.getValue ( name_obj ) ;
      tmp = tmp.split ( ';' ) ;
      latLng = new google.maps.LatLng ( tmp[0], tmp[1] ) ;
      p = document.getElementById ( 'gps_r_'+name_obj ).value ;
      p = latLng.lat() + ';' + latLng.lng() + ';' + p ;
      ExtComponents.setValue ( name_obj, p, false ) ;
    }
    else
    {
      mEvent = GoogleMaps.lastEvent [ name ] ;
      p = document.getElementById ( 'gps_r_'+name_obj ).value ;
      p = mEvent.latLng.lat() + ';' + mEvent.latLng.lng() + ';' + p ;
      ExtComponents.setValue ( name_obj, p, false ) ;
    }
  }

}

EditBox_gps = new classEditBox_gps () ;
