﻿
    /*
    Include the following code in <head></head> of page
    
    <script language="javascript" src="stopgate.js"></script>
    <script>stopGate("rating", "sitename", "redirect");</script>
    
    Possible Values for "rating":
     "M":	Mature
     "AO":	Adults Only
     "T":	Teen
     "RP":	Rating Pending
     "EC":	Early Childhood
     "K-A":	Kids to Adults
     "E":	Everyone
     
     "sitename" should be a unique name for the site. Using the directory name is the most conveient method     
     
     "redirect" should be the directory/site/page the user should be forwarded too if the age test fails.
     
     The following are all equivalent assuming default.aspx is the default page for the site
     
     /games/<sitename>/default.aspx 
     /games/<sitename>/
     default.aspx
     
     If you are redirecting to a page outside of http://www.microsoft.com. You MUST include http://
     
     For example, http://www.dungeonsiege2.com
     
     Entering just a "/" for redirect will result in the page being redirected to the root.
     
     For exmample, if you are on http://www.microsoft.com/games/dungeonsiege2/ and you set "redirect" to "/"
     then you will be redirected to http://www.microsoft.com
     
     Example of how to use the script:
     
     <script language="javascript" src="stopgate.js"></script>
     <script>stopGate("M", "dungeonsiege2", "/games/dungeonsiege2/");</script>
     
    
    */
    
    function stopGate(rating, sitename, redirect){        
        if(document.cookie.length > 0 && document.cookie.indexOf("microsoft_games_stopgate") > -1 && document.cookie.indexOf(sitename) > -1){            
            NameOfCookie = "microsoft_games_stopgate";
            begin = document.cookie.indexOf(NameOfCookie + "="); 
            if (begin != -1) 
            { 
                begin += NameOfCookie.length+1; 
                end = document.cookie.indexOf(";", begin);
                if (end == -1) end = document.cookie.length;                
            }
            pass = getKeyName(document.cookie.substring(begin,end),sitename);
            if (pass != 1) window.location = redirect;          
        }
        else window.location="stopgate.aspx?r=" + rating + "&t=" + unescape(location.href) + "&s=" + sitename + "&d=" + redirect;            
    }
    
    function getKeyName(s, keyname){            
            b = s.indexOf(keyname+"="); 
            if (b != -1) 
            { 
                b += keyname.length+1; 
                e = s.indexOf("&", b);
                if (e == -1) e = s.length;
                if(s.substring(b, e)=="pass") return 1;
                else return 0;
            }    
    }

  