CoverYourASP --> utils/Banners.asp" --> Source

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
99 active users
3425 visitors today
2962 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2016 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

This page shows the actual source code used on this site. If this is the first CYA source code you've seen you should read this overview first.

Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!

Please spread the word by recommending my site to your friends and colleagues!

This is JScript (server-side JavaScript), not the more common VBScript. More...

utils/Banners.asp

<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================

// ============================================
// show a specific banner if passed in, else the next available banner
// ============================================
function ShowAd ( sShowBanner )
{
   // should we make a plain page for printing?
   if ( bPlainJane )
   {
      Out ( '&nbsp;' );
      return;
   }

   var nTopBanners = Application ( 'TotalTopBanners' );

   if ( !nTopBanners )
   {
      // if there are no CYA banners left, optionally
      // display ASPAlliance banners instead
      if ( bDisplayAllianceBanners )
      {
         DebugOut ( '<font color="blue">showing ASPAlliance 468 banner</font>' );
         ShowAllianceAd ( 468, 1 );
      }
      else
      {
         DebugOut ( '<font color="blue">[no banners]</font>' );
      }

      return;
   }

   // do we need to display a particular banner?
   if ( sShowBanner )
   {
      DebugOut ( '<font color="blue">' + nTopBanners + ' banners, showing ' + sShowBanner + '</font>' );
      // search for the banner and display
      for ( var i=0; i<nTopBanners; i++ )
      {
         var sBanner = Application ( 'TopBanner' + i );

         if ( -1 != sBanner.indexOf ( sShowBanner ) )
         {
            Out ( sBanner );
            return;    // we're done
         }
      }

      // if not found, continue to show the next available banner...
   }

   // increment banner counter
   Application.Lock ( );

   if ( ++Application ( 'CurrentTopBanner' ) >= nTopBanners )
      Application ( 'CurrentTopBanner' ) = 0;

   Application.Unlock ( );

   // output banner html
   Out ( Application ( 'TopBanner' + Application ( 'CurrentTopBanner' ) ) );
}

// ============================================
// show given number of affilate sites (that publish my articles)
//      nNumberToDisplay specifies how many to display
// ============================================
function ShowAffiliates ( nNumberToDisplay )
{
   // should we make a plain page for printing?
   if ( bPlainJane )
   {
      Out ( '&nbsp;' );
      return;
   }

   Out ( '<p><a href="/eu_url_httpwww.htmlconnections.comrefer.html" target="CYAexternal"><img src="images/affiliates/ASPNETConnections100x69.jpg" width="100" height="69" border="0"></a>' );

   var nAffiliates = Application ( 'TotalAffiliates' );

   if ( !nAffiliates )
   {
      DebugOut ( '<font color="blue">[no affiliates]</font>' );
   }
   else
   {
      // be safe!
      if ( nNumberToDisplay > nAffiliates )
         nNumberToDisplay = nAffiliates;

      DebugOut ( '<font color="blue">' + nAffiliates + ' affiliates, showing ' + nNumberToDisplay + '</font>' );

      // start from the next affiliate
      var nNext = Application ( 'CurrentAffiliate' );

      for ( var i=0; i<nNumberToDisplay; i++ )
      {
         // check for rollover
         if ( nNext+i > nAffiliates-1 )
            nNext = -i;

         var nAffiliate = nNext + i;

         DebugOut ( '<font color="blue">' + nAffiliate + ':</font>' );

         // output banner image
         Out ( '<p>' + Application ( 'Affiliate' + nAffiliate ) );
      }

      // move pointer to current affiliate
      Application.Lock ( );

      Application ( 'CurrentAffiliate' ) = nNext + nNumberToDisplay;

      Application.Unlock ( );
   }
}

