//history table click
var tableDetailPoup = null;
function showTableDetail(popupdata,x,y)
{
  $jq("#userHistoryMenu").history.pauseAnimate();
  var point = new OpenLayers.Geometry.Point(x, y);
	var point_merc = OpenLayers.Projection.transform(point, "epsg:4326", "epsg:54004");
		 			 
  if (tableDetailPoup != null){
      tableDetailPoup.destroy();
  }
  olmapHistory.getMap().setCenter(new OpenLayers.LonLat(point_merc.x,point_merc.y), 11);
  tableDetailPoup = new OpenLayers.Popup.Anchored("tx1ddjeuejhdki", 
                         new OpenLayers.LonLat(point_merc.x,point_merc.y),
                         new OpenLayers.Size(400,400),
                         popupdata,null,true);
  olmapHistory.getMap().addPopup(tableDetailPoup);

}

//reports
function porociloVoznja(idnaprave,od_datum, do_datum, interval,tip,excel)
{
    var nid = document.getElementById(idnaprave).value;
    var ds = document.getElementById(od_datum).value;
    var de = document.getElementById(do_datum).value;
    var interv = document.getElementById(interval).value;
    var tip = document.getElementById(tip).value;
    
    if (tip == 'R_VOZNJE')
        uReports.porociloVoznja(nid,ds, de, interv,excel);
    else if(tip == 'R_POSTANKI')
        uReports.porociloPostanki(nid,ds, de, interv,excel);      
}       

//tabs
//show def content
function showDefault()
{
    $jq('#htmlContentPanel').hide();
    $jq('#form_left').show();
    $jq('#map').show();
    
}

//show def content by table
function showDevicesInfo()
{
     $jq.get('devicesinfo.php',{},function(data)
     {
          $jq('#htmlContentPanel').html(data);
          $jq('#htmlContentPanel').show();
          $jq('#form_left').hide();
          $jq('#map').hide();
          $jq("#devicesInfoTable").devicesTableView({},"http://www.yellowlbs.com/gpsDevicesClient.php");
     });
}

//show old positions manager
function showHistoryDiv ()
{
      $jq.get('history.php',{},function(data)
      {
          $jq('#htmlContentPanel').html(data);
          $jq('#htmlContentPanel').show();
          $jq('#form_left').hide();
          $jq('#map').hide();
          olmapHistory  = new OLMap(mapHistorySettings);
          var m = olmapHistory.getMap();
          //m.updateSize();			
          Calendar.setup(
      		{
      		   inputField : "CAS_OD", // ID of the input field
      		   ifFormat : "%d.%m.%Y %H:%M" , // the date format
      		   showsTime      :    true,
             button : "btnod" // ID of the button
      		}
      		);
          Calendar.setup(
      		{
      		   inputField : "CAS_DO", // ID of the input field
      		   ifFormat : "%d.%m.%Y %H:%M" , // the date format
      		   showsTime      :    true,
             button : "btndo" // ID of the button
      		});
          
          $jq("#userHistoryMenu").history({},"http://www.yellowlbs.com/gpsDevicesClient.php","http://www.yellowlbs.com/gpsPositionsClient.php",m,"http://");
      
      }
      );
}

//show old positions manager
function showReportDiv ()
{
      $jq.get('reports.php',{},function(data)
      {
          $jq('#htmlContentPanel').html(data);
          $jq('#htmlContentPanel').show();
          $jq('#form_left').hide();
          $jq('#map').hide();
          //m.updateSize();			
          Calendar.setup(
      		{
      		   inputField : "CAS_OD", // ID of the input field
      		   ifFormat : "%d.%m.%Y %H:%M" , // the date format
      		   showsTime      :    true,
             button : "btnod" // ID of the button
      		}
      		);
          Calendar.setup(
      		{
      		   inputField : "CAS_DO", // ID of the input field
      		   ifFormat : "%d.%m.%Y %H:%M" , // the date format
      		   showsTime      :    true,
             button : "btndo" // ID of the button
      		});
      
      });
}
//end tabs
//full screenmap ? IE 7  hack
function resizeMap()
{
    if ($jq("#map").css("position")!="absolute")
    {
      document.body.appendChild(document.getElementById('map'));
      $jq("#map").addClass("fullScreenMap");
      olmap.getMap().updateSize();
    }
    else
    {
       olmapParent.appendChild(document.getElementById('map'));
       $jq("#map").removeClass();
       olmap.getMap().updateSize();
    }  
}  

function selectTab(spanob)
{
    if (spanob != null)
    {
      $jq("span[@id*=m]").each(function()
      {
          $jq(this).css('color','white');
      });
      $jq("#"+spanob.id).css('color','red');
    }
    else
    {
        //def tab
        $jq("#m3").css('color','red');
        $jq("#m2").css('color','red');
    }
}


function printPreviewMap()
{
  
  var x = $jq('#map').height();
  var y = $jq('#map').width();   
  var con = $jq('#map_OpenLayers_Container').clone().html();

  var a = window.open('','','resizable=yes, scrollbars=0, menubar=0,width='+y+',height='+x);
  //a.document.open("text/html");
  a.document.write('<html> <head>');
  a.document.write('</head> <body>');
  a.document.write('<div style="z-index:99999;position:absolute;top:0px;left:0px;"> <img onclick="window.print();" style="cursor:pointer;" src="./image/print.png" alt="print"  border="0"></div>');
  a.document.write(con);
  a.document.write('</body> </html>');
  a.document.close(); 
  
}
