﻿


var expDays = 1; 
var thisurl = location.href; 
var stringArray = thisurl.split('/'); 
var pagename = "/ads/rates.aspx?ic_id=br3int_popup";
var winprops = "toolbar=yes,location=yes,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=1000,height=600";
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*2*60*60*1000));
var AllowedList = ["br3","br3_b","br3_c","baw","bhabr","bhn2","blm","bos","bosre","bravd_t","brm_c","brm_sem","cic","cld","crc","crt","csoup","cycl","deal","dls","dmn","fci","gookeyword","hch","igg","kgw","kings","kmov","kvue","lapalma","mchx","mhe","milfn","movebr","mtry","ndaq","nltrack","nscre","nwcn","prj","realfc","rss","_trk","rtrs","rvrt","sae","sam","selcbsmw","selcweb","selexct","sema","semb","sfc2","stb","tnp","treebr","usn","wfaa","whas","wpbf","zlw"];
var AllowCobrand=true;
var cobrandid="";

if (PageManager)
 {
      if (PageManager.PageMetaData) 
      {
	  
	   if(CookieManager)	    
           {		
			   var pidvalue = CookieManager.Open('brmp').Get('pid');
			   if(!IsNullorUndefined(pidvalue))
			   {
				   PID$ = new $H(pidvalue);				  
				   if(!IsNullorUndefined(PID$) && !IsNullorUndefined(PID$.get('p')) && !IsNullorUndefined(PID$.get('c')))
					   cobrandid=PID$.get('p')+PID$.get('c');
				   else if(!IsNullorUndefined(PID$) && !IsNullorUndefined(PID$.get('p')))
					  cobrandid=PID$.get('p');
				 } 
		   }
	 
	 
            if(PageManager.PageMetaData.ContainsKey('Location') && PageManager.PageMetaData.ContainsKey('PageType'))
            { 			  
               pagename=pagename+ '&location' + '='+ PageManager.PageMetaData.Values['Location'].replace(' ','').replace(' ','')  +  '&pagetype='+PageManager.PageMetaData.Values['PageType'];
               ProcessPopUnder(PageManager.PageMetaData.Values['Location'].replace(' ','').replace(' ','')  ,PageManager.PageMetaData.Values['PageType']);   
            } 
            else if(PageManager.PageMetaData.ContainsKey('Location') )
            {
                 pagename=pagename+ '&location' + '='+ PageManager.PageMetaData.Values['Location'].replace(' ','').replace(' ','')   ;
                 ProcessPopUnder(PageManager.PageMetaData.Values['Location'].replace(' ','').replace(' ','')   ,null); 
              
            }            
            else 
            {
              ProcessPopUnder(null,null);               

            }                        
        }       
 }
 else
 {
      ProcessPopUnder(null,null,PageManager);            
 }


function ProcessPopUnder(Location, PageType) 
{
   var query=thisurl.toQueryParams([separator = '&']);	 
   if((cobrandid=="" || (AllowCobrand  && AllowedList.indexOf(cobrandid)>-1)) && (query.pop!="nopop"))
    {
        var key = (Location==null ? "Default" : Location ) + (PageType ==null ? "" : PageType)		
        var count = GetCookie(key);		
        if (count == null)
         {
             count=1;
             SetCookie(key, count, exp);
             var nWindow=window.open(pagename, "", winprops);
             nWindow.blur();
             window.focus();
          }
        else
          {
            count++;
            SetCookie(key, count, exp);
          }
     }
}


function GetCookie (key) 
{         
    var arg = key + "=";  
    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 SetCookie (key, value)
  {  
    var argv = SetCookie.arguments;  
    var argc = SetCookie.arguments.length;  
    var expires = (argc > 2) ? argv[2] : null;  
    var path = "/";
    var domain = (argc > 4) ? argv[4] : null;  
    var secure = (argc > 5) ? argv[5] : false;  
    document.cookie = key + "=" + escape (value) +  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset)
 {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
  }


