<!--

//Copyright Mangolab Ltd. 2008. All rights reserved.
//SUMMARY:
// Code previously used in IND_HEAD.HTM updated to no frames
// files are named season XX, month MM, Day DD such that: 
// each logo has a start possible display date and an end date
//HISTORY:
// 16.10.2008 Version 2.0
// 23.10.08 Version 2.0 - <FC> - Reviewd / FB ref: CASE:1496
// 19.03.09 Version 2.1 -<FC> - Updated to use new versions of logos FB ref: CASE:1750

var CntLogos = 30;
var aLogos = new Array(CntLogos);
var aDateRange = new Array(CntLogos);
var aDescription = new Array(CntLogos);
var SitePath = '/';

function SetLogoData() {
var i=0;
//Special variable date occasions
aLogos[i] = "pb_logo_easter.jpg"; aDateRange[i] = "02/04 - 05/04"; aDescription[i] = "Happy Easter from all at Polybags!"; i++;
aLogos[i] = "pb_logo_pudsey.jpg"; aDateRange[i] = "13/11 - 20/11"; aDescription[i] = "We give one pound to Children in Need for every online order we receive. So thank you from Pudsey!"; i++;
//aLogos[i] = "pb_logo_rednose.jpg"; aDateRange[i] = "10/03 - 17/03"; aDescription[i] = "For every online sale we&#146;re donating £1 to Comic Relief for Red nose Day (and we&#146;ll even wear the red nose for you!), so on behalf of Comic Relief, thank you."; i++;//Runs alternately with Sports Relief (no logo)
aLogos[i] = "pb_logo_poppy.jpg"; aDateRange[i] = "2/11 - 12/11"; aDescription[i] = "Remembrancetide: We will not forget..."; i++;//aLogos[i] = "pb_logo_rednose.jpg"; aDateRange[i] = "10/03 - 17/03"; aDescription[i] = "For every online sale we&#146;re donating £1 to Comic Relief for Red nose Day (and we&#146;ll even wear the red nose for you!), so on behalf of Comic Relief, thank you."; i++;//is on 16/3/2007
aLogos[i] = "pb_logo_poppy.jpg"; aDateRange[i] = "02/11 - 12/11"; aDescription[i] = "Remembrancetide: We will not forget..."; i++;
//Variable Sporting occasions:
// - cricket:
aLogos[i] = "pb_logo_cricket.jpg"; aDateRange[i] = "25/11 - 29/11"; aDescription[i] = "Good luck in the 1st test!"; i++;
aLogos[i] = "pb_logo_cricket.jpg"; aDateRange[i] = "03/12 - 07/12"; aDescription[i] = "Good luck in the 2nd Test!"; i++;
aLogos[i] = "pb_logo_cricket.jpg"; aDateRange[i] = "16/12 - 20/12"; aDescription[i] = "Good luck in the 3rd Test!"; i++;
aLogos[i] = "pb_logo_cricket.jpg"; aDateRange[i] = "26/12 - 30/12"; aDescription[i] = "Good luck in the 4th Test!"; i++;
aLogos[i] = "pb_logo_cricket.jpg"; aDateRange[i] = "03/01 - 07/01"; aDescription[i] = "Good luck in the 5th Test!"; i++;
// - football:
aLogos[i] = "pb_logo_football.jpg"; aDateRange[i] = "11/06 - 11/07"; aDescription[i] = "Good luck all in The World Cup!"; i++;
// - rugby:
aLogos[i] = "pb_logo_rugby.jpg"; aDateRange[i] = "13/03 - 14/03"; aDescription[i] = "Good luck all in the Rugby!"; i++;
aLogos[i] = "pb_logo_rugby.jpg"; aDateRange[i] = "19/03 - 20/03"; aDescription[i] = "Good luck all in Rugby!"; i++;
// - wimbledon:
aLogos[i] = "pb_logo_strawberries.jpg"; aDateRange[i] = "21/06 - 04/07"; aDescription[i] = "Welcome to Polybags - anyone for tennis? Or maybe you just need some food bags?!"; i++;
//All year
aLogos[i] = "pb_logo_plain.jpg"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags"; i++;
aLogos[i] = "pb_logo_antistatic_bags.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your antistatic bags!"; i++;
aLogos[i] = "pb_logo_biodegradable_bags.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your biodegradable bags!"; i++;
aLogos[i] = "pb_logo_mailing_bags_metallic.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your metallic mailing bags!"; i++;
aLogos[i] = "pb_logo_mailing_envelopes.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your mailing envelopes!"; i++;
aLogos[i] = "pb_logo_polythene_bags_1.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your polythene bags!"; i++;
aLogos[i] = "pb_logo_polythene_bags_2.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your polythene bags!"; i++;
aLogos[i] = "pb_logo_polythene_film.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your polythene film!"; i++;
aLogos[i] = "pb_logo_polythene_film_on_the_roll.png"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags. The best place to get your polythene film on the roll!"; i++;
//nasty - delete: aLogos[i] = "pb_logo_online_yellow.jpg"; aDateRange[i] = "01/01 - 31/12"; aDescription[i] = "Welcome to Polybags"; i++;
//Spring
//aLogos[i] = "pb_logo_april_fool.jpg"; aDateRange[i] = "01/04 - 01/04"; aDescription[i] = "Is nothing safe?! Happy April Fool&#146;s Day!"; i++;
aLogos[i] = "pb_logo_daffodils.jpg"; aDateRange[i] = "10/03 - 30/04"; aDescription[i] = "Welcome to Polybags - Looking for flower sleeves?"; i++;
aLogos[i] = "pb_logo_snowdrops.jpg"; aDateRange[i] = "01/02 - 15/03"; aDescription[i] = "Welcome to Polybags - Looking for flower sleeves?"; i++;
aLogos[i] = "pb_logo_blackberries.jpg"; aDateRange[i] = "01/08 - 15/10"; aDescription[i] = "Welcome to Polybags - need bags for your blackberries? You can never pick them too early!"; i++;
//Late Spring to summer
//aLogos[i] = "pb_logo_april_showers.jpg"; aDateRange[i] = "01/04 - 01/06"; aDescription[i] = "The sun may come and go but Polybags is always here!"; i++;
aLogos[i] = "pb_logo_lawn.jpg"; aDateRange[i] = "01/05 - 01/07"; aDescription[i] = "Welcome to Polybags - *the* place to get your compost bags!"; i++;
//aLogos[i] = "pb_logo_parasol.jpg"; aDateRange[i] = "01/06 - 10/09"; aDescription[i] = "Welcome to Polybags - Summertime... and the buying is easy!"; i++;
//Summer
aLogos[i] = "pb_logo_deckchair.jpg"; aDateRange[i] = "15/07 - 31/08"; aDescription[i] = "Welcome to Summertime at Polybags - we like to make re-ordering fast and easy to give you a little extra time for lounging!"; i++;
aLogos[i] = "pb_logo_bbq.jpg"; aDateRange[i] = "15/07 - 31/08"; aDescription[i] = "Welcome to Polybags - the place to get your food bags for those BBQ leftovers!"; i++;
//aLogos[i] = "pb_logo_hotsun.jpg"; aDateRange[i] = "12/07 - 20/08"; aDescription[i] = "Welcome to Summertime at Polybags - your place for those scorching hot deals!"; i++;
aLogos[i] = "pb_logo_strawberries.jpg"; aDateRange[i] = "20/06 - 20/07"; aDescription[i] = "Welcome to Polybags - anyone for tennis? Or maybe some food bags?"; i++;
//Autumn
aLogos[i] = "pb_logo_autumn.jpg"; aDateRange[i] = "20/09 - 20/11"; aDescription[i] = "Welcome to Polybags"; i++;
//Winter - November, December
aLogos[i] = "pb_logo_halloween.jpg"; aDateRange[i] = "31/10 - 31/10"; aDescription[i] = "Happy Halloween! Only treats here..."; i++;
aLogos[i] = "pb_logo_snow.jpg"; aDateRange[i] = "01/12 - 31/12"; aDescription[i] = "Welcome to Polybags - a place where you can wrap up well!"; i++;
aLogos[i] = "pb_logo_xmas.jpg"; aDateRange[i] = "15/12 - 28/12"; aDescription[i] = "Happy Christmas from all at Polybags!"; i++;
aLogos[i] = "pb_logo_fireworks.jpg"; aDateRange[i] = "05/11 - 05/11"; aDescription[i] = "Happy Bonfire Night!"; i++;
aLogos[i] = "pb_logo_fireworks.jpg"; aDateRange[i] = "30/12 - 31/12";  aDescription[i] = "Happy New Year from us all at Polybags!"; i++;//ie new year
aLogos[i] = "pb_logo_fireworks.jpg"; aDateRange[i] = "28/01 - 29/01";  aDescription[i] = "Happy Chinese New Year!"; i++;//ie Chinese new year
aLogos[i] = "pb_logo_party.jpg"; aDateRange[i] = "01/01 - 05/01";  aDescription[i] = "Happy New Year from us all at Polybags!"; i++;//ie new year
aLogos[i] = "pb_logo_party.jpg"; aDateRange[i] = "28/01 - 29/01";  aDescription[i] = "Happy Chinese New Year!"; i++;//ie Chinese new year
//Winter - Jan,Feb
aLogos[i] = "pb_logo_snow.jpg"; aDateRange[i] = "01/01 - 01/02"; aDescription[i] = "Welcome to Polybags - a good place to get your freezer bags!"; i++;
aLogos[i] = "pb_logo_snow.jpg"; aDateRange[i] = "01/12 - 31/12"; aDescription[i] = "Welcome to Polybags - a place where you can wrap up well!"; i++;
}

