({
	name:"Cookie",
	set:function(n,v,c,dm){var d,e,domain="";if(dm){domain="domain="+dm;}if(c){d=new Date();d.setTime(d.getTime()+c*24*60*60*1000);e="; expires="+d.toGMTString()}document.cookie=escape(n)+"="+v+e+"; path=/;"+domain},
	get:function(n){var e,b,p,c=document.cookie;p=n+"=";b=c.indexOf(";"+" "+p);if(b==-1){b=c.indexOf(p);if(b!=0)return ""}else b+=2;e=c.indexOf(";",b);if(e==-1)e=c.length;return unescape(c.substring(b+p.length,e))},
	unset:function(n){return this.set(n,"",1,"")},
	init:function(){window[this.name]=this}
}).init();

// 	Generates Guid - Global Unique Identifier
function __newGuid(){
    var g = "";
    for(var i = 0; i < 32; i++)
    	g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
    return g;
};

function _onunload() {
	Cookie.unset("ca_cat_sent");
};
window.attachEvent ? window.attachEvent("onbeforeunload", _onunload) : window.addEventListener("unload", _onunload, false);

//	wrapping object
var adaptMA = {};

// 	Generates Guid - Global Unique Identifier
adaptMA.__newGuid = function ()
{
    var g = "";
    for(var i = 0; i < 32; i++)
    	g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
    return g;
};

adaptMA.__sendRequest = function (url)
{
	var bearer = new Image();
	bearer.src = url;
	setTimeout( function() {
			if (!bearer.complete) {
				bearer = null;
				return;
			}
		}
		, 5000);
};

adaptMA.start = function ()
{
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
		document.cookie = "testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}
	if (!cookieEnabled) return;
	
	//	config values
    
	var _cid = 'user_carnegie';
	var _cdomain = "carnegie.se";
	var _cpath = "/";
    var _aid = 'carnegie';

	//	server-load control
	var _peload = 100;
	var _maloadprob=Math.floor(Math.random()*101);
	if (_maloadprob > _peload) return;

	//	processing cookie
	var now = new Date();
	var exp_date = new Date(Date.UTC(now.getUTCFullYear()+1, now.getUTCMonth(), now.getUTCDate()));
	
	if (Cookie.get("ca_cat_sent")) {		
		return;
	} else {
		Cookie.set("ca_cat_sent", "is_set", 1);
	}
	
	var url  = 'http://pec3.adaptlogic.com/Adapt-0.1/adapt/markAction?user=server_cookie&customer=' + _aid + '&category=edge';
	adaptMA.__sendRequest(url);
};

//	This is entry-point
adaptMA.start();
