////encode
/// <reference path="../cookies/global.js"/>
/// <reference path="../base32/global.js"/>

function DeviceProfile()
{
    this.ScreenPixelsWidth=screen.width;
    this.ScreenPixelsHeight=screen.height;
    this.ScreenBitDepth=screen.colorDepth;
    this.FontSmoothingEnabled=screen.fontSmoothingEnabled;
    this.Cookies=(navigator.cookieEnabled)? true : false;

    //Flash Detection
    this.Flash={};
    this.Flash.isInstalled = function()
    {
        var i,x;
        this.Version=0;
        if (navigator.plugins && navigator.plugins.length > 0)
        {
	        var plugin = navigator.plugins['Shockwave Flash'];
	        if (plugin)
	        {
		        var words = plugin.description.split(' ');
		        for (var i = 0; i < words.length; ++i)
		        {
			        if (isNaN(parseInt(words[i])))
			        continue;
                    this.Version = words[i];
		        }
                if (this.Version >= 0);
		        {
			        var numTypes = plugin.length;
			        var FlashMode;
			        for (j = 0; j < numTypes; j++) 
			        {
				        mimetype = plugin[j];
				        if (mimetype)
				        {
					        if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf('swf') != -1))
						        FlashMode = true;
                            // Mac wierdness
					        if (navigator.mimeTypes['application/x-shockwave-flash'] == null)
						        FlashMode = false;
				        }
			        }
			        if(!FlashMode)
			        {
                        this.Version = 0;
			        }
		        }
	        }
        }
        else
        {
            for(i=1;i<10;i++)
            {
                try
                {
	                x = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.'+i);
                    if (x){this.Version=i}
                }
                catch(error){}
            }
        }
    };
    this.Flash.isInstalled();    

    //Silverlight Detection
    this.Silverlight={};
    this.Silverlight.isInstalled = function() {
        var c = false, a = null, v = 0;
        try {
            var b = null;
            if (!navigator.plugins || navigator.plugins.length == 0)
                b = new ActiveXObject('AgControl.AgControl');
            else if (navigator.plugins['Silverlight Plug-In']) {
                a = document.createElement('div');
                document.body.appendChild(a);
                a.innerHTML = '<embed type=\"application/x-silverlight\" />';
                b = a.childNodes[0];
            }
            var maxVersion = 30;
            for (j = 1; j < maxVersion; j += 0.1) {
                var vS = j.toFixed(1);
                if (b.IsVersionSupported(vS)) {
                    v = vS;
                }
                else {
                    break;
                }
            }
            c = true;
            b = null;
            this.Available = true;
            this.Version = v;
        }
        catch (e) {
            c = false;
        }
        if (a) document.body.removeChild(a);
        return v;
    };
    this.Silverlight.isInstalled();
    
    this.SendData=function(nonCookiePath)
    {
        var data="sw="+this.ScreenPixelsWidth
                +"&sh="+this.ScreenPixelsHeight
                +"&sd="+this.ScreenBitDepth
                +"&fs="+(this.FontSmoothingEnabled?"t":"f")
                +"&ck="+this.Cookies
                +"&js=t"
                +"&rf="+escape(document.referrer)
                +"&fv="+this.Flash.Version
                + "&sv=" + this.Silverlight.Version;
        if (this.Cookies) {
            createCookie("DeviceProfile", data, 0);
            document.location.href = document.location.href;
        }
        else {
            var href = nonCookiePath;
            document.location.href = href + (href.indexOf("?") > 0 ? "&" : "?") + "_dp=" + Base32.ToBase32String(data)
        }                
//        if(this.Cookies)
//        {
//            createCookie("SID","NoCook",0);
//            createCookie("Init","false",0);
//            createCookie("DeviceProfile",data,0);
//            document.location.href=document.location.href;
//        }
//        else
//        {
//            var href=nonCookiePath;
//            document.location.href=href+(href.indexOf("?")>0?"&":"?")+"_dp="+Base32.ToBase32String(data)
//        }
    };
};