function deviceProtocol(){this.currentLogin=null;this.idUserServer=null;this.identifierDevice=null;this.idDevice=null;this.currentRequest=null;var a=this,b=0;this.login=function(a,c){this.currentLogin=a;var d=plateformePrefix+"0,0,LGI,DEVICE,0.1.0;",b=d+a+";"+c+",,,,,,0,"+processDate()+"N00000000E00000000000000000000000.0";this.httpPost(b,this.processResponse)};this.loginCreate=function(a,c,e){this.currentLogin=a;var d=plateformePrefix+"0,0,LGC,DEVICE,",b=d+mbdVersion+";"+a+";"+c+";"+e+";"+global.userLanguage+",,,,,,0,"+processDate()+"N00000000E00000000000000000000000.0";this.httpPost(b,this.processResponse)};this.processResponse=function(b){if(b.charCodeAt(b.length-1)==10)b=b.substring(0,b.length-1);var c=b.split(","),d=c[3];if(d!="OK")alert(identificationError);else{a.idUserServer=c[4];a.identifierDevice=c[5];gDbHelper.getDevice(a.idUserServer,a.checkExist)}login_localisation()};this.checkExist=function(b){if(b.rows.length>0){a.idDevice=b.rows.item(0).IdDevice;gDbHelper.connectDevice(a.idDevice,a.idUserServer);updatePage()}else gDbHelper.addDevice(a.currentLogin,a.idUserServer,a.identifierDevice,1,a.addDeviceSuccess,a.addDeviceError)};this.addDeviceSuccess=function(b){a.idDevice=b.insertId;gDbHelper.connectDevice(a.idDevice,a.idUserServer);updatePage()};this.addDeviceError=function(){alert("Enregistrement device erreur")};this.sendSpo=function(){var a=plateformePrefix+this.identifierDevice+",0,SPO,DEVICE,"+this.currentRequest.guid+";"+this.currentRequest.type+",,,,,,0,"+processDate()+"N00000000E00000000000000000000000.0";this.httpPost(a,this.processResponceSpo)};this.sendWpt=function(){if(b<this.currentRequest.arrayPositions.length){var a=this.currentRequest.arrayPositions[b];if(a.toSave&&a.isWaypoint){var c=plateformePrefix+this.identifierDevice+",0,POI,DEVICE,WPT,,,,,9,1,"+processDate(a.timestamp)+toDegrees(a)+toKnots(a)+processHeading(a)+processAltitude(a)+"00"+processAccuracy(a);this.httpPost(c,this.processResponceWpt)}else this.implementIndice()}else{b=0;this.sendTrace(this.processResponceTrace)}};this.sendTrace=function(f){var b=[];for(indice in this.currentRequest.arrayPositions){var a=this.currentRequest.arrayPositions[indice];if(a.toSave){var e=processDate(a.timestamp)+toDegrees(a)+toKnots(a)+processHeading(a)+processAltitude(a)+"00"+processAccuracy(a);b.push(e)}}var c=plateformePrefix+this.identifierDevice+",0,UPL,DEVICE,RAW,,,,,,0,"+processDate()+'N00000000E00000000000000000000000.0,<UPL mode="SPO" type="'+this.currentRequest.type+'" name="'+this.currentRequest.name+'" GUID="'+this.currentRequest.guid+'" timer_session="'+this.currentRequest.chrono.getTotalSecondes()+'" distance_session="'+this.currentRequest.getDistance()+'" denivpos_session="'+this.currentRequest.getPosDenivellation()+'" denivneg_session="'+this.currentRequest.getNegDenivellation()+'">';if(b.length>1)for(var d=0;d<b.length-1;d++)c+=b[d]+";";c+=b[b.length-1];c+="</UPL>";this.httpPost(c,f)};this.sendEnd=function(){var a=plateformePrefix+this.identifierDevice+",0,STO,DEVICE,SPO;"+this.currentRequest.guid+",,,,,,0,"+processDate()+"N00000000E00000000000000000000000.0";this.httpPost(a,this.processResponceEnd)};this.traceUpload=function(a,b,c){this.currentRequest=a;if(b)this.sendTrace(this.processResponceTraceHistory);else this.sendSpo();c(a)};this.poiSynchro=function(){};this.httpPost=function(b,a){xmlhttpPost("./HttpPost/DeviceComm.aspx",b,a)};this.processResponceTrace=function(b){if(b.charCodeAt(b.length-1)==10)b=b.substring(0,b.length-1);a.sendEnd()};this.processResponceTraceHistory=function(a){if(a.charCodeAt(a.length-1)==10)a=a.substring(0,a.length-1)};this.processResponceSpo=function(b){if(b.charCodeAt(b.length-1)==10)b=b.substring(0,b.length-1);a.sendWpt()};this.processResponceWpt=function(c){if(c.charCodeAt(c.length-1)==10)c=c.substring(0,c.length-1);b+=1;a.sendWpt()};this.implementIndice=function(){b+=1;a.sendWpt()};this.processResponceEnd=function(a){if(a.charCodeAt(a.length-1)==10)a=a.substring(0,a.length-1);this.currentRequest=null}}
