function r2iClass()
{
	function CookieClass()
	{
		this.getVal=function(offset){
			var endstr=document.cookie.indexOf(";",offset);
			if(endstr==-1)
				endstr=document.cookie.length;
			return unescape(document.cookie.substring(offset,endstr));
		};
		this.get=function(name){
			var arg=name+"=";
			var alen=arg.length;
			var clen=document.cookie.length;
			var cookiei=0;
			while(cookiei<clen)
			{
				var j=cookiei+alen;
				if(document.cookie.substring(cookiei,j)==arg)
					return this.getVal(j);
				cookiei=document.cookie.indexOf(" ",cookiei)+1;
				if(cookiei==0)
					break;
			}
			return null;	
		};
		this.set=function(name,value,expires,path,domain,secure)
		{
			if (typeof expires=='undefined') expires=null;
			if (typeof path=='undefined') path=null;
			if (typeof domain=='undefined') domain=null;
			if (typeof secure=='undefined') secure=false;
			document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");		
			//var img=new Image();
			//img.src=document.location;
		};
		this.clear=function()
		{
			var exp=new Date;
			exp.setTime(exp.getTime()-1000000000);
			var cval=this.get('DemoName');
			document.cookie='DemoName'+"="+cval+"; expires="+exp.toGMTString();
		};
	}
	function TrackClass()
	{
		this.branch=function(urlSegment,message,isconfirmation,confirmanswer)
		{
	
			if (typeof isconfirmation=='undefined') isconfirmation = false;
			if (typeof confirmanswer=='undefined') confirmanswer = false;

			if (this.check(urlSegment,true)) 
			{
			 if (!isconfirmation) 
				alert(message);
			 else
				{
					if (confirm(message)==confirmanswer) 
						window.history.go(-1);
				}
				
			}
		}
		this.check=function(urlSegment,autoset)
		{
			var key = 'r2i.url.track.check.';
			if (typeof autoset==null) autoset=false;
			if ((document.location+'').toLowerCase().match(urlSegment)==null)
			{ //not in the urlSegment
				if (r2i.cookie.get(key+urlSegment)!=null&&r2i.cookie.get(key+urlSegment)!='')
				{
					if (autoset) r2i.cookie.set(key+urlSegment,'',null,'/');
					return true;
				}
			}
			else {
				if (autoset) r2i.cookie.set(key+urlSegment,true,null,'/');
			}
			return false;		
		}
	}
	function URLClass()
	{
		this.track=new TrackClass();
	}
	this.url=new URLClass();
	this.cookie = new CookieClass();	
}
var r2i=new r2iClass();