// ============================================
// show given number of content items in random order
//      nNumberToDisplay specifies how many to display
// ============================================
function ShowBanners ( nNumberToDisplay )
{
   // should we make a plain page for printing?
   if ( bPlainJane )
   {
      Out ( '&nbsp;' );
      return;
   }

   // with new left navigation bar we always
   // show a minimum of 4 banners
   if ( nNumberToDisplay < 4 )
      nNumberToDisplay = 4;

   NavTableTop ( 'Featured sponsor' );

   // show the next 125x125 advertiser banner at top
   var nSideBanners = Application ( 'TotalSideBanners' );

   if ( !nSideBanners )
   {
      if ( bDisplayAllianceBanners )
      {
         DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );

         Out ( '<center>' );
            ShowAllianceAd ( 126, 1 );
         Out ( '</center>' );
            NavTableBottom ( );
            NavTableTop ( 'My favorite resources' );
         Out ( '<center>' );
      //      Out ('<h3><a href="http://www.royaltiki.com/" target="CYAexternal">Tiki Statues - Tiki Masks - Tiki Totems</a></h3><hr>');
            DebugOut ( '<font color="blue">showing ASPAlliance textad</font>' );
            ShowAllianceAd ( 100, 1 );
         Out ( '</center>' );

         // decrement number of rotating banners by one
         if ( --nNumberToDisplay == 0 )
         {
            NavTableBottom ( );
            return;
         }
      }
      else
      {
         DebugOut ( '<font color="blue">[no banners]</font>' );
      }
   }
   else
   {
      // increment banner counter
      Application.Lock ( );

      if ( ++Application ( 'CurrentSideBanner' ) >= nSideBanners )
         Application ( 'CurrentSideBanner' ) = 0;

      Application.Unlock ( );

      // output banner html
      Out ( '<center>' + Application ( 'SideBanner' + Application ( 'CurrentSideBanner' ) ) + '</center>' );

      // decrement number of rotating banners by one
      if ( --nNumberToDisplay == 0 )
      {
         NavTableBottom ( );
         return;
      }
   }

   if ( bDisplayAllianceBanners )
   {
      // show an ASPAlliance button
      Out ( '<center>' );
            Out ( '<p>' );
         DebugOut ( '<font color="blue">showing ASPAlliance textad</font>' );
            ShowAllianceAd ( 100, 2 );
            Out ( '<p>' );
         DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );
            ShowAllianceAd ( 125, 1 );
            Out ( '<p>' );
      Out ( '</center>' );

      // decrement number of rotating banners by one
      if ( --nNumberToDisplay == 0 )
      {
         NavTableBottom ( );
         return;
      }
   }

   // fill the remaining slots with my rotating side content

   // how many banners do I have to choose from?
   var nContent = Application ( 'TotalMyBanners' );

   if ( !nContent )
   {
      DebugOut ( '<font color="blue">[no banners]</font>' );
      return;
   }

   // be safe!
   if ( nNumberToDisplay > nContent )
      nNumberToDisplay = nContent;

   // the random list of unique numbers
   var nOrder = new Array ( nNumberToDisplay );

   // an easy way to see if I've had this random number before
   var bUsed = new Array ( nContent );

   // the total number of random numbers I had to generate
   var nLoops = 0;

   for ( var i=0; i<nNumberToDisplay; i++ )
   {
      // generate a random number, and stay in loop until it's unique

      // ========================================
      // this loop should always quit on its own, but PLEASE remember
      // to always write safe code rather than clever code! There are
      // probably other sites on your server that you will hang up too.
      //
      // in this case I allow the loop to run 50 times, then I quit anyway
      // ========================================
      for ( var j=0; j<50; j++ )
      {
         // generate a random integer between 0 and nContent-1
         nRandom = Math.floor ( Math.random () * nContent );

         // increment our debug counter
         nLoops++;

         // have I used this number before?
         if ( !bUsed [ nRandom ] )
         {
            bUsed [ nRandom ] = true;
            break;
         }
      }

      nOrder [ i ] = nRandom;
   }

   Out ( '<center>' );

   // display the content in random order
   for ( i=0; i<nNumberToDisplay; i++ )
      Out ( Application ( 'MyBanner' + nOrder [ i ] ) + '<p>' );

   if ( bDisplayAllianceBanners )
   {
         DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );
         ShowAllianceAd ( 125, 2 );
   }

   Out ( '</center>' );

   // display the number of random numbers I had to waste!
   DebugOut ( '<font color="blue">[I had to generate ' + (nLoops-nNumberToDisplay) + ' wasted numbers!]</font>' );

   NavTableBottom ( );
}


// ============================================
// show the bottom banner
// ============================================
function ShowBottomBanner ( )
{
   if ( bDisplayAllianceBanners )
   {
      DebugOut ( '<font color="blue">showing ASPAlliance 468 banner</font>' );
      Out ( '<p align="center">' );
            ShowAllianceAd ( 469, 1 );
      Out ( '</p>' );
   }
}

