// Dan Mazzella
// Error Reports to: dan@rotarynews.com
// Last Updated:     8/7/2001

//------------------------------------
// For some reason Netscape 4 on Linux was 
// complaining about variables being undefined.
// I moved the script to the end of the page, 
// and it stopped. Neat-o. I wish everyone would just
// switch over to Mozilla/Netscape 6.1!!


//------------------------------------
//  Use Cookies to disable ads 
// Setup all the stuff needed
//
var expDays = 30 ;                                    // number of days the cookie should last
var exp = new Date();                                 // Today
exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); // Don't quite know why we do this, Just copy and paste :)



//------------------------------------
// F/N to open stuff in a new window
//
function openIt(targetURL, loc)
{
  if(loc == 1)
  {
    window.open(targetURL,"ROTARYNEWS",
                "height=380,width=630,status=no,toolbar=no,menubar=no," + 
    	        "location=no,top=0,left=0,resizable=yes,scrollbars=yes" +
	        ",top=0,alwaysRaised=0,dependent=1,directories=0," +
	        "fullscreen=0,location=0,menubar=0,resizable=1," +
	        "scrollbars=1,status=0,toolbar=0") ;
  }
  else
  {
    with(document)
    {
      target_URL.src = targetURL  ;
    }
  }
}

// ---------------------------------------
// Add a side bar to Mozilla or Netscape 6
//
function addSidebar()
{
  if ((typeof window.sidebar == "object") &&
      (typeof window.sidebar.addPanel == "function"))
  {
    window.sidebar.addPanel("rotarynews.com","http:\/\/rotarynews.com/sidebar.shtml","");
  }
}

//--------------------------------------
// If they click on the rotary top 50, 
//------------------------------------ 

// New Popup Ad to get interest in the 
// store added 7/19/2001 Test for  1 
// week, see if it works... 8/7/2001, P
// revious month: 0 orders. Within one 
// week (7/19-7/26, 3 orders) Keeping 
// popup ad with modifications...
//
function openAd()
{
    var top  = screen.height - 10 ;
    var left = screen.width - 10 ;    
    var width  = 230 ;
    var height = 285 ;
    var date = new Date() ;
    var location = "http://rotarynews.com/store-ad.html" ;
    if(date.getSeconds()%2)
    { 
      location = "http://rotarynews.com/shirt-ad.html" ;
    }

    window.open(location, 
                "RNSTORE",
                "height="+ height + "," +
		"width=" + width  + "," +
		"top=" + (top - height) + "," +
		"left=" + (left - width) + "," +
		"status=0,toolbar=0,menubar=0," + 
    	        "location=0,resizable=1,scrollbars=0," +
	        "alwaysRaised=0,dependent=1,directories=0," +
	        "fullscreen=0" ) ;
  }

//------------------------------------
// Get a cookie by name
//
function GetCookie (name) 
{  
   var arg = name + "=";  
   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;
}

//------------------------------------
//Set a value to cookie of name
//
function SetCookie (name, value) 
{  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (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;  
  document.cookie = name + "=" + escape (value) + 
                    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
                    ((path == null) ? "" : ("; path=" + path)) +  
                    ((domain == null) ? "" : ("; domain=" + domain)) +    
                    ((secure == true) ? "; secure" : "");
}

//------------------------------------
// Bye Bye cookie
//
function DeleteCookie (name) 
{  
  var exp = new Date();  
  exp.setTime (exp.getTime() - 1);  
  var cval = GetCookie (name);  
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//------------------------------------
// Set the amount
//
function amt()
{
  var count = GetCookie('rnCookie')
    if(count == null) 
      {
	SetCookie('rnCookie','1') ;
	return 1 ;
      }
    else 
      {
	var newcount = parseInt(count) + 1;
	DeleteCookie('rnCookie') ;
	SetCookie('rnCookie',newcount,exp) ;
	return count ;
      }
}


//------------------------------------
// Get the value of a cookie via offset
//
function getCookieVal(offset) 
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//------------------------------------
// Check the count and open the ad
//
function checkCount() 
{
  var count = GetCookie('rnCookie');
  if (count == null) 
    {
      count=1;
      SetCookie('rnCookie', count, exp);
      openAd() ;     
    }
  else 
    {
      count++;
      SetCookie('rnCookie', count, exp);
    }
}

//------------------------------------
// Last, call checkCount to open the ad
//
checkCount() ;





