Type.registerNamespace("ASPCode.net");
/*
    Version 0.01
    
    Ported to Microsoft Ajax by Stefan Holmberg
    http://www.aspcode.net
    (C) Stefan Holmberg 2007
    
    
Much code borrowed from JQuery cookie plugin 
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 
 
 expires : date or num = seconds
 path : '' or undefined = no special path  while '/test/' for example sets cookie for requests to '/test/' subdir
 secure : true/false (undefined=false)
 domain: undefined = 
 
 sample use:

Sets a SESSION cookie = lost when coming back
ASPCode.net.CookieManager.setCookie('foosession', 'sessionvalue'); 

 Sets a persistent cookie = We set expired to 5 days
ASPCode.net.CookieManager.setCookie('foo5days', 'barvalue', { expires: 5}); 
 
get value
var sCookieVal = ASPCode.net.CookieManager.getCookie('foo5days'); 

deletes cookie
ASPCode.net.CookieManager.deleteCookie('foo5days'); 


as for domain and path options
Path:
If set to '/', the cookie will be available within the entire domain. 
If set to '/foo/', the cookie will only be available within the /foo/ directory 
and all sub-directories such as /foo/bar/ of domain. 

Domain:
To make the cookie available on all subdomains of example.com then you'd 
set it to '.example.com'. The . is not required but makes it compatible 
with more browsers. Setting it to www.example.com will make the cookie 
only available in the www subdomain.

Secure:
true or false. If true it would be used in https scenarios as well





 */
 
ASPCode.net._CookieManager = function() 
{
    ASPCode.net._CookieManager.initializeBase(this);
}
ASPCode.net._CookieManager.prototype = 
{
    setCookie: function(sName, sValue, oOptions )
    {
        oOptions = oOptions || {};
        var sExpires = '';
        if (oOptions.expires && (typeof oOptions.expires == 'number' || oOptions.expires.toGMTString)) {
            var date;
            if (typeof oOptions.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (oOptions.expires * 24 * 60 * 60 * 1000));
            } else {
                date = oOptions.expires;
            }
            sExpires = '; expires=' + date.toGMTString(); 
        }
        var sPath = oOptions.path ? '; path=' + oOptions.path : '';
        var sDomain = oOptions.domain ? '; domain=' + oOptions.domain : '';
        var sSecure = oOptions.secure ? '; secure=' + oOptions.secure : '';
        
        document.cookie = sName + '=' + sValue + 
			sPath +
			sDomain +
			sSecure +
			sExpires;
        
        
        
    },
    deleteCookie: function(sName, oOptions)
    {
        if ( this.getCookie( sName ) ) 
        {
            oOptions = oOptions || {};
            var sPath = oOptions.path ? '; path=' + oOptions.path : '';
            var sDomain = oOptions.domain ? '; domain=' + oOptions.domain : '';
        
            document.cookie = sName + '=' + '' + 
			sPath +
			sDomain +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
    },
    cookies: function()
    {
        //Return array - of string...
        if (document.cookie && document.cookie != '')
        {
            return document.cookie.split(';');
        }
        
    },
    getCookie: function(sName)
    {
        var retValue = null;
        //Supports?
        if (document.cookie && document.cookie != '')
        {
            var cookieArray = document.cookie.split(';');
            for (var n = 0; n < cookieArray.length; n++) 
            {
                var oneCookie = cookieArray[n].trim();
                if ( oneCookie.startsWith(sName + '=') )
                {
                    retValue = decodeURIComponent(oneCookie.substring(sName.length + 1));
                    break;
                }
            }
        }
        return retValue;
    }
}


ASPCode.net._CookieManager.registerClass('ASPCode.net._CookieManager', Sys.Component);

ASPCode.net.CookieManager = new ASPCode.net._CookieManager();









