
if(typeof TSCM == "undefined") { TSCM = {};
if(typeof TSCM.util == "undefined") { TSCM.util = {};}
TSCM.util.getTrackingPixel = function(){ return "";}
};

TSCM.util.OverlayManager = {
      node:null,
      init:function(){


	// bail out if referrer matches...
	try {
	  var ref = TSC_WWW_REFERRER;
	  	if(ref.indexOf("partners-businessweek.com")!=-1){
			return;  
		}
	}catch(e){
	}

      //cookie stuff

      var now = new Date();
      eval("var cookieName='overlay_"+now.getMonth()+1+now.getDate()+now.getYear()+"';");
      var expires = new Date();
      expires.setHours(23); 
      expires.setMinutes(59); 
      expires.setSeconds(59); 
      expires = expires.toGMTString();

      var version = navigator.appVersion;

      if(document.cookie.indexOf(cookieName) == -1) {
         document.cookie = cookieName + "=" + now + ";expires=" + expires + ";path=/;domain=.thestreet.com";
      }else{
         return; // no ad
      }

      var callback = {
        success:TSCM.util.OverlayManager.processConfig,
        failure:this.handleConfigError,
        scope:this,
        argument:null
      }
      var path = "/files/tsc/v2008/ads/roadblockadcfg.xml";
      //var path = "/tsc/v2008/ads/roadblockadcfg.xml";
      var conn = YAHOO.util.Connect.asyncRequest('GET',path ,callback, null);

   },
   processConfig:function(o){

         try {

         var now = new Date();

         var doc = o.responseXML;
         var nodes = doc.getElementsByTagName("roadblock");
         for(var i=0;i<nodes.length;i++){
            var node = nodes[i];

            this.overlayad_offset = Number(node.getAttribute("timeout"));

            var startmonth = Number(node.getAttribute("startmonth"));
            var startdate  = Number(node.getAttribute("startdate"));
            var starthour  = Number(node.getAttribute("starthour"));
            var startmin   = Number(node.getAttribute("startmin"));
            var endmonth = Number(node.getAttribute("endmonth"));
            var enddate  = Number(node.getAttribute("enddate"));
            var endhour  = Number(node.getAttribute("endhour"));
            var endmin   = Number(node.getAttribute("endmin"));

            var start = new Date();
            start.setMonth(startmonth-1);
            start.setDate(startdate);
            start.setHours(starthour);
            start.setMinutes(startmin);
            var end = new Date();
            end.setMonth(endmonth-1);
            end.setDate(enddate);
            end.setHours(endhour);
            end.setMinutes(endmin);

            if((start.getTime() <= now.getTime()) && (now.getTime() < end.getTime())){
               if(Boolean(node.getAttribute("enabled"))==true){
                     TSCM.util.OverlayManager.runad(node);
               };
            }else{
               
            }
         }
         }catch(e){
            
         }


   },
   runad:function(node){
      if( (!disablePopup()) && (navigator.userAgent.indexOf("Mac") < 0)) {
         var qs = location.search;
         if(qs.indexOf("?")==-1){
            qs += "?";
         }else{
            qs += "&";
         }
         qs += "t=" + node.getAttribute("timeout");


         var path=node.getAttribute("path");
         path += qs;
         window.location.replace(path);	// use replace() so we don't break the back button
      }else{
       

      }
   },
   handleConfigError:function(o){

   }
}

TSCM.util.OverlayManager.init();




function UserStatus(){
   this.RM = '1';
   this.SI = '631';
	this.AAP = '765';
	this.globalState = "U";
	this.version = "VER0";
	this.streetCookie =  (readCookie("STATUS"))
	if (this.streetCookie != null){
		var list = this.streetCookie.split('|');
      if(list[0].length==1){
         this.globalState = list[0];
      }else{
         var sublist = list[0].split('~');
         this.version=sublist[0];
         this.globalState = sublist[1];
      }
	}
}

function UserStatus_isEtradeUser(product){
   var retVal = '';
	if (this.streetCookie != null){
		var statusList = this.streetCookie.split('|');
		
	    for(i=1;i<statusList.length;i++) {
         if(this.version=="VER1"){
	        if(statusList[i].split(':')[0] == product && (((statusList[i].split(':')[2]).substring(5,7) == "ET") 
			|| (statusList[i].split(':')[2]).substring(5,7) == "EI")){
	            retVal = true;
               break;
           }
         }
	    }
	}
    return retVal;
}

function UserStatus_hasAccess(product){
   var retVal = '';
	if (this.streetCookie != null){
		var statusList = this.streetCookie.split('|');
		
	    for(i=1;i<statusList.length;i++) {
         if(this.version=="VER1"){
	        if(statusList[i].split(':')[0] == product && statusList[i].split(':')[1] != 'E'){
	            retVal = true;
               break;
           }
         }else{
	        if(statusList[i].split('-')[0] == product && statusList[i].split('-')[1] != 'E'){
	            retVal = true;
               break;
           }
         }
	    }
	}
    return retVal;
	
}


function UserStatus_hasPaidAccess(product){
   var retVal = '';
	if (this.streetCookie != null){
		var statusList = this.streetCookie.split('|');
		
	    for(i=1;i<statusList.length;i++) {
         if(this.version=="VER1"){
	        if(statusList[i].split(':')[0] == product && statusList[i].split(':')[1] == 'P'){
	            retVal = true;
               break;
           }
			}else{
	        if(statusList[i].split('-')[0] == product && statusList[i].split('-')[1] == 'P'){
	            retVal = true;
               break;
           }
         }
	    }
	}
    return retVal;
	
}

function UserStatus_hasCompAccess(product){
   var retVal = '';
	if (this.streetCookie != null){
		var statusList = this.streetCookie.split('|');
	    for(i=1;i<statusList.length;i++) {
         if(this.version=="VER1"){
	        if(statusList[i].split(':')[0] == product && statusList[i].split(':')[1] == 'C'){
	            retVal = true;
               break;
           }
			}else{
	        if(statusList[i].split('-')[0] == product && statusList[i].split('-')[1] == 'C'){
	            retVal = true;
               break;
           }
         }
	    }
	}
    return retVal;
}


function UserStatus_isPaid(){ return (this.globalState == "P"); }
function UserStatus_isTrialer(){ return (this.globalState == "F"); }
function UserStatus_isComp(){ return (this.globalState == "C"); }
function UserStatus_isRegistrant(){ return (this.globalState == "R"); }
function UserStatus_isExpired(){ return (this.globalState == "E"); }
UserStatus.prototype.isEtradeUser = UserStatus_isEtradeUser;
UserStatus.prototype.hasCompAccess = UserStatus_hasCompAccess;
UserStatus.prototype.hasPaidAccess = UserStatus_hasPaidAccess;
UserStatus.prototype.hasAccess = UserStatus_hasAccess;
UserStatus.prototype.isPaid = UserStatus_isPaid;
UserStatus.prototype.isTrialer = UserStatus_isTrialer;
UserStatus.prototype.isComp = UserStatus_isComp;
UserStatus.prototype.isRegistrant = UserStatus_isRegistrant;
UserStatus.prototype.isExpired = UserStatus_isExpired;


function disablePopup(){
	var user = new UserStatus();
	if ( (user.globalState == "P") || (user.globalState =="F") ){
      return true;
	}else{
      return false;
   }
}

function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
}


function log(m){if(typeof console !="undefined")console.log(m);}




//


