﻿//<class name='cookie' version='8.28' date='01.04.2006' author='HK510.com' />
function __cookie(o)
{
	this.extend = __class;
	this.extend(o);
	this.toString		= _toString;
	this.enable 		= _enable();
	this.setValue 		= _setValue;
	this.getValue 		= _getValue;
	this.erase 			= _erase;
	this.trace 			= _trace;
	function _toString(){return "root.browser.cookie";};
	function _setValue(n,v,u)
	{
		var o 	= _scope(this);
		if(o.enable)
		{
			var e = "";
			var g = (typeof(u)!='undefined')? u : 1;
			var d = new Date();
			d.setTime(d.getTime()+(g*24*60*60*1000));
			e = "; expires="+d.toGMTString();
			document.cookie = n+"="+v+e+"; path=/";
			document.cookie = "bob=wanda"+e+"; path=/";
		}			
	};
	function _getValue(n)
	{
		var o 	= _scope(this);
		var r = null;
		if(o.enable)
		{
			var a1 = document.cookie.split(';');
			for(var i = 0;i< a1.length;i++)
			{
				var a2 = a1[i].split('=');
				if(a2[0]==n)
				{
					r = a2[1];
					break;
				}
			}
		}
		if(r == '') r = null;
		return r;
	}
	function _erase(n)
	{
		var o 	= _scope(this);
		if(o.enable) o.setValue(n,"",-1);	
	};
	function _trace(o)
	{
		var s = '';
		for(var i in o) s += i +" = "+ o[i]+"\n";
		if(s == '') s = null;
		alert(s);
	};
	function _scope(s){return (s==root.browser.cookie)?s:root.browser.cookie;};
	function _enable()
	{
		var o 	= _scope(this);
		var c 	= navigator.cookieEnabled;
		var r	= (c)? true : false;
		var n 	= "IsEnable";
		if(typeof(c)=="undefined" && c==false)
		{
			o.setValue(n,"HK510.com - checking if cookie enabled",1);
			r = document.cookie == n;
			if(r) o.erase(n);
		}
		return r;	
	};
}
root.browser.extendClass('cookie',__cookie);