// ============================================
// show the next available advertisement
// ============================================
function ShowTestimonials ( )
{
   // should we make a plain page for printing?
   if ( bPlainJane )
   {
      Out ( '&nbsp;' );
      return;
   }

   NavTableTop ( 'Testimonials' );
   // put these into database later..
   Out ( 'Some kind words from readers...' );
   Out ( '<hr color="#ff9900"><i>"No book I have bought, or forum I have read can compare to the simplistic and clean hands on structure you have developed in your site which inspires learning. Truly genius. T.J."</i>' );
   Out ( '<hr color="#ff9900"><i>"Just wanted to offer kudos for an application well done.  I\'ve played around with other "complete" web sites like WebWrox and other such things, but they lacked polish.  Yours kicks serious ass. S.C."</i>' );
   Out ( '<hr color="#ff9900"><i>"All in all an excellent "how-to" site. R.A."</i>' );
   Out ( '<hr color="#ff9900"><i>"I am really in awe of your site. It has everything that one can ask for. S.N."</i>' );
   Out ( '<hr color="#ff9900"><i>"Wicked site by the way... L.W."</i>' );
   Out ( '<hr color="#ff9900"><i>"Awesome site.  Keep up the good work. J."</i>' );
   NavTableBottom ( );
}

// ============================================
// show all affilates - used by Resource.asp
// ============================================
function DumpAffiliates ( )
{
   // how many banners to loop through
   var nAffiliates = Application ( 'TotalAffiliates' );

   var nNext = Application ( 'CurrentAffiliate' );

   for ( var i=0; i<nAffiliates; i++ )
   {
      // check for rollover
      if ( nNext+i > nAffiliates-1 )
         nNext = -i;

      var nAffiliate = nNext + i;

      // output banner image
      Out ( Application ( 'Affiliate' + nAffiliate ) + ' ' );
   }

   // move pointer to current affiliate
   Application.Lock ( );

   Application ( 'CurrentAffiliate' ) = nNext + nAffiliates;

   Application.Unlock ( );
}

// ============================================
// show all content in three columns - used by Resource.asp
// ============================================
function DumpContent ( )
{
   // how many banners to loop through
   var nContent = Application ( 'TotalMyBanners' );

   Out ( '<table width="100%" border=0 cellpadding=10 cellspacing=0>' );

   for ( var nRow=0; nRow < nContent; nRow+=3 )
   {
      Out ( '<tr>' );

      for ( var nOffset=0; nOffset<3; nOffset++)
      {
         Out ( '<td width="33%" align="center" valign="top"><table width="152"><tr><td>' );

            var nIndex = nRow + nOffset;

            if ( nIndex < nContent )
               Out ( Application ( 'MyBanner' + nIndex ) );
            else
               Out ( '&nbsp;' );

         Out ( '</td></tr></table></td>' );
      }

      Out ( '</tr>' );
   }

   Out ( '</table>' );
}

// ============================================
// show an ASP Alliance ad
// ============================================
function ShowAllianceAd ( nWidth, nPage )
{
return;

   // if the ads have to be taken offline, set this flag
   var bOffline = false;

   var nHeight;
   var nType, sType;

   switch ( nWidth )
   {
   case 469:
      nType = 1; // was 7
      nWidth = 468;
      nHeight = 60;
      sType = '468x60';
      break;
   case 468:
      nType = 1;
      nHeight = 60;
      sType = '468x60';
      break;
   case 126:
      nType = 5; // was 6;
      nWidth = 125;
      nHeight = 125;
      sType = '125x125';
      break;
   case 125:
      nType = 5;
      nHeight = 125;
      sType = '125x125';
      break;
   case 100:
      nType = 2;
      nHeight = 30;
      sType = '';
      break;
   case 1:
      nType = 2; // was 10
      sType = '1x2';
      break;
   case 0:
      nType = 3;
      sType = '1x2';
      break;
   default:
      return;
   }

   if ( bOffline )
   {
      Out ( '<table width="' + nWidth +'" height="' + nHeight + '"><tr><td>Ads offline</td></tr></table>' );
      return;
   }
   
   if (sType == '')
      return;
   
   Out ( '<div class="lqm_ad" lqm_publisher="lqm.coveryourasp.site" lqm_zone="ron" lqm_format="' + sType + '"></div>' );

//   Out ( '<script type="text/javascript">\n<!-- \nlqm_channel=1;\nlqm_publisher=6;\nlqm_zone=' + nPage + ';\nlqm_format=' + nType + ';\n//-->\n</script>\n' );
//   Out ( '<script type="text/javascript" src="http://a.lakequincy.com/s.js"></script>' );


//   Out ( '<iframe src="http://ads.aspalliance.com/displayad.aspx?m=6&t=' + nType + '&page=' + nPage + '&target=CYAexternal" width="' + nWidth +'" height="' + nHeight + '" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no">' );
//      Out ( '<script language="javascript" src="http://ads.aspalliance.com/displayad.asp?m=6&t=' + nType + '&page=' + nPage + '&target=CYAexternal"></script>' );
//   Out ( '</iframe>' );
}
%>

Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line.

To see the source code for this page, click on the icon below.

Featured sponsor
My favorite resources


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...