		 
		function readCookie(cookieName) {
			 var theCookie=""+document.cookie;
			 var ind=theCookie.indexOf(cookieName);
			 if (ind==-1 || cookieName=="") return ""; 
			 var ind1=theCookie.indexOf(';',ind);
			 if (ind1==-1) ind1=theCookie.length; 
			 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
			}
			

	
function setCookie(name,value,seconds,domain) {
    var expires = '';
    if (domain == null) {
        domain = cookieDomain();
    }
    if (seconds != 0) {
        var date = new Date();
        date.setTime(date.getTime() + seconds*1000);
        expires = '; expires=' + date.toGMTString();
    }
    document.cookie = name + '=' + escape(value) + expires + '; path=/; domain=.' + domain; 
}
	
	

    function getCookies() {
    var hash = new Array;
    if (document.cookie != null) {
        var a = document.cookie.split('; ');
        for (var i=0; i < a.length; i++) {
            var nv = a[i].split('=');
            if (nv[1] != null) {
                hash[nv[0]] = unescape(nv[1]);
            }
        }
    }
    return hash;
}

    function deleteCookie(name) {
        setCookie(name, 'x', -1);
    }
    function cookieDomain() {
        var d;
        var parts = window.location.hostname.split('.');
        if (parts[parts.length-1].length == 2) {
            // Domains like cnn.co.jp should retain 3 parts
            d = parts[parts.length-3] + '.' +
                parts[parts.length-2] + '.' +
                parts[parts.length-1];
        }
        else {
            // Other domains like cnn.com should retain 2 parts
            d = parts[parts.length-2] + '.' +
            parts[parts.length-1];
        }
        return d;
    }

// detect login state
/// Dash board functionality
loginStatus = new Object();

var hostUrl = "http://www.cartoonnetwork.com/games/ben10/bountyhunters";

loginStatus.init=function(){ 

	this.textcolor = "000000";
	this.linkcolor = "0000ff";
	this.linkrollcolor = "0000ff";
	this.fbgcolor = "ffffff";
	this.COOKIE_DOMAIN="cartoonnetwork.com";
	this.COOKIE_STATIC=" expires=Sunday, 21-Mar-2010 23:59:59 GMT;";
	this.COOKIE_DELETE=" expires=Fri, 02-Jan-1970 00:00:00 GMT;";
	this.lHref = window.location.href;
	
	if(this.isLoggedIn()){
		this.fvUsername = this.getCookie("dname");
		this.fvLoggedin = "true";
	}else{
		this.fvUsername = "null";
		this.fvLoggedin = "null";
	}
	
}

/// ----- cookie code -----------
loginStatus.getPropVal=function(sString,sProp,cDelim,cEnd){
	var match = (sString == null) ? null : sString.match(sProp + cDelim + "[^" +cEnd + "]*");
	return (match == null) ? null :match[0].split(cDelim)[1];
}
loginStatus.getCookie=function(sCookie){
	return this.getPropVal(document.cookie,sCookie,"=",";");
}
loginStatus.setCookie=function(sCookieName, sVal, sCookieType){
	sCookieType = (sCookieType == null) ? "" : sCookieType;
	document.cookie = sCookieName+"="+sVal+ ";" + sCookieType+" path=/; domain=."+this.COOKIE_DOMAIN;
}
loginStatus.deleteCookie=function(sCookieName){
	this.setCookie(sCookieName, "", this.COOKIE_DELETE);
}

/// ------- various functions --------------
loginStatus.isLoggedIn=function(){
	return (this.getCookie("authid") != null); 
}
loginStatus.logOut=function(){ 
	this.deleteCookie("authid");
	this.deleteCookie("authpass");
	this.deleteCookie("displayname");
	this.deleteCookie("LiSESSIONID");

	if(this.lHref.indexOf("cartoonnetwork")!= -1 || this.lHref.indexOf("cartoonnetwork")!= -1 || this.lHref.indexOf("audience.cartoonnetwork")!= -1 || this.lHref.indexOf("aud-ite.cartoonnetwork")!= -1 || this.lHref.indexOf("otis.turner")!= -1 || this.lHref.indexOf("redesign.cartoonnetwork")!= -1){
		window.location.reload();
	}else{
		window.location.reload();
	}

}

loginStatus.goMsgURL=function(){
	window.location.href = gotoMsgURL;
}

loginStatus.goFriendRequest=function(){
	window.location.href = gotoFriendReqURL;
}


/// --------- build object tag ------------  
loginStatus.getParams=function(){ 
	var s="";
	s+="fvUsername=" + this.fvUsername; 
	s+="&fvMsgURL=" + this.fvMsgURL; 
	s+="&fvTextcolor=" + this.textcolor;
	s+="&fvLinkcolor=" + this.linkcolor;
	s+="&fvLinkRollcolor=" + this.linkrollcolor;
	
	s+="&";	
	
	return s;
}

loginStatus.writeSWF=function(){
	var s='';
	s+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  ';
	s+='codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"  ';
	s+='width="180" height="100" id="login"> ';
	s+='<param name="wmode" value="opaque">'; 
	s+='<param name="allowScriptAccess" value="always" /> ';
	s+='<param name="movie" value="http://www.adultswim.com/tools/media/login.swf" /> ';
	s+='<param name="quality" value="high" /> ';
	s+='<param name="bgcolor" value="#' + this.fbgcolor + '" /> ';
	s+='<param name="FlashVars" value="'+ this.getParams() + '" /> ';
	s+='<embed src="http://www.adultswim.com/tools/media/login.swf" quality="high" wmode="opaque" bgcolor="#' + this.fbgcolor + '" ';
	s+='width="180" height="100" name="login" ';
	s+='FlashVars="'+ this.getParams() + '" ';
	s+='allowScriptAccess="always" type="application/x-shockwave-flash"  ';
	s+='pluginspage="http://www.macromedia.com/go/getflashplayer" /> ';
	s+='</object>';
	
	document.write(s);
}


loginStatus.init(); 