$.validator.unobtrusive.adapters.add('requireddependentregex',['siblingproperty','regexpattern'],function(options){var params={siblingproperty:options.params.siblingproperty,regexpattern:options.params.regexpattern};options.rules['requireddependentregex']=params;options.messages['requireddependentregex']=options.message?options.message:"Field is required";});$.validator.addMethod('requireddependentregex',function(value,elem,param){var siblingPropertyValue,regExp,match
var isNullOrWhiteSpace=function(string){if(!string)
return true;if($.trim(string)=="")
return true;return false;};var $siblingProperty=$('[name="'+param['siblingproperty']+'"], [name$=".'+param['siblingproperty']+'"]');if($siblingProperty.length>1)
siblingPropertyValue=$siblingProperty.filter(':checked, :selected').val();else
siblingPropertyValue=$siblingProperty.val();if(isNullOrWhiteSpace(param['regexpattern'])){if(isNullOrWhiteSpace(value)&&isNullOrWhiteSpace(siblingPropertyValue)){return false;}}else{regExp=new RegExp(param['regexpattern']);match=regExp.exec(siblingPropertyValue);if(match&&match[0]==siblingPropertyValue&&isNullOrWhiteSpace(value))
return false;}
return true;});;$.validator.unobtrusive.adapters.add('mustbetrue',function(options){options.rules['mustbetrue']=options.params;options.messages['mustbetrue']=options.message?options.message:"Field is required";});$.validator.addMethod('mustbetrue',function(value,elem,param){switch(elem.type){case "checkbox":return elem.checked;break;case "hidden":return(value.toLowerCase()=='true');break;default:return true;break;}});;$.validator.unobtrusive.adapters.add('requireatleastonecheckbox',['checkboxnames'],function(options){var params={checkboxnames:options.params.checkboxnames};options.rules['requireatleastonecheckbox']=params;options.messages['requireatleastonecheckbox']=options.message?options.message:"Field is required";});$.validator.addMethod('requireatleastonecheckbox',function(value,elem,param){var checkboxnames=param["checkboxnames"].split(',');for(i=0;i<checkboxnames.length;i++){var input=$('[name="'+checkboxnames[i]+'"]:checked, [name$=".'+checkboxnames[i]+'"]:checked');if(input.length>0){return true;}}
return false;});;(function($){$.widget('LandingPage.managedButton',{options:{validation:false},_create:function(){this.$errorDiv=$('<div class="form__error-summary padding-small"></div>');this.BindEvents();},_destroy:function(){},_setOption:function(key,value){},BindEvents:function(){var me=this;this.element.click(function(e){if($(this).hasClass('is-disabled')){e.preventDefault();return false;}
if(me.options.validation){if(!$(this).closest("form").valid()){return true;}}
me._ShowSpinnerAndDisableButton();return true;});},ShowErrorMessage:function(errorMessage){this._RemoveSpinner();this.$errorDiv.html('<p>'+errorMessage+'</p>');this.element.before(this.$errorDiv);},ShowSuccess:function(errorMessage){this._RemoveSpinner();this.RemoveErrorMessage();},RemoveErrorMessage:function(errorMessage){this.$errorDiv.remove();},_ShowSpinnerAndDisableButton:function(){this.RemoveErrorMessage();this.element.addClass('btn--waiting is-disabled');},_RemoveSpinner:function(){this.element.removeClass('btn--waiting is-disabled');}});})(window.jQuery);;(function($){$.widget("LocalBelgium.petitionForm",{options:{petitionSubmitBtnSelector:".jq_petitionFormButton",petitionFormWrapperSelector:".jq_petitionFormWrapper",petitionErrorSelector:".jq_petitionFormError",petitionerNumberSelector:"#jq_petitionerNumber",petitionSignaturesCounterSelector:"#jq_signaturesCounter"},_create:function(){this.BindEvents();},HandleResult:function(data,xhr,status){$(this.options.petitionFormWrapperSelector).html(data);$(this.options.petitionSubmitBtnSelector).managedButton("ShowSuccess");var count=$(data).find('#jq_petitionerNumber').html();$(this.options.petitionSignaturesCounterSelector).html(count);$(this.options.petitionToSignWrapper).hide();$(this.options.petitionAlreadySignedWrapper).show();},OnError:function(){$(this.options.petitionSubmitBtnSelector).managedButton("ShowErrorMessage",$(this.options.petitionErrorSelector).html());},BindEvents:function(){$(this.options.petitionSubmitBtnSelector).managedButton({validation:true});}});$.widget("LocalBelgium.petitionNewsletter",{options:{petitionNewsletterSubmitBtnClass:".jq_petitionNewsletterFormButton",petitionNewsletterWrapperClass:".jq_petitionNewsletterWrapper",petitionErrorSelector:".jq_petitionNewsletterError"},_create:function(){this.BindEvents();},HandleResult:function(data,xhr,status){$(this.options.petitionNewsletterWrapperClass).html(data);$(this.options.petitionNewsletterSubmitBtnClass).managedButton("ShowSuccess");},OnError:function(){$(this.options.petitionNewsletterSubmitBtnClass).managedButton("ShowErrorMessage",$(this.options.petitionErrorSelector).html());},BindEvents:function(){$(this.options.petitionNewsletterSubmitBtnClass).managedButton({validation:true});}});})(window.jQuery);;(function($){$.widget("LocalBelgium.insulationForm",{options:{formSubmitBtnSelector:".jq_formButton",formWrapperSelector:".jq_formWrapper",formErrorSelector:".jq_formError"},_create:function(){this.BindEvents();},HandleResult:function(data,xhr,status){this.CreateCookie($("#FormId").val(),1,120);$(this.options.formSignedWrapper).html(data);$(this.options.formToSignWrapper).hide();$(this.options.formSignedWrapper).show();},OnError:function(){$(this.options.formSubmitBtnSelector).managedButton("ShowErrorMessage",$(this.options.formErrorSelector).html());},BindEvents:function(){$(this.options.formSubmitBtnSelector).managedButton({validation:true});},CreateCookie:function(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();}
else{expires="";}
document.cookie=name+"="+value+expires+"; path=/";}});})(window.jQuery);;(function($){$.widget("LocalBelgium.internetSpeedTest",{options:{debugMode:false,updateInterval:100,donutSize:250,tests:['download','upload'],onTestDoneCallback:null,onTestProgressCallback:null,uploadMeterClass:'',downloadMeterClass:'',latencyClass:'',runButtonClass:'',statusClass:'',uploadProgressColor:'#4e967f',downloadProgressColor:'#4e7096',language:'eng',translations:{runTest:{eng:'Run Test',fr:'Démarrer le test',nl:'Doe de test'},idle:{eng:'Idle',fr:'En attente',nl:'Wachtend'},latency:{eng:'Latency: ',fr:'Latence: ',nl:'Latency: '},testingUploadSpeed:{eng:'Testing Upload speed...',fr:'Test de la vitesse d\'upload en cours...',nl:'Testen van de upload speed...'},uploadTestDone:{eng:'Upload test done.',fr:'Test de la vitesse d\'upload fait.',nl:'Testen van de upload speed voltooid.'},testingDownloadSpeed:{eng:'Testing Download speed...',fr:'Test de la vitesse de download en cours...',nl:'Testen van de download speed...'},downloadTestDone:{eng:'Download test done.',fr:'Test de la vitesse de download fait.',nl:'Testen van de download speed voltooid.'},allTestsDone:{eng:'All tests done.',fr:'Tous les tests sont finis.',nl:'Alle testen zijn voltooid.'}}},_vars:{client:null,status:'idle',s2cProcent:0,c2sProcent:0,remainingTests:[],currentTest:null,$uploadMeter:null,uploadProgress:null,$downloadMeter:null,downloadProgress:null,$latency:null,$runButton:null,$status:null},_create:function(){this._init_ndtBowserClient()._extend_ndtBowserClient()._init_progressDonut()._init_DOM().runTest();},_init_DOM:function(){var IST=this;$.extend(IST._vars,{$uploadMeter:$('<div id="internetspeed-meters-upload">').addClass('internetspeed-meter-wrapper').addClass(IST.options.uploadMeterClass),$downloadMeter:$('<div id="internetspeed-meters-download">').addClass('internetspeed-meter-wrapper').addClass(IST.options.downloadMeterClass),$latency:$('<div id="internetspeed-latency">').addClass(IST.options.latencyClass).html(IST.options.translations.latency[IST.options.language]),$runButton:$('<div id="internetspeed-run">').addClass(IST.options.runButtonClass).html(IST.options.translations.runTest[IST.options.language]).click(function(event){event.preventDefault();if(IST._vars.status==='idle'){IST.runTest();}}),$status:$('<div id="internetspeed-status">').addClass(IST.options.statusClass)});IST.element.append(IST._vars.$uploadMeter,IST._vars.$downloadMeter,IST._vars.$latency,IST._vars.$runButton,IST._vars.$status);return IST._reset();},_displayResults:function(results){if(this.testResults.latency>0)
this._vars.$latency.html(this.options.translations.latency[this.options.language]+this.testResults.latency.toFixed(3)+' ms');return this;},_serverCACHE:{'type':undefined,'answer':undefined,'all':undefined,},_findServer:function(metroSelection){var IST=this;var findDeferred=jQuery.Deferred();var temporaryCache,temporaryResponse;if(IST._serverCACHE.type===metroSelection&&IST._serverCACHE.answer!==undefined){if(IST._serverCACHE.all!==undefined){temporaryCache=IST._serverCACHE.all.filter(function(cachedResponse){return cachedResponse.metro===IST._serverCACHE.answer.metro;});temporaryResponse=temporaryCache[Math.floor(Math.random()*temporaryCache.length)];}else if(IST._serverCACHE.answer!==undefined){temporaryResponse=IST._serverCACHE.answer;}
findDeferred.resolve(temporaryResponse);}else{var mlabNsUrl='https://mlab-ns.appspot.com/ndt_ssl?format=json';if(metroSelection&&metroSelection!=="automatic"){mlabNsUrl='https://mlab-ns.appspot.com/ndt_ssl?format=json&policy=metro&metro='+metroSelection;}
IST._serverCACHE.type=metroSelection;$.get(mlabNsUrl).done(function(responseObject){responseObject.label=responseObject.city.replace('_',' ');responseObject.metro=responseObject.site.slice(0,3);IST._serverCACHE.answer=responseObject;findDeferred.resolve(responseObject);}).fail(function(data){findDeferred.reject(data);});}
return findDeferred.promise();},ndtBowserClient:null,_init_ndtBowserClient:function(){var NDTjs=function(server,serverPort,serverProtocol,serverPath,callbacks,updateInterval){this.server=server;this.serverPort=serverPort||3001;this.serverPath=serverPath||'/ndt_protocol';this.serverProtocol=serverProtocol||'ws';this.updateInterval=updateInterval/1000.0||false;this.results={c2sRate:undefined,s2cRate:undefined};this.SEND_BUFFER_SIZE=1048576;if(callbacks===undefined){this.callbacks={'onstart':function(){return false;},'onstatechange':function(){return false;},'onprogress':function(){return false;},'onfinish':function(){return false;},'onerror':function(){return false;},};}else{this.callbacks=callbacks;}
this.COMM_FAILURE=0;this.SRV_QUEUE=1;this.MSG_LOGIN=2;this.TEST_PREPARE=3;this.TEST_START=4;this.TEST_MSG=5;this.TEST_FINALIZE=6;this.MSG_ERROR=7;this.MSG_RESULTS=8;this.MSG_LOGOUT=9;this.MSG_WAITING=10;this.MSG_EXTENDED_LOGIN=11;this.NDT_MESSAGES=[];this.NDT_MESSAGES[this.COMM_FAILURE]='COMM_FAILURE';this.NDT_MESSAGES[this.SRV_QUEUE]='SRV_QUEUE';this.NDT_MESSAGES[this.MSG_LOGIN]='MSG_LOGIN';this.NDT_MESSAGES[this.TEST_PREPARE]='TEST_PREPARE';this.NDT_MESSAGES[this.TEST_START]='TEST_START';this.NDT_MESSAGES[this.TEST_MSG]='TEST_MSG';this.NDT_MESSAGES[this.TEST_FINALIZE]='TEST_FINALIZE';this.NDT_MESSAGES[this.MSG_ERROR]='MSG_ERROR';this.NDT_MESSAGES[this.MSG_RESULTS]='MSG_RESULTS';this.NDT_MESSAGES[this.MSG_LOGOUT]='MSG_LOGOUT';this.NDT_MESSAGES[this.MSG_WAITING]='MSG_WAITING';this.NDT_MESSAGES[this.MSG_EXTENDED_LOGIN]='MSG_EXTENDED_LOGIN';}
NDTjs.prototype.logger=function(logMessage,debugging){debugging=debugging||false;if(debugging===true){}};NDTjs.prototype.checkBrowserSupport=function(){if(self.WebSocket===undefined&&self.MozWebSocket===undefined){throw this.UnsupportedBrowser('No Websockets');}
return true;};NDTjs.prototype.makeLoginMessage=function(desiredTests){var i,loginMessage='XXX { "msg": "v3.5.5", "tests": "'+(desiredTests|16)+
'" }',loginData=new Uint8Array(loginMessage.length);loginData[0]=this.MSG_EXTENDED_LOGIN;loginData[1]=0;loginData[2]=loginMessage.length-3;for(i=3;i<loginMessage.length;i+=1){loginData[i]=loginMessage.charCodeAt(i);}
return loginData;};NDTjs.prototype.makeNdtMessage=function(messageType,messageContent){var messageBody,ndtMessage,i;messageBody='{ "msg": "'+messageContent+'" } ';ndtMessage=new Uint8Array(messageBody.length+3);ndtMessage[0]=messageType;ndtMessage[1]=(messageBody.length>>8)&0xFF;ndtMessage[2]=messageBody.length&0xFF;for(i=0;i<messageBody.length;i+=1){ndtMessage[i+3]=messageBody.charCodeAt(i);}
return ndtMessage;};NDTjs.prototype.parseNdtMessage=function(buffer){var i,response=[],bufferArray=new Uint8Array(buffer),message=String.fromCharCode.apply(null,new Uint8Array(buffer.slice(3)));for(i=0;i<3;i+=1){response[i]=bufferArray[i];}
response.push(message);return response;};NDTjs.prototype.ConnectionException=function(message){this.logger(message);this.callbacks.onerror(message);};NDTjs.prototype.UnsupportedBrowser=function(message){this.logger(message);this.callbacks.onerror(message);};NDTjs.prototype.TestFailureException=function(message){this.logger(message);this.callbacks.onerror(message);};NDTjs.prototype.createWebsocket=function(serverProtocol,serverAddress,serverPort,urlPath,protocol){var createdWebsocket=new WebSocket(serverProtocol+'://'+
serverAddress+':'+serverPort+
urlPath,protocol);createdWebsocket.binaryType='arraybuffer';return createdWebsocket;};NDTjs.prototype.ndtC2sTest=function(){var serverPort,testConnection,testStart,i,dataToSend=new Uint8Array(this.SEND_BUFFER_SIZE),that=this,state='WAIT_FOR_TEST_PREPARE',totalSent=0,nextCallback=that.updateInterval,keepSendingData;for(i=0;i<dataToSend.length;i+=1){dataToSend[i]=32+(i*101)%(126-32);}
keepSendingData=function(){var currentTime=Date.now()/1000.0;if(testConnection.readyState>0){if(testConnection.bufferedAmount<8192){testConnection.send(dataToSend);totalSent+=dataToSend.length;}
if(that.updateInterval&&currentTime>(testStart+nextCallback)){that.results.c2sRate=8*(totalSent-testConnection.bufferedAmount)/1000/(currentTime-testStart);that.callbacks.onprogress('interval_c2s',that.results);nextCallback+=that.updateInterval;currentTime=Date.now()/1000.0;}}
if(currentTime<testStart+10){setTimeout(keepSendingData,0);}else{if(totalSent===0)
that.callbacks.onerror('error_c2s','COULD_NOT_CONNECT_TO_SERVER');return false;}};return function(messageType,messageContent){that.logger('CALLED C2S with '+messageType+' ('+
that.NDT_MESSAGES[messageType]+') '+messageContent.msg+
' in state '+state);if(state==='WAIT_FOR_TEST_PREPARE'&&messageType===that.TEST_PREPARE){that.callbacks.onstatechange('preparing_c2s',that.results);serverPort=Number(messageContent.msg);testConnection=that.createWebsocket(that.serverProtocol,that.server,serverPort,that.serverPath,'c2s');state='WAIT_FOR_TEST_START';return false;}
if(state==='WAIT_FOR_TEST_START'&&messageType===that.TEST_START){that.callbacks.onstatechange('running_c2s',that.results);testStart=Date.now()/1000;keepSendingData();state='WAIT_FOR_TEST_MSG';return false;}
if(state==='WAIT_FOR_TEST_MSG'&&messageType===that.TEST_MSG){that.results.c2sRate=Number(messageContent.msg);that.logger('C2S rate calculated by server: '+that.results.c2sRate);state='WAIT_FOR_TEST_FINALIZE';return false;}
if(state==='WAIT_FOR_TEST_FINALIZE'&&messageType===that.TEST_FINALIZE){that.callbacks.onstatechange('finished_c2s',that.results);state='DONE';return true;}
that.logger('C2S: State = '+state+' type = '+messageType+'('+
that.NDT_MESSAGES[messageType]+') message = ',messageContent);};};NDTjs.prototype.ndtS2cTest=function(ndtSocket){var serverPort,testConnection,testStart,testEnd,errorMessage,state='WAIT_FOR_TEST_PREPARE',receivedBytes=0,nextCallback=this.updateInterval,that=this;return function(messageType,messageContent){that.logger('CALLED S2C with '+messageType+' ('+
that.NDT_MESSAGES[messageType]+') in state '+state);if(state==='WAIT_FOR_TEST_PREPARE'&&messageType===that.TEST_PREPARE){that.callbacks.onstatechange('preparing_s2c',that.results);serverPort=Number(messageContent.msg);testConnection=that.createWebsocket(that.serverProtocol,that.server,serverPort,that.serverPath,'s2c');testConnection.onopen=function(){that.logger('Successfully opened S2C test connection.');testStart=Date.now()/1000;};testConnection.onmessage=function(response){var hdrSize,currentTime;if(response.data.byteLength<126){hdrSize=2;}else if(response.data.byteLength<65536){hdrSize=4;}else{hdrSize=10;}
receivedBytes+=(hdrSize+response.data.byteLength);currentTime=Date.now()/1000.0;if(that.updateInterval&&currentTime>(testStart+nextCallback)){that.results.s2cRate=8*receivedBytes/1000/(currentTime-testStart);that.callbacks.onprogress('interval_s2c',that.results);nextCallback+=that.updateInterval;}};testConnection.onerror=function(response){errorMessage=that.parseNdtMessage(response.data)[3].msg;throw that.TestFailureException(errorMessage);};state='WAIT_FOR_TEST_START';return false;}
if(state==='WAIT_FOR_TEST_START'&&messageType===that.TEST_START){that.callbacks.onstatechange('running_s2c',that.results);state='WAIT_FOR_FIRST_TEST_MSG';return false;}
if(state==='WAIT_FOR_FIRST_TEST_MSG'&&messageType===that.TEST_MSG){that.logger('Got message: '+JSON.stringify(messageContent));state='WAIT_FOR_TEST_MSG_OR_TEST_FINISH';if(testEnd===undefined){testEnd=Date.now()/1000;}
that.results.s2cRate=8*receivedBytes/1000/(testEnd-testStart);that.logger('S2C rate calculated by client: '+that.results.s2cRate);that.logger('S2C rate calculated by server: '+
messageContent.ThroughputValue);ndtSocket.send(that.makeNdtMessage(that.TEST_MSG,String(that.results.s2cRate)));return false;}
if(state==='WAIT_FOR_TEST_MSG_OR_TEST_FINISH'&&messageType===that.TEST_MSG){var web100Record=messageContent.msg.split(': '),web100Variable=web100Record[0],web100Result=web100Record[1].trim();that.results[web100Variable]=web100Result;return false;}
if(state==='WAIT_FOR_TEST_MSG_OR_TEST_FINISH'&&messageType===that.TEST_FINALIZE){that.callbacks.onstatechange('finished_s2c',that.results);that.logger('NDT S2C test is complete: '+messageContent.msg);return true;}
that.logger('S2C: State = '+state+' type = '+messageType+'('+
that.NDT_MESSAGES[messageType]+') message = ',messageContent);};};NDTjs.prototype.ndtMetaTest=function(ndtSocket){var errorMessage,that=this,state='WAIT_FOR_TEST_PREPARE';return function(messageType,messageContent){if(state==='WAIT_FOR_TEST_PREPARE'&&messageType===that.TEST_PREPARE){that.callbacks.onstatechange('preparing_meta',that.results);state='WAIT_FOR_TEST_START';return false;}
if(state==='WAIT_FOR_TEST_START'&&messageType===that.TEST_START){that.callbacks.onstatechange('running_meta',that.results);ndtSocket.send(that.makeNdtMessage(that.TEST_MSG,'client.os.name:NDTjs'));ndtSocket.send(that.makeNdtMessage(that.TEST_MSG,''));state='WAIT_FOR_TEST_FINALIZE';return false;}
if(state==='WAIT_FOR_TEST_FINALIZE'&&messageType===that.TEST_FINALIZE){that.callbacks.onstatechange('finished_meta',that.results);that.logger('NDT META test complete.');return true;}
errorMessage='Bad state and message combo for META test: '+
state+', '+messageType+', '+messageContent.msg;throw that.TestFailureException(errorMessage);};};NDTjs.prototype.startTest=function(){var ndtSocket,activeTest,state,errorMessage,i,testsToRun=[],that=this;this.checkBrowserSupport();this.logger('Test started.  Waiting for connection to server...');this.callbacks.onstart(this.server);ndtSocket=this.createWebsocket(this.serverProtocol,this.server,this.serverPort,this.serverPath,'ndt');ndtSocket.onopen=function(){that.logger('Opened connection on port '+that.serverPort);ndtSocket.send(that.makeLoginMessage(2|4|32));state='LOGIN_SENT';};ndtSocket.onmessage=function(response){var tests,message=that.parseNdtMessage(response.data),messageType=message[0],messageContent=JSON.parse(message[3]);that.logger('type = '+messageType+' ('+
that.NDT_MESSAGES[messageType]+') body = "'+
messageContent.msg+'"');if(activeTest===undefined&&testsToRun.length>0){activeTest=testsToRun.pop();}
if(activeTest!==undefined){that.logger('Calling a subtest');if(activeTest(messageType,messageContent)===true){activeTest=undefined;that.logger('Subtest complete');}
return;}
if(state==='LOGIN_SENT'){if(messageType===that.SRV_QUEUE){if(messageContent.msg==='9990'){ndtSocket.send(that.makeNdtMessage(that.MSG_WAITING,''));}else if(messageContent.msg==='9977'){throw that.TestFailureException('Server terminated test '+
'with SRV_QUEUE 9977');}
that.logger('Got SRV_QUEUE. Ignoring and waiting for '+
'MSG_LOGIN.');}else if(messageType===that.MSG_LOGIN){if(messageContent.msg[0]!=='v'){that.logger('Bad msg '+messageContent.msg);}
state='WAIT_FOR_TEST_IDS';}else{errorMessage='Expected type 1 (SRV_QUEUE) or 2 (MSG_LOGIN)'+
'but got '+messageType+' ('+
that.NDT_MESSAGES[messageType]+')';throw that.TestFailureException(errorMessage);}}else if(state==='WAIT_FOR_TEST_IDS'&&messageType===that.MSG_LOGIN){tests=messageContent.msg.split(' ');for(i=tests.length-1;i>=0;i-=1){if(tests[i]==='2'){testsToRun.push(that.ndtC2sTest());}else if(tests[i]==='4'){testsToRun.push(that.ndtS2cTest(ndtSocket));}else if(tests[i]==='32'){testsToRun.push(that.ndtMetaTest(ndtSocket));}else if(tests[i]!==''){errorMessage='Unknown test type: '+tests[i];throw that.TestFailureException(errorMessage);}}
state='WAIT_FOR_MSG_RESULTS';}else if(state==='WAIT_FOR_MSG_RESULTS'&&messageType===that.MSG_RESULTS){that.logger(messageContent);var lines=messageContent.msg.split('\n');for(i=0;i<lines.length;i++){var line=lines[i];var record=line.split(': ');var variable=record[0];var result=record[1];that.results[variable]=result;}}else if(state==='WAIT_FOR_MSG_RESULTS'&&messageType===that.MSG_LOGOUT){ndtSocket.close();that.callbacks.onstatechange('finished_all',that.results);that.callbacks.onfinish(that.results);that.logger('All tests successfully completed.');}else{errorMessage='No handler for message '+messageType+
' in state '+state;throw that.TestFailureException(errorMessage);}};ndtSocket.onerror=function(response){errorMessage=that.parseNdtMessage(response.data)[3].msg;throw that.TestFailureException(errorMessage);};};this.ndtBowserClient=NDTjs;return this;},_extend_ndtBowserClient:function(){var IST=this;IST.ndtBowserClient.prototype.initial_logger=IST.ndtBowserClient.prototype.logger;IST.ndtBowserClient.prototype.logger=function(logMessage,debugging){this.initial_logger(logMessage,IST.options.debugMode);};IST.ndtBowserClient.prototype.initial_makeLoginMessage=IST.ndtBowserClient.prototype.makeLoginMessage;IST.ndtBowserClient.prototype.makeLoginMessage=function(desiredTests){if(IST._vars.currentTest==="upload")
desiredTests=2;if(IST._vars.currentTest==="download")
desiredTests=4;return this.initial_makeLoginMessage(desiredTests);};return IST;},_ndtClientOptions:{port:'https:'==location.protocol?3010:3001,protocol:'https:'==location.protocol?'wss':'ws',path:'/ndt_protocol'},_ndtClientCallbacks:function(){var IST=this;return{'onstart':function(server){},'onstatechange':function(state,results){if(state==='running_s2c'){var intervalDownload=setInterval(function(){IST.testResults.download=results&&results['s2cRate']?results['s2cRate']/1000:0;IST._vars.downloadProgress.progress(IST._vars.s2cProcent,IST.testResults.download.toFixed(3).replace('\.',',')+' Mbps');if(IST._vars.s2cProcent>=100)
clearInterval(intervalDownload);else
IST._vars.s2cProcent=IST._vars.s2cProcent+(IST.options.updateInterval/100)},IST.options.updateInterval)
IST._vars.$status.html(IST.options.translations.testingDownloadSpeed[IST.options.language]);}
if(state==='finished_s2c')
IST._vars.$status.html(IST.options.translations.downloadTestDone[IST.options.language]);if(state==='running_c2s'){var intervalUpload=setInterval(function(){IST.testResults.upload=results&&results['c2sRate']?results['c2sRate']/1000:0;IST._vars.uploadProgress.progress(IST._vars.c2sProcent,IST.testResults.upload.toFixed(3).replace('\.',',')+' Mbps');if(IST._vars.c2sProcent>=100)
clearInterval(intervalUpload);else
IST._vars.c2sProcent=IST._vars.c2sProcent+(IST.options.updateInterval/100)},IST.options.updateInterval)
IST._vars.$status.html(IST.options.translations.testingUploadSpeed[IST.options.language]);}
if(state=='finished_c2s')
IST._vars.$status.html(IST.options.translations.uploadTestDone[IST.options.language]);},'onprogress':function(state,results){if(IST.options.onTestProgressCallback&&$.type(IST.options.onTestProgressCallback)==='function')
IST.options.onTestProgressCallback.call();},'onfinish':function(passed_results){if(IST._vars.currentTest==="download"){IST.testResults.latency=passed_results['SumRTT']/passed_results['CountRTT'];}
if(IST._vars.currentTest==="upload"){}
if(IST._vars.remainingTests.length>0){IST._selectAndRunTest();return;}
IST._displayResults();IST._vars.status='idle';IST._vars.$status.html(IST.options.translations.allTestsDone[IST.options.language]);if(IST.options.onTestDoneCallback&&$.type(IST.options.onTestDoneCallback)==='function')
IST.options.onTestDoneCallback.call(undefined,passed_results);},'onerror':function(error_message){}};},_visuals:{progressDonut:null,},_init_progressDonut:function(){var IST=this,progressDonut=function(container,options){var _this=this;_this.options=$.extend({size:200,title:'Title',progressColor:'#1abc9c',titleColor:'#bdc3c7',textColor:'#000',textFont:'Calibri, Verdana, sans-serif'},options);_this._$elements={$container:$(container),$wrapper:null,$content:null,$label:null,$title:null,$donut:null,$halfcircleLeft:null,$halfcircleRight:null,$shadow:null};return _this._initialize();};progressDonut.prototype._initialize=function(){return this._initDOM()._initCSS();};progressDonut.prototype._initDOM=function(){var _this=this;_this._$elements.$wrapper=$('<div>').addClass('progressdonut-wrapper').appendTo(_this._$elements.$container);_this._$elements.$content=$('<div>').addClass('progressdonut-content').appendTo(_this._$elements.$wrapper);_this._$elements.$label=$('<div>').addClass('progressdonut-content-label').text('0 Mbps').appendTo(_this._$elements.$content);_this._$elements.$title=$('<div>').addClass('progressdonut-content-title').text(_this.options.title).appendTo(_this._$elements.$content);_this._$elements.$donut=$('<div>').addClass('progressdonut-donut').appendTo(_this._$elements.$wrapper);_this._$elements.$halfcircleLeft=$('<div>').addClass('progressdonut-halfcircle progressdonut-halfcircle-left').appendTo(_this._$elements.$donut);_this._$elements.$halfcircleRight=$('<div>').addClass('progressdonut-halfcircle progressdonut-halfcircle-right').appendTo(_this._$elements.$donut);_this._$elements.$shadow=$('<div>').addClass('progressdonut-shadow').appendTo(_this._$elements.$wrapper);return _this;};progressDonut.prototype._initCSS=function(){var _this=this;_this._$elements.$container.css({'font-size':_this.options.size+'px'});_this._$elements.$wrapper.css({'position':'relative','width':'1em','height':'1em','margin':'0px auto','overflow':'hidden'});_this._$elements.$content.css({'position':'absolute','top':'0.4em','right':'0em','bottom':'0em','left':'0em','width':'1em','margin':'auto','z-index':'2'});_this._$elements.$label.css({'font-family':_this.options.textFont,'color':_this.options.textColor,'font-size':'0.1em','width':_this.options.size+'px','text-align':'center','cursor':'default'});_this._$elements.$title.css({'font-family':_this.options.textFont,'font-weight':'bold','text-transform':'uppercase','color':_this.options.titleColor,'font-size':'0.1em','width':_this.options.size+'px','text-align':'center','cursor':'default'});_this._$elements.$donut.css({'position':'absolute','top':'0px','left':'0px','width':'1em','height':'1em','clip':'rect(0, 1em, 1em, 0.5em)'});_this._$elements.$halfcircleLeft.add(_this._$elements.$halfcircleRight).css({'position':'absolute','top':'0px','left':'0px','width':'0.8em','height':'0.8em','border':'0.1em solid '+_this.options.progressColor,'border-radius':'50%','clip':'rect(0em, 0.5em, 1em, 0em)','transform':'rotate(0deg)'});_this._$elements.$shadow.css({'width':'0.8em','height':'0.8em','border':'0.1em solid #BDC3C7','border-radius':'50%'});return _this;};progressDonut.prototype.progress=function(percent,text){var _this=this;percent=Math.round(percent);if(percent>100)
percent=100;if(percent<0)
percent=0;var deg=Math.round(360*(percent/100));if(percent>50){_this._$elements.$donut.css('clip','rect(auto, auto, auto, auto)');_this._$elements.$halfcircleRight.css('transform','rotate(180deg)');}
else{_this._$elements.$donut.css('clip','rect(0, 1em, 1em, 0.5em)');_this._$elements.$halfcircleRight.css('transform','rotate(0deg)');}
text=text||percent;_this._$elements.$label.text(text);_this._$elements.$halfcircleLeft.css('transform','rotate('+deg+'deg)');};IST._visuals.progressDonut=progressDonut;return IST;},_reset:function(){var IST=this;for(var index in IST.testResults){IST.testResults[index]=null;}
IST._vars.currentTest=null;IST._vars.remainingTests=[];IST._vars.c2sProcent=0;IST._vars.s2cProcent=0;IST._vars.$uploadMeter.empty();IST._vars.$downloadMeter.empty();IST._vars.uploadProgress=new IST._visuals.progressDonut(IST._vars.$uploadMeter,{size:IST.options.donutSize,title:'Upload',titleColor:'#1abc9c',progressColor:'#1abc9c'});IST._vars.downloadProgress=new IST._visuals.progressDonut(IST._vars.$downloadMeter,{size:IST.options.donutSize,title:'Download',titleColor:'#4f67a3',progressColor:'#4f67a3'});return IST;},_selectAndRunTest:function(){var IST=this,allTestDone=false;if(IST._vars.currentTest==null)
IST._vars.remainingTests=IST.options.tests.slice();if(IST._vars.remainingTests.length>0){IST._vars.currentTest=IST._vars.remainingTests.shift();IST._vars.client.startTest();}
else{IST._vars.currentTest=null;}},testResults:{upload:0,download:0,latency:0},status:function(){return this._vars.status;},runTest:function(){var IST=this;IST._vars.status='running';IST._reset()._findServer().then(function(){IST._vars.client=new IST.ndtBowserClient(IST._serverCACHE.answer.fqdn,IST._ndtClientOptions.port,IST._ndtClientOptions.protocol,IST._ndtClientOptions.path,IST._ndtClientCallbacks(),IST.options.updateInterval);IST._selectAndRunTest();});},});})(window.jQuery);;