// JavaScript Document
                var scriptLoc = 'http://www.iasbetaffiliate.com/rep.asp';
               
                var kbId = '0';
                var queryString = window.location.search.substring(1);
                var imgdata = '';
                var subdata = '';
                var overwrite = 1;
                var Days = 30;
                var sLand = '';
                var sCookieName = '';
 
                if (queryString.length > 0)
                {
                                var pairs = queryString.split('&');
                                                                                                                               
                                for(var i = 0; i < pairs.length; i++)
                                {
                                                var pairs2 = pairs[i].split('=');
                                               
                                                switch(pairs2[0].toLowerCase())
                                                {
                                                                case 'iat':
                                                                                kbId = pairs2[1];
                                                                                sCookieName = 'iat';
                                                                                break;
                                                                case 'btag':
                                                                                kbId = pairs2[1];
                                                                                sCookieName = 'btag';
                                                                                break;  
                                                                case 'kbid':
                                                                                kbId = pairs2[1];
                                                                                sCookieName = 'myaffiliate';
                                                                                break;
                                                                case 'clearcookie':
                                                                                sCookieName = 'myaffiliate';
                                                                                if (pairs2[1] == 1)
                                                                                {
                                                                                                DeleteCookie(sCookieName);
                                                                                }
                                                                                break;
                                                                case 'img':
                                                                                imgdata = pairs2[1];
                                                                                break;
                                                                case 'sub':
                                                                                subdata = pairs2[1];
                                                                                break;
                                                                case 'land':
                                                                                sLand = pairs2[1];
                                                                                break;
                                                }
                                } //end for
                }//end if
 
                                switch(sCookieName){
                                                case 'iat':
                                                                                if (GetCookie('btag') == null && GetCookie('myaffiliate') == null){
                                                                                                                SetCookie(sCookieName, kbId, Days,'/', 'iasbet.com');
                                                                                }                             
                                                                                break;
                                                case 'btag':
                                                                                if (GetCookie('iat') == null && GetCookie('myaffiliate') == null){
                                                                                                                SetCookie(sCookieName, kbId, Days,'/', 'iasbet.com');
                                                                                }                                                             
                                                                                break;
                                                case 'myaffiliate':
                                                                                if (GetCookie('iat') == null && GetCookie('btag') == null){
                                                                                                                SetCookie(sCookieName, kbId, Days,'/', 'iasbet.com');
                                                                                }                                                             
                                                                                break;
                                }             
 
//            if (GetCookie(sCookieName) == null || overwrite == 1)
//            {
//                            if (kbId != '0')
//                            {
                                                // Only perform this for Referdetect (Days==1)
                                 
                                  /* From Investigation Days has been hardcoded to 30
                                     This section is no longer being called - 24 Mar 2008
                                  if (Days == 1) {
                                                                var img = new Image();
                                                                var url = scriptLoc + '?id=' + kbId;
                                                                if (imgdata != '')
                                                                {
                                                                                url += '&img=' + imgdata
                                                                }
 
                                                                if (subdata != '')
                                                                {
                                                                                url += '⊂=' + subdata
                                                                }
                                                                img.src = url;
                                                }
                                                */
                                                // Set cookie for both Referdetect and Commission King
//                                            SetCookie(sCookieName, kbId, Days,'/');
//                            }
//            }//end if
               
               
                // Set Landing Page
                if (sLand != '')
                {
                                                switch(sLand.toLowerCase())
                                                {
                                                                case 'poker':
                                                                                window.location.href='/site/poker/default.aspx';
                                                                                break;
                                                                case 'casino':
                                                                                window.location.href='/site/casino/default.aspx';
                                                                                break;
                                                                case 'games':
                                                                                window.location.href='/site/games/default.aspx';
                                                                                break;
                                                                case 'sport':
                                                                                window.location.href='/Sport/SportMain.aspx';
                                                                                break;
                                                }                             
                }
               
                function getCookieVal (offset)
                {
                                var endstr = document.cookie.indexOf (";", offset);
                                if (endstr == -1)
                                                endstr = document.cookie.length;
 
                                return unescape(document.cookie.substring(offset, endstr));
                }
 
                function GetCookie (name)
                {
                                var arg = name + "=";
                                var alen = arg.length;
                                var clen = document.cookie.length;
                                var i = 0;
                               
                                while (i < clen)
                                {
                                                var j = i + alen;
                                                if (document.cookie.substring(i, j) == arg)
                                                                return getCookieVal (j);
                                               
                                                i = document.cookie.indexOf(" ", i) + 1;
 
                                                if (i == 0) break;
                                }
                               
                                return null;
                }
 
                function WriteCookie (name, value, expires)
                {
                                var argv = SetCookie.arguments;
                                var argc = SetCookie.arguments.length;
                                var path = (argc > 3) ? argv[3] : null;
                                var domain = (argc > 4) ? argv[4] : null;
                                var secure = (argc > 5) ? argv[5] : false;
                               
                                var cookie = name + "=" + escape(value) +
                                                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                                                ((path == null) ? "" : ("; path=" + path)) +
                                                ((domain == null) ? "" : ("; domain=" + domain)) +
                                                ((secure == true) ? "; secure" : "");
                               
                                document.cookie = cookie;
                }
 
                function DeleteCookie (name)
                {
                                var exp = new Date();
                                exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
                                var cval = GetCookie (name);
                                document.cookie =name + "=" + cval + "; expires=" + exp.toGMTString();
                }
 
                function SetCookie(name, value, expiredays)
                {
                                var expdate = new Date();
                                expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * expiredays));
                                WriteCookie(name, value, expdate); 
                }

