function del_cookie(name,domain) { document.cookie = name +'=; expires=Thu, 01-Jan-70 00:00:01 GMT;' + ( ( domain ) ? ";domain=" + domain + ";" : "" );};

function BTrck(url, crb) {
    var cref, i, cref_part;
	this.ctag='';
	this.urldwnld=url;

	this.trk_mems = new Trck();
	if (this.trk_mems.initFCookie()) {
	      cref = this.trk_mems.creferer.split(';');
	      for (i=0; i < cref.length; i++) {
	           cref_part = cref[i].split(':');
	           switch (cref_part[0]) {
	               case 'source':
	                   this.csrc = cref_part[1];
	                   break;
	               case 'tag':
	                   this.ctag = cref_part[1];
	                   break;
	           }
	      }
	}

    if(this.ctag == '' && this.trk_mems.tagtrack != '') {
       this.ctag = this.trk_mems.tagtrack;
    }

	if (typeof member!="undefined" && typeof profile!="undefined") {
			this.trk_mems.init(member, profile);
	}


	this.openexitstatus=1;
	this.country_code = 'US';
	
	this.getCountryCode = function() {
	   return this.country_code;
	}
	
	this.opt_lang = '';
	
	this.getCRB = function(crb) {
	   var platform = this.trk_mems.readCookie('platform');
	   var template = this.trk_mems.readCookie('template_' + platform);
	   if (!platform || !template) {
	       this.crb = crb;
	       return;
	   }
	   
        var crb_a = crb.split('+');
        crb_a[1] = template;
        this.crb = crb_a.join('+');	   
	}
	
	this.getCRB(crb);

    this.exitPage = function(lang, msg) {

	
		if (this.openexitstatus==0) return false;


		if(confirm(msg)) {
			window.open("http://banner.casinotropez.com/cgi-bin/redir.cgi?id=N&member="+this.trk_mems.member+"&profile=exitk&lang=uk","","toolbar, location=yes, width=1024, height=728, menubar=yes, status=yes, resizable=yes, scrollbars=yes, directories=yes");
		}
		

		return true;
		}

	this.trckImg = function(_url) {
		var url=_url+(_url.indexOf("?") == -1 ? "?": "&")+this.trk_mems.getQuery();

		try {
			var img=document.createElement('img');
			img.src = url;
			img.setAttribute('width', 0);
			img.setAttribute('height', 0);
			img=document.body.appendChild(img);
			img.style.visibility="hidden";
			img.style.display="none";
			return true;
		}
		catch (ex) { }
		return false;
	}

	this.trackImg = function()
	{

		
		if (this.trk_mems.readCookie('make_impr') != '') {
			this.trckImg('http://banner.casinodelrio.com/cgi-bin/banner.cgi?id=N');
			del_cookie('make_impr','casinodelrio.com');
			
		}
	}

	this.isURL = function(str) {
		if (str == '@' || str == '-') {
			return false;
		}
		if (typeof str == "string") {
			return (str.search(/^(http:\/\/)?[a-zA-Z0-9][a-zA-Z0-9\.\-_]+/) != -1);
		} else {
			return false;
		}
	}

	this.updateRef = function(cr) {
		if (this.csrc || this.ctag || (this.crb && cr)) {
			var p= this.csrc ? 'source:'+this.URLEncode(this.csrc)+';' : '';
	   		p+= this.ctag ? 'tag:'+this.URLEncode(this.ctag)+';' : '';
			p+=(this.crb && cr) ? 'dp:'+escape(this.crb)+'+'+escape(cr.replace(/_/, ' ')) : '';
			this.trk_mems.creferer = p;
		}
	}

	this.download = function(cr, win, src_page) {
	    var url = this.dwldurl(cr);
		if (this.opt_lang)
		{
			url+="&" + "opt_lang" + "=" + this.opt_lang;
		}
		if (src_page) {
			url = url.replace('+download+', '+' + src_page + '+');
		}
		this.openexitstatus=0;
		win.location.href = url;
		return true;
	}

	this.downloadgo = function(cr, win) {
		this.openexitstatus=0;
		var dwldurl = this.dwldurl(cr);
		window.open(dwldurl, "Download","width=1,height=1,top=0,left=0");
		win.location.href='download.html';
		return true;
	}

	this.dwldurl = function(cr) {
		this.updateRef(cr);
		return this.urldwnld + (this.urldwnld.indexOf('?') > 0 ? '&' : '?') + this.trk_mems.getQuery();
	}

	this.downloadRedirect = function (cr, win, page, src_page) {
		this.openexitstatus=0;
		if (document.readyState) {
			this.updateRef(cr);
			win.location.href=this.dwldurl(cr);
			if (document.readyState && document.readyState=='loading') {
				win.status = document.readyState;
				setTimeout('downloadpage("' + page + '")', 200);
				return false;
			}
		} else {
			var parts = this.crb.split('+');
			document.cookie = 'page=' + parts[parts.length -1] + '; expires=Fri, 3 Aug 2039 20:47:11 UTC; path=/';
			document.cookie = 'cr=' + cr + '; expires=Fri, 3 Aug 2039 20:47:11 UTC; path=/';
		}
		return true;
	}

	this.dnldAfterRedir = function(win) {
		if (!document.readyState)  {
			var src_page = this.trk_mems.readCookie('page');
			var src_crb = this.trk_mems.readCookie('cr');
			if (src_page && src_crb) {
				this.download(src_crb, win, src_page);
				document.cookie = 'page=; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/';
				document.cookie = 'cr=; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/';
			}
		}
	}
	this.URLEncode = function (clearString) {
        var output = '';
        var x = 0;
        clearString = clearString.toString();
        var regex = /(^[a-zA-Z0-9_+-]*)/;
        while (x < clearString.length) {
            var match = regex.exec(clearString.substr(x));
            if (match != null && match.length > 1 && match[1] != '') {
                output += match[1];
                x += match[1].length;
            } else {
                if (clearString[x] == ' ')
                    output += '+';
                else {
                    var charCode = clearString.charCodeAt(x);
                    var hexVal = charCode.toString(16);
                    output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
                }
                x++;
            }
        }
        return output;
    }
}
function downloadpage(page) {
		if (document.readyState=='loading') {
			setTimeout('downloadpage("' + page + '")', 200);
		} else {
			location.href=page;
		}
	}
