
//uncomment/comment this to activate/deactivate the whole domain pre-ad.
CheckPre("/ads-pre.html", "pre", document.location, "/", "cwnp.com");

function doneNewCookie(Name) 
{
   var search = Name + "="
   if (document.cookie.length > 0)
   { 
      // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1)
      {
         return true;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return false;
   }
}

function SetCookie (name, value, expire, path, domain)
{ 
	var argv = SetCookie.arguments; 
	var argc = SetCookie.arguments.length; 
	var expires = null;
	var expire = (argc > 2) ? argv[2] : null; 
	var path = (argc > 3) ? argv[3] : null; 
	var domain = (argc > 4) ? argv[4] : null; 
	var secure = (argc > 5) ? argv[5] : false; 

	if(expire != null)
   {
      expires = new Date(expire);
   }	
   var cookieVal = name + "=" + value + 
   	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
   	((path == null) ? "" : ("; path=" + path)) + 
   	((domain == null) ? "" : ("; domain=" + domain)) + 
   	((secure == true) ? "; secure" : "");
   document.cookie = cookieVal; 
} 


function CheckPre(URL, cookiename, cookievalue, path, domain)
{
   //this is where we skip over certain pages and do not show the message
   //we skip the practice test
   //we skip the store in case we are sending a mailing and sending people to the store.  No point in showing them an ad.
   if (document.location.href.indexOf("/pt") > 0 || 
       document.location.href.indexOf("/store") > 0)
   {
      return;
   }		
   if (doneNewCookie(cookiename) != true)
   {
      var expires = new Date();
      
      expires.setDate(expires.getDate()+3); // add x days
      
      SetCookie(cookiename, cookievalue, expires, path, domain);
      
      if (doneNewCookie(cookiename) == true)
      {
         window.location.href = URL; 
      }
   }
}