//see http://www.w3schools.com/jsref/jsref_obj_date.asp

function GetLogoImgTag() {
var Now = new Date(); //ie holds current date as initial value
var StrDtD = ""; var StrDtM = "";
var DtStart = new Date();
var DtEnd = new Date();
var Dt = new Array(aLogos.length);
var aTodaysRange = new Array(CntLogos);
var aTodaysLogos = new Array(CntLogos);
var aTodaysDescriptions = new Array(CntLogos);
var CntToday = 0;
var SumTodaysRanges = 0;
var SumTodaysInverseRanges = 0;
var CumulativeRange = 0;
var Html='';
//set the data arrays
SetLogoData();
//ie tests from [0]
for (var i = 0 ; i < aLogos.length ; i++){  
    if (aLogos[i]!=undefined){
	   //Month is 0 based so 0=January, NB Slice does not include end character
	   DtStart = new Date(); DtEnd = new Date(); //needs these or date setting routines below cock up when var are reused
	   StrDtD=aDateRange[i].slice(0,2); StrDtM=aDateRange[i].slice(3,5)-1;
	   //alert('Date='+StrDtD+' Month='+StrDtM);
	   DtStart.setDate(StrDtD); DtStart.setMonth(StrDtM); DtStart.setHours(0); DtStart.setMinutes(0);
	   StrDtD=aDateRange[i].slice(8,10); StrDtM=aDateRange[i].slice(11,13)-1;	   
	   DtEnd.setDate(StrDtD); DtEnd.setMonth(StrDtM); DtEnd.setHours(23); DtEnd.setMinutes(59); 
	   //If today is within range add it to our possible today date ranges
	   //alert('i='+i+' next Logo: '+aLogos[i]+' with DtStart='+DtStart+' DtEnd='+DtEnd);
	   if ((Now <= DtEnd) && (Now >= DtStart)){	  
	      //alert('Adding Logo: '+aLogos[i]+' with DtStart='+DtStart+' DtEnd='+DtEnd);	   
		  aTodaysLogos[CntToday] = aLogos[i];
		  aTodaysDescriptions[CntToday] = aDescription[i];
		  aTodaysRange[CntToday] = (DtEnd.getTime()-DtStart.getTime());
		  //So that its more likely we show a logo with a smaller range
		  //We total up all the ranges so that each logo covers a range within the total range figure, then we will consider the inverse relative proportions of each range to the others
          SumTodaysRanges+= aTodaysRange[CntToday];
		  //alert('CntToday='+CntToday+' Added Logo: '+aTodaysLogos[CntToday]+' with aTodaysRange='+aTodaysRange[CntToday]+' SumTodaysRanges='+SumTodaysRanges);
		  CntToday++;
		  } 	
	   }
    }
//Now we have to reverse the importance of the ranges so that the biggest ranges proportionately become the smallest ones
for (i = 0 ; i < CntToday ; i++){
    aTodaysRange[i] = SumTodaysRanges/aTodaysRange[i];
    SumTodaysInverseRanges+=aTodaysRange[i];
	}
//alert('CntToday='+CntToday+' SumTodaysRanges='+SumTodaysRanges);	
//Now we pick a single point from within our total inverse range  - ie this guarantees that one of them will definately win
var RandomPoint = Math.random() * SumTodaysInverseRanges;
for (i = 0 ; i < CntToday ; i++){ 
	//the RandomPoint lies within one of the inverse-date-ranges now, so as we rebuild SumTodaysInverseRanges, as soon as CumulativeRange hits/exceeds the RandomPoint we have our winner
	CumulativeRange+= aTodaysRange[i];
	//alert('i='+i+'/'+(CntToday-1)+' pic='+aTodaysLogos[i]+' RandomPoint='+RandomPoint+' CumulativeRange='+CumulativeRange +' aTodaysRange='+aTodaysRange[i]);
 	if (RandomPoint<=CumulativeRange){
	   Html='<a href="/index.htm" title="' + aTodaysDescriptions[i] + '"><img id="logo" style="border:none;" src="'+SitePath+aTodaysLogos[i]+ '" alt="' + aTodaysDescriptions[i] + '" \/><\/a>';
	   //alert(Html);
	   return Html;
	   }
	}	
}


//-->
