﻿<!-- ======================================================================================================= -->
<!-- IPv6 monitoring test script This script is used to scientifically measure IPv4 and IPv6 capabilities of --> 
<!-- visitors to statistically determine IPv6 deployment in Europe.                                          -->
<!-- ======================================================================================================= -->

var __ipv6_test_objects=new Array();

function IPv6Test(site, code){
  this.site=site;
  this.code=code;
  this.timeoutMsec=10000;
  this.hostSuffix=".test.ipv6monitoring.eu";
  this.timeout=false;
  var now=new Date();
  this.test_time=now.getTime()+(now.getTimezoneOffset()*60000);
  this.test_id=Math.floor(Math.random()*Math.pow(2,31));
  __ipv6_test_objects[this.test_id]=this;
}

IPv6Test.prototype.setCookie=function(){
  var now=new Date();
  var expire=new Date(now.getTime()+86400000);
  document.cookie='ipv6test_last_run='+now.getTime()+';expires='+expire.toGMTString()+';path=/';
}

IPv6Test.prototype.checkCookie=function(){
  var a_all_cookies=document.cookie.split(';');
  for(i=0;i<a_all_cookies.length;i++){
    var a_temp_cookie=a_all_cookies[i].split('=');
    var cookie_name=a_temp_cookie[0].replace(/^\s+|\s+$/g,'');
    if(cookie_name=='ipv6test_last_run'){
      var cookie_value=unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g,''));
      var last_run=parseInt(cookie_value);
      if(isNaN(last_run)) return true;
      var now=new Date();
      return(last_run<(now.getTime()-86400000));
    }
  }
  return true;
}

IPv6Test.prototype.run=function(forced){
  if(!forced&&!this.checkCookie()) return;
  this.writeHtml();
  var oldonload=window.onload;
  var myself=this;
  window.onload=function(){
    if(typeof oldonload=='function') oldonload();
    myself.startTest();
  }
}

IPv6Test.prototype.writeHtml=function(){
  document.writeln('<div style="visibility: hidden;">');
  document.writeln('<img height="1" width="1" src="" id="__ipv6wwwtest_'+this.test_id+'_ipv4Img" />');
  document.writeln('<img height="1" width="1" src="" id="__ipv6wwwtest_'+this.test_id+'_ipv6Img" />');
  document.writeln('<img height="1" width="1" src="" id="__ipv6wwwtest_'+this.test_id+'_ipv4v6Img" />');
  document.writeln('</div>');
}

IPv6Test.prototype.startTest=function(){
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv4Img").src="http://ipv4"+this.hostSuffix+"/ipv6mon/testimg.php?site="+this.site+"&code="+this.code+"&time="+this.test_time+"&id="+this.test_id;
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv6Img").src="http://ipv6"+this.hostSuffix+"/ipv6mon/testimg.php?site="+this.site+"&code="+this.code+"&time="+this.test_time+"&id="+this.test_id;
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv4v6Img").src="http://v4v6"+this.hostSuffix+"/ipv6mon/testimg.php?site="+this.site+"&code="+this.code+"&time="+this.test_time+"&id="+this.test_id;
  this.timeout=window.setTimeout('__ipv6_test_objects['+this.test_id+'].cleanUp()',this.timeoutMsec);
}

IPv6Test.prototype.cleanUp=function(){
  if(this.timeout){
    window.clearTimeout(this.timeout);
  }
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv4Img").src="";
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv6Img").src="";
  document.getElementById("__ipv6wwwtest_"+this.test_id+"_ipv4v6Img").src="";
  this.setCookie();
}
