/*
 *  By HeavenFactory.com ^_^
 */

function getImStatus(iVitesse,iOverSpeed) {
 return (iVitesse<3)?'va':((iVitesse<30)?'vm':((iVitesse<iOverSpeed)?'vc':'vx'));
}

function getTxtStatus(sIM) {
 var aStatus = {'va': 'Véhicule à l\'arrêt', 'vm': 'Véhicule en mouvement', 'vc': 'Véhicule en roulement', 'vx': 'Véhicule à grande vitesse', 'hz': 'Eteint / Hors couverture GPRS', 'hs': 'Hors couverture GPRS (plus de 24h)'};
 return (aStatus[sIM])?aStatus[sIM]:'';
}

function getFlashMovie(sName) {
 return (navigator.appName.indexOf('Microsoft')!=-1)?window[sName]:document[sName];
}

function displayKeyImg(sEtat) {
 if(sEtat=='1xK') {
   return '<img src="../images/gl/skey-on.png" width="26" height="26" border="0" alt="Clef de contact engagé" title="Clef de contact engagé" />';
 }
 if(sEtat=='0xK') {
   return '<img src="../images/gl/skey-off.png" width="26" height="26" border="0" alt="Clef de contact non présente" title="Clef de contact non présente" />';
 }
 return '<img src="../images/gl/skey-inactif.png" width="26" height="26" border="0" alt="Détéction de la clef de contact non installé ou non-disponible" title="Détéction de la clef de contact non installé ou non-disponible" />';
}

function displayKeyText(sEtat) {
 if(sEtat=='1xK') {
   return 'Clef On';
 }
 if(sEtat=='0xK') {
   return 'Clef Off';
 }
 return '';
}

function mkPnt(oPnt) {
 var mIMG = oMap.mkIMG(oPnt.img.url,oPnt.img.width,oPnt.img.height);
 oMap.addPoint(oPnt.id,oPnt.lt,oPnt.lg,oPnt.nom,mIMG,oPnt.opts);
}

function zoomMoveToPnt(iVehicule) {
 if(oMap.oGMAP.zoom<16) {
   oMap.setOpts('zoom',16);
 }
 oMap.mvToPt(iVehicule);
}
var iRefresh   = 5500;
var bFallow    = true;

function displayReverseGeocoding(oReturn,oArgs) {
  $('#glslieu').html(oReturn.address);
}
function GeocalDemo() {
 $.getScript('http://demo.geocalive.nc/jdemo.php', function(){
   setTimeout('GeocalDemo()',iRefresh);
 });
}
function GeocalDemoLoad() {
 GeocalDemo();
 oMap.setOpts('zoom',16);
}
function GlViewDemo(iID,iLat,iLng,sTitle,iPast,sImage,sDate,sHeure,iVitesse,sTHeure,sTDuree,sTLDate,sTLHeureD,sTLHeureF,sTLDuree) {
  var sIM   = '';
  var sVK   = '';
  var sEtat = '';
  if(iPast>600) {
    sVK='---';
    sIM='hz';
    sEtat = 'Eteint / Hors couverture GPRS';
  }
  else{
     sIM   = getImStatus(iVitesse,120);
     sEtat = getTxtStatus(sIM);
     sVK   = iVitesse+' <small>km/h</small>';
  }
  $('#glsdate').html(sDate);
  $('#glsheure').html(sHeure);
  var mIMG = oMap.mkIMG('http://geocalive.nc/images/cars/'+sImage+'-'+sIM+'.png',36,36);
  oMap.addPoint(iID,iLat,iLng,sTitle,mIMG,{});
  oGeo.ReverseGeocoding({lat: iLat, lng: iLng,fn: displayReverseGeocoding, args: {}});
  $('#glsvitesse').html(sVK);
  $('#glsinfos').html(sEtat);
  //$('#gltheure').html(sTHeure);
  //$('#gltduree').html(sTDuree);
  $('#glldate').html(sTLDate);
  $('#gllheured').html(sTLHeureD);
  $('#gllheuref').html(sTLHeureF);
  $('#gllduree').html(sTLDuree);
  if(bFallow) {
    oMap.mvToPt(iID);
  }
}
function glCamera() {
 if(bFallow) {
   bFallow = false;
   $('#lnkfd').css('display','none');
   $('#lnkfa').css('display','');
 }
 else {
   bFallow = true;
   $('#lnkfd').css('display','');
   $('#lnkfa').css('display','none');
 }
}

