
// encode qui provient de function.js
function encode( strValue )
{
	var strReturnValue;

	if( strValue == "" || strValue == null )	
		return "";

	try
	{
		var strReturnValue = encodeURIComponent( strValue );
		strReturnValue = strReturnValue.replace( /'/g, "%27" );
	}
	catch(e)
	{
		strReturnValue = escape( strValue );
	}
	return strReturnValue;
}

// Gestion des cookies
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value)
{
var c_value=escape(value);
document.cookie=c_name + "=" + c_value;
}

function SqueereHTTP(url, instance)
{
   this.loaded = false;
   this.url=url;
   this.script;
   this.firstparam=true;
   this.serverResponse;
   this.instance=instance;
   that=this;
   

   this.AddParam = function(p, v) {
	  if (that.firstparam) {
		 that.url+='?'+p+'='+v;
		 that.firstparam=false;
	  } else {
		 that.url+='&'+p+'='+v;
	  }
   }

   this.Request = function(force) {
	  that.AddParam('instance', that.instance);
	  if (force) {
		 var axd = new Date();
		 var shake = axd.getDate()+""+axd.getMonth()+1+""+axd.getFullYear()+""+axd.getHours()+""+axd.getMinutes()+""+axd.getSeconds();
		 that.AddParam('squeereshaker', shake);
	  }
	  that.script = document.createElement('script');
	  that.script.setAttribute('charset','UTF-8');
	  that.script.setAttribute('type','text/javascript');
	  that.script.setAttribute('src', that.url);
	  that.script.onload = that.onLoad;
	  that.script.onreadystatechange = that.onLoad;
	  document.getElementsByTagName('head')[0].appendChild(that.script);
   }

   this.onComplete = function(serverResponse) { }

   this.onLoad = function() {
	  if (that.loaded) { return; }
	  that.loaded=true;
   };

   return this;
}



var strNavigator = encode(navigator.userAgent);
var strIdEudoWebSite = "0";

if (document.cookie.indexOf("EudowebSite") != -1 && getCookie("EudowebSite") != "")
{
	strIdEudoWebSite = getCookie("EudowebSite");
}

var myReq;

var strURL = 'http://www.eudoweb.com/websiteconnectionstats/default.aspx';
// var strURL = 'http://localhost:53643/Default.aspx';
//alert(strURL);
myReq = new SqueereHTTP(strURL, 'myReq');

myReq.AddParam('a', encode(document.referrer));
myReq.AddParam('b', encode(document.URL));
myReq.AddParam('c', strNavigator);
myReq.AddParam('d', 'false');
myReq.AddParam('e', strIdEudoWebSite);


// var strNewId;
// myReq.onComplete = function(serverResponse)
// {
	// alert(serverResponse);
	// strNewId = serverResponse;
// }

myReq.Request(true);


window.onunload = function(){
	var oldonunload = window.onload;  
	
	if(oldonunload)
		 oldonunload();  
		
	UnLoad();
	}

function UnLoad()
{
	myReq2 = new SqueereHTTP(strURL, 'myReq2');

	myReq2.AddParam('a', encode(document.referrer));
	myReq2.AddParam('b', encode(document.URL));
	myReq2.AddParam('c', strNavigator);
	myReq2.AddParam('d', 'true');
	myReq2.AddParam('e', strIdEudoWebSite);
	
	// myReq2.onComplete = function(serverResponse)
	// {
		// alert(serverResponse);
		// strNewId = serverResponse;
	// }
	
	myReq2.Request(true);

	

}


