// JavaScript Document

<!--
  window.onerror = silentHandler;
  function silentHandler() {return false};

  var push = function() 
  {
    var j = this.length;
    for (var i=0;i<push.arguments.length;++i) 
    {
      this[j] = push.arguments[i]
      j++
    }
  }
  Array.prototype.push = push

  var associativeClass = function(j) 
  {
    for (var i=1;i<=j;++i) 
    {
      this[i] = new associativeObj();
    }
  }
  var associativeObj = function() {}

  var getBannerTemplate = function() 
  {
    // define the total number of banners in the set
    var iBannerTotal = 2;

    // create an implicit array
    var ia = new associativeClass(iBannerTotal); 

    // create an explicit array
    var ar = new Array();

    // define each image within the set (the set must be equal in number to iBannerTotal)
    ia[1].imageName = '/ftproot/images/col_puppy_guide_yellow.gif';
    ia[2].imageName = '/ftproot/images/col_kitten_guide_lblue.gif';

    // assign a weight to each image in the set 
    ia[1].weight = 5;
    ia[2].weight = 5;

    // assign background color values to each image in the set
    ia[1].backgroundcolor = '#09438A';
    ia[2].backgroundcolor = '#09438A';

    // assign a url to each image in the set 
    ia[1].url = 'location.href=' + "'/PuppyTrainingAndSocialisation/553/n/3/0/0/'" + '"';
    ia[2].url = 'location.href=' + "'/TopTipsForKittenTraining/539/n/3/0/0/'" + '"';

    // assign title text to each image in the set 
    ia[1].title = 'Click here to get the best tips for your pup';
    ia[2].title = 'Click here to get the best tips for your kitten';

    // assign any other required values to each image in the set
    // ia[1].height = 80;
    // width, border, target, script etc. whatevers needed to build the final script

    // get the sum of the weighted values
    var iWeightTotal = 0;
    for (i in ia) 
    {
      iWeightTotal += ia[i].weight
    }

    // calculate and store the weight percentages
    for (i in ia) 
    {
      ia[i].percentage = Math.round((ia[i].weight / iWeightTotal) * 100);
    }

    // push an implicit array object id onto the explicit array once for each id percentage point 
    for (i in ia) 
    {
      for (var j=0;j<ia[i].percentage;++j) 
      {
         ar.push(i)
      }
    }

    // get a random integer value between 0 and the explicit array length
    var k = Math.round(Math.random()*ar.length)

    // return a weighted imageName object
    // return ia[ar[k]].imageName

    // as an alternative to returning an explicit value embed multiple values within script
    var scriptText = '<br><table border="0" cellspacing="0" cellpadding="0" width="100%">';  
    if (ia[ar[k]].url) 
    { 
      scriptText += '  <tr><td onclick="javascript:' + ia[ar[k]].url + ' target="_blank" style="cursor:pointer; background-color: ' + ia[ar[k]].backgroundcolor + '; background-position: top left; background-image: url(' + ia[ar[k]].imageName + '); background-repeat: no-repeat" valign="top" title="' + ia[ar[k]].title + '" width="906"><img height="100" src="/images/cs_tm.gif" width="100%" border="0" /></td></tr>';
    } 
    else 
    {
      scriptText += '  <tr><td style="background-color: ' + ia[ar[k]].backgroundcolor + '; background-position: top left; background-image: url(' + ia[ar[k]].imageName + '); background-repeat: no-repeat" valign="top" width="906"><a href="" target=""><img height="100" src="/images/cs_tm.gif" width="1" border="0" /></td></tr>';
    }
    scriptText += '</table>';  

    return scriptText;

  }

  document.write(getBannerTemplate());
// -->
